Skip to content

Commit 5fbb9ff

Browse files
authored
Merge pull request shader-slang#1401 from jsmall-nvidia/feature/prelude-fix
Prelude fix/disable memaccess warning on gcc
2 parents aa6aca4 + 515d8eb commit 5fbb9ff

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

prelude/slang-cpp-prelude.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@
33

44
#include "../slang.h"
55

6-
#include <math.h>
6+
// Because the signiture of isnan, isfinite, and is isinf changed in C++, we use the macro
7+
// to use the version in the std namespace.
8+
// https://stackoverflow.com/questions/39130040/cmath-hides-isnan-in-math-h-in-c14-c11
9+
10+
#if SLANG_GCC_FAMILY && __GNUC__ < 6
11+
# include <cmath>
12+
# define SLANG_PRELUDE_STD std::
13+
#else
14+
# include <math.h>
15+
# define SLANG_PRELUDE_STD
16+
#endif
17+
718
#include <assert.h>
819
#include <stdlib.h>
920

prelude/slang-cpp-scalar-intrinsics.h

+15-11
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ SLANG_FORCE_INLINE float F32_rsqrt(float f) { return 1.0f / F32_sqrt(f); }
6868
SLANG_FORCE_INLINE float F32_sign(float f) { return ( f == 0.0f) ? f : (( f < 0.0f) ? -1.0f : 1.0f); }
6969
SLANG_FORCE_INLINE float F32_frac(float f) { return f - F32_floor(f); }
7070

71-
SLANG_FORCE_INLINE bool F32_isnan(float f) { return isnan(f); }
72-
SLANG_FORCE_INLINE bool F32_isfinite(float f) { return isfinite(f); }
73-
SLANG_FORCE_INLINE bool F32_isinf(float f) { return isinf(f); }
71+
SLANG_FORCE_INLINE bool F32_isnan(float f) { return SLANG_PRELUDE_STD isnan(f); }
72+
SLANG_FORCE_INLINE bool F32_isfinite(float f) { return SLANG_PRELUDE_STD isfinite(f); }
73+
SLANG_FORCE_INLINE bool F32_isinf(float f) { return SLANG_PRELUDE_STD isinf(f); }
7474

7575
// Binary
7676
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)
8484
{
8585
int ei;
8686
float m = ::frexpf(x, &ei);
87-
e = ei;
87+
e = float(ei);
8888
return m;
8989
}
9090
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); }
135135
SLANG_FORCE_INLINE double F64_sign(double f) { return (f == 0.0) ? f : ((f < 0.0) ? -1.0 : 1.0); }
136136
SLANG_FORCE_INLINE double F64_frac(double f) { return f - F64_floor(f); }
137137

138-
SLANG_FORCE_INLINE bool F64_isnan(double f) { return isnan(f); }
139-
SLANG_FORCE_INLINE bool F64_isfinite(double f) { return isfinite(f); }
140-
SLANG_FORCE_INLINE bool F64_isinf(double f) { return isinf(f); }
138+
SLANG_FORCE_INLINE bool F64_isnan(double f) { return SLANG_PRELUDE_STD isnan(f); }
139+
SLANG_FORCE_INLINE bool F64_isfinite(double f) { return SLANG_PRELUDE_STD isfinite(f); }
140+
SLANG_FORCE_INLINE bool F64_isinf(double f) { return SLANG_PRELUDE_STD isinf(f); }
141141

142142
// Binary
143143
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)
151151
{
152152
int ei;
153153
double m = ::frexp(x, &ei);
154-
e = ei;
154+
e = float(ei);
155155
return m;
156156
}
157+
157158
SLANG_FORCE_INLINE double F64_modf(double x, double& ip)
158159
{
159160
return ::modf(x, &ip);
@@ -236,14 +237,17 @@ SLANG_FORCE_INLINE uint64_t U64_abs(uint64_t f) { return f; }
236237
SLANG_FORCE_INLINE uint64_t U64_min(uint64_t a, uint64_t b) { return a < b ? a : b; }
237238
SLANG_FORCE_INLINE uint64_t U64_max(uint64_t a, uint64_t b) { return a > b ? a : b; }
238239

240+
// TODO(JS): We don't define countbits for 64bit in stdlib currently.
241+
// It's not clear from documentation if it should return 32 or 64 bits, if it exists.
242+
// 32 bits can always hold the result, and will be implicitly promoted.
239243
SLANG_FORCE_INLINE uint32_t U64_countbits(uint64_t v)
240244
{
241245
#if SLANG_GCC_FAMILY
242-
return __builtin_popcountl(v);
246+
return uint32_t(__builtin_popcountl(v));
243247
#elif SLANG_PROCESSOR_X86_64 && SLANG_VC
244-
return __popcnt64(v);
248+
return uint32_t(__popcnt64(v));
245249
#else
246-
uint64_t c = 0;
250+
uint32_t c = 0;
247251
while (v)
248252
{
249253
c++;

premake5.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ workspace "slang"
201201
architecture "ARM"
202202

203203
filter { "toolset:clang or gcc*" }
204-
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"}
204+
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"}
205205

206206
filter { "toolset:gcc*"}
207207
buildoptions { "-Wno-unused-but-set-variable", "-Wno-implicit-fallthrough" }

0 commit comments

Comments
 (0)