Skip to content

Commit

Permalink
Add intptr_t abs/min/max operations for CPU & CUDA targets
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusikkala committed Jan 22, 2025
1 parent 8000e0e commit d8c1652
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
33 changes: 33 additions & 0 deletions prelude/slang-cpp-scalar-intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------

Expand Down
33 changes: 33 additions & 0 deletions prelude/slang-cuda-prelude.h
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,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 -----------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions source/slang/slang-intrinsic-expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ const char* IntrinsicExpandContext::_emitSpecial(const char* cursor)
CASE(UInt16Type, U16);
CASE(UIntType, U32);
CASE(UInt64Type, U64);
CASE(IntPtrType, IPTR);
CASE(UIntPtrType, UPTR);
CASE(HalfType, F16);
CASE(FloatType, F32);
CASE(DoubleType, F64);
Expand Down

0 comments on commit d8c1652

Please sign in to comment.