v3d: rename vertex shader key (num)_fs_inputs fields
[mesa.git] / src / broadcom / cle / v3d_packet_helpers.h
index d01ff6ef0ad5c4f90bf97915f804b358defd1153..53a5215fb9a2410dd478590081964a2b6f6301c2 100644 (file)
  * IN THE SOFTWARE.
  */
 
+#ifndef MESA_V3D_PACKET_HELPERS_H
+#define MESA_V3D_PACKET_HELPERS_H
+
 #include <stdio.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <assert.h>
 #include <math.h>
+#include "util/u_math.h"
 
 #ifdef HAVE_VALGRIND
 #include <valgrind.h>
 #include <memcheck.h>
 #define VG(x) x
+#ifndef NDEBUG
 #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
+#endif
 #else
-#define VG(x)
+#define VG(x) ((void)0)
 #endif
 
 #ifndef __gen_validate_value
@@ -64,7 +70,7 @@ __gen_uint(uint64_t v, uint32_t start, uint32_t end)
 {
    __gen_validate_value(v);
 
-#if DEBUG
+#ifndef NDEBUG
    const int width = end - start + 1;
    if (width < 64) {
       const uint64_t max = (1ull << width) - 1;
@@ -82,7 +88,7 @@ __gen_sint(int64_t v, uint32_t start, uint32_t end)
 
    __gen_validate_value(v);
 
-#if DEBUG
+#ifndef NDEBUG
    if (width < 64) {
       const int64_t max = (1ll << (width - 1)) - 1;
       const int64_t min = -(1ll << (width - 1));
@@ -99,7 +105,7 @@ static inline uint64_t
 __gen_offset(uint64_t v, uint32_t start, uint32_t end)
 {
    __gen_validate_value(v);
-#if DEBUG
+#ifndef NDEBUG
    uint64_t mask = (~0ull >> (64 - (end - start + 1))) << start;
 
    assert((v & ~mask) == 0);
@@ -122,7 +128,7 @@ __gen_sfixed(float v, uint32_t start, uint32_t end, uint32_t fract_bits)
 
    const float factor = (1 << fract_bits);
 
-#if DEBUG
+#ifndef NDEBUG
    const float max = ((1 << (end - start)) - 1) / factor;
    const float min = -(1 << (end - start)) / factor;
    assert(min <= v && v <= max);
@@ -141,7 +147,7 @@ __gen_ufixed(float v, uint32_t start, uint32_t end, uint32_t fract_bits)
 
    const float factor = (1 << fract_bits);
 
-#if DEBUG
+#ifndef NDEBUG
    const float max = ((1 << (end - start + 1)) - 1) / factor;
    const float min = 0.0f;
    assert(min <= v && v <= max);
@@ -176,6 +182,22 @@ __gen_unpack_sint(const uint8_t *restrict cl, uint32_t start, uint32_t end)
    return (val << (64 - size)) >> (64 - size);
 }
 
+static inline float
+__gen_unpack_sfixed(const uint8_t *restrict cl, uint32_t start, uint32_t end,
+                    uint32_t fractional_size)
+{
+        int32_t bits = __gen_unpack_sint(cl, start, end);
+        return (float)bits / (1 << fractional_size);
+}
+
+static inline float
+__gen_unpack_ufixed(const uint8_t *restrict cl, uint32_t start, uint32_t end,
+                    uint32_t fractional_size)
+{
+        int32_t bits = __gen_unpack_uint(cl, start, end);
+        return (float)bits / (1 << fractional_size);
+}
+
 static inline float
 __gen_unpack_float(const uint8_t *restrict cl, uint32_t start, uint32_t end)
 {
@@ -187,3 +209,12 @@ __gen_unpack_float(const uint8_t *restrict cl, uint32_t start, uint32_t end)
    return f->f;
 }
 
+static inline float
+__gen_unpack_f187(const uint8_t *restrict cl, uint32_t start, uint32_t end)
+{
+   assert(end - start == 15);
+   uint32_t bits = __gen_unpack_uint(cl, start, end);
+   return uif(bits << 16);
+}
+
+#endif