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