volatile uint64 value;
} Atomic_uint64;
-#if defined __GNUC__ && defined VM_64BIT && \
- (defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 || defined VM_ARM_64)
+#ifdef VM_HAS_INT128
typedef ALIGNED(16) struct Atomic_uint128 {
volatile uint128 value;
} Atomic_uint128;
* registers.
*/
-#if defined __GNUC__ && defined VM_ARM_32
/* Force the link step to fail for unimplemented functions. */
extern int AtomicUndefined(void const *);
-#endif
/*
*
* Atomic_ReadIfEqualWrite128 --
*
- * Compare and exchange a 16 byte tuple.
+ * Compare exchange: Read variable, if equal to oldVal, write newVal
*
* Results:
- * old value
+ * The value that was compared against oldVal.
*
* Side effects:
- * None
+ * None.
*
*-----------------------------------------------------------------------------
*/
-#if defined __GNUC__ && defined VM_64BIT && \
- (defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 || defined VM_ARM_64)
+
+#ifdef VM_HAS_INT128
static INLINE uint128
Atomic_ReadIfEqualWrite128(Atomic_uint128 *ptr, // IN/OUT
uint128 oldVal, // IN
uint128 newVal) // IN
{
-#if defined VM_ARM_64
+#if defined __GNUC__ && defined VM_ARM_64
+#define VM_HAS_ATOMIC_READIFEQUALWRITE128 // This function can be used.
/*
* Don't use __sync_val_compare_and_swap, as this cannot magically
* use the right (LL/SC vs LSE) atomics without -moutline-atomics.
SMP_RW_BARRIER_RW();
return res.raw;
}
-#elif __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+#elif defined __GNUC__ && defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+#define VM_HAS_ATOMIC_READIFEQUALWRITE128 // This function can be used.
return __sync_val_compare_and_swap(&ptr->value, oldVal, newVal);
+#else
+ return AtomicUndefined(ptr + oldVal + newVal);
#endif
}
#endif
#elif defined _MSC_VER
val = var->value;
#else
-#error No compiler defined for Atomic_Read8
+#error Atomic_Read8 not implemented
#endif
return val;
#elif defined _MSC_VER
return _InterlockedExchange8((volatile char *)&var->value, val);
#else
-#error No compiler defined for Atomic_ReadWrite8
+#error Atomic_ReadWrite8 not implemented
#endif
}
#elif defined _MSC_VER
var->value = val;
#else
-#error No compiler defined for Atomic_Write8
+#error Atomic_Write8 not implemented
#endif
}
* Compare exchange: Read variable, if equal to oldVal, write newVal.
*
* Results:
- * The value of the atomic variable before the write.
+ * The value that was compared against oldVal.
*
* Side effects:
- * The variable may be modified.
+ * None.
*
*-----------------------------------------------------------------------------
*/
return _InterlockedCompareExchange8((volatile char *)&var->value,
newVal, oldVal);
#else
-#error No compiler defined for Atomic_ReadIfEqualWrite8
+#error Atomic_ReadIfEqualWrite8 not implemented
#endif
}
value = var->value;
#else
-#error No compiler defined for Atomic_Read
+#error Atomic_Read32 not implemented
#endif
return value;
#elif defined _MSC_VER
return _InterlockedExchange((long *)&var->value, (long)val);
#else
-#error No compiler defined for Atomic_ReadWrite
+#error Atomic_ReadWrite32 not implemented
#endif // __GNUC__
}
#define Atomic_ReadWrite Atomic_ReadWrite32
var->value = val;
#else
-#error No compiler defined for Atomic_Write
+#error Atomic_Write32 not implemented
#endif
}
#define Atomic_Write Atomic_Write32
* Compare exchange: Read variable, if equal to oldVal, write newVal
*
* Results:
- * The value of the atomic variable before the write.
+ * The value that was compared against oldVal.
*
* Side effects:
- * The variable may be modified.
+ * None.
*
*-----------------------------------------------------------------------------
*/
(long)newVal,
(long)oldVal);
#else
-#error No compiler defined for Atomic_ReadIfEqualWrite
+#error Atomic_ReadIfEqualWrite32 not implemented
#endif
}
#define Atomic_ReadIfEqualWrite Atomic_ReadIfEqualWrite32
* Compare exchange: Read variable, if equal to oldVal, write newVal
*
* Results:
- * The value of the atomic variable before the write.
+ * The value that was compared against oldVal.
*
* Side effects:
- * The variable may be modified.
+ * None.
*
*-----------------------------------------------------------------------------
*/
(__int64)newVal,
(__int64)oldVal);
#else
-#error No compiler defined for Atomic_ReadIfEqualWrite64
+#error Atomic_ReadIfEqualWrite64 not implemented
#endif
}
#endif
#elif defined _MSC_VER
_InterlockedAnd((long *)&var->value, (long)val);
#else
-#error No compiler defined for Atomic_And
+#error Atomic_And32 not implemented
#endif
}
#define Atomic_And Atomic_And32
#elif defined _MSC_VER
_InterlockedOr((long *)&var->value, (long)val);
#else
-#error No compiler defined for Atomic_Or
+#error Atomic_Or32 not implemented
#endif
}
#define Atomic_Or Atomic_Or32
#elif defined _MSC_VER
_InterlockedXor((long *)&var->value, (long)val);
#else
-#error No compiler defined for Atomic_Xor
+#error Atomic_Xor32 not implemented
#endif
}
#define Atomic_Xor Atomic_Xor32
#elif defined _MSC_VER
_InterlockedXor64((__int64 *)&var->value, (__int64)val);
#else
-#error No compiler defined for Atomic_Xor64
+#error Atomic_Xor64 not implemented
#endif
}
#endif
#elif defined _MSC_VER
_InterlockedExchangeAdd((long *)&var->value, (long)val);
#else
-#error No compiler defined for Atomic_Add
+#error Atomic_Add32 not implemented
#endif
}
#define Atomic_Add Atomic_Add32
_InterlockedExchangeAdd((long *)&var->value, (long)-val);
# pragma warning(pop)
#else
-#error No compiler defined for Atomic_Sub
+#error Atomic_Sub32 not implemented
#endif
}
#define Atomic_Sub Atomic_Sub32
#elif defined _MSC_VER
_InterlockedIncrement((long *)&var->value);
#else
-#error No compiler defined for Atomic_Inc
+#error Atomic_Inc32 not implemented
#endif
}
#define Atomic_Inc Atomic_Inc32
#elif defined _MSC_VER
_InterlockedDecrement((long *)&var->value);
#else
-#error No compiler defined for Atomic_Dec
+#error Atomic_Dec32 not implemented
#endif
}
#define Atomic_Dec Atomic_Dec32
#elif defined _MSC_VER
return _InterlockedExchangeAdd((long *)&var->value, (long)val);
#else
-#error No compiler defined for Atomic_ReadAdd32
+#error Atomic_ReadAdd32 not implemented
#endif
}
(__int64)newVal,
(__int64)oldVal);
#else
-#error No compiler defined for Atomic_CMPXCHG64
+#error Atomic_CMPXCHG64 not implemented
#endif // !GNUC
}
#elif defined _MSC_VER
return _InterlockedExchangeAdd64((__int64 *)&var->value, (__int64)val);
#else
-#error No compiler defined for Atomic_ReadAdd64
+#error Atomic_ReadAdd64 not implemented
#endif
#else
#elif defined _MSC_VER
_InterlockedExchangeAdd64((__int64 *)&var->value, (__int64)val);
#else
-#error No compiler defined for Atomic_Add64
+#error Atomic_Add64 not implemented
#endif
}
#elif defined _MSC_VER
_InterlockedExchangeAdd64((__int64 *)&var->value, (__int64)-val);
#else
-#error No compiler defined for Atomic_Sub64
+#error Atomic_Sub64 not implemented
#endif
}
#elif defined _MSC_VER
_InterlockedIncrement64((__int64 *)&var->value);
#else
-#error No compiler defined for Atomic_Inc64
+#error Atomic_Inc64 not implemented
#endif
}
#elif defined _MSC_VER
_InterlockedDecrement64((__int64 *)&var->value);
#else
-#error No compiler defined for Atomic_Dec64
+#error Atomic_Dec64 not implemented
#endif
}
#elif defined VM_ARM_64
value = _VMATOM_X(R, 16, &var->value);
#else
-#error No 16-bits atomics.
+#error Atomic_Read16 not implemented
#endif
#endif
#elif defined VM_ARM_64
return _VMATOM_X(RW, 16, TRUE, &var->value, val);
#else
-#error No 16-bits atomics.
+#error Atomic_ReadWrite16 not implemented
#endif
#endif
}
*/
Atomic_ReadWrite16(var, val);
#else
-#error No 16-bits atomics.
+#error Atomic_Write16 not implemented
#endif
#endif
}
* Compare exchange: Read variable, if equal to oldVal, write newVal
*
* Results:
- * The value of the atomic variable before the write.
+ * The value that was compared against oldVal.
*
* Side effects:
- * The variable may be modified.
+ * None.
*
*-----------------------------------------------------------------------------
*/
#elif defined VM_ARM_64
return _VMATOM_X(RIFEQW, 16, TRUE, &var->value, oldVal, newVal);
#else
-#error No 16-bits atomics.
+#error Atomic_ReadIfEqualWrite16 not implemented
#endif
#endif
}
#elif defined VM_ARM_64
_VMATOM_X(OP, 16, TRUE, &var->value, and, val);
#else
-#error No 16-bits atomics.
+#error Atomic_And16 not implemented
#endif
#endif
}
#elif defined VM_ARM_64
_VMATOM_X(OP, 16, TRUE, &var->value, orr, val);
#else
-#error No 16-bits atomics.
+#error Atomic_Or16 not implemented
#endif
#endif
}
#elif defined VM_ARM_64
_VMATOM_X(OP, 16, TRUE, &var->value, eor, val);
#else
-#error No 16-bits atomics.
+#error Atomic_Xor16 not implemented
#endif
#endif
}
#elif defined VM_ARM_64
_VMATOM_X(OP, 16, TRUE, &var->value, add, val);
#else
-#error No 16-bits atomics.
+#error Atomic_Add16 not implemented
#endif
#endif
}
#elif defined VM_ARM_64
_VMATOM_X(OP, 16, TRUE, &var->value, sub, val);
#else
-#error No 16-bits atomics.
+#error Atomic_Sub16 not implemented
#endif
#endif
}
#elif defined VM_ARM_ANY
Atomic_Add16(var, 1);
#else
-#error No 16-bits atomics.
+#error Atomic_Inc16 not implemented
#endif
#endif
}
#elif defined VM_ARM_ANY
Atomic_Sub16(var, 1);
#else
-#error No 16-bits atomics.
+#error Atomic_Dec16 not implemented
#endif
#endif
}
#elif defined VM_ARM_64
return _VMATOM_X(ROP, 16, TRUE, &var->value, add, val);
#else
-#error No 16-bits atomics.
+#error Atomic_ReadAdd16 not implemented
#endif
#endif
}