Added some more preshader opcodes, cleaned up opcode handling elsewhere.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 30 May 2011 19:56:41 -0400
changeset 1032 464f38a2fb70
parent 1031 e6be730725d7
child 1033 b72073c4820e
Added some more preshader opcodes, cleaned up opcode handling elsewhere.
mojoshader.c
mojoshader.h
utils/testparse.c
--- a/mojoshader.c	Mon May 30 19:34:03 2011 -0400
+++ b/mojoshader.c	Mon May 30 19:56:41 2011 -0400
@@ -7269,18 +7269,25 @@
             case 0x1070: opcode = MOJOSHADER_PRESHADEROP_RSQ; break;
             case 0x1080: opcode = MOJOSHADER_PRESHADEROP_SIN; break;
             case 0x1090: opcode = MOJOSHADER_PRESHADEROP_COS; break;
+            case 0x10A0: opcode = MOJOSHADER_PRESHADEROP_ASIN; break;
+            case 0x10B0: opcode = MOJOSHADER_PRESHADEROP_ACOS; break;
+            case 0x10C0: opcode = MOJOSHADER_PRESHADEROP_ATAN; break;
+            case 0x2000: opcode = MOJOSHADER_PRESHADEROP_MIN; break;
             case 0x2010: opcode = MOJOSHADER_PRESHADEROP_MAX; break;
             case 0x2020: opcode = MOJOSHADER_PRESHADEROP_CMPLT; break;
             case 0x2030: opcode = MOJOSHADER_PRESHADEROP_CMPGE; break;
             case 0x2040: opcode = MOJOSHADER_PRESHADEROP_ADD; break;
             case 0x2050: opcode = MOJOSHADER_PRESHADEROP_MUL; break;
+            case 0x2060: opcode = MOJOSHADER_PRESHADEROP_ATAN2; break;
             case 0x3000: opcode = MOJOSHADER_PRESHADEROP_CMP; break;
             case 0x5000: opcode = MOJOSHADER_PRESHADEROP_DOT; break;
+            case 0xA000: opcode = MOJOSHADER_PRESHADEROP_MIN_SCALAR; break;
             case 0xA010: opcode = MOJOSHADER_PRESHADEROP_MAX_SCALAR; break;
             case 0xA020: opcode = MOJOSHADER_PRESHADEROP_CMPLT_SCALAR; break;
             case 0xA030: opcode = MOJOSHADER_PRESHADEROP_CMPGE_SCALAR; break;
             case 0xA040: opcode = MOJOSHADER_PRESHADEROP_ADD_SCALAR; break;
             case 0xA050: opcode = MOJOSHADER_PRESHADEROP_MUL_SCALAR; break;
+            case 0xA060: opcode = MOJOSHADER_PRESHADEROP_ATAN2_SCALAR; break;
             case 0xD000: opcode = MOJOSHADER_PRESHADEROP_DOT_SCALAR; break;
             default: fail(ctx, "Unknown preshader opcode."); break;
         } // switch
