Skip to content

Commit

Permalink
remaining release -> relaxed
Browse files Browse the repository at this point in the history
  • Loading branch information
dpdani committed Aug 29, 2024
1 parent c006e1d commit 488dea5
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 264 deletions.
47 changes: 20 additions & 27 deletions Include/cpython/pyatomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,56 +482,49 @@ _Py_atomic_store_ullong_relaxed(unsigned long long *obj,
static inline void
_Py_atomic_store_char_relaxed(char *obj, char value);


// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------

// Loads `*obj` (acquire operation)
static inline void *
_Py_atomic_load_ptr_acquire(const void *obj);

static inline uintptr_t
_Py_atomic_load_uintptr_acquire(const uintptr_t *obj);

// Stores `*obj = value` (release operation)
static inline void
_Py_atomic_store_ptr_release(void *obj, void *value);
_Py_atomic_store_uchar_relaxed(unsigned char *obj, unsigned char value);

static inline void
_Py_atomic_store_uintptr_release(uintptr_t *obj, uintptr_t value);
_Py_atomic_store_short_relaxed(short *obj, short value);

static inline void
_Py_atomic_store_ssize_release(Py_ssize_t *obj, Py_ssize_t value);
_Py_atomic_store_ushort_relaxed(unsigned short *obj, unsigned short value);

static inline void
_Py_atomic_store_int_release(int *obj, int value);
_Py_atomic_store_long_relaxed(long *obj, long value);

static inline void
_Py_atomic_store_uchar_release(unsigned char *obj, unsigned char value);
_Py_atomic_store_float_relaxed(float *obj, float value);

static inline void
_Py_atomic_store_short_release(short *obj, short value);
_Py_atomic_store_double_relaxed(double *obj, double value);

static inline void
_Py_atomic_store_ushort_release(unsigned short *obj, unsigned short value);
_Py_atomic_store_llong_relaxed(long long *obj, long long value);

static inline void
_Py_atomic_store_uint_release(unsigned int *obj, unsigned int value);

static inline void
_Py_atomic_store_long_release(long *obj, long value);
// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------

// Loads `*obj` (acquire operation)
static inline void *
_Py_atomic_load_ptr_acquire(const void *obj);

static inline uintptr_t
_Py_atomic_load_uintptr_acquire(const uintptr_t *obj);

// Stores `*obj = value` (release operation)
static inline void
_Py_atomic_store_float_release(float *obj, float value);
_Py_atomic_store_ptr_release(void *obj, void *value);

static inline void
_Py_atomic_store_double_release(double *obj, double value);
_Py_atomic_store_uintptr_release(uintptr_t *obj, uintptr_t value);

static inline void
_Py_atomic_store_llong_release(long long *obj, long long value);
_Py_atomic_store_ssize_release(Py_ssize_t *obj, Py_ssize_t value);

static inline void
_Py_atomic_store_ullong_release(unsigned long long *obj,
unsigned long long value);
_Py_atomic_store_int_release(int *obj, int value);

static inline int
_Py_atomic_load_int_acquire(const int *obj);
Expand Down
63 changes: 27 additions & 36 deletions Include/cpython/pyatomic_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,64 +521,55 @@ static inline void
_Py_atomic_store_char_relaxed(char *obj, char value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }


// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------

static inline void *
_Py_atomic_load_ptr_acquire(const void *obj)
{ return (void *)__atomic_load_n((void * const *)obj, __ATOMIC_ACQUIRE); }

static inline uintptr_t
_Py_atomic_load_uintptr_acquire(const uintptr_t *obj)
{ return (uintptr_t)__atomic_load_n(obj, __ATOMIC_ACQUIRE); }

static inline void
_Py_atomic_store_ptr_release(void *obj, void *value)
{ __atomic_store_n((void **)obj, value, __ATOMIC_RELEASE); }
_Py_atomic_store_uchar_relaxed(unsigned char *obj, unsigned char value)
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }

static inline void
_Py_atomic_store_uintptr_release(uintptr_t *obj, uintptr_t value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }
_Py_atomic_store_short_relaxed(short *obj, short value)
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }

static inline void
_Py_atomic_store_int_release(int *obj, int value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }
_Py_atomic_store_ushort_relaxed(unsigned short *obj, unsigned short value)
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }

static inline void
_Py_atomic_store_uchar_release(unsigned char *obj, unsigned char value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }
_Py_atomic_store_long_relaxed(long *obj, long value)
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }

static inline void
_Py_atomic_store_short_release(short *obj, short value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }
_Py_atomic_store_float_relaxed(float *obj, float value)
{ __atomic_store(obj, &value, __ATOMIC_RELAXED); }

