diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-01-31 08:55:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-31 08:55:40 -0500 |
| commit | 52b78ad9bf99660593c49a8da0bdcec19016ee25 (patch) | |
| tree | fbf2d7181799593fde31747ed98477bba37fce6c /prelude | |
| parent | ec056fd30c8b7357568e57cf9d52fc159b56602f (diff) | |
64 bit types doc (#1194)
* * For integer literals add postfix, and use unsigned/signed output appropriately
* Extend GLSL extension handling by type, and for adding 64 bit int extensions
* Added tests for int/uint64 types
* Add explicit Int/UInt64 emit functions to avoid ambiguity.
* Fix uint64_t intrinsics on CUDA/C++.
* WIP 64 bit types documentation.
* Testing int64 intrinsic support.
* Dx12 Dxil sm6.0 does actually support int64_t.
Diffstat (limited to 'prelude')
| -rw-r--r-- | prelude/slang-cpp-scalar-intrinsics.h | 35 | ||||
| -rw-r--r-- | prelude/slang-cuda-prelude.h | 26 |
2 files changed, 61 insertions, 0 deletions
diff --git a/prelude/slang-cpp-scalar-intrinsics.h b/prelude/slang-cpp-scalar-intrinsics.h index 6c577733d..9fc387b6e 100644 --- a/prelude/slang-cpp-scalar-intrinsics.h +++ b/prelude/slang-cpp-scalar-intrinsics.h @@ -197,6 +197,7 @@ 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 @@ -214,6 +215,40 @@ SLANG_FORCE_INLINE uint32_t U32_countbits(uint32_t v) #endif } +// ----------------------------- U64 ----------------------------------------- + +SLANG_FORCE_INLINE uint64_t U64_abs(uint64_t f) { return f; } + +SLANG_FORCE_INLINE uint64_t U64_min(uint64_t a, uint64_t b) { return a < b ? a : b; } +SLANG_FORCE_INLINE uint64_t U64_max(uint64_t a, uint64_t b) { return a > b ? a : b; } + +SLANG_FORCE_INLINE uint64_t U64_clamp(uint64_t x, uint64_t min, uint64_t max) { return ( x < min) ? min : ((x > max) ? max : x); } + +SLANG_FORCE_INLINE uint32_t U64_countbits(uint64_t v) +{ +#if SLANG_GCC_FAMILY + return __builtin_popcountl(v); +#elif SLANG_PROCESSOR_X86_64 && SLANG_VC + return __popcnt64(v); +#else + uint64_t c = 0; + while (v) + { + c++; + v &= v - 1; + } + return c; +#endif +} + +// ----------------------------- I64 ----------------------------------------- + +SLANG_FORCE_INLINE int64_t I64_abs(int64_t f) { return (f < 0) ? -f : f; } + +SLANG_FORCE_INLINE int64_t I64_min(int64_t a, int64_t b) { return a < b ? a : b; } +SLANG_FORCE_INLINE int64_t I64_max(int64_t a, int64_t b) { return a > b ? a : b; } + +SLANG_FORCE_INLINE int64_t I64_clamp(int64_t x, int64_t min, int64_t max) { return ( x < min) ? min : ((x > max) ? max : x); } #ifdef SLANG_PRELUDE_NAMESPACE } diff --git a/prelude/slang-cuda-prelude.h b/prelude/slang-cuda-prelude.h index 7e6e5957d..233903134 100644 --- a/prelude/slang-cuda-prelude.h +++ b/prelude/slang-cuda-prelude.h @@ -214,6 +214,32 @@ SLANG_CUDA_CALL uint32_t U32_countbits(uint32_t v) return __popc(v); } + +// ----------------------------- I64 ----------------------------------------- + +SLANG_CUDA_CALL int64_t I64_abs(int64_t f) { return (f < 0) ? -f : f; } + +SLANG_CUDA_CALL int64_t I64_min(int64_t a, int64_t b) { return a < b ? a : b; } +SLANG_CUDA_CALL int64_t I64_max(int64_t a, int64_t b) { return a > b ? a : b; } + +SLANG_CUDA_CALL int64_t I64_clamp(int64_t x, int64_t min, int64_t max) { return ( x < min) ? min : ((x > max) ? max : x); } + +// ----------------------------- U64 ----------------------------------------- + +SLANG_CUDA_CALL int64_t U64_abs(uint64_t f) { return f; } + +SLANG_CUDA_CALL int64_t U64_min(uint64_t a, uint64_t b) { return a < b ? a : b; } +SLANG_CUDA_CALL int64_t U64_max(uint64_t a, uint64_t b) { return a > b ? a : b; } + +SLANG_CUDA_CALL int64_t U64_clamp(uint64_t x, uint64_t min, uint64_t max) { return ( x < min) ? min : ((x > max) ? max : x); } + +SLANG_CUDA_CALL uint32_t U64_countbits(uint64_t v) +{ + // https://docs.nvidia.com/cuda/cuda-math-api/group__CUDA__MATH__INTRINSIC__INT.html#group__CUDA__MATH__INTRINSIC__INT_1g43c9c7d2b9ebf202ff1ef5769989be46 + return __popcll(v); +} + + // ----------------------------- ResourceType ----------------------------------------- |
