Skip to content

Commit 4667915

Browse files
authored
[SYCL] Add static cast for half builtins relational (#6133)
This PR adds a static cast to builtins_relational functions which apply a negative operation to a boolean type. This is only applied to functions which are specialised for cl_half. The cast prevents windows error message C4804. This resolves a windows build issue introduced by #6061
1 parent 76a3898 commit 4667915

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

sycl/source/detail/builtins_relational.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,48 @@ __SYCL_INLINE_NAMESPACE(cl) {
2121
namespace __host_std {
2222
namespace {
2323

24-
template <typename T> inline T __vFOrdEqual(T x, T y) { return -(x == y); }
24+
template <typename T> inline T __vFOrdEqual(T x, T y) {
25+
return -static_cast<T>(x == y);
26+
}
2527

2628
template <typename T> inline T __sFOrdEqual(T x, T y) { return x == y; }
2729

28-
template <typename T> inline T __vFUnordNotEqual(T x, T y) { return -(x != y); }
30+
template <typename T> inline T __vFUnordNotEqual(T x, T y) {
31+
return -static_cast<T>(x != y);
32+
}
2933

3034
template <typename T> inline T __sFUnordNotEqual(T x, T y) { return x != y; }
3135

32-
template <typename T> inline T __vFOrdGreaterThan(T x, T y) { return -(x > y); }
36+
template <typename T> inline T __vFOrdGreaterThan(T x, T y) {
37+
return -static_cast<T>(x > y);
38+
}
3339

3440
template <typename T> inline T __sFOrdGreaterThan(T x, T y) { return x > y; }
3541

3642
template <typename T> inline T __vFOrdGreaterThanEqual(T x, T y) {
37-
return -(x >= y);
43+
return -static_cast<T>(x >= y);
3844
}
3945

4046
template <typename T> inline T __sFOrdGreaterThanEqual(T x, T y) {
4147
return x >= y;
4248
}
4349

4450
template <typename T> inline T __vFOrdLessThanEqual(T x, T y) {
45-
return -(x <= y);
51+
return -static_cast<T>(x <= y);
4652
}
4753

4854
template <typename T> inline T __sFOrdLessThanEqual(T x, T y) { return x <= y; }
4955

5056
template <typename T> inline T __vFOrdNotEqual(T x, T y) {
51-
return -((x < y) || (x > y));
57+
return -static_cast<T>((x < y) || (x > y));
5258
}
5359

5460
template <typename T> inline T __sFOrdNotEqual(T x, T y) {
5561
return ((x < y) || (x > y));
5662
}
5763

5864
template <typename T> inline T __vLessOrGreater(T x, T y) {
59-
return -((x < y) || (x > y));
65+
return -static_cast<T>((x < y) || (x > y));
6066
}
6167

6268
template <typename T> inline T __sLessOrGreater(T x, T y) {
@@ -67,7 +73,7 @@ template <typename T> s::cl_int inline __Any(T x) { return d::msbIsSet(x); }
6773
template <typename T> s::cl_int inline __All(T x) { return d::msbIsSet(x); }
6874

6975
template <typename T> inline T __vOrdered(T x, T y) {
70-
return -(
76+
return -static_cast<T>(
7177
!(std::isunordered(d::cast_if_host_half(x), d::cast_if_host_half(y))));
7278
}
7379

@@ -227,7 +233,7 @@ __SYCL_EXPORT s::cl_int FOrdLessThan(s::cl_half x, s::cl_half y) __NOEXC {
227233
return (x < y);
228234
}
229235
__SYCL_EXPORT s::cl_short __vFOrdLessThan(s::cl_half x, s::cl_half y) __NOEXC {
230-
return -(x < y);
236+
return -static_cast<s::cl_short>(x < y);
231237
}
232238
MAKE_1V_2V_FUNC(FOrdLessThan, __vFOrdLessThan, s::cl_int, s::cl_float,
233239
s::cl_float)

0 commit comments

Comments
 (0)