summaryrefslogtreecommitdiffstats
path: root/prelude
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-08-22 15:58:28 -0400
committerGitHub <noreply@github.com>2019-08-22 15:58:28 -0400
commit06a0e3980fd04fa265bd20eb11f2abc18bd6a215 (patch)
treeea664d7f0ecfa4b6948319d4fcfb0bbd1e3af888 /prelude
parentbc392f9dbfb8cb6c359bb890fb85b831e49bfd55 (diff)
WIP: CPU compute coverage (#1030)
* Add support for '=' when defining a name in test. * Add support for double intrinsics. * Add support for asdouble Add findOrAddInst - used instead of findOrEmitHoistableInst, for nominal instructions. Support cloning of string literals. C++ working on more compute tests. * Constant buffer support in reflection. Fixed debugging into source for generated C++. buffer-layout.slang works. * Added cpu test result. * Remove some commented out code. Comment on next fixes. * Improvements to reflection CPU code. * C++ working with ByteAddressBuffer. * Enabled more compute tests for CPU. * Enabled more compute tests on CPU. Added support for [] style access to a vector. * Enabled more CPU compute tests. * Handling of buffer-type-splitting.slang Named buffers can be paths to resources * Fix some warnings, remove some dead code. * Fix problem with verification of number of operands for asuint/asint as they can have 1 or 3 operands. asdouble takes 2. * Fix handling in MemoryArena around aligned allocations. That _allocateAlignedFromNewBlock assumed the block allocated has the aligment that was requested and so did not correct the start address.
Diffstat (limited to 'prelude')
-rw-r--r--prelude/slang-cpp-scalar-intrinsics.h45
1 files changed, 40 insertions, 5 deletions
diff --git a/prelude/slang-cpp-scalar-intrinsics.h b/prelude/slang-cpp-scalar-intrinsics.h
index 217a79e02..40d137395 100644
--- a/prelude/slang-cpp-scalar-intrinsics.h
+++ b/prelude/slang-cpp-scalar-intrinsics.h
@@ -20,6 +20,13 @@ union Union32
float f;
};
+union Union64
+{
+ uint64_t u;
+ int64_t i;
+ double d;
+};
+
// Helpers
SLANG_FORCE_INLINE float F32_calcSafeRadians(float radians)
{
@@ -112,10 +119,6 @@ SLANG_FORCE_INLINE double F64_lerp(double x, double y, double s) { return x + s
SLANG_FORCE_INLINE double F64_clamp(double x, double min, double max) { return (x < min) ? min : ((x > max) ? max : x); }
SLANG_FORCE_INLINE void F64_sincos(double f, double& outSin, double& outCos) { outSin = F64_sin(f); outCos = F64_cos(f); }
-// TODO!
-//uint32_t F64_asuint(float f);
-//int32_t F64_asint(float f);
-
// ----------------------------- I32 -----------------------------------------
SLANG_FORCE_INLINE int32_t I32_abs(int32_t f) { return (f < 0) ? -f : f; }
@@ -126,7 +129,13 @@ SLANG_FORCE_INLINE int32_t I32_max(int32_t a, int32_t b) { return a > b ? a : b;
SLANG_FORCE_INLINE int32_t I32_clamp(int32_t x, int32_t min, int32_t max) { return ( x < min) ? min : ((x > max) ? max : x); }
SLANG_FORCE_INLINE float I32_asfloat(int32_t x) { Union32 u; u.i = x; return u.f; }
-SLANG_FORCE_INLINE uint32_t I32_asuint(int32_t x) { return uint32_t(x); }
+SLANG_FORCE_INLINE uint32_t I32_asuint(int32_t x) { return uint32_t(x); }
+SLANG_FORCE_INLINE double I32_asdouble(int32_t low, int32_t hi )
+{
+ Union64 u;
+ u.i = (int64_t(hi) << 32) | low;
+ return u.d;
+}
// ----------------------------- U32 -----------------------------------------
@@ -140,6 +149,32 @@ SLANG_FORCE_INLINE uint32_t U32_clamp(uint32_t x, uint32_t min, uint32_t max) {
SLANG_FORCE_INLINE float U32_asfloat(uint32_t x) { Union32 u; u.u = x; return u.f; }
SLANG_FORCE_INLINE uint32_t U32_asint(int32_t x) { return uint32_t(x); }
+SLANG_FORCE_INLINE double U32_asdouble(uint32_t low, uint32_t hi)
+{
+ Union64 u;
+ u.u = (uint64_t(hi) << 32) | low;
+ return u.d;
+}
+
+// ----------------------------- F64 -----------------------------------------
+
+SLANG_FORCE_INLINE void F64_asuint(double d, uint32_t& low, uint32_t& hi)
+{
+ Union64 u;
+ u.d = d;
+ low = uint32_t(u.u);
+ hi = uint32_t(u.u >> 32);
+}
+
+SLANG_FORCE_INLINE void F64_asint(double d, int32_t& low, uint32_t& hi)
+{
+ Union64 u;
+ u.d = d;
+ low = int32_t(u.u);
+ hi = int32_t(u.u >> 32);
+}
+
+
#ifdef SLANG_PRELUDE_NAMESPACE
}
#endif