Add (largely untested) float/int conversion.
authorDavid Given <dg@cowlark.com>
Mon, 1 Jul 2013 12:05:36 +0000 (13:05 +0100)
committerDavid Given <dg@cowlark.com>
Mon, 1 Jul 2013 12:05:36 +0000 (13:05 +0100)
--HG--
branch : dtrg-videocore

mach/vc4/as/mach1.c
mach/vc4/as/mach2.c
mach/vc4/as/mach3.c
mach/vc4/as/mach4.c
mach/vc4/as/mach5.c
mach/vc4/ncg/table

index 315468f..44caf0c 100644 (file)
@@ -24,4 +24,5 @@ extern void branch_addcmp_lit_reg_instr(int cc, int rd, long va, int rs, struct
 extern void branch_addcmp_reg_lit_instr(int cc, int rd, int ra, long vs, struct expr_t* expr);
 extern void branch_addcmp_lit_lit_instr(int cc, int rd, long va, long vs, struct expr_t* expr);
 extern void lea_stack_instr(int rd, long va, int rs);
-extern void lea_address_instr(int rd, struct expr_t* expr);
\ No newline at end of file
+extern void lea_address_instr(int rd, struct expr_t* expr);
+extern void fltcnv_instr(quad opcode, int cc, int rd, int ra, quad shift);
index 4c02efb..ec7a948 100644 (file)
@@ -17,6 +17,7 @@
 %token <y_word> OP_MEM
 %token <y_word> OP_MISC
 %token <y_word> OP_MISCL
+%token <y_word> OP_FLTCNV
 %token <y_word> OP_STACK
 %token <y_word> OP_LEA
 
index 502894a..4ca73f4 100644 (file)
 0,     OP_MISC,               B16(11001001,11100000),                  "exp2",
 0,     OP_MISC,               B16(11000101,11100000),                  "adds256",
 
+0,     OP_FLTCNV,             B16(11001010,00000000),                  "ftrunc",
+0,     OP_FLTCNV,             B16(11001010,00100000),                  "floor",
+0,     OP_FLTCNV,             B16(11001010,01000000),                  "flts",
+0,     OP_FLTCNV,             B16(11001010,01100000),                  "fltu",
+
 0,     OP_MISCL,              B16(11000100,10000000),                  "divs",
 0,     OP_MISCL,              B16(11000100,11100000),                  "divu",
 
index ef0b500..99c368c 100644 (file)
@@ -74,5 +74,14 @@ operation
 
     | OP_LEA GPR ',' absexp '(' GPR ')'    { lea_stack_instr($2, $4, $6); }
        | OP_LEA GPR ',' expr                  { lea_address_instr($2, &$4); }
+
+       | OP_FLTCNV GPR ',' GPR                { fltcnv_instr($1, ALWAYS, $2, $4, 0); }
+       | OP_FLTCNV CC GPR ',' GPR             { fltcnv_instr($1, $2, $3, $5, 0); }
+       | OP_FLTCNV GPR ',' GPR ',' shift '#' absexp { fltcnv_instr($1, ALWAYS, $2, $4, $8); }
+       | OP_FLTCNV CC GPR ',' GPR ',' shift '#' absexp { fltcnv_instr($1, $2, $3, $5, $9); }
        ;
 
+shift
+       : 'l' 's' 'r'
+    | 'l' 's' 'l';
+
index 350806e..9166f34 100644 (file)
@@ -487,3 +487,13 @@ void lea_address_instr(int rd, struct expr_t* expr)
        emit4(expr->val - pc);
 }
 
+/* Floating point conversion opcodes (ftrunc, floor, flts, fltu). */
+
+void fltcnv_instr(quad opcode, int cc, int rd, int ra, quad shift)
+{
+       fitx(shift, 6);
+
+       emit2(opcode | (rd<<0));
+       emit2(B16(00000000,01000000) | (ra<<11) | (cc<<7) | shift);
+}
+
index 963fb74..8b4fe60 100644 (file)
@@ -131,8 +131,11 @@ INSTRUCTIONS
        fadd          GPR:wo, GPR:ro, GPR:ro.
        fcmp          GPR:wo, GPR:ro, GPR:ro.
        fdiv          GPR:wo, GPR:ro, GPR:ro.
+       flts          GPR:wo, GPR:ro.
+       fltu          GPR:wo, GPR:ro.
        fmul          GPR:wo, GPR:ro, GPR:ro.
        fsub          GPR:wo, GPR:ro, GPR:ro.
+       ftrunc        GPR:wo, GPR:ro.
        ld            GPR:wo, GPRINC:rw.
        ld            GPR:wo, GPROFFSET+GPRGPR+LABEL:ro.
        ldb           GPR:wo, GPROFFSET+GPRGPR+LABEL:ro.
@@ -1511,36 +1514,32 @@ PATTERNS
                        nop
                                         
        pat loc loc cfi $1==$2 && $1==QUAD /* Convert float -> integer */
-               leaving
-                       loc 0
-#if 0
-                       cal ".cfi"
-                       lfr QUAD
-#endif
+               with GPR
+                       uses reusing %1, REG
+                       gen
+                               ftrunc %a, %1
+                       yields %a
 
        pat loc loc cfu $1==$2 && $1==QUAD /* Convert float -> unsigned */
-               leaving
-                       loc 0
-#if 0
-                       cal ".cfu"
-                       lfr QUAD
-#endif
+               with GPR
+                       uses reusing %1, REG
+                       gen
+                               ftrunc %a, %1
+                       yields %a
 
        pat loc loc cif $1==$2 && $1==QUAD /* Convert integer -> float */
-               leaving
-                       loc 0
-#if 0
-                       cal ".cif"
-                       lfr QUAD
-#endif
+               with GPR
+                       uses reusing %1, REG
+                       gen
+                               flts %a, %1
+                       yields %a
 
        pat loc loc cuf $1==$2 && $1==QUAD /* Convert unsigned -> float */
-               leaving
-                       loc 0
-#if 0
-                       cal ".cuf"
-                       lfr QUAD
-#endif
+               with GPR
+                       uses reusing %1, REG
+                       gen
+                               fltu %a, %1
+                       yields %a
 
        pat fef                            /* Split float */
                leaving