mesa/st: enable carry/borrow lowering pass
[mesa.git] / src / mesa / main / macros.h
index 05aad4eb8b1e939c39fb5c331abd54c973ae8191..5228c3a8f28e798ddab8d7cd4d095d3bf9d098b6 100644 (file)
@@ -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.0f ? 0 : (uint32_t) 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 int32_t
+S_FIXED(float value, uint32_t frac_bits)
+{
+   return (int32_t) (value * (1 << frac_bits));
+}
 /*@}*/
 
 
@@ -662,6 +684,17 @@ minify(unsigned value, unsigned levels)
     return MAX2(1, value >> levels);
 }
 
+/**
+ * Return true if the given value is a power of two.
+ *
+ * Note that this considers 0 a power of two.
+ */
+static inline bool
+is_power_of_two(unsigned value)
+{
+   return (value & (value - 1)) == 0;
+}
+
 /**
  * Align a value up to an alignment value
  *
@@ -675,6 +708,18 @@ minify(unsigned value, unsigned levels)
  */
 #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 */
@@ -775,5 +820,7 @@ DIFFERENT_SIGNS(GLfloat x, GLfloat y)
 /* Compute the size of an array */
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
 
+/* Stringify */
+#define STRINGIFY(x) #x
 
 #endif