Skip to content

Commit 8b82c67

Browse files
authored
[SYCL] Fix __s_long_mad_sat built-in function implementation (#2790)
In the function '__s_long_mad_sat', the second condition had an incorrect return value. It must return a negative value, but only positive value was returned. Signed-off-by: mdimakov <maxim.dimakov@intel.com>
1 parent 10b4e8a commit 8b82c67

File tree

2 files changed

+139
-1
lines changed

2 files changed

+139
-1
lines changed

sycl/source/detail/builtins_integer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ template <typename T> inline T __s_long_mad_sat(T a, T b, T c) {
171171
if (!neg_prod && mulhi != 0)
172172
return d::max_v<T>();
173173
if (neg_prod && mulhi != -1)
174-
return d::max_v<T>(); // essentially some other negative value.
174+
return d::min_v<T>(); // essentially some other negative value.
175175
return __s_add_sat(T(a * b), c);
176176
}
177177

sycl/test/regression/mad_sat.cpp

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// RUN: %clangxx -fsycl %s -o %t.out
2+
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
3+
4+
#include <CL/sycl.hpp>
5+
6+
int main() {
7+
cl::sycl::queue testQueue;
8+
9+
{
10+
const cl::sycl::longlong3 verification3(
11+
9223372036854775807LL, 9223372036854775807LL, -9223372036854775808LL);
12+
13+
cl::sycl::longlong3 inputData_0(
14+
1152105081885725616LL, 8383539663869980295LL, -3013159033463244495LL);
15+
cl::sycl::longlong3 inputData_1(9169239286331099647LL,
16+
8545168655265359544LL, 69290337040907021LL);
17+
cl::sycl::longlong3 inputData_2(
18+
-5670250901301018333LL, 216462155376518854LL, -7910909987096217335LL);
19+
20+
cl::sycl::buffer<cl::sycl::longlong3, 1> buffer(1);
21+
22+
testQueue.submit([&](cl::sycl::handler &h) {
23+
auto resultPtr =
24+
buffer.template get_access<cl::sycl::access::mode::write>(h);
25+
h.single_task<class k3>([=]() {
26+
resultPtr[0] = cl::sycl::mad_sat(inputData_0, inputData_1, inputData_2);
27+
});
28+
});
29+
const auto HostAccessor = buffer.get_access<cl::sycl::access::mode::read>();
30+
for (int i = 0; i < 3; i++)
31+
assert((HostAccessor[0][i] == verification3[i]) && "Incorrect result");
32+
}
33+
{
34+
const cl::sycl::longlong4 verification4(
35+
9223372036854775807LL, 9223372036854775807LL, -9223372036854775808LL,
36+
9223372036854775807LL);
37+
38+
cl::sycl::longlong4 inputData_0(
39+
-4713774672458165250LL, 7161321293740295698LL, -7560042360032818022LL,
40+
1712118953348815386LL);
41+
cl::sycl::longlong4 inputData_1(
42+
-5256951628950351348LL, 3094294642897896981LL, 4183324171724765944LL,
43+
1726930751531248453LL);
44+
cl::sycl::longlong4 inputData_2(
45+
-614349234816759997LL, -7793620271163345724LL, 5480991826433743823LL,
46+
-3977840325478979484LL);
47+
48+
cl::sycl::buffer<cl::sycl::longlong4, 1> buffer(1);
49+
50+
testQueue.submit([&](cl::sycl::handler &h) {
51+
auto resultPtr =
52+
buffer.template get_access<cl::sycl::access::mode::write>(h);
53+
h.single_task<class k4>([=]() {
54+
resultPtr[0] = cl::sycl::mad_sat(inputData_0, inputData_1, inputData_2);
55+
});
56+
});
57+
const auto HostAccessor = buffer.get_access<cl::sycl::access::mode::read>();
58+
for (int i = 0; i < 4; i++)
59+
assert((HostAccessor[0][i] == verification4[i]) && "Incorrect result");
60+
}
61+
{
62+
const cl::sycl::longlong8 verification8(
63+
9223372036854775807LL, 9223372036854775807LL, -9223372036854775808LL,
64+
-9223372036854775808LL, 9223372036854775807LL, 9223372036854775807LL,
65+
-9223372036854775808LL, -9223372036854775808LL);
66+
67+
cl::sycl::longlong8 inputData_0(
68+
3002837817109371705LL, -6132505093056073745LL, -2677806413031023542LL,
69+
-3906932152445696896LL, -5966911996430888011LL, 487233493241732294LL,
70+
8234534527416862935LL, 8302379558520488989LL);
71+
cl::sycl::longlong8 inputData_1(
72+
3895748400226584336LL, -3171989754828069475LL, 6135091761884568657LL,
73+
3449810579449494485LL, -5153085649597103327LL, 2036067225828737775LL,
74+
-2456339276147680058LL, -2321401317481120691LL);
75+
cl::sycl::longlong8 inputData_2(
76+
5847800471474896191LL, 6421268696360310080LL, 426131359031594004LL,
77+
3388848179800138438LL, 9095634920776267157LL, 3909069092545608647LL,
78+
-6551917618131929798LL, -5283018165188606431LL);
79+
80+
cl::sycl::buffer<cl::sycl::longlong8, 1> buffer(1);
81+
82+
testQueue.submit([&](cl::sycl::handler &h) {
83+
auto resultPtr =
84+
buffer.template get_access<cl::sycl::access::mode::write>(h);
85+
h.single_task<class k8>([=]() {
86+
resultPtr[0] = cl::sycl::mad_sat(inputData_0, inputData_1, inputData_2);
87+
});
88+
});
89+
const auto HostAccessor = buffer.get_access<cl::sycl::access::mode::read>();
90+
for (int i = 0; i < 8; i++)
91+
assert((HostAccessor[0][i] == verification8[i]) && "Incorrect result");
92+
}
93+
{
94+
const cl::sycl::longlong16 verification16(
95+
-9223372036854775808LL, 9223372036854775807LL, 9223372036854775807LL,
96+
-9223372036854775808LL, 9223372036854775807LL, 9223372036854775807LL,
97+
9223372036854775807LL, 9223372036854775807LL, 9223372036854775807LL,
98+
9223372036854775807LL, -9223372036854775808LL, 9223372036854775807LL,
99+
-9223372036854775808LL, 9223372036854775807LL, -9223372036854775808LL,
100+
-9223372036854775808LL);
101+
102+
cl::sycl::longlong16 inputData_0(
103+
4711072418277000515LL, -8205098172692021203LL, -7385016145788992368LL,
104+
5953521028589173909LL, -5219240995491769312LL, 8710496141913755416LL,
105+
-6685846261491268433LL, 4193173269411595542LL, -8540195959022520771LL,
106+
-4715465363106336895LL, -1020086937442724783LL, 4496316677230042947LL,
107+
1321442475247578017LL, -7374746170855359764LL, -3206370806055241163LL,
108+
-2175226063524462053LL);
109+
cl::sycl::longlong16 inputData_1(
110+
-9126728881985856159LL, -8235441378758843293LL, -3529617622861997052LL,
111+
-4696495345590499183LL, -2446014787831249326LL, 3966377959819902357LL,
112+
-8707315735766590681LL, 4940281453308003965LL, -4008494233289413829LL,
113+
-1007875458987895243LL, 8007184939842565626LL, 7006363475270750393LL,
114+
-3126435375497361798LL, -2666957213164527889LL, 3425215156535282625LL,
115+
5057359883753713949LL);
116+
cl::sycl::longlong16 inputData_2(
117+
-5792361016316836568LL, 1155364222481085809LL, 7552404711758320408LL,
118+
-9123476257323872288LL, -924920183965907175LL, 1921314238201973170LL,
119+
3462681782260196063LL, 7822120358287768333LL, -3130033938219713817LL,
120+
-3165995450630991604LL, -7647706888277832178LL, -8427901934971949821LL,
121+
4207763935319579681LL, 1564279736903158695LL, 3722632463806041635LL,
122+
939009161285897285LL);
123+
124+
cl::sycl::buffer<cl::sycl::longlong16, 1> buffer(1);
125+
126+
testQueue.submit([&](cl::sycl::handler &h) {
127+
auto resultPtr =
128+
buffer.template get_access<cl::sycl::access::mode::write>(h);
129+
130+
h.single_task<class k16>([=]() {
131+
resultPtr[0] = cl::sycl::mad_sat(inputData_0, inputData_1, inputData_2);
132+
});
133+
});
134+
const auto HostAccessor = buffer.get_access<cl::sycl::access::mode::read>();
135+
for (int i = 0; i < 16; i++)
136+
assert((HostAccessor[0][i] == verification16[i]) && "Incorrect result");
137+
}
138+
}

0 commit comments

Comments
 (0)