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