X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fmacros.h;h=bd07fa71bc662e2a1e52384df969053e80aa4c40;hb=6aea39641a6c32f780c40e3344096d3e0eccb590;hp=c3ef42a4282dda84eeb3b089e6ab3a3f177ca10b;hpb=97f4efd573aed7ffc0ea9395f4e69ccdeb5041f6;p=mesa.git diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h index c3ef42a4282..bd07fa71bc6 100644 --- a/src/mesa/main/macros.h +++ b/src/mesa/main/macros.h @@ -34,7 +34,9 @@ #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" /** @@ -194,6 +196,30 @@ static inline fi_type FLOAT_AS_UNION(GLfloat f) 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. * @@ -278,14 +304,14 @@ COPY_4UBV(GLubyte dst[4], const GLubyte src[4]) } /** 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 @@ -660,61 +686,12 @@ INTERP_4F(GLfloat t, GLfloat dst[4], const GLfloat out[4], const GLfloat in[4]) -/** 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 @@ -811,4 +788,13 @@ DIFFERENT_SIGNS(GLfloat x, GLfloat y) /* 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