Debian Codegraph @

openmp/runtime/src/z_Linux_asm.S

raw
1 // z_Linux_asm.S: - microtasking routines specifically
2 // written for Intel platforms running Linux* OS
3
4 //
5 ////===----------------------------------------------------------------------===//
6 ////
7 //// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 //// See https://llvm.org/LICENSE.txt for license information.
9 //// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 ////
11 ////===----------------------------------------------------------------------===//
12 //
13
14 // -----------------------------------------------------------------------
15 // macros
16 // -----------------------------------------------------------------------
17
18 #include "kmp_config.h"
19
20 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
21 .att_syntax
22
23 # if defined(__ELF__) && defined(__CET__) && defined(__has_include)
24 # if __has_include(<cet.h>)
25 # include <cet.h>
26 # endif
27 # endif
28
29 # if !defined(_CET_ENDBR)
30 # define _CET_ENDBR
31 # endif
32
33 # if KMP_MIC
34 // the 'delay r16/r32/r64' should be used instead of the 'pause'.
35 // The delay operation has the effect of removing the current thread from
36 // the round-robin HT mechanism, and therefore speeds up the issue rate of
37 // the other threads on the same core.
38 //
39 // A value of 0 works fine for <= 2 threads per core, but causes the EPCC
40 // barrier time to increase greatly for 3 or more threads per core.
41 //
42 // A value of 100 works pretty well for up to 4 threads per core, but isn't
43 // quite as fast as 0 for 2 threads per core.
44 //
45 // We need to check what happens for oversubscription / > 4 threads per core.
46 // It is possible that we need to pass the delay value in as a parameter
47 // that the caller determines based on the total # threads / # cores.
48 //
49 //.macro pause_op
50 // mov $100, %rax
51 // delay %rax
52 //.endm
53 # else
54 # define pause_op .byte 0xf3,0x90
55 # endif // KMP_MIC
56
57 # if KMP_OS_DARWIN
58 # define KMP_PREFIX_UNDERSCORE(x) _##x // extra underscore for OS X* symbols
59 # define KMP_LABEL(x) L_##x // form the name of label
60 .macro KMP_CFI_DEF_OFFSET
61 .endmacro
62 .macro KMP_CFI_OFFSET
63 .endmacro
64 .macro KMP_CFI_REGISTER
65 .endmacro
66 .macro KMP_CFI_DEF
67 .endmacro
68 .macro ALIGN
69 .align $0
70 .endmacro
71 .macro DEBUG_INFO
72 /* Not sure what .size does in icc, not sure if we need to do something
73 similar for OS X*.
74 */
75 .endmacro
76 .macro PROC
77 ALIGN 4
78 .globl KMP_PREFIX_UNDERSCORE($0)
79 KMP_PREFIX_UNDERSCORE($0):
80 _CET_ENDBR
81 .endmacro
82 # else // KMP_OS_DARWIN
83 # define KMP_PREFIX_UNDERSCORE(x) x //no extra underscore for Linux* OS symbols
84 // Format labels so that they don't override function names in gdb's backtraces
85 // MIC assembler doesn't accept .L syntax, the L works fine there (as well as
86 // on OS X*)
87 # if KMP_MIC
88 # define KMP_LABEL(x) L_##x // local label
89 # else
90 # define KMP_LABEL(x) .L_##x // local label hidden from backtraces
91 # endif // KMP_MIC
92 .macro ALIGN size
93 .align 1<<(\size)
94 .endm
95 .macro DEBUG_INFO proc
96 .cfi_endproc
97 // Not sure why we need .type and .size for the functions
98 .align 16
99 .type \proc,@function
100 .size \proc,.-\proc
101 .endm
102 .macro PROC proc
103 ALIGN 4
104 .globl KMP_PREFIX_UNDERSCORE(\proc)
105 KMP_PREFIX_UNDERSCORE(\proc):
106 .cfi_startproc
107 _CET_ENDBR
108 .endm
109 .macro KMP_CFI_DEF_OFFSET sz
110 .cfi_def_cfa_offset \sz
111 .endm
112 .macro KMP_CFI_OFFSET reg, sz
113 .cfi_offset \reg,\sz
114 .endm
115 .macro KMP_CFI_REGISTER reg
116 .cfi_def_cfa_register \reg
117 .endm
118 .macro KMP_CFI_DEF reg, sz
119 .cfi_def_cfa \reg,\sz
120 .endm
121 # endif // KMP_OS_DARWIN
122 #endif // KMP_ARCH_X86 || KMP_ARCH_x86_64
123
124 #if KMP_ARCH_AARCH64 || KMP_ARCH_AARCH64_32 || KMP_ARCH_ARM
125
126 # if KMP_OS_DARWIN
127 # define KMP_PREFIX_UNDERSCORE(x) _##x // extra underscore for OS X* symbols
128 # define KMP_LABEL(x) L_##x // form the name of label
129
130 .macro ALIGN
131 .align $0
132 .endmacro
133
134 .macro DEBUG_INFO
135 /* Not sure what .size does in icc, not sure if we need to do something
136 similar for OS X*.
137 */
138 .endmacro
139
140 .macro PROC
141 ALIGN 4
142 .globl KMP_PREFIX_UNDERSCORE($0)
143 KMP_PREFIX_UNDERSCORE($0):
144 .endmacro
145 # elif KMP_OS_WINDOWS
146 # define KMP_PREFIX_UNDERSCORE(x) x // no extra underscore for Windows/ARM64 symbols
147 // Format labels so that they don't override function names in gdb's backtraces
148 # define KMP_LABEL(x) .L_##x // local label hidden from backtraces
149
150 .macro ALIGN size
151 .align 1<<(\size)
152 .endm
153
154 .macro DEBUG_INFO proc
155 ALIGN 2
156 .endm
157
158 .macro PROC proc
159 ALIGN 2
160 .globl KMP_PREFIX_UNDERSCORE(\proc)
161 KMP_PREFIX_UNDERSCORE(\proc):
162 .endm
163 # else // KMP_OS_DARWIN || KMP_OS_WINDOWS
164 # define KMP_PREFIX_UNDERSCORE(x) x // no extra underscore for Linux* OS symbols
165 // Format labels so that they don't override function names in gdb's backtraces
166 # define KMP_LABEL(x) .L_##x // local label hidden from backtraces
167
168 .macro ALIGN size
169 .align 1<<(\size)
170 .endm
171
172 .macro DEBUG_INFO proc
173 .cfi_endproc
174 // Not sure why we need .type and .size for the functions
175 ALIGN 2
176 #if KMP_ARCH_ARM
177 .type \proc,%function
178 #else
179 .type \proc,@function
180 #endif
181 .size \proc,.-\proc
182 .endm
183
184 .macro PROC proc
185 ALIGN 2
186 .globl KMP_PREFIX_UNDERSCORE(\proc)
187 KMP_PREFIX_UNDERSCORE(\proc):
188 .cfi_startproc
189 .endm
190 # endif // KMP_OS_DARWIN
191
192 # if KMP_OS_LINUX || KMP_OS_OPENBSD
193 // BTI and PAC gnu property note
194 # define NT_GNU_PROPERTY_TYPE_0 5
195 # define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000
196 # define GNU_PROPERTY_AARCH64_FEATURE_1_BTI 1
197 # define GNU_PROPERTY_AARCH64_FEATURE_1_PAC 2
198
199 # define GNU_PROPERTY(type, value) \
200 .pushsection .note.gnu.property, "a"; \
201 .p2align 3; \
202 .word 4; \
203 .word 16; \
204 .word NT_GNU_PROPERTY_TYPE_0; \
205 .asciz "GNU"; \
206 .word type; \
207 .word 4; \
208 .word value; \
209 .word 0; \
210 .popsection
211 # endif
212
213 # if defined(__ARM_FEATURE_BTI_DEFAULT)
214 # define BTI_FLAG GNU_PROPERTY_AARCH64_FEATURE_1_BTI
215 # else
216 # define BTI_FLAG 0
217 # endif
218 # if __ARM_FEATURE_PAC_DEFAULT & 3
219 # define PAC_FLAG GNU_PROPERTY_AARCH64_FEATURE_1_PAC
220 # else
221 # define PAC_FLAG 0
222 # endif
223
224 # if (BTI_FLAG | PAC_FLAG) != 0
225 # if PAC_FLAG != 0
226 # define PACBTI_C hint #25
227 # define PACBTI_RET hint #29
228 # else
229 # define PACBTI_C hint #34
230 # define PACBTI_RET
231 # endif
232 # define GNU_PROPERTY_BTI_PAC \
233 GNU_PROPERTY(GNU_PROPERTY_AARCH64_FEATURE_1_AND, BTI_FLAG | PAC_FLAG)
234 # else
235 # define PACBTI_C
236 # define PACBTI_RET
237 # define GNU_PROPERTY_BTI_PAC
238 # endif
239 #endif // KMP_ARCH_AARCH64 || KMP_ARCH_AARCH64_32 || KMP_ARCH_ARM
240
241 .macro COMMON name, size, align_power
242 #if KMP_OS_DARWIN
243 .comm \name, \size
244 #elif KMP_OS_WINDOWS
245 .comm \name, \size, \align_power
246 #else // !KMP_OS_DARWIN && !KMP_OS_WINDOWS
247 .comm \name, \size, (1<<(\align_power))
248 #endif
249 .endm
250
251 // -----------------------------------------------------------------------
252 // data
253 // -----------------------------------------------------------------------
254
255 #ifdef KMP_GOMP_COMPAT
256
257 // Support for unnamed common blocks.
258 //
259 // Because the symbol ".gomp_critical_user_" contains a ".", we have to
260 // put this stuff in assembly.
261
262 # if KMP_ARCH_X86
263 # if KMP_OS_DARWIN
264 .data
265 .comm .gomp_critical_user_,32
266 .data
267 .globl ___kmp_unnamed_critical_addr
268 ___kmp_unnamed_critical_addr:
269 .long .gomp_critical_user_
270 # else /* Linux* OS */
271 .data
272 .comm .gomp_critical_user_,32,8
273 .data
274 ALIGN 4
275 .global __kmp_unnamed_critical_addr
276 __kmp_unnamed_critical_addr:
277 .4byte .gomp_critical_user_
278 .type __kmp_unnamed_critical_addr,@object
279 .size __kmp_unnamed_critical_addr,4
280 # endif /* KMP_OS_DARWIN */
281 # endif /* KMP_ARCH_X86 */
282
283 # if KMP_ARCH_X86_64
284 # if KMP_OS_DARWIN
285 .data
286 .comm .gomp_critical_user_,32
287 .data
288 .globl ___kmp_unnamed_critical_addr
289 ___kmp_unnamed_critical_addr:
290 .quad .gomp_critical_user_
291 # else /* Linux* OS */
292 .data
293 .comm .gomp_critical_user_,32,8
294 .data
295 ALIGN 8
296 .global __kmp_unnamed_critical_addr
297 __kmp_unnamed_critical_addr:
298 .8byte .gomp_critical_user_
299 .type __kmp_unnamed_critical_addr,@object
300 .size __kmp_unnamed_critical_addr,8
301 # endif /* KMP_OS_DARWIN */
302 # endif /* KMP_ARCH_X86_64 */
303
304 #endif /* KMP_GOMP_COMPAT */
305
306
307 #if KMP_ARCH_X86 && !KMP_ARCH_PPC64
308
309 // -----------------------------------------------------------------------
310 // microtasking routines specifically written for IA-32 architecture
311 // running Linux* OS
312 // -----------------------------------------------------------------------
313
314 .ident "Intel Corporation"
315 .data
316 ALIGN 4
317 // void
318 // __kmp_x86_pause( void );
319
320 .text
321 PROC __kmp_x86_pause
322
323 pause_op
324 ret
325
326 DEBUG_INFO __kmp_x86_pause
327
328 # if !KMP_ASM_INTRINS
329
330 //------------------------------------------------------------------------
331 // kmp_int32
332 // __kmp_test_then_add32( volatile kmp_int32 *p, kmp_int32 d );
333
334 PROC __kmp_test_then_add32
335
336 movl 4(%esp), %ecx
337 movl 8(%esp), %eax
338 lock
339 xaddl %eax,(%ecx)
340 ret
341
342 DEBUG_INFO __kmp_test_then_add32
343
344 //------------------------------------------------------------------------
345 // FUNCTION __kmp_xchg_fixed8
346 //
347 // kmp_int32
348 // __kmp_xchg_fixed8( volatile kmp_int8 *p, kmp_int8 d );
349 //
350 // parameters:
351 // p: 4(%esp)
352 // d: 8(%esp)
353 //
354 // return: %al
355 PROC __kmp_xchg_fixed8
356
357 movl 4(%esp), %ecx // "p"
358 movb 8(%esp), %al // "d"
359
360 lock
361 xchgb %al,(%ecx)
362 ret
363
364 DEBUG_INFO __kmp_xchg_fixed8
365
366
367 //------------------------------------------------------------------------
368 // FUNCTION __kmp_xchg_fixed16
369 //
370 // kmp_int16
371 // __kmp_xchg_fixed16( volatile kmp_int16 *p, kmp_int16 d );
372 //
373 // parameters:
374 // p: 4(%esp)
375 // d: 8(%esp)
376 // return: %ax
377 PROC __kmp_xchg_fixed16
378
379 movl 4(%esp), %ecx // "p"
380 movw 8(%esp), %ax // "d"
381
382 lock
383 xchgw %ax,(%ecx)
384 ret
385
386 DEBUG_INFO __kmp_xchg_fixed16
387
388
389 //------------------------------------------------------------------------
390 // FUNCTION __kmp_xchg_fixed32
391 //
392 // kmp_int32
393 // __kmp_xchg_fixed32( volatile kmp_int32 *p, kmp_int32 d );
394 //
395 // parameters:
396 // p: 4(%esp)
397 // d: 8(%esp)
398 //
399 // return: %eax
400 PROC __kmp_xchg_fixed32
401
402 movl 4(%esp), %ecx // "p"
403 movl 8(%esp), %eax // "d"
404
405 lock
406 xchgl %eax,(%ecx)
407 ret
408
409 DEBUG_INFO __kmp_xchg_fixed32
410
411
412 // kmp_int8
413 // __kmp_compare_and_store8( volatile kmp_int8 *p, kmp_int8 cv, kmp_int8 sv );
414 PROC __kmp_compare_and_store8
415
416 movl 4(%esp), %ecx
417 movb 8(%esp), %al
418 movb 12(%esp), %dl
419 lock
420 cmpxchgb %dl,(%ecx)
421 sete %al // if %al == (%ecx) set %al = 1 else set %al = 0
422 and $1, %eax // sign extend previous instruction
423 ret
424
425 DEBUG_INFO __kmp_compare_and_store8
426
427 // kmp_int16
428 // __kmp_compare_and_store16(volatile kmp_int16 *p, kmp_int16 cv, kmp_int16 sv);
429 PROC __kmp_compare_and_store16
430
431 movl 4(%esp), %ecx
432 movw 8(%esp), %ax
433 movw 12(%esp), %dx
434 lock
435 cmpxchgw %dx,(%ecx)
436 sete %al // if %ax == (%ecx) set %al = 1 else set %al = 0
437 and $1, %eax // sign extend previous instruction
438 ret
439
440 DEBUG_INFO __kmp_compare_and_store16
441
442 // kmp_int32
443 // __kmp_compare_and_store32(volatile kmp_int32 *p, kmp_int32 cv, kmp_int32 sv);
444 PROC __kmp_compare_and_store32
445
446 movl 4(%esp), %ecx
447 movl 8(%esp), %eax
448 movl 12(%esp), %edx
449 lock
450 cmpxchgl %edx,(%ecx)
451 sete %al // if %eax == (%ecx) set %al = 1 else set %al = 0
452 and $1, %eax // sign extend previous instruction
453 ret
454
455 DEBUG_INFO __kmp_compare_and_store32
456
457 // kmp_int32
458 // __kmp_compare_and_store64(volatile kmp_int64 *p, kmp_int64 cv, kmp_int64 s );
459 PROC __kmp_compare_and_store64
460
461 pushl %ebp
462 movl %esp, %ebp
463 pushl %ebx
464 pushl %edi
465 movl 8(%ebp), %edi
466 movl 12(%ebp), %eax // "cv" low order word
467 movl 16(%ebp), %edx // "cv" high order word
468 movl 20(%ebp), %ebx // "sv" low order word
469 movl 24(%ebp), %ecx // "sv" high order word
470 lock
471 cmpxchg8b (%edi)
472 sete %al // if %edx:eax == (%edi) set %al = 1 else set %al = 0
473 and $1, %eax // sign extend previous instruction
474 popl %edi
475 popl %ebx
476 movl %ebp, %esp
477 popl %ebp
478 ret
479
480 DEBUG_INFO __kmp_compare_and_store64
481
482 // kmp_int8
483 // __kmp_compare_and_store_ret8(volatile kmp_int8 *p, kmp_int8 cv, kmp_int8 sv);
484 PROC __kmp_compare_and_store_ret8
485
486 movl 4(%esp), %ecx
487 movb 8(%esp), %al
488 movb 12(%esp), %dl
489 lock
490 cmpxchgb %dl,(%ecx)
491 ret
492
493 DEBUG_INFO __kmp_compare_and_store_ret8
494
495 // kmp_int16
496 // __kmp_compare_and_store_ret16(volatile kmp_int16 *p, kmp_int16 cv,
497 // kmp_int16 sv);
498 PROC __kmp_compare_and_store_ret16
499
500 movl 4(%esp), %ecx
501 movw 8(%esp), %ax
502 movw 12(%esp), %dx
503 lock
504 cmpxchgw %dx,(%ecx)
505 ret
506
507 DEBUG_INFO __kmp_compare_and_store_ret16
508
509 // kmp_int32
510 // __kmp_compare_and_store_ret32(volatile kmp_int32 *p, kmp_int32 cv,
511 // kmp_int32 sv);
512 PROC __kmp_compare_and_store_ret32
513
514 movl 4(%esp), %ecx
515 movl 8(%esp), %eax
516 movl 12(%esp), %edx
517 lock
518 cmpxchgl %edx,(%ecx)
519 ret
520
521 DEBUG_INFO __kmp_compare_and_store_ret32
522
523 // kmp_int64
524 // __kmp_compare_and_store_ret64(volatile kmp_int64 *p, kmp_int64 cv,
525 // kmp_int64 sv);
526 PROC __kmp_compare_and_store_ret64
527
528 pushl %ebp
529 movl %esp, %ebp
530 pushl %ebx
531 pushl %edi
532 movl 8(%ebp), %edi
533 movl 12(%ebp), %eax // "cv" low order word
534 movl 16(%ebp), %edx // "cv" high order word
535 movl 20(%ebp), %ebx // "sv" low order word
536 movl 24(%ebp), %ecx // "sv" high order word
537 lock
538 cmpxchg8b (%edi)
539 popl %edi
540 popl %ebx
541 movl %ebp, %esp
542 popl %ebp
543 ret
544
545 DEBUG_INFO __kmp_compare_and_store_ret64
546
547
548 //------------------------------------------------------------------------
549 // FUNCTION __kmp_xchg_real32
550 //
551 // kmp_real32
552 // __kmp_xchg_real32( volatile kmp_real32 *addr, kmp_real32 data );
553 //
554 // parameters:
555 // addr: 4(%esp)
556 // data: 8(%esp)
557 //
558 // return: %eax
559 PROC __kmp_xchg_real32
560
561 pushl %ebp
562 movl %esp, %ebp
563 subl $4, %esp
564 pushl %esi
565
566 movl 4(%ebp), %esi
567 flds (%esi)
568 // load <addr>
569 fsts -4(%ebp)
570 // store old value
571
572 movl 8(%ebp), %eax
573
574 lock
575 xchgl %eax, (%esi)
576
577 flds -4(%ebp)
578 // return old value
579
580 popl %esi
581 movl %ebp, %esp
582 popl %ebp
583 ret
584
585 DEBUG_INFO __kmp_xchg_real32
586
587 # endif /* !KMP_ASM_INTRINS */
588
589 //------------------------------------------------------------------------
590 // int
591 // __kmp_invoke_microtask( void (*pkfn) (int gtid, int tid, ...),
592 // int gtid, int tid,
593 // int argc, void *p_argv[]
594 // #if OMPT_SUPPORT
595 // ,
596 // void **exit_frame_ptr
597 // #endif
598 // ) {
599 // #if OMPT_SUPPORT
600 // *exit_frame_ptr = OMPT_GET_FRAME_ADDRESS(0);
601 // #endif
602 //
603 // (*pkfn)( & gtid, & tid, argv[0], ... );
604 // return 1;
605 // }
606
607 // -- Begin __kmp_invoke_microtask
608 // mark_begin;
609 PROC __kmp_invoke_microtask
610
611 pushl %ebp
612 KMP_CFI_DEF_OFFSET 8
613 KMP_CFI_OFFSET ebp,-8
614 movl %esp,%ebp // establish the base pointer for this routine.
615 KMP_CFI_REGISTER ebp
616 subl $8,%esp // allocate space for two local variables.
617 // These varibales are:
618 // argv: -4(%ebp)
619 // temp: -8(%ebp)
620 //
621 pushl %ebx // save %ebx to use during this routine
622 //
623 #if OMPT_SUPPORT
624 movl 28(%ebp),%ebx // get exit_frame address
625 movl %ebp,(%ebx) // save exit_frame
626 #endif
627
628 movl 20(%ebp),%ebx // Stack alignment - # args
629 addl $2,%ebx // #args +2 Always pass at least 2 args (gtid and tid)
630 shll $2,%ebx // Number of bytes used on stack: (#args+2)*4
631 movl %esp,%eax //
632 subl %ebx,%eax // %esp-((#args+2)*4) -> %eax -- without mods, stack ptr would be this
633 movl %eax,%ebx // Save to %ebx
634 andl $0xFFFFFF80,%eax // mask off 7 bits
635 subl %eax,%ebx // Amount to subtract from %esp
636 subl %ebx,%esp // Prepare the stack ptr --
637 // now it will be aligned on 128-byte boundary at the call
638
639 movl 24(%ebp),%eax // copy from p_argv[]
640 movl %eax,-4(%ebp) // into the local variable *argv.
641
642 movl 20(%ebp),%ebx // argc is 20(%ebp)
643 shll $2,%ebx
644
645 KMP_LABEL(invoke_2):
646 cmpl $0,%ebx
647 jg KMP_LABEL(invoke_4)
648 jmp KMP_LABEL(invoke_3)
649 ALIGN 2
650 KMP_LABEL(invoke_4):
651 movl -4(%ebp),%eax
652 subl $4,%ebx // decrement argc.
653 addl %ebx,%eax // index into argv.
654 movl (%eax),%edx
655 pushl %edx
656
657 jmp KMP_LABEL(invoke_2)
658 ALIGN 2
659 KMP_LABEL(invoke_3):
660 leal 16(%ebp),%eax // push & tid
661 pushl %eax
662
663 leal 12(%ebp),%eax // push & gtid
664 pushl %eax
665
666 movl 8(%ebp),%ebx
667 call *%ebx // call (*pkfn)();
668
669 movl $1,%eax // return 1;
670
671 movl -12(%ebp),%ebx // restore %ebx
672 leave
673 KMP_CFI_DEF esp,4
674 ret
675
676 DEBUG_INFO __kmp_invoke_microtask
677 // -- End __kmp_invoke_microtask
678
679
680 // kmp_uint64
681 // __kmp_hardware_timestamp(void)
682 PROC __kmp_hardware_timestamp
683 rdtsc
684 ret
685
686 DEBUG_INFO __kmp_hardware_timestamp
687 // -- End __kmp_hardware_timestamp
688
689 #endif /* KMP_ARCH_X86 */
690
691
692 #if KMP_ARCH_X86_64
693
694 // -----------------------------------------------------------------------
695 // microtasking routines specifically written for IA-32 architecture and
696 // Intel(R) 64 running Linux* OS
697 // -----------------------------------------------------------------------
698
699 // -- Machine type P
700 // mark_description "Intel Corporation";
701 .ident "Intel Corporation"
702 // -- .file "z_Linux_asm.S"
703 .data
704 ALIGN 4
705
706 // To prevent getting our code into .data section .text added to every routine
707 // definition for x86_64.
708 //------------------------------------------------------------------------
709 # if !KMP_ASM_INTRINS
710
711 //------------------------------------------------------------------------
712 // FUNCTION __kmp_test_then_add32
713 //
714 // kmp_int32
715 // __kmp_test_then_add32( volatile kmp_int32 *p, kmp_int32 d );
716 //
717 // parameters:
718 // p: %rdi
719 // d: %esi
720 //
721 // return: %eax
722 .text
723 PROC __kmp_test_then_add32
724
725 movl %esi, %eax // "d"
726 lock
727 xaddl %eax,(%rdi)
728 ret
729
730 DEBUG_INFO __kmp_test_then_add32
731
732
733 //------------------------------------------------------------------------
734 // FUNCTION __kmp_test_then_add64
735 //
736 // kmp_int64
737 // __kmp_test_then_add64( volatile kmp_int64 *p, kmp_int64 d );
738 //
739 // parameters:
740 // p: %rdi
741 // d: %rsi
742 // return: %rax
743 .text
744 PROC __kmp_test_then_add64
745
746 movq %rsi, %rax // "d"
747 lock
748 xaddq %rax,(%rdi)
749 ret
750
751 DEBUG_INFO __kmp_test_then_add64
752
753
754 //------------------------------------------------------------------------
755 // FUNCTION __kmp_xchg_fixed8
756 //
757 // kmp_int32
758 // __kmp_xchg_fixed8( volatile kmp_int8 *p, kmp_int8 d );
759 //
760 // parameters:
761 // p: %rdi
762 // d: %sil
763 //
764 // return: %al
765 .text
766 PROC __kmp_xchg_fixed8
767
768 movb %sil, %al // "d"
769
770 lock
771 xchgb %al,(%rdi)
772 ret
773
774 DEBUG_INFO __kmp_xchg_fixed8
775
776
777 //------------------------------------------------------------------------
778 // FUNCTION __kmp_xchg_fixed16
779 //
780 // kmp_int16
781 // __kmp_xchg_fixed16( volatile kmp_int16 *p, kmp_int16 d );
782 //
783 // parameters:
784 // p: %rdi
785 // d: %si
786 // return: %ax
787 .text
788 PROC __kmp_xchg_fixed16
789
790 movw %si, %ax // "d"
791
792 lock
793 xchgw %ax,(%rdi)
794 ret
795
796 DEBUG_INFO __kmp_xchg_fixed16
797
798
799 //------------------------------------------------------------------------
800 // FUNCTION __kmp_xchg_fixed32
801 //
802 // kmp_int32
803 // __kmp_xchg_fixed32( volatile kmp_int32 *p, kmp_int32 d );
804 //
805 // parameters:
806 // p: %rdi
807 // d: %esi
808 //
809 // return: %eax
810 .text
811 PROC __kmp_xchg_fixed32
812
813 movl %esi, %eax // "d"
814
815 lock
816 xchgl %eax,(%rdi)
817 ret
818
819 DEBUG_INFO __kmp_xchg_fixed32
820
821
822 //------------------------------------------------------------------------
823 // FUNCTION __kmp_xchg_fixed64
824 //
825 // kmp_int64
826 // __kmp_xchg_fixed64( volatile kmp_int64 *p, kmp_int64 d );
827 //
828 // parameters:
829 // p: %rdi
830 // d: %rsi
831 // return: %rax
832 .text
833 PROC __kmp_xchg_fixed64
834
835 movq %rsi, %rax // "d"
836
837 lock
838 xchgq %rax,(%rdi)
839 ret
840
841 DEBUG_INFO __kmp_xchg_fixed64
842
843
844 //------------------------------------------------------------------------
845 // FUNCTION __kmp_compare_and_store8
846 //
847 // kmp_int8
848 // __kmp_compare_and_store8( volatile kmp_int8 *p, kmp_int8 cv, kmp_int8 sv );
849 //
850 // parameters:
851 // p: %rdi
852 // cv: %esi
853 // sv: %edx
854 //
855 // return: %eax
856 .text
857 PROC __kmp_compare_and_store8
858
859 movb %sil, %al // "cv"
860 lock
861 cmpxchgb %dl,(%rdi)
862 sete %al // if %al == (%rdi) set %al = 1 else set %al = 0
863 andq $1, %rax // sign extend previous instruction for return value
864 ret
865
866 DEBUG_INFO __kmp_compare_and_store8
867
868
869 //------------------------------------------------------------------------
870 // FUNCTION __kmp_compare_and_store16
871 //
872 // kmp_int16
873 // __kmp_compare_and_store16( volatile kmp_int16 *p, kmp_int16 cv, kmp_int16 sv );
874 //
875 // parameters:
876 // p: %rdi
877 // cv: %si
878 // sv: %dx
879 //
880 // return: %eax
881 .text
882 PROC __kmp_compare_and_store16
883
884 movw %si, %ax // "cv"
885 lock
886 cmpxchgw %dx,(%rdi)
887 sete %al // if %ax == (%rdi) set %al = 1 else set %al = 0
888 andq $1, %rax // sign extend previous instruction for return value
889 ret
890
891 DEBUG_INFO __kmp_compare_and_store16
892
893
894 //------------------------------------------------------------------------
895 // FUNCTION __kmp_compare_and_store32
896 //
897 // kmp_int32
898 // __kmp_compare_and_store32( volatile kmp_int32 *p, kmp_int32 cv, kmp_int32 sv );
899 //
900 // parameters:
901 // p: %rdi
902 // cv: %esi
903 // sv: %edx
904 //
905 // return: %eax
906 .text
907 PROC __kmp_compare_and_store32
908
909 movl %esi, %eax // "cv"
910 lock
911 cmpxchgl %edx,(%rdi)
912 sete %al // if %eax == (%rdi) set %al = 1 else set %al = 0
913 andq $1, %rax // sign extend previous instruction for return value
914 ret
915
916 DEBUG_INFO __kmp_compare_and_store32
917
918
919 //------------------------------------------------------------------------
920 // FUNCTION __kmp_compare_and_store64
921 //
922 // kmp_int32
923 // __kmp_compare_and_store64( volatile kmp_int64 *p, kmp_int64 cv, kmp_int64 sv );
924 //
925 // parameters:
926 // p: %rdi
927 // cv: %rsi
928 // sv: %rdx
929 // return: %eax
930 .text
931 PROC __kmp_compare_and_store64
932
933 movq %rsi, %rax // "cv"
934 lock
935 cmpxchgq %rdx,(%rdi)
936 sete %al // if %rax == (%rdi) set %al = 1 else set %al = 0
937 andq $1, %rax // sign extend previous instruction for return value
938 ret
939
940 DEBUG_INFO __kmp_compare_and_store64
941
942 //------------------------------------------------------------------------
943 // FUNCTION __kmp_compare_and_store_ret8
944 //
945 // kmp_int8
946 // __kmp_compare_and_store_ret8( volatile kmp_int8 *p, kmp_int8 cv, kmp_int8 sv );
947 //
948 // parameters:
949 // p: %rdi
950 // cv: %esi
951 // sv: %edx
952 //
953 // return: %eax
954 .text
955 PROC __kmp_compare_and_store_ret8
956
957 movb %sil, %al // "cv"
958 lock
959 cmpxchgb %dl,(%rdi)
960 ret
961
962 DEBUG_INFO __kmp_compare_and_store_ret8
963
964
965 //------------------------------------------------------------------------
966 // FUNCTION __kmp_compare_and_store_ret16
967 //
968 // kmp_int16
969 // __kmp_compare_and_store16_ret( volatile kmp_int16 *p, kmp_int16 cv, kmp_int16 sv );
970 //
971 // parameters:
972 // p: %rdi
973 // cv: %si
974 // sv: %dx
975 //
976 // return: %eax
977 .text
978 PROC __kmp_compare_and_store_ret16
979
980 movw %si, %ax // "cv"
981 lock
982 cmpxchgw %dx,(%rdi)
983 ret
984
985 DEBUG_INFO __kmp_compare_and_store_ret16
986
987
988 //------------------------------------------------------------------------
989 // FUNCTION __kmp_compare_and_store_ret32
990 //
991 // kmp_int32
992 // __kmp_compare_and_store_ret32( volatile kmp_int32 *p, kmp_int32 cv, kmp_int32 sv );
993 //
994 // parameters:
995 // p: %rdi
996 // cv: %esi
997 // sv: %edx
998 //
999 // return: %eax
1000 .text
1001 PROC __kmp_compare_and_store_ret32
1002
1003 movl %esi, %eax // "cv"
1004 lock
1005 cmpxchgl %edx,(%rdi)
1006 ret
1007
1008 DEBUG_INFO __kmp_compare_and_store_ret32
1009
1010
1011 //------------------------------------------------------------------------
1012 // FUNCTION __kmp_compare_and_store_ret64
1013 //
1014 // kmp_int64
1015 // __kmp_compare_and_store_ret64( volatile kmp_int64 *p, kmp_int64 cv, kmp_int64 sv );
1016 //
1017 // parameters:
1018 // p: %rdi
1019 // cv: %rsi
1020 // sv: %rdx
1021 // return: %eax
1022 .text
1023 PROC __kmp_compare_and_store_ret64
1024
1025 movq %rsi, %rax // "cv"
1026 lock
1027 cmpxchgq %rdx,(%rdi)
1028 ret
1029
1030 DEBUG_INFO __kmp_compare_and_store_ret64
1031
1032 # endif /* !KMP_ASM_INTRINS */
1033
1034
1035 # if !KMP_MIC
1036
1037 # if !KMP_ASM_INTRINS
1038
1039 //------------------------------------------------------------------------
1040 // FUNCTION __kmp_xchg_real32
1041 //
1042 // kmp_real32
1043 // __kmp_xchg_real32( volatile kmp_real32 *addr, kmp_real32 data );
1044 //
1045 // parameters:
1046 // addr: %rdi
1047 // data: %xmm0 (lower 4 bytes)
1048 //
1049 // return: %xmm0 (lower 4 bytes)
1050 .text
1051 PROC __kmp_xchg_real32
1052
1053 movd %xmm0, %eax // load "data" to eax
1054
1055 lock
1056 xchgl %eax, (%rdi)
1057
1058 movd %eax, %xmm0 // load old value into return register
1059
1060 ret
1061
1062 DEBUG_INFO __kmp_xchg_real32
1063
1064
1065 //------------------------------------------------------------------------
1066 // FUNCTION __kmp_xchg_real64
1067 //
1068 // kmp_real64
1069 // __kmp_xchg_real64( volatile kmp_real64 *addr, kmp_real64 data );
1070 //
1071 // parameters:
1072 // addr: %rdi
1073 // data: %xmm0 (lower 8 bytes)
1074 // return: %xmm0 (lower 8 bytes)
1075 .text
1076 PROC __kmp_xchg_real64
1077
1078 movd %xmm0, %rax // load "data" to rax
1079
1080 lock
1081 xchgq %rax, (%rdi)
1082
1083 movd %rax, %xmm0 // load old value into return register
1084 ret
1085
1086 DEBUG_INFO __kmp_xchg_real64
1087
1088
1089 # endif /* !KMP_MIC */
1090
1091 # endif /* !KMP_ASM_INTRINS */
1092
1093 //------------------------------------------------------------------------
1094 // int
1095 // __kmp_invoke_microtask( void (*pkfn) (int gtid, int tid, ...),
1096 // int gtid, int tid,
1097 // int argc, void *p_argv[]
1098 // #if OMPT_SUPPORT
1099 // ,
1100 // void **exit_frame_ptr
1101 // #endif
1102 // ) {
1103 // #if OMPT_SUPPORT
1104 // *exit_frame_ptr = OMPT_GET_FRAME_ADDRESS(0);
1105 // #endif
1106 //
1107 // (*pkfn)( & gtid, & tid, argv[0], ... );
1108 // return 1;
1109 // }
1110 //
1111 // note: at call to pkfn must have %rsp 128-byte aligned for compiler
1112 //
1113 // parameters:
1114 // %rdi: pkfn
1115 // %esi: gtid
1116 // %edx: tid
1117 // %ecx: argc
1118 // %r8: p_argv
1119 // %r9: &exit_frame
1120 //
1121 // locals:
1122 // __gtid: gtid parm pushed on stack so can pass &gtid to pkfn
1123 // __tid: tid parm pushed on stack so can pass &tid to pkfn
1124 //
1125 // reg temps:
1126 // %rax: used all over the place
1127 // %rdx: used in stack pointer alignment calculation
1128 // %r11: used to traverse p_argv array
1129 // %rsi: used as temporary for stack parameters
1130 // used as temporary for number of pkfn parms to push
1131 // %rbx: used to hold pkfn address, and zero constant, callee-save
1132 //
1133 // return: %eax (always 1/TRUE)
1134 __gtid = -16
1135 __tid = -24
1136
1137 // -- Begin __kmp_invoke_microtask
1138 // mark_begin;
1139 .text
1140 PROC __kmp_invoke_microtask
1141
1142 pushq %rbp // save base pointer
1143 KMP_CFI_DEF_OFFSET 16
1144 KMP_CFI_OFFSET rbp,-16
1145 movq %rsp,%rbp // establish the base pointer for this routine.
1146 KMP_CFI_REGISTER rbp
1147
1148 #if OMPT_SUPPORT
1149 movq %rbp, (%r9) // save exit_frame
1150 #endif
1151
1152 pushq %rbx // %rbx is callee-saved register
1153 pushq %rsi // Put gtid on stack so can pass &tgid to pkfn
1154 pushq %rdx // Put tid on stack so can pass &tid to pkfn
1155
1156 movq %rcx, %rax // Stack alignment calculation begins; argc -> %rax
1157 movq $0, %rbx // constant for cmovs later
1158 subq $4, %rax // subtract four args passed in registers to pkfn
1159 #if KMP_MIC
1160 js KMP_LABEL(kmp_0) // jump to movq
1161 jmp KMP_LABEL(kmp_0_exit) // jump ahead
1162 KMP_LABEL(kmp_0):
1163 movq %rbx, %rax // zero negative value in %rax <- max(0, argc-4)
1164 KMP_LABEL(kmp_0_exit):
1165 #else
1166 cmovsq %rbx, %rax // zero negative value in %rax <- max(0, argc-4)
1167 #endif // KMP_MIC
1168
1169 movq %rax, %rsi // save max(0, argc-4) -> %rsi for later
1170 shlq $3, %rax // Number of bytes used on stack: max(0, argc-4)*8
1171
1172 movq %rsp, %rdx //
1173 subq %rax, %rdx // %rsp-(max(0,argc-4)*8) -> %rdx --
1174 // without align, stack ptr would be this
1175 movq %rdx, %rax // Save to %rax
1176
1177 andq $0xFFFFFFFFFFFFFF80, %rax // mask off lower 7 bits (128 bytes align)
1178 subq %rax, %rdx // Amount to subtract from %rsp
1179 subq %rdx, %rsp // Prepare the stack ptr --
1180 // now %rsp will align to 128-byte boundary at call site
1181
1182 // setup pkfn parameter reg and stack
1183 movq %rcx, %rax // argc -> %rax
1184 cmpq $0, %rsi
1185 je KMP_LABEL(kmp_invoke_pass_parms) // jump ahead if no parms to push
1186 shlq $3, %rcx // argc*8 -> %rcx
1187 movq %r8, %rdx // p_argv -> %rdx
1188 addq %rcx, %rdx // &p_argv[argc] -> %rdx
1189
1190 movq %rsi, %rcx // max (0, argc-4) -> %rcx
1191
1192 KMP_LABEL(kmp_invoke_push_parms):
1193 // push nth - 7th parms to pkfn on stack
1194 subq $8, %rdx // decrement p_argv pointer to previous parm
1195 movq (%rdx), %rsi // p_argv[%rcx-1] -> %rsi
1196 pushq %rsi // push p_argv[%rcx-1] onto stack (reverse order)
1197 subl $1, %ecx
1198
1199 // C69570: "X86_64_RELOC_BRANCH not supported" error at linking on mac_32e
1200 // if the name of the label that is an operand of this jecxz starts with a dot (".");
1201 // Apple's linker does not support 1-byte length relocation;
1202 // Resolution: replace all .labelX entries with L_labelX.
1203
1204 jecxz KMP_LABEL(kmp_invoke_pass_parms) // stop when four p_argv[] parms left
1205 jmp KMP_LABEL(kmp_invoke_push_parms)
1206 ALIGN 3
1207 KMP_LABEL(kmp_invoke_pass_parms): // put 1st - 6th parms to pkfn in registers.
1208 // order here is important to avoid trashing
1209 // registers used for both input and output parms!
1210 movq %rdi, %rbx // pkfn -> %rbx
1211 leaq __gtid(%rbp), %rdi // &gtid -> %rdi (store 1st parm to pkfn)
1212 leaq __tid(%rbp), %rsi // &tid -> %rsi (store 2nd parm to pkfn)
1213 // Check if argc is 0
1214 cmpq $0, %rax
1215 je KMP_LABEL(kmp_no_args) // Jump ahead
1216
1217 movq %r8, %r11 // p_argv -> %r11
1218
1219 #if KMP_MIC
1220 cmpq $4, %rax // argc >= 4?
1221 jns KMP_LABEL(kmp_4) // jump to movq
1222 jmp KMP_LABEL(kmp_4_exit) // jump ahead
1223 KMP_LABEL(kmp_4):
1224 movq 24(%r11), %r9 // p_argv[3] -> %r9 (store 6th parm to pkfn)
1225 KMP_LABEL(kmp_4_exit):
1226
1227 cmpq $3, %rax // argc >= 3?
1228 jns KMP_LABEL(kmp_3) // jump to movq
1229 jmp KMP_LABEL(kmp_3_exit) // jump ahead
1230 KMP_LABEL(kmp_3):
1231 movq 16(%r11), %r8 // p_argv[2] -> %r8 (store 5th parm to pkfn)
1232 KMP_LABEL(kmp_3_exit):
1233
1234 cmpq $2, %rax // argc >= 2?
1235 jns KMP_LABEL(kmp_2) // jump to movq
1236 jmp KMP_LABEL(kmp_2_exit) // jump ahead
1237 KMP_LABEL(kmp_2):
1238 movq 8(%r11), %rcx // p_argv[1] -> %rcx (store 4th parm to pkfn)
1239 KMP_LABEL(kmp_2_exit):
1240
1241 cmpq $1, %rax // argc >= 1?
1242 jns KMP_LABEL(kmp_1) // jump to movq
1243 jmp KMP_LABEL(kmp_1_exit) // jump ahead
1244 KMP_LABEL(kmp_1):
1245 movq (%r11), %rdx // p_argv[0] -> %rdx (store 3rd parm to pkfn)
1246 KMP_LABEL(kmp_1_exit):
1247 #else
1248 cmpq $4, %rax // argc >= 4?
1249 cmovnsq 24(%r11), %r9 // p_argv[3] -> %r9 (store 6th parm to pkfn)
1250
1251 cmpq $3, %rax // argc >= 3?
1252 cmovnsq 16(%r11), %r8 // p_argv[2] -> %r8 (store 5th parm to pkfn)
1253
1254 cmpq $2, %rax // argc >= 2?
1255 cmovnsq 8(%r11), %rcx // p_argv[1] -> %rcx (store 4th parm to pkfn)
1256
1257 cmpq $1, %rax // argc >= 1?
1258 cmovnsq (%r11), %rdx // p_argv[0] -> %rdx (store 3rd parm to pkfn)
1259 #endif // KMP_MIC
1260
1261 KMP_LABEL(kmp_no_args):
1262 call *%rbx // call (*pkfn)();
1263 movq $1, %rax // move 1 into return register;
1264
1265 movq -8(%rbp), %rbx // restore %rbx using %rbp since %rsp was modified
1266 movq %rbp, %rsp // restore stack pointer
1267 popq %rbp // restore frame pointer
1268 KMP_CFI_DEF rsp,8
1269 ret
1270
1271 DEBUG_INFO __kmp_invoke_microtask
1272 // -- End __kmp_invoke_microtask
1273
1274 // kmp_uint64
1275 // __kmp_hardware_timestamp(void)
1276 .text
1277 PROC __kmp_hardware_timestamp
1278 rdtsc
1279 shlq $32, %rdx
1280 orq %rdx, %rax
1281 ret
1282
1283 DEBUG_INFO __kmp_hardware_timestamp
1284 // -- End __kmp_hardware_timestamp
1285
1286 //------------------------------------------------------------------------
1287 // FUNCTION __kmp_bsr32
1288 //
1289 // int
1290 // __kmp_bsr32( int );
1291 .text
1292 PROC __kmp_bsr32
1293
1294 bsr %edi,%eax
1295 ret
1296
1297 DEBUG_INFO __kmp_bsr32
1298
1299 // -----------------------------------------------------------------------
1300 #endif /* KMP_ARCH_X86_64 */
1301
1302 // '
1303 #if KMP_ARCH_AARCH64 || KMP_ARCH_AARCH64_32
1304
1305 //------------------------------------------------------------------------
1306 // int
1307 // __kmp_invoke_microtask( void (*pkfn) (int gtid, int tid, ...),
1308 // int gtid, int tid,
1309 // int argc, void *p_argv[]
1310 // #if OMPT_SUPPORT
1311 // ,
1312 // void **exit_frame_ptr
1313 // #endif
1314 // ) {
1315 // #if OMPT_SUPPORT
1316 // *exit_frame_ptr = OMPT_GET_FRAME_ADDRESS(0);
1317 // #endif
1318 //
1319 // (*pkfn)( & gtid, & tid, argv[0], ... );
1320 //
1321 // // FIXME: This is done at call-site and can be removed here.
1322 // #if OMPT_SUPPORT
1323 // *exit_frame_ptr = 0;
1324 // #endif
1325 //
1326 // return 1;
1327 // }
1328 //
1329 // parameters:
1330 // x0: pkfn
1331 // w1: gtid
1332 // w2: tid
1333 // w3: argc
1334 // x4: p_argv
1335 // x5: &exit_frame
1336 //
1337 // locals:
1338 // __gtid: gtid parm pushed on stack so can pass &gtid to pkfn
1339 // __tid: tid parm pushed on stack so can pass &tid to pkfn
1340 //
1341 // reg temps:
1342 // x8: used to hold pkfn address
1343 // w9: used as temporary for number of pkfn parms
1344 // x10: used to traverse p_argv array
1345 // x11: used as temporary for stack placement calculation
1346 // x12: used as temporary for stack parameters
1347 // x19: used to preserve exit_frame_ptr, callee-save
1348 //
1349 // return: w0 (always 1/TRUE)
1350 //
1351
1352 __gtid = 4
1353 __tid = 8
1354
1355 // -- Begin __kmp_invoke_microtask
1356 // mark_begin;
1357 .text
1358 PROC __kmp_invoke_microtask
1359 PACBTI_C
1360
1361 # if OMPT_SUPPORT
1362 stp x19, x20, [sp, #-16]!
1363 # endif
1364 stp x29, x30, [sp, #-16]!
1365 mov x29, sp
1366
1367 orr w9, wzr, #1
1368 add w9, w9, w3, lsr #1
1369 sub sp, sp, w9, uxtw #4
1370 mov x11, sp
1371
1372 mov x8, x0
1373 str w1, [x29, #-__gtid]
1374 str w2, [x29, #-__tid]
1375 mov w9, w3
1376 mov x10, x4
1377 # if OMPT_SUPPORT
1378 mov x19, x5
1379 str x29, [x19]
1380 # endif
1381
1382 sub x0, x29, #__gtid
1383 sub x1, x29, #__tid
1384
1385 cbz w9, KMP_LABEL(kmp_1)
1386 ldr x2, [x10]
1387
1388 sub w9, w9, #1
1389 cbz w9, KMP_LABEL(kmp_1)
1390 ldr x3, [x10, #8]!
1391
1392 sub w9, w9, #1
1393 cbz w9, KMP_LABEL(kmp_1)
1394 ldr x4, [x10, #8]!
1395
1396 sub w9, w9, #1
1397 cbz w9, KMP_LABEL(kmp_1)
1398 ldr x5, [x10, #8]!
1399
1400 sub w9, w9, #1
1401 cbz w9, KMP_LABEL(kmp_1)
1402 ldr x6, [x10, #8]!
1403
1404 sub w9, w9, #1
1405 cbz w9, KMP_LABEL(kmp_1)
1406 ldr x7, [x10, #8]!
1407
1408 KMP_LABEL(kmp_0):
1409 sub w9, w9, #1
1410 cbz w9, KMP_LABEL(kmp_1)
1411 ldr x12, [x10, #8]!
1412 str x12, [x11], #8
1413 b KMP_LABEL(kmp_0)
1414 KMP_LABEL(kmp_1):
1415 blr x8
1416 orr w0, wzr, #1
1417 mov sp, x29
1418 ldp x29, x30, [sp], #16
1419 # if OMPT_SUPPORT
1420 str xzr, [x19]
1421 ldp x19, x20, [sp], #16
1422 # endif
1423 PACBTI_RET
1424 ret
1425
1426 DEBUG_INFO __kmp_invoke_microtask
1427 // -- End __kmp_invoke_microtask
1428
1429 #endif /* KMP_ARCH_AARCH64 || KMP_ARCH_AARCH64_32 */
1430
1431 #if KMP_ARCH_ARM
1432
1433 //------------------------------------------------------------------------
1434 // int
1435 // __kmp_invoke_microtask( void (*pkfn) (int gtid, int tid, ...),
1436 // int gtid, int tid,
1437 // int argc, void *p_argv[]
1438 // #if OMPT_SUPPORT
1439 // ,
1440 // void **exit_frame_ptr
1441 // #endif
1442 // ) {
1443 // #if OMPT_SUPPORT
1444 // *exit_frame_ptr = OMPT_GET_FRAME_ADDRESS(0);
1445 // #endif
1446 //
1447 // (*pkfn)( & gtid, & tid, argv[0], ... );
1448 //
1449 // // FIXME: This is done at call-site and can be removed here.
1450 // #if OMPT_SUPPORT
1451 // *exit_frame_ptr = 0;
1452 // #endif
1453 //
1454 // return 1;
1455 // }
1456 //
1457 // parameters:
1458 // r0: pkfn
1459 // r1: gtid
1460 // r2: tid
1461 // r3: argc
1462 // r4(stack): p_argv
1463 // r5(stack): &exit_frame
1464 //
1465 // locals:
1466 // __gtid: gtid parm pushed on stack so can pass &gtid to pkfn
1467 // __tid: tid parm pushed on stack so can pass &tid to pkfn
1468 //
1469 // reg temps:
1470 // r4: used to hold pkfn address
1471 // r5: used as temporary for number of pkfn parms
1472 // r6: used to traverse p_argv array
1473 // r7: frame pointer (in some configurations)
1474 // r8: used as temporary for stack placement calculation
1475 // and as pointer to base of callee saved area
1476 // r9: used as temporary for stack parameters
1477 // r10: used to preserve exit_frame_ptr, callee-save
1478 // r11: frame pointer (in some configurations)
1479 //
1480 // return: r0 (always 1/TRUE)
1481 //
1482
1483 __gtid = 4
1484 __tid = 8
1485
1486 // -- Begin __kmp_invoke_microtask
1487 // mark_begin;
1488 .text
1489 PROC __kmp_invoke_microtask
1490
1491 // Pushing one extra register (r3) to keep the stack aligned
1492 // for when we call pkfn below
1493 push {r3-r11,lr}
1494 // Load p_argv and &exit_frame
1495 ldr r4, [sp, #10*4]
1496 # if OMPT_SUPPORT
1497 ldr r5, [sp, #11*4]
1498 # endif
1499
1500 # if KMP_OS_DARWIN || (defined(__thumb__) && !KMP_OS_WINDOWS)
1501 # define FP r7
1502 # define FPOFF 4*4
1503 #else
1504 # define FP r11
1505 # define FPOFF 8*4
1506 #endif
1507 add FP, sp, #FPOFF
1508 # if OMPT_SUPPORT
1509 mov r10, r5
1510 str FP, [r10]
1511 # endif
1512 mov r8, sp
1513
1514 // Calculate how much stack to allocate, in increments of 8 bytes.
1515 // We strictly need 4*(argc-2) bytes (2 arguments are passed in
1516 // registers) but allocate 4*argc for simplicity (to avoid needing
1517 // to handle the argc<2 cases). We align the number of bytes
1518 // allocated to 8 bytes, to keep the stack aligned. (Since we
1519 // already allocate more than enough, it's ok to round down
1520 // instead of up for the alignment.) We allocate another extra
1521 // 8 bytes for gtid and tid.
1522 mov r5, #1
1523 add r5, r5, r3, lsr #1
1524 sub sp, sp, r5, lsl #3
1525
1526 str r1, [r8, #-__gtid]
1527 str r2, [r8, #-__tid]
1528 mov r5, r3
1529 mov r6, r4
1530 mov r4, r0
1531
1532 // Prepare the first 2 parameters to pkfn - pointers to gtid and tid
1533 // in our stack frame.
1534 sub r0, r8, #__gtid
1535 sub r1, r8, #__tid
1536
1537 mov r8, sp
1538
1539 // Load p_argv[0] and p_argv[1] into r2 and r3, if argc >= 1/2
1540 cmp r5, #0
1541 beq KMP_LABEL(kmp_1)
1542 ldr r2, [r6]
1543
1544 subs r5, r5, #1
1545 beq KMP_LABEL(kmp_1)
1546 ldr r3, [r6, #4]!
1547
1548 // Loop, loading the rest of p_argv and writing the elements on the
1549 // stack.
1550 KMP_LABEL(kmp_0):
1551 subs r5, r5, #1
1552 beq KMP_LABEL(kmp_1)
1553 ldr r12, [r6, #4]!
1554 str r12, [r8], #4
1555 b KMP_LABEL(kmp_0)
1556 KMP_LABEL(kmp_1):
1557 blx r4
1558 mov r0, #1
1559
1560 sub r4, FP, #FPOFF
1561 mov sp, r4
1562 # undef FP
1563 # undef FPOFF
1564
1565 # if OMPT_SUPPORT
1566 mov r1, #0
1567 str r1, [r10]
1568 # endif
1569 pop {r3-r11,pc}
1570
1571 DEBUG_INFO __kmp_invoke_microtask
1572 // -- End __kmp_invoke_microtask
1573
1574 #endif /* KMP_ARCH_ARM */
1575
1576 #if KMP_ARCH_PPC64
1577
1578 //------------------------------------------------------------------------
1579 // int
1580 // __kmp_invoke_microtask( void (*pkfn) (int gtid, int tid, ...),
1581 // int gtid, int tid,
1582 // int argc, void *p_argv[]
1583 // #if OMPT_SUPPORT
1584 // ,
1585 // void **exit_frame_ptr
1586 // #endif
1587 // ) {
1588 // #if OMPT_SUPPORT
1589 // *exit_frame_ptr = OMPT_GET_FRAME_ADDRESS(0);
1590 // #endif
1591 //
1592 // (*pkfn)( & gtid, & tid, argv[0], ... );
1593 //
1594 // // FIXME: This is done at call-site and can be removed here.
1595 // #if OMPT_SUPPORT
1596 // *exit_frame_ptr = 0;
1597 // #endif
1598 //
1599 // return 1;
1600 // }
1601 //
1602 // parameters:
1603 // r3: pkfn
1604 // r4: gtid
1605 // r5: tid
1606 // r6: argc
1607 // r7: p_argv
1608 // r8: &exit_frame
1609 //
1610 // return: r3 (always 1/TRUE)
1611 //
1612 .text
1613 # if KMP_ARCH_PPC64_ELFv2
1614 .abiversion 2
1615 # endif
1616 .globl __kmp_invoke_microtask
1617
1618 # if KMP_ARCH_PPC64_ELFv2
1619 .p2align 4
1620 # else
1621 .p2align 2
1622 # endif
1623
1624 .type __kmp_invoke_microtask,@function
1625
1626 # if KMP_ARCH_PPC64_ELFv2
1627 __kmp_invoke_microtask:
1628 .Lfunc_begin0:
1629 .Lfunc_gep0:
1630 addis 2, 12, .TOC.-.Lfunc_gep0@ha
1631 addi 2, 2, .TOC.-.Lfunc_gep0@l
1632 .Lfunc_lep0:
1633 .localentry __kmp_invoke_microtask, .Lfunc_lep0-.Lfunc_gep0
1634 # else
1635 .section .opd,"aw",@progbits
1636 __kmp_invoke_microtask:
1637 .p2align 3
1638 .quad .Lfunc_begin0
1639 .quad .TOC.@tocbase
1640 .quad 0
1641 .text
1642 .Lfunc_begin0:
1643 # endif
1644
1645 // -- Begin __kmp_invoke_microtask
1646 // mark_begin;
1647
1648 // We need to allocate a stack frame large enough to hold all of the parameters
1649 // on the stack for the microtask plus what this function needs. That's 48
1650 // bytes under the ELFv1 ABI (32 bytes under ELFv2), plus 8*(2 + argc) for the
1651 // parameters to the microtask, plus 8 bytes to store the values of r4 and r5,
1652 // and 8 bytes to store r31. With OMP-T support, we need an additional 8 bytes
1653 // to save r30 to hold a copy of r8.
1654
1655 .cfi_startproc
1656 mflr 0
1657 std 31, -8(1)
1658 std 0, 16(1)
1659
1660 // This is unusual because normally we'd set r31 equal to r1 after the stack
1661 // frame is established. In this case, however, we need to dynamically compute
1662 // the stack frame size, and so we keep a direct copy of r1 to access our
1663 // register save areas and restore the r1 value before returning.
1664 mr 31, 1
1665 .cfi_def_cfa_register r31
1666 .cfi_offset r31, -8
1667 .cfi_offset lr, 16
1668
1669 // Compute the size necessary for the local stack frame.
1670 # if KMP_ARCH_PPC64_ELFv2
1671 li 12, 72
1672 # else
1673 li 12, 88
1674 # endif
1675 sldi 0, 6, 3
1676 add 12, 0, 12
1677 neg 12, 12
1678
1679 // We need to make sure that the stack frame stays aligned (to 16 bytes).
1680 li 0, -16
1681 and 12, 0, 12
1682
1683 // Establish the local stack frame.
1684 stdux 1, 1, 12
1685
1686 # if OMPT_SUPPORT
1687 .cfi_offset r30, -16
1688 std 30, -16(31)
1689 std 1, 0(8)
1690 mr 30, 8
1691 # endif
1692
1693 // Store gtid and tid to the stack because they're passed by reference to the microtask.
1694 stw 4, -20(31)
1695 stw 5, -24(31)
1696
1697 mr 12, 6
1698 mr 4, 7
1699
1700 cmpwi 0, 12, 1
1701 blt 0, .Lcall
1702
1703 ld 5, 0(4)
1704
1705 cmpwi 0, 12, 2
1706 blt 0, .Lcall
1707
1708 ld 6, 8(4)
1709
1710 cmpwi 0, 12, 3
1711 blt 0, .Lcall
1712
1713 ld 7, 16(4)
1714
1715 cmpwi 0, 12, 4
1716 blt 0, .Lcall
1717
1718 ld 8, 24(4)
1719
1720 cmpwi 0, 12, 5
1721 blt 0, .Lcall
1722
1723 ld 9, 32(4)
1724
1725 cmpwi 0, 12, 6
1726 blt 0, .Lcall
1727
1728 ld 10, 40(4)
1729
1730 cmpwi 0, 12, 7
1731 blt 0, .Lcall
1732
1733 // There are more than 6 microtask parameters, so we need to store the
1734 // remainder to the stack.
1735 addi 12, 12, -6
1736 mtctr 12
1737
1738 // These are set to 8 bytes before the first desired store address (we're using
1739 // pre-increment loads and stores in the loop below). The parameter save area
1740 // for the microtask begins 48 + 8*8 == 112 bytes above r1 for ELFv1 and
1741 // 32 + 8*8 == 96 bytes above r1 for ELFv2.
1742 addi 4, 4, 40
1743 # if KMP_ARCH_PPC64_ELFv2
1744 addi 12, 1, 88
1745 # else
1746 addi 12, 1, 104
1747 # endif
1748
1749 .Lnext:
1750 ldu 0, 8(4)
1751 stdu 0, 8(12)
1752 bdnz .Lnext
1753
1754 .Lcall:
1755 # if KMP_ARCH_PPC64_ELFv2
1756 std 2, 24(1)
1757 mr 12, 3
1758 #else
1759 std 2, 40(1)
1760 // For ELFv1, we need to load the actual function address from the function descriptor.
1761 ld 12, 0(3)
1762 ld 2, 8(3)
1763 ld 11, 16(3)
1764 #endif
1765
1766 addi 3, 31, -20
1767 addi 4, 31, -24
1768
1769 mtctr 12
1770 bctrl
1771 # if KMP_ARCH_PPC64_ELFv2
1772 ld 2, 24(1)
1773 # else
1774 ld 2, 40(1)
1775 # endif
1776
1777 # if OMPT_SUPPORT
1778 li 3, 0
1779 std 3, 0(30)
1780 # endif
1781
1782 li 3, 1
1783
1784 # if OMPT_SUPPORT
1785 ld 30, -16(31)
1786 # endif
1787
1788 mr 1, 31
1789 ld 0, 16(1)
1790 ld 31, -8(1)
1791 mtlr 0
1792 blr
1793
1794 .long 0
1795 .quad 0
1796 .Lfunc_end0:
1797 .size __kmp_invoke_microtask, .Lfunc_end0-.Lfunc_begin0
1798 .cfi_endproc
1799
1800 // -- End __kmp_invoke_microtask
1801
1802 #endif /* KMP_ARCH_PPC64 */
1803
1804 #if KMP_ARCH_RISCV64
1805
1806 //------------------------------------------------------------------------
1807 //
1808 // typedef void (*microtask_t)(int *gtid, int *tid, ...);
1809 //
1810 // int __kmp_invoke_microtask(microtask_t pkfn, int gtid, int tid, int argc,
1811 // void *p_argv[]
1812 // #if OMPT_SUPPORT
1813 // ,
1814 // void **exit_frame_ptr
1815 // #endif
1816 // ) {
1817 // #if OMPT_SUPPORT
1818 // *exit_frame_ptr = OMPT_GET_FRAME_ADDRESS(0);
1819 // #endif
1820 //
1821 // (*pkfn)(&gtid, &tid, argv[0], ...);
1822 //
1823 // return 1;
1824 // }
1825 //
1826 // Parameters:
1827 // a0: pkfn
1828 // a1: gtid
1829 // a2: tid
1830 // a3: argc
1831 // a4: p_argv
1832 // a5: exit_frame_ptr
1833 //
1834 // Locals:
1835 // __gtid: gtid param pushed on stack so can pass &gtid to pkfn
1836 // __tid: tid param pushed on stack so can pass &tid to pkfn
1837 //
1838 // Temp. registers:
1839 //
1840 // t0: used to calculate the dynamic stack size / used to hold pkfn address
1841 // t1: used as temporary for stack placement calculation
1842 // t2: used as temporary for stack arguments
1843 // t3: used as temporary for number of remaining pkfn parms
1844 // t4: used to traverse p_argv array
1845 //
1846 // return: a0 (always 1/TRUE)
1847 //
1848
1849 __gtid = -20
1850 __tid = -24
1851
1852 // -- Begin __kmp_invoke_microtask
1853 // mark_begin;
1854 .text
1855 .globl __kmp_invoke_microtask
1856 .p2align 1
1857 .type __kmp_invoke_microtask,@function
1858 __kmp_invoke_microtask:
1859 .cfi_startproc
1860
1861 // First, save ra and fp
1862 addi sp, sp, -16
1863 sd ra, 8(sp)
1864 sd fp, 0(sp)
1865 addi fp, sp, 16
1866 .cfi_def_cfa fp, 0
1867 .cfi_offset ra, -8
1868 .cfi_offset fp, -16
1869
1870 // Compute the dynamic stack size:
1871 //
1872 // - We need 8 bytes for storing 'gtid' and 'tid', so we can pass them by
1873 // reference
1874 // - We need 8 bytes for each argument that cannot be passed to the 'pkfn'
1875 // function by register. Given that we have 8 of such registers (a[0-7])
1876 // and two + 'argc' arguments (consider &gtid and &tid), we need to
1877 // reserve max(0, argc - 6)*8 extra bytes
1878 //
1879 // The total number of bytes is then max(0, argc - 6)*8 + 8
1880
1881 // Compute max(0, argc - 6) using the following bithack:
1882 // max(0, x) = x - (x & (x >> 31)), where x := argc - 6
1883 // Source: http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
1884 addi t0, a3, -6
1885 srai t1, t0, 31
1886 and t1, t0, t1
1887 sub t0, t0, t1
1888
1889 addi t0, t0, 1
1890
1891 slli t0, t0, 3
1892 sub sp, sp, t0
1893
1894 // Align the stack to 16 bytes
1895 andi sp, sp, -16
1896
1897 mv t0, a0
1898 mv t3, a3
1899 mv t4, a4
1900
1901 #if OMPT_SUPPORT
1902 // Save frame pointer into exit_frame
1903 sd fp, 0(a5)
1904 #endif
1905
1906 // Prepare arguments for the pkfn function (first 8 using a0-a7 registers)
1907
1908 sw a1, __gtid(fp)
1909 sw a2, __tid(fp)
1910
1911 addi a0, fp, __gtid
1912 addi a1, fp, __tid
1913
1914 beqz t3, .L_kmp_3
1915 ld a2, 0(t4)
1916
1917 addi t3, t3, -1
1918 beqz t3, .L_kmp_3
1919 ld a3, 8(t4)
1920
1921 addi t3, t3, -1
1922 beqz t3, .L_kmp_3
1923 ld a4, 16(t4)
1924
1925 addi t3, t3, -1
1926 beqz t3, .L_kmp_3
1927 ld a5, 24(t4)
1928
1929 addi t3, t3, -1
1930 beqz t3, .L_kmp_3
1931 ld a6, 32(t4)
1932
1933 addi t3, t3, -1
1934 beqz t3, .L_kmp_3
1935 ld a7, 40(t4)
1936
1937 // Prepare any additional argument passed through the stack
1938 addi t4, t4, 48
1939 mv t1, sp
1940 j .L_kmp_2
1941 .L_kmp_1:
1942 ld t2, 0(t4)
1943 sd t2, 0(t1)
1944 addi t4, t4, 8
1945 addi t1, t1, 8
1946 .L_kmp_2:
1947 addi t3, t3, -1
1948 bnez t3, .L_kmp_1
1949
1950 .L_kmp_3:
1951 // Call pkfn function
1952 jalr t0
1953
1954 // Restore stack and return
1955
1956 addi a0, zero, 1
1957
1958 addi sp, fp, -16
1959 ld fp, 0(sp)
1960 ld ra, 8(sp)
1961 addi sp, sp, 16
1962 ret
1963 .Lfunc_end0:
1964 .size __kmp_invoke_microtask, .Lfunc_end0-__kmp_invoke_microtask
1965 .cfi_endproc
1966
1967 // -- End __kmp_invoke_microtask
1968
1969 #endif /* KMP_ARCH_RISCV64 */
1970
1971 #if KMP_ARCH_LOONGARCH64
1972
1973 //------------------------------------------------------------------------
1974 //
1975 // typedef void (*microtask_t)(int *gtid, int *tid, ...);
1976 //
1977 // int __kmp_invoke_microtask(microtask_t pkfn, int gtid, int tid, int argc,
1978 // void *p_argv[]
1979 // #if OMPT_SUPPORT
1980 // ,
1981 // void **exit_frame_ptr
1982 // #endif
1983 // ) {
1984 // #if OMPT_SUPPORT
1985 // *exit_frame_ptr = OMPT_GET_FRAME_ADDRESS(0);
1986 // #endif
1987 //
1988 // (*pkfn)(&gtid, &tid, argv[0], ...);
1989 //
1990 // return 1;
1991 // }
1992 //
1993 // Parameters:
1994 // a0: pkfn
1995 // a1: gtid
1996 // a2: tid
1997 // a3: argc
1998 // a4: p_argv
1999 // a5: exit_frame_ptr
2000 //
2001 // Locals:
2002 // __gtid: gtid param pushed on stack so can pass &gtid to pkfn
2003 // __tid: tid param pushed on stack so can pass &tid to pkfn
2004 //
2005 // Temp registers:
2006 //
2007 // t0: used to calculate the dynamic stack size / used to hold pkfn address
2008 // t1: used as temporary for stack placement calculation
2009 // t2: used as temporary for stack arguments
2010 // t3: used as temporary for number of remaining pkfn parms
2011 // t4: used to traverse p_argv array
2012 //
2013 // return: a0 (always 1/TRUE)
2014 //
2015
2016 // -- Begin __kmp_invoke_microtask
2017 // mark_begin;
2018 .text
2019 .globl __kmp_invoke_microtask
2020 .p2align 2
2021 .type __kmp_invoke_microtask,@function
2022 __kmp_invoke_microtask:
2023 .cfi_startproc
2024
2025 // First, save ra and fp
2026 addi.d $sp, $sp, -16
2027 st.d $ra, $sp, 8
2028 st.d $fp, $sp, 0
2029 addi.d $fp, $sp, 16
2030 .cfi_def_cfa 22, 0
2031 .cfi_offset 1, -8
2032 .cfi_offset 22, -16
2033
2034 // Compute the dynamic stack size:
2035 //
2036 // - We need 8 bytes for storing 'gtid' and 'tid', so we can pass them by
2037 // reference
2038 // - We need 8 bytes for each argument that cannot be passed to the 'pkfn'
2039 // function by register. Given that we have 8 of such registers (a[0-7])
2040 // and two + 'argc' arguments (consider &gtid and &tid), we need to
2041 // reserve max(0, argc - 6)*8 extra bytes
2042 //
2043 // The total number of bytes is then max(0, argc - 6)*8 + 8
2044
2045 addi.d $t0, $a3, -6
2046 slt $t1, $t0, $zero
2047 masknez $t0, $t0, $t1
2048 addi.d $t0, $t0, 1
2049 slli.d $t0, $t0, 3
2050 sub.d $sp, $sp, $t0
2051
2052 // Align the stack to 16 bytes
2053 bstrins.d $sp, $zero, 3, 0
2054
2055 move $t0, $a0
2056 move $t3, $a3
2057 move $t4, $a4
2058
2059 #if OMPT_SUPPORT
2060 // Save frame pointer into exit_frame
2061 st.d $fp, $a5, 0
2062 #endif
2063
2064 // Prepare arguments for the pkfn function (first 8 using a0-a7 registers)
2065
2066 st.w $a1, $fp, -20
2067 st.w $a2, $fp, -24
2068
2069 addi.d $a0, $fp, -20
2070 addi.d $a1, $fp, -24
2071
2072 beqz $t3, .L_kmp_3
2073 ld.d $a2, $t4, 0
2074
2075 addi.d $t3, $t3, -1
2076 beqz $t3, .L_kmp_3
2077 ld.d $a3, $t4, 8
2078
2079 addi.d $t3, $t3, -1
2080 beqz $t3, .L_kmp_3
2081 ld.d $a4, $t4, 16
2082
2083 addi.d $t3, $t3, -1
2084 beqz $t3, .L_kmp_3
2085 ld.d $a5, $t4, 24
2086
2087 addi.d $t3, $t3, -1
2088 beqz $t3, .L_kmp_3
2089 ld.d $a6, $t4, 32
2090
2091 addi.d $t3, $t3, -1
2092 beqz $t3, .L_kmp_3
2093 ld.d $a7, $t4, 40
2094
2095 // Prepare any additional argument passed through the stack
2096 addi.d $t4, $t4, 48
2097 move $t1, $sp
2098 b .L_kmp_2
2099 .L_kmp_1:
2100 ld.d $t2, $t4, 0
2101 st.d $t2, $t1, 0
2102 addi.d $t4, $t4, 8
2103 addi.d $t1, $t1, 8
2104 .L_kmp_2:
2105 addi.d $t3, $t3, -1
2106 bnez $t3, .L_kmp_1
2107
2108 .L_kmp_3:
2109 // Call pkfn function
2110 jirl $ra, $t0, 0
2111
2112 // Restore stack and return
2113
2114 addi.d $a0, $zero, 1
2115
2116 addi.d $sp, $fp, -16
2117 ld.d $fp, $sp, 0
2118 ld.d $ra, $sp, 8
2119 addi.d $sp, $sp, 16
2120 jr $ra
2121 .Lfunc_end0:
2122 .size __kmp_invoke_microtask, .Lfunc_end0-__kmp_invoke_microtask
2123 .cfi_endproc
2124
2125 // -- End __kmp_invoke_microtask
2126
2127 #endif /* KMP_ARCH_LOONGARCH64 */
2128
2129 #if KMP_ARCH_VE
2130
2131 //------------------------------------------------------------------------
2132 //
2133 // typedef void (*microtask_t)(int *gtid, int *tid, ...);
2134 //
2135 // int __kmp_invoke_microtask(microtask_t pkfn, int gtid, int tid, int argc,
2136 // void *p_argv[]
2137 // #if OMPT_SUPPORT
2138 // ,
2139 // void **exit_frame_ptr
2140 // #endif
2141 // ) {
2142 // #if OMPT_SUPPORT
2143 // *exit_frame_ptr = OMPT_GET_FRAME_ADDRESS(0);
2144 // #endif
2145 //
2146 // (*pkfn)(&gtid, &tid, argv[0], ...);
2147 //
2148 // return 1;
2149 // }
2150 //
2151 // Parameters:
2152 // s0: pkfn
2153 // s1: gtid
2154 // s2: tid
2155 // s3: argc
2156 // s4: p_argv
2157 // s5: exit_frame_ptr
2158 //
2159 // Locals:
2160 // __gtid: gtid param pushed on stack so can pass &gtid to pkfn
2161 // __tid: tid param pushed on stack so can pass &tid to pkfn
2162 //
2163 // Temp. registers:
2164 //
2165 // s34: used to calculate the dynamic stack size
2166 // s35: used as temporary for stack placement calculation
2167 // s36: used as temporary for stack arguments
2168 // s37: used as temporary for number of remaining pkfn parms
2169 // s38: used to traverse p_argv array
2170 //
2171 // return: s0 (always 1/TRUE)
2172 //
2173
2174 __gtid = -4
2175 __tid = -8
2176
2177 // -- Begin __kmp_invoke_microtask
2178 // mark_begin;
2179 .text
2180 .globl __kmp_invoke_microtask
2181 // A function requires 8 bytes align.
2182 .p2align 3
2183 .type __kmp_invoke_microtask,@function
2184 __kmp_invoke_microtask:
2185 .cfi_startproc
2186
2187 // First, save fp and lr. VE stores them at caller stack frame.
2188 st %fp, 0(, %sp)
2189 st %lr, 8(, %sp)
2190 or %fp, 0, %sp
2191 .cfi_def_cfa %fp, 0
2192 .cfi_offset %lr, 8
2193 .cfi_offset %fp, 0
2194
2195 // Compute the dynamic stack size:
2196 //
2197 // - We need 8 bytes for storing 'gtid' and 'tid', so we can pass them
2198 // by reference
2199 // - We need 8 bytes for whole arguments. We have two + 'argc'
2200 // arguments (condider &gtid and &tid). We need to reserve
2201 // (argc + 2) * 8 bytes.
2202 // - We need 176 bytes for RSA and others
2203 //
2204 // The total number of bytes is then (argc + 2) * 8 + 8 + 176.
2205 //
2206 // |------------------------------|
2207 // | return address of callee | 8(%fp)
2208 // |------------------------------|
2209 // | frame pointer of callee | 0(%fp)
2210 // |------------------------------| <------------------ %fp
2211 // | __tid / __gtid | -8(%fp) / -4(%fp)
2212 // |------------------------------|
2213 // | argc+2 for arguments | 176(%sp)
2214 // |------------------------------|
2215 // | RSA |
2216 // |------------------------------|
2217 // | return address |
2218 // |------------------------------|
2219 // | frame pointer |
2220 // |------------------------------| <------------------ %sp
2221
2222 adds.w.sx %s34, 2, %s3
2223 sll %s34, %s34, 3
2224 lea %s34, 184(, %s34)
2225 subs.l %sp, %sp, %s34
2226
2227 // Align the stack to 16 bytes.
2228 and %sp, -16, %sp
2229
2230 // Save pkfn.
2231 or %s12, 0, %s0
2232
2233 // Call host to allocate stack if it is necessary.
2234 brge.l %sp, %sl, .L_kmp_pass
2235 ld %s61, 24(, %tp)
2236 lea %s63, 0x13b
2237 shm.l %s63, 0(%s61)
2238 shm.l %sl, 8(%s61)
2239 shm.l %sp, 16(%s61)
2240 monc
2241
2242 .L_kmp_pass:
2243 lea %s35, 176(, %sp)
2244 adds.w.sx %s37, 0, %s3
2245 or %s38, 0, %s4
2246
2247 #if OMPT_SUPPORT
2248 // Save frame pointer into exit_frame.
2249 st %fp, 0(%s5)
2250 #endif
2251
2252 // Prepare arguments for the pkfn function (first 8 using s0-s7
2253 // registers, but need to store stack also because of varargs).
2254
2255 stl %s1, __gtid(%fp)
2256 stl %s2, __tid(%fp)
2257
2258 adds.l %s0, __gtid, %fp
2259 st %s0, 0(, %s35)
2260 adds.l %s1, __tid, %fp
2261 st %s1, 8(, %s35)
2262
2263 breq.l 0, %s37, .L_kmp_call
2264 ld %s2, 0(, %s38)
2265 st %s2, 16(, %s35)
2266
2267 breq.l 1, %s37, .L_kmp_call
2268 ld %s3, 8(, %s38)
2269 st %s3, 24(, %s35)
2270
2271 breq.l 2, %s37, .L_kmp_call
2272 ld %s4, 16(, %s38)
2273 st %s4, 32(, %s35)
2274
2275 breq.l 3, %s37, .L_kmp_call
2276 ld %s5, 24(, %s38)
2277 st %s5, 40(, %s35)
2278
2279 breq.l 4, %s37, .L_kmp_call
2280 ld %s6, 32(, %s38)
2281 st %s6, 48(, %s35)
2282
2283 breq.l 5, %s37, .L_kmp_call
2284 ld %s7, 40(, %s38)
2285 st %s7, 56(, %s35)
2286
2287 breq.l 6, %s37, .L_kmp_call
2288
2289 // Prepare any additional argument passed through the stack.
2290 adds.l %s37, -6, %s37
2291 lea %s38, 48(, %s38)
2292 lea %s35, 64(, %s35)
2293 .L_kmp_loop:
2294 ld %s36, 0(, %s38)
2295 st %s36, 0(, %s35)
2296 adds.l %s37, -1, %s37
2297 adds.l %s38, 8, %s38
2298 adds.l %s35, 8, %s35
2299 brne.l 0, %s37, .L_kmp_loop
2300
2301 .L_kmp_call:
2302 // Call pkfn function.
2303 bsic %lr, (, %s12)
2304
2305 // Return value.
2306 lea %s0, 1
2307
2308 // Restore stack and return.
2309 or %sp, 0, %fp
2310 ld %lr, 8(, %sp)
2311 ld %fp, 0(, %sp)
2312 b.l.t (, %lr)
2313 .Lfunc_end0:
2314 .size __kmp_invoke_microtask, .Lfunc_end0-__kmp_invoke_microtask
2315 .cfi_endproc
2316
2317 // -- End __kmp_invoke_microtask
2318
2319 #endif /* KMP_ARCH_VE */
2320
2321 #if KMP_ARCH_S390X
2322
2323 //------------------------------------------------------------------------
2324 //
2325 // typedef void (*microtask_t)(int *gtid, int *tid, ...);
2326 //
2327 // int __kmp_invoke_microtask(microtask_t pkfn, int gtid, int tid, int argc,
2328 // void *p_argv[]
2329 // #if OMPT_SUPPORT
2330 // ,
2331 // void **exit_frame_ptr
2332 // #endif
2333 // ) {
2334 // #if OMPT_SUPPORT
2335 // *exit_frame_ptr = OMPT_GET_FRAME_ADDRESS(0);
2336 // #endif
2337 //
2338 // (*pkfn)(&gtid, &tid, argv[0], ...);
2339 //
2340 // return 1;
2341 // }
2342 //
2343 // Parameters:
2344 // r2: pkfn
2345 // r3: gtid
2346 // r4: tid
2347 // r5: argc
2348 // r6: p_argv
2349 // SP+160: exit_frame_ptr
2350 //
2351 // Locals:
2352 // __gtid: gtid param pushed on stack so can pass &gtid to pkfn
2353 // __tid: tid param pushed on stack so can pass &tid to pkfn
2354 //
2355 // Temp. registers:
2356 //
2357 // r0: used to fetch argv slots
2358 // r7: used as temporary for number of remaining pkfn parms
2359 // r8: argv
2360 // r9: pkfn
2361 // r10: stack size
2362 // r11: previous fp
2363 // r12: stack parameter area
2364 // r13: argv slot
2365 //
2366 // return: r2 (always 1/TRUE)
2367 //
2368
2369 // -- Begin __kmp_invoke_microtask
2370 // mark_begin;
2371 .text
2372 .globl __kmp_invoke_microtask
2373 .p2align 1
2374 .type __kmp_invoke_microtask,@function
2375 __kmp_invoke_microtask:
2376 .cfi_startproc
2377
2378 stmg %r6,%r14,48(%r15)
2379 .cfi_offset %r6, -112
2380 .cfi_offset %r7, -104
2381 .cfi_offset %r8, -96
2382 .cfi_offset %r9, -88
2383 .cfi_offset %r10, -80
2384 .cfi_offset %r11, -72
2385 .cfi_offset %r12, -64
2386 .cfi_offset %r13, -56
2387 .cfi_offset %r14, -48
2388 .cfi_offset %r15, -40
2389 lgr %r11,%r15
2390 .cfi_def_cfa %r11, 160
2391
2392 // Compute the dynamic stack size:
2393 //
2394 // - We need 8 bytes for storing 'gtid' and 'tid', so we can pass them by
2395 // reference
2396 // - We need 8 bytes for each argument that cannot be passed to the 'pkfn'
2397 // function by register. Given that we have 5 of such registers (r[2-6])
2398 // and two + 'argc' arguments (consider &gtid and &tid), we need to
2399 // reserve max(0, argc - 3)*8 extra bytes
2400 //
2401 // The total number of bytes is then max(0, argc - 3)*8 + 8
2402
2403 lgr %r10,%r5
2404 aghi %r10,-2
2405 jnm 0f
2406 lghi %r10,0
2407 0:
2408 sllg %r10,%r10,3
2409 lgr %r12,%r10
2410 aghi %r10,176
2411 sgr %r15,%r10
2412 agr %r12,%r15
2413 stg %r11,0(%r15)
2414
2415 lgr %r9,%r2 // pkfn
2416
2417 #if OMPT_SUPPORT
2418 // Save frame pointer into exit_frame
2419 lg %r8,160(%r11)
2420 stg %r11,0(%r8)
2421 #endif
2422
2423 // Prepare arguments for the pkfn function (first 5 using r2-r6 registers)
2424
2425 stg %r3,160(%r12)
2426 la %r2,164(%r12) // gid
2427 stg %r4,168(%r12)
2428 la %r3,172(%r12) // tid
2429 lgr %r8,%r6 // argv
2430
2431 // If argc > 0
2432 ltgr %r7,%r5
2433 jz 1f
2434
2435 lg %r4,0(%r8) // argv[0]
2436 aghi %r7,-1
2437 jz 1f
2438
2439 // If argc > 1
2440 lg %r5,8(%r8) // argv[1]
2441 aghi %r7,-1
2442 jz 1f
2443
2444 // If argc > 2
2445 lg %r6,16(%r8) // argv[2]
2446 aghi %r7,-1
2447 jz 1f
2448
2449 lghi %r13,0 // Index [n]
2450 2:
2451 lg %r0,24(%r13,%r8) // argv[2+n]
2452 stg %r0,160(%r13,%r15) // parm[2+n]
2453 aghi %r13,8 // Next
2454 aghi %r7,-1
2455 jnz 2b
2456
2457 1:
2458 basr %r14,%r9 // Call pkfn
2459
2460 // Restore stack and return
2461
2462 lgr %r15,%r11
2463 lmg %r6,%r14,48(%r15)
2464 lghi %r2,1
2465 br %r14
2466 .Lfunc_end0:
2467 .size __kmp_invoke_microtask, .Lfunc_end0-__kmp_invoke_microtask
2468 .cfi_endproc
2469
2470 // -- End __kmp_invoke_microtask
2471
2472 #endif /* KMP_ARCH_S390X */
2473
2474 #if KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_PPC || KMP_ARCH_AARCH64_32 || KMP_ARCH_SPARC32
2475 #ifndef KMP_PREFIX_UNDERSCORE
2476 # define KMP_PREFIX_UNDERSCORE(x) x
2477 #endif
2478 .data
2479 COMMON .gomp_critical_user_, 32, 3
2480 .data
2481 .align 4
2482 .global KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr)
2483 KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr):
2484 .4byte .gomp_critical_user_
2485 #ifdef __ELF__
2486 .type KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr),%object
2487 .size KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr),4
2488 #endif
2489 #endif /* KMP_ARCH_ARM || KMP_ARCH_MIPS || KMP_ARCH_AARCH64_32 || KMP_ARCH_SPARC32 */
2490
2491 #if KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS64 || \
2492 KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 || KMP_ARCH_VE || \
2493 KMP_ARCH_S390X || KMP_ARCH_SPARC64
2494 #ifndef KMP_PREFIX_UNDERSCORE
2495 # define KMP_PREFIX_UNDERSCORE(x) x
2496 #endif
2497 .data
2498 COMMON .gomp_critical_user_, 32, 3
2499 .data
2500 .align 8
2501 .global KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr)
2502 KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr):
2503 .8byte .gomp_critical_user_
2504 #ifdef __ELF__
2505 .type KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr),%object
2506 .size KMP_PREFIX_UNDERSCORE(__kmp_unnamed_critical_addr),8
2507 #endif
2508 #endif /* KMP_ARCH_PPC64 || KMP_ARCH_AARCH64 || KMP_ARCH_MIPS64 ||
2509 KMP_ARCH_RISCV64 || KMP_ARCH_LOONGARCH64 || KMP_ARCH_VE ||
2510 KMP_ARCH_S390X || KMP_ARCH_SPARC64 */
2511
2512 #if KMP_OS_LINUX
2513 # if KMP_ARCH_ARM || KMP_ARCH_AARCH64
2514 .section .note.GNU-stack,"",%progbits
2515 # elif !KMP_ARCH_WASM
2516 .section .note.GNU-stack,"",@progbits
2517 # endif
2518 #endif
2519
2520 #if (KMP_OS_LINUX || KMP_OS_OPENBSD) && \
2521 (KMP_ARCH_AARCH64 || KMP_ARCH_AARCH64_32)
2522 GNU_PROPERTY_BTI_PAC
2523 #endif