aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/macros.h
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/mesa/main/macros.h')
-rw-r--r--mesalib/src/mesa/main/macros.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/mesalib/src/mesa/main/macros.h b/mesalib/src/mesa/main/macros.h
index 1052f7560..880c6564e 100644
--- a/mesalib/src/mesa/main/macros.h
+++ b/mesalib/src/mesa/main/macros.h
@@ -184,6 +184,28 @@ static inline GLfloat UINT_AS_FLT(GLuint u)
return tmp.f;
}
+/**
+ * Convert a floating point value to an unsigned fixed point value.
+ *
+ * \param frac_bits The number of bits used to store the fractional part.
+ */
+static INLINE uint32_t
+U_FIXED(float value, uint32_t frac_bits)
+{
+ value *= (1 << frac_bits);
+ return value < 0 ? 0 : value;
+}
+
+/**
+ * Convert a floating point value to an signed fixed point value.
+ *
+ * \param frac_bits The number of bits used to store the fractional part.
+ */
+static INLINE uint32_t
+S_FIXED(float value, uint32_t frac_bits)
+{
+ return value * (1 << frac_bits);
+}
/*@}*/
@@ -673,8 +695,20 @@ minify(unsigned value, unsigned levels)
*
* \sa ROUND_DOWN_TO()
*/
-#define ALIGN(value, alignment) (((value) + alignment - 1) & ~(alignment - 1))
+#define ALIGN(value, alignment) (((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()
+ */
+#define ROUND_DOWN_TO(value, alignment) ((value) & ~(alignment - 1))
/** Cross product of two 3-element vectors */