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 18 kB

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