Skip to content

Commit 1abba25

Browse files
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>
1 parent 0dd9076 commit 1abba25

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

prelude/slang-cpp-scalar-intrinsics.h

+33
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,39 @@ SLANG_FORCE_INLINE int64_t I64_max(int64_t a, int64_t b)
765765
return a > b ? a : b;
766766
}
767767

768+
// ----------------------------- UPTR -----------------------------------------
769+
770+
SLANG_FORCE_INLINE uintptr_t UPTR_abs(uintptr_t f)
771+
{
772+
return f;
773+
}
774+
775+
SLANG_FORCE_INLINE uintptr_t UPTR_min(uintptr_t a, uintptr_t b)
776+
{
777+
return a < b ? a : b;
778+
}
779+
780+
SLANG_FORCE_INLINE uintptr_t UPTR_max(uintptr_t a, uintptr_t b)
781+
{
782+
return a > b ? a : b;
783+
}
784+
785+
// ----------------------------- IPTR -----------------------------------------
786+
787+
SLANG_FORCE_INLINE intptr_t IPTR_abs(intptr_t f)
788+
{
789+
return (f < 0) ? -f : f;
790+
}
791+
792+
SLANG_FORCE_INLINE intptr_t IPTR_min(intptr_t a, intptr_t b)
793+
{
794+
return a < b ? a : b;
795+
}
796+
797+
SLANG_FORCE_INLINE intptr_t IPTR_max(intptr_t a, intptr_t b)
798+
{
799+
return a > b ? a : b;
800+
}
768801

769802
// ----------------------------- Interlocked ---------------------------------
770803

prelude/slang-cuda-prelude.h

+35
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,13 @@ typedef signed char int8_t;
205205
typedef short int16_t;
206206
typedef int int32_t;
207207
typedef long long int64_t;
208+
typedef ptrdiff_t intptr_t;
208209

209210
typedef unsigned char uint8_t;
210211
typedef unsigned short uint16_t;
211212
typedef unsigned int uint32_t;
212213
typedef unsigned long long uint64_t;
214+
typedef size_t uintptr_t;
213215

214216
#endif
215217

@@ -1902,6 +1904,39 @@ SLANG_FORCE_INLINE SLANG_CUDA_CALL uint32_t U64_countbits(uint64_t v)
19021904
return __popcll(v);
19031905
}
19041906

1907+
// ----------------------------- IPTR -----------------------------------------
1908+
1909+
SLANG_FORCE_INLINE SLANG_CUDA_CALL intptr_t IPTR_abs(intptr_t f)
1910+
{
1911+
return (f < 0) ? -f : f;
1912+
}
1913+
1914+
SLANG_FORCE_INLINE SLANG_CUDA_CALL intptr_t IPTR_min(intptr_t a, intptr_t b)
1915+
{
1916+
return a < b ? a : b;
1917+
}
1918+
1919+
SLANG_FORCE_INLINE SLANG_CUDA_CALL intptr_t IPTR_max(intptr_t a, intptr_t b)
1920+
{
1921+
return a > b ? a : b;
1922+
}
1923+
1924+
// ----------------------------- UPTR -----------------------------------------
1925+
1926+
SLANG_FORCE_INLINE SLANG_CUDA_CALL uintptr_t UPTR_abs(uintptr_t f)
1927+
{
1928+
return f;
1929+
}
1930+
1931+
SLANG_FORCE_INLINE SLANG_CUDA_CALL uintptr_t UPTR_min(uintptr_t a, uintptr_t b)
1932+
{
1933+
return a < b ? a : b;
1934+
}
1935+
1936+
SLANG_FORCE_INLINE SLANG_CUDA_CALL uintptr_t UPTR_max(uintptr_t a, uintptr_t b)
1937+
{
1938+
return a > b ? a : b;
1939+
}
19051940

19061941
// ----------------------------- ResourceType -----------------------------------------
19071942

source/slang/slang-intrinsic-expand.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ const char* IntrinsicExpandContext::_emitSpecial(const char* cursor)
704704
CASE(UInt16Type, U16);
705705
CASE(UIntType, U32);
706706
CASE(UInt64Type, U64);
707+
CASE(IntPtrType, IPTR);
708+
CASE(UIntPtrType, UPTR);
707709
CASE(HalfType, F16);
708710
CASE(FloatType, F32);
709711
CASE(DoubleType, F64);

0 commit comments

Comments
 (0)