diff --git a/clang/lib/Sema/SPIRVBuiltins.td b/clang/lib/Sema/SPIRVBuiltins.td index d5a0e52e3404e..e226e3b223e17 100644 --- a/clang/lib/Sema/SPIRVBuiltins.td +++ b/clang/lib/Sema/SPIRVBuiltins.td @@ -321,8 +321,8 @@ class ConstOCLSPVBuiltin _Signature> : // OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types. def Bool : IntType<"bool", QualType<"Context.BoolTy">, 1>; -def TrueChar : IntType<"_char", QualType<"Context.CharTy", 0, 1>, 8>; -def Char : IntType<"char", QualTypeFromFunction<"GetCharType", 0, 1>, 8>; +def Char : IntType<"char", QualType<"Context.CharTy", 0, 1>, 8>; +def SChar : IntType<"schar", QualType<"Context.SignedCharTy", 0, 1>, 8>; def UChar : UIntType<"uchar", QualType<"Context.UnsignedCharTy">, 8>; def Short : IntType<"short", QualType<"Context.ShortTy", 0, 1>, 16>; def UShort : UIntType<"ushort", QualType<"Context.UnsignedShortTy">, 16>; @@ -355,19 +355,20 @@ def Vec16 : IntList<"Vec16", [16]>; def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>; // Type lists. -def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>; -def TLAllUnsigned : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>; -def TLAllWithBool : TypeList<[Bool, Char, UChar, Short, UShort, Int, UInt, Long, +def TLAll : TypeList<[Char, SChar, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>; +def TLAllUnsigned : TypeList<[UChar, UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>; +def TLAllWithBool : TypeList<[Bool, Char, SChar, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>; def TLFloat : TypeList<[Float, Double, Half]>; // FIXME: handle properly char (signed or unsigned depending on host) -def TLSignedInts : TypeList<[Char, Short, Int, Long]>; -def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>; +def TLSignedInts : TypeList<[Char, SChar, Short, Int, Long]>; +def TLUIToSIInts : TypeList<[UChar, UChar, UShort, UInt, ULong]>; +def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>; // Signed to Unsigned conversion // FIXME: handle properly char (signed or unsigned depending on host) -def TLSToUSignedInts : TypeList<[Char, Short, Int, Long]>; -def TLSToUUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>; +def TLSToUSignedInts : TypeList<[Char, SChar, Short, Int, Long]>; +def TLSToUUnsignedInts : TypeList<[UChar, UChar, UShort, UInt, ULong]>; def TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>; @@ -376,7 +377,7 @@ def TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>; // uchar abs(uchar). def TLAllUIntsTwice : TypeList<[UChar, UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>; -def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>; +def TLAllInts : TypeList<[Char, SChar, UChar, Short, UShort, Int, UInt, Long, ULong]>; // GenType definitions for multiple base types (e.g. all floating point types, // or all integer types). @@ -393,6 +394,8 @@ def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>; def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>; def AUIGenTypeN : GenericType<"AUIGenTypeN", TLUnsignedInts, VecAndScalar>; def ASIGenTypeN : GenericType<"ASIGenTypeN", TLSignedInts, VecAndScalar>; +// unsigned integers matching 1:1 with signed ints +def AUIToSIGenTypeN : GenericType<"AUIToSIGenTypeN", TLUIToSIInts, VecAndScalar>; def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>; // All integer to unsigned def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>; @@ -402,6 +405,7 @@ def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar // Unsigned integer def UGenType1 : GenericType<"UGenType1", TLUnsignedInts, Vec1>; def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>; +def UToSGenTypeN : GenericType<"UToSGenTypeN", TLUIToSIInts, VecAndScalar>; def UInt4 : GenericType<"UInt4", TypeList<[UInt]>, Vec4>; // Float def FGenType1 : GenericType<"FGenType1", TLFloat, Vec1>; @@ -411,7 +415,7 @@ def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats // GenType definitions for every single base type (e.g. fp32 only). // Names are like: GenTypeFloatVecAndScalar. -foreach Type = [Char, UChar, Short, UShort, +foreach Type = [Char, SChar, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half] in { foreach VecSizes = [VecAndScalar, VecNoScalar] in { @@ -549,9 +553,9 @@ foreach name = ["clz", "ctz", "popcount"] in { def : ConstOCLSPVBuiltin<"rotate", [AIGenTypeN, AIGenTypeN, AIGenTypeN]>; -def : ConstOCLSPVBuiltin<"s_abs", [AUIGenTypeN, ASIGenTypeN]>; +def : ConstOCLSPVBuiltin<"s_abs", [AUIToSIGenTypeN, ASIGenTypeN]>; -def : ConstOCLSPVBuiltin<"s_abs_diff", [AUIGenTypeN, ASIGenTypeN, ASIGenTypeN]>; +def : ConstOCLSPVBuiltin<"s_abs_diff", [AUIToSIGenTypeN, ASIGenTypeN, ASIGenTypeN]>; foreach name = ["s_add_sat", "s_hadd", "s_rhadd", @@ -651,9 +655,9 @@ def : ConstOCLSPVBuiltin<"bitselect", [AGenTypeN, AGenTypeN, AGenTypeN, AGenType foreach name = ["select"] in { def : ConstOCLSPVBuiltin; - def : ConstOCLSPVBuiltin; + def : ConstOCLSPVBuiltin; def : ConstOCLSPVBuiltin; - def : ConstOCLSPVBuiltin; + def : ConstOCLSPVBuiltin; def : ConstOCLSPVBuiltin; def : ConstOCLSPVBuiltin; def : ConstOCLSPVBuiltin; @@ -988,7 +992,7 @@ foreach name = ["GroupLogicalAndKHR", "GroupLogicalOrKHR"] in { def SubgroupShuffleINTELVecType : GenericType<"SubgroupShuffleINTELVecType", - TypeList<[Char, UChar, Short, UShort, Int, UInt, Float]>, + TypeList<[Char, SChar, UChar, Short, UShort, Int, UInt, Float]>, VecNoScalar>; foreach name = ["SubgroupShuffleINTEL", "SubgroupShuffleXorINTEL"] in { diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index b6a7f8ce8f0a6..e4fcb86c31b4e 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -51,7 +51,6 @@ #include #include -static inline clang::QualType GetCharType(clang::ASTContext &Context); static inline clang::QualType GetFloat16Type(clang::ASTContext &Context); #include "OpenCLBuiltins.inc" @@ -702,10 +701,6 @@ LLVM_DUMP_METHOD void LookupResult::dump() { D->dump(); } -static inline QualType GetCharType(clang::ASTContext &Context) { - return Context.getLangOpts().OpenCL ? Context.CharTy : Context.SignedCharTy; -} - static inline QualType GetFloat16Type(clang::ASTContext &Context) { return Context.getLangOpts().OpenCL ? Context.HalfTy : Context.Float16Ty; } diff --git a/clang/test/CodeGenSPIRV/spirv-builtin-lookup-group-non-uniform.cpp b/clang/test/CodeGenSPIRV/spirv-builtin-lookup-group-non-uniform.cpp index 08001cdda8bab..f9ae499c5b7e7 100644 --- a/clang/test/CodeGenSPIRV/spirv-builtin-lookup-group-non-uniform.cpp +++ b/clang/test/CodeGenSPIRV/spirv-builtin-lookup-group-non-uniform.cpp @@ -189,6 +189,7 @@ template void test_logical() { void test() { test_with_bool(); test_with_bool(); + test_with_bool(); test_with_bool(); test_with_bool(); test_with_bool(); @@ -199,6 +200,7 @@ void test() { test_with_bool(); test_integer(); + test_integer(); test_integer(); test_integer(); test_integer(); @@ -206,6 +208,7 @@ void test() { test_integer(); test_signed(); + test_signed(); test_signed(); test_signed(); @@ -232,13 +235,20 @@ void test() { // CHECK: call noundef zeroext i1 @_Z33__spirv_GroupNonUniformShuffleXoribj // CHECK: call noundef zeroext i1 @_Z32__spirv_GroupNonUniformShuffleUpibj // CHECK: call noundef zeroext i1 @_Z34__spirv_GroupNonUniformShuffleDownibj -// CHECK: call noundef zeroext i1 @_Z31__spirv_GroupNonUniformAllEqualii -// CHECK: call noundef i32 @_Z32__spirv_GroupNonUniformBroadcastiij -// CHECK: call noundef i32 @_Z37__spirv_GroupNonUniformBroadcastFirstii -// CHECK: call noundef i32 @_Z30__spirv_GroupNonUniformShuffleiij -// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformShuffleXoriij -// CHECK: call noundef i32 @_Z32__spirv_GroupNonUniformShuffleUpiij -// CHECK: call noundef i32 @_Z34__spirv_GroupNonUniformShuffleDowniij +// CHECK: call noundef zeroext i1 @_Z31__spirv_GroupNonUniformAllEqualic +// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBroadcasticj +// CHECK: call noundef signext i8 @_Z37__spirv_GroupNonUniformBroadcastFirstic +// CHECK: call noundef signext i8 @_Z30__spirv_GroupNonUniformShuffleicj +// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformShuffleXoricj +// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformShuffleUpicj +// CHECK: call noundef signext i8 @_Z34__spirv_GroupNonUniformShuffleDownicj +// CHECK: call noundef zeroext i1 @_Z31__spirv_GroupNonUniformAllEqualia +// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBroadcastiaj +// CHECK: call noundef signext i8 @_Z37__spirv_GroupNonUniformBroadcastFirstia +// CHECK: call noundef signext i8 @_Z30__spirv_GroupNonUniformShuffleiaj +// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformShuffleXoriaj +// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformShuffleUpiaj +// CHECK: call noundef signext i8 @_Z34__spirv_GroupNonUniformShuffleDowniaj // CHECK: call noundef zeroext i1 @_Z31__spirv_GroupNonUniformAllEqualih // CHECK: call noundef zeroext i8 @_Z32__spirv_GroupNonUniformBroadcastihj // CHECK: call noundef zeroext i8 @_Z37__spirv_GroupNonUniformBroadcastFirstih @@ -295,16 +305,26 @@ void test() { // CHECK: call noundef double @_Z33__spirv_GroupNonUniformShuffleXoridj // CHECK: call noundef double @_Z32__spirv_GroupNonUniformShuffleUpidj // CHECK: call noundef double @_Z34__spirv_GroupNonUniformShuffleDownidj -// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformIAddiii -// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformIAddiiij -// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformIMuliii -// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformIMuliiij -// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseAndiii -// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseAndiiij -// CHECK: call noundef i32 @_Z32__spirv_GroupNonUniformBitwiseOriii -// CHECK: call noundef i32 @_Z32__spirv_GroupNonUniformBitwiseOriiij -// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseXoriii -// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseXoriiij +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIAddiic +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIAddiicj +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIMuliic +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIMuliicj +// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseAndiic +// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseAndiicj +// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBitwiseOriic +// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBitwiseOriicj +// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseXoriic +// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseXoriicj +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIAddiia +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIAddiiaj +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIMuliia +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIMuliiaj +// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseAndiia +// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseAndiiaj +// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBitwiseOriia +// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBitwiseOriiaj +// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseXoriia +// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseXoriiaj // CHECK: call noundef zeroext i8 @_Z27__spirv_GroupNonUniformIAddiih // CHECK: call noundef zeroext i8 @_Z27__spirv_GroupNonUniformIAddiihj // CHECK: call noundef zeroext i8 @_Z27__spirv_GroupNonUniformIMuliih @@ -355,10 +375,14 @@ void test() { // CHECK: call noundef i32 @_Z32__spirv_GroupNonUniformBitwiseOriijj // CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseXoriij // CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseXoriijj -// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformSMiniii -// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformSMiniiij -// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformSMaxiii -// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformSMaxiiij +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMiniic +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMiniicj +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMaxiic +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMaxiicj +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMiniia +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMiniiaj +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMaxiia +// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMaxiiaj // CHECK: call noundef signext i16 @_Z27__spirv_GroupNonUniformSMiniis // CHECK: call noundef signext i16 @_Z27__spirv_GroupNonUniformSMiniisj // CHECK: call noundef signext i16 @_Z27__spirv_GroupNonUniformSMaxiis diff --git a/libclc/libspirv/lib/generic/gen_convert.py b/libclc/libspirv/lib/generic/gen_convert.py index 899476cd4e82a..2153f9eadc5bf 100755 --- a/libclc/libspirv/lib/generic/gen_convert.py +++ b/libclc/libspirv/lib/generic/gen_convert.py @@ -91,6 +91,15 @@ #pragma OPENCL EXTENSION cles_khr_int64 : enable #endif +// Typedef some signed char types that SPIR-V requires as the destination of +// certain conversion builtins. +typedef signed char schar; +typedef __attribute__((ext_vector_type(2))) signed char schar2; +typedef __attribute__((ext_vector_type(3))) signed char schar3; +typedef __attribute__((ext_vector_type(4))) signed char schar4; +typedef __attribute__((ext_vector_type(8))) signed char schar8; +typedef __attribute__((ext_vector_type(16))) signed char schar16; + """ ) @@ -151,11 +160,22 @@ def is_signed_unsigned_conversion(src, dst): def generate_spirv_fn_impl(src, dst, size="", mode="", sat="", force_decoration=False): close_conditional = conditional_guard(src, dst) + # If the destination is an schar type, we will be converting using the + # equivalent char type which in OpenCL C is signed. For vector types, we + # cannot rely on implicit casts back to the schar type so insert an + # explicit cast. + if dst.startswith("schar") and size: + cast = "__builtin_convertvector(" + cast_end = f", {dst}{size})" + else: + cast = "" + cast_end = "" + print( """_CLC_DEF _CLC_OVERLOAD _CLC_CONSTFN {DST}{N} {FN}({SRC}{N} x) {{ - return {CORE_FN}(x); + return {CAST}{CORE_FN}(x){CAST_END}; }} """.format( FN=spirv_fn_name( @@ -166,6 +186,8 @@ def generate_spirv_fn_impl(src, dst, size="", mode="", sat="", force_decoration= mode=mode, force_sat_decoration=force_decoration, ), + CAST=cast, + CAST_END=cast_end, CORE_FN=clc_core_fn_name(dst, size=size, sat=sat, mode=mode), SRC=src, DST=dst, @@ -203,6 +225,10 @@ def generate_spirv_fn(src, dst, size="", mode="", sat=""): # __spirv_ConvertUToF / __spirv_ConvertSToF + mode for src in int_types: + # We're not interested in schar as source types; remangling will do that + # for us. + if src == "schar": + continue for dst in float_types: for size in vector_sizes: for mode in rounding_modes: @@ -217,6 +243,10 @@ def generate_spirv_fn(src, dst, size="", mode="", sat=""): # __spirv_UConvert + sat for src in int_types: + # We're not interested in schar as source types; remangling will do that + # for us. + if src == "schar": + continue for dst in unsigned_types: for size in vector_sizes: for sat in saturation: @@ -224,6 +254,10 @@ def generate_spirv_fn(src, dst, size="", mode="", sat=""): # __spirv_SConvert + sat for src in int_types: + # We're not interested in schar as source types; remangling will do that + # for us. + if src == "schar": + continue for dst in signed_types: for size in vector_sizes: for sat in saturation: diff --git a/libclc/libspirv/lib/generic/gen_convert_common.py b/libclc/libspirv/lib/generic/gen_convert_common.py index 53c8bf1290bf4..e36c63eb8bd65 100644 --- a/libclc/libspirv/lib/generic/gen_convert_common.py +++ b/libclc/libspirv/lib/generic/gen_convert_common.py @@ -3,6 +3,7 @@ types = [ "char", + "schar", "uchar", "short", "ushort", @@ -16,6 +17,7 @@ ] int_types = [ "char", + "schar", "uchar", "short", "ushort", @@ -25,7 +27,7 @@ "ulong", ] unsigned_types = ["uchar", "ushort", "uint", "ulong"] -signed_types = ["char", "short", "int", "long"] +signed_types = ["char", "schar", "short", "int", "long"] float_types = ["half", "float", "double"] int64_types = ["long", "ulong"] float64_types = ["double"] @@ -40,6 +42,7 @@ bool_type = { "char": "char", + "schar": "char", "uchar": "char", "short": "short", "ushort": "short", @@ -54,6 +57,7 @@ unsigned_type = { "char": "uchar", + "schar": "uchar", "uchar": "uchar", "short": "ushort", "ushort": "ushort", @@ -65,6 +69,7 @@ sizeof_type = { "char": 1, + "schar": 1, "uchar": 1, "short": 2, "ushort": 2, @@ -79,6 +84,7 @@ limit_max = { "char": "CHAR_MAX", + "schar": "SCHAR_MAX", "uchar": "UCHAR_MAX", "short": "SHRT_MAX", "ushort": "USHRT_MAX", @@ -91,6 +97,7 @@ limit_min = { "char": "CHAR_MIN", + "schar": "SCHAR_MIN", "uchar": "0", "short": "SHRT_MIN", "ushort": "0", @@ -145,5 +152,5 @@ def clc_core_fn_name(dst, size="", mode="", sat=""): and saturation arguments. """ return "__clc_convert_{DST}{N}{SAT}{MODE}".format( - DST=dst, N=size, SAT=sat, MODE=mode + DST="char" if dst == "schar" else dst, N=size, SAT=sat, MODE=mode ) diff --git a/sycl/include/sycl/detail/vector_convert.hpp b/sycl/include/sycl/detail/vector_convert.hpp index d66f869885efc..8f4ff466c04f9 100644 --- a/sycl/include/sycl/detail/vector_convert.hpp +++ b/sycl/include/sycl/detail/vector_convert.hpp @@ -387,94 +387,94 @@ using enable_if_to_int_vector_t = RoundingModeCondition, RoundingMode>::type; // signed to signed, unsigned to unsigned conversions -#define __SYCL_SCALAR_INT_INT_CONVERT(Op, DestType) \ +#define __SYCL_SCALAR_INT_INT_CONVERT(Op, DestType, SPVType) \ template \ enable_if_to_int_scalar_t \ Op##Convert(From value) { \ - return __spirv_##Op##Convert_R##DestType(value); \ + return __spirv_##Op##Convert_R##SPVType(value); \ } -#define __SYCL_VECTOR_INT_INT_CONVERT(Op, N, DestType) \ +#define __SYCL_VECTOR_INT_INT_CONVERT(Op, N, DestType, SPVType) \ template \ enable_if_to_int_vector_t \ Op##Convert(From value) { \ - return __spirv_##Op##Convert_R##DestType##N(value); \ + return __spirv_##Op##Convert_R##SPVType##N(value); \ } -#define __SYCL_INT_INT_CONVERT(Op, DestType) \ - __SYCL_SCALAR_INT_INT_CONVERT(Op, DestType) \ - __SYCL_VECTOR_INT_INT_CONVERT(Op, 2, DestType) \ - __SYCL_VECTOR_INT_INT_CONVERT(Op, 3, DestType) \ - __SYCL_VECTOR_INT_INT_CONVERT(Op, 4, DestType) \ - __SYCL_VECTOR_INT_INT_CONVERT(Op, 8, DestType) \ - __SYCL_VECTOR_INT_INT_CONVERT(Op, 16, DestType) +#define __SYCL_INT_INT_CONVERT(Op, DestType, SPVType) \ + __SYCL_SCALAR_INT_INT_CONVERT(Op, DestType, SPVType) \ + __SYCL_VECTOR_INT_INT_CONVERT(Op, 2, DestType, SPVType) \ + __SYCL_VECTOR_INT_INT_CONVERT(Op, 3, DestType, SPVType) \ + __SYCL_VECTOR_INT_INT_CONVERT(Op, 4, DestType, SPVType) \ + __SYCL_VECTOR_INT_INT_CONVERT(Op, 8, DestType, SPVType) \ + __SYCL_VECTOR_INT_INT_CONVERT(Op, 16, DestType, SPVType) -__SYCL_INT_INT_CONVERT(S, char) -__SYCL_INT_INT_CONVERT(S, short) -__SYCL_INT_INT_CONVERT(S, int) -__SYCL_INT_INT_CONVERT(S, long) +__SYCL_INT_INT_CONVERT(S, char, schar) +__SYCL_INT_INT_CONVERT(S, short, short) +__SYCL_INT_INT_CONVERT(S, int, int) +__SYCL_INT_INT_CONVERT(S, long, long) -__SYCL_INT_INT_CONVERT(U, uchar) -__SYCL_INT_INT_CONVERT(U, ushort) -__SYCL_INT_INT_CONVERT(U, uint) -__SYCL_INT_INT_CONVERT(U, ulong) +__SYCL_INT_INT_CONVERT(U, uchar, uchar) +__SYCL_INT_INT_CONVERT(U, ushort, ushort) +__SYCL_INT_INT_CONVERT(U, uint, uint) +__SYCL_INT_INT_CONVERT(U, ulong, ulong) #undef __SYCL_SCALAR_INT_INT_CONVERT #undef __SYCL_VECTOR_INT_INT_CONVERT #undef __SYCL_INT_INT_CONVERT // float to signed, float to unsigned conversion -#define __SYCL_SCALAR_FLOAT_INT_CONVERT(Op, DestType, RoundingMode, \ +#define __SYCL_SCALAR_FLOAT_INT_CONVERT(Op, DestType, SPVType, RoundingMode, \ RoundingModeCondition) \ template \ enable_if_to_int_scalar_t \ Convert##Op(From Value) { \ - return __spirv_Convert##Op##_R##DestType##_##RoundingMode(Value); \ + return __spirv_Convert##Op##_R##SPVType##_##RoundingMode(Value); \ } -#define __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, N, DestType, RoundingMode, \ - RoundingModeCondition) \ +#define __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, N, DestType, SPVType, \ + RoundingMode, RoundingModeCondition) \ template \ enable_if_to_int_vector_t \ Convert##Op(From Value) { \ - return __spirv_Convert##Op##_R##DestType##N##_##RoundingMode(Value); \ + return __spirv_Convert##Op##_R##SPVType##N##_##RoundingMode(Value); \ } -#define __SYCL_FLOAT_INT_CONVERT(Op, DestType, RoundingMode, \ +#define __SYCL_FLOAT_INT_CONVERT(Op, DestType, SPVType, RoundingMode, \ RoundingModeCondition) \ - __SYCL_SCALAR_FLOAT_INT_CONVERT(Op, DestType, RoundingMode, \ + __SYCL_SCALAR_FLOAT_INT_CONVERT(Op, DestType, SPVType, RoundingMode, \ RoundingModeCondition) \ - __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, 2, DestType, RoundingMode, \ + __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, 2, DestType, SPVType, RoundingMode, \ RoundingModeCondition) \ - __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, 3, DestType, RoundingMode, \ + __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, 3, DestType, SPVType, RoundingMode, \ RoundingModeCondition) \ - __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, 4, DestType, RoundingMode, \ + __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, 4, DestType, SPVType, RoundingMode, \ RoundingModeCondition) \ - __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, 8, DestType, RoundingMode, \ + __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, 8, DestType, SPVType, RoundingMode, \ RoundingModeCondition) \ - __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, 16, DestType, RoundingMode, \ + __SYCL_VECTOR_FLOAT_INT_CONVERT(Op, 16, DestType, SPVType, RoundingMode, \ RoundingModeCondition) -#define __SYCL_FLOAT_INT_CONVERT_FOR_TYPE(Op, DestType) \ - __SYCL_FLOAT_INT_CONVERT(Op, DestType, rte, RteOrAutomatic) \ - __SYCL_FLOAT_INT_CONVERT(Op, DestType, rtz, Rtz) \ - __SYCL_FLOAT_INT_CONVERT(Op, DestType, rtp, Rtp) \ - __SYCL_FLOAT_INT_CONVERT(Op, DestType, rtn, Rtn) - -__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToS, char) -__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToS, short) -__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToS, int) -__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToS, long) - -__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToU, uchar) -__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToU, ushort) -__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToU, uint) -__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToU, ulong) +#define __SYCL_FLOAT_INT_CONVERT_FOR_TYPE(Op, DestType, SPVType) \ + __SYCL_FLOAT_INT_CONVERT(Op, DestType, SPVType, rte, RteOrAutomatic) \ + __SYCL_FLOAT_INT_CONVERT(Op, DestType, SPVType, rtz, Rtz) \ + __SYCL_FLOAT_INT_CONVERT(Op, DestType, SPVType, rtp, Rtp) \ + __SYCL_FLOAT_INT_CONVERT(Op, DestType, SPVType, rtn, Rtn) + +__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToS, char, schar) +__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToS, short, short) +__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToS, int, int) +__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToS, long, long) + +__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToU, uchar, uchar) +__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToU, ushort, ushort) +__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToU, uint, uint) +__SYCL_FLOAT_INT_CONVERT_FOR_TYPE(FToU, ulong, ulong) #undef __SYCL_SCALAR_FLOAT_INT_CONVERT #undef __SYCL_VECTOR_FLOAT_INT_CONVERT