gallium: remove the swizzling parts of ExtSwizzle
[mesa.git] / src / gallium / auxiliary / draw / draw_vs_aos.c
index 87232865e23c89ed756fa7bfc30bf1adab98b71e..88bc790b6211b79fae74455c16250fbc4e050eae 100644 (file)
@@ -32,7 +32,7 @@
 #include "util/u_memory.h"
 #include "util/u_math.h"
 #include "pipe/p_shader_tokens.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 #include "tgsi/tgsi_parse.h"
 #include "tgsi/tgsi_util.h"
 #include "tgsi/tgsi_exec.h"
@@ -143,7 +143,7 @@ static struct x86_reg get_reg_ptr(struct aos_compilation *cp,
       return x86_make_disp(aos_get_x86(cp, 1, X86_CONSTANTS), idx * 4 * sizeof(float));
 
    default:
-      ERROR(cp, "unknown reg file");
+      AOS_ERROR(cp, "unknown reg file");
       return x86_make_reg(0,0);
    }
 }
@@ -177,7 +177,7 @@ static void spill( struct aos_compilation *cp, unsigned idx )
        (cp->xmm[idx].file != TGSI_FILE_INPUT && /* inputs are fetched into xmm & set dirty */
         cp->xmm[idx].file != TGSI_FILE_OUTPUT &&
         cp->xmm[idx].file != TGSI_FILE_TEMPORARY)) {
-      ERROR(cp, "invalid spill");
+      AOS_ERROR(cp, "invalid spill");
       return;
    }
    else {
@@ -284,6 +284,15 @@ void aos_release_xmm_reg( struct aos_compilation *cp,
 }
 
 
+static void aos_soft_release_xmm( struct aos_compilation *cp,
+                                  struct x86_reg reg )
+{
+   if (reg.file == file_XMM) {
+      assert(cp->xmm[reg.idx].last_used == cp->insn_counter);
+      cp->xmm[reg.idx].last_used = cp->insn_counter - 1;
+   }
+}
+
 
      
 /* Mark an xmm reg as holding the current copy of a shader reg.
@@ -528,19 +537,10 @@ static struct x86_reg fetch_src( struct aos_compilation *cp,
    unsigned abs = 0;
 
    for (i = 0; i < 4; i++) {
-      unsigned swizzle = tgsi_util_get_full_src_register_extswizzle( src, i );
+      unsigned swizzle = tgsi_util_get_full_src_register_swizzle( src, i );
       unsigned neg = tgsi_util_get_full_src_register_sign_mode( src, i );
 
-      switch (swizzle) {
-      case TGSI_EXTSWIZZLE_ZERO:
-      case TGSI_EXTSWIZZLE_ONE:
-         ERROR(cp, "not supporting full swizzles yet in tgsi_aos_sse2");
-         break;
-
-      default:
-         swz |= (swizzle & 0x3) << (i * 2);
-         break;
-      }
+      swz |= (swizzle & 0x3) << (i * 2);
 
       switch (neg) {
       case TGSI_UTIL_SIGN_TOGGLE:
@@ -555,7 +555,7 @@ static struct x86_reg fetch_src( struct aos_compilation *cp,
          break;
 
       default:
-         ERROR(cp, "unsupported sign-mode");
+         AOS_ERROR(cp, "unsupported sign-mode");
          break;
       }
    }
@@ -584,15 +584,17 @@ static struct x86_reg fetch_src( struct aos_compilation *cp,
          sse_mulps(cp->func, dst, tmp);
 
          aos_release_xmm_reg(cp, tmp.idx);
+         aos_soft_release_xmm(cp, imm_swz);
       }
       else if (negs) {
          struct x86_reg imm_negs = aos_get_internal_xmm(cp, IMM_NEGS);
          sse_mulps(cp->func, dst, imm_negs);
+         aos_soft_release_xmm(cp, imm_negs);
       }
 
 
       if (abs && abs != 0xf) {
-         ERROR(cp, "unsupported partial abs");
+         AOS_ERROR(cp, "unsupported partial abs");
       }
       else if (abs) {
          struct x86_reg neg = aos_get_internal(cp, IMM_NEGS);
@@ -603,8 +605,10 @@ static struct x86_reg fetch_src( struct aos_compilation *cp,
          sse_maxps(cp->func, dst, tmp);
 
          aos_release_xmm_reg(cp, tmp.idx);
+         aos_soft_release_xmm(cp, neg);
       }
 
+      aos_soft_release_xmm(cp, arg0);
       return dst;
    }
       
@@ -619,23 +623,10 @@ static void x87_fld_src( struct aos_compilation *cp,
                                                 src->SrcRegister.File, 
                                                 src->SrcRegister.Index);
 
-   unsigned swizzle = tgsi_util_get_full_src_register_extswizzle( src, channel );
+   unsigned swizzle = tgsi_util_get_full_src_register_swizzle( src, channel );
    unsigned neg = tgsi_util_get_full_src_register_sign_mode( src, channel );
 
-   switch (swizzle) {
-   case TGSI_EXTSWIZZLE_ZERO:
-      x87_fldz( cp->func );
-      break;
-
-   case TGSI_EXTSWIZZLE_ONE:
-      x87_fld1( cp->func );
-      break;
-
-   default:
-      x87_fld( cp->func, x86_make_disp(arg0, (swizzle & 3) * sizeof(float)) );
-      break;
-   }
-   
+   x87_fld( cp->func, x86_make_disp(arg0, (swizzle & 3) * sizeof(float)) );
 
    switch (neg) {
    case TGSI_UTIL_SIGN_TOGGLE:
@@ -657,7 +648,7 @@ static void x87_fld_src( struct aos_compilation *cp,
       break;
 
    default:
-      ERROR(cp, "unsupported sign-mode");
+      AOS_ERROR(cp, "unsupported sign-mode");
       break;
    }
 }
@@ -871,14 +862,14 @@ static void set_fpu_round_nearest( struct aos_compilation *cp )
    }
 }
 
-
+#if 0
 static void x87_emit_ex2( struct aos_compilation *cp )
 {
    struct x86_reg st0 = x86_make_reg(file_x87, 0);
    struct x86_reg st1 = x86_make_reg(file_x87, 1);
    int stack = cp->func->x87_stack;
 
-//   set_fpu_round_neg_inf( cp );
+   /* set_fpu_round_neg_inf( cp ); */
 
    x87_fld(cp->func, st0);      /* a a */
    x87_fprndint( cp->func );   /* int(a) a*/
@@ -894,13 +885,17 @@ static void x87_emit_ex2( struct aos_compilation *cp )
    assert( stack == cp->func->x87_stack);
       
 }
