put register classes into arch_env struct, no need for complicated callbacks
[libfirm] / ir / be / sparc / sparc_spec.pl
index fae0740..484cf02 100644 (file)
@@ -114,22 +114,10 @@ $state       = 32; # register represents a state
 %emit_templates = (
 # emit source reg or imm dep. on node's arity
        RI  => "${arch}_emit_reg_or_imm(node, -1);",
-       R1I => "${arch}_emit_reg_or_imm(node, 0);",
-       R2I => "${arch}_emit_reg_or_imm(node, 1);",
-       R3I => "${arch}_emit_reg_or_imm(node, 2);",
-       S1  => "${arch}_emit_source_register(node, 0);",
-       S2  => "${arch}_emit_source_register(node, 1);",
-       S3  => "${arch}_emit_source_register(node, 2);",
-       S4  => "${arch}_emit_source_register(node, 3);",
-       S5  => "${arch}_emit_source_register(node, 4);",
-       S6  => "${arch}_emit_source_register(node, 5);",
-       D1  => "${arch}_emit_dest_register(node, 0);",
-       D2  => "${arch}_emit_dest_register(node, 1);",
-       D3  => "${arch}_emit_dest_register(node, 2);",
-       D4  => "${arch}_emit_dest_register(node, 3);",
-       D5  => "${arch}_emit_dest_register(node, 4);",
-       D6  => "${arch}_emit_dest_register(node, 5);",
-       IM  => "${arch}_emit_immediate(node);",
+       R1I => "${arch}_emit_reg_or_imm(node, 1);",
+       S0  => "${arch}_emit_source_register(node, 0);",
+       S1  => "${arch}_emit_source_register(node, 1);",
+       D0  => "${arch}_emit_dest_register(node, 0);",
        HIM => "${arch}_emit_high_immediate(node);",
        LM  => "${arch}_emit_load_mode(node);",
        SM  => "${arch}_emit_store_mode(node);",
@@ -137,8 +125,8 @@ $state       = 32; # register represents a state
        FPM  => "${arch}_emit_fp_mode_suffix(node);",
        FCONVS => "${arch}_emit_fp_conv_source(node);",
        FCONVD => "${arch}_emit_fp_conv_destination(node);",
-       O2     => "${arch}_emit_offset(node, 1);",
-       O3     => "${arch}_emit_offset(node, 2);",
+       O1     => "${arch}_emit_offset(node, 1);",
+       O2     => "${arch}_emit_offset(node, 2);",
 );
 
 $default_attr_type = "sparc_attr_t";
@@ -202,6 +190,19 @@ my %binop_operand_constructors = (
        },
 );
 
