|
23 | 23 | #include <sstream>
|
24 | 24 | #include <vector>
|
25 | 25 |
|
| 26 | +template <> |
| 27 | +bool host_atomic_compare_exchange<float, float>( |
| 28 | + volatile float *a, float *expected, float desired, |
| 29 | + TExplicitMemoryOrderType order_success, |
| 30 | + TExplicitMemoryOrderType order_failure) |
| 31 | +{ |
| 32 | + union FloatInt { |
| 33 | + float f; |
| 34 | + int i; |
| 35 | + }; |
| 36 | + FloatInt a2{ *a }; |
| 37 | + FloatInt expected2{ *expected }; |
| 38 | + FloatInt desired2{ desired }; |
| 39 | + FloatInt tmp; |
| 40 | +#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32)) |
| 41 | + tmp.i = InterlockedCompareExchange(&a2.i, desired2.i, expected2.i); |
| 42 | +#elif defined(__GNUC__) |
| 43 | + tmp.i = __sync_val_compare_and_swap(&a2.i, expected2.i, desired2.i); |
| 44 | +#else |
| 45 | + log_info("Host function not implemented: atomic_compare_exchange\n"); |
| 46 | + tmp.i = 0; |
| 47 | +#endif |
| 48 | + if (tmp.i == expected2.i) |
| 49 | + { |
| 50 | + *a = a2.f; |
| 51 | + return true; |
| 52 | + } |
| 53 | + *expected = tmp.f; |
| 54 | + return false; |
| 55 | +} |
| 56 | + |
| 57 | +template <> |
| 58 | +bool host_atomic_compare_exchange<double, double>( |
| 59 | + volatile double *a, double *expected, double desired, |
| 60 | + TExplicitMemoryOrderType order_success, |
| 61 | + TExplicitMemoryOrderType order_failure) |
| 62 | +{ |
| 63 | + union DoubleInt64 { |
| 64 | + double d; |
| 65 | + int64_t i; |
| 66 | + }; |
| 67 | + DoubleInt64 a2{ *a }; |
| 68 | + DoubleInt64 expected2{ *expected }; |
| 69 | + DoubleInt64 desired2{ desired }; |
| 70 | + DoubleInt64 tmp; |
| 71 | +#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32)) |
| 72 | + tmp.i = InterlockedCompareExchange(&a2.i, desired2.i, expected2.i); |
| 73 | +#elif defined(__GNUC__) |
| 74 | + tmp.i = __sync_val_compare_and_swap(&a2.i, expected2.i, desired2.i); |
| 75 | +#else |
| 76 | + log_info("Host function not implemented: atomic_compare_exchange\n"); |
| 77 | + tmp.i = 0; |
| 78 | +#endif |
| 79 | + if (tmp.i == expected2.i) |
| 80 | + { |
| 81 | + *a = a2.d; |
| 82 | + return true; |
| 83 | + } |
| 84 | + *expected = tmp.d; |
| 85 | + return false; |
| 86 | +} |
| 87 | + |
26 | 88 | template <typename HostAtomicType, typename HostDataType>
|
27 | 89 | class CBasicTestStore
|
28 | 90 | : public CBasicTestMemOrderScope<HostAtomicType, HostDataType> {
|
@@ -852,6 +914,14 @@ int test_atomic_compare_exchange_strong_generic(cl_device_id deviceID,
|
852 | 914 | TYPE_ATOMIC_ULONG, useSVM);
|
853 | 915 | EXECUTE_TEST(error,
|
854 | 916 | test_ulong.Execute(deviceID, context, queue, num_elements));
|
| 917 | + CBasicTestCompareStrong<HOST_ATOMIC_FLOAT, HOST_FLOAT> test_float( |
| 918 | + TYPE_ATOMIC_FLOAT, useSVM); |
| 919 | + EXECUTE_TEST(error, |
| 920 | + test_float.Execute(deviceID, context, queue, num_elements)); |
| 921 | + CBasicTestCompareStrong<HOST_ATOMIC_DOUBLE, HOST_DOUBLE> test_double( |
| 922 | + TYPE_ATOMIC_DOUBLE, useSVM); |
| 923 | + EXECUTE_TEST(error, |
| 924 | + test_double.Execute(deviceID, context, queue, num_elements)); |
855 | 925 | if (AtomicTypeInfo(TYPE_ATOMIC_SIZE_T).Size(deviceID) == 4)
|
856 | 926 | {
|
857 | 927 | CBasicTestCompareStrong<HOST_ATOMIC_INTPTR_T32, HOST_INTPTR_T32>
|
@@ -986,6 +1056,14 @@ int test_atomic_compare_exchange_weak_generic(cl_device_id deviceID,
|
986 | 1056 | test_long.Execute(deviceID, context, queue, num_elements));
|
987 | 1057 | CBasicTestCompareWeak<HOST_ATOMIC_ULONG, HOST_ULONG> test_ulong(
|
988 | 1058 | TYPE_ATOMIC_ULONG, useSVM);
|
| 1059 | + CBasicTestCompareWeak<HOST_ATOMIC_FLOAT, HOST_FLOAT> test_float( |
| 1060 | + TYPE_ATOMIC_FLOAT, useSVM); |
| 1061 | + EXECUTE_TEST(error, |
| 1062 | + test_float.Execute(deviceID, context, queue, num_elements)); |
| 1063 | + CBasicTestCompareWeak<HOST_ATOMIC_DOUBLE, HOST_DOUBLE> test_double( |
| 1064 | + TYPE_ATOMIC_DOUBLE, useSVM); |
| 1065 | + EXECUTE_TEST(error, |
| 1066 | + test_double.Execute(deviceID, context, queue, num_elements)); |
989 | 1067 | EXECUTE_TEST(error,
|
990 | 1068 | test_ulong.Execute(deviceID, context, queue, num_elements));
|
991 | 1069 | if (AtomicTypeInfo(TYPE_ATOMIC_SIZE_T).Size(deviceID) == 4)
|
|
0 commit comments