summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-06-18 23:15:39 -0700
committerGitHub <noreply@github.com>2020-06-18 23:15:39 -0700
commit5fbb9ff7e1516bd787695d2c9d80b696f0a9ca9a (patch)
tree3e78893a74af856fb29158078bed7099a567f5dd
parentaa6aca498cd1f7fbbdb143e72dd48b1d714c8fbb (diff)
parent515d8eb0cd719ae31db2f6e03751011a123bc0ba (diff)
Merge pull request #1401 from jsmall-nvidia/feature/prelude-fix
Prelude fix/disable memaccess warning on gcc
-rw-r--r--prelude/slang-cpp-prelude.h13
-rw-r--r--prelude/slang-cpp-scalar-intrinsics.h26
-rw-r--r--premake5.lua2
3 files changed, 28 insertions, 13 deletions
diff --git a/prelude/slang-cpp-prelude.h b/prelude/slang-cpp-prelude.h
index 7da613024..d47b0463c 100644
--- a/prelude/slang-cpp-prelude.h
+++ b/prelude/slang-cpp-prelude.h
@@ -3,7 +3,18 @@
#include "../slang.h"
-#include <math.h>
+// Because the signiture of isnan, isfinite, and is isinf changed in C++, we use the macro
+// to use the version in the std namespace.
+// https://stackoverflow.com/questions/39130040/cmath-hides-isnan-in-math-h-in-c14-c11
+
+#if SLANG_GCC_FAMILY && __GNUC__ < 6
+# include <cmath>
+# define SLANG_PRELUDE_STD std::
+#else
+# include <math.h>
+# define SLANG_PRELUDE_STD
+#endif
+
#include <assert.h>
#include <stdlib.h>
diff --git a/prelude/slang-cpp-scalar-intrinsics.h b/prelude/slang-cpp-scalar-intrinsics.h
index c814365c6..07945f1e0 100644
--- a/prelude/slang-cpp-scalar-intrinsics.h
+++ b/prelude/slang-cpp-scalar-intrinsics.h
@@ -68,9 +68,9 @@ SLANG_FORCE_INLINE float F32_rsqrt(float f) { return 1.0f / F32_sqrt(f); }
SLANG_FORCE_INLINE float F32_sign(float f) { return ( f == 0.0f) ? f : (( f < 0.0f) ? -1.0f : 1.0f); }
SLANG_FORCE_INLINE float F32_frac(float f) { return f - F32_floor(f); }
-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); }
+SLANG_FORCE_INLINE bool F32_isnan(float f) { return SLANG_PRELUDE_STD isnan(f); }
+SLANG_FORCE_INLINE bool F32_isfinite(float f) { return SLANG_PRELUDE_STD isfinite(f); }
+SLANG_FORCE_INLINE bool F32_isinf(float f) { return SLANG_PRELUDE_STD isinf(f); }
// Binary
SLANG_FORCE_INLINE float F32_min(float a, float b) { return ::fminf(a, b); }
@@ -84,7 +84,7 @@ SLANG_FORCE_INLINE float F32_frexp(float x, float& e)
{
int ei;
float m = ::frexpf(x, &ei);
- e = ei;
+ e = float(ei);
return m;
}
SLANG_FORCE_INLINE float F32_modf(float x, float& ip)
@@ -135,9 +135,9 @@ SLANG_FORCE_INLINE double F64_rsqrt(double f) { return 1.0 / F64_sqrt(f); }
SLANG_FORCE_INLINE double F64_sign(double f) { return (f == 0.0) ? f : ((f < 0.0) ? -1.0 : 1.0); }
SLANG_FORCE_INLINE double F64_frac(double f) { return f - F64_floor(f); }
-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); }
+SLANG_FORCE_INLINE bool F64_isnan(double f) { return SLANG_PRELUDE_STD isnan(f); }
+SLANG_FORCE_INLINE bool F64_isfinite(double f) { return SLANG_PRELUDE_STD isfinite(f); }
+SLANG_FORCE_INLINE bool F64_isinf(double f) { return SLANG_PRELUDE_STD isinf(f); }
// Binary
SLANG_FORCE_INLINE double F64_min(double a, double b) { return ::fmin(a, b); }
@@ -151,9 +151,10 @@ SLANG_FORCE_INLINE double F64_frexp(double x, double& e)
{
int ei;
double m = ::frexp(x, &ei);
- e = ei;
+ e = float(ei);
return m;
}
+
SLANG_FORCE_INLINE double F64_modf(double x, double& ip)
{
return ::modf(x, &ip);
@@ -236,14 +237,17 @@ SLANG_FORCE_INLINE uint64_t U64_abs(uint64_t f) { return f; }
SLANG_FORCE_INLINE uint64_t U64_min(uint64_t a, uint64_t b) { return a < b ? a : b; }
SLANG_FORCE_INLINE uint64_t U64_max(uint64_t a, uint64_t b) { return a > b ? a : b; }
+// TODO(JS): We don't define countbits for 64bit in stdlib currently.
+// It's not clear from documentation if it should return 32 or 64 bits, if it exists.
+// 32 bits can always hold the result, and will be implicitly promoted.
SLANG_FORCE_INLINE uint32_t U64_countbits(uint64_t v)
{
#if SLANG_GCC_FAMILY
- return __builtin_popcountl(v);
+ return uint32_t(__builtin_popcountl(v));
#elif SLANG_PROCESSOR_X86_64 && SLANG_VC
- return __popcnt64(v);
+ return uint32_t(__popcnt64(v));
#else
- uint64_t c = 0;
+ uint32_t c = 0;
while (v)
{
c++;
diff --git a/premake5.lua b/premake5.lua
index 93d310ee0..2b3385b1c 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -201,7 +201,7 @@ workspace "slang"
architecture "ARM"
filter { "toolset:clang or gcc*" }
- buildoptions { "-Wno-unused-parameter", "-Wno-type-limits", "-Wno-sign-compare", "-Wno-unused-variable", "-Wno-reorder", "-Wno-switch", "-Wno-return-type", "-Wno-unused-local-typedefs", "-Wno-parentheses", "-std=c++11", "-fvisibility=hidden" , "-Wno-ignored-optimization-argument", "-Wno-unknown-warning-option"}
+ buildoptions { "-Wno-unused-parameter", "-Wno-type-limits", "-Wno-sign-compare", "-Wno-unused-variable", "-Wno-reorder", "-Wno-switch", "-Wno-return-type", "-Wno-unused-local-typedefs", "-Wno-parentheses", "-std=c++11", "-fvisibility=hidden" , "-Wno-ignored-optimization-argument", "-Wno-unknown-warning-option", "-Wno-class-memaccess"}
filter { "toolset:gcc*"}
buildoptions { "-Wno-unused-but-set-variable", "-Wno-implicit-fallthrough" }