Browse Source

+ implemented code generation for signed 16/32/64-bit comparisons (<,<=,>,>=)

git-svn-id: branches/z80@44980 -
nickysn 5 years ago
parent
commit
9fc1d39beb
1 changed files with 54 additions and 11 deletions
  1. 54 11
      compiler/z80/nz80add.pas

+ 54 - 11
compiler/z80/nz80add.pas

@@ -331,6 +331,7 @@ interface
         unsigned  : boolean;
         unsigned  : boolean;
         i, size: Integer;
         i, size: Integer;
         tmpref: treference;
         tmpref: treference;
+        op: TAsmOp;
       begin
       begin
         truelabel:=nil;
         truelabel:=nil;
         falselabel:=nil;
         falselabel:=nil;
@@ -425,7 +426,7 @@ interface
                 internalerror(2020042103);
                 internalerror(2020042103);
             end;
             end;
           end
           end
-        else if unsigned then
+        else {if unsigned then}
           begin
           begin
             if left.location.loc<>LOC_REGISTER then
             if left.location.loc<>LOC_REGISTER then
               hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
               hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
@@ -440,8 +441,23 @@ interface
                     for i:=size-1 downto 0 do
                     for i:=size-1 downto 0 do
                       begin
                       begin
                         cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
                         cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
-                        current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(A_CP,NR_A,tmpref));
-                        if i<>0 then
+                        if (i=(size-1)) and (not unsigned) then
+                          op:=A_SUB
+                        else
+                          op:=A_CP;
+                        current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(op,NR_A,tmpref));
+                        if (i=(size-1)) and (not unsigned) then
+                          case NodeType of
+                            ltn,
+                            lten:
+                              tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
+                            gtn,
+                            gten:
+                              tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
+                            else
+                              internalerror(2020042202);
+                          end
+                        else if i<>0 then
                           case NodeType of
                           case NodeType of
                             ltn,
                             ltn,
                             lten:
                             lten:
@@ -480,8 +496,23 @@ interface
                   for i:=size-1 downto 0 do
                   for i:=size-1 downto 0 do
                     begin
                     begin
                       cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
                       cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
-                      current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(A_CP,NR_A,byte(right.location.value shr (i*8))));
-                      if i<>0 then
+                      if (i=(size-1)) and (not unsigned) then
+                        op:=A_SUB
+                      else
+                        op:=A_CP;
+                      current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(op,NR_A,byte(right.location.value shr (i*8))));
+                      if (i=(size-1)) and (not unsigned) then
+                        case NodeType of
+                          ltn,
+                          lten:
+                            tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
+                          gtn,
+                          gten:
+                            tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
+                          else
+                            internalerror(2020042202);
+                        end
+                      else if i<>0 then
                         case NodeType of
                         case NodeType of
                           ltn,
                           ltn,
                           lten:
                           lten:
@@ -514,8 +545,23 @@ interface
                   for i:=size-1 downto 0 do
                   for i:=size-1 downto 0 do
                     begin
                     begin
                       cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
                       cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
-                      current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_CP,NR_A,tcgz80(cg).GetOffsetReg64(right.location.register,right.location.registerhi,i)));
-                      if i<>0 then
+                      if (i=(size-1)) and (not unsigned) then
+                        op:=A_SUB
+                      else
+                        op:=A_CP;
+                      current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(op,NR_A,tcgz80(cg).GetOffsetReg64(right.location.register,right.location.registerhi,i)));
+                      if (i=(size-1)) and (not unsigned) then
+                        case NodeType of
+                          ltn,
+                          lten:
+                            tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
+                          gtn,
+                          gten:
+                            tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
+                          else
+                            internalerror(2020042202);
+                        end
+                      else if i<>0 then
                         case NodeType of
                         case NodeType of
                           ltn,
                           ltn,
                           lten:
                           lten:
@@ -549,10 +595,7 @@ interface
               else
               else
                 internalerror(2020042103);
                 internalerror(2020042103);
             end;
             end;
-          end
-        else
-          // todo: implement the rest
-          internalerror(2020042104);
+          end;
       end;
       end;