+#endif
 
+#if 0
 static void PIPE_CDECL print_reg( const char *msg,
                                   const float *reg )
 {
    debug_printf("%s: %f %f %f %f\n", msg, reg[0], reg[1], reg[2], reg[3]);
 }
+#endif
 
+#if 0
 static void emit_print( struct aos_compilation *cp,
                         const char *message, /* must point to a static string! */
                         unsigned file,
@@ -952,6 +947,7 @@ static void emit_print( struct aos_compilation *cp,
    /* Done... 
     */
 }
+#endif
 
 /**
  * The traditional instructions.  All operate on internal registers
@@ -1090,7 +1086,7 @@ static boolean emit_LG2( struct aos_compilation *cp, const struct tgsi_full_inst
    return TRUE;
 }
 
-
+#if 0
 static boolean emit_EX2( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) 
 {
    x87_fld_src(cp, &op->FullSrcRegisters[0], 0);
@@ -1098,6 +1094,7 @@ static boolean emit_EX2( struct aos_compilation *cp, const struct tgsi_full_inst
    x87_fstp_dest4(cp, &op->FullDstRegisters[0]);
    return TRUE;
 }
+#endif
 
 
 static boolean emit_FLR( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) 
@@ -1553,7 +1550,6 @@ static boolean emit_RCP( struct aos_compilation *cp, const struct tgsi_full_inst
  */
 static boolean emit_RSQ( struct aos_compilation *cp, const struct tgsi_full_instruction *op )
 {
-
    if (0) {
       struct x86_reg arg0 = fetch_src(cp, &op->FullSrcRegisters[0]);
       struct x86_reg r = aos_get_xmm_reg(cp);
@@ -1562,21 +1558,30 @@ static boolean emit_RSQ( struct aos_compilation *cp, const struct tgsi_full_inst
       return TRUE;
    }
    else {
-      struct x86_reg arg0 = fetch_src(cp, &op->FullSrcRegisters[0]);
-      struct x86_reg r = aos_get_xmm_reg(cp);
+      struct x86_reg arg0           = fetch_src(cp, &op->FullSrcRegisters[0]);
+      struct x86_reg r              = aos_get_xmm_reg(cp);
 
       struct x86_reg neg_half       = get_reg_ptr( cp, AOS_FILE_INTERNAL, IMM_RSQ );
       struct x86_reg one_point_five = x86_make_disp( neg_half, 4 );
       struct x86_reg src            = get_xmm_writable( cp, arg0 );
-      
-      sse_rsqrtss( cp->func, r, src  );             /* rsqrtss(a) */
-      sse_mulss(   cp->func, src, neg_half  );      /* -.5 * a */
-      sse_mulss(   cp->func, src,  r );             /* -.5 * a * r */
-      sse_mulss(   cp->func, src,  r );             /* -.5 * a * r * r */
-      sse_addss(   cp->func, src, one_point_five ); /* 1.5 - .5 * a * r * r */
-      sse_mulss(   cp->func, r,  src );             /* r * (1.5 - .5 * a * r * r) */
+      struct x86_reg neg            = aos_get_internal(cp, IMM_NEGS);
+      struct x86_reg tmp            = aos_get_xmm_reg(cp);
+
+      sse_movaps(cp->func, tmp, src);
+      sse_mulps(cp->func, tmp, neg);
+      sse_maxps(cp->func, tmp, src);
+   
+      sse_rsqrtss( cp->func, r, tmp  );             /* rsqrtss(a) */
+      sse_mulss(   cp->func, tmp, neg_half  );      /* -.5 * a */
+      sse_mulss(   cp->func, tmp,  r );             /* -.5 * a * r */
+      sse_mulss(   cp->func, tmp,  r );             /* -.5 * a * r * r */
+      sse_addss(   cp->func, tmp, one_point_five ); /* 1.5 - .5 * a * r * r */
+      sse_mulss(   cp->func, r,  tmp );             /* r * (1.5 - .5 * a * r * r) */
 
       store_scalar_dest(cp, &op->FullDstRegisters[0], r);
+
+      aos_release_xmm_reg(cp, tmp.idx);
+
       return TRUE;
    }
 }
@@ -1632,6 +1637,17 @@ static boolean emit_SUB( struct aos_compilation *cp, const struct tgsi_full_inst
    return TRUE;
 }
 
+static boolean emit_TRUNC( struct aos_compilation *cp, const struct tgsi_full_instruction *op )
+{
+   struct x86_reg arg0 = fetch_src(cp, &op->FullSrcRegisters[0]);
+   struct x86_reg tmp0 = aos_get_xmm_reg(cp);
+
+   sse2_cvttps2dq(cp->func, tmp0, arg0);
+   sse2_cvtdq2ps(cp->func, tmp0, tmp0);
+
+   store_dest(cp, &op->FullDstRegisters[0], tmp0);
+   return TRUE;
+}
 
 static boolean emit_XPD( struct aos_compilation *cp, const struct tgsi_full_instruction *op ) 
 {
@@ -1720,24 +1736,24 @@ emit_instruction( struct aos_compilation *cp,
    case TGSI_OPCODE_SUB:
       return emit_SUB(cp, inst);
  
-   case TGSI_OPCODE_LERP:
-//      return emit_LERP(cp, inst);
+   case TGSI_OPCODE_LRP:
+      /*return emit_LERP(cp, inst);*/
       return FALSE;
 
-   case TGSI_OPCODE_FRAC:
+   case TGSI_OPCODE_FRC:
       return emit_FRC(cp, inst);
 
    case TGSI_OPCODE_CLAMP:
-//      return emit_CLAMP(cp, inst);
+      /*return emit_CLAMP(cp, inst);*/
       return FALSE;
 
-   case TGSI_OPCODE_FLOOR:
+   case TGSI_OPCODE_FLR:
       return emit_FLR(cp, inst);
 
    case TGSI_OPCODE_ROUND:
       return emit_RND(cp, inst);
 
-   case TGSI_OPCODE_EXPBASE2:
+   case TGSI_OPCODE_EX2:
 #if FAST_MATH
       return emit_EXPBASE2(cp, inst);
 #elif 0
@@ -1749,13 +1765,13 @@ emit_instruction( struct aos_compilation *cp,
       return FALSE;
 #endif
 
-   case TGSI_OPCODE_LOGBASE2:
+   case TGSI_OPCODE_LG2:
       return emit_LG2(cp, inst);
 
-   case TGSI_OPCODE_POWER:
+   case TGSI_OPCODE_POW:
       return emit_POW(cp, inst);
 
-   case TGSI_OPCODE_CROSSPRODUCT:
+   case TGSI_OPCODE_XPD:
       return emit_XPD(cp, inst);
 
    case TGSI_OPCODE_ABS:
@@ -1770,6 +1786,9 @@ emit_instruction( struct aos_compilation *cp,
    case TGSI_OPCODE_SIN:
       return emit_SIN(cp, inst);
 
+   case TGSI_OPCODE_TRUNC:
+      return emit_TRUNC(cp, inst);
+
    case TGSI_OPCODE_END:
       return TRUE;
 
@@ -1850,8 +1869,9 @@ static boolean note_immediate( struct aos_compilation *cp,
    unsigned pos = cp->num_immediates++;
    unsigned j;
 
-   for (j = 0; j < imm->Immediate.Size; j++) {
-      cp->vaos->machine->immediate[pos][j] = imm->u.ImmediateFloat32[j].Float;
+   assert( imm->Immediate.NrTokens <= 4 + 1 );
+   for (j = 0; j < imm->Immediate.NrTokens - 1; j++) {
+      cp->vaos->machine->immediate[pos][j] = imm->u[j].Float;
    }
 
    return TRUE;
@@ -2176,7 +2196,8 @@ static struct draw_vs_varient *varient_aos_sse( struct draw_vertex_shader *vs,
    if (!vaos->buffer)
       goto fail;
 
-   debug_printf("nr_vb: %d const: %x\n", vaos->nr_vb, vaos->base.key.const_vbuffers);
+   if (0)
+      debug_printf("nr_vb: %d const: %x\n", vaos->nr_vb, vaos->base.key.const_vbuffers);
 
 #if 0
    tgsi_dump(vs->state.tokens, 0);