<atomic> design

This is more of a synopsis than a true description. The compiler supplies all of the intrinsics as described below. This list of intrinsics roughly parallels the requirements of the C and C++ atomics proposals. The C and C++ library imlpementations simply drop through to these intrinsics. Anything the platform does not support in hardware, the compiler arranges for a (compiler-rt) library call to be made which will do the job with a mutex, and in this case ignoring the memory ordering parameter.

// In every intrinsic signature below, type* atomic_obj may be a pointer to a
//    volatile-qualifed type.

// type must be trivially copyable
// Behavior is defined for mem_ord = 0, 1, 2, 5
type __atomic_load(const type* atomic_obj, int mem_ord);

// type must be trivially copyable
// Behavior is defined for mem_ord = 0, 3, 5
type __atomic_store(type* atomic_obj, type desired, int mem_ord);

// type must be trivially copyable
// Behavior is defined for mem_ord = [0 ... 5]
type __atomic_exchange(type* atomic_obj, type desired, int mem_ord);

// type must be trivially copyable
// Behavior is defined for mem_success = [0 ... 5],
//   mem_falure <= mem_success
bool __atomic_compare_exchange_strong(type* atomic_obj,
                                      type* expected, type desired,
                                      int mem_success, int mem_failure);

// type must be trivially copyable
// Behavior is defined for mem_success = [0 ... 5],
//   mem_falure <= mem_success
bool __atomic_compare_exchange_weak(type* atomic_obj,
                                    type* expected, type desired,
                                    int mem_success, int mem_failure);

// type is one of: char, signed char, unsigned char, short, unsigned short, int,
//      unsigned int, long, unsigned long, long long, unsigned long long,
//      char16_t, char32_t, wchar_t
// Behavior is defined for mem_ord = [0 ... 5]
type __atomic_fetch_add(type* atomic_obj, type operand, int mem_ord);

// type is one of: char, signed char, unsigned char, short, unsigned short, int,
//      unsigned int, long, unsigned long, long long, unsigned long long,
//      char16_t, char32_t, wchar_t
// Behavior is defined for mem_ord = [0 ... 5]
type __atomic_fetch_sub(type* atomic_obj, type operand, int mem_ord);

// type is one of: char, signed char, unsigned char, short, unsigned short, int,
//      unsigned int, long, unsigned long, long long, unsigned long long,
//      char16_t, char32_t, wchar_t
// Behavior is defined for mem_ord = [0 ... 5]
type __atomic_fetch_and(type* atomic_obj, type operand, int mem_ord);

// type is one of: char, signed char, unsigned char, short, unsigned short, int,
//      unsigned int, long, unsigned long, long long, unsigned long long,
//      char16_t, char32_t, wchar_t
// Behavior is defined for mem_ord = [0 ... 5]
type __atomic_fetch_or(type* atomic_obj, type operand, int mem_ord);

// type is one of: char, signed char, unsigned char, short, unsigned short, int,
//      unsigned int, long, unsigned long, long long, unsigned long long,
//      char16_t, char32_t, wchar_t
// Behavior is defined for mem_ord = [0 ... 5]
type __atomic_fetch_xor(type* atomic_obj, type operand, int mem_ord);

// Behavior is defined for mem_ord = [0 ... 5]
void* __atomic_fetch_add(void** atomic_obj, ptrdiff_t operand, int mem_ord);
void* __atomic_fetch_sub(void** atomic_obj, ptrdiff_t operand, int mem_ord);

// Behavior is defined for mem_ord = [0 ... 5]
void __atomic_thread_fence(int mem_ord);
void __atomic_signal_fence(int mem_ord);

If desired the intrinsics taking a single mem_ord parameter can default this argument to 5.

If desired the intrinsics taking two ordering parameters can default mem_success to 5, and mem_failure to mem_success.