first implementation of floatingpoint arithmetic operations
[libfirm] / ir / be / sparc / sparc_spec.pl
index fb97f01..4e2da4d 100644 (file)
@@ -54,7 +54,7 @@ $state       = 32; # register represents a state
                { name => "i3", realname => "i3", type => 0 }, # param 4
                { name => "i4", realname => "i4", type => 0 }, # param 5
                { name => "i5", realname => "i5", type => 0 }, # param 6
-               { name => "fp", realname => "fp", type => $ignore }, # our framepointer
+               { name => "frame_pointer", realname => "fp", type => $ignore }, # our framepointer
                { name => "i7", realname => "i7", type => $ignore }, # return address - 8
                { mode => $mode_gp }
        ],
@@ -63,7 +63,7 @@ $state       = 32; # register represents a state
                { mode => $mode_flags, flags => "manual_ra" }
        ],
        # fp registers can be accessed any time
-       fp  => [
+       fp => [
                { name => "f0",  type => $caller_save },
                { name => "f1",  type => $caller_save },
                { name => "f2",  type => $caller_save },
@@ -102,32 +102,29 @@ $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);",
+       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);",
-# simple reg emitters
-       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);",
-# more custom emitters
-       C  => "${arch}_emit_immediate(node);",
+       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);",
        LM  => "${arch}_emit_load_mode(node);",
        SM  => "${arch}_emit_store_mode(node);",
-       EXTPREF  => "${arch}_emit_mode_sign_prefix(node);",
        FPM  => "${arch}_emit_fp_mode_suffix(node);",
-       FPLM  => "${arch}_emit_fp_load_mode(node);",
-       FPSM  => "${arch}_emit_fp_store_mode(node);",
-       O  => "${arch}_emit_offset(node);",
+       FCONVS => "${arch}_emit_fp_conv_source(node);",
+       FCONVD => "${arch}_emit_fp_conv_destination(node);",
+       O      => "${arch}_emit_offset(node);",
 );
 
 $default_attr_type = "sparc_attr_t";
@@ -143,7 +140,10 @@ $default_copy_attr = "sparc_copy_attr";
        sparc_jmp_cond_attr_t    => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
        sparc_jmp_switch_attr_t  => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
        sparc_save_attr_t        => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);",
-
+       sparc_fp_attr_t          => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);\n".
+                                   "\tinit_sparc_fp_attributes(res, fp_mode);\n",
+       sparc_fp_conv_attr_t     => "\tinit_sparc_attributes(res, flags, in_reqs, exec_units, n_res);".
+                                   "\tinit_sparc_fp_conv_attributes(res, src_mode, dest_mode);\n",
 );
 
 %compare_attr = (
@@ -153,6 +153,8 @@ $default_copy_attr = "sparc_copy_attr";
        sparc_jmp_cond_attr_t   => "cmp_attr_sparc_jmp_cond",
        sparc_jmp_switch_attr_t => "cmp_attr_sparc_jmp_switch",
        sparc_save_attr_t       => "cmp_attr_sparc_save",
+       sparc_fp_attr_t         => "cmp_attr_sparc_fp",
+       sparc_fp_conv_attr_t    => "cmp_attr_sparc_fp_conv",
 );
 
 # addressing modes: imm, reg, reg +/- imm, reg + reg
