diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-10-27 06:03:34 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-26 15:03:34 -0700 |
| commit | 41e17d370d67a584fbac9bbbe435c057c18715f4 (patch) | |
| tree | 7d262d4734186fda93ea32ab9f1a7c31b7ef2e1c | |
| parent | bee74b16eafa64ccc33bb386a1dc753cd6c41a82 (diff) | |
Make the exponent return value from frexp int (#3284)
* Make the exponent return value from frexp int
Fixes https://github.com/shader-slang/slang/issues/3282
* Update slang-llvm.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
| -rw-r--r-- | deps/target-deps.json | 10 | ||||
| -rw-r--r-- | docs/stdlib-doc.md | 6 | ||||
| -rw-r--r-- | prelude/slang-cpp-scalar-intrinsics.h | 22 | ||||
| -rw-r--r-- | prelude/slang-cuda-prelude.h | 18 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang | 8 | ||||
| -rw-r--r-- | tests/bugs/frexp-double.slang | 27 | ||||
| -rw-r--r-- | tests/bugs/frexp.slang | 26 |
7 files changed, 76 insertions, 41 deletions
diff --git a/deps/target-deps.json b/deps/target-deps.json index c6201d5a9..55014c130 100644 --- a/deps/target-deps.json +++ b/deps/target-deps.json @@ -4,14 +4,14 @@ "dependencies" : [ { "name" : "slang-llvm", - "baseUrl" : "https://github.com/shader-slang/slang-llvm/releases/download/v13.x-41/", + "baseUrl" : "https://github.com/shader-slang/slang-llvm/releases/download/v13.x-42/", "optional" : true, "packages" : { - "windows-x86_64" : { "type" : "url", "path" : "slang-llvm-13.x-41-win64.zip" }, - "windows-x86" : { "type": "url", "path" : "slang-llvm-13.x-41-win32.zip" }, - "linux-x86_64" : { "type": "url", "path" : "slang-llvm-v13.x-41-linux-x86_64-release.zip" }, - "macosx-x86_64" : { "type": "url", "path" : "slang-llvm-v13.x-41-macosx-x86_64-release.zip" } + "windows-x86_64" : { "type" : "url", "path" : "slang-llvm-13.x-42-win64.zip" }, + "windows-x86" : { "type": "url", "path" : "slang-llvm-13.x-42-win32.zip" }, + "linux-x86_64" : { "type": "url", "path" : "slang-llvm-v13.x-42-linux-x86_64-release.zip" }, + "macosx-x86_64" : { "type": "url", "path" : "slang-llvm-v13.x-42-macosx-x86_64-release.zip" } } }, { diff --git a/docs/stdlib-doc.md b/docs/stdlib-doc.md index f2489bb97..1431fdfb2 100644 --- a/docs/stdlib-doc.md +++ b/docs/stdlib-doc.md @@ -60352,14 +60352,14 @@ matrix<T,N,M> frac<T, N:int, M:int>(matrix<T,N,M> x); /// See Availability 1 T frexp<T>( T x, - out T exp); + out int exp); vector<T,N> frexp<T, N:int>( vector<T,N> x, - out vector<T,N> exp); + out vector<int,N> exp); /// See Availability 2 matrix<T,N,M> frexp<T, N:int, M:int>( matrix<T,N,M> x, - out matrix<T,N,M> exp); + out matrix<int,N,M> exp); ``` ## Availability diff --git a/prelude/slang-cpp-scalar-intrinsics.h b/prelude/slang-cpp-scalar-intrinsics.h index 2b9e7f777..acbe00152 100644 --- a/prelude/slang-cpp-scalar-intrinsics.h +++ b/prelude/slang-cpp-scalar-intrinsics.h @@ -169,7 +169,8 @@ float F32_fmod(float a, float b); float F32_remainder(float a, float b); float F32_atan2(float a, float b); -float F32_frexp(float x, float* e); +float F32_frexp(float x, int* e); + float F32_modf(float x, float* ip); // Ternary @@ -213,13 +214,8 @@ SLANG_FORCE_INLINE float F32_fmod(float a, float b) { return ::fmodf(a, b); } SLANG_FORCE_INLINE float F32_remainder(float a, float b) { return ::remainderf(a, b); } SLANG_FORCE_INLINE float F32_atan2(float a, float b) { return float(::atan2(a, b)); } -SLANG_FORCE_INLINE float F32_frexp(float x, float* e) -{ - int ei; - float m = ::frexpf(x, &ei); - *e = float(ei); - return m; -} +SLANG_FORCE_INLINE float F32_frexp(float x, int* e) { return ::frexpf(x, e); } + SLANG_FORCE_INLINE float F32_modf(float x, float* ip) { return ::modff(x, ip); @@ -289,7 +285,7 @@ double F64_fmod(double a, double b); double F64_remainder(double a, double b); double F64_atan2(double a, double b); -double F64_frexp(double x, double* e); +double F64_frexp(double x, int* e); double F64_modf(double x, double* ip); @@ -335,13 +331,7 @@ SLANG_FORCE_INLINE double F64_fmod(double a, double b) { return ::fmod(a, b); } SLANG_FORCE_INLINE double F64_remainder(double a, double b) { return ::remainder(a, b); } SLANG_FORCE_INLINE double F64_atan2(double a, double b) { return ::atan2(a, b); } -SLANG_FORCE_INLINE double F64_frexp(double x, double* e) -{ - int ei; - double m = ::frexp(x, &ei); - *e = float(ei); - return m; -} +SLANG_FORCE_INLINE double F64_frexp(double x, int* e) { return ::frexp(x, e); } SLANG_FORCE_INLINE double F64_modf(double x, double* ip) { diff --git a/prelude/slang-cuda-prelude.h b/prelude/slang-cuda-prelude.h index 9075ed3d3..24e400d2d 100644 --- a/prelude/slang-cuda-prelude.h +++ b/prelude/slang-cuda-prelude.h @@ -1018,13 +1018,8 @@ SLANG_FORCE_INLINE SLANG_CUDA_CALL float F32_fmod(float a, float b) { return ::f SLANG_FORCE_INLINE SLANG_CUDA_CALL float F32_remainder(float a, float b) { return ::remainderf(a, b); } SLANG_FORCE_INLINE SLANG_CUDA_CALL float F32_atan2(float a, float b) { return float(::atan2(a, b)); } -SLANG_FORCE_INLINE SLANG_CUDA_CALL float F32_frexp(float x, float* e) -{ - int ei; - float m = ::frexpf(x, &ei); - *e = ei; - return m; -} +SLANG_FORCE_INLINE SLANG_CUDA_CALL float F32_frexp(float x, int* e) { return frexpf(x, e); } + SLANG_FORCE_INLINE SLANG_CUDA_CALL float F32_modf(float x, float* ip) { return ::modff(x, ip); @@ -1077,13 +1072,8 @@ SLANG_FORCE_INLINE SLANG_CUDA_CALL double F64_fmod(double a, double b) { return SLANG_FORCE_INLINE SLANG_CUDA_CALL double F64_remainder(double a, double b) { return ::remainder(a, b); } SLANG_FORCE_INLINE SLANG_CUDA_CALL double F64_atan2(double a, double b) { return ::atan2(a, b); } -SLANG_FORCE_INLINE SLANG_CUDA_CALL double F64_frexp(double x, double* e) -{ - int ei; - double m = ::frexp(x, &ei); - *e = ei; - return m; -} +SLANG_FORCE_INLINE SLANG_CUDA_CALL double F64_frexp(double x, int* e) { return ::frexp(x, e); } + SLANG_FORCE_INLINE SLANG_CUDA_CALL double F64_modf(double x, double* ip) { return ::modf(x, ip); diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 1d5c68a0d..92ccbe9c5 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -2888,18 +2888,20 @@ matrix<T, N, M> frac(matrix<T, N, M> x) // Split float into mantissa and exponent __generic<T : __BuiltinFloatingPointType> +__target_intrinsic(cpp, "$P_frexp($0, $1)") +__target_intrinsic(cuda, "$P_frexp($0, $1)") __target_intrinsic(hlsl) __target_intrinsic(glsl) __target_intrinsic(spirv, "OpExtInst resultType resultId glsl450 Frexp _0 _1") [__readNone] -T frexp(T x, out T exp); +T frexp(T x, out int exp); __generic<T : __BuiltinFloatingPointType, let N : int> __target_intrinsic(hlsl) __target_intrinsic(glsl) __target_intrinsic(spirv, "OpExtInst resultType resultId glsl450 Frexp _0 _1") [__readNone] -vector<T, N> frexp(vector<T, N> x, out vector<T, N> exp) +vector<T, N> frexp(vector<T, N> x, out vector<int, N> exp) { VECTOR_MAP_BINARY(T, N, frexp, x, exp); } @@ -2907,7 +2909,7 @@ vector<T, N> frexp(vector<T, N> x, out vector<T, N> exp) __generic<T : __BuiltinFloatingPointType, let N : int, let M : int, let L : int> __target_intrinsic(hlsl) [__readNone] -matrix<T, N, M> frexp(matrix<T, N, M> x, out matrix<T, N, M, L> exp) +matrix<T, N, M> frexp(matrix<T, N, M> x, out matrix<int, N, M, L> exp) { MATRIX_MAP_BINARY(T, N, M, frexp, x, exp); } diff --git a/tests/bugs/frexp-double.slang b/tests/bugs/frexp-double.slang new file mode 100644 index 000000000..1ad5a57e8 --- /dev/null +++ b/tests/bugs/frexp-double.slang @@ -0,0 +1,27 @@ +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-output-using-type +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-dx12 -use-dxil -output-using-type +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-cpu -output-using-type +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -output-using-type +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -emit-spirv-directly -output-using-type +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-cuda -output-using-type + +// BUF: type: int32_t +// BUF-NEXT: 1 +// BUF-NEXT: 6 +// BUF-NEXT: -1 +// BUF-NEXT: 0 + +// The values are: [1.0 42.75 0.25 0.0] +//TEST_INPUT:set inputBuffer = ubuffer(data=[0 1072693248 0 1078288384 0 1070596096 0 0], stride=4) +RWStructuredBuffer<double> inputBuffer; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint i : SV_GroupIndex) +{ + var exponent : int; + frexp(inputBuffer[i], exponent); + outputBuffer[i] = exponent; +} diff --git a/tests/bugs/frexp.slang b/tests/bugs/frexp.slang new file mode 100644 index 000000000..ea8f17411 --- /dev/null +++ b/tests/bugs/frexp.slang @@ -0,0 +1,26 @@ +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-output-using-type +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-dx12 -use-dxil -output-using-type +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-cpu -output-using-type +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -output-using-type +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -emit-spirv-directly -output-using-type +//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-cuda -output-using-type + +// BUF: type: int32_t +// BUF-NEXT: 1 +// BUF-NEXT: 6 +// BUF-NEXT: -1 +// BUF-NEXT: 0 + +//TEST_INPUT:set inputBuffer = ubuffer(data=[1.0 42.75 0.25 0.0], stride=4) +RWStructuredBuffer<float> inputBuffer; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint i : SV_GroupIndex) +{ + var exponent : int = 0; + frexp(inputBuffer[i], exponent); + outputBuffer[i] = exponent; +} |
