Skip to content

Commit a480191

Browse files
committed
Fix Darwin build of huf_decompress_amd64.S
1 parent 80cac40 commit a480191

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

lib/decompress/huf_decompress_amd64.S

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838

3939
#endif
4040

41+
// There appears to be an unreconcilable syntax difference between Linux and Darwin assemblers.
42+
// Name of a private label (i.e. not exported to symbol table) on Darwin has to start with "L",
43+
// on Linux has to start with ".". There's no way to have a name start with both "." and "L", so
44+
// we have to use a macro.
45+
#if defined(__APPLE__)
46+
#define LOCAL_LABEL(label) L_ ## label
47+
#else
48+
#define LOCAL_LABEL(label) .L_ ## label
49+
#endif
50+
4151
#if ZSTD_ENABLE_ASM_X86_64_BMI2
4252

4353
/* Calling convention:
@@ -198,7 +208,7 @@ HUF_decompress4X1_usingDTable_internal_fast_asm_loop:
198208
subq $24, %rsp
199209
.cfi_def_cfa_offset 184
200210

201-
.L_4X1_compute_olimit:
211+
LOCAL_LABEL(4X1_compute_olimit):
202212
/* Computes how many iterations we can do safely
203213
* %r15, %rax may be clobbered
204214
* rbx, rdx must be saved
@@ -245,19 +255,19 @@ HUF_decompress4X1_usingDTable_internal_fast_asm_loop:
245255
/* If (op3 + 20 > olimit) */
246256
movq %op3, %rax /* rax = op3 */
247257
cmpq %rax, %olimit /* op3 == olimit */
248-
je .L_4X1_exit
258+
je LOCAL_LABEL(4X1_exit)
249259

250260
/* If (ip1 < ip0) go to exit */
251261
cmpq %ip0, %ip1
252-
jb .L_4X1_exit
262+
jb LOCAL_LABEL(4X1_exit)
253263

254264
/* If (ip2 < ip1) go to exit */
255265
cmpq %ip1, %ip2
256-
jb .L_4X1_exit
266+
jb LOCAL_LABEL(4X1_exit)
257267

258268
/* If (ip3 < ip2) go to exit */
259269
cmpq %ip2, %ip3
260-
jb .L_4X1_exit
270+
jb LOCAL_LABEL(4X1_exit)
261271

262272
/* Reads top 11 bits from bits[n]
263273
* Loads dt[bits[n]] into var[n]
@@ -318,7 +328,7 @@ HUF_decompress4X1_usingDTable_internal_fast_asm_loop:
318328

319329
.p2align 6
320330

321-
.L_4X1_loop_body:
331+
LOCAL_LABEL(4X1_loop_body):
322332
/* Decode 5 symbols in each of the 4 streams (20 total)
323333
* Must have called GET_NEXT_DELT for each stream
324334
*/
@@ -356,21 +366,21 @@ HUF_decompress4X1_usingDTable_internal_fast_asm_loop:
356366

357367
/* If op3 < olimit: continue the loop */
358368
cmp %op3, 24(%rsp)
359-
ja .L_4X1_loop_body
369+
ja LOCAL_LABEL(4X1_loop_body)
360370

361371
/* Reload ip[1,2,3] from stack */
362372
movq 0(%rsp), %ip1
363373
movq 8(%rsp), %ip2
364374
movq 16(%rsp), %ip3
365375

366376
/* Re-compute olimit */
367-
jmp .L_4X1_compute_olimit
377+
jmp LOCAL_LABEL(4X1_compute_olimit)
368378

369379
#undef GET_NEXT_DELT
370380
#undef DECODE_FROM_DELT
371381
#undef DECODE
372382
#undef RELOAD_BITS
373-
.L_4X1_exit:
383+
LOCAL_LABEL(4X1_exit):
374384
addq $24, %rsp
375385
.cfi_def_cfa_offset 160
376386

@@ -546,7 +556,7 @@ HUF_decompress4X2_usingDTable_internal_fast_asm_loop:
546556
subq $8, %rsp
547557
.cfi_def_cfa_offset 192
548558

549-
.L_4X2_compute_olimit:
559+
LOCAL_LABEL(4X2_compute_olimit):
550560
/* Computes how many iterations we can do safely
551561
* %r15, %rax may be clobbered
552562
* rdx must be saved
@@ -610,19 +620,19 @@ HUF_decompress4X2_usingDTable_internal_fast_asm_loop:
610620
/* If (op3 + 10 > olimit) */
611621
movq %op3, %rax /* rax = op3 */
612622
cmpq %rax, %olimit /* op3 == olimit */
613-
je .L_4X2_exit
623+
je LOCAL_LABEL(4X2_exit)
614624

615625
/* If (ip1 < ip0) go to exit */
616626
cmpq %ip0, %ip1
617-
jb .L_4X2_exit
627+
jb LOCAL_LABEL(4X2_exit)
618628

619629
/* If (ip2 < ip1) go to exit */
620630
cmpq %ip1, %ip2
621-
jb .L_4X2_exit
631+
jb LOCAL_LABEL(4X2_exit)
622632

623633
/* If (ip3 < ip2) go to exit */
624634
cmpq %ip2, %ip3
625-
jb .L_4X2_exit
635+
jb LOCAL_LABEL(4X2_exit)
626636

627637
#define DECODE(n, idx) \
628638
movq %bits##n, %rax; \
@@ -649,7 +659,7 @@ HUF_decompress4X2_usingDTable_internal_fast_asm_loop:
649659

650660
.p2align 6
651661

652-
.L_4X2_loop_body:
662+
LOCAL_LABEL(4X2_loop_body):
653663
/* We clobber r8, so store it on the stack */
654664
movq %r8, 0(%rsp)
655665

@@ -666,12 +676,12 @@ HUF_decompress4X2_usingDTable_internal_fast_asm_loop:
666676
FOR_EACH_STREAM(RELOAD_BITS)
667677

668678
cmp %op3, 48(%rsp)
669-
ja .L_4X2_loop_body
670-
jmp .L_4X2_compute_olimit
679+
ja LOCAL_LABEL(4X2_loop_body)
680+
jmp LOCAL_LABEL(4X2_compute_olimit)
671681

672682
#undef DECODE
673683
#undef RELOAD_BITS
674-
.L_4X2_exit:
684+
LOCAL_LABEL(4X2_exit):
675685
addq $8, %rsp
676686
.cfi_def_cfa_offset 184
677687
/* Restore stack (oend & olimit) */

0 commit comments

Comments
 (0)