projects
/
mesa.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
util: Don't destroy shaders null shaders
[mesa.git]
/
src
/
gallium
/
auxiliary
/
util
/
u_math.h
diff --git
a/src/gallium/auxiliary/util/u_math.h
b/src/gallium/auxiliary/util/u_math.h
index 81aeb83cbb5f149951492ce0f9cdc27ce3b8f200..30555f92a6d021d9eede41b7e4204aacda1625a4 100644
(file)
--- a/
src/gallium/auxiliary/util/u_math.h
+++ b/
src/gallium/auxiliary/util/u_math.h
@@
-118,6
+118,11
@@
__inline double __cdecl atan2(double val)
#endif
#endif
+#ifndef M_SQRT2
+#define M_SQRT2 1.41421356237309504880
+#endif
+
+
#if defined(_MSC_VER)
#if _MSC_VER < 1400 && !defined(__cplusplus) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
#if defined(_MSC_VER)
#if _MSC_VER < 1400 && !defined(__cplusplus) || defined(PIPE_SUBSYSTEM_WINDOWS_CE)
@@
-168,7
+173,10
@@
static INLINE float logf( float f )
#undef logf
#define logf(x) ((float)log((double)(x)))
#endif /* logf */
#undef logf
#define logf(x) ((float)log((double)(x)))
#endif /* logf */
-#endif
+
+#define isfinite(x) _finite((double)(x))
+#define isnan(x) _isnan((double)(x))
+#endif /* _MSC_VER < 1400 && !defined(__cplusplus) */
static INLINE double log2( double x )
{
static INLINE double log2( double x )
{
@@
-176,6
+184,18
@@
static INLINE double log2( double x )
return log( x ) * invln2;
}
return log( x ) * invln2;
}
+static INLINE double
+round(double x)
+{
+ return x >= 0.0 ? floor(x + 0.5) : ceil(x - 0.5);
+}
+
+static INLINE float
+roundf(float x)
+{
+ return x >= 0.0f ? floorf(x + 0.5f) : ceilf(x - 0.5f);
+}
+
#endif /* _MSC_VER */
#endif /* _MSC_VER */
@@
-335,26
+355,25
@@
util_iround(float f)
}
}
-
/**
/**
- *
Test if x is NaN or +/- infinity.
+ *
Approximate floating point comparison
*/
static INLINE boolean
*/
static INLINE boolean
-util_is_
inf_or_nan(float x
)
+util_is_
approx(float a, float b, float tol
)
{
{
- union fi tmp;
- tmp.f = x;
- return !(int)((unsigned int)((tmp.i & 0x7fffffff)-0x7f800000) >> 31);
+ return fabs(b - a) <= tol;
}
/**
}
/**
- * Test
whether x is a power of two
.
+ * Test
if x is NaN or +/- infinity
.
*/
static INLINE boolean
*/
static INLINE boolean
-util_is_
pot(unsigned
x)
+util_is_
inf_or_nan(float
x)
{
{
- return (x & (x - 1)) == 0;
+ union fi tmp;
+ tmp.f = x;
+ return !(int)((unsigned int)((tmp.i & 0x7fffffff)-0x7f800000) >> 31);
}
}
@@
-531,6
+550,17
@@
util_bswap32(uint32_t n)
}
}
+/**
+ * Reverse byte order of a 16 bit word.
+ */
+static INLINE uint16_t
+util_bswap16(uint16_t n)
+{
+ return (n >> 8) |
+ (n << 8);
+}
+
+
/**
* Clamp X to [MIN, MAX].
* This is a macro to allow float, int, uint, etc. types.
/**
* Clamp X to [MIN, MAX].
* This is a macro to allow float, int, uint, etc. types.
@@
-543,13
+573,30
@@
util_bswap32(uint32_t n)
#define MIN3( A, B, C ) MIN2( MIN2( A, B ), C )
#define MAX3( A, B, C ) MAX2( MAX2( A, B ), C )
#define MIN3( A, B, C ) MIN2( MIN2( A, B ), C )
#define MAX3( A, B, C ) MAX2( MAX2( A, B ), C )
+#define MIN4( A, B, C, D ) MIN2( MIN2( A, B ), MIN2(C, D) )
+#define MAX4( A, B, C, D ) MAX2( MAX2( A, B ), MAX2(C, D) )
+
+/**
+ * Align a value, only works pot alignemnts.
+ */
static INLINE int
align(int value, int alignment)
{
return (value + alignment - 1) & ~(alignment - 1);
}
static INLINE int
align(int value, int alignment)
{
return (value + alignment - 1) & ~(alignment - 1);
}
+/**
+ * Works like align but on npot alignments.
+ */
+static INLINE size_t
+util_align_npot(size_t value, size_t alignment)
+{
+ if (value % alignment)
+ return value + (alignment - (value % alignment));
+ return value;
+}
+
static INLINE unsigned
u_minify(unsigned value, unsigned levels)
{
static INLINE unsigned
u_minify(unsigned value, unsigned levels)
{
@@
-585,13
+632,12
@@
do { \
static INLINE uint32_t util_unsigned_fixed(float value, unsigned frac_bits)
{
static INLINE uint32_t util_unsigned_fixed(float value, unsigned frac_bits)
{
- value *= (1<<frac_bits);
- return value < 0 ? 0 : value;
+ return value < 0 ? 0 : (uint32_t)(value * (1<<frac_bits));
}
static INLINE int32_t util_signed_fixed(float value, unsigned frac_bits)
{
}
static INLINE int32_t util_signed_fixed(float value, unsigned frac_bits)
{
- return
value * (1<<frac_bits
);
+ return
(int32_t)(value * (1<<frac_bits)
);
}
}