summaryrefslogtreecommitdiffstats
path: root/prelude
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-02-12 10:44:07 -0500
committerGitHub <noreply@github.com>2020-02-12 10:44:07 -0500
commite1e7a6eec04ee1d04dc7e0d0212208d4c7a9592b (patch)
tree18543abbb95cb93accedf4b0ecc894b6a363f11b /prelude
parentfe9d27af9de047ea75db1334c961bb025fb732f6 (diff)
Support for isinf/isfinite/isnan/ldexp (#1219)
* Added support ldexp. * Added classify-float.slang test Fixed glsl output. * Added classify-double.slang * Added ldexp test to scalar-double.slang * isnan, isinf, isfinite are macros (on some targets) so remove :: prefix.
Diffstat (limited to 'prelude')
-rw-r--r--prelude/slang-cpp-scalar-intrinsics.h20
-rw-r--r--prelude/slang-cuda-prelude.h16
2 files changed, 34 insertions, 2 deletions
diff --git a/prelude/slang-cpp-scalar-intrinsics.h b/prelude/slang-cpp-scalar-intrinsics.h
index 9fc387b6e..95acd9335 100644
--- a/prelude/slang-cpp-scalar-intrinsics.h
+++ b/prelude/slang-cpp-scalar-intrinsics.h
@@ -67,6 +67,10 @@ SLANG_FORCE_INLINE float F32_saturate(float f) { return (f < 0.0f) ? 0.0f : (f >
SLANG_FORCE_INLINE float F32_frac(float f) { return f - F32_floor(f); }
SLANG_FORCE_INLINE float F32_radians(float f) { return f * 0.01745329222f; }
+SLANG_FORCE_INLINE bool F32_isnan(float f) { return isnan(f); }
+SLANG_FORCE_INLINE bool F32_isfinite(float f) { return isfinite(f); }
+SLANG_FORCE_INLINE bool F32_isinf(float f) { return isinf(f); }
+
// Binary
SLANG_FORCE_INLINE float F32_min(float a, float b) { return a < b ? a : b; }
SLANG_FORCE_INLINE float F32_max(float a, float b) { return a > b ? a : b; }
@@ -74,7 +78,11 @@ SLANG_FORCE_INLINE float F32_pow(float a, float b) { return ::powf(a, b); }
SLANG_FORCE_INLINE float F32_fmod(float a, float b) { return ::fmodf(a, b); }
SLANG_FORCE_INLINE float F32_remainder(float a, float b) { return ::remainderf(a, b); }
SLANG_FORCE_INLINE float F32_step(float a, float b) { return float(b >= a); }
-SLANG_FORCE_INLINE float F32_atan2(float a, float b) { return float(atan2(a, b)); }
+SLANG_FORCE_INLINE float F32_atan2(float a, float b) { return float(::atan2(a, b)); }
+
+// TODO(JS):
+// Note C++ has ldexp, but it takes an integer for the exponent, it seems HLSL takes both as float
+SLANG_FORCE_INLINE float F32_ldexp(float m, float e) { return m * ::powf(2.0f, e); }
// Ternary
SLANG_FORCE_INLINE float F32_smoothstep(float min, float max, float x)
@@ -125,6 +133,10 @@ SLANG_FORCE_INLINE double F64_saturate(double f) { return (f < 0.0) ? 0.0 : (f >
SLANG_FORCE_INLINE double F64_frac(double f) { return f - F64_floor(f); }
SLANG_FORCE_INLINE double F64_radians(double f) { return f * 0.01745329222; }
+SLANG_FORCE_INLINE bool F64_isnan(double f) { return isnan(f); }
+SLANG_FORCE_INLINE bool F64_isfinite(double f) { return isfinite(f); }
+SLANG_FORCE_INLINE bool F64_isinf(double f) { return isinf(f); }
+
// Binary
SLANG_FORCE_INLINE double F64_min(double a, double b) { return a < b ? a : b; }
SLANG_FORCE_INLINE double F64_max(double a, double b) { return a > b ? a : b; }
@@ -132,7 +144,11 @@ SLANG_FORCE_INLINE double F64_pow(double a, double b) { return ::pow(a, b); }
SLANG_FORCE_INLINE double F64_fmod(double a, double b) { return ::fmod(a, b); }
SLANG_FORCE_INLINE double F64_remainder(double a, double b) { return ::remainder(a, b); }
SLANG_FORCE_INLINE double F64_step(double a, double b) { return double(b >= a); }
-SLANG_FORCE_INLINE double F64_atan2(double a, double b) { return atan2(a, b); }
+SLANG_FORCE_INLINE double F64_atan2(double a, double b) { return ::atan2(a, b); }
+
+// TODO(JS):
+// Note C++ has ldexp, but it takes an integer for the exponent, it seems HLSL takes both as float
+SLANG_FORCE_INLINE double F64_ldexp(double m, double e) { return m * ::pow(2.0, e); }
// Ternary
SLANG_FORCE_INLINE double F64_smoothstep(double min, double max, double x)
diff --git a/prelude/slang-cuda-prelude.h b/prelude/slang-cuda-prelude.h
index dc0ba4b5e..768e33d13 100644
--- a/prelude/slang-cuda-prelude.h
+++ b/prelude/slang-cuda-prelude.h
@@ -120,11 +120,19 @@ SLANG_CUDA_CALL float F32_sign(float f) { return ( f == 0.0f) ? f : (( f < 0.0f)
SLANG_CUDA_CALL float F32_saturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; }
SLANG_CUDA_CALL float F32_frac(float f) { return f - floorf(f); }
+SLANG_CUDA_CALL bool F32_isnan(float f) { return isnan(f); }
+SLANG_CUDA_CALL bool F32_isfinite(float f) { return isfinite(f); }
+SLANG_CUDA_CALL bool F32_isinf(float f) { return isinf(f); }
+
// Binary
SLANG_CUDA_CALL float F32_min(float a, float b) { return a < b ? a : b; }
SLANG_CUDA_CALL float F32_max(float a, float b) { return a > b ? a : b; }
SLANG_CUDA_CALL float F32_step(float a, float b) { return float(b >= a); }
+// TODO(JS):
+// Note CUDA has ldexp, but it takes an integer for the exponent, it seems HLSL takes both as float
+SLANG_CUDA_CALL float F32_ldexp(float m, float e) { return m * powf(2.0f, e); }
+
// Ternary
SLANG_CUDA_CALL float F32_lerp(float x, float y, float s) { return x + s * (y - x); }
SLANG_CUDA_CALL void F32_sincos(float f, float& outSin, float& outCos) { sincosf(f, &outSin, &outCos); }
@@ -146,11 +154,19 @@ SLANG_CUDA_CALL double F64_sign(double f) { return (f == 0.0) ? f : ((f < 0.0) ?
SLANG_CUDA_CALL double F64_saturate(double f) { return (f < 0.0) ? 0.0 : (f > 1.0) ? 1.0 : f; }
SLANG_CUDA_CALL double F64_frac(double f) { return f - floor(f); }
+SLANG_CUDA_CALL bool F64_isnan(double f) { return isnan(f); }
+SLANG_CUDA_CALL bool F64_isfinite(double f) { return isfinite(f); }
+SLANG_CUDA_CALL bool F64_isinf(double f) { return isinf(f); }
+
// Binary
SLANG_CUDA_CALL double F64_min(double a, double b) { return a < b ? a : b; }
SLANG_CUDA_CALL double F64_max(double a, double b) { return a > b ? a : b; }
SLANG_CUDA_CALL double F64_step(double a, double b) { return double(b >= a); }
+// TODO(JS):
+// Note CUDA has ldexp, but it takes an integer for the exponent, it seems HLSL takes both as float
+SLANG_CUDA_CALL double F64_ldexp(double m, double e) { return m * pow(2.0, e); }
+
// Ternary
SLANG_CUDA_CALL double F64_lerp(double x, double y, double s) { return x + s * (y - x); }
SLANG_CUDA_CALL void F64_sincos(double f, double& outSin, double& outCos) { sincos(f, &outSin, &outCos); }