--- a/mojoshader.h	Mon May 30 19:34:03 2011 -0400
+++ b/mojoshader.h	Mon May 30 19:56:41 2011 -0400
@@ -359,27 +359,35 @@
 {
     MOJOSHADER_PRESHADEROP_NOP,
     MOJOSHADER_PRESHADEROP_MOV,
-    MOJOSHADER_PRESHADEROP_CMP,
-    MOJOSHADER_PRESHADEROP_DOT,
-    MOJOSHADER_PRESHADEROP_DOT_SCALAR,
     MOJOSHADER_PRESHADEROP_NEG,
-    MOJOSHADER_PRESHADEROP_MAX,
-    MOJOSHADER_PRESHADEROP_MAX_SCALAR,
-    MOJOSHADER_PRESHADEROP_CMPLT,
-    MOJOSHADER_PRESHADEROP_CMPLT_SCALAR,
-    MOJOSHADER_PRESHADEROP_CMPGE,
-    MOJOSHADER_PRESHADEROP_CMPGE_SCALAR,
     MOJOSHADER_PRESHADEROP_RCP,
     MOJOSHADER_PRESHADEROP_FRC,
     MOJOSHADER_PRESHADEROP_EXP,
-    MOJOSHADER_PRESHADEROP_ADD,
-    MOJOSHADER_PRESHADEROP_ADD_SCALAR,
-    MOJOSHADER_PRESHADEROP_MUL,
-    MOJOSHADER_PRESHADEROP_MUL_SCALAR,
     MOJOSHADER_PRESHADEROP_LOG,
     MOJOSHADER_PRESHADEROP_RSQ,
     MOJOSHADER_PRESHADEROP_SIN,
     MOJOSHADER_PRESHADEROP_COS,
+    MOJOSHADER_PRESHADEROP_ASIN,
+    MOJOSHADER_PRESHADEROP_ACOS,
+    MOJOSHADER_PRESHADEROP_ATAN,
+    MOJOSHADER_PRESHADEROP_MIN,
+    MOJOSHADER_PRESHADEROP_MAX,
+    MOJOSHADER_PRESHADEROP_CMPLT,
+    MOJOSHADER_PRESHADEROP_CMPGE,
+    MOJOSHADER_PRESHADEROP_ADD,
+    MOJOSHADER_PRESHADEROP_MUL,
+    MOJOSHADER_PRESHADEROP_ATAN2,
+    MOJOSHADER_PRESHADEROP_CMP,
+    MOJOSHADER_PRESHADEROP_DOT,
+    MOJOSHADER_PRESHADEROP_SCALAR_OPS,
+    MOJOSHADER_PRESHADEROP_MIN_SCALAR = MOJOSHADER_PRESHADEROP_SCALAR_OPS,
+    MOJOSHADER_PRESHADEROP_MAX_SCALAR,
+    MOJOSHADER_PRESHADEROP_CMPLT_SCALAR,
+    MOJOSHADER_PRESHADEROP_CMPGE_SCALAR,
+    MOJOSHADER_PRESHADEROP_ADD_SCALAR,
+    MOJOSHADER_PRESHADEROP_MUL_SCALAR,
+    MOJOSHADER_PRESHADEROP_ATAN2_SCALAR,
+    MOJOSHADER_PRESHADEROP_DOT_SCALAR,
 } MOJOSHADER_preshaderOpcode;
 
 typedef enum MOJOSHADER_preshaderOperandType
--- a/utils/testparse.c	Mon May 30 19:34:03 2011 -0400
+++ b/utils/testparse.c	Mon May 30 19:56:41 2011 -0400
@@ -114,9 +114,10 @@
     int i, j, k;
 
     static const char *opcodestr[] = {
-        "nop", "mov", "cmp", "dot", "dot", "neg", "max", "max",
-        "cmplt", "cmplt", "cmpge", "cmpge", "rcp", "frc", "exp",
-        "add", "add", "mul", "mul", "log", "rsq", "sin", "cos"
+        "nop", "mov", "neg", "rcp", "frc", "exp", "log", "rsq", "sin", "cos",
+        "asin", "acos", "atan", "min", "max", "cmplt", "cmpge", "add", "mul",
+        "atan2", "cmp", "dot", "min", "max", "cmplt", "cmpge", "add", "mul",
+        "atan2", "dot"
     };
 
     static char mask[] = { 'x', 'y', 'z', 'w' };
@@ -125,28 +126,15 @@
     for (i = 0; i < preshader->instruction_count; i++, inst++)
     {
         const MOJOSHADER_preshaderOperand *operand = inst->operands;
+        const int scalarstart = (int) MOJOSHADER_PRESHADEROP_SCALAR_OPS;
+        const int isscalarop = (inst->opcode >= scalarstart);
 
-        INDENT();
-        printf("    %s", opcodestr[inst->opcode]);
+        INDENT(); printf("    %s", opcodestr[inst->opcode]);
+
         for (j = 0; j < inst->operand_count; j++, operand++)
         {
             const int elems = inst->element_count;
-            int isscalar = 0;
-            if (j == 1)  // This is probably wrong.
-            {
-                switch (inst->opcode)
-                {
-                    case MOJOSHADER_PRESHADEROP_DOT_SCALAR:
-                    case MOJOSHADER_PRESHADEROP_MAX_SCALAR:
-                    case MOJOSHADER_PRESHADEROP_CMPLT_SCALAR:
-                    case MOJOSHADER_PRESHADEROP_CMPGE_SCALAR:
-                    case MOJOSHADER_PRESHADEROP_ADD_SCALAR:
-                    case MOJOSHADER_PRESHADEROP_MUL_SCALAR:
-                        isscalar = 1; break;
-                    default:
-                        isscalar = 0; break;
-                } // switch
-            } // if
+            const int isscalar = ((isscalarop) && (j == 1)); // probably wrong.
 
             if (j != 0)
                 printf(",");