static inline void
_Py_atomic_store_ushort_release(unsigned short *obj, unsigned short value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }
_Py_atomic_store_double_relaxed(double *obj, double value)
{ __atomic_store(obj, &value, __ATOMIC_RELAXED); }

static inline void
_Py_atomic_store_uint_release(unsigned int *obj, unsigned int value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }
_Py_atomic_store_llong_relaxed(long long *obj, long long value)
{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }

static inline void
_Py_atomic_store_long_release(long *obj, long value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }

static inline void
_Py_atomic_store_float_release(float *obj, float value)
{ __atomic_store(obj, &value, __ATOMIC_RELEASE); }
// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------

static inline void *
_Py_atomic_load_ptr_acquire(const void *obj)
{ return (void *)__atomic_load_n((void * const *)obj, __ATOMIC_ACQUIRE); }

static inline uintptr_t
_Py_atomic_load_uintptr_acquire(const uintptr_t *obj)
{ return (uintptr_t)__atomic_load_n(obj, __ATOMIC_ACQUIRE); }

static inline void
_Py_atomic_store_double_release(double *obj, double value)
{ __atomic_store(obj, &value, __ATOMIC_RELEASE); }
_Py_atomic_store_ptr_release(void *obj, void *value)
{ __atomic_store_n((void **)obj, value, __ATOMIC_RELEASE); }

static inline void
_Py_atomic_store_llong_release(long long *obj, long long value)
_Py_atomic_store_uintptr_release(uintptr_t *obj, uintptr_t value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }

static inline void
_Py_atomic_store_ullong_release(unsigned long long *obj,
unsigned long long value)
_Py_atomic_store_int_release(int *obj, int value)
{ __atomic_store_n(obj, value, __ATOMIC_RELEASE); }

static inline void
Expand Down
153 changes: 42 additions & 111 deletions Include/cpython/pyatomic_msc.h
Original file line number Diff line number Diff line change
Expand Up @@ -953,185 +953,116 @@ _Py_atomic_store_char_relaxed(char *obj, char value)
*(volatile char *)obj = value;
}


// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------

static inline void *
_Py_atomic_load_ptr_acquire(const void *obj)
{
#if defined(_M_X64) || defined(_M_IX86)
return *(void * volatile *)obj;
#elif defined(_M_ARM64)
return (void *)__ldar64((unsigned __int64 volatile *)obj);
#else
# error "no implementation of _Py_atomic_load_ptr_acquire"
#endif
}

static inline uintptr_t
_Py_atomic_load_uintptr_acquire(const uintptr_t *obj)
static inline void
_Py_atomic_store_uchar_relaxed(unsigned char *obj, unsigned char value)
{
#if defined(_M_X64) || defined(_M_IX86)
return *(uintptr_t volatile *)obj;
#elif defined(_M_ARM64)
return (uintptr_t)__ldar64((unsigned __int64 volatile *)obj);
#else
# error "no implementation of _Py_atomic_load_uintptr_acquire"
#endif
*(volatile unsigned char*)obj = value;
}

static inline void
_Py_atomic_store_ptr_release(void *obj, void *value)
_Py_atomic_store_short_relaxed(short *obj, short value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(void * volatile *)obj = value;
#elif defined(_M_ARM64)
__stlr64((unsigned __int64 volatile *)obj, (uintptr_t)value);
#else
# error "no implementation of _Py_atomic_store_ptr_release"
#endif
*(volatile short*)obj = value;
}

static inline void
_Py_atomic_store_uintptr_release(uintptr_t *obj, uintptr_t value)
_Py_atomic_store_ushort_relaxed(unsigned short *obj, unsigned short value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(uintptr_t volatile *)obj = value;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int64);
__stlr64((unsigned __int64 volatile *)obj, (unsigned __int64)value);
#else
# error "no implementation of _Py_atomic_store_uintptr_release"
#endif
*(volatile unsigned short*)obj = value;
}

static inline void
_Py_atomic_store_int_release(int *obj, int value)
_Py_atomic_store_uint_release(unsigned int *obj, unsigned int value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(int volatile *)obj = value;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int32);
__stlr32((unsigned __int32 volatile *)obj, (unsigned __int32)value);
#else
# error "no implementation of _Py_atomic_store_int_release"
#endif
*(volatile unsigned int*)obj = value;
}

