mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
newlib: stdatomic: implement missing "op_fetch", "nand" builtins
* Adds implementations of __{atomic,sync}_nand_fetch_n. These builtins were implemented for other operations but were not defined for NAND. * Adds implementation of __atomic_OP_fetch_n for all OPs. * Adds implementation of __sync_OP_and_fetch_n for all OPs. Reported in https://github.com/espressif/arduino-esp32/issues/5948
This commit is contained in:
parent
1c82e6eac7
commit
01033a3a60
@ -132,6 +132,15 @@ __asm__(".type " # name_ ", @function\n" \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define ADD_FETCH(n, type) type __atomic_add_fetch_ ## n (type* ptr, type value, int memorder) \
|
||||
{ \
|
||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
||||
type ret = *ptr + value; \
|
||||
*ptr = ret; \
|
||||
_ATOMIC_EXIT_CRITICAL(state); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define FETCH_SUB(n, type) type __atomic_fetch_sub_ ## n (type* ptr, type value, int memorder) \
|
||||
{ \
|
||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
||||
@ -141,6 +150,15 @@ __asm__(".type " # name_ ", @function\n" \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define SUB_FETCH(n, type) type __atomic_sub_fetch_ ## n (type* ptr, type value, int memorder) \
|
||||
{ \
|
||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
||||
type ret = *ptr - value; \
|
||||
*ptr = ret; \
|
||||
_ATOMIC_EXIT_CRITICAL(state); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define FETCH_AND(n, type) type __atomic_fetch_and_ ## n (type* ptr, type value, int memorder) \
|
||||
{ \
|
||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
||||
@ -150,6 +168,15 @@ __asm__(".type " # name_ ", @function\n" \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define AND_FETCH(n, type) type __atomic_and_fetch_ ## n (type* ptr, type value, int memorder) \
|
||||
{ \
|
||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
||||
type ret = *ptr & value; \
|
||||
*ptr = ret; \
|
||||
_ATOMIC_EXIT_CRITICAL(state); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define FETCH_OR(n, type) type __atomic_fetch_or_ ## n (type* ptr, type value, int memorder) \
|
||||
{ \
|
||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
||||
@ -159,6 +186,15 @@ __asm__(".type " # name_ ", @function\n" \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define OR_FETCH(n, type) type __atomic_or_fetch_ ## n (type* ptr, type value, int memorder) \
|
||||
{ \
|
||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
||||
type ret = *ptr | value; \
|
||||
*ptr = ret; \
|
||||
_ATOMIC_EXIT_CRITICAL(state); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define FETCH_XOR(n, type) type __atomic_fetch_xor_ ## n (type* ptr, type value, int memorder) \
|
||||
{ \
|
||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
||||
@ -168,6 +204,32 @@ __asm__(".type " # name_ ", @function\n" \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define XOR_FETCH(n, type) type __atomic_xor_fetch_ ## n (type* ptr, type value, int memorder) \
|
||||
{ \
|
||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
||||
type ret = *ptr ^ value; \
|
||||
*ptr = ret; \
|
||||
_ATOMIC_EXIT_CRITICAL(state); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define FETCH_NAND(n, type) type __atomic_fetch_nand_ ## n (type* ptr, type value, int memorder) \
|
||||
{ \
|
||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
||||
type ret = *ptr; \
|
||||
*ptr = ~(*ptr & value); \
|
||||
_ATOMIC_EXIT_CRITICAL(state); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define NAND_FETCH(n, type) type __atomic_nand_fetch_ ## n (type* ptr, type value, int memorder) \
|
||||
{ \
|
||||
unsigned state = _ATOMIC_ENTER_CRITICAL(); \
|
||||
type ret = ~(*ptr & value); \
|
||||
*ptr = ret; \
|
||||
_ATOMIC_EXIT_CRITICAL(state); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define SYNC_FETCH_OP(op, n, type) type CLANG_ATOMIC_SUFFIX(__sync_fetch_and_ ## op ##_ ## n) (type* ptr, type value) \
|
||||
{ \
|
||||
@ -175,6 +237,12 @@ __asm__(".type " # name_ ", @function\n" \
|
||||
} \
|
||||
CLANG_DECLARE_ALIAS( __sync_fetch_and_ ## op ##_ ## n )
|
||||
|
||||
#define SYNC_OP_FETCH(op, n, type) type CLANG_ATOMIC_SUFFIX(__sync_ ## op ##_and_fetch_ ## n) (type* ptr, type value) \
|
||||
{ \
|
||||
return __atomic_ ## op ##_fetch_ ## n (ptr, value, __ATOMIC_SEQ_CST); \
|
||||
} \
|
||||
CLANG_DECLARE_ALIAS( __sync_ ## op ##_and_fetch_ ## n )
|
||||
|
||||
#define SYNC_BOOL_CMP_EXCHANGE(n, type) bool CLANG_ATOMIC_SUFFIX(__sync_bool_compare_and_swap_ ## n) (type *ptr, type oldval, type newval) \
|
||||
{ \
|
||||
bool ret = false; \
|
||||
@ -233,42 +301,98 @@ FETCH_ADD(1, uint8_t)
|
||||
FETCH_ADD(2, uint16_t)
|
||||
FETCH_ADD(4, uint32_t)
|
||||
|
||||
ADD_FETCH(1, uint8_t)
|
||||
ADD_FETCH(2, uint16_t)
|
||||
ADD_FETCH(4, uint32_t)
|
||||
|
||||
FETCH_SUB(1, uint8_t)
|
||||
FETCH_SUB(2, uint16_t)
|
||||
FETCH_SUB(4, uint32_t)
|
||||
|
||||
SUB_FETCH(1, uint8_t)
|
||||
SUB_FETCH(2, uint16_t)
|
||||
SUB_FETCH(4, uint32_t)
|
||||
|
||||
FETCH_AND(1, uint8_t)
|
||||
FETCH_AND(2, uint16_t)
|
||||
FETCH_AND(4, uint32_t)
|
||||
|
||||
AND_FETCH(1, uint8_t)
|
||||
AND_FETCH(2, uint16_t)
|
||||
AND_FETCH(4, uint32_t)
|
||||
|
||||
FETCH_OR(1, uint8_t)
|
||||
FETCH_OR(2, uint16_t)
|
||||
FETCH_OR(4, uint32_t)
|
||||
|
||||
OR_FETCH(1, uint8_t)
|
||||
OR_FETCH(2, uint16_t)
|
||||
OR_FETCH(4, uint32_t)
|
||||
|
||||
FETCH_XOR(1, uint8_t)
|
||||
FETCH_XOR(2, uint16_t)
|
||||
FETCH_XOR(4, uint32_t)
|
||||
|
||||
XOR_FETCH(1, uint8_t)
|
||||
XOR_FETCH(2, uint16_t)
|
||||
XOR_FETCH(4, uint32_t)
|
||||
|
||||
FETCH_NAND(1, uint8_t)
|
||||
FETCH_NAND(2, uint16_t)
|
||||
FETCH_NAND(4, uint32_t)
|
||||
|
||||
NAND_FETCH(1, uint8_t)
|
||||
NAND_FETCH(2, uint16_t)
|
||||
NAND_FETCH(4, uint32_t)
|
||||
|
||||
SYNC_FETCH_OP(add, 1, uint8_t)
|
||||
SYNC_FETCH_OP(add, 2, uint16_t)
|
||||
SYNC_FETCH_OP(add, 4, uint32_t)
|
||||
|
||||
SYNC_OP_FETCH(add, 1, uint8_t)
|
||||
SYNC_OP_FETCH(add, 2, uint16_t)
|
||||
SYNC_OP_FETCH(add, 4, uint32_t)
|
||||
|
||||
SYNC_FETCH_OP(sub, 1, uint8_t)
|
||||
SYNC_FETCH_OP(sub, 2, uint16_t)
|
||||
SYNC_FETCH_OP(sub, 4, uint32_t)
|
||||
|
||||
SYNC_OP_FETCH(sub, 1, uint8_t)
|
||||
SYNC_OP_FETCH(sub, 2, uint16_t)
|
||||
SYNC_OP_FETCH(sub, 4, uint32_t)
|
||||
|
||||
SYNC_FETCH_OP(and, 1, uint8_t)
|
||||
SYNC_FETCH_OP(and, 2, uint16_t)
|
||||
SYNC_FETCH_OP(and, 4, uint32_t)
|
||||
|
||||
SYNC_OP_FETCH(and, 1, uint8_t)
|
||||
SYNC_OP_FETCH(and, 2, uint16_t)
|
||||
SYNC_OP_FETCH(and, 4, uint32_t)
|
||||
|
||||
SYNC_FETCH_OP(or, 1, uint8_t)
|
||||
SYNC_FETCH_OP(or, 2, uint16_t)
|
||||
SYNC_FETCH_OP(or, 4, uint32_t)
|
||||
|
||||
SYNC_OP_FETCH(or, 1, uint8_t)
|
||||
SYNC_OP_FETCH(or, 2, uint16_t)
|
||||
SYNC_OP_FETCH(or, 4, uint32_t)
|
||||
|
||||
SYNC_FETCH_OP(xor, 1, uint8_t)
|
||||
SYNC_FETCH_OP(xor, 2, uint16_t)
|
||||
SYNC_FETCH_OP(xor, 4, uint32_t)
|
||||
|
||||
SYNC_OP_FETCH(xor, 1, uint8_t)
|
||||
SYNC_OP_FETCH(xor, 2, uint16_t)
|
||||
SYNC_OP_FETCH(xor, 4, uint32_t)
|
||||
|
||||
SYNC_FETCH_OP(nand, 1, uint8_t)
|
||||
SYNC_FETCH_OP(nand, 2, uint16_t)
|
||||
SYNC_FETCH_OP(nand, 4, uint32_t)
|
||||
|
||||
SYNC_OP_FETCH(nand, 1, uint8_t)
|
||||
SYNC_OP_FETCH(nand, 2, uint16_t)
|
||||
SYNC_OP_FETCH(nand, 4, uint32_t)
|
||||
|
||||
SYNC_BOOL_CMP_EXCHANGE(1, uint8_t)
|
||||
SYNC_BOOL_CMP_EXCHANGE(2, uint16_t)
|
||||
SYNC_BOOL_CMP_EXCHANGE(4, uint32_t)
|
||||
@ -313,6 +437,20 @@ FETCH_OR(8, uint64_t)
|
||||
|
||||
FETCH_XOR(8, uint64_t)
|
||||
|
||||
FETCH_NAND(8, uint64_t)
|
||||
|
||||
ADD_FETCH(8, uint64_t)
|
||||
|
||||
SUB_FETCH(8, uint64_t)
|
||||
|
||||
AND_FETCH(8, uint64_t)
|
||||
|
||||
OR_FETCH(8, uint64_t)
|
||||
|
||||
XOR_FETCH(8, uint64_t)
|
||||
|
||||
NAND_FETCH(8, uint64_t)
|
||||
|
||||
SYNC_FETCH_OP(add, 8, uint64_t)
|
||||
|
||||
SYNC_FETCH_OP(sub, 8, uint64_t)
|
||||
@ -323,6 +461,20 @@ SYNC_FETCH_OP(or, 8, uint64_t)
|
||||
|
||||
SYNC_FETCH_OP(xor, 8, uint64_t)
|
||||
|
||||
SYNC_FETCH_OP(nand, 8, uint64_t)
|
||||
|
||||
SYNC_OP_FETCH(add, 8, uint64_t)
|
||||
|
||||
SYNC_OP_FETCH(sub, 8, uint64_t)
|
||||
|
||||
SYNC_OP_FETCH(and, 8, uint64_t)
|
||||
|
||||
SYNC_OP_FETCH(or, 8, uint64_t)
|
||||
|
||||
SYNC_OP_FETCH(xor, 8, uint64_t)
|
||||
|
||||
SYNC_OP_FETCH(nand, 8, uint64_t)
|
||||
|
||||
SYNC_BOOL_CMP_EXCHANGE(8, uint64_t)
|
||||
|
||||
SYNC_VAL_CMP_EXCHANGE(8, uint64_t)
|
||||
|
Loading…
Reference in New Issue
Block a user