x86: Avoid using gas local labels

Which are unsupported by Darwin cctools as.
Thankfully this doesn't uglify the source too much.
This commit is contained in:
Richard Henderson
2015-01-05 10:01:37 -08:00
parent ed1ca2777c
commit 5f35e0ffcc
2 changed files with 247 additions and 221 deletions
+74 -65
View File
@@ -43,6 +43,12 @@
# define C(X) X
#endif
#ifdef __APPLE__
# define L(X) C1(L, X)
#else
# define L(X) C1(.L, X)
#endif
#ifdef __ELF__
# define PLT(X) X@PLT
# define ENDF(X) .type X,@function; .size X, . - X
@@ -55,12 +61,11 @@
actual table. The entry points into the table are all 8 bytes.
The use of ORG asserts that we're at the correct location. */
/* ??? The clang assembler doesn't handle .org with symbolic expressions. */
.macro E index
.balign 8
#if !defined(__clang__) && !defined(__APPLE__)
.org 0b + \index * 8, 0x90
#if defined(__clang__) || defined(__APPLE__)
# define E(BASE, X) .balign 8
#else
# define E(BASE, X) .balign 8; .org BASE + X * 8
#endif
.endm
/* ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags,
void *raddr, void (*fnaddr)(void));
@@ -106,8 +111,8 @@ C(ffi_call_unix64):
movq 0x28(%r10), %r9
movl 0xb0(%r10), %eax
testl %eax, %eax
jnz .Lload_sse
.Lret_from_load_sse:
jnz L(load_sse)
L(ret_from_load_sse):
/* Deallocate the reg arg area, except for r10, then load via pop. */
leaq 0xb8(%r10), %rsp
@@ -129,8 +134,8 @@ C(ffi_call_unix64):
/* The first byte of the flags contains the FFI_TYPE. */
cmpb $UNIX64_RET_LAST, %cl
movzbl %cl, %r10d
leaq 0f(%rip), %r11
ja 9f
leaq L(store_table)(%rip), %r11
ja L(sa)
leaq (%r11, %r10, 8), %r10
/* Prep for the structure cases: scratch area in redzone. */
@@ -138,78 +143,80 @@ C(ffi_call_unix64):
jmp *%r10
.balign 8
0:
E UNIX64_RET_VOID
L(store_table):
E(L(store_table), UNIX64_RET_VOID)
ret
E UNIX64_RET_UINT8
E(L(store_table), UNIX64_RET_UINT8)
movzbl %al, %eax
movq %rax, (%rdi)
ret
E UNIX64_RET_UINT16
E(L(store_table), UNIX64_RET_UINT16)
movzwl %ax, %eax
movq %rax, (%rdi)
ret
E UNIX64_RET_UINT32
E(L(store_table), UNIX64_RET_UINT32)
movl %eax, %eax
movq %rax, (%rdi)
ret
E UNIX64_RET_SINT8
E(L(store_table), UNIX64_RET_SINT8)
movsbq %al, %rax
movq %rax, (%rdi)
ret
E UNIX64_RET_SINT16
E(L(store_table), UNIX64_RET_SINT16)
movswq %ax, %rax
movq %rax, (%rdi)
ret
E UNIX64_RET_SINT32
E(L(store_table), UNIX64_RET_SINT32)
cltq
movq %rax, (%rdi)
ret
E UNIX64_RET_INT64
E(L(store_table), UNIX64_RET_INT64)
movq %rax, (%rdi)
ret
E UNIX64_RET_XMM32
E(L(store_table), UNIX64_RET_XMM32)
movd %xmm0, (%rdi)
ret
E UNIX64_RET_XMM64
E(L(store_table), UNIX64_RET_XMM64)
movq %xmm0, (%rdi)
ret
E UNIX64_RET_X87
E(L(store_table), UNIX64_RET_X87)
fstpt (%rdi)
ret
E UNIX64_RET_X87_2
E(L(store_table), UNIX64_RET_X87_2)
fstpt (%rdi)
fstpt 16(%rdi)
ret
E UNIX64_RET_ST_XMM0_RAX
E(L(store_table), UNIX64_RET_ST_XMM0_RAX)
movq %rax, 8(%rsi)
jmp 3f
E UNIX64_RET_ST_RAX_XMM0
jmp L(s3)
E(L(store_table), UNIX64_RET_ST_RAX_XMM0)
movq %xmm0, 8(%rsi)
jmp 2f
E UNIX64_RET_ST_XMM0_XMM1
jmp L(s2)
E(L(store_table), UNIX64_RET_ST_XMM0_XMM1)
movq %xmm1, 8(%rsi)
jmp 3f
E UNIX64_RET_ST_RAX_RDX
jmp L(s3)
E(L(store_table), UNIX64_RET_ST_RAX_RDX)
movq %rdx, 8(%rsi)
2: movq %rax, (%rsi)
L(s2):
movq %rax, (%rsi)
shrl $UNIX64_SIZE_SHIFT, %ecx
rep movsb
ret
.balign 8
3: movq %xmm0, (%rsi)
L(s3):
movq %xmm0, (%rsi)
shrl $UNIX64_SIZE_SHIFT, %ecx
rep movsb
ret
9: call PLT(C(abort))
L(sa): call PLT(C(abort))
/* Many times we can avoid loading any SSE registers at all.
It's not worth an indirect jump to load the exact set of
SSE registers needed; zero or all is a good compromise. */
.balign 2
cfi_restore_state
.Lload_sse:
L(load_sse):
movdqa 0x30(%r10), %xmm0
movdqa 0x40(%r10), %xmm1
movdqa 0x50(%r10), %xmm2
@@ -218,7 +225,7 @@ E UNIX64_RET_ST_RAX_RDX
movdqa 0x80(%r10), %xmm5
movdqa 0x90(%r10), %xmm6
movdqa 0xa0(%r10), %xmm7
jmp .Lret_from_load_sse
jmp L(ret_from_load_sse)
cfi_endproc
ENDF(C(ffi_call_unix64))
@@ -251,7 +258,7 @@ C(ffi_closure_unix64_sse):
movdqa %xmm5, ffi_closure_OFS_V+0x50(%rsp)
movdqa %xmm6, ffi_closure_OFS_V+0x60(%rsp)
movdqa %xmm7, ffi_closure_OFS_V+0x70(%rsp)
jmp 0f
jmp L(sse_entry1)
cfi_endproc
ENDF(C(ffi_closure_unix64_sse))
@@ -265,7 +272,7 @@ C(ffi_closure_unix64):
subq $ffi_closure_FS, %rsp
/* Note clang bug 21515: adjust_cfa_offset error across endproc. */
cfi_def_cfa_offset(ffi_closure_FS + 8)
0:
L(sse_entry1):
movq %rdi, ffi_closure_OFS_G+0x00(%rsp)
movq %rsi, ffi_closure_OFS_G+0x08(%rsp)
movq %rdx, ffi_closure_OFS_G+0x10(%rsp)
@@ -282,7 +289,7 @@ C(ffi_closure_unix64):
movq FFI_TRAMPOLINE_SIZE+8(%r10), %rsi /* Load fun */
movq FFI_TRAMPOLINE_SIZE+16(%r10), %rdx /* Load user_data */
#endif
.Ldo_closure:
L(do_closure):
leaq ffi_closure_OFS_RVALUE(%rsp), %rcx /* Load rvalue */
movq %rsp, %r8 /* Load reg_args */
leaq ffi_closure_FS+8(%rsp), %r9 /* Load argp */
@@ -295,68 +302,70 @@ C(ffi_closure_unix64):
/* The first byte of the return value contains the FFI_TYPE. */
cmpb $UNIX64_RET_LAST, %al
movzbl %al, %r10d
leaq 0f(%rip), %r11
ja 9f
leaq L(load_table)(%rip), %r11
ja L(la)
leaq (%r11, %r10, 8), %r10
leaq ffi_closure_RED_RVALUE(%rsp), %rsi
jmp *%r10
.balign 8
0:
E UNIX64_RET_VOID
L(load_table):
E(L(load_table), UNIX64_RET_VOID)
ret
E UNIX64_RET_UINT8
E(L(load_table), UNIX64_RET_UINT8)
movzbl (%rsi), %eax
ret
E UNIX64_RET_UINT16
E(L(load_table), UNIX64_RET_UINT16)
movzwl (%rsi), %eax
ret
E UNIX64_RET_UINT32
E(L(load_table), UNIX64_RET_UINT32)
movl (%rsi), %eax
ret
E UNIX64_RET_SINT8
E(L(load_table), UNIX64_RET_SINT8)
movsbl (%rsi), %eax
ret
E UNIX64_RET_SINT16
E(L(load_table), UNIX64_RET_SINT16)
movswl (%rsi), %eax
ret
E UNIX64_RET_SINT32
E(L(load_table), UNIX64_RET_SINT32)
movl (%rsi), %eax
ret
E UNIX64_RET_INT64
E(L(load_table), UNIX64_RET_INT64)
movq (%rsi), %rax
ret
E UNIX64_RET_XMM32
E(L(load_table), UNIX64_RET_XMM32)
movd (%rsi), %xmm0
ret
E UNIX64_RET_XMM64
E(L(load_table), UNIX64_RET_XMM64)
movq (%rsi), %xmm0
ret
E UNIX64_RET_X87
E(L(load_table), UNIX64_RET_X87)
fldt (%rsi)
ret
E UNIX64_RET_X87_2
E(L(load_table), UNIX64_RET_X87_2)
fldt 16(%rsi)
fldt (%rsi)
ret
E UNIX64_RET_ST_XMM0_RAX
E(L(load_table), UNIX64_RET_ST_XMM0_RAX)
movq 8(%rsi), %rax
jmp 3f
E UNIX64_RET_ST_RAX_XMM0
jmp L(l3)
E(L(load_table), UNIX64_RET_ST_RAX_XMM0)
movq 8(%rsi), %xmm0
jmp 2f
E UNIX64_RET_ST_XMM0_XMM1
jmp L(l2)
E(L(load_table), UNIX64_RET_ST_XMM0_XMM1)
movq 8(%rsi), %xmm1
jmp 3f
E UNIX64_RET_ST_RAX_RDX
jmp L(l3)
E(L(load_table), UNIX64_RET_ST_RAX_RDX)
movq 8(%rsi), %rdx
2: movq (%rsi), %rax
L(l2):
movq (%rsi), %rax
ret
.balign 8
3: movq (%rsi), %xmm0
L(l3):
movq (%rsi), %xmm0
ret
9: call PLT(C(abort))
L(la): call PLT(C(abort))
cfi_endproc
ENDF(C(ffi_closure_unix64))
@@ -379,7 +388,7 @@ C(ffi_go_closure_unix64_sse):
movdqa %xmm5, ffi_closure_OFS_V+0x50(%rsp)
movdqa %xmm6, ffi_closure_OFS_V+0x60(%rsp)
movdqa %xmm7, ffi_closure_OFS_V+0x70(%rsp)
jmp 0f
jmp L(sse_entry2)
cfi_endproc
ENDF(C(ffi_go_closure_unix64_sse))
@@ -393,7 +402,7 @@ C(ffi_go_closure_unix64):
subq $ffi_closure_FS, %rsp
/* Note clang bug 21515: adjust_cfa_offset error across endproc. */
cfi_def_cfa_offset(ffi_closure_FS + 8)
0:
L(sse_entry2):
movq %rdi, ffi_closure_OFS_G+0x00(%rsp)
movq %rsi, ffi_closure_OFS_G+0x08(%rsp)
movq %rdx, ffi_closure_OFS_G+0x10(%rsp)
@@ -410,7 +419,7 @@ C(ffi_go_closure_unix64):
movq 16(%r10), %rsi /* Load fun */
movq %r10, %rdx /* Load closure (user_data) */
#endif
jmp .Ldo_closure
jmp L(do_closure)
cfi_endproc
ENDF(C(ffi_go_closure_unix64))