gallium/util: fix util_color_[un]pack[-ub] to be strict aliasing safe
[mesa.git] / src / gallium / drivers / llvmpipe / lp_bld_debug.c
index 30925b5f415d3f65d113769f3c1e8b01349afa76..59d8f492e60af0af4585c1fcaa5ac95f8154e5f6 100644 (file)
 #include <udis86.h>
 #endif
 
+#include "util/u_math.h"
 #include "util/u_debug.h"
 #include "lp_bld_debug.h"
 
 
+/**
+ * Check alignment.
+ *
+ * It is important that this check is not implemented as a macro or inlined
+ * function, as the compiler assumptions in respect to alignment of global
+ * and stack variables would often make the check a no op, defeating the
+ * whole purpose of the exercise.
+ */
+boolean
+lp_check_alignment(const void *ptr, unsigned alignment)
+{
+   assert(util_is_pot(alignment));
+   return ((uintptr_t)ptr & (alignment - 1)) == 0;
+}
+
+
 void
 lp_disassemble(const void* func)
 {