gallium: remove the swizzling parts of ExtSwizzle
[mesa.git] / src / gallium / auxiliary / tgsi / tgsi_exec.c
index 711e86d6edfdf4df2f53f632e376d30fef28a867..14f0fc4e389cda89ed1b69ba26925e9fd0eed19e 100644 (file)
@@ -210,9 +210,8 @@ tgsi_check_soa_dependencies(const struct tgsi_full_instruction *inst)
          uint channelsWritten = 0x0;
          FOR_EACH_ENABLED_CHANNEL(*inst, chan) {
             /* check if we're reading a channel that's been written */
-            uint swizzle = tgsi_util_get_full_src_register_extswizzle(&inst->FullSrcRegisters[i], chan);
-            if (swizzle <= TGSI_SWIZZLE_W &&
-                (channelsWritten & (1 << swizzle))) {
+            uint swizzle = tgsi_util_get_full_src_register_swizzle(&inst->FullSrcRegisters[i], chan);
+            if (channelsWritten & (1 << swizzle)) {
                return TRUE;
             }
 
@@ -338,7 +337,7 @@ tgsi_exec_machine_bind_shader(
             /* XXX we only handle SOA dependencies properly for MOV/SWZ
              * at this time!
              */
-            if (opcode != TGSI_OPCODE_MOV && opcode != TGSI_OPCODE_SWZ) {
+            if (opcode != TGSI_OPCODE_MOV) {
                debug_printf("Warning: SOA dependency in instruction"
                             " is not handled:\n");
                tgsi_dump_instruction(&parse.FullToken.FullInstruction,
@@ -1130,10 +1129,10 @@ fetch_src_file_channel(
    union tgsi_exec_channel *chan )
 {
    switch( swizzle ) {
-   case TGSI_EXTSWIZZLE_X:
-   case TGSI_EXTSWIZZLE_Y:
-   case TGSI_EXTSWIZZLE_Z:
-   case TGSI_EXTSWIZZLE_W:
+   case TGSI_SWIZZLE_X:
+   case TGSI_SWIZZLE_Y:
+   case TGSI_SWIZZLE_Z:
+   case TGSI_SWIZZLE_W:
       switch( file ) {
       case TGSI_FILE_CONSTANT:
          assert(mach->Consts);
@@ -1201,14 +1200,6 @@ fetch_src_file_channel(
       }
       break;
 
-   case TGSI_EXTSWIZZLE_ZERO:
-      *chan = mach->Temps[TEMP_0_I].xyzw[TEMP_0_C];
-      break;
-
-   case TGSI_EXTSWIZZLE_ONE:
-      *chan = mach->Temps[TEMP_1_I].xyzw[TEMP_1_C];
-      break;
-
    default:
       assert( 0 );
    }
@@ -1367,7 +1358,7 @@ fetch_source(
        */
    }
 
-   swizzle = tgsi_util_get_full_src_register_extswizzle( reg, chan_index );
+   swizzle = tgsi_util_get_full_src_register_swizzle( reg, chan_index );
    fetch_src_file_channel(
       mach,
       reg->SrcRegister.File,
@@ -1689,10 +1680,8 @@ exec_kil(struct tgsi_exec_machine *mach,
    uint kilmask = 0; /* bit 0 = pixel 0, bit 1 = pixel 1, etc */
    union tgsi_exec_channel r[1];
 
-   /* This mask stores component bits that were already tested. Note that
-    * we test if the value is less than zero, so 1.0 and 0.0 need not to be
-    * tested. */
-   uniquemask = (1 << TGSI_EXTSWIZZLE_ZERO) | (1 << TGSI_EXTSWIZZLE_ONE);
+   /* This mask stores component bits that were already tested. */
+   uniquemask = 0;
 
    for (chan_index = 0; chan_index < 4; chan_index++)
    {
@@ -1700,7 +1689,7 @@ exec_kil(struct tgsi_exec_machine *mach,
       uint i;
 
       /* unswizzle channel */
-      swizzle = tgsi_util_get_full_src_register_extswizzle (
+      swizzle = tgsi_util_get_full_src_register_swizzle (
                         &inst->FullSrcRegisters[0],
                         chan_index);
 
@@ -2031,7 +2020,6 @@ exec_instruction(
       break;
 
    case TGSI_OPCODE_MOV:
-   case TGSI_OPCODE_SWZ:
       if (inst->Flags & SOA_DEPENDENCY_FLAG) {
          /* Do all fetches into temp regs, then do all stores to avoid
           * intermediate/accidental clobbering.  This could be done all the
@@ -2329,16 +2317,6 @@ exec_instruction(
       }
       break;
 
-   case TGSI_OPCODE_CND0:
-      FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) {
-         FETCH(&r[0], 0, chan_index);
-         FETCH(&r[1], 1, chan_index);
-         FETCH(&r[2], 2, chan_index);
-         micro_le(&r[0], &mach->Temps[TEMP_0_I].xyzw[TEMP_0_C], &r[2], &r[0], &r[1]);
-         STORE(&r[0], 0, chan_index);
-      }
-      break;
-
    case TGSI_OPCODE_DP2A:
       FETCH( &r[0], 0, CHAN_X );
       FETCH( &r[1], 1, CHAN_X );
@@ -2766,19 +2744,32 @@ exec_instruction(
       if (mach->ExecMask) {
          /* do the call */
 
-         /* push the Cond, Loop, Cont stacks */
+         /* First, record the depths of the execution stacks.
+          * This is important for deeply nested/looped return statements.
+          * We have to unwind the stacks by the correct amount.  For a
+          * real code generator, we could determine the number of entries
+          * to pop off each stack with simple static analysis and avoid
+          * implementing this data structure at run time.
+          */
+         mach->CallStack[mach->CallStackTop].CondStackTop = mach->CondStackTop;
+         mach->CallStack[mach->CallStackTop].LoopStackTop = mach->LoopStackTop;
+         mach->CallStack[mach->CallStackTop].ContStackTop = mach->ContStackTop;
+         /* note that PC was already incremented above */
+         mach->CallStack[mach->CallStackTop].ReturnAddr = *pc;
+
+         mach->CallStackTop++;
+
+         /* Second, push the Cond, Loop, Cont, Func stacks */
          assert(mach->CondStackTop < TGSI_EXEC_MAX_COND_NESTING);
          mach->CondStack[mach->CondStackTop++] = mach->CondMask;
          assert(mach->LoopStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
          mach->LoopStack[mach->LoopStackTop++] = mach->LoopMask;
          assert(mach->ContStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
          mach->ContStack[mach->ContStackTop++] = mach->ContMask;
-
          assert(mach->FuncStackTop < TGSI_EXEC_MAX_CALL_NESTING);
          mach->FuncStack[mach->FuncStackTop++] = mach->FuncMask;
 
-         /* note that PC was already incremented above */
-         mach->CallStack[mach->CallStackTop++] = *pc;
+         /* Finally, jump to the subroutine */
          *pc = inst->InstructionExtLabel.Label;
       }
       break;
@@ -2795,18 +2786,24 @@ exec_instruction(
             *pc = -1;
             return;
          }
-         *pc = mach->CallStack[--mach->CallStackTop];
 
-         /* pop the Cond, Loop, Cont stacks */
-         assert(mach->CondStackTop > 0);
-         mach->CondMask = mach->CondStack[--mach->CondStackTop];
-         assert(mach->LoopStackTop > 0);
-         mach->LoopMask = mach->LoopStack[--mach->LoopStackTop];
-         assert(mach->ContStackTop > 0);
-         mach->ContMask = mach->ContStack[--mach->ContStackTop];
+         assert(mach->CallStackTop > 0);
+         mach->CallStackTop--;
+
+         mach->CondStackTop = mach->CallStack[mach->CallStackTop].CondStackTop;
+         mach->CondMask = mach->CondStack[mach->CondStackTop];
+
+         mach->LoopStackTop = mach->CallStack[mach->CallStackTop].LoopStackTop;
+         mach->LoopMask = mach->LoopStack[mach->LoopStackTop];
+
+         mach->ContStackTop = mach->CallStack[mach->CallStackTop].ContStackTop;
+         mach->ContMask = mach->ContStack[mach->ContStackTop];
+
          assert(mach->FuncStackTop > 0);
          mach->FuncMask = mach->FuncStack[--mach->FuncStackTop];
 
+         *pc = mach->CallStack[mach->CallStackTop].ReturnAddr;
+
          UPDATE_EXEC_MASK(mach);
       }
       break;
@@ -3104,6 +3101,12 @@ exec_instruction(
       break;
 
    case TGSI_OPCODE_BGNFOR:
+      assert(mach->LoopCounterStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
+      for (chan_index = 0; chan_index < 3; chan_index++) {
+         FETCH( &mach->LoopCounterStack[mach->LoopCounterStackTop].xyzw[chan_index], 0, chan_index );
+      }
+      STORE( &mach->LoopCounterStack[mach->LoopCounterStackTop].xyzw[CHAN_Y], 0, CHAN_X );
+      ++mach->LoopCounterStackTop;
       /* fall-through (for now) */
    case TGSI_OPCODE_BGNLOOP:
       /* push LoopMask and ContMasks */
@@ -3111,10 +3114,58 @@ exec_instruction(
       mach->LoopStack[mach->LoopStackTop++] = mach->LoopMask;
       assert(mach->ContStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
       mach->ContStack[mach->ContStackTop++] = mach->ContMask;
+      assert(mach->LoopLabelStackTop < TGSI_EXEC_MAX_LOOP_NESTING);
+      mach->LoopLabelStack[mach->LoopLabelStackTop++] = *pc - 1;
       break;
 
    case TGSI_OPCODE_ENDFOR:
-      /* fall-through (for now at least) */
+      assert(mach->LoopCounterStackTop > 0);
+      micro_sub( &mach->LoopCounterStack[mach->LoopCounterStackTop - 1].xyzw[CHAN_X], 
+                 &mach->LoopCounterStack[mach->LoopCounterStackTop - 1].xyzw[CHAN_X],
+                 &mach->Temps[TEMP_1_I].xyzw[TEMP_1_C] );
+      /* update LoopMask */
+      if( mach->LoopCounterStack[mach->LoopCounterStackTop - 1].xyzw[CHAN_X].f[0] <= 0) {
+         mach->LoopMask &= ~0x1;
+      }
+      if( mach->LoopCounterStack[mach->LoopCounterStackTop - 1].xyzw[CHAN_X].f[1] <= 0 ) {
+         mach->LoopMask &= ~0x2;
+      }
+      if( mach->LoopCounterStack[mach->LoopCounterStackTop - 1].xyzw[CHAN_X].f[2] <= 0 ) {
+         mach->LoopMask &= ~0x4;
+      }
+      if( mach->LoopCounterStack[mach->LoopCounterStackTop - 1].xyzw[CHAN_X].f[3] <= 0 ) {
+         mach->LoopMask &= ~0x8;
+      }
+      micro_add( &mach->LoopCounterStack[mach->LoopCounterStackTop - 1].xyzw[CHAN_Y], 
+                 &mach->LoopCounterStack[mach->LoopCounterStackTop - 1].xyzw[CHAN_Y], 
+                 &mach->LoopCounterStack[mach->LoopCounterStackTop - 1].xyzw[CHAN_Z]);
+      assert(mach->LoopLabelStackTop > 0);
+      inst = mach->Instructions + mach->LoopLabelStack[mach->LoopLabelStackTop - 1];
+      STORE( &mach->LoopCounterStack[mach->LoopCounterStackTop].xyzw[CHAN_Y], 0, CHAN_X );
+      /* Restore ContMask, but don't pop */
+      assert(mach->ContStackTop > 0);
+      mach->ContMask = mach->ContStack[mach->ContStackTop - 1];
+      UPDATE_EXEC_MASK(mach);
+      if (mach->ExecMask) {
+         /* repeat loop: jump to instruction just past BGNLOOP */
+         assert(mach->LoopLabelStackTop > 0);
+         *pc = mach->LoopLabelStack[mach->LoopLabelStackTop - 1] + 1;
+      }
+      else {
+         /* exit loop: pop LoopMask */
+         assert(mach->LoopStackTop > 0);
+         mach->LoopMask = mach->LoopStack[--mach->LoopStackTop];
+         /* pop ContMask */
+         assert(mach->ContStackTop > 0);
+         mach->ContMask = mach->ContStack[--mach->ContStackTop];
+         assert(mach->LoopLabelStackTop > 0);
+         --mach->LoopLabelStackTop;
+         assert(mach->LoopCounterStackTop > 0);
+         --mach->LoopCounterStackTop;
+      }
+      UPDATE_EXEC_MASK(mach);
+      break;
+      
    case TGSI_OPCODE_ENDLOOP:
       /* Restore ContMask, but don't pop */
       assert(mach->ContStackTop > 0);
@@ -3122,7 +3173,8 @@ exec_instruction(
       UPDATE_EXEC_MASK(mach);
       if (mach->ExecMask) {
          /* repeat loop: jump to instruction just past BGNLOOP */
-         *pc = inst->InstructionExtLabel.Label + 1;
+         assert(mach->LoopLabelStackTop > 0);
+         *pc = mach->LoopLabelStack[mach->LoopLabelStackTop - 1] + 1;
       }
       else {
          /* exit loop: pop LoopMask */
@@ -3131,6 +3183,8 @@ exec_instruction(
          /* pop ContMask */
          assert(mach->ContStackTop > 0);
          mach->ContMask = mach->ContStack[--mach->ContStackTop];
+         assert(mach->LoopLabelStackTop > 0);
+         --mach->LoopLabelStackTop;
       }
       UPDATE_EXEC_MASK(mach);
       break;
@@ -3157,22 +3211,6 @@ exec_instruction(
       /* no-op */
       break;
 
-   case TGSI_OPCODE_NOISE1:
-      assert( 0 );
-      break;
-
-   case TGSI_OPCODE_NOISE2:
-      assert( 0 );
-      break;
-
-   case TGSI_OPCODE_NOISE3:
-      assert( 0 );
-      break;
-
-   case TGSI_OPCODE_NOISE4:
-      assert( 0 );
-      break;
-
    case TGSI_OPCODE_NOP:
       break;
 
@@ -3198,7 +3236,6 @@ tgsi_exec_machine_run( struct tgsi_exec_machine *mach )
    mach->FuncMask = 0xf;
    mach->ExecMask = 0xf;
 
-   mach->CondStackTop = 0; /* temporarily subvert this assertion */
    assert(mach->CondStackTop == 0);
    assert(mach->LoopStackTop == 0);
    assert(mach->ContStackTop == 0);