Relational functions#
Relational functions are defined in the sycl
namespace
and are available on both host and device. These functions
perform various relational comparisons on sycl::vec
,
sycl::marray
, and scalar types.
The comparisons performed by sycl::isequal
, sycl::isgreater
,
sycl::isgreaterequal
, sycl::isless
, sycl::islessequal
,
and sycl::islessgreater
are false
when one or both operands
are NaN. The comparison performed by sycl::isnotequal
is true
when one or both operands are NaN.
The function descriptions in this section use two terms that refer to a specific list of types. The term generic scalar type represents the following types:
char
signed char
short
int
long
long long
unsigned char
unsigned short
unsigned int
unsigned long
unsigned long long
float
double
half
The term vector element type represents these types:
int8_t
int16_t
int32_t
int64_t
uint8_t
uint16_t
uint32_t
uint64_t
float
double
half
See also
SYCL Specification Section 4.17.10
sycl::isequal
#
Overloads 1-3
bool isequal(float x, float y);
bool isequal(double x, double y);
bool isequal(half x, half y);
Returns the value (x == y)
.
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isequal(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1
andNonScalar2
:Both
NonScalar1
andNonScalar2
aresycl::marray
;NonScalar1
andNonScalar2
are any combination ofsycl::vec
and the__swizzled_vec__
type;
NonScalar1
andNonScalar2
have the same number of elements and the same element type;The element type is
float
,double
, orhalf
.
If NonScalar1
is sycl::marray
, the value (x[i] == y[i])
for each element of x
and y
. If NonScalar1
is
sycl::vec
or the __swizzled_vec__
type, returns the value
((x[i] == y[i]) ? -1 : 0)
for each element of x
and y
.
The return type depends on NonScalar1
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::isnotequal
#
Overloads 1-3
bool isnotequal(float x, float y);
bool isnotequal(double x, double y);
bool isnotequal(half x, half y);
Returns the value (x != y)
.
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isnotequal(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1
andNonScalar2
:Both
NonScalar1
andNonScalar2
aresycl::marray
;NonScalar1
andNonScalar2
are any combination ofsycl::vec
and the__swizzled_vec__
type;
NonScalar1
andNonScalar2
have the same number of elements and the same element type;The element type is
float
,double
, orhalf
.
If NonScalar1
is sycl::marray
, the value (x[i] != y[i])
for each element of x
and y
. If NonScalar1
is
sycl::vec
or the __swizzled_vec__
type, returns the value
((x[i] != y[i]) ? -1 : 0)
for each element of x
and y
.
The return type depends on NonScalar1
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::isgreater
#
Overloads 1-3
bool isgreater(float x, float y);
bool isgreater(double x, double y);
bool isgreater(half x, half y);
Returns the value (x > y)
.
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isgreater(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1
andNonScalar2
:Both
NonScalar1
andNonScalar2
aresycl::marray
;NonScalar1
andNonScalar2
are any combination ofsycl::vec
and the__swizzled_vec__
type;
NonScalar1
andNonScalar2
have the same number of elements and the same element type;The element type is
float
,double
, orhalf
.
If NonScalar1
is sycl::marray
, the value (x[i] > y[i])
for each element of x
and y
. If NonScalar1
is
sycl::vec
or the __swizzled_vec__
type, returns the value
((x[i] > y[i]) ? -1 : 0)
for each element of x
and y
.
The return type depends on NonScalar1
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::isgreaterequal
#
Overloads 1-3
bool isgreaterequal(float x, float y);
bool isgreaterequal(double x, double y);
bool isgreaterequal(half x, half y);
Returns the value (x >= y)
.
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isgreaterequal(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1
andNonScalar2
:Both
NonScalar1
andNonScalar2
aresycl::marray
;NonScalar1
andNonScalar2
are any combination ofsycl::vec
and the__swizzled_vec__
type;
NonScalar1
andNonScalar2
have the same number of elements and the same element type;The element type is
float
,double
, orhalf
.
If NonScalar1
is sycl::marray
, the value (x[i] >= y[i])
for each element of x
and y
. If NonScalar1
is
sycl::vec
or the __swizzled_vec__
type, returns the value
((x[i] >= y[i]) ? -1 : 0)
for each element of x
and y
.
The return type depends on NonScalar1
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::isless
#
Overloads 1-3
bool isless(float x, float y);
bool isless(double x, double y);
bool isless(half x, half y);
Returns the value (x < y)
.
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isless(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1
andNonScalar2
:Both
NonScalar1
andNonScalar2
aresycl::marray
;NonScalar1
andNonScalar2
are any combination ofsycl::vec
and the__swizzled_vec__
type;
NonScalar1
andNonScalar2
have the same number of elements and the same element type;The element type is
float
,double
, orhalf
.
If NonScalar1
is sycl::marray
, the value (x[i] < y[i])
for each element of x
and y
. If NonScalar1
is
sycl::vec
or the __swizzled_vec__
type, returns the value
((x[i] < y[i]) ? -1 : 0)
for each element of x
and y
.
The return type depends on NonScalar1
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::islessequal
#
Overloads 1-3
bool islessequal(float x, float y);
bool islessequal(double x, double y);
bool islessequal(half x, half y);
Returns the value (x <= y)
.
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ islessequal(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1
andNonScalar2
:Both
NonScalar1
andNonScalar2
aresycl::marray
;NonScalar1
andNonScalar2
are any combination ofsycl::vec
and the__swizzled_vec__
type;
NonScalar1
andNonScalar2
have the same number of elements and the same element type;The element type is
float
,double
, orhalf
.
If NonScalar1
is sycl::marray
, the value (x[i] <= y[i])
for each element of x
and y
. If NonScalar1
is
sycl::vec
or the __swizzled_vec__
type, returns the value
((x[i] <= y[i]) ? -1 : 0)
for each element of x
and y
.
The return type depends on NonScalar1
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::islessgreater
#
Overloads 1-3
bool islessgreater(float x, float y);
bool islessgreater(double x, double y);
bool islessgreater(half x, half y);
Returns the value (x < y) || (x > y)
.
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ islessgreater(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1
andNonScalar2
:Both
NonScalar1
andNonScalar2
aresycl::marray
;NonScalar1
andNonScalar2
are any combination ofsycl::vec
and the__swizzled_vec__
type;
NonScalar1
andNonScalar2
have the same number of elements and the same element type;The element type is
float
,double
, orhalf
.
If NonScalar1
is sycl::marray
, the value
(x[i] < y[i]) || (x[i] > y[i])
for each element of x
and y
. If NonScalar1
is
sycl::vec
or the __swizzled_vec__
type, returns the value
(((x[i] < y[i]) || (x[i] > y[i])) ? -1 : 0)
for each element
of x
and y
.
The return type depends on NonScalar1
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::isfinite
#
Overloads 1-3
bool isfinite(float x);
bool isfinite(double x);
bool isfinite(half x);
Returns the value true
only if x
has finite value
.
Overload 4
template<typename NonScalar>
/*return-type*/ isfinite(NonScalar x);
Available only if all of the following conditions are met:
NonScalar
issycl::marray
,sycl::vec
, or the__swizzled_vec__
type;The element type is
float
,double
, orhalf
.
If NonScalar
is sycl::marray
, returns true
for
each element of x
only if x[i]
is a finite value. If
NonScalar
is sycl::vec
or the __swizzled_vec__
type,
returns -1 for each element of x
if x[i]
is a finite
value and returns 0 otherwise.
The return type depends on NonScalar
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::isinf
#
Overloads 1-3
bool isinf(float x);
bool isinf(double x);
bool isinf(half x);
Returns the value true
only if x
has an
infinity value (either positive or negative).
Overload 4
template<typename NonScalar>
/*return-type*/ isinf(NonScalar x);
Available only if all of the following conditions are met:
NonScalar
issycl::marray
,sycl::vec
, or the__swizzled_vec__
type;The element type is
float
,double
, orhalf
.
If NonScalar
is sycl::marray
, returns true
for
each element of x
only if x[i]
has an infinity value.
If NonScalar
is sycl::vec
or the __swizzled_vec__
type, returns -1 for each element of x
if x[i]
has an
infinity value and returns 0 otherwise.
The return type depends on NonScalar
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::isnan
#
Overloads 1-3
bool isnan(float x);
bool isnan(double x);
bool isnan(half x);
Returns the value true
only if x
has a NaN value.
Overload 4
template<typename NonScalar>
/*return-type*/ isnan(NonScalar x);
Available only if all of the following conditions are met:
NonScalar
issycl::marray
,sycl::vec
, or the__swizzled_vec__
type;The element type is
float
,double
, orhalf
.
If NonScalar is sycl::marray
, returns true
for each
element of x
only if x[i]
has a NaN value. If
NonScalar
is sycl::vec
or the __swizzled_vec__
type, returns -1 for each element of x
if x[i]
has
a NaN value and returns 0 otherwise.
The return type depends on NonScalar
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::isnormal
#
Overloads 1-3
bool isnormal(float x);
bool isnormal(double x);
bool isnormal(half x);
Returns the value true
only if x
has a normal value.
Overload 4
template<typename NonScalar>
/*return-type*/ isnormal(NonScalar x);
Available only if all of the following conditions are met:
NonScalar
issycl::marray
,sycl::vec
, or the__swizzled_vec__
type;The element type is
float
,double
, orhalf
.
If NonScalar
is sycl::marray
, returns true
for
each element of x
only if x[i]
has a normal value.
If NonScalar
is sycl::vec
or the __swizzled_vec__
type, returns -1 for each element of x
if x[i]
has a
normal value and returns 0 otherwise.
The return type depends on NonScalar
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::isordered
#
Overloads 1-3
bool isordered(float x, float y);
bool isordered(double x, double y);
bool isordered(half x, half y);
Returns the value sycl::isequal(x, x) && sycl::isequal(y, y)
.
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isordered(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1
andNonScalar2
:Both
NonScalar1
andNonScalar2
aresycl::marray
;NonScalar1
andNonScalar2
are any combination ofsycl::vec
and the__swizzled_vec__
type;
NonScalar1
andNonScalar2
have the same number of elements and the same element type;The element type is
float
,double
, orhalf
.
Tests if each element of x
and y
are ordered.
If NonScalar1
is marray
, the value
sycl::isequal(x[i], x[i]) && sycl::isequal(y[i], y[i])
for
each element of x
and y
. If NonScalar1
is sycl::vec
or the __swizzled_vec__
type, returns the value
((sycl::isequal(x[i], x[i]) && sycl::isequal(y[i], y[i])) ? -1 : 0)
for each element of x
and y
.
The return type depends on NonScalar1
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::isunordered
#
Overloads 1-3
bool isunordered(float x, float y);
bool isunordered(double x, double y);
bool isunordered(half x, half y);
Returns the value sycl::isnan(x) || sycl::isnan(y)
.
Overload 4
template<typename NonScalar1, typename NonScalar2>
/*return-type*/ isunordered(NonScalar1 x, NonScalar2 y);
Available only if all of the following conditions are met:
One of the following conditions must hold for
NonScalar1
andNonScalar2
:Both
NonScalar1
andNonScalar2
aresycl::marray
;NonScalar1
andNonScalar2
are any combination ofsycl::vec
and the__swizzled_vec__
type;
NonScalar1
andNonScalar2
have the same number of elements and the same element type;The element type is
float
,double
, orhalf
.
Tests if each element of x
and y
are unordered.
If NonScalar1
is marray
, the value
sycl::isnan(x[i]) || sycl::isnan(y[i])
for
each element of x
and y
. If NonScalar1
is sycl::vec
or the __swizzled_vec__
type, returns the value
((sycl::isnan(x[i]) || sycl::isnan(y[i])) ? -1 : 0)
for each element of x
and y
.
The return type depends on NonScalar1
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::signbit
#
Overloads 1-3
bool signbit(float x);
bool signbit(double x);
bool signbit(half x);
Returns the value true
only if the sign bit of x
is set.
Overload 4
template<typename NonScalar>
/*return-type*/ signbit(NonScalar x);
Available only if all of the following conditions are met:
NonScalar
issycl::marray
,sycl::vec
, or the__swizzled_vec__
type;The element type is
float
,double
, orhalf
.
If NonScalar
is sycl::marray
, returns true
for
each element of x
only if the sign bit of x[i]
is set.
If NonScalar
is sycl::vec
or the __swizzled_vec__
type, returns -1 for each element of x
if the sign bit of
x[i]
is set and returns 0 otherwise.
The return type depends on NonScalar
:
|
Return Type |
---|---|
|
|
|
|
|
|
|
|
sycl::any
#
Overload 1
template<typename GenInt>
/*return-type*/ any(GenInt x);
Available only if GenInt
is one of the following types:
sycl::marray<bool, N>
sycl::vec<int8_t, N>
sycl::vec<int16_t, N>
sycl::vec<int32_t, N>
sycl::vec<int64_t, N>
__swizzled_vec__
that is convertible tosycl::vec<int8_t, N>
__swizzled_vec__
that is convertible tosycl::vec<int16_t, N>
__swizzled_vec__
that is convertible tosycl::vec<int32_t, N>
__swizzled_vec__
that is convertible tosycl::vec<int64_t, N>
When x
is sycl::marray
, returns a Boolean
telling whether any element of x
is true
.
When x
is sycl::vec
or the __swizzled_vec__
type, returns the value 1 if any element in x
has
its most significant bit set, otherwise returns the value 0.
The return type is bool
if GenInt
is sycl::marray
.
Otherwise, the return type is int
.
Overload 2
template<typename GenInt>
bool any(GenInt x);
Warning
This overload is deprecated in SYCL 2020.
Available only if GenInt
is one of the following types:
signed char
short
int
long
long long
sycl::marray<signed char, N>
sycl::marray<short, N>
sycl::marray<int, N>
sycl::marray<long, N>
sycl::marray<long long, N>
When x
is a scalar, returns a Boolean telling whether
the most significant bit of x
is set. When x
is
sycl::marray
, returns a Boolean telling whether the
most significant bit of any element in x
is set.
sycl::all
#
Overload 1
template<typename GenInt>
/*return-type*/ all(GenInt x);
Available only if GenInt
is one of the following types:
sycl::marray<bool, N>
sycl::vec<int8_t, N>
sycl::vec<int16_t, N>
sycl::vec<int32_t, N>
sycl::vec<int64_t, N>
__swizzled_vec__
that is convertible tosycl::vec<int8_t, N>
__swizzled_vec__
that is convertible tosycl::vec<int16_t, N>
__swizzled_vec__
that is convertible tosycl::vec<int32_t, N>
__swizzled_vec__
that is convertible tosycl::vec<int64_t, N>
When x
is sycl::marray
, returns a Boolean
telling whether all elements of x
are true
.
When x
is sycl::vec
or the __swizzled_vec__
type, returns the value 1 if all elements in x
have
their most significant bit set, otherwise returns the value 0.
The return type is bool
if GenInt
is sycl::marray
.
Otherwise, the return type is int
.
Overload 2
template<typename GenInt>
bool all(GenInt x);
Warning
This overload is deprecated in SYCL 2020.
Available only if GenInt
is one of the following types:
signed char
short
int
long
long long
sycl::marray<signed char, N>
sycl::marray<short, N>
sycl::marray<int, N>
sycl::marray<long, N>
sycl::marray<long long, N>
When x
is a scalar, returns a Boolean telling whether
the most significant bit of x
is set. When x
is
sycl::marray
, returns a Boolean telling whether the
most significant bit of all elements in x
are set.
sycl::bitselect
#
template<typename GenType1, typename GenType2, typename GenType3>
/*return-type*/ bitselect(GenType1 a, GenType2 b, GenType3 c);
Available only if all of the following conditions are met:
GenType1
is one of the following types:One of the generic scalar types as defined above;
sycl::marray<T, N>
, whereT
is one of the generic scalar types;sycl::vec<T, N>
, whereT
is one of the vector element types as defined above;__swizzled_vec__
that is convertible tosycl::vec<T, N>
, whereT
is one of the vector element types;
If
GenType1
is notsycl::vec
or the__swizzled_vec__
type, thenGenType2
andGenType3
must be the same asGenType1
;If
GenType1
issycl::vec
or the__swizzled_vec__
type, thenGenType2
andGenType3
must also besycl::vec
or the__swizzled_vec__
type, and all three must have the same element type and the same number of elements.
When the input parameters are scalars, returns a result where each
bit of the result is the corresponding bit of a
if the
corresponding bit of c
is 0. Otherwise it is the corresponding
bit of b
.
When the input parameters are not scalars, returns a result for
each element where each bit of the result for element i
is
the corresponding bit of a[i]
if the corresponding bit of
c[i]
is 0. Otherwise it is the corresponding bit of b[i]
.
The return type is GenType1
unless GenType1
is the
__swizzled_vec__
type, in which case the return type is
the corresponding sycl::vec
.
sycl::select
#
Overload 1
template<typename Scalar>
Scalar select(Scalar a, Scalar b, bool c);
Available only if Scalar is one of the generic scalar types as defined above.
Returns the value (c ? b : a)
.
Overload 2
template<typename NonScalar1, typename NonScalar2, typename NonScalar3>
/*return-type*/ select(NonScalar1 a, NonScalar2 b, NonScalar3 c);
Available only if all of the following conditions are met:
NonScalar1
is one of the following types:sycl::marray<T, N>
, whereT
is one of the generic scalar types as defined above;sycl::vec<T, N>
, whereT
is one of the vector element types as defined above;__swizzled_vec__
that is convertible tosycl::vec<T, N>
, whereT
is one of the vector element types;
If
NonScalar1
issycl::marray
, then:NonScalar2
must be the same asNonScalar1
;NonScalar3
must besycl::marray
with element type bool and the same number of elements asNonScalar1
;
If
NonScalar1
issycl::vec
or the__swizzled_vec__
type, then:NonScalar2
must also besycl::vec
or the__swizzled_vec__
type, and both must have the same element type and the same number of elements; andNonScalar3
must besycl::vec
or the__swizzled_vec__
type with the same number of elements asNonScalar1
. The element type ofNonScalar3
must be a signed or unsigned integer with the same number of bits as the element type ofNonScalar1
.
If NonScalar1
is sycl::marray
, return the value (c[i] ? b[i] : a[i])
for each element of a
, b
, and c
.
If NonScalar1
is sycl::vec
or the __swizzled_vec__
type,
returns the value ((MSB of c[i] is set) ? b[i] : a[i])
for each
element of a
, b
, and c
.
The return type is NonScalar1
unless NonScalar1
is the
__swizzled_vec__
type, in which case the return type is the
corresponding sycl::vec
.