You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

common_power.h 17 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* All rights reserved. */
  4. /* */
  5. /* Redistribution and use in source and binary forms, with or */
  6. /* without modification, are permitted provided that the following */
  7. /* conditions are met: */
  8. /* */
  9. /* 1. Redistributions of source code must retain the above */
  10. /* copyright notice, this list of conditions and the following */
  11. /* disclaimer. */
  12. /* */
  13. /* 2. Redistributions in binary form must reproduce the above */
  14. /* copyright notice, this list of conditions and the following */
  15. /* disclaimer in the documentation and/or other materials */
  16. /* provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  19. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  20. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  21. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  22. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  23. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  24. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  25. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  26. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  27. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  28. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  29. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  30. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  31. /* POSSIBILITY OF SUCH DAMAGE. */
  32. /* */
  33. /* The views and conclusions contained in the software and */
  34. /* documentation are those of the authors and should not be */
  35. /* interpreted as representing official policies, either expressed */
  36. /* or implied, of The University of Texas at Austin. */
  37. /*********************************************************************/
  38. #ifndef COMMON_POWER
  39. #define COMMON_POWER
  40. #if defined(POWER8) || defined(POWER9)
  41. #define MB __asm__ __volatile__ ("eieio":::"memory")
  42. #define WMB __asm__ __volatile__ ("eieio":::"memory")
  43. #else
  44. #define MB __asm__ __volatile__ ("sync")
  45. #define WMB __asm__ __volatile__ ("sync")
  46. #endif
  47. #define INLINE inline
  48. #ifdef PPC440
  49. #define STDERR stdout
  50. #define QNONCACHE 0x1
  51. #define QCOMMS 0x2
  52. #define QFAST 0x4
  53. #endif
  54. #ifndef ASSEMBLER
  55. void *qalloc(int flags, size_t bytes);
  56. static void INLINE blas_lock(volatile unsigned long *address){
  57. long int ret, val = 1;
  58. do {
  59. while (*address) {YIELDING;};
  60. #if defined(OS_LINUX) || defined(OS_DARWIN)
  61. __asm__ __volatile__ (
  62. "0: lwarx %0, 0, %1\n"
  63. " cmpwi %0, 0\n"
  64. " bne- 1f\n"
  65. " stwcx. %2,0, %1\n"
  66. " bne- 0b\n"
  67. "1: "
  68. : "=&r"(ret)
  69. : "r"(address), "r" (val)
  70. : "cr0", "memory");
  71. #else
  72. __asm__ __volatile__ (
  73. ".machine \"any\"\n"
  74. " lwarx %0, 0, %1\n"
  75. " cmpwi %0, 0\n"
  76. " bne- $+12\n"
  77. " stwcx. %2,0, %1\n"
  78. " bne- $-16\n"
  79. : "=&r"(ret)
  80. : "r"(address), "r" (val)
  81. : "cr0", "memory");
  82. #endif
  83. } while (ret);
  84. }
  85. #define BLAS_LOCK_DEFINED
  86. static inline unsigned long rpcc(void){
  87. unsigned long ret;
  88. #ifdef OS_AIX
  89. __asm__ __volatile__(".machine \"any\" ;");
  90. #endif
  91. __asm__ __volatile__ ("mftb %0" : "=r" (ret) : );
  92. #if defined(POWER5) || defined(PPC970)
  93. return (ret << 6);
  94. #else
  95. return (ret << 3);
  96. #endif
  97. }
  98. #define RPCC_DEFINED
  99. #ifdef __64BIT__
  100. #define RPCC64BIT
  101. #endif
  102. static inline unsigned long getstackaddr(void){
  103. unsigned long addr;
  104. __asm__ __volatile__ ("mr %0, 1"
  105. : "=r"(addr) : : "memory");
  106. return addr;
  107. };
  108. #if defined(OS_LINUX) || defined(OS_AIX)
  109. #define GET_IMAGE(res) __asm__ __volatile__("fmr %0, 2" : "=f"(res) : : "memory")
  110. #else
  111. #define GET_IMAGE(res) __asm__ __volatile__("fmr %0, f2" : "=f"(res) : : "memory")
  112. #define GET_IMAGE_CANCEL
  113. #endif
  114. #ifdef SMP
  115. static inline int blas_quickdivide(blasint x, blasint y){
  116. return x / y;
  117. }
  118. #endif
  119. #endif
  120. #ifdef ASSEMBLER
  121. #ifdef DOUBLE
  122. #define LFD lfd
  123. #define LFDX lfdx
  124. #define LFPDX lfpdx
  125. #define LFSDX lfsdx
  126. #define LFXDX lfxdx
  127. #define LFDU lfdu
  128. #define LFDUX lfdux
  129. #define LFPDUX lfpdux
  130. #define LFSDUX lfsdux
  131. #define LFXDUX lfxdux
  132. #define STFD stfd
  133. #define STFDX stfdx
  134. #define STFPDX stfpdx
  135. #define STFSDX stfsdx
  136. #define STFXDX stfxdx
  137. #define STFDU stfdu
  138. #define STFDUX stfdux
  139. #define STFPDUX stfpdux
  140. #define STFSDUX stfsdux
  141. #define STFXDUX stfxdux
  142. #define FMADD fmadd
  143. #define FMSUB fmsub
  144. #define FNMADD fnmadd
  145. #define FNMSUB fnmsub
  146. #define FMUL fmul
  147. #define FADD fadd
  148. #define FSUB fsub
  149. #else
  150. #define LFD lfs
  151. #define LFDX lfsx
  152. #define LFPDX lfpsx
  153. #define LFSDX lfssx
  154. #define LFXDX lfxsx
  155. #define LFDU lfsu
  156. #define LFDUX lfsux
  157. #define LFPDUX lfpsux
  158. #define LFSDUX lfssux
  159. #define LFXDUX lfxsux
  160. #define STFD stfs
  161. #define STFDX stfsx
  162. #define STFPDX stfpsx
  163. #define STFSDX stfssx
  164. #define STFXDX stfxsx
  165. #define STFDU stfsu
  166. #define STFDUX stfsux
  167. #define STFPDUX stfpsux
  168. #define STFSDUX stfssux
  169. #define STFXDUX stfxsux
  170. #define FMADD fmadds
  171. #define FMSUB fmsubs
  172. #define FNMADD fnmadds
  173. #define FNMSUB fnmsubs
  174. #define FMUL fmuls
  175. #define FADD fadds
  176. #define FSUB fsubs
  177. #endif
  178. #ifdef __64BIT__
  179. #define LDLONG ld
  180. #else
  181. #define LDLONG lwz
  182. #endif
  183. #ifdef OS_DARWIN
  184. #define LL(x) L##x
  185. #endif
  186. #ifdef OS_LINUX
  187. #define LL(x) .L##x
  188. #endif
  189. #ifndef LL
  190. #define LL(x) __L##x
  191. #endif
  192. #if defined(__64BIT__) && defined(USE64BITINT)
  193. #define LDINT ld
  194. #elif defined(__64BIT__) && !defined(USE64BITINT)
  195. #define LDINT lwa
  196. #else
  197. #define LDINT lwz
  198. #endif
  199. /*
  200. #define DCBT(REGA, REGB, NUM) .long (0x7c00022c | (REGA << 16) | (REGB << 11) | ((NUM) << 21))
  201. #define DCBTST(REGA, REGB, NUM) .long (0x7c0001ec | (REGA << 16) | (REGB << 11) | ((NUM) << 21))
  202. */
  203. #define DSTATTR_H(SIZE, COUNT, STRIDE) ((SIZE << 8) | (COUNT))
  204. #define DSTATTR_L(SIZE, COUNT, STRIDE) (STRIDE)
  205. #if defined(PPC970) || defined(POWER3) || defined(POWER4) || defined(POWER5) || defined(PPCG4)
  206. #define HAVE_PREFETCH
  207. #endif
  208. #if defined(POWER3) || defined(POWER6) || defined(PPCG4) || defined(CELL) || defined(POWER8) || defined(POWER9) || ( defined(PPC970) && defined(OS_DARWIN) )
  209. #define DCBT_ARG 0
  210. #else
  211. #define DCBT_ARG 8
  212. #endif
  213. #ifdef CELL
  214. #define L1_DUALFETCH
  215. #define L1_PREFETCHSIZE (64 + 128 * 13)
  216. #endif
  217. #if defined(POWER3) || defined(POWER4) || defined(POWER5)
  218. #define L1_DUALFETCH
  219. #define L1_PREFETCHSIZE (96 + 128 * 12)
  220. #endif
  221. #if defined(POWER6)
  222. #define L1_DUALFETCH
  223. #define L1_PREFETCHSIZE (16 + 128 * 100)
  224. #define L1_PREFETCH dcbtst
  225. #endif
  226. #if defined(POWER8) || defined(POWER9)
  227. #define L1_DUALFETCH
  228. #define L1_PREFETCHSIZE (16 + 128 * 100)
  229. #define L1_PREFETCH dcbtst
  230. #endif
  231. #
  232. #ifndef L1_PREFETCH
  233. #define L1_PREFETCH dcbt
  234. #endif
  235. #ifndef L1_PREFETCHW
  236. #define L1_PREFETCHW dcbtst
  237. #endif
  238. #if DCBT_ARG == 0
  239. #define DCBT(REGA, REGB) L1_PREFETCH REGB, REGA
  240. #define DCBTST(REGA, REGB) L1_PREFETCHW REGB, REGA
  241. #else
  242. #define DCBT(REGA, REGB) L1_PREFETCH DCBT_ARG, REGB, REGA
  243. #define DCBTST(REGA, REGB) L1_PREFETCHW DCBT_ARG, REGB, REGA
  244. #endif
  245. #ifndef L1_PREFETCHSIZE
  246. #define L1_PREFETCHSIZE (96 + 128 * 12)
  247. #endif
  248. #if !defined(OS_DARWIN) || defined(NEEDPARAM)
  249. #define f0 0
  250. #define f1 1
  251. #define f2 2
  252. #define f3 3
  253. #define f4 4
  254. #define f5 5
  255. #define f6 6
  256. #define f7 7
  257. #define f8 8
  258. #define f9 9
  259. #define f10 10
  260. #define f11 11
  261. #define f12 12
  262. #define f13 13
  263. #define f14 14
  264. #define f15 15
  265. #define f16 16
  266. #define f17 17
  267. #define f18 18
  268. #define f19 19
  269. #define f20 20
  270. #define f21 21
  271. #define f22 22
  272. #define f23 23
  273. #define f24 24
  274. #define f25 25
  275. #define f26 26
  276. #define f27 27
  277. #define f28 28
  278. #define f29 29
  279. #define f30 30
  280. #define f31 31
  281. #define r0 0
  282. #define r1 1
  283. #define r2 2
  284. #define r3 3
  285. #define r4 4
  286. #define r5 5
  287. #define r6 6
  288. #define r7 7
  289. #define r8 8
  290. #define r9 9
  291. #define r10 10
  292. #define r11 11
  293. #define r12 12
  294. #define r13 13
  295. #define r14 14
  296. #define r15 15
  297. #define r16 16
  298. #define r17 17
  299. #define r18 18
  300. #define r19 19
  301. #define r20 20
  302. #define r21 21
  303. #define r22 22
  304. #define r23 23
  305. #define r24 24
  306. #define r25 25
  307. #define r26 26
  308. #define r27 27
  309. #define r28 28
  310. #define r29 29
  311. #define r30 30
  312. #define r31 31
  313. #define v0 0
  314. #define v1 1
  315. #define v2 2
  316. #define v3 3
  317. #define v4 4
  318. #define v5 5
  319. #define v6 6
  320. #define v7 7
  321. #define v8 8
  322. #define v9 9
  323. #define v10 10
  324. #define v11 11
  325. #define v12 12
  326. #define v13 13
  327. #define v14 14
  328. #define v15 15
  329. #define v16 16
  330. #define v17 17
  331. #define v18 18
  332. #define v19 19
  333. #define v20 20
  334. #define v21 21
  335. #define v22 22
  336. #define v23 23
  337. #define v24 24
  338. #define v25 25
  339. #define v26 26
  340. #define v27 27
  341. #define v28 28
  342. #define v29 29
  343. #define v30 30
  344. #define v31 31
  345. #define BO_dCTR_NZERO_AND_NOT 0
  346. #define BO_dCTR_NZERO_AND_NOT_1 1
  347. #define BO_dCTR_ZERO_AND_NOT 2
  348. #define BO_dCTR_ZERO_AND_NOT_1 3
  349. #define BO_IF_NOT 4
  350. #define BO_IF_NOT_1 5
  351. #define BO_IF_NOT_2 6
  352. #define BO_IF_NOT_3 7
  353. #define BO_dCTR_NZERO_AND 8
  354. #define BO_dCTR_NZERO_AND_1 9
  355. #define BO_dCTR_ZERO_AND 10
  356. #define BO_dCTR_ZERO_AND_1 11
  357. #define BO_IF 12
  358. #define BO_IF_1 13
  359. #define BO_IF_2 14
  360. #define BO_IF_3 15
  361. #define BO_dCTR_NZERO 16
  362. #define BO_dCTR_NZERO_1 17
  363. #define BO_dCTR_ZERO 18
  364. #define BO_dCTR_ZERO_1 19
  365. #define BO_ALWAYS 20
  366. #define BO_ALWAYS_1 21
  367. #define BO_ALWAYS_2 22
  368. #define BO_ALWAYS_3 23
  369. #define BO_dCTR_NZERO_8 24
  370. #define BO_dCTR_NZERO_9 25
  371. #define BO_dCTR_ZERO_8 26
  372. #define BO_dCTR_ZERO_9 27
  373. #define BO_ALWAYS_8 28
  374. #define BO_ALWAYS_9 29
  375. #define BO_ALWAYS_10 30
  376. #define BO_ALWAYS_11 31
  377. #define CR0_LT 0
  378. #define CR0_GT 1
  379. #define CR0_EQ 2
  380. #define CR0_SO 3
  381. #define CR1_FX 4
  382. #define CR1_FEX 5
  383. #define CR1_VX 6
  384. #define CR1_OX 7
  385. #define CR2_LT 8
  386. #define CR2_GT 9
  387. #define CR2_EQ 10
  388. #define CR2_SO 11
  389. #define CR3_LT 12
  390. #define CR3_GT 13
  391. #define CR3_EQ 14
  392. #define CR3_SO 15
  393. #define CR4_LT 16
  394. #define CR4_GT 17
  395. #define CR4_EQ 18
  396. #define CR4_SO 19
  397. #define CR5_LT 20
  398. #define CR5_GT 21
  399. #define CR5_EQ 22
  400. #define CR5_SO 23
  401. #define CR6_LT 24
  402. #define CR6_GT 25
  403. #define CR6_EQ 26
  404. #define CR6_SO 27
  405. #define CR7_LT 28
  406. #define CR7_GT 29
  407. #define CR7_EQ 30
  408. #define CR7_SO 31
  409. #define TO_LT 16
  410. #define TO_GT 8
  411. #define TO_EQ 4
  412. #define TO_LLT 2
  413. #define TO_LGT 1
  414. #define CR0 0
  415. #define CR1 1
  416. #define CR2 2
  417. #define CR3 3
  418. #define CR4 4
  419. #define CR5 5
  420. #define CR6 6
  421. #define CR7 7
  422. #define cr0 0
  423. #define cr1 1
  424. #define cr2 2
  425. #define cr3 3
  426. #define cr4 4
  427. #define cr5 5
  428. #define cr6 6
  429. #define cr7 7
  430. #define VRsave 256
  431. #endif
  432. #define CTR 9
  433. #define SP r1
  434. #ifdef __64BIT__
  435. #define slwi sldi
  436. #define cmpwi cmpdi
  437. #define srawi sradi
  438. #define mullw mulld
  439. #endif
  440. #ifndef F_INTERFACE
  441. #define REALNAME ASMNAME
  442. #else
  443. #define REALNAME ASMFNAME
  444. #endif
  445. #if defined(ASSEMBLER) && !defined(NEEDPARAM)
  446. #ifdef OS_LINUX
  447. #ifndef __64BIT__
  448. #define PROLOGUE \
  449. .section .text;\
  450. .align 6;\
  451. .globl REALNAME;\
  452. .type REALNAME, @function;\
  453. REALNAME:
  454. #define EPILOGUE .size REALNAME, .-REALNAME
  455. #else
  456. #if _CALL_ELF == 2
  457. #define PROLOGUE \
  458. .section .text;\
  459. .align 6;\
  460. .globl REALNAME;\
  461. .type REALNAME, @function;\
  462. REALNAME:
  463. #define EPILOGUE .size REALNAME, .-REALNAME
  464. #else
  465. #define PROLOGUE \
  466. .section .text;\
  467. .align 5;\
  468. .globl REALNAME;\
  469. .section ".opd","aw";\
  470. .align 3;\
  471. REALNAME:;\
  472. .quad .REALNAME, .TOC.@tocbase, 0;\
  473. .previous;\
  474. .size REALNAME, 24;\
  475. .type .REALNAME, @function;\
  476. .globl .REALNAME;\
  477. .REALNAME:
  478. #define EPILOGUE \
  479. .long 0 ; \
  480. .byte 0,0,0,1,128,0,0,0 ; \
  481. .size .REALNAME, .-.REALNAME; \
  482. .section .note.GNU-stack,"",@progbits
  483. #endif
  484. #endif
  485. #ifdef PROFILE
  486. #ifndef __64BIT__
  487. #define PROFCODE ;\
  488. .section ".data";\
  489. .align 2;\
  490. .LP3:;\
  491. .long 0;\
  492. .section ".text";\
  493. mflr r0;\
  494. stw r0, 4(SP);\
  495. lis r12, .LP3@ha;\
  496. la r0, .LP3@l(r12);\
  497. bl _mcount;\
  498. lwz r0, 4(SP);\
  499. mtlr r0
  500. #else
  501. #define PROFCODE \
  502. .globl _mcount; \
  503. mflr r0; \
  504. std r0, 16(SP); \
  505. mr r11, SP; \
  506. addi SP, SP, -256; \
  507. std r11, 0(SP); \
  508. std r3, 128(SP); \
  509. std r4, 136(SP); \
  510. std r5, 144(SP); \
  511. std r6, 152(SP); \
  512. std r7, 160(SP); \
  513. std r8, 168(SP); \
  514. std r9, 176(SP); \
  515. std r10, 184(SP); \
  516. stfd f3, 192(SP); \
  517. stfd f4, 200(SP); \
  518. bl ._mcount; \
  519. nop; \
  520. ld r3, 128(SP);\
  521. ld r4, 136(SP);\
  522. ld r5, 144(SP);\
  523. ld r6, 152(SP);\
  524. ld r7, 160(SP);\
  525. ld r8, 168(SP);\
  526. ld r9, 176(SP);\
  527. ld r10, 184(SP);\
  528. lfd f3, 192(SP);\
  529. lfd f4, 200(SP);\
  530. addi SP, SP, 256;\
  531. ld r0, 16(SP);\
  532. mtlr r0
  533. #endif
  534. #else
  535. #define PROFCODE
  536. #endif
  537. #endif
  538. #if OS_AIX
  539. #ifndef __64BIT__
  540. #define PROLOGUE \
  541. .machine "any";\
  542. .toc;\
  543. .globl .REALNAME;\
  544. .globl REALNAME;\
  545. .csect REALNAME[DS],3;\
  546. REALNAME:;\
  547. .long .REALNAME, TOC[tc0], 0;\
  548. .csect .text[PR],5;\
  549. .REALNAME:
  550. #define EPILOGUE \
  551. _section_.text:;\
  552. .csect .data[RW],4;\
  553. .long _section_.text;
  554. #else
  555. #define PROLOGUE \
  556. .machine "any";\
  557. .toc;\
  558. .globl .REALNAME;\
  559. .globl REALNAME;\
  560. .csect REALNAME[DS],3;\
  561. REALNAME:;\
  562. .llong .REALNAME, TOC[tc0], 0;\
  563. .csect .text[PR], 5;\
  564. .REALNAME:
  565. #define EPILOGUE \
  566. _section_.text:;\
  567. .csect .data[RW],4;\
  568. .llong _section_.text;
  569. #endif
  570. #define PROFCODE
  571. #endif
  572. #ifdef OS_DARWIN
  573. #ifndef __64BIT__
  574. .macro PROLOGUE
  575. .section __TEXT,__text,regular,pure_instructions
  576. .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
  577. .machine ppc
  578. .text
  579. .align 4
  580. .globl REALNAME
  581. REALNAME:
  582. .endmacro
  583. #else
  584. .macro PROLOGUE
  585. .section __TEXT,__text,regular,pure_instructions
  586. .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
  587. .machine ppc64
  588. .text
  589. .align 4
  590. .globl REALNAME
  591. REALNAME:
  592. .endmacro
  593. #endif
  594. #ifndef PROFILE
  595. #define PROFCODE
  596. #define EPILOGUE .subsections_via_symbols
  597. #else
  598. #ifndef __64BIT__
  599. .macro PROFCODE
  600. mflr r0
  601. stw r0, 8(SP)
  602. addi SP, SP, -64
  603. stw SP, 0(SP)
  604. stw r3, 12(SP)
  605. stw r4, 16(SP)
  606. stw r5, 20(SP)
  607. stw r6, 24(SP)
  608. stw r7, 28(SP)
  609. stw r8, 32(SP)
  610. stw r9, 36(SP)
  611. stw r10, 40(SP)
  612. stfd f1, 48(SP)
  613. stfd f2, 56(SP)
  614. mr r3, r0
  615. bl Lmcount$stub
  616. nop
  617. lwz r3, 12(SP)
  618. lwz r4, 16(SP)
  619. lwz r5, 20(SP)
  620. lwz r6, 24(SP)
  621. lwz r7, 28(SP)
  622. lwz r8, 32(SP)
  623. lwz r9, 36(SP)
  624. lwz r10, 40(SP)
  625. lfd f1, 48(SP)
  626. lfd f2, 56(SP)
  627. addi SP, SP, 64
  628. lwz r0, 8(SP)
  629. mtlr r0
  630. .endmacro
  631. .macro EPILOGUE
  632. .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
  633. .align 5
  634. Lmcount$stub:
  635. .indirect_symbol mcount
  636. mflr r0
  637. bcl 20,31,L00000000001$spb
  638. L00000000001$spb:
  639. mflr r11
  640. addis r11,r11,ha16(Lmcount$lazy_ptr-L00000000001$spb)
  641. mtlr r0
  642. lwzu r12,lo16(Lmcount$lazy_ptr-L00000000001$spb)(r11)
  643. mtctr r12
  644. bctr
  645. .lazy_symbol_pointer
  646. Lmcount$lazy_ptr:
  647. .indirect_symbol mcount
  648. .long dyld_stub_binding_helper
  649. .subsections_via_symbols
  650. .endmacro
  651. #else
  652. .macro PROFCODE
  653. mflr r0
  654. std r0, 16(SP)
  655. addi SP, SP, -128
  656. std SP, 0(SP)
  657. std r3, 24(SP)
  658. std r4, 32(SP)
  659. std r5, 40(SP)
  660. std r6, 48(SP)
  661. std r7, 56(SP)
  662. std r8, 64(SP)
  663. std r9, 72(SP)
  664. std r10, 80(SP)
  665. stfd f1, 88(SP)
  666. stfd f2, 96(SP)
  667. mr r3, r0
  668. bl Lmcount$stub
  669. nop
  670. ld r3, 24(SP)
  671. ld r4, 32(SP)
  672. ld r5, 40(SP)
  673. ld r6, 48(SP)
  674. ld r7, 56(SP)
  675. ld r8, 64(SP)
  676. ld r9, 72(SP)
  677. ld r10, 80(SP)
  678. lfd f1, 88(SP)
  679. lfd f2, 86(SP)
  680. addi SP, SP, 128
  681. ld r0, 16(SP)
  682. mtlr r0
  683. .endmacro
  684. .macro EPILOGUE
  685. .data
  686. .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
  687. .align 5
  688. Lmcount$stub:
  689. .indirect_symbol mcount
  690. mflr r0
  691. bcl 20,31,L00000000001$spb
  692. L00000000001$spb:
  693. mflr r11
  694. addis r11,r11,ha16(Lmcount$lazy_ptr-L00000000001$spb)
  695. mtlr r0
  696. ld r12,lo16(Lmcount$lazy_ptr-L00000000001$spb)(r11)
  697. mtctr r12
  698. bctr
  699. .lazy_symbol_pointer
  700. Lmcount$lazy_ptr:
  701. .indirect_symbol mcount
  702. .quad dyld_stub_binding_helper
  703. .subsections_via_symbols
  704. .endmacro
  705. #endif
  706. #endif
  707. #endif
  708. #endif
  709. #endif
  710. #define HALT mfspr r0, 1023
  711. #ifdef OS_LINUX
  712. #if defined(PPC440) || defined(PPC440FP2)
  713. #undef MAX_CPU_NUMBER
  714. #define MAX_CPU_NUMBER 1
  715. #endif
  716. #if !defined(__64BIT__) && !defined(PROFILE) && !defined(PPC440) && !defined(PPC440FP2)
  717. #define START_ADDRESS (0x0b000000UL)
  718. #else
  719. #define SEEK_ADDRESS
  720. #endif
  721. #endif
  722. #ifdef OS_AIX
  723. #ifndef __64BIT__
  724. #define START_ADDRESS (0xf0000000UL)
  725. #else
  726. #define SEEK_ADDRESS
  727. #endif
  728. #endif
  729. #ifdef OS_DARWIN
  730. #define SEEK_ADDRESS
  731. #endif
  732. #if defined(PPC440)
  733. #define BUFFER_SIZE ( 2 << 20)
  734. #elif defined(PPC440FP2)
  735. #define BUFFER_SIZE ( 16 << 20)
  736. #elif defined(POWER8) || defined(POWER9)
  737. #define BUFFER_SIZE ( 64 << 20)
  738. #else
  739. #define BUFFER_SIZE ( 16 << 20)
  740. #endif
  741. #ifndef PAGESIZE
  742. #define PAGESIZE ( 4 << 10)
  743. #endif
  744. #define HUGE_PAGESIZE (16 << 20)
  745. #define BASE_ADDRESS (START_ADDRESS - BUFFER_SIZE * MAX_CPU_NUMBER)
  746. #ifndef MAP_ANONYMOUS
  747. #define MAP_ANONYMOUS MAP_ANON
  748. #endif
  749. #ifdef OS_LINUX
  750. #ifndef __64BIT__
  751. #define FRAMESLOT(X) (((X) * 4) + 8)
  752. #else
  753. #if _CALL_ELF == 2
  754. #define FRAMESLOT(X) (((X) * 8) + 96)
  755. #else
  756. #define FRAMESLOT(X) (((X) * 8) + 112)
  757. #endif
  758. #endif
  759. #endif
  760. #if defined(OS_AIX) || defined(OS_DARWIN)
  761. #ifndef __64BIT__
  762. #define FRAMESLOT(X) (((X) * 4) + 56)
  763. #else
  764. #define FRAMESLOT(X) (((X) * 8) + 112)
  765. #endif
  766. #endif
  767. #endif