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