Fix two bugs related to C11 atomics (#2700)
Some checks failed
Presubmit / Build ubuntu-22.04 gl (push) Failing after 1s
Presubmit / Build ubuntu-22.04 aarch64 debug (push) Failing after 1s
Presubmit / Build ubuntu-22.04 android-aarch64 (push) Failing after 1s
Presubmit / Check code format (push) Failing after 1s
Presubmit / Build macos-latest (push) Has been cancelled
Presubmit / Build windows-11-arm (push) Has been cancelled
Presubmit / Build windows-latest (push) Has been cancelled
Presubmit / Run Tests (pocl) (push) Has been cancelled

Fix two bugs related to C11 atomics (#2700)
This commit is contained in:
Michal Babej 2026-06-16 19:02:54 +03:00 committed by GitHub
parent 8d8f3d272d
commit 726a6d94da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 5 deletions

View file

@ -17,6 +17,7 @@
#define HOST_ATOMICS_H_
#include "harness/testHarness.h"
#include <cstring>
#include <mutex>
#include "CL/cl_half.h"
@ -281,13 +282,15 @@ bool host_atomic_compare_exchange(volatile AtomicType *a, CorrespondingType *exp
{
static std::mutex mtx;
std::lock_guard<std::mutex> lock(mtx);
tmp = static_cast<CorrespondingType>(*a);
if (tmp == *expected)
// this is necessary so that (*a == *exp) evaluates to true when
// comparing NANs
if (std::memcmp((const void *)a, expected, sizeof(CorrespondingType))
== 0)
{
*a = static_cast<AtomicType>(desired);
return true;
}
*expected = tmp;
*expected = *a;
}
else
{
@ -299,7 +302,9 @@ bool host_atomic_compare_exchange(volatile AtomicType *a, CorrespondingType *exp
log_info("Host function not implemented: atomic_compare_exchange\n");
tmp = 0;
#endif
if (tmp == *expected) return true;
if (std::memcmp((const void *)&tmp, expected, sizeof(CorrespondingType))
== 0)
return true;
*expected = tmp;
}
return false;

View file

@ -3740,7 +3740,10 @@ public:
}
cl_uint NumResults(cl_uint threadCount, cl_device_id deviceID) override
{
if constexpr (std::is_same_v<HostDataType, HOST_FLOAT>)
if constexpr (
std::is_same_v<
HostDataType,
HOST_DOUBLE> || std::is_same_v<HostDataType, HOST_FLOAT>)
{
return threadCount;
}