static inline void
_Py_atomic_store_uchar_release(unsigned char *obj, unsigned char value)
_Py_atomic_store_long_relaxed(long *obj, long value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(unsigned char volatile *)obj = value;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int8);
__stlr8((unsigned __int8 volatile *)obj, (unsigned __int8)value);
#else
# error "no implementation of _Py_atomic_store_uchar_release"
#endif
*(volatile long *)obj = value;
}

static inline void
_Py_atomic_store_short_release(short *obj, short value)
_Py_atomic_store_float_relaxed(float *obj, float value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(short volatile *)obj = value;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int16);
__stlr16((unsigned __int16 volatile *)obj, (unsigned __int16)value);
#else
# error "no implementation of _Py_atomic_store_short_release"
#endif
*(volatile float *)obj = value;
}

static inline void
_Py_atomic_store_ushort_release(unsigned short *obj, unsigned short value)
_Py_atomic_store_double_relaxed(double *obj, double value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(unsigned short volatile *)obj = value;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int16);
__stlr16((unsigned __int16 volatile *)obj, (unsigned __int16)value);
#else
# error "no implementation of _Py_atomic_store_ushort_release"
#endif
*(volatile double *)obj = value;
}

static inline void
_Py_atomic_store_uint_release(unsigned int *obj, unsigned int value)
_Py_atomic_store_llong_relaxed(long long *obj, long long value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(unsigned int volatile *)obj = value;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int32);
__stlr32((unsigned __int32 volatile *)obj, (unsigned __int32)value);
#else
# error "no implementation of _Py_atomic_store_uint_release"
#endif
*(volatile long long*)obj = value;
}

static inline void
_Py_atomic_store_long_release(long *obj, long value)

// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------

static inline void *
_Py_atomic_load_ptr_acquire(const void *obj)
{
#if defined(_M_X64) || defined(_M_IX86)
*(long volatile *)obj = value;
return *(void * volatile *)obj;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int32);
__stlr32((unsigned __int32 volatile *)obj, (unsigned __int32)value);
return (void *)__ldar64((unsigned __int64 volatile *)obj);
#else
# error "no implementation of _Py_atomic_store_long_release"
# error "no implementation of _Py_atomic_load_ptr_acquire"
#endif
}

static inline void
_Py_atomic_store_float_release(float *obj, float value)
static inline uintptr_t
_Py_atomic_load_uintptr_acquire(const uintptr_t *obj)
{
#if defined(_M_X64) || defined(_M_IX86)
*(float volatile *)obj = value;
return *(uintptr_t volatile *)obj;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int32);
__stlr32((unsigned __int32 volatile *)obj, (unsigned __int32)value);
return (uintptr_t)__ldar64((unsigned __int64 volatile *)obj);
#else
# error "no implementation of _Py_atomic_store_float_release"
# error "no implementation of _Py_atomic_load_uintptr_acquire"
#endif
}

static inline void
_Py_atomic_store_double_release(double *obj, double value)
_Py_atomic_store_ptr_release(void *obj, void *value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(double volatile *)obj = value;
*(void * volatile *)obj = value;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int64);
__stlr64((unsigned __int64 volatile *)obj, (unsigned __int64)value);
__stlr64((unsigned __int64 volatile *)obj, (uintptr_t)value);
#else
# error "no implementation of _Py_atomic_store_double_release"
# error "no implementation of _Py_atomic_store_ptr_release"
#endif
}

static inline void
_Py_atomic_store_llong_release(long long *obj, long long value)
_Py_atomic_store_uintptr_release(uintptr_t *obj, uintptr_t value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(long long volatile *)obj = value;
*(uintptr_t volatile *)obj = value;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int64);
__stlr64((unsigned __int64 volatile *)obj, (unsigned __int64)value);
#else
# error "no implementation of _Py_atomic_store_llong_release"
# error "no implementation of _Py_atomic_store_uintptr_release"
#endif
}

static inline void
_Py_atomic_store_ullong_release(unsigned long long *obj, unsigned long long value)
_Py_atomic_store_int_release(int *obj, int value)
{
#if defined(_M_X64) || defined(_M_IX86)
*(unsigned long long volatile *)obj = value;
*(int volatile *)obj = value;
#elif defined(_M_ARM64)
_Py_atomic_ASSERT_ARG_TYPE(__int64);
__stlr64((unsigned __int64 volatile *)obj, (unsigned __int64)value);
_Py_atomic_ASSERT_ARG_TYPE(unsigned __int32);
__stlr32((unsigned __int32 volatile *)obj, (unsigned __int32)value);
#else
# error "no implementation of _Py_atomic_store_ullong_release"
# error "no implementation of _Py_atomic_store_int_release"
#endif
}

Expand Down
Loading

0 comments on commit 488dea5

Please sign in to comment.