summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2013-11-22 15:59:56 -0800
committerFrancisco Jerez <[email protected]>2014-02-19 16:56:57 +0100
commitbbf8239f92ecd79431dfa41402e1c85318e7267f (patch)
treec2151a09a2feb600251a8789fdffc6079eaad67b /src/mesa
parent51b00c5cb9383e59a04431356e3b3605801d13e3 (diff)
i965: Have brw_imm_vf4() take the vector components as integer values.
Reviewed-by: Paul Berry <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/drivers/dri/i965/brw_clip_util.c2
-rw-r--r--src/mesa/drivers/dri/i965/brw_reg.h40
2 files changed, 31 insertions, 11 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_clip_util.c b/src/mesa/drivers/dri/i965/brw_clip_util.c
index 263cfdcea85..10ec2667067 100644
--- a/src/mesa/drivers/dri/i965/brw_clip_util.c
+++ b/src/mesa/drivers/dri/i965/brw_clip_util.c
@@ -224,7 +224,7 @@ void brw_clip_interp_vertex( struct brw_clip_compile *c,
vec1(t_nopersp),
brw_imm_f(0));
brw_IF(p, BRW_EXECUTE_1);
- brw_MOV(p, t_nopersp, brw_imm_vf4(VF_ONE, VF_ZERO, VF_ZERO, VF_ZERO));
+ brw_MOV(p, t_nopersp, brw_imm_vf4(1, 0, 0, 0));
brw_ENDIF(p);
/* Now compute t_nopersp = t_nopersp.y/t_nopersp.x and broadcast it. */
diff --git a/src/mesa/drivers/dri/i965/brw_reg.h b/src/mesa/drivers/dri/i965/brw_reg.h
index f497366b444..a0de75ef63b 100644
--- a/src/mesa/drivers/dri/i965/brw_reg.h
+++ b/src/mesa/drivers/dri/i965/brw_reg.h
@@ -43,6 +43,7 @@
#define BRW_REG_H
#include <stdbool.h>
+#include "main/imports.h"
#include "program/prog_instruction.h"
#include "brw_defines.h"
@@ -510,19 +511,38 @@ brw_imm_vf(unsigned v)
return imm;
}
-#define VF_ZERO 0x0
-#define VF_ONE 0x30
-#define VF_NEG (1<<7)
+/**
+ * Convert an integer into a "restricted" 8-bit float, used in vector
+ * immediates. The 8-bit floating point format has a sign bit, an
+ * excess-3 3-bit exponent, and a 4-bit mantissa. All integer values
+ * from -31 to 31 can be represented exactly.
+ */
+static inline uint8_t
+int_to_float8(int x)
+{
+ if (x == 0) {
+ return 0;
+ } else if (x < 0) {
+ return 1 << 7 | int_to_float8(-x);
+ } else {
+ const unsigned exponent = _mesa_logbase2(x);
+ const unsigned mantissa = (x - (1 << exponent)) << (4 - exponent);
+ assert(exponent <= 4);
+ return (exponent + 3) << 4 | mantissa;
+ }
+}
+/**
+ * Construct a floating-point packed vector immediate from its integer
+ * values. \sa int_to_float8()
+ */
static inline struct brw_reg
-brw_imm_vf4(unsigned v0, unsigned v1, unsigned v2, unsigned v3)
+brw_imm_vf4(int v0, int v1, int v2, int v3)
{
- struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_VF);
- imm.vstride = BRW_VERTICAL_STRIDE_0;
- imm.width = BRW_WIDTH_4;
- imm.hstride = BRW_HORIZONTAL_STRIDE_1;
- imm.dw1.ud = ((v0 << 0) | (v1 << 8) | (v2 << 16) | (v3 << 24));
- return imm;
+ return brw_imm_vf((int_to_float8(v0) << 0) |
+ (int_to_float8(v1) << 8) |
+ (int_to_float8(v2) << 16) |
+ (int_to_float8(v3) << 24));
}