@@ -807,6 +807,35 @@ fn (mut g Gen) mov_var_to_reg(reg Register, var Var, config VarConfig) {
807
807
}
808
808
}
809
809
810
+ fn (mut g Gen) mov_extend_reg (a Register, b Register, typ ast.Type) {
811
+ size := g.get_type_size (typ)
812
+ is_signed := ! typ.is_real_pointer () && typ.is_signed ()
813
+
814
+ if size in [1 , 2 , 4 ] {
815
+ if size == 4 && ! is_signed {
816
+ g.write8 (0x40 + if int (a) > = int (Register.r8 ) { 1 } else { 0 } +
817
+ if int (b) > = int (Register.r8 ) { 4 } else { 0 })
818
+ g.write8 (0x89 )
819
+ } else {
820
+ g.write8 (0x48 + if int (a) > = int (Register.r8 ) { 1 } else { 0 } +
821
+ if int (b) > = int (Register.r8 ) { 4 } else { 0 })
822
+ if size in [1 , 2 ] {
823
+ g.write8 (0x0f )
824
+ }
825
+ g.write8 (match true {
826
+ size == 1 && is_signed { 0xbe }
827
+ size == 1 && ! is_signed { 0xb6 }
828
+ size == 2 && is_signed { 0xbf }
829
+ size == 2 && ! is_signed { 0xb7 }
830
+ else { 0x63 }
831
+ })
832
+ }
833
+ g.write8 (0xc0 + int (a) % 8 * 8 + int (b) % 8 )
834
+ instruction := if is_signed { 's' } else { 'z' }
835
+ g.println ('mov${instruction} x $a , $b ' )
836
+ }
837
+ }
838
+
810
839
fn (mut g Gen) call_addr_at (addr int , at i64 ) i64 {
811
840
// Need to calculate the difference between current position (position after the e8 call)
812
841
// and the function to call.
@@ -2135,20 +2164,6 @@ fn (mut g Gen) assign_stmt(node ast.AssignStmt) {
2135
2164
ast.GoExpr {
2136
2165
g.v_error ('threads not implemented for the native backend' , node.pos)
2137
2166
}
2138
- ast.CastExpr {
2139
- g.warning ('cast expressions are work in progress' , right.pos)
2140
- match right.typname {
2141
- 'u64' {
2142
- g.allocate_var (name, 8 , right.expr.str ().int ())
2143
- }
2144
- 'int' {
2145
- g.allocate_var (name, 4 , right.expr.str ().int ())
2146
- }
2147
- else {
2148
- g.v_error ('unsupported cast type $right.typ ' , node.pos)
2149
- }
2150
- }
2151
- }
2152
2167
ast.FloatLiteral {
2153
2168
g.v_error ('floating point arithmetic not yet implemented for the native backend' ,
2154
2169
node.pos)
0 commit comments