diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-01-22 11:06:20 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-22 11:06:20 -0500 |
| commit | c74a700681b0be44a74f16b0f9eaad05bba159d2 (patch) | |
| tree | 6855baa362b336f17e199f1ad33242e73e98f6a7 /prelude | |
| parent | 346a56749c99e4e05d24ad6217f34dd5d44af189 (diff) | |
WIP HLSL intrinsic coverage (#1171)
* Added hlsl-intrinsic test folder.
Enabled ceil as works across targets.
* log10 support.
* Fix float % on CPU/CUDA to match HLSL which is fmod (not fremainder).
* Added log10 tests back to scalar-float.slang
* Don't add the ( for $Sx - it's clearer what's going on without it.
* Works on CUDA/CPU. Problem with asint/asuint do not seem to be found.
* Only asuint exists for double.
* Support countbits on CUDA and C++.
* Fix typo in C++ population count.
* First pass at int vector intrinsic tests.
* Swizzle for int.
* Bit cast tests on CUDA.
* Fix warning on gcc.
* Fix bit-cast-double execution on CUDA.
* scalar-int test working on gcc release.
Diffstat (limited to 'prelude')
| -rw-r--r-- | prelude/slang-cpp-scalar-intrinsics.h | 22 | ||||
| -rw-r--r-- | prelude/slang-cuda-prelude.h | 7 |
2 files changed, 28 insertions, 1 deletions
diff --git a/prelude/slang-cpp-scalar-intrinsics.h b/prelude/slang-cpp-scalar-intrinsics.h index 63fe9c926..6c577733d 100644 --- a/prelude/slang-cpp-scalar-intrinsics.h +++ b/prelude/slang-cpp-scalar-intrinsics.h @@ -3,6 +3,11 @@ #include "../slang.h" +#if SLANG_PROCESSOR_X86_64 && SLANG_VC +// If we have visual studio and 64 bit processor, we can assume we have popcnt, and can include x86 intrinsics +# include <intrin.h> +#endif + #ifdef SLANG_PRELUDE_NAMESPACE namespace SLANG_PRELUDE_NAMESPACE { #endif @@ -192,7 +197,22 @@ SLANG_FORCE_INLINE double U32_asdouble(uint32_t low, uint32_t hi) return u.d; } - +SLANG_FORCE_INLINE uint32_t U32_countbits(uint32_t v) +{ +#if SLANG_GCC_FAMILY + return __builtin_popcount(v); +#elif SLANG_PROCESSOR_X86_64 && SLANG_VC + return __popcnt(v); +#else + uint32_t c = 0; + while (v) + { + c++; + v &= v - 1; + } + return c; +#endif +} #ifdef SLANG_PRELUDE_NAMESPACE diff --git a/prelude/slang-cuda-prelude.h b/prelude/slang-cuda-prelude.h index 8d100b0db..f78814486 100644 --- a/prelude/slang-cuda-prelude.h +++ b/prelude/slang-cuda-prelude.h @@ -161,6 +161,13 @@ SLANG_CUDA_CALL double U32_asdouble(uint32_t low, uint32_t hi) return u.d; } +SLANG_CUDA_CALL uint32_t U32_countbits(uint32_t v) +{ + // https://docs.nvidia.com/cuda/cuda-math-api/group__CUDA__MATH__INTRINSIC__INT.html#group__CUDA__MATH__INTRINSIC__INT_1g43c9c7d2b9ebf202ff1ef5769989be46 + return __popc(v); +} + + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ |
