i965: Add function to negate immediates.
authorMatt Turner <mattst88@gmail.com>
Thu, 29 Jan 2015 19:15:10 +0000 (11:15 -0800)
committerMatt Turner <mattst88@gmail.com>
Tue, 3 Feb 2015 20:25:14 +0000 (12:25 -0800)
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/mesa/drivers/dri/i965/brw_shader.cpp
src/mesa/drivers/dri/i965/brw_shader.h

index 20cbf5bacdb3aedabf4a81c2434a79bd29f2e8b9..c5a666cf2cc6468077e9a3a2dc6511cdda5d76de 100644 (file)
@@ -620,6 +620,45 @@ brw_saturate_immediate(enum brw_reg_type type, struct brw_reg *reg)
    return false;
 }
 
+bool
+brw_negate_immediate(enum brw_reg_type type, struct brw_reg *reg)
+{
+   switch (type) {
+   case BRW_REGISTER_TYPE_D:
+      reg->dw1.d = -reg->dw1.d;
+      return true;
+   case BRW_REGISTER_TYPE_W:
+      reg->dw1.d = -(int16_t)reg->dw1.ud;
+      return true;
+   case BRW_REGISTER_TYPE_F:
+      reg->dw1.f = -reg->dw1.f;
+      return true;
+   case BRW_REGISTER_TYPE_VF:
+      reg->dw1.ud ^= 0x80808080;
+      return true;
+   case BRW_REGISTER_TYPE_UB:
+   case BRW_REGISTER_TYPE_B:
+      unreachable("no UB/B immediates");
+   case BRW_REGISTER_TYPE_UD:
+   case BRW_REGISTER_TYPE_UW:
+      /* Presumably the negate modifier on an unsigned source is the same as
+       * on a signed source but it would be nice to confirm.
+       */
+      assert(!"unimplemented: negate UD/UW immediate");
+   case BRW_REGISTER_TYPE_UV:
+   case BRW_REGISTER_TYPE_V:
+      assert(!"unimplemented: negate UV/V immediate");
+   case BRW_REGISTER_TYPE_UQ:
+   case BRW_REGISTER_TYPE_Q:
+      assert(!"unimplemented: negate UQ/Q immediate");
+   case BRW_REGISTER_TYPE_DF:
+   case BRW_REGISTER_TYPE_HF:
+      assert(!"unimplemented: negate DF/HF immediate");
+   }
+
+   return false;
+}
+
 backend_visitor::backend_visitor(struct brw_context *brw,
                                  struct gl_shader_program *shader_prog,
                                  struct gl_program *prog,
index 6fc86e1c549bf8af7edd1275651544c3e6678bff..2b9b72e3ece7ec6d07b653458d42a871e8b20b64 100644 (file)
@@ -195,6 +195,7 @@ enum brw_conditional_mod brw_conditional_for_comparison(unsigned int op);
 uint32_t brw_math_function(enum opcode op);
 const char *brw_instruction_name(enum opcode op);
 bool brw_saturate_immediate(enum brw_reg_type type, struct brw_reg *reg);
+bool brw_negate_immediate(enum brw_reg_type type, struct brw_reg *reg);
 
 #ifdef __cplusplus
 extern "C" {