#include "util/macros.h"
#include "util/u_math.h"
#include "util/rounding.h"
-#include "imports.h"
+#include "util/compiler.h"
+#include "main/glheader.h"
+#include "mesa_private.h"
/**
return tmp;
}
+static inline uint64_t DOUBLE_AS_UINT64(double d)
+{
+ union {
+ double d;
+ uint64_t u64;
+ } tmp;
+ tmp.d = d;
+ return tmp.u64;
+}
+
+static inline double UINT64_AS_DOUBLE(uint64_t u)
+{
+ union {
+ double d;
+ uint64_t u64;
+ } tmp;
+ tmp.u64 = u;
+ return tmp.d;
+}
+
+/* First sign-extend x, then return uint32_t. */
+#define INT_AS_UINT(x) ((uint32_t)((int32_t)(x)))
+#define FLOAT_AS_UINT(x) (FLOAT_AS_UNION(x).u)
+
/**
* Convert a floating point value to an unsigned fixed point value.
*
}
/** Copy \p SZ elements into a 4-element vector */
-#define COPY_SZ_4V(DST, SZ, SRC) \
-do { \
- switch (SZ) { \
- case 4: (DST)[3] = (SRC)[3]; \
- case 3: (DST)[2] = (SRC)[2]; \
- case 2: (DST)[1] = (SRC)[1]; \
- case 1: (DST)[0] = (SRC)[0]; \
- } \
+#define COPY_SZ_4V(DST, SZ, SRC) \
+do { \
+ switch (SZ) { \
+ case 4: (DST)[3] = (SRC)[3]; /* fallthrough */ \
+ case 3: (DST)[2] = (SRC)[2]; /* fallthrough */ \
+ case 2: (DST)[1] = (SRC)[1]; /* fallthrough */ \
+ case 1: (DST)[0] = (SRC)[0]; /* fallthrough */ \
+ } \
} while(0)
/** Copy \p SZ elements into a homegeneous (4-element) vector, giving
-/** Clamp X to [MIN,MAX] */
-#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
-
-/** Minimum of two values: */
-#define MIN2( A, B ) ( (A)<(B) ? (A) : (B) )
-
-/** Maximum of two values: */
-#define MAX2( A, B ) ( (A)>(B) ? (A) : (B) )
-
-/** Minimum and maximum of three values: */
-#define MIN3( A, B, C ) ((A) < (B) ? MIN2(A, C) : MIN2(B, C))
-#define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))
-
static inline unsigned
minify(unsigned value, unsigned levels)
{
return MAX2(1, value >> levels);
}
-/**
- * Align a value up to an alignment value
- *
- * If \c value is not already aligned to the requested alignment value, it
- * will be rounded up.
- *
- * \param value Value to be rounded
- * \param alignment Alignment value to be used. This must be a power of two.
- *
- * \sa ROUND_DOWN_TO()
- */
-static inline uintptr_t
-ALIGN(uintptr_t value, int32_t alignment)
-{
- assert((alignment > 0) && _mesa_is_pow_two(alignment));
- return (((value) + (alignment) - 1) & ~((alignment) - 1));
-}
-
-/**
- * Align a value down to an alignment value
- *
- * If \c value is not already aligned to the requested alignment value, it
- * will be rounded down.
- *
- * \param value Value to be rounded
- * \param alignment Alignment value to be used. This must be a power of two.
- *
- * \sa ALIGN()
- */
-static inline uintptr_t
-ROUND_DOWN_TO(uintptr_t value, int32_t alignment)
-{
- assert((alignment > 0) && _mesa_is_pow_two(alignment));
- return ((value) & ~(alignment - 1));
-}
-
/** Cross product of two 3-element vectors */
static inline void
/* Stringify */
#define STRINGIFY(x) #x
+/*
+ * For GL_ARB_vertex_buffer_object we need to treat vertex array pointers
+ * as offsets into buffer stores. Since the vertex array pointer and
+ * buffer store pointer are both pointers and we need to add them, we use
+ * this macro.
+ * Both pointers/offsets are expressed in bytes.
+ */
+#define ADD_POINTERS(A, B) ( (GLubyte *) (A) + (uintptr_t) (B) )
+
#endif