@@ -251,7 +253,7 @@ St => {
        mode            => "mode_M",
        state     => "exc_pinned",
        ins       => [ "ptr", "val", "mem" ],
-       outs      => [ "mem" ],
+       outs      => [ "M" ],
        reg_req   => { in => [ "gp", "gp", "none" ], out => [ "none" ] },
        attr_type => "sparc_load_store_attr_t",
        attr      => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
@@ -269,13 +271,13 @@ Mov => {
 Save => {
        reg_req   => {
                in => [ "sp", "none"],
-               out => [ "sp:I|S","none" ]
+               out => [ "sp:I|S", "frame_pointer:I", "none" ]
        },
        ins       => [ "stack", "mem" ],
-       outs      => [ "stack", "mem" ],
+       outs      => [ "stack", "frame", "mem" ],
        attr      => "int initial_stacksize",
        attr_type => "sparc_save_attr_t",
-       init_attr => "\tinit_sparc_save_attr(res, initial_stacksize);",
+       init_attr => "\tinit_sparc_save_attributes(res, initial_stacksize);",
 },
 
 SubSP => {
@@ -329,6 +331,25 @@ Ba => {
        mode      => "mode_X",
 },
 
+Call => {
+       irn_flags => [ "modify_flags" ],
+       state     => "exc_pinned",
+       arity     => "variable",
+       out_arity => "variable",
+       constructors => {
+               imm => {
+                       attr       => "ir_entity *entity, long offset",
+                       custominit => "get_sparc_attr(res)->immediate_value_entity = entity;",
+                       arity     => "variable",
+                       out_arity => "variable",
+               },
+               reg => {
+                       arity     => "variable",
+                       out_arity => "variable",
+               }
+       },
+},
+
 Cmp => {
        irn_flags    => [ "rematerializable", "modify_flags" ],
        emit         => '. cmp %S1, %R2I',
@@ -357,7 +378,7 @@ SwitchJmp => {
 
 Sll => {
        irn_flags => [ "rematerializable" ],
-       mode            => $mode_gp,
+       mode      => $mode_gp,
        reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
        emit      => '. sll %S1, %R2I, %D1',
        constructors => \%binop_operand_constructors,
@@ -365,7 +386,7 @@ Sll => {
 
 Slr => {
        irn_flags => [ "rematerializable" ],
-       mode            => $mode_gp,
+       mode      => $mode_gp,
        reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
        emit      => '. srl %S1, %R2I, %D1',
        constructors => \%binop_operand_constructors,
@@ -373,7 +394,7 @@ Slr => {
 
 Sra => {
        irn_flags => [ "rematerializable" ],
-       mode            => $mode_gp,
+       mode      => $mode_gp,
        reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
        emit      => '. sra %S1, %R2I, %D1',
        constructors => \%binop_operand_constructors,
@@ -381,7 +402,7 @@ Sra => {
 
 And => {
        irn_flags => [ "rematerializable" ],
-       mode            => $mode_gp,
+       mode      => $mode_gp,
        reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
        emit      => '. and %S1, %R2I, %D1',
        constructors => \%binop_operand_constructors,
@@ -389,7 +410,7 @@ And => {
 
 Or => {
        irn_flags => [ "rematerializable" ],
-       mode            => $mode_gp,
+       mode      => $mode_gp,
        reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
        emit      => '. or %S1, %R2I, %D1',
        constructors => \%binop_operand_constructors,
@@ -397,22 +418,20 @@ Or => {
 
 Xor => {
        irn_flags => [ "rematerializable" ],
-       mode            => $mode_gp,
+       mode      => $mode_gp,
        reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
        emit      => '. xor %S1, %R2I, %D1',
        constructors => \%binop_operand_constructors,
 },
 
 Mul => {
-       state     => "exc_pinned",
-       reg_req   => { in => [ "gp", "gp" ], out => [ "gp", "flags" ] },
-       outs      => [ "low", "high" ],
+       reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
        constructors => \%binop_operand_constructors,
-       #emit      =>'. mul %S1, %R2I, %D1'
+       emit      => '. mul %S1, %R2I, %D1',
+       mode      => $mode_gp,
 },
 
 Mulh => {
-       state     => "exc_pinned",
        reg_req   => { in => [ "gp", "gp" ], out => [ "gp", "gp" ] },
        outs      => [ "low", "high" ],
        constructors => \%binop_operand_constructors,
@@ -421,25 +440,24 @@ Mulh => {
 Div => {
        irn_flags => [ "rematerializable" ],
        state     => "exc_pinned",
-       reg_req   => { in => [ "gp", "gp" ], out => [ "gp" ] },
-       outs      => [ "res" ],
+       reg_req   => { in => [ "gp", "gp" ], out => [ "gp", "none" ] },
+       outs      => [ "res", "M" ],
        constructors => \%binop_operand_constructors,
-       #mode      => $mode_gp,
-       #emit      =>'. div %S1, %R2I, %D1'
+       emit      => '. div %S1, %R2I, %D1',
 },
 
 Minus => {
        irn_flags => [ "rematerializable" ],
-       mode        => $mode_gp,
+       mode      => $mode_gp,
        reg_req   => { in => [ "gp" ], out => [ "gp" ] },
        emit      => ". sub %%g0, %S1, %D1"
 },
 
 Not => {
-       irn_flags   => [ "rematerializable" ],
-       mode          => $mode_gp,
-       reg_req     => { in => [ "gp" ], out => [ "gp" ] },
-       emit        => '. xnor %S1, %%g0, %D1'
+       irn_flags => [ "rematerializable" ],
+       mode      => $mode_gp,
+       reg_req   => { in => [ "gp" ], out => [ "gp" ] },
+       emit      => '. xnor %S1, %%g0, %D1'
 },
 
 Nop => {
@@ -448,59 +466,110 @@ Nop => {
        emit     => '. nop',
 },
 
-fAdd => {
+fadd => {
        op_flags  => [ "commutative" ],
        irn_flags => [ "rematerializable" ],
        reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
-       emit      => '. fadd%FPM %S1, %S2, %D1'
+       emit      => '. fadd%FPM %S1, %S2, %D1',
+       attr_type => "sparc_fp_attr_t",
+       attr      => "ir_mode *fp_mode",
+       mode      => $mode_fp,
 },
 
-fMul => {
-       op_flags  => [ "commutative" ],
+fsub => {
+       irn_flags => [ "rematerializable" ],
        reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
-       emit      =>'. fmul%FPM %S1, %S2, %D1'
+       emit      => '. fsub%FPM %S1, %S2, %D1',
+       attr_type => "sparc_fp_attr_t",
+       attr      => "ir_mode *fp_mode",
+       mode      => $mode_fp,
 },
 
-fsMuld => {
+fmul => {
+       irn_flags => [ "rematerializable" ],
        op_flags  => [ "commutative" ],
        reg_req   => { in => [ "fp", "fp" ], out => [ "fp" ] },
-       emit      =>'. fsmuld %S1, %S2, %D1'
+       emit      =>'. fmul%FPM %S1, %S2, %D1',
+       attr_type => "sparc_fp_attr_t",
+       attr      => "ir_mode *fp_mode",
+       mode      => $mode_fp,
+},
+
+fdiv => {
+       irn_flags => [ "rematerializable" ],
+       reg_req   => { in => [ "fp", "fp" ], out => [ "fp", "none" ] },
+       emit      => '. fdiv%FPM %S1, %S2, %D1',
+       attr_type => "sparc_fp_attr_t",
+       attr      => "ir_mode *fp_mode",
+       outs      => [ "res", "M" ],
 },
 
-FsTOd => {
+fneg => {
        irn_flags => [ "rematerializable" ],
        reg_req   => { in => [ "fp" ], out => [ "fp" ] },
-       emit      =>'. FsTOd %S1, %D1'
+       emit      => '. fneg%FPM %S1, %D1',
+       attr_type => "sparc_fp_attr_t",
+       attr      => "ir_mode *fp_mode",
+       mode      => $mode_fp,
 },
 
-FdTOs => {
+"fabs" => {
        irn_flags => [ "rematerializable" ],
        reg_req   => { in => [ "fp" ], out => [ "fp" ] },
-       emit      =>'. FdTOs %S1, %D1'
+       emit      => '. fabs%FPM %S1, %D1',
+       attr_type => "sparc_fp_attr_t",
+       attr      => "ir_mode *fp_mode",
+       mode      => $mode_fp,
 },
 
-FiTOs => {
+fftof => {
        irn_flags => [ "rematerializable" ],
-       reg_req   => { in => [ "gp" ], out => [ "fp" ] },
-       emit      =>'. FiTOs %S1, %D1'
+       reg_req   => { in => [ "fp" ], out => [ "fp" ] },
+       emit      => '. f%FCONVS.to%FCONVD %S1, %D1',
+       attr_type => "sparc_fp_conv_attr_t",
+       attr      => "ir_mode *src_mode, ir_mode *dest_mode",
+       mode      => $mode_fp,
 },
 
-FiTOd => {
+fitof => {
        irn_flags => [ "rematerializable" ],
        reg_req   => { in => [ "gp" ], out => [ "fp" ] },
-       emit      =>'. FiTOd %S1, %D1'
+       emit      => '. fito%FPM %S1, %D1',
+       attr_type => "sparc_fp_attr_t",
+       attr      => "ir_mode *fp_mode",
+       mode      => $mode_fp,
 },
 
-FsTOi => {
+fftoi => {
        irn_flags => [ "rematerializable" ],
        reg_req   => { in => [ "fp" ], out => [ "gp" ] },
-       emit      =>'. FsTOi %S1, %D1'
+       emit      => '. f%FPM.toi %S1, %D1',
+       attr_type => "sparc_fp_attr_t",
+       attr      => "ir_mode *fp_mode",
+       mode      => $mode_gp,
 },
 
-FdTOi => {
-       irn_flags => [ "rematerializable" ],
-       reg_req   => { in => [ "fp" ], out => [ "gp" ] },
-       emit      =>'. FdTOi %S1, %D1'
+Ldf => {
+       op_flags  => [ "labeled", "fragile" ],
+       state     => "exc_pinned",
+       ins       => [ "ptr", "mem" ],
+       outs      => [ "res", "M" ],
+       reg_req   => { in => [ "gp", "none" ], out => [ "fp", "none" ] },
+       attr_type => "sparc_load_store_attr_t",
+       attr      => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
+       emit      => '. ld [%S1%O], %D1'
+},
+
+Stf => {
+       op_flags  => [ "labeled", "fragile" ],
+       state     => "exc_pinned",
+       ins       => [ "ptr", "val", "mem" ],
+       outs      => [ "M" ],
+       reg_req   => { in => [ "gp", "fp", "none" ], out => [ "none" ] },
+       attr_type => "sparc_load_store_attr_t",
+       attr      => "ir_mode *ls_mode, ir_entity *entity, int entity_sign, long offset, bool is_frame_entity",
+       emit      => '. st %S2, [%S1%O]',
+       mode      => 'mode_M',
 },
 
 ); # end of %nodes