+my %binopcczero_operand_constructors = (
+       imm => {
+               attr       => "ir_entity *immediate_entity, int32_t immediate_value",
+               custominit => "sparc_set_attr_imm(res, immediate_entity, immediate_value);",
+               reg_req    => { in => [ "gp" ], out => [ "flags" ] },
+               ins        => [ "left" ],
+       },
+       reg => {
+               reg_req    => { in => [ "gp", "gp" ], out => [ "flags" ] },
+               ins        => [ "left", "right" ],
+       },
+);
+
 my %div_operand_constructors = (
        imm => {
                attr       => "ir_entity *immediate_entity, int32_t immediate_value",
@@ -248,14 +249,14 @@ my %float_unop_constructors = (
 Add => {
        irn_flags    => [ "rematerializable" ],
        mode         => $mode_gp,
-       emit         => '. add %S1, %R2I, %D1',
+       emit         => '. add %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
 Sub => {
        irn_flags    => [ "rematerializable" ],
        mode         => $mode_gp,
-       emit         => '. sub %S1, %R2I, %D1',
+       emit         => '. sub %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
@@ -281,7 +282,7 @@ Ld => {
        ins       => [ "ptr", "mem" ],
        outs      => [ "res", "M" ],
        attr_type => "sparc_load_store_attr_t",
-       emit      => '. ld%LM [%S1%O2], %D1'
+       emit      => '. ld%LM [%S0%O1], %D0'
 },
 
 SetHi => {
@@ -291,7 +292,7 @@ SetHi => {
        reg_req    => { in => [], out => [ "gp" ] },
        attr       => "ir_entity *entity, int32_t immediate_value",
        custominit => "sparc_set_attr_imm(res, entity, immediate_value);",
-       emit       => '. sethi %HIM, %D1'
+       emit       => '. sethi %HIM, %D0'
 },
 
 St => {
@@ -315,7 +316,7 @@ St => {
        ins       => [ "val", "ptr", "mem" ],
        outs      => [ "M" ],
        attr_type => "sparc_load_store_attr_t",
-       emit      => '. st%SM %S1, [%S2%O3]'
+       emit      => '. st%SM %S0, [%S1%O2]'
 },
 
 Save => {
@@ -334,14 +335,14 @@ SubSP => {
        reg_req   => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "gp", "none" ] },
        ins       => [ "stack", "size", "mem" ],
        outs      => [ "stack", "addr", "M" ],
-       emit      => ". sub %S1, %S2, %D1\n",
+       emit      => ". sub %S0, %S1, %D0\n",
 },
 
 AddSP => {
        reg_req   => { in => [ "sp", "gp", "none" ], out => [ "sp:I|S", "none" ] },
        ins       => [ "stack", "size", "mem" ],
        outs      => [ "stack", "M" ],
-       emit      => ". add %S1, %S2, %D1\n",
+       emit      => ". add %S0, %S1, %D0\n",
 },
 
 FrameAddr => {
@@ -402,20 +403,11 @@ Call => {
        },
 },
 
-Cmp => {
+Cmp => {  # aka SubccZero
        irn_flags    => [ "rematerializable", "modifies_flags" ],
-       emit         => '. cmp %S1, %R2I',
-       ins          => [ "left", "right" ],
+       emit         => '. cmp %S0, %R1I',
        mode         => $mode_flags,
-       constructors => \%cmp_operand_constructors,
-},
-
-Tst => {
-       irn_flags    => [ "rematerializable", "modifies_flags" ],
-       emit         => '. tst %S1',
-       mode         => $mode_flags,
-       reg_req      => { in => [ "gp" ], out => [ "flags" ] },
-       ins          => [ "val" ],
+       constructors => \%binopcczero_operand_constructors,
 },
 
 SwitchJmp => {
@@ -431,70 +423,112 @@ SwitchJmp => {
 Sll => {
        irn_flags    => [ "rematerializable" ],
        mode         => $mode_gp,
-       emit         => '. sll %S1, %R2I, %D1',
+       emit         => '. sll %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
-Slr => {
+Srl => {
        irn_flags    => [ "rematerializable" ],
        mode         => $mode_gp,
-       emit         => '. srl %S1, %R2I, %D1',
+       emit         => '. srl %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
 Sra => {
        irn_flags    => [ "rematerializable" ],
        mode         => $mode_gp,
-       emit         => '. sra %S1, %R2I, %D1',
+       emit         => '. sra %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
 And => {
        irn_flags    => [ "rematerializable" ],
        mode         => $mode_gp,
-       emit         => '. and %S1, %R2I, %D1',
+       emit         => '. and %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
+AndCCZero => {
+       irn_flags    => [ "rematerializable", "modifies_flags" ],
+       emit         => '. andcc %S0, %R1I, %%g0',
+       mode         => $mode_flags,
+       constructors => \%binopcczero_operand_constructors,
+},
+
 AndN => {
        irn_flags => [ "rematerializable" ],
        mode      => $mode_gp,
-       emit      => '. andn %S1, %R2I, %D1',
+       emit      => '. andn %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
+AndNCCZero => {
+       irn_flags    => [ "rematerializable", "modifies_flags" ],
+       emit         => '. andncc %S0, %R1I, %%g0',
+       mode         => $mode_flags,
+       constructors => \%binopcczero_operand_constructors,
+},
+
 Or => {
        irn_flags    => [ "rematerializable" ],
        mode         => $mode_gp,
-       emit         => '. or %S1, %R2I, %D1',
+       emit         => '. or %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
+OrCCZero => {
+       irn_flags    => [ "rematerializable", "modifies_flags" ],
+       emit         => '. orcc %S0, %R1I, %%g0',
+       mode         => $mode_flags,
+       constructors => \%binopcczero_operand_constructors,
+},
+
 OrN => {
        irn_flags => [ "rematerializable" ],
        mode      => $mode_gp,
-       emit      => '. orn %S1, %R2I, %D1',
+       emit      => '. orn %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
+OrNCCZero => {
+       irn_flags    => [ "rematerializable", "modifies_flags" ],
+       emit         => '. orncc %S0, %R1I, %%g0',
+       mode         => $mode_flags,
+       constructors => \%binopcczero_operand_constructors,
+},
+
 Xor => {
        irn_flags    => [ "rematerializable" ],
        mode         => $mode_gp,
-       emit         => '. xor %S1, %R2I, %D1',
+       emit         => '. xor %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
+XorCCZero => {
+       irn_flags    => [ "rematerializable", "modifies_flags" ],
+       emit         => '. xorcc %S0, %R1I, %%g0',
+       mode         => $mode_flags,
+       constructors => \%binopcczero_operand_constructors,
+},
+
 XNor => {
        irn_flags => [ "rematerializable" ],
        mode      => $mode_gp,
-       emit      => '. xnor %S1, %R2I, %D1',
+       emit      => '. xnor %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
+XNorCCZero => {
+       irn_flags    => [ "rematerializable", "modifies_flags" ],
+       emit         => '. xnorcc %S0, %R1I, %%g0',
+       mode         => $mode_flags,
+       constructors => \%binopcczero_operand_constructors,
+},
+
 Mul => {
        irn_flags    => [ "rematerializable" ],
        mode         => $mode_gp,
-       emit         => '. smul %S1, %R2I, %D1',
+       emit         => '. smul %S0, %R1I, %D0',
        constructors => \%binop_operand_constructors,
 },
 
@@ -522,7 +556,7 @@ UDiv => {
 
 fcmp => {
        irn_flags => [ "rematerializable", "modifies_fp_flags" ],
-       emit      => '. fcmp%FPM %S1, %S2',
+       emit      => '. fcmp%FPM %S0, %S1',
        attr_type => "sparc_fp_attr_t",
        attr      => "ir_mode *fp_mode",
        mode      => $mode_fpflags,
@@ -542,7 +576,7 @@ fcmp => {
 fadd => {
        op_flags     => [ "commutative" ],
        irn_flags    => [ "rematerializable" ],
-       emit         => '. fadd%FPM %S1, %S2, %D1',
+       emit         => '. fadd%FPM %S0, %S1, %D0',
        attr_type    => "sparc_fp_attr_t",
        attr         => "ir_mode *fp_mode",
        ins          => [ "left", "right" ],
@@ -551,7 +585,7 @@ fadd => {
 
 fsub => {
        irn_flags    => [ "rematerializable" ],
-       emit         => '. fsub%FPM %S1, %S2, %D1',
+       emit         => '. fsub%FPM %S0, %S1, %D0',
        attr_type    => "sparc_fp_attr_t",
        attr         => "ir_mode *fp_mode",
        ins          => [ "left", "right" ],
@@ -561,7 +595,7 @@ fsub => {
 fmul => {
        irn_flags    => [ "rematerializable" ],
        op_flags     => [ "commutative" ],
-       emit         =>'. fmul%FPM %S1, %S2, %D1',
+       emit         =>'. fmul%FPM %S0, %S1, %D0',
        attr_type    => "sparc_fp_attr_t",
        attr         => "ir_mode *fp_mode",
        ins          => [ "left", "right" ],
@@ -570,19 +604,29 @@ fmul => {
 
 fdiv => {
        irn_flags    => [ "rematerializable" ],
-       emit         => '. fdiv%FPM %S1, %S2, %D1',
+       emit         => '. fdiv%FPM %S0, %S1, %D0',
        attr_type    => "sparc_fp_attr_t",
        attr         => "ir_mode *fp_mode",
        ins          => [ "left", "right" ],
        outs         => [ "res", "M" ],
-       constructors => \%float_binop_constructors,
+       constructors => {
+               s => {
+                       reg_req => { in => [ "fp", "fp" ], out => [ "fp", "none" ] },
+               },
+               d => {
+                       reg_req => { in => [ "fp:a|2", "fp:a|2" ], out => [ "fp:a|2", "none" ] },
+               },
+               q => {
+                       reg_req => { in => [ "fp:a|4", "fp:a|4" ], out => [ "fp:a|4", "none" ] },
+               }
+       },
 },
 
 fneg => {
        irn_flags => [ "rematerializable" ],
        reg_req   => { in => [ "fp" ], out => [ "fp" ] },
        # note that we only need the first register even for wide-values
-       emit      => '. fneg %S1, %D1',
+       emit      => '. fneg %S0, %D0',
        attr_type => "sparc_fp_attr_t",
        attr      => "ir_mode *fp_mode",
        ins          => [ "val" ],
@@ -592,7 +636,7 @@ fneg => {
 "fabs" => {
        irn_flags    => [ "rematerializable" ],
        # note that we only need the first register even for wide-values
-       emit         => '. fabs %S1, %D1',
+       emit         => '. fabs %S0, %D0',
        attr_type    => "sparc_fp_attr_t",
        attr         => "ir_mode *fp_mode",
        ins          => [ "val" ],
@@ -601,7 +645,7 @@ fneg => {
 
 fftof => {
        irn_flags => [ "rematerializable" ],
-       emit      => '. f%FCONVS%.to%FCONVD %S1, %D1',
+       emit      => '. f%FCONVS%.to%FCONVD %S0, %D0',
        attr_type => "sparc_fp_conv_attr_t",
        attr      => "ir_mode *src_mode, ir_mode *dest_mode",
        constructors => {
@@ -634,21 +678,20 @@ fftof => {
 
 fitof => {
        irn_flags => [ "rematerializable" ],
-       reg_req   => { in => [ "gp" ], out => [ "fp" ] },
-       emit      => '. fito%FPM %S1, %D1',
+       emit      => '. fito%FPM %S0, %D0',
        attr_type => "sparc_fp_attr_t",
        attr      => "ir_mode *fp_mode",
        constructors => {
                s => {
-                       reg_req => { in => [ "gp" ], out => [ "fp" ] },
+                       reg_req => { in => [ "fp" ], out => [ "fp" ] },
                        mode    => $mode_fp,
                },
                d => {
-                       reg_req => { in => [ "gp" ], out => [ "fp:a|2" ] },
+                       reg_req => { in => [ "fp" ], out => [ "fp:a|2" ] },
                        mode    => $mode_fp2,
                },
                q => {
-                       reg_req => { in => [ "gp" ], out => [ "fp:a|4" ] },
+                       reg_req => { in => [ "fp" ], out => [ "fp:a|4" ] },
                        mode    => $mode_fp4,
                },
        },
@@ -656,20 +699,19 @@ fitof => {
 
 fftoi => {
        irn_flags => [ "rematerializable" ],
-       reg_req   => { in => [ "fp" ], out => [ "gp" ] },
-       emit      => '. f%FPM.toi %S1, %D1',
+       emit      => '. f%FPM%.toi %S0, %D0',
        attr_type => "sparc_fp_attr_t",
        attr      => "ir_mode *fp_mode",
        mode      => $mode_gp,
        constructors => {
                s => {
-                       reg_req => { in => [ "gp" ], out => [ "gp" ] },
+                       reg_req => { in => [ "fp" ], out => [ "fp" ] },
                },
                d => {
-                       reg_req => { in => [ "fp:a|2" ], out => [ "gp" ] },
+                       reg_req => { in => [ "fp:a|2" ], out => [ "fp" ] },
                },
                q => {
-                       reg_req => { in => [ "fp:a|4" ], out => [ "gp" ] },
+                       reg_req => { in => [ "fp:a|4" ], out => [ "fp" ] },
                },
        },
 },
@@ -693,7 +735,7 @@ Ldf => {
        attr_type => "sparc_load_store_attr_t",
        attr      => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
        custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
-       emit      => '. ld%FLSM [%S1%O2], %D1'
+       emit      => '. ld%FLSM [%S0%O1], %D0'
 },
 
 Stf => {
@@ -715,7 +757,7 @@ Stf => {
        attr_type => "sparc_load_store_attr_t",
        attr      => "ir_mode *ls_mode, ir_entity *entity, int32_t offset, bool is_frame_entity",
        custominit => "init_sparc_load_store_attributes(res, ls_mode, entity, offset, is_frame_entity, false);",
-       emit      => '. st%FLSM %S2, [%S1%O2]',
+       emit      => '. st%FLSM %S0, [%S1%O2]',
        mode      => 'mode_M',
 },