From 7f13f24e1275acf56d754c95f3016f62e905fc7c Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Tue, 24 Jun 2025 22:40:07 +0800 Subject: [PATCH] Use asm implements some atomic functions Use asm implements for i386/x86_64/arm/aarch64/riscv: __atomic_load_[1,2,4,8] __atomic_store_[1,2,4,8] __atomic_compare_exchange_[1,2,4,8] __atomic_test_and_set_[1,2,4,8] atomic_thread_fence atomic_signal_fence atomic_flag_test_and_set atomic_flag_test_and_set_explicit atomic_flag_clear atomic_flag_clear_explicit `atomic.S` is extracted from `gcc` v15.1.0 `libatomic.a`. And generated by https://github.com/kbkpbot/gen_atomic.git --- include/stdatomic.h | 22 +- lib/atomic.S | 3134 ++++++++++++++++++++++++++++++++----------- lib/stdatomic.c | 77 +- 3 files changed, 2375 insertions(+), 858 deletions(-) diff --git a/include/stdatomic.h b/include/stdatomic.h index 58b75173..a03c2ca6 100644 --- a/include/stdatomic.h +++ b/include/stdatomic.h @@ -80,16 +80,6 @@ typedef struct { #define ATOMIC_FLAG_INIT {0} #define ATOMIC_VAR_INIT(value) (value) -#define atomic_flag_test_and_set_explicit(object, order) \ - __atomic_test_and_set((void *)(&((object)->value)), order) -#define atomic_flag_test_and_set(object) \ - atomic_flag_test_and_set_explicit(object, __ATOMIC_SEQ_CST) - -#define atomic_flag_clear_explicit(object, order) \ - __atomic_clear((bool *)(&((object)->value)), order) -#define atomic_flag_clear(object) \ - atomic_flag_clear_explicit(object, __ATOMIC_SEQ_CST) - /* Generic routines */ #define atomic_init(object, desired) \ atomic_store_explicit(object, desired, __ATOMIC_RELAXED) @@ -167,15 +157,15 @@ typedef struct { #define atomic_fetch_and_explicit __atomic_fetch_and extern void atomic_thread_fence (memory_order); -extern void __atomic_thread_fence (memory_order); -#define atomic_thread_fence(order) __atomic_thread_fence (order) +#define __atomic_thread_fence(order) atomic_thread_fence (order) extern void atomic_signal_fence (memory_order); -extern void __atomic_signal_fence (memory_order); +#define __atomic_signal_fence(order) atomic_signal_fence(order) #define atomic_signal_fence(order) __atomic_signal_fence (order) extern bool __atomic_is_lock_free(size_t size, void *ptr); #define atomic_is_lock_free(OBJ) __atomic_is_lock_free (sizeof (*(OBJ)), (OBJ)) -extern bool __atomic_test_and_set (void *, memory_order); -extern void __atomic_clear (bool *, memory_order); - +extern bool atomic_flag_test_and_set(void *object); +extern bool atomic_flag_test_and_set_explicit(void *object, memory_order order); +extern void atomic_flag_clear(void *object); +extern void atomic_flag_clear_explicit(void *object, memory_order order); #endif /* _STDATOMIC_H */ diff --git a/lib/atomic.S b/lib/atomic.S index 29fdbee1..2a219dea 100644 --- a/lib/atomic.S +++ b/lib/atomic.S @@ -1,858 +1,2452 @@ /* ---------------------------------------------- */ -/* This file implements for arm/arm64/riscv: - * __atomic_compare_exchange_1 - * __atomic_compare_exchange_2 - * __atomic_compare_exchange_4 - * __atomic_compare_exchange_8 +/* This file is extracted from `gcc` v15.1.0 `libatomic.a`. */ +/* This file is generated by https://github.com/kbkpbot/gen_atomic.git */ +/* This file is generated at 2025-06-24 21:37. */ +/* This file implements for i386/x86_64/arm/aarch64/riscv: + * __atomic_load_[1,2,4,8] + * __atomic_store_[1,2,4,8] + * __atomic_compare_exchange_[1,2,4,8] + * __atomic_test_and_set_[1,2,4,8] + * atomic_thread_fence + * atomic_signal_fence + * atomic_flag_test_and_set + * atomic_flag_test_and_set_explicit + * atomic_flag_clear + * atomic_flag_clear_explicit */ - #ifdef __leading_underscore # define _(s) _##s #else # define _(s) s #endif + +/* ---------------------------------------------- */ #if defined __i386__ .text .align 2 - .global _(__atomic_test_and_set) - .type _(__atomic_test_and_set), %function -_(__atomic_test_and_set): - movl 4(%esp), %edx - movl $1, %eax - xchgb (%edx), %al + .global _(__atomic_load_1) + .type _(__atomic_load_1), %function +_(__atomic_load_1): + endbr32 + mov 0x4(%esp),%eax + movzbl (%eax),%eax ret - .size _(__atomic_test_and_set), .-_(__atomic_test_and_set) + .size _(__atomic_load_1), .-_(__atomic_load_1) - .global _(__atomic_clear) - .type _(__atomic_clear), %function -_(__atomic_clear): - movl 4(%esp), %edx - xorl %eax, %eax - xchgb (%edx), %al + .global _(__atomic_load_2) + .type _(__atomic_load_2), %function +_(__atomic_load_2): + endbr32 + mov 0x4(%esp),%eax + movzwl (%eax),%eax ret - .size _(__atomic_clear), .-_(__atomic_clear) + .size _(__atomic_load_2), .-_(__atomic_load_2) -#elif defined __x86_64__ - .text - .align 2 - - .global _(__atomic_test_and_set) - .type _(__atomic_test_and_set), %function -_(__atomic_test_and_set): - movl $1, %eax - xchgb (%rdi), %al + .global _(__atomic_load_4) + .type _(__atomic_load_4), %function +_(__atomic_load_4): + endbr32 + mov 0x4(%esp),%eax + mov (%eax),%eax ret - .size _(__atomic_test_and_set), .-_(__atomic_test_and_set) + .size _(__atomic_load_4), .-_(__atomic_load_4) - .global _(__atomic_clear) - .type _(__atomic_clear), %function -_(__atomic_clear): - xorl %eax, %eax - xchgb (%rdi), %al + .global _(__atomic_load_8) + .type _(__atomic_load_8), %function +_(__atomic_load_8): + endbr32 + sub $0xc,%esp + mov 0x10(%esp),%eax + fildll (%eax) + fistpll (%esp) + mov (%esp),%eax + mov 0x4(%esp),%edx + add $0xc,%esp ret - .size _(__atomic_clear), .-_(__atomic_clear) + .size _(__atomic_load_8), .-_(__atomic_load_8) -#elif defined __arm__ + .global _(__atomic_store_1) + .type _(__atomic_store_1), %function +_(__atomic_store_1): + endbr32 + mov 0x4(%esp),%edx + mov 0x8(%esp),%eax + xchg %al,(%edx) + ret + .size _(__atomic_store_1), .-_(__atomic_store_1) -#ifndef __TINYC__ - .arch armv6k - .syntax unified -#endif - .text - .align 2 + .global _(__atomic_store_2) + .type _(__atomic_store_2), %function +_(__atomic_store_2): + endbr32 + mov 0x4(%esp),%edx + mov 0x8(%esp),%eax + xchg %ax,(%edx) + ret + .size _(__atomic_store_2), .-_(__atomic_store_2) - .global _(fetch_and_add_arm) - .type _(fetch_and_add_arm), %function -_(fetch_and_add_arm): - mcr p15, #0, r0, c7, c10, #5 -.L0: - ldrex r3, [r0] - add r3, r3, r1 - strex r2, r3, [r0] - cmp r2, #0 - bne .L0 - mcr p15, #0, r0, c7, c10, #5 - bx lr - .size _(fetch_and_add_arm), .-_(fetch_and_add_arm) + .global _(__atomic_store_4) + .type _(__atomic_store_4), %function +_(__atomic_store_4): + endbr32 + mov 0x4(%esp),%edx + mov 0x8(%esp),%eax + xchg %eax,(%edx) + ret + .size _(__atomic_store_4), .-_(__atomic_store_4) - .global _(__atomic_test_and_set) - .type _(__atomic_test_and_set), %function -_(__atomic_test_and_set): -#ifdef __TINYC__ - .int 0xe92d4030 - .int 0xee070fba - .int 0xe5d03000 - .int 0xe24dd014 - .int 0xe1a05000 - .int 0xe2533000 - .int 0xe1a04001 - .int 0x13a03001 - .int 0xee070fba - .int 0xe5cd300f - .int 0xe3a03001 - .int 0xe1a02003 - .int 0xe28d100f - .int 0xe1a00005 - .int 0xe58d4004 - .int 0xe58d4000 - .int 0xeb000009 - .int 0xe3500000 - .int 0x0afffff6 - .int 0xe5dd000f - .int 0xe28dd014 - .int 0xe8bd8030 -#else - push {r4, r5, lr} - mcr p15, 0, r0, c7, c10, 5 - ldrb r3, [r0] - sub sp, sp, #20 - mov r5, r0 - subs r3, r3, #0 - mov r4, r1 - movne r3, #1 - mcr p15, 0, r0, c7, c10, 5 - strb r3, [sp, #15] -.L20: - mov r3, #1 - mov r2, r3 - add r1, sp, #15 - mov r0, r5 - str r4, [sp, #4] - str r4, [sp] - bl __atomic_compare_exchange_1 - cmp r0, #0 - beq .L20 - ldrb r0, [sp, #15] - add sp, sp, #20 - pop {r4, r5, pc} -#endif - .size _(__atomic_test_and_set), .-_(__atomic_test_and_set) - - .global _(__atomic_clear) - .type _(__atomic_clear), %function -_(__atomic_clear): -#ifdef __TINYC__ - .int 0xe3a03000 - .int 0xee070fba - .int 0xe5c03000 - .int 0xee070fba - .int 0xe12fff1e -#else - mov r3, #0 - mcr p15, 0, r0, c7, c10, 5 - strb r3, [r0] - mcr p15, 0, r0, c7, c10, 5 - bx lr -#endif - .size _(__atomic_clear), .-_(__atomic_clear) + .global _(__atomic_store_8) + .type _(__atomic_store_8), %function +_(__atomic_store_8): + endbr32 + push %ebx + sub $0x8,%esp + mov 0x18(%esp),%ebx + mov 0x14(%esp),%ecx + mov %ecx,(%esp) + mov %ebx,0x4(%esp) + fildll (%esp) + mov 0x10(%esp),%eax + fistpll (%eax) + lock orl $0x0,(%esp) + add $0x8,%esp + pop %ebx + ret + .size _(__atomic_store_8), .-_(__atomic_store_8) .global _(__atomic_compare_exchange_1) .type _(__atomic_compare_exchange_1), %function _(__atomic_compare_exchange_1): -#ifdef __TINYC__ - .int 0xe52de004 - .int 0xe5d13000 - .int 0xf57ff05b - .int 0xe1d0cf9f - .int 0xe15c0003 - .int 0x1a000002 - .int 0xe1c0ef92 - .int 0xe35e0000 - .int 0x1afffff9 - .int 0x03a00001 - .int 0x13a00000 - .int 0xf57ff05b - .int 0x15c1c000 - .int 0xe49df004 -#else - str lr, [sp, #-4]! - ldrb r3, [r1] - mcr p15, 0, r0, c7, c10, 5 -.L1: - ldrexb ip, [r0] - cmp ip, r3 - bne .L2 - strexb lr, r2, [r0] - cmp lr, #0 - bne .L1 -.L2: - mcr p15, 0, r0, c7, c10, 5 - moveq r0, #1 - movne r0, #0 - strbne ip, [r1] - ldr pc, [sp], #4 -#endif + endbr32 + push %ebx + mov 0xc(%esp),%ecx + mov 0x8(%esp),%edx + movzbl 0x10(%esp),%ebx + movzbl (%ecx),%eax + lock cmpxchg %bl,(%edx) + sete %dl + je .L___atomic_compare_exchange_1_020 + mov %al,(%ecx) +.L___atomic_compare_exchange_1_020: + mov %edx,%eax + pop %ebx + ret .size _(__atomic_compare_exchange_1), .-_(__atomic_compare_exchange_1) .global _(__atomic_compare_exchange_2) .type _(__atomic_compare_exchange_2), %function _(__atomic_compare_exchange_2): -#ifdef __TINYC__ - .int 0xe52de004 - .int 0xe1d130b0 - .int 0xf57ff05b - .int 0xe1f0cf9f - .int 0xe15c0003 - .int 0x1a000002 - .int 0xe1e0ef92 - .int 0xe35e0000 - .int 0x1afffff9 - .int 0x03a00001 - .int 0x13a00000 - .int 0xf57ff05b - .int 0x11c1c0b0 - .int 0xe49df004 -#else - str lr, [sp, #-4]! - ldrh r3, [r1] - mcr p15, 0, r0, c7, c10, 5 -.L3: - ldrexh ip, [r0] - cmp ip, r3 - bne .L4 - strexh lr, r2, [r0] - cmp lr, #0 - bne .L3 -.L4: - mcr p15, 0, r0, c7, c10, 5 - moveq r0, #1 - movne r0, #0 - strhne ip, [r1] - ldr pc, [sp], #4 -#endif + endbr32 + push %ebx + mov 0xc(%esp),%ecx + mov 0x8(%esp),%edx + movzwl 0x10(%esp),%ebx + movzwl (%ecx),%eax + lock cmpxchg %bx,(%edx) + sete %dl + je .L___atomic_compare_exchange_2_022 + mov %ax,(%ecx) +.L___atomic_compare_exchange_2_022: + mov %edx,%eax + pop %ebx + ret .size _(__atomic_compare_exchange_2), .-_(__atomic_compare_exchange_2) .global _(__atomic_compare_exchange_4) .type _(__atomic_compare_exchange_4), %function _(__atomic_compare_exchange_4): -#ifdef __TINYC__ - .int 0xe52de004 - .int 0xe5913000 - .int 0xf57ff05b - .int 0xe190cf9f - .int 0xe15c0003 - .int 0x1a000002 - .int 0xe180ef92 - .int 0xe35e0000 - .int 0x1afffff9 - .int 0x03a00001 - .int 0x13a00000 - .int 0xf57ff05b - .int 0x1581c000 - .int 0xe49df004 -#else - str lr, [sp, #-4]! - ldr r3, [r1] - mcr p15, 0, r0, c7, c10, 5 -.L5: - ldrex ip, [r0] - cmp ip, r3 - bne .L6 - strex lr, r2, [r0] - cmp lr, #0 - bne .L5 -.L6: - mcr p15, 0, r0, c7, c10, 5 - moveq r0, #1 - movne r0, #0 - strne ip, [r1] - ldr pc, [sp], #4 -#endif + endbr32 + push %ebx + mov 0xc(%esp),%ecx + mov 0x8(%esp),%edx + mov 0x10(%esp),%ebx + mov (%ecx),%eax + lock cmpxchg %ebx,(%edx) + sete %dl + je .L___atomic_compare_exchange_4_01e + mov %eax,(%ecx) +.L___atomic_compare_exchange_4_01e: + mov %edx,%eax + pop %ebx + ret .size _(__atomic_compare_exchange_4), .-_(__atomic_compare_exchange_4) -/* ---------------------------------------------- */ -#elif defined __aarch64__ - - .text - .align 2 - - .global _(fetch_and_add_arm64) - .type _(fetch_and_add_arm64), %function -_(fetch_and_add_arm64): -#ifdef __TINYC__ - .int 0x885f7c02 - .int 0x0b010042 - .int 0x8803fc02 - .int 0x35ffffa3 - .int 0xd5033bbf - .int 0xd65f03c0 -#else - ldxr w2, [x0] - add w2, w2, w1 - stlxr w3, w2, [x0] - cbnz w3, _(fetch_and_add_arm64) - dmb ish - ret -#endif - .size _(fetch_and_add_arm64), .-_(fetch_and_add_arm64) - - .global _(__atomic_test_and_set) - .type _(__atomic_test_and_set), %function -_(__atomic_test_and_set): -#ifdef __TINYC__ - .int 0xa9bf7bfd - .int 0xaa0003e1 - .int 0x52800020 - .int 0x910003fd - .int 0x2a0003f0 - .int 0x085ffc20 - .int 0x0811fc30 - .int 0x35ffffd1 - .int 0xa8c17bfd - .int 0xd65f03c0 -#else - stp x29, x30, [sp, -16]! - mov x1, x0 - mov w0, 1 - mov x29, sp - mov w16, w0 -.L20: - ldaxrb w0, [x1] - stlxrb w17, w16, [x1] - cbnz w17, .L20 - ldp x29, x30, [sp], 16 - ret -#endif - .size _(__atomic_test_and_set), .-_(__atomic_test_and_set) - - .global _(__atomic_clear) - .type _(__atomic_clear), %function -_(__atomic_clear): -#ifdef __TINYC__ - .int 0x089ffc1f - .int 0xd65f03c0 -#else - stlrb wzr, [x0] - ret -#endif - .size _(__atomic_clear), .-_(__atomic_clear) - - .global _(__atomic_compare_exchange_1) - .type _(__atomic_compare_exchange_1), %function -_(__atomic_compare_exchange_1): -#ifdef __TINYC__ - .int 0xa9be7bfd - .int 0x910003fd - .int 0xa90153f3 - .int 0xaa0103f3 - .int 0x12001c41 - .int 0xaa0003e2 - .int 0x39400274 - .int 0x2a1403e0 - .int 0x53001c10 - .int 0x085ffc40 - .int 0x6b10001f - .int 0x54000061 - .int 0x0811fc41 - .int 0x35ffff91 - .int 0x6b34001f - .int 0x1a9f17e1 - .int 0x54000040 - .int 0x39000260 - .int 0x2a0103e0 - .int 0xa94153f3 - .int 0xa8c27bfd - .int 0xd65f03c0 -#else - stp x29, x30, [sp, -32]! - mov x29, sp - stp x19, x20, [sp, 16] - mov x19, x1 - and w1, w2, 255 - mov x2, x0 - ldrb w20, [x19] - mov w0, w20 - uxtb w16, w0 -.L1: - ldaxrb w0, [x2] - cmp w0, w16 - b.ne .L2 - stlxrb w17, w1, [x2] - cbnz w17, .L1 -.L2: - cmp w0, w20, uxtb - cset w1, eq - beq .L3 - strb w0, [x19] -.L3: - mov w0, w1 - ldp x19, x20, [sp, 16] - ldp x29, x30, [sp], 32 - ret -#endif - .size _(__atomic_compare_exchange_1), .-_(__atomic_compare_exchange_1) - - .global _(__atomic_compare_exchange_2) - .type _(__atomic_compare_exchange_2), %function -_(__atomic_compare_exchange_2): -#ifdef __TINYC__ - .int 0xa9be7bfd - .int 0x910003fd - .int 0xa90153f3 - .int 0xaa0103f3 - .int 0x12003c41 - .int 0xaa0003e2 - .int 0x79400274 - .int 0x2a1403e0 - .int 0x53003c10 - .int 0x485ffc40 - .int 0x6b10001f - .int 0x54000061 - .int 0x4811fc41 - .int 0x35ffff91 - .int 0x6b34201f - .int 0x1a9f17e1 - .int 0x54000040 - .int 0x79000260 - .int 0x2a0103e0 - .int 0xa94153f3 - .int 0xa8c27bfd - .int 0xd65f03c0 -#else - stp x29, x30, [sp, -32]! - mov x29, sp - stp x19, x20, [sp, 16] - mov x19, x1 - and w1, w2, 65535 - mov x2, x0 - ldrh w20, [x19] - mov w0, w20 - uxth w16, w0 -.L4: - ldaxrh w0, [x2] - cmp w0, w16 - b.ne .L5 - stlxrh w17, w1, [x2] - cbnz w17, .L4 -.L5: - cmp w0, w20, uxth - cset w1, eq - beq .L6 - strh w0, [x19] -.L6: - mov w0, w1 - ldp x19, x20, [sp, 16] - ldp x29, x30, [sp], 32 - ret -#endif - .size _(__atomic_compare_exchange_2), .-_(__atomic_compare_exchange_2) - - .global _(__atomic_compare_exchange_4) - .type _(__atomic_compare_exchange_4), %function -_(__atomic_compare_exchange_4): -#ifdef __TINYC__ - .int 0xa9be7bfd - .int 0x910003fd - .int 0xa90153f3 - .int 0xaa0103f3 - .int 0x2a0203e1 - .int 0xaa0003e2 - .int 0xb9400274 - .int 0x2a1403e0 - .int 0x2a0003f0 - .int 0x885ffc40 - .int 0x6b10001f - .int 0x54000061 - .int 0x8811fc41 - .int 0x35ffff91 - .int 0x6b14001f - .int 0x1a9f17e1 - .int 0x54000040 - .int 0xb9000260 - .int 0x2a0103e0 - .int 0xa94153f3 - .int 0xa8c27bfd - .int 0xd65f03c0 -#else - stp x29, x30, [sp, -32]! - mov x29, sp - stp x19, x20, [sp, 16] - mov x19, x1 - mov w1, w2 - mov x2, x0 - ldr w20, [x19] - mov w0, w20 - mov w16, w0 -.L7: - ldaxr w0, [x2] - cmp w0, w16 - b.ne .L8 - stlxr w17, w1, [x2] - cbnz w17, .L7 -.L8: - cmp w0, w20 - cset w1, eq - beq .L9 - str w0, [x19] -.L9: - mov w0, w1 - ldp x19, x20, [sp, 16] - ldp x29, x30, [sp], 32 - ret -#endif - .size _(__atomic_compare_exchange_4), .-_(__atomic_compare_exchange_4) - .global _(__atomic_compare_exchange_8) .type _(__atomic_compare_exchange_8), %function _(__atomic_compare_exchange_8): -#ifdef __TINYC__ - .int 0xa9be7bfd - .int 0x910003fd - .int 0xa90153f3 - .int 0xaa0103f3 - .int 0xaa0203e1 - .int 0xaa0003e2 - .int 0xf9400274 - .int 0xaa1403e0 - .int 0xaa0003f0 - .int 0xc85ffc40 - .int 0xeb10001f - .int 0x54000061 - .int 0xc811fc41 - .int 0x35ffff91 - .int 0xeb14001f - .int 0x1a9f17e1 - .int 0x54000040 - .int 0xf9000260 - .int 0x2a0103e0 - .int 0xa94153f3 - .int 0xa8c27bfd - .int 0xd65f03c0 -#else - stp x29, x30, [sp, -32]! - mov x29, sp - stp x19, x20, [sp, 16] - mov x19, x1 - mov x1, x2 - mov x2, x0 - ldr x20, [x19] - mov x0, x20 - mov x16, x0 -.L10: - ldaxr x0, [x2] - cmp x0, x16 - b.ne .L11 - stlxr w17, x1, [x2] - cbnz w17, .L10 -.L11: - cmp x0, x20 - cset w1, eq - beq .L12 - str x0, [x19] -.L12: - mov w0, w1 - ldp x19, x20, [sp, 16] - ldp x29, x30, [sp], 32 + endbr32 + push %edi + push %esi + push %ebx + mov 0x14(%esp),%esi + mov 0x1c(%esp),%ecx + mov 0x10(%esp),%edi + mov (%esi),%eax + mov 0x4(%esi),%edx + mov 0x18(%esp),%ebx + lock cmpxchg8b (%edi) + sete %cl + je .L___atomic_compare_exchange_8_02a + mov %eax,(%esi) + mov %edx,0x4(%esi) +.L___atomic_compare_exchange_8_02a: + pop %ebx + mov %ecx,%eax + pop %esi + pop %edi ret -#endif - .size _(__atomic_compare_exchange_8), .-_(__atomic_compare_exchange_8) + .size _(__atomic_compare_exchange_8), .-_(__atomic_compare_exchange_8) + + .global _(__atomic_test_and_set_1) + .type _(__atomic_test_and_set_1), %function +_(__atomic_test_and_set_1): + endbr32 + mov 0x4(%esp),%edx + mov $0x1,%eax + xchg %al,(%edx) + ret + .size _(__atomic_test_and_set_1), .-_(__atomic_test_and_set_1) + + .global _(__atomic_test_and_set_2) + .type _(__atomic_test_and_set_2), %function +_(__atomic_test_and_set_2): + endbr32 + mov 0x4(%esp),%edx + mov $0x1,%eax + xchg %al,(%edx) + ret + .size _(__atomic_test_and_set_2), .-_(__atomic_test_and_set_2) + + .global _(__atomic_test_and_set_4) + .type _(__atomic_test_and_set_4), %function +_(__atomic_test_and_set_4): + endbr32 + mov 0x4(%esp),%edx + mov $0x1,%eax + xchg %al,(%edx) + ret + .size _(__atomic_test_and_set_4), .-_(__atomic_test_and_set_4) + + .global _(__atomic_test_and_set_8) + .type _(__atomic_test_and_set_8), %function +_(__atomic_test_and_set_8): + endbr32 + mov 0x4(%esp),%edx + mov $0x1,%eax + xchg %al,(%edx) + ret + .size _(__atomic_test_and_set_8), .-_(__atomic_test_and_set_8) + + .global _(atomic_thread_fence) + .type _(atomic_thread_fence), %function +_(atomic_thread_fence): + endbr32 + lock orl $0x0,(%esp) + ret + .size _(atomic_thread_fence), .-_(atomic_thread_fence) + + .global _(atomic_signal_fence) + .type _(atomic_signal_fence), %function +_(atomic_signal_fence): + endbr32 + ret + .size _(atomic_signal_fence), .-_(atomic_signal_fence) + + .global _(atomic_flag_test_and_set) + .type _(atomic_flag_test_and_set), %function +_(atomic_flag_test_and_set): + endbr32 + mov 0x4(%esp),%edx + mov $0x1,%eax + xchg %al,(%edx) + ret + .size _(atomic_flag_test_and_set), .-_(atomic_flag_test_and_set) + + .global _(atomic_flag_test_and_set_explicit) + .type _(atomic_flag_test_and_set_explicit), %function +_(atomic_flag_test_and_set_explicit): + endbr32 + mov 0x4(%esp),%edx + mov $0x1,%eax + xchg %al,(%edx) + ret + .size _(atomic_flag_test_and_set_explicit), .-_(atomic_flag_test_and_set_explicit) + + .global _(atomic_flag_clear) + .type _(atomic_flag_clear), %function +_(atomic_flag_clear): + endbr32 + mov 0x4(%esp),%edx + xor %eax,%eax + xchg %al,(%edx) + ret + .size _(atomic_flag_clear), .-_(atomic_flag_clear) + + .global _(atomic_flag_clear_explicit) + .type _(atomic_flag_clear_explicit), %function +_(atomic_flag_clear_explicit): + endbr32 + mov 0x4(%esp),%edx + xor %eax,%eax + xchg %al,(%edx) + ret + .size _(atomic_flag_clear_explicit), .-_(atomic_flag_clear_explicit) + +#endif //__i386__ /* ---------------------------------------------- */ -#elif defined __riscv - +#if defined __x86_64__ .text .align 2 - .global _(fetch_and_add_riscv64) - .type _(fetch_and_add_riscv64), %function -_(fetch_and_add_riscv64): -#ifdef __TINYC__ - .int 0x0f50000f - .int 0x004b5202f - .short 0x8082 -#else - fence iorw,ow - amoadd.w.aq zero,a1,0(a0) + .global _(__atomic_load_1) + .type _(__atomic_load_1), %function +_(__atomic_load_1): + endbr64 + movzbl (%rdi),%eax ret -#endif - .size _(fetch_and_add_riscv64), .-_(fetch_and_add_riscv64) + .size _(__atomic_load_1), .-_(__atomic_load_1) - .global _(__atomic_test_and_set) - .type _(__atomic_test_and_set), %function -_(__atomic_test_and_set): -#ifdef __TINYC__ - .int 0x00357793 - .int 0x0037979b - .short 0x4685 - .short 0x9971 - .int 0x00f696bb - .int 0x0f50000f - .int 0x44d5272f - .int 0x00f7553b - .int 0x0ff57513 - .short 0x8082 -#else - andi a5,a0,3 - slliw a5,a5,3 - li a3,1 - andi a0,a0,-4 - sllw a3,a3,a5 - fence iorw,ow; amoor.w.aq a4,a3,0(a0) - srlw a0,a4,a5 - andi a0,a0,0xff + .global _(__atomic_load_2) + .type _(__atomic_load_2), %function +_(__atomic_load_2): + endbr64 + movzwl (%rdi),%eax ret -#endif - .size _(__atomic_test_and_set), .-_(__atomic_test_and_set) + .size _(__atomic_load_2), .-_(__atomic_load_2) - .global _(__atomic_clear) - .type _(__atomic_clear), %function -_(__atomic_clear): -#ifdef __TINYC__ - .int 0x0ff0000f - .int 0x00050023 - .int 0x0ff0000f - .short 0x8082 -#else - fence iorw,iorw - sb zero,0(a0) - fence iorw,iorw + .global _(__atomic_load_4) + .type _(__atomic_load_4), %function +_(__atomic_load_4): + endbr64 + mov (%rdi),%eax ret -#endif - .size _(__atomic_clear), .-_(__atomic_clear) + .size _(__atomic_load_4), .-_(__atomic_load_4) + + .global _(__atomic_load_8) + .type _(__atomic_load_8), %function +_(__atomic_load_8): + endbr64 + mov (%rdi),%rax + ret + .size _(__atomic_load_8), .-_(__atomic_load_8) + + .global _(__atomic_store_1) + .type _(__atomic_store_1), %function +_(__atomic_store_1): + endbr64 + xchg %sil,(%rdi) + ret + .size _(__atomic_store_1), .-_(__atomic_store_1) + + .global _(__atomic_store_2) + .type _(__atomic_store_2), %function +_(__atomic_store_2): + endbr64 + xchg %si,(%rdi) + ret + .size _(__atomic_store_2), .-_(__atomic_store_2) + + .global _(__atomic_store_4) + .type _(__atomic_store_4), %function +_(__atomic_store_4): + endbr64 + xchg %esi,(%rdi) + ret + .size _(__atomic_store_4), .-_(__atomic_store_4) + + .global _(__atomic_store_8) + .type _(__atomic_store_8), %function +_(__atomic_store_8): + endbr64 + xchg %rsi,(%rdi) + ret + .size _(__atomic_store_8), .-_(__atomic_store_8) .global _(__atomic_compare_exchange_1) .type _(__atomic_compare_exchange_1), %function _(__atomic_compare_exchange_1): -#ifdef __TINYC__ - .short 0x1141 - .short 0x86ba - .short 0x873e - .short 0xe406 - .int 0x0ff0000f - .int 0x0005c803 - .int 0xff857893 - .int 0x0008b783 - .short 0x891d - .short 0x050e - .int 0x0ff00693 - .int 0x00a696b3 - .int 0x00a81833 - .int 0x00a61633 - .int 0xfff6c713 - .short 0x8f7d - .int 0x00f6f333 - .short 0x8f51 - .int 0x03031263 - .int 0x1008b32f - .int 0x00f31663 - .int 0x18e8be2f - .int 0xfe0e1ae3 - .int 0x40f30733 - .short 0x879a - .short 0xff69 - .int 0x0ff0000f - .short 0x4505 - .short 0xa801 - .int 0x00a7d7b3 - .int 0x00f58023 - .int 0x0ff0000f - .short 0x4501 - .short 0x60a2 - .short 0x0141 - .short 0x8082 -#else - addi sp,sp,-16 - mv a3,a4 - mv a4,a5 - sd ra,8(sp) - fence - lbu a6,0(a1) - andi a7,a0,-8 - ld a5,0(a7) - andi a0,a0,7 - slli a0,a0,0x3 - li a3,255 - sll a3,a3,a0 - sll a6,a6,a0 - sll a2,a2,a0 -.L1: - not a4,a3 - and a4,a4,a5 - and t1,a3,a5 - or a4,a4,a2 - bne t1,a6,.L4 -.L2: - lr.d t1,(a7) - bne t1,a5,.L3 - sc.d t3,a4,(a7) - bnez t3,.L2 -.L3: - sub a4,t1,a5 - mv a5,t1 - bnez a4,.L1 - fence - li a0,1 - j .L5 -.L4: - srl a5,a5,a0 - sb a5,0(a1) - fence - li a0,0 -.L5: - ld ra,8(sp) - addi sp,sp,16 - jr ra -#endif - .size _(__atomic_compare_exchange_1), .-_(__atomic_compare_exchange_1) + endbr64 + movzbl (%rsi),%eax + lock cmpxchg %dl,(%rdi) + sete %dl + je .L___atomic_compare_exchange_1_012 + mov %al,(%rsi) +.L___atomic_compare_exchange_1_012: + mov %edx,%eax + ret + .size _(__atomic_compare_exchange_1), .-_(__atomic_compare_exchange_1) .global _(__atomic_compare_exchange_2) .type _(__atomic_compare_exchange_2), %function _(__atomic_compare_exchange_2): -#ifdef __TINYC__ - .short 0x1141 - .short 0x86ba - .short 0x873e - .short 0xe406 - .int 0x0ff0000f - .int 0x0005d803 - .int 0xff857893 - .short 0x67c1 - .short 0x891d - .int 0x0008b703 - .short 0x050e - .short 0x17fd - .int 0x00a797b3 - .int 0x00a81833 - .int 0x00a61633 - .int 0xfff7c693 - .short 0x8ef9 - .int 0x00e7f333 - .short 0x8ed1 - .int 0x03031263 - .int 0x1008b32f - .int 0x00e31663 - .int 0x18d8be2f - .int 0xfe0e1ae3 - .int 0x40e306b3 - .short 0x871a - .short 0xfee9 - .int 0x0ff0000f - .short 0x4505 - .short 0xa801 - .int 0x00a75733 - .int 0x00e59023 - .int 0x0ff0000f - .short 0x4501 - .short 0x60a2 - .short 0x0141 - .short 0x8082 -#else - addi sp,sp,-16 - mv a3,a4 - mv a4,a5 - sd ra,8(sp) - fence - lhu a6,0(a1) - andi a7,a0,-8 - lui a5,0x10 - andi a0,a0,7 - ld a4,0(a7) - slli a0,a0,0x3 - addi a5,a5,-1 - sll a5,a5,a0 - sll a6,a6,a0 - sll a2,a2,a0 -.L6: - not a3,a5 - and a3,a3,a4 - and t1,a5,a4 - or a3,a3,a2 - bne t1,a6,.L9 -.L7: - lr.d t1,(a7) - bne t1,a4,.L8 - sc.d t3,a3,(a7) - bnez t3,.L7 -.L8: - sub a3,t1,a4 - mv a4,t1 - bnez a3,.L6 - fence - li a0,1 - j .L10 -.L9: - srl a4,a4,a0 - sh a4,0(a1) - fence - li a0,0 -.L10: - ld ra,8(sp) - addi sp,sp,16 - jr ra -#endif - .size _(__atomic_compare_exchange_2), .-_(__atomic_compare_exchange_2) + endbr64 + movzwl (%rsi),%eax + lock cmpxchg %dx,(%rdi) + sete %dl + je .L___atomic_compare_exchange_2_014 + mov %ax,(%rsi) +.L___atomic_compare_exchange_2_014: + mov %edx,%eax + ret + .size _(__atomic_compare_exchange_2), .-_(__atomic_compare_exchange_2) .global _(__atomic_compare_exchange_4) .type _(__atomic_compare_exchange_4), %function _(__atomic_compare_exchange_4): + endbr64 + mov (%rsi),%eax + lock cmpxchg %edx,(%rdi) + sete %dl + je .L___atomic_compare_exchange_4_011 + mov %eax,(%rsi) +.L___atomic_compare_exchange_4_011: + mov %edx,%eax + ret + .size _(__atomic_compare_exchange_4), .-_(__atomic_compare_exchange_4) + + .global _(__atomic_compare_exchange_8) + .type _(__atomic_compare_exchange_8), %function +_(__atomic_compare_exchange_8): + endbr64 + mov (%rsi),%rax + lock cmpxchg %rdx,(%rdi) + sete %dl + je .L___atomic_compare_exchange_8_014 + mov %rax,(%rsi) +.L___atomic_compare_exchange_8_014: + mov %edx,%eax + ret + .size _(__atomic_compare_exchange_8), .-_(__atomic_compare_exchange_8) + + .global _(__atomic_test_and_set_1) + .type _(__atomic_test_and_set_1), %function +_(__atomic_test_and_set_1): + endbr64 + mov $0x1,%eax + xchg %al,(%rdi) + ret + .size _(__atomic_test_and_set_1), .-_(__atomic_test_and_set_1) + + .global _(__atomic_test_and_set_2) + .type _(__atomic_test_and_set_2), %function +_(__atomic_test_and_set_2): + endbr64 + mov $0x1,%eax + xchg %al,(%rdi) + ret + .size _(__atomic_test_and_set_2), .-_(__atomic_test_and_set_2) + + .global _(__atomic_test_and_set_4) + .type _(__atomic_test_and_set_4), %function +_(__atomic_test_and_set_4): + endbr64 + mov $0x1,%eax + xchg %al,(%rdi) + ret + .size _(__atomic_test_and_set_4), .-_(__atomic_test_and_set_4) + + .global _(__atomic_test_and_set_8) + .type _(__atomic_test_and_set_8), %function +_(__atomic_test_and_set_8): + endbr64 + mov $0x1,%eax + xchg %al,(%rdi) + ret + .size _(__atomic_test_and_set_8), .-_(__atomic_test_and_set_8) + + .global _(atomic_thread_fence) + .type _(atomic_thread_fence), %function +_(atomic_thread_fence): + endbr64 + lock orq $0x0,(%rsp) + ret + .size _(atomic_thread_fence), .-_(atomic_thread_fence) + + .global _(atomic_signal_fence) + .type _(atomic_signal_fence), %function +_(atomic_signal_fence): + endbr64 + ret + .size _(atomic_signal_fence), .-_(atomic_signal_fence) + + .global _(atomic_flag_test_and_set) + .type _(atomic_flag_test_and_set), %function +_(atomic_flag_test_and_set): + endbr64 + mov $0x1,%eax + xchg %al,(%rdi) + ret + .size _(atomic_flag_test_and_set), .-_(atomic_flag_test_and_set) + + .global _(atomic_flag_test_and_set_explicit) + .type _(atomic_flag_test_and_set_explicit), %function +_(atomic_flag_test_and_set_explicit): + endbr64 + mov $0x1,%eax + xchg %al,(%rdi) + ret + .size _(atomic_flag_test_and_set_explicit), .-_(atomic_flag_test_and_set_explicit) + + .global _(atomic_flag_clear) + .type _(atomic_flag_clear), %function +_(atomic_flag_clear): + endbr64 + xor %eax,%eax + xchg %al,(%rdi) + ret + .size _(atomic_flag_clear), .-_(atomic_flag_clear) + + .global _(atomic_flag_clear_explicit) + .type _(atomic_flag_clear_explicit), %function +_(atomic_flag_clear_explicit): + endbr64 + xor %eax,%eax + xchg %al,(%rdi) + ret + .size _(atomic_flag_clear_explicit), .-_(atomic_flag_clear_explicit) + +#endif //__x86_64__ + +/* ---------------------------------------------- */ +#if defined __arm__ + .text + .align 2 + .thumb + .syntax unified + + .global _(__atomic_load_1) + .type _(__atomic_load_1), %function +_(__atomic_load_1): +#ifdef __TINYC__ + .short 0xb911 + .short 0x7800 + .short 0xb2c0 + .short 0x4770 + .short 0xf3bf + .short 0x7800 + .short 0xf3bf + .short 0xb2c0 + .short 0x4770 +#else + cbnz r1, .L___atomic_load_1_008 + ldrb r0, [r0, #0] + uxtb r0, r0 + bx lr +.L___atomic_load_1_008: + dmb ish + ldrb r0, [r0, #0] + dmb ish + uxtb r0, r0 + bx lr + .size _(__atomic_load_1), .-_(__atomic_load_1) + +#endif + .global _(__atomic_load_2) + .type _(__atomic_load_2), %function +_(__atomic_load_2): +#ifdef __TINYC__ + .short 0xb911 + .short 0x8800 + .short 0xb280 + .short 0x4770 + .short 0xf3bf + .short 0x8800 + .short 0xf3bf + .short 0xb280 + .short 0x4770 +#else + cbnz r1, .L___atomic_load_2_008 + ldrh r0, [r0, #0] + uxth r0, r0 + bx lr +.L___atomic_load_2_008: + dmb ish + ldrh r0, [r0, #0] + dmb ish + uxth r0, r0 + bx lr + .size _(__atomic_load_2), .-_(__atomic_load_2) + +#endif + .global _(__atomic_load_4) + .type _(__atomic_load_4), %function +_(__atomic_load_4): +#ifdef __TINYC__ + .short 0xb909 + .short 0x6800 + .short 0x4770 + .short 0xf3bf + .short 0x6800 + .short 0xf3bf + .short 0x4770 +#else + cbnz r1, .L___atomic_load_4_006 + ldr r0, [r0, #0] + bx lr +.L___atomic_load_4_006: + dmb ish + ldr r0, [r0, #0] + dmb ish + bx lr + .size _(__atomic_load_4), .-_(__atomic_load_4) + +#endif + .global _(__atomic_load_8) + .type _(__atomic_load_8), %function +_(__atomic_load_8): +#ifdef __TINYC__ + .short 0xb911 + .short 0xe8d0 + .short 0x4770 + .short 0xf3bf + .short 0xe8d0 + .short 0xf3bf + .short 0x4770 +#else + cbnz r1, .L___atomic_load_8_008 + ldrexd r0, r1, [r0] + bx lr +.L___atomic_load_8_008: + dmb ish + ldrexd r0, r1, [r0] + dmb ish + bx lr + .size _(__atomic_load_8), .-_(__atomic_load_8) + +#endif + .global _(__atomic_store_1) + .type _(__atomic_store_1), %function +_(__atomic_store_1): +#ifdef __TINYC__ + .short 0xb90a + .short 0x7001 + .short 0x4770 + .short 0xf3bf + .short 0x7001 + .short 0xf3bf + .short 0x4770 +#else + cbnz r2, .L___atomic_store_1_006 + strb r1, [r0, #0] + bx lr +.L___atomic_store_1_006: + dmb ish + strb r1, [r0, #0] + dmb ish + bx lr + .size _(__atomic_store_1), .-_(__atomic_store_1) + +#endif + .global _(__atomic_store_2) + .type _(__atomic_store_2), %function +_(__atomic_store_2): +#ifdef __TINYC__ + .short 0xb90a + .short 0x8001 + .short 0x4770 + .short 0xf3bf + .short 0x8001 + .short 0xf3bf + .short 0x4770 +#else + cbnz r2, .L___atomic_store_2_006 + strh r1, [r0, #0] + bx lr +.L___atomic_store_2_006: + dmb ish + strh r1, [r0, #0] + dmb ish + bx lr + .size _(__atomic_store_2), .-_(__atomic_store_2) + +#endif + .global _(__atomic_store_4) + .type _(__atomic_store_4), %function +_(__atomic_store_4): +#ifdef __TINYC__ + .short 0xb90a + .short 0x6001 + .short 0x4770 + .short 0xf3bf + .short 0x6001 + .short 0xf3bf + .short 0x4770 +#else + cbnz r2, .L___atomic_store_4_006 + str r1, [r0, #0] + bx lr +.L___atomic_store_4_006: + dmb ish + str r1, [r0, #0] + dmb ish + bx lr + .size _(__atomic_store_4), .-_(__atomic_store_4) + +#endif + .global _(__atomic_store_8) + .type _(__atomic_store_8), %function +_(__atomic_store_8): +#ifdef __TINYC__ + .short 0xb430 + .short 0x4614 + .short 0x9902 + .short 0x461d + .short 0xb939 + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xbc30 + .short 0x4770 + .short 0xf3bf + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xf3bf + .short 0xbc30 + .short 0x4770 +#else + push {r4, r5} + mov r4, r2 + ldr r1, [sp, #8] + mov r5, r3 + cbnz r1, .L___atomic_store_8_01a +.L___atomic_store_8_00a: + ldrexd r2, r3, [r0] + strexd r1, r4, r5, [r0] + cmp r1, #0 + bne.n .L___atomic_store_8_00a + pop {r4, r5} + bx lr +.L___atomic_store_8_01a: + dmb ish +.L___atomic_store_8_01e: + ldrexd r2, r3, [r0] + strexd r1, r4, r5, [r0] + cmp r1, #0 + bne.n .L___atomic_store_8_01e + dmb ish + pop {r4, r5} + bx lr + .size _(__atomic_store_8), .-_(__atomic_store_8) + +#endif + .global _(__atomic_compare_exchange_1) + .type _(__atomic_compare_exchange_1), %function +_(__atomic_compare_exchange_1): +#ifdef __TINYC__ + .short 0xb500 + .short 0xb983 + .short 0x780b + .short 0xe8d0 + .short 0x459c + .short 0xd104 + .short 0xe8c0 + .short 0xf1be + .short 0xd1f6 + .short 0xbf0e + .short 0x2001 + .short 0x2000 + .short 0xf881 + .short 0xf85d + .short 0x780b + .short 0xf3bf + .short 0xe8d0 + .short 0x459c + .short 0xd1f1 + .short 0xe8c0 + .short 0xf1be + .short 0xd1f6 + .short 0xf3bf + .short 0xe7e9 +#else + push {lr} + cbnz r3, .L___atomic_compare_exchange_1_026 + ldrb r3, [r1, #0] +.L___atomic_compare_exchange_1_006: + ldrexb ip, [r0] + cmp ip, r3 + bne.n .L___atomic_compare_exchange_1_018 + strexb lr, r2, [r0] + cmp.w lr, #0 + bne.n .L___atomic_compare_exchange_1_006 +.L___atomic_compare_exchange_1_018: + itee eq + moveq r0, #1 + movne r0, #0 + strbne.w ip, [r1] + ldr.w pc, [sp], #4 +.L___atomic_compare_exchange_1_026: + ldrb r3, [r1, #0] + dmb ish +.L___atomic_compare_exchange_1_02c: + ldrexb ip, [r0] + cmp ip, r3 + bne.n .L___atomic_compare_exchange_1_018 + strexb lr, r2, [r0] + cmp.w lr, #0 + bne.n .L___atomic_compare_exchange_1_02c + dmb ish + b.n .L___atomic_compare_exchange_1_018 + .size _(__atomic_compare_exchange_1), .-_(__atomic_compare_exchange_1) + +#endif + .global _(__atomic_compare_exchange_2) + .type _(__atomic_compare_exchange_2), %function +_(__atomic_compare_exchange_2): +#ifdef __TINYC__ + .short 0xb500 + .short 0xb983 + .short 0x880b + .short 0xe8d0 + .short 0x459c + .short 0xd104 + .short 0xe8c0 + .short 0xf1be + .short 0xd1f6 + .short 0xbf0e + .short 0x2001 + .short 0x2000 + .short 0xf8a1 + .short 0xf85d + .short 0x880b + .short 0xf3bf + .short 0xe8d0 + .short 0x459c + .short 0xd1f1 + .short 0xe8c0 + .short 0xf1be + .short 0xd1f6 + .short 0xf3bf + .short 0xe7e9 +#else + push {lr} + cbnz r3, .L___atomic_compare_exchange_2_026 + ldrh r3, [r1, #0] +.L___atomic_compare_exchange_2_006: + ldrexh ip, [r0] + cmp ip, r3 + bne.n .L___atomic_compare_exchange_2_018 + strexh lr, r2, [r0] + cmp.w lr, #0 + bne.n .L___atomic_compare_exchange_2_006 +.L___atomic_compare_exchange_2_018: + itee eq + moveq r0, #1 + movne r0, #0 + strhne.w ip, [r1] + ldr.w pc, [sp], #4 +.L___atomic_compare_exchange_2_026: + ldrh r3, [r1, #0] + dmb ish +.L___atomic_compare_exchange_2_02c: + ldrexh ip, [r0] + cmp ip, r3 + bne.n .L___atomic_compare_exchange_2_018 + strexh lr, r2, [r0] + cmp.w lr, #0 + bne.n .L___atomic_compare_exchange_2_02c + dmb ish + b.n .L___atomic_compare_exchange_2_018 + .size _(__atomic_compare_exchange_2), .-_(__atomic_compare_exchange_2) + +#endif + .global _(__atomic_compare_exchange_4) + .type _(__atomic_compare_exchange_4), %function +_(__atomic_compare_exchange_4): +#ifdef __TINYC__ + .short 0xb410 + .short 0xb983 + .short 0x680b + .short 0xe850 + .short 0x429c + .short 0xd104 + .short 0xe840 + .short 0xf1bc + .short 0xd1f6 + .short 0xbf0e + .short 0x2001 + .short 0x2000 + .short 0x600c + .short 0xf85d + .short 0x4770 + .short 0x680b + .short 0xf3bf + .short 0xe850 + .short 0x429c + .short 0xd1f1 + .short 0xe840 + .short 0xf1bc + .short 0xd1f6 + .short 0xf3bf + .short 0xe7e9 +#else + push {r4} + cbnz r3, .L___atomic_compare_exchange_4_026 + ldr r3, [r1, #0] +.L___atomic_compare_exchange_4_006: + ldrex r4, [r0] + cmp r4, r3 + bne.n .L___atomic_compare_exchange_4_018 + strex ip, r2, [r0] + cmp.w ip, #0 + bne.n .L___atomic_compare_exchange_4_006 +.L___atomic_compare_exchange_4_018: + itee eq + moveq r0, #1 + movne r0, #0 + strne r4, [r1, #0] + ldr.w r4, [sp], #4 + bx lr +.L___atomic_compare_exchange_4_026: + ldr r3, [r1, #0] + dmb ish +.L___atomic_compare_exchange_4_02c: + ldrex r4, [r0] + cmp r4, r3 + bne.n .L___atomic_compare_exchange_4_018 + strex ip, r2, [r0] + cmp.w ip, #0 + bne.n .L___atomic_compare_exchange_4_02c + dmb ish + b.n .L___atomic_compare_exchange_4_018 + .size _(__atomic_compare_exchange_4), .-_(__atomic_compare_exchange_4) + +#endif + .global _(__atomic_compare_exchange_8) + .type _(__atomic_compare_exchange_8), %function +_(__atomic_compare_exchange_8): +#ifdef __TINYC__ + .short 0xb4f0 + .short 0x461d + .short 0x9b04 + .short 0x4614 + .short 0xb99b + .short 0xe9d1 + .short 0xe8d0 + .short 0x429f + .short 0xbf08 + .short 0x4296 + .short 0xd104 + .short 0xe8c0 + .short 0xf1bc + .short 0xd1f4 + .short 0xbf0e + .short 0x2001 + .short 0x2000 + .short 0xe9c1 + .short 0xbcf0 + .short 0x4770 + .short 0xe9d1 + .short 0xf3bf + .short 0xe8d0 + .short 0x429f + .short 0xbf08 + .short 0x4296 + .short 0xd1ee + .short 0xe8c0 + .short 0xf1bc + .short 0xd1f4 + .short 0xf3bf + .short 0xe7e6 +#else + push {r4, r5, r6, r7} + mov r5, r3 + ldr r3, [sp, #16] + mov r4, r2 + cbnz r3, .L___atomic_compare_exchange_8_032 + ldrd r2, r3, [r1] +.L___atomic_compare_exchange_8_00e: + ldrexd r6, r7, [r0] + cmp r7, r3 + it eq + cmpeq r6, r2 + bne.n .L___atomic_compare_exchange_8_024 + strexd ip, r4, r5, [r0] + cmp.w ip, #0 + bne.n .L___atomic_compare_exchange_8_00e +.L___atomic_compare_exchange_8_024: + itee eq + moveq r0, #1 + movne r0, #0 + strdne r6, r7, [r1] + pop {r4, r5, r6, r7} + bx lr +.L___atomic_compare_exchange_8_032: + ldrd r2, r3, [r1] + dmb ish +.L___atomic_compare_exchange_8_03a: + ldrexd r6, r7, [r0] + cmp r7, r3 + it eq + cmpeq r6, r2 + bne.n .L___atomic_compare_exchange_8_024 + strexd ip, r4, r5, [r0] + cmp.w ip, #0 + bne.n .L___atomic_compare_exchange_8_03a + dmb ish + b.n .L___atomic_compare_exchange_8_024 + .size _(__atomic_compare_exchange_8), .-_(__atomic_compare_exchange_8) + +#endif + .global _(__atomic_test_and_set_1) + .type _(__atomic_test_and_set_1), %function +_(__atomic_test_and_set_1): +#ifdef __TINYC__ + .short 0xf04f + .short 0xb939 + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xb2d8 + .short 0x4770 + .short 0xf3bf + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xb2d8 + .short 0xf3bf + .short 0x4770 +#else + mov.w r2, #1 + cbnz r1, .L___atomic_test_and_set_1_016 +.L___atomic_test_and_set_1_006: + ldrexb r3, [r0] + strexb r1, r2, [r0] + cmp r1, #0 + bne.n .L___atomic_test_and_set_1_006 + uxtb r0, r3 + bx lr +.L___atomic_test_and_set_1_016: + dmb ish +.L___atomic_test_and_set_1_01a: + ldrexb r3, [r0] + strexb r1, r2, [r0] + cmp r1, #0 + bne.n .L___atomic_test_and_set_1_01a + uxtb r0, r3 + dmb ish + bx lr + .size _(__atomic_test_and_set_1), .-_(__atomic_test_and_set_1) + +#endif + .global _(__atomic_test_and_set_2) + .type _(__atomic_test_and_set_2), %function +_(__atomic_test_and_set_2): +#ifdef __TINYC__ + .short 0xf04f + .short 0xb939 + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xb2d8 + .short 0x4770 + .short 0xf3bf + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xb2d8 + .short 0xf3bf + .short 0x4770 +#else + mov.w r2, #1 + cbnz r1, .L___atomic_test_and_set_2_016 +.L___atomic_test_and_set_2_006: + ldrexb r3, [r0] + strexb r1, r2, [r0] + cmp r1, #0 + bne.n .L___atomic_test_and_set_2_006 + uxtb r0, r3 + bx lr +.L___atomic_test_and_set_2_016: + dmb ish +.L___atomic_test_and_set_2_01a: + ldrexb r3, [r0] + strexb r1, r2, [r0] + cmp r1, #0 + bne.n .L___atomic_test_and_set_2_01a + uxtb r0, r3 + dmb ish + bx lr + .size _(__atomic_test_and_set_2), .-_(__atomic_test_and_set_2) + +#endif + .global _(__atomic_test_and_set_4) + .type _(__atomic_test_and_set_4), %function +_(__atomic_test_and_set_4): +#ifdef __TINYC__ + .short 0xf04f + .short 0xb939 + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xb2d8 + .short 0x4770 + .short 0xf3bf + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xb2d8 + .short 0xf3bf + .short 0x4770 +#else + mov.w r2, #1 + cbnz r1, .L___atomic_test_and_set_4_016 +.L___atomic_test_and_set_4_006: + ldrexb r3, [r0] + strexb r1, r2, [r0] + cmp r1, #0 + bne.n .L___atomic_test_and_set_4_006 + uxtb r0, r3 + bx lr +.L___atomic_test_and_set_4_016: + dmb ish +.L___atomic_test_and_set_4_01a: + ldrexb r3, [r0] + strexb r1, r2, [r0] + cmp r1, #0 + bne.n .L___atomic_test_and_set_4_01a + uxtb r0, r3 + dmb ish + bx lr + .size _(__atomic_test_and_set_4), .-_(__atomic_test_and_set_4) + +#endif + .global _(__atomic_test_and_set_8) + .type _(__atomic_test_and_set_8), %function +_(__atomic_test_and_set_8): +#ifdef __TINYC__ + .short 0xf04f + .short 0xb939 + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xb2d8 + .short 0x4770 + .short 0xf3bf + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xb2d8 + .short 0xf3bf + .short 0x4770 +#else + mov.w r2, #1 + cbnz r1, .L___atomic_test_and_set_8_016 +.L___atomic_test_and_set_8_006: + ldrexb r3, [r0] + strexb r1, r2, [r0] + cmp r1, #0 + bne.n .L___atomic_test_and_set_8_006 + uxtb r0, r3 + bx lr +.L___atomic_test_and_set_8_016: + dmb ish +.L___atomic_test_and_set_8_01a: + ldrexb r3, [r0] + strexb r1, r2, [r0] + cmp r1, #0 + bne.n .L___atomic_test_and_set_8_01a + uxtb r0, r3 + dmb ish + bx lr + .size _(__atomic_test_and_set_8), .-_(__atomic_test_and_set_8) + +#endif + .global _(atomic_thread_fence) + .type _(atomic_thread_fence), %function +_(atomic_thread_fence): +#ifdef __TINYC__ + .short 0xf3bf + .short 0x4770 +#else + dmb ish + bx lr + .size _(atomic_thread_fence), .-_(atomic_thread_fence) + +#endif + .global _(atomic_signal_fence) + .type _(atomic_signal_fence), %function +_(atomic_signal_fence): +#ifdef __TINYC__ + .short 0x4770 +#else + bx lr + .size _(atomic_signal_fence), .-_(atomic_signal_fence) + +#endif + .global _(atomic_flag_test_and_set) + .type _(atomic_flag_test_and_set), %function +_(atomic_flag_test_and_set): +#ifdef __TINYC__ + .short 0xf04f + .short 0xf3bf + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xb2d8 + .short 0xf3bf + .short 0x4770 +#else + mov.w r2, #1 + dmb ish +.L_atomic_flag_test_and_set_008: + ldrexb r3, [r0] + strexb r1, r2, [r0] + cmp r1, #0 + bne.n .L_atomic_flag_test_and_set_008 + uxtb r0, r3 + dmb ish + bx lr + .size _(atomic_flag_test_and_set), .-_(atomic_flag_test_and_set) + +#endif + .global _(atomic_flag_test_and_set_explicit) + .type _(atomic_flag_test_and_set_explicit), %function +_(atomic_flag_test_and_set_explicit): +#ifdef __TINYC__ + .short 0xf04f + .short 0xf3bf + .short 0xe8d0 + .short 0xe8c0 + .short 0x2900 + .short 0xd1f9 + .short 0xb2d8 + .short 0xf3bf + .short 0x4770 +#else + mov.w r2, #1 + dmb ish +.L_atomic_flag_test_and_set_explicit_024: + ldrexb r3, [r0] + strexb r1, r2, [r0] + cmp r1, #0 + bne.n .L_atomic_flag_test_and_set_explicit_024 + uxtb r0, r3 + dmb ish + bx lr + .size _(atomic_flag_test_and_set_explicit), .-_(atomic_flag_test_and_set_explicit) + +#endif + .global _(atomic_flag_clear) + .type _(atomic_flag_clear), %function +_(atomic_flag_clear): +#ifdef __TINYC__ + .short 0x2300 + .short 0xf3bf + .short 0x7003 + .short 0xf3bf + .short 0x4770 +#else + movs r3, #0 + dmb ish + strb r3, [r0, #0] + dmb ish + bx lr + .size _(atomic_flag_clear), .-_(atomic_flag_clear) + +#endif + .global _(atomic_flag_clear_explicit) + .type _(atomic_flag_clear_explicit), %function +_(atomic_flag_clear_explicit): +#ifdef __TINYC__ + .short 0x2300 + .short 0xf3bf + .short 0x7003 + .short 0xf3bf + .short 0x4770 +#else + movs r3, #0 + dmb ish + strb r3, [r0, #0] + dmb ish + bx lr + .size _(atomic_flag_clear_explicit), .-_(atomic_flag_clear_explicit) + +#endif +#endif //__arm__ + +/* ---------------------------------------------- */ +#if defined __aarch64__ + .text + .align 2 + + .global _(__atomic_load_1) + .type _(__atomic_load_1), %function +_(__atomic_load_1): +#ifdef __TINYC__ + .int 0x35000081 + .int 0x39400000 + .int 0x12001c00 + .int 0xd65f03c0 + .int 0x08dffc00 + .int 0x12001c00 + .int 0xd65f03c0 +#else + cbnz w1, .L___atomic_load_1_010 + ldrb w0, [x0] + and w0, w0, #0xff + ret +.L___atomic_load_1_010: + ldarb w0, [x0] + and w0, w0, #0xff + ret + .size _(__atomic_load_1), .-_(__atomic_load_1) + +#endif + .global _(__atomic_load_2) + .type _(__atomic_load_2), %function +_(__atomic_load_2): +#ifdef __TINYC__ + .int 0x35000081 + .int 0x79400000 + .int 0x12003c00 + .int 0xd65f03c0 + .int 0x48dffc00 + .int 0x12003c00 + .int 0xd65f03c0 +#else + cbnz w1, .L___atomic_load_2_010 + ldrh w0, [x0] + and w0, w0, #0xffff + ret +.L___atomic_load_2_010: + ldarh w0, [x0] + and w0, w0, #0xffff + ret + .size _(__atomic_load_2), .-_(__atomic_load_2) + +#endif + .global _(__atomic_load_4) + .type _(__atomic_load_4), %function +_(__atomic_load_4): +#ifdef __TINYC__ + .int 0x35000061 + .int 0xb9400000 + .int 0xd65f03c0 + .int 0x88dffc00 + .int 0xd65f03c0 +#else + cbnz w1, .L___atomic_load_4_00c + ldr w0, [x0] + ret +.L___atomic_load_4_00c: + ldar w0, [x0] + ret + .size _(__atomic_load_4), .-_(__atomic_load_4) + +#endif + .global _(__atomic_load_8) + .type _(__atomic_load_8), %function +_(__atomic_load_8): +#ifdef __TINYC__ + .int 0x35000061 + .int 0xf9400000 + .int 0xd65f03c0 + .int 0xc8dffc00 + .int 0xd65f03c0 +#else + cbnz w1, .L___atomic_load_8_00c + ldr x0, [x0] + ret +.L___atomic_load_8_00c: + ldar x0, [x0] + ret + .size _(__atomic_load_8), .-_(__atomic_load_8) + +#endif + .global _(__atomic_store_1) + .type _(__atomic_store_1), %function +_(__atomic_store_1): +#ifdef __TINYC__ + .int 0x12001c21 + .int 0x35000062 + .int 0x39000001 + .int 0xd65f03c0 + .int 0x089ffc01 + .int 0xd65f03c0 +#else + and w1, w1, #0xff + cbnz w2, .L___atomic_store_1_010 + strb w1, [x0] + ret +.L___atomic_store_1_010: + stlrb w1, [x0] + ret + .size _(__atomic_store_1), .-_(__atomic_store_1) + +#endif + .global _(__atomic_store_2) + .type _(__atomic_store_2), %function +_(__atomic_store_2): +#ifdef __TINYC__ + .int 0x12003c21 + .int 0x35000062 + .int 0x79000001 + .int 0xd65f03c0 + .int 0x489ffc01 + .int 0xd65f03c0 +#else + and w1, w1, #0xffff + cbnz w2, .L___atomic_store_2_010 + strh w1, [x0] + ret +.L___atomic_store_2_010: + stlrh w1, [x0] + ret + .size _(__atomic_store_2), .-_(__atomic_store_2) + +#endif + .global _(__atomic_store_4) + .type _(__atomic_store_4), %function +_(__atomic_store_4): +#ifdef __TINYC__ + .int 0x35000062 + .int 0xb9000001 + .int 0xd65f03c0 + .int 0x889ffc01 + .int 0xd65f03c0 +#else + cbnz w2, .L___atomic_store_4_00c + str w1, [x0] + ret +.L___atomic_store_4_00c: + stlr w1, [x0] + ret + .size _(__atomic_store_4), .-_(__atomic_store_4) + +#endif + .global _(__atomic_store_8) + .type _(__atomic_store_8), %function +_(__atomic_store_8): +#ifdef __TINYC__ + .int 0x35000062 + .int 0xf9000001 + .int 0xd65f03c0 + .int 0xc89ffc01 + .int 0xd65f03c0 +#else + cbnz w2, .L___atomic_store_8_00c + str x1, [x0] + ret +.L___atomic_store_8_00c: + stlr x1, [x0] + ret + .size _(__atomic_store_8), .-_(__atomic_store_8) + +#endif + .global _(__atomic_compare_exchange_1) + .type _(__atomic_compare_exchange_1), %function +_(__atomic_compare_exchange_1): +#ifdef __TINYC__ + .int 0x12001c42 + .int 0x35000143 + .int 0x39400023 + .int 0x085f7c04 + .int 0x6b23009f + .int 0x54000061 + .int 0x08057c02 + .int 0x35ffff85 + .int 0x1a9f17e0 + .int 0x54000141 + .int 0xd65f03c0 + .int 0x39400023 + .int 0x085ffc04 + .int 0x6b23009f + .int 0x54000061 + .int 0x0805fc02 + .int 0x35ffff85 + .int 0x1a9f17e0 + .int 0x54ffff00 + .int 0x39000024 + .int 0xd65f03c0 +#else + and w2, w2, #0xff + cbnz w3, .L___atomic_compare_exchange_1_02c + ldrb w3, [x1] +.L___atomic_compare_exchange_1_00c: + ldxrb w4, [x0] + cmp w4, w3, uxtb + b.ne .L___atomic_compare_exchange_1_020 + stxrb w5, w2, [x0] + cbnz w5, .L___atomic_compare_exchange_1_00c +.L___atomic_compare_exchange_1_020: + cset w0, eq // eq = none + b.ne .L___atomic_compare_exchange_1_04c +.L___atomic_compare_exchange_1_028: + ret +.L___atomic_compare_exchange_1_02c: + ldrb w3, [x1] +.L___atomic_compare_exchange_1_030: + ldaxrb w4, [x0] + cmp w4, w3, uxtb + b.ne .L___atomic_compare_exchange_1_044 + stlxrb w5, w2, [x0] + cbnz w5, .L___atomic_compare_exchange_1_030 +.L___atomic_compare_exchange_1_044: + cset w0, eq // eq = none + b.eq .L___atomic_compare_exchange_1_028 +.L___atomic_compare_exchange_1_04c: + strb w4, [x1] + ret + .size _(__atomic_compare_exchange_1), .-_(__atomic_compare_exchange_1) + +#endif + .global _(__atomic_compare_exchange_2) + .type _(__atomic_compare_exchange_2), %function +_(__atomic_compare_exchange_2): +#ifdef __TINYC__ + .int 0x12003c42 + .int 0x35000143 + .int 0x79400023 + .int 0x485f7c04 + .int 0x6b23209f + .int 0x54000061 + .int 0x48057c02 + .int 0x35ffff85 + .int 0x1a9f17e0 + .int 0x54000141 + .int 0xd65f03c0 + .int 0x79400023 + .int 0x485ffc04 + .int 0x6b23209f + .int 0x54000061 + .int 0x4805fc02 + .int 0x35ffff85 + .int 0x1a9f17e0 + .int 0x54ffff00 + .int 0x79000024 + .int 0xd65f03c0 +#else + and w2, w2, #0xffff + cbnz w3, .L___atomic_compare_exchange_2_02c + ldrh w3, [x1] +.L___atomic_compare_exchange_2_00c: + ldxrh w4, [x0] + cmp w4, w3, uxth + b.ne .L___atomic_compare_exchange_2_020 + stxrh w5, w2, [x0] + cbnz w5, .L___atomic_compare_exchange_2_00c +.L___atomic_compare_exchange_2_020: + cset w0, eq // eq = none + b.ne .L___atomic_compare_exchange_2_04c +.L___atomic_compare_exchange_2_028: + ret +.L___atomic_compare_exchange_2_02c: + ldrh w3, [x1] +.L___atomic_compare_exchange_2_030: + ldaxrh w4, [x0] + cmp w4, w3, uxth + b.ne .L___atomic_compare_exchange_2_044 + stlxrh w5, w2, [x0] + cbnz w5, .L___atomic_compare_exchange_2_030 +.L___atomic_compare_exchange_2_044: + cset w0, eq // eq = none + b.eq .L___atomic_compare_exchange_2_028 +.L___atomic_compare_exchange_2_04c: + strh w4, [x1] + ret + .size _(__atomic_compare_exchange_2), .-_(__atomic_compare_exchange_2) + +#endif + .global _(__atomic_compare_exchange_4) + .type _(__atomic_compare_exchange_4), %function +_(__atomic_compare_exchange_4): +#ifdef __TINYC__ + .int 0x35000143 + .int 0xb9400023 + .int 0x885f7c04 + .int 0x6b03009f + .int 0x54000061 + .int 0x88057c02 + .int 0x35ffff85 + .int 0x1a9f17e0 + .int 0x54000141 + .int 0xd65f03c0 + .int 0xb9400023 + .int 0x885ffc04 + .int 0x6b03009f + .int 0x54000061 + .int 0x8805fc02 + .int 0x35ffff85 + .int 0x1a9f17e0 + .int 0x54ffff00 + .int 0xb9000024 + .int 0xd65f03c0 +#else + cbnz w3, .L___atomic_compare_exchange_4_028 + ldr w3, [x1] +.L___atomic_compare_exchange_4_008: + ldxr w4, [x0] + cmp w4, w3 + b.ne .L___atomic_compare_exchange_4_01c + stxr w5, w2, [x0] + cbnz w5, .L___atomic_compare_exchange_4_008 +.L___atomic_compare_exchange_4_01c: + cset w0, eq // eq = none + b.ne .L___atomic_compare_exchange_4_048 +.L___atomic_compare_exchange_4_024: + ret +.L___atomic_compare_exchange_4_028: + ldr w3, [x1] +.L___atomic_compare_exchange_4_02c: + ldaxr w4, [x0] + cmp w4, w3 + b.ne .L___atomic_compare_exchange_4_040 + stlxr w5, w2, [x0] + cbnz w5, .L___atomic_compare_exchange_4_02c +.L___atomic_compare_exchange_4_040: + cset w0, eq // eq = none + b.eq .L___atomic_compare_exchange_4_024 +.L___atomic_compare_exchange_4_048: + str w4, [x1] + ret + .size _(__atomic_compare_exchange_4), .-_(__atomic_compare_exchange_4) + +#endif + .global _(__atomic_compare_exchange_8) + .type _(__atomic_compare_exchange_8), %function +_(__atomic_compare_exchange_8): +#ifdef __TINYC__ + .int 0x35000143 + .int 0xf9400023 + .int 0xc85f7c04 + .int 0xeb03009f + .int 0x54000061 + .int 0xc8057c02 + .int 0x35ffff85 + .int 0x1a9f17e0 + .int 0x54000141 + .int 0xd65f03c0 + .int 0xf9400023 + .int 0xc85ffc04 + .int 0xeb03009f + .int 0x54000061 + .int 0xc805fc02 + .int 0x35ffff85 + .int 0x1a9f17e0 + .int 0x54ffff00 + .int 0xf9000024 + .int 0xd65f03c0 +#else + cbnz w3, .L___atomic_compare_exchange_8_028 + ldr x3, [x1] +.L___atomic_compare_exchange_8_008: + ldxr x4, [x0] + cmp x4, x3 + b.ne .L___atomic_compare_exchange_8_01c + stxr w5, x2, [x0] + cbnz w5, .L___atomic_compare_exchange_8_008 +.L___atomic_compare_exchange_8_01c: + cset w0, eq // eq = none + b.ne .L___atomic_compare_exchange_8_048 +.L___atomic_compare_exchange_8_024: + ret +.L___atomic_compare_exchange_8_028: + ldr x3, [x1] +.L___atomic_compare_exchange_8_02c: + ldaxr x4, [x0] + cmp x4, x3 + b.ne .L___atomic_compare_exchange_8_040 + stlxr w5, x2, [x0] + cbnz w5, .L___atomic_compare_exchange_8_02c +.L___atomic_compare_exchange_8_040: + cset w0, eq // eq = none + b.eq .L___atomic_compare_exchange_8_024 +.L___atomic_compare_exchange_8_048: + str x4, [x1] + ret + .size _(__atomic_compare_exchange_8), .-_(__atomic_compare_exchange_8) + +#endif + .global _(__atomic_test_and_set_1) + .type _(__atomic_test_and_set_1), %function +_(__atomic_test_and_set_1): +#ifdef __TINYC__ + .int 0x52800022 + .int 0x350000c1 + .int 0x085f7c01 + .int 0x08037c02 + .int 0x35ffffc3 + .int 0x12001c20 + .int 0xd65f03c0 + .int 0x085ffc01 + .int 0x0803fc02 + .int 0x35ffffc3 + .int 0x12001c20 + .int 0xd65f03c0 +#else + mov w2, #0x1 // #1 + cbnz w1, .L___atomic_test_and_set_1_01c +.L___atomic_test_and_set_1_008: + ldxrb w1, [x0] + stxrb w3, w2, [x0] + cbnz w3, .L___atomic_test_and_set_1_008 + and w0, w1, #0xff + ret +.L___atomic_test_and_set_1_01c: + ldaxrb w1, [x0] + stlxrb w3, w2, [x0] + cbnz w3, .L___atomic_test_and_set_1_01c + and w0, w1, #0xff + ret + .size _(__atomic_test_and_set_1), .-_(__atomic_test_and_set_1) + +#endif + .global _(__atomic_test_and_set_2) + .type _(__atomic_test_and_set_2), %function +_(__atomic_test_and_set_2): +#ifdef __TINYC__ + .int 0x52800022 + .int 0x350000c1 + .int 0x085f7c01 + .int 0x08037c02 + .int 0x35ffffc3 + .int 0x12001c20 + .int 0xd65f03c0 + .int 0x085ffc01 + .int 0x0803fc02 + .int 0x35ffffc3 + .int 0x12001c20 + .int 0xd65f03c0 +#else + mov w2, #0x1 // #1 + cbnz w1, .L___atomic_test_and_set_2_01c +.L___atomic_test_and_set_2_008: + ldxrb w1, [x0] + stxrb w3, w2, [x0] + cbnz w3, .L___atomic_test_and_set_2_008 + and w0, w1, #0xff + ret +.L___atomic_test_and_set_2_01c: + ldaxrb w1, [x0] + stlxrb w3, w2, [x0] + cbnz w3, .L___atomic_test_and_set_2_01c + and w0, w1, #0xff + ret + .size _(__atomic_test_and_set_2), .-_(__atomic_test_and_set_2) + +#endif + .global _(__atomic_test_and_set_4) + .type _(__atomic_test_and_set_4), %function +_(__atomic_test_and_set_4): +#ifdef __TINYC__ + .int 0x52800022 + .int 0x350000c1 + .int 0x085f7c01 + .int 0x08037c02 + .int 0x35ffffc3 + .int 0x12001c20 + .int 0xd65f03c0 + .int 0x085ffc01 + .int 0x0803fc02 + .int 0x35ffffc3 + .int 0x12001c20 + .int 0xd65f03c0 +#else + mov w2, #0x1 // #1 + cbnz w1, .L___atomic_test_and_set_4_01c +.L___atomic_test_and_set_4_008: + ldxrb w1, [x0] + stxrb w3, w2, [x0] + cbnz w3, .L___atomic_test_and_set_4_008 + and w0, w1, #0xff + ret +.L___atomic_test_and_set_4_01c: + ldaxrb w1, [x0] + stlxrb w3, w2, [x0] + cbnz w3, .L___atomic_test_and_set_4_01c + and w0, w1, #0xff + ret + .size _(__atomic_test_and_set_4), .-_(__atomic_test_and_set_4) + +#endif + .global _(__atomic_test_and_set_8) + .type _(__atomic_test_and_set_8), %function +_(__atomic_test_and_set_8): +#ifdef __TINYC__ + .int 0x52800022 + .int 0x350000c1 + .int 0x085f7c01 + .int 0x08037c02 + .int 0x35ffffc3 + .int 0x12001c20 + .int 0xd65f03c0 + .int 0x085ffc01 + .int 0x0803fc02 + .int 0x35ffffc3 + .int 0x12001c20 + .int 0xd65f03c0 +#else + mov w2, #0x1 // #1 + cbnz w1, .L___atomic_test_and_set_8_01c +.L___atomic_test_and_set_8_008: + ldxrb w1, [x0] + stxrb w3, w2, [x0] + cbnz w3, .L___atomic_test_and_set_8_008 + and w0, w1, #0xff + ret +.L___atomic_test_and_set_8_01c: + ldaxrb w1, [x0] + stlxrb w3, w2, [x0] + cbnz w3, .L___atomic_test_and_set_8_01c + and w0, w1, #0xff + ret + .size _(__atomic_test_and_set_8), .-_(__atomic_test_and_set_8) + +#endif + .global _(atomic_thread_fence) + .type _(atomic_thread_fence), %function +_(atomic_thread_fence): +#ifdef __TINYC__ + .int 0xd5033bbf + .int 0xd65f03c0 +#else + dmb ish + ret + .size _(atomic_thread_fence), .-_(atomic_thread_fence) + +#endif + .global _(atomic_signal_fence) + .type _(atomic_signal_fence), %function +_(atomic_signal_fence): +#ifdef __TINYC__ + .int 0xd65f03c0 +#else + ret + .size _(atomic_signal_fence), .-_(atomic_signal_fence) + +#endif + .global _(atomic_flag_test_and_set) + .type _(atomic_flag_test_and_set), %function +_(atomic_flag_test_and_set): +#ifdef __TINYC__ + .int 0xaa0003e1 + .int 0x52800022 + .int 0x085ffc20 + .int 0x0803fc22 + .int 0x35ffffc3 + .int 0xd65f03c0 +#else + mov x1, x0 + mov w2, #0x1 // #1 +.L_atomic_flag_test_and_set_008: + ldaxrb w0, [x1] + stlxrb w3, w2, [x1] + cbnz w3, .L_atomic_flag_test_and_set_008 + ret + .size _(atomic_flag_test_and_set), .-_(atomic_flag_test_and_set) + +#endif + .global _(atomic_flag_test_and_set_explicit) + .type _(atomic_flag_test_and_set_explicit), %function +_(atomic_flag_test_and_set_explicit): +#ifdef __TINYC__ + .int 0xaa0003e1 + .int 0x52800022 + .int 0x085ffc20 + .int 0x0803fc22 + .int 0x35ffffc3 + .int 0xd65f03c0 +#else + mov x1, x0 + mov w2, #0x1 // #1 +.L_atomic_flag_test_and_set_explicit_020: + ldaxrb w0, [x1] + stlxrb w3, w2, [x1] + cbnz w3, .L_atomic_flag_test_and_set_explicit_020 + ret + .size _(atomic_flag_test_and_set_explicit), .-_(atomic_flag_test_and_set_explicit) + +#endif + .global _(atomic_flag_clear) + .type _(atomic_flag_clear), %function +_(atomic_flag_clear): +#ifdef __TINYC__ + .int 0x089ffc1f + .int 0xd65f03c0 +#else + stlrb wzr, [x0] + ret + .size _(atomic_flag_clear), .-_(atomic_flag_clear) + +#endif + .global _(atomic_flag_clear_explicit) + .type _(atomic_flag_clear_explicit), %function +_(atomic_flag_clear_explicit): +#ifdef __TINYC__ + .int 0x089ffc1f + .int 0xd65f03c0 +#else + stlrb wzr, [x0] + ret + .size _(atomic_flag_clear_explicit), .-_(atomic_flag_clear_explicit) + +#endif +#endif //__aarch64__ + +/* ---------------------------------------------- */ +#if defined __riscv + .text + .align 2 + + .global _(__atomic_load_1) + .type _(__atomic_load_1), %function +_(__atomic_load_1): +#ifdef __TINYC__ + .int 0x0330000f + .int 0x00054503 + .int 0x0330000f + .short 0x8082 +#else + fence rw,rw + lbu a0,0(a0) + fence rw,rw + ret + .size _(__atomic_load_1), .-_(__atomic_load_1) + +#endif + .global _(__atomic_load_2) + .type _(__atomic_load_2), %function +_(__atomic_load_2): +#ifdef __TINYC__ + .int 0x0330000f + .int 0x00055503 + .int 0x0330000f + .short 0x8082 +#else + fence rw,rw + lhu a0,0(a0) + fence rw,rw + ret + .size _(__atomic_load_2), .-_(__atomic_load_2) + +#endif + .global _(__atomic_load_4) + .type _(__atomic_load_4), %function +_(__atomic_load_4): +#ifdef __TINYC__ + .int 0x0330000f + .short 0x4108 + .int 0x0230000f + .short 0x2501 + .short 0x8082 +#else + fence rw,rw + lw a0,0(a0) + fence r,rw + sext.w a0,a0 + ret + .size _(__atomic_load_4), .-_(__atomic_load_4) + +#endif + .global _(__atomic_load_8) + .type _(__atomic_load_8), %function +_(__atomic_load_8): +#ifdef __TINYC__ + .int 0x0330000f + .short 0x6108 + .int 0x0230000f + .short 0x8082 +#else + fence rw,rw + ld a0,0(a0) + fence r,rw + ret + .size _(__atomic_load_8), .-_(__atomic_load_8) + +#endif + .global _(__atomic_store_1) + .type _(__atomic_store_1), %function +_(__atomic_store_1): +#ifdef __TINYC__ + .int 0x0330000f + .int 0x00b50023 + .int 0x0330000f + .short 0x8082 +#else + fence rw,rw + sb a1,0(a0) + fence rw,rw + ret + .size _(__atomic_store_1), .-_(__atomic_store_1) + +#endif + .global _(__atomic_store_2) + .type _(__atomic_store_2), %function +_(__atomic_store_2): +#ifdef __TINYC__ + .int 0x0330000f + .int 0x00b51023 + .int 0x0330000f + .short 0x8082 +#else + fence rw,rw + sh a1,0(a0) + fence rw,rw + ret + .size _(__atomic_store_2), .-_(__atomic_store_2) + +#endif + .global _(__atomic_store_4) + .type _(__atomic_store_4), %function +_(__atomic_store_4): +#ifdef __TINYC__ + .int 0x0310000f + .short 0xc10c + .int 0x0330000f + .short 0x8082 +#else + fence rw,w + sw a1,0(a0) + fence rw,rw + ret + .size _(__atomic_store_4), .-_(__atomic_store_4) + +#endif + .global _(__atomic_store_8) + .type _(__atomic_store_8), %function +_(__atomic_store_8): +#ifdef __TINYC__ + .int 0x0310000f + .short 0xe10c + .int 0x0330000f + .short 0x8082 +#else + fence rw,w + sd a1,0(a0) + fence rw,rw + ret + .size _(__atomic_store_8), .-_(__atomic_store_8) + +#endif + .global _(__atomic_compare_exchange_1) + .type _(__atomic_compare_exchange_1), %function +_(__atomic_compare_exchange_1): +#ifdef __TINYC__ + .int 0x0005c683 + .int 0x00357793 + .int 0x0037979b + .int 0x0ff00713 + .int 0x00f7173b + .int 0x00f698bb + .int 0x00f6163b + .short 0x9971 + .int 0xfff74313 + .int 0x00e8f8b3 + .short 0x8e79 + .int 0x1605282f + .int 0x00e87e33 + .int 0x011e1a63 + .int 0x00687e33 + .int 0x00ce6e33 + .int 0x1bc52e2f + .int 0xfe0e14e3 + .int 0x40f8583b + .int 0x0188179b + .int 0x0186969b + .int 0x4187d79b + .int 0x4186d69b + .short 0x9f95 + .int 0x0017b513 + .short 0xc399 + .int 0x01058023 + .short 0x8905 + .short 0x8082 +#else + lbu a3,0(a1) + andi a5,a0,3 + slliw a5,a5,0x3 + li a4,255 + sllw a4,a4,a5 + sllw a7,a3,a5 + sllw a2,a2,a5 + andi a0,a0,-4 + not t1,a4 + and a7,a7,a4 + and a2,a2,a4 +.L___atomic_compare_exchange_1_028: + lr.w.aqrl a6,(a0) + and t3,a6,a4 + bne t3,a7, .L___atomic_compare_exchange_1_044 + and t3,a6,t1 + or t3,t3,a2 + sc.w.rl t3,t3,(a0) + bnez t3, .L___atomic_compare_exchange_1_028 +.L___atomic_compare_exchange_1_044: + sraw a6,a6,a5 + slliw a5,a6,0x18 + slliw a3,a3,0x18 + sraiw a5,a5,0x18 + sraiw a3,a3,0x18 + subw a5,a5,a3 + seqz a0,a5 + beqz a5, .L___atomic_compare_exchange_1_064 + sb a6,0(a1) +.L___atomic_compare_exchange_1_064: + andi a0,a0,1 + ret + .size _(__atomic_compare_exchange_1), .-_(__atomic_compare_exchange_1) + +#endif + .global _(__atomic_compare_exchange_2) + .type _(__atomic_compare_exchange_2), %function +_(__atomic_compare_exchange_2): +#ifdef __TINYC__ + .int 0x0005d683 + .int 0x00357713 + .short 0x67c1 + .int 0x0037171b + .short 0x37fd + .int 0x00e797bb + .int 0x00e698bb + .int 0x00e6163b + .short 0x9971 + .int 0xfff7c313 + .int 0x00f8f8b3 + .short 0x8e7d + .int 0x1605282f + .int 0x00f87e33 + .int 0x011e1a63 + .int 0x00687e33 + .int 0x00ce6e33 + .int 0x1bc52e2f + .int 0xfe0e14e3 + .int 0x40e8583b + .int 0x0108179b + .int 0x0106969b + .int 0x4107d79b + .int 0x4106d69b + .short 0x9f95 + .int 0x0017b513 + .short 0xc399 + .int 0x01059023 + .short 0x8905 + .short 0x8082 +#else + lhu a3,0(a1) + andi a4,a0,3 + lui a5,0x10 + slliw a4,a4,0x3 + addiw a5,a5,-1 # ffff <.LASF16+0xfec8> + sllw a5,a5,a4 + sllw a7,a3,a4 + sllw a2,a2,a4 + andi a0,a0,-4 + not t1,a5 + and a7,a7,a5 + and a2,a2,a5 +.L___atomic_compare_exchange_2_028: + lr.w.aqrl a6,(a0) + and t3,a6,a5 + bne t3,a7, .L___atomic_compare_exchange_2_044 + and t3,a6,t1 + or t3,t3,a2 + sc.w.rl t3,t3,(a0) + bnez t3, .L___atomic_compare_exchange_2_028 +.L___atomic_compare_exchange_2_044: + sraw a6,a6,a4 + slliw a5,a6,0x10 + slliw a3,a3,0x10 + sraiw a5,a5,0x10 + sraiw a3,a3,0x10 + subw a5,a5,a3 + seqz a0,a5 + beqz a5, .L___atomic_compare_exchange_2_064 + sh a6,0(a1) +.L___atomic_compare_exchange_2_064: + andi a0,a0,1 + ret + .size _(__atomic_compare_exchange_2), .-_(__atomic_compare_exchange_2) + +#endif + .global _(__atomic_compare_exchange_4) + .type _(__atomic_compare_exchange_4), %function +_(__atomic_compare_exchange_4): #ifdef __TINYC__ .short 0x419c - .int 0x0f50000f - .int 0x1405272f - .int 0x00f71663 - .int 0x1cc5282f - .int 0xfe081ae3 - .int 0x40f707bb - .int 0x0017b513 + .int 0x1605272f + .int 0x00f71563 + .int 0x1ac526af + .short 0xfaf5 + .int 0x40f707bb + .int 0x0017b513 .short 0xc391 .short 0xc198 .short 0x8905 .short 0x8082 #else - lw a5,0(a1) - fence iorw,ow; -.L11: - lr.w.aq a4,0(a0) - bne a4,a5,.L12 - sc.w.aq a6,a2,0(a0) - bnez a6,.L11 -.L12: - subw a5,a4,a5 - seqz a0,a5 - beq a5,zero,.L13 - sw a4,0(a1) -.L13: - andi a0,a0,1 + lw a5,0(a1) +.L___atomic_compare_exchange_4_002: + lr.w.aqrl a4,(a0) + bne a4,a5, .L___atomic_compare_exchange_4_010 + sc.w.rl a3,a2,(a0) + bnez a3, .L___atomic_compare_exchange_4_002 +.L___atomic_compare_exchange_4_010: + subw a5,a4,a5 + seqz a0,a5 + beqz a5, .L___atomic_compare_exchange_4_01c + sw a4,0(a1) +.L___atomic_compare_exchange_4_01c: + andi a0,a0,1 ret -#endif - .size _(__atomic_compare_exchange_4), .-_(__atomic_compare_exchange_4) + .size _(__atomic_compare_exchange_4), .-_(__atomic_compare_exchange_4) +#endif .global _(__atomic_compare_exchange_8) .type _(__atomic_compare_exchange_8), %function _(__atomic_compare_exchange_8): #ifdef __TINYC__ .short 0x619c - .int 0x0f50000f - .int 0x1405372f - .int 0x00f71563 - .int 0x1cc536af + .int 0x1605372f + .int 0x00f71563 + .int 0x1ac536af .short 0xfaf5 - .int 0x40f707b3 - .int 0x0017b513 + .int 0x40f707b3 + .int 0x0017b513 .short 0xc391 .short 0xe198 .short 0x8905 .short 0x8082 #else - ld a5,0(a1) - fence iorw,ow; -.L14: - lr.d.aq a4,0(a0) - bne a4,a5,.L15 - sc.d.aq a3,a2,0(a0) - bnez a3,.L14 -.L15: - sub a5,a4,a5 - seqz a0,a5 - beq a5,zero,.L16 - sd a4,0(a1) -.L16: - andi a0,a0,1 + ld a5,0(a1) +.L___atomic_compare_exchange_8_002: + lr.d.aqrl a4,(a0) + bne a4,a5, .L___atomic_compare_exchange_8_010 + sc.d.rl a3,a2,(a0) + bnez a3, .L___atomic_compare_exchange_8_002 +.L___atomic_compare_exchange_8_010: + sub a5,a4,a5 + seqz a0,a5 + beqz a5, .L___atomic_compare_exchange_8_01c + sd a4,0(a1) +.L___atomic_compare_exchange_8_01c: + andi a0,a0,1 ret -#endif - .size _(__atomic_compare_exchange_8), .-_(__atomic_compare_exchange_8) + .size _(__atomic_compare_exchange_8), .-_(__atomic_compare_exchange_8) -/* ---------------------------------------------- */ #endif + .global _(__atomic_test_and_set_1) + .type _(__atomic_test_and_set_1), %function +_(__atomic_test_and_set_1): +#ifdef __TINYC__ + .int 0x00357793 + .int 0x0037979b + .short 0x4685 + .short 0x9971 + .int 0x00f696bb + .int 0x46d5272f + .int 0x00f7553b + .int 0x0ff57513 + .short 0x8082 +#else + andi a5,a0,3 + slliw a5,a5,0x3 + li a3,1 + andi a0,a0,-4 + sllw a3,a3,a5 + amoor.w.aqrl a4,a3,(a0) + srlw a0,a4,a5 + zext.b a0,a0 + ret + .size _(__atomic_test_and_set_1), .-_(__atomic_test_and_set_1) + +#endif + .global _(__atomic_test_and_set_2) + .type _(__atomic_test_and_set_2), %function +_(__atomic_test_and_set_2): +#ifdef __TINYC__ + .int 0x00357793 + .int 0x0037979b + .short 0x4685 + .short 0x9971 + .int 0x00f696bb + .int 0x46d5272f + .int 0x00f7553b + .int 0x0ff57513 + .short 0x8082 +#else + andi a5,a0,3 + slliw a5,a5,0x3 + li a3,1 + andi a0,a0,-4 + sllw a3,a3,a5 + amoor.w.aqrl a4,a3,(a0) + srlw a0,a4,a5 + zext.b a0,a0 + ret + .size _(__atomic_test_and_set_2), .-_(__atomic_test_and_set_2) + +#endif + .global _(__atomic_test_and_set_4) + .type _(__atomic_test_and_set_4), %function +_(__atomic_test_and_set_4): +#ifdef __TINYC__ + .int 0x00357793 + .int 0x0037979b + .short 0x4685 + .short 0x9971 + .int 0x00f696bb + .int 0x46d5272f + .int 0x00f7553b + .int 0x0ff57513 + .short 0x8082 +#else + andi a5,a0,3 + slliw a5,a5,0x3 + li a3,1 + andi a0,a0,-4 + sllw a3,a3,a5 + amoor.w.aqrl a4,a3,(a0) + srlw a0,a4,a5 + zext.b a0,a0 + ret + .size _(__atomic_test_and_set_4), .-_(__atomic_test_and_set_4) + +#endif + .global _(__atomic_test_and_set_8) + .type _(__atomic_test_and_set_8), %function +_(__atomic_test_and_set_8): +#ifdef __TINYC__ + .int 0x00357793 + .int 0x0037979b + .short 0x4685 + .short 0x9971 + .int 0x00f696bb + .int 0x46d5272f + .int 0x00f7553b + .int 0x0ff57513 + .short 0x8082 +#else + andi a5,a0,3 + slliw a5,a5,0x3 + li a3,1 + andi a0,a0,-4 + sllw a3,a3,a5 + amoor.w.aqrl a4,a3,(a0) + srlw a0,a4,a5 + zext.b a0,a0 + ret + .size _(__atomic_test_and_set_8), .-_(__atomic_test_and_set_8) + +#endif + .global _(atomic_thread_fence) + .type _(atomic_thread_fence), %function +_(atomic_thread_fence): +#ifdef __TINYC__ + .int 0x0330000f + .short 0x8082 +#else + fence rw,rw + ret + .size _(atomic_thread_fence), .-_(atomic_thread_fence) + +#endif + .global _(atomic_signal_fence) + .type _(atomic_signal_fence), %function +_(atomic_signal_fence): +#ifdef __TINYC__ + .short 0x8082 +#else + ret + .size _(atomic_signal_fence), .-_(atomic_signal_fence) + +#endif + .global _(atomic_flag_test_and_set) + .type _(atomic_flag_test_and_set), %function +_(atomic_flag_test_and_set): +#ifdef __TINYC__ + .int 0x00357793 + .int 0x0037979b + .short 0x4685 + .short 0x9971 + .int 0x00f696bb + .int 0x46d5272f + .int 0x00f7553b + .int 0x0ff57513 + .short 0x8082 +#else + andi a5,a0,3 + slliw a5,a5,0x3 + li a3,1 + andi a0,a0,-4 + sllw a3,a3,a5 + amoor.w.aqrl a4,a3,(a0) + srlw a0,a4,a5 + zext.b a0,a0 + ret + .size _(atomic_flag_test_and_set), .-_(atomic_flag_test_and_set) + +#endif + .global _(atomic_flag_test_and_set_explicit) + .type _(atomic_flag_test_and_set_explicit), %function +_(atomic_flag_test_and_set_explicit): +#ifdef __TINYC__ + .int 0x00357793 + .int 0x0037979b + .short 0x4685 + .short 0x9971 + .int 0x00f696bb + .int 0x46d5272f + .int 0x00f7553b + .int 0x0ff57513 + .short 0x8082 +#else + andi a5,a0,3 + slliw a5,a5,0x3 + li a3,1 + andi a0,a0,-4 + sllw a3,a3,a5 + amoor.w.aqrl a4,a3,(a0) + srlw a0,a4,a5 + zext.b a0,a0 + ret + .size _(atomic_flag_test_and_set_explicit), .-_(atomic_flag_test_and_set_explicit) + +#endif + .global _(atomic_flag_clear) + .type _(atomic_flag_clear), %function +_(atomic_flag_clear): +#ifdef __TINYC__ + .int 0x0330000f + .int 0x00050023 + .int 0x0330000f + .short 0x8082 +#else + fence rw,rw + sb zero,0(a0) + fence rw,rw + ret + .size _(atomic_flag_clear), .-_(atomic_flag_clear) + +#endif + .global _(atomic_flag_clear_explicit) + .type _(atomic_flag_clear_explicit), %function +_(atomic_flag_clear_explicit): +#ifdef __TINYC__ + .int 0x0330000f + .int 0x00050023 + .int 0x0330000f + .short 0x8082 +#else + fence rw,rw + sb zero,0(a0) + fence rw,rw + ret + .size _(atomic_flag_clear_explicit), .-_(atomic_flag_clear_explicit) + +#endif +#endif //__riscv diff --git a/lib/stdatomic.c b/lib/stdatomic.c index 732657a8..fe03623d 100644 --- a/lib/stdatomic.c +++ b/lib/stdatomic.c @@ -15,47 +15,6 @@ #define __ATOMIC_SEQ_CST 5 typedef __SIZE_TYPE__ size_t; -void __atomic_thread_fence(int memorder); -#define MemoryBarrier(memorder) __atomic_thread_fence(memorder) - -#if defined __i386__ || defined __x86_64__ -#define ATOMIC_COMPARE_EXCHANGE(TYPE, MODE, SUFFIX) \ - bool __atomic_compare_exchange_##MODE \ - (volatile void *atom, void *ref, TYPE xchg, \ - bool weak, int success_memorder, int failure_memorder) \ - { \ - TYPE rv; \ - TYPE cmp = *(TYPE *)ref; \ - __asm__ volatile( \ - "lock cmpxchg" SUFFIX " %2,%1\n" \ - : "=a" (rv), "+m" (*(TYPE *)atom) \ - : "q" (xchg), "0" (cmp) \ - : "memory" \ - ); \ - *(TYPE *)ref = rv; \ - return (rv == cmp); \ - } -#else -#define ATOMIC_COMPARE_EXCHANGE(TYPE, MODE, SUFFIX) \ - extern bool __atomic_compare_exchange_##MODE \ - (volatile void *atom, void *ref, TYPE xchg, \ - bool weak, int success_memorder, int failure_memorder); -#endif - -#define ATOMIC_LOAD(TYPE, MODE) \ - TYPE __atomic_load_##MODE(const volatile void *atom, int memorder) \ - { \ - MemoryBarrier(__ATOMIC_ACQUIRE); \ - return *(volatile TYPE *)atom; \ - } - -#define ATOMIC_STORE(TYPE, MODE) \ - void __atomic_store_##MODE(volatile void *atom, TYPE value, int memorder) \ - { \ - *(volatile TYPE *)atom = value; \ - MemoryBarrier(__ATOMIC_ACQ_REL); \ - } - #define ATOMIC_GEN_OP(TYPE, MODE, NAME, OP, RET) \ TYPE __atomic_##NAME##_##MODE(volatile void *atom, TYPE value, int memorder) \ { \ @@ -95,10 +54,7 @@ void __atomic_thread_fence(int memorder); #define ATOMIC_FETCH_NAND(TYPE, MODE) \ ATOMIC_GEN_OP(TYPE, MODE, fetch_nand, ~(cmp & value), cmp) -#define ATOMIC_GEN(TYPE, SIZE, SUFFIX) \ - ATOMIC_STORE(TYPE, SIZE) \ - ATOMIC_LOAD(TYPE, SIZE) \ - ATOMIC_COMPARE_EXCHANGE(TYPE, SIZE, SUFFIX) \ +#define ATOMIC_GEN(TYPE, SIZE) \ ATOMIC_EXCHANGE(TYPE, SIZE) \ ATOMIC_ADD_FETCH(TYPE, SIZE) \ ATOMIC_SUB_FETCH(TYPE, SIZE) \ @@ -113,12 +69,10 @@ void __atomic_thread_fence(int memorder); ATOMIC_FETCH_XOR(TYPE, SIZE) \ ATOMIC_FETCH_NAND(TYPE, SIZE) -ATOMIC_GEN(uint8_t, 1, "b") -ATOMIC_GEN(uint16_t, 2, "w") -ATOMIC_GEN(uint32_t, 4, "l") -#if defined __x86_64__ || defined __aarch64__ || defined __riscv -ATOMIC_GEN(uint64_t, 8, "q") -#endif +ATOMIC_GEN(uint8_t, 1) +ATOMIC_GEN(uint16_t, 2) +ATOMIC_GEN(uint32_t, 4) +ATOMIC_GEN(uint64_t, 8) /* uses alias to allow building with gcc/clang */ #ifdef __TINYC__ @@ -127,25 +81,6 @@ ATOMIC_GEN(uint64_t, 8, "q") #define ATOMIC(x) __tcc_atomic_##x #endif -void ATOMIC(signal_fence) (int memorder) -{ -} - -void ATOMIC(thread_fence) (int memorder) -{ -#if defined __i386__ - __asm__ volatile("lock orl $0, (%esp)"); -#elif defined __x86_64__ - __asm__ volatile("lock orq $0, (%rsp)"); -#elif defined __arm__ - __asm__ volatile(".int 0xee070fba"); // mcr p15, 0, r0, c7, c10, 5 -#elif defined __aarch64__ - __asm__ volatile(".int 0xd5033bbf"); // dmb ish -#elif defined __riscv - __asm__ volatile(".int 0x0ff0000f"); // fence iorw,iorw -#endif -} - bool ATOMIC(is_lock_free) (unsigned long size, const volatile void *ptr) { bool ret; @@ -165,7 +100,5 @@ bool ATOMIC(is_lock_free) (unsigned long size, const volatile void *ptr) } #ifndef __TINYC__ -void __atomic_signal_fence(int memorder) __attribute__((alias("__tcc_atomic_signal_fence"))); -void __atomic_thread_fence(int memorder) __attribute__((alias("__tcc_atomic_thread_fence"))); bool __atomic_is_lock_free(unsigned long size, const volatile void *ptr) __attribute__((alias("__tcc_atomic_is_lock_free"))); #endif