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

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