diff options
| author | Julius Ikkala <julius.ikkala@gmail.com> | 2025-01-25 01:50:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-24 15:50:45 -0800 |
| commit | 1abba25401c59a5634955ca44806834186e6b082 (patch) | |
| tree | f409b1a352beb7bad4e7bc1236800acddbbd3283 /prelude | |
| parent | 0dd9076db2154d787f6e06b713721e877b746b83 (diff) | |
Add intptr_t abs/min/max operations for CPU & CUDA targets (#6160)
* Add intptr_t abs/min/max operations for CPU & CUDA targets
* Define intptr_t and uintptr_t with CUDACC_RTC
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'prelude')
| -rw-r--r-- | prelude/slang-cpp-scalar-intrinsics.h | 33 | ||||
| -rw-r--r-- | prelude/slang-cuda-prelude.h | 35 |
2 files changed, 68 insertions, 0 deletions
diff --git a/prelude/slang-cpp-scalar-intrinsics.h b/prelude/slang-cpp-scalar-intrinsics.h index 6aa72df4f..22b5e12e4 100644 --- a/prelude/slang-cpp-scalar-intrinsics.h +++ b/prelude/slang-cpp-scalar-intrinsics.h @@ -765,6 +765,39 @@ SLANG_FORCE_INLINE int64_t I64_max(int64_t a, int64_t b) return a > b ? a : b; } +// ----------------------------- UPTR ----------------------------------------- + +SLANG_FORCE_INLINE uintptr_t UPTR_abs(uintptr_t f) +{ + return f; +} + +SLANG_FORCE_INLINE uintptr_t UPTR_min(uintptr_t a, uintptr_t b) +{ + return a < b ? a : b; +} + +SLANG_FORCE_INLINE uintptr_t UPTR_max(uintptr_t a, uintptr_t b) +{ + return a > b ? a : b; +} + +// ----------------------------- IPTR ----------------------------------------- + +SLANG_FORCE_INLINE intptr_t IPTR_abs(intptr_t f) +{ + return (f < 0) ? -f : f; +} + +SLANG_FORCE_INLINE intptr_t IPTR_min(intptr_t a, intptr_t b) +{ + return a < b ? a : b; +} + +SLANG_FORCE_INLINE intptr_t IPTR_max(intptr_t a, intptr_t b) +{ + return a > b ? a : b; +} // ----------------------------- Interlocked --------------------------------- diff --git a/prelude/slang-cuda-prelude.h b/prelude/slang-cuda-prelude.h index 46c6a4394..5585ad6e0 100644 --- a/prelude/slang-cuda-prelude.h +++ b/prelude/slang-cuda-prelude.h @@ -205,11 +205,13 @@ typedef signed char int8_t; typedef short int16_t; typedef int int32_t; typedef long long int64_t; +typedef ptrdiff_t intptr_t; typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; typedef unsigned long long uint64_t; +typedef size_t uintptr_t; #endif @@ -1902,6 +1904,39 @@ SLANG_FORCE_INLINE SLANG_CUDA_CALL uint32_t U64_countbits(uint64_t v) return __popcll(v); } +// ----------------------------- IPTR ----------------------------------------- + +SLANG_FORCE_INLINE SLANG_CUDA_CALL intptr_t IPTR_abs(intptr_t f) +{ + return (f < 0) ? -f : f; +} + +SLANG_FORCE_INLINE SLANG_CUDA_CALL intptr_t IPTR_min(intptr_t a, intptr_t b) +{ + return a < b ? a : b; +} + +SLANG_FORCE_INLINE SLANG_CUDA_CALL intptr_t IPTR_max(intptr_t a, intptr_t b) +{ + return a > b ? a : b; +} + +// ----------------------------- UPTR ----------------------------------------- + +SLANG_FORCE_INLINE SLANG_CUDA_CALL uintptr_t UPTR_abs(uintptr_t f) +{ + return f; +} + +SLANG_FORCE_INLINE SLANG_CUDA_CALL uintptr_t UPTR_min(uintptr_t a, uintptr_t b) +{ + return a < b ? a : b; +} + +SLANG_FORCE_INLINE SLANG_CUDA_CALL uintptr_t UPTR_max(uintptr_t a, uintptr_t b) +{ + return a > b ? a : b; +} // ----------------------------- ResourceType ----------------------------------------- |
