Browse Source

* overflow check abs(...) for x86

florian 1 year ago
parent
commit
2a46596edd
1 changed files with 11 additions and 0 deletions
  1. 11 0
      compiler/x86/nx86inl.pas

+ 11 - 0
compiler/x86/nx86inl.pas

@@ -1074,6 +1074,7 @@ implementation
         hregister : tregister;
         hregister : tregister;
         opsize : tcgsize;
         opsize : tcgsize;
         hp : taicpu;
         hp : taicpu;
+        hl: TAsmLabel;
       begin
       begin
 {$if defined(i8086) or defined(i386)}
 {$if defined(i8086) or defined(i386)}
         if not(CPUX86_HAS_CMOV in cpu_capabilities[current_settings.cputype]) then
         if not(CPUX86_HAS_CMOV in cpu_capabilities[current_settings.cputype]) then
@@ -1099,9 +1100,19 @@ implementation
             location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
             location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
             cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,hregister);
             cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,hregister);
             cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,location.register);
             cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,location.register);
+
+            cg.a_reg_alloc(current_asmdata.CurrAsmList, NR_DEFAULTFLAGS);
             emit_reg(A_NEG,tcgsize2opsize[opsize],hregister);
             emit_reg(A_NEG,tcgsize2opsize[opsize],hregister);
+            if cs_check_overflow in current_settings.localswitches then
+              begin
+                current_asmdata.getjumplabel(hl);
+                cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NO,hl);
+                cg.a_call_name(current_asmdata.CurrAsmList,'FPC_OVERFLOW',false);
+                cg.a_label(current_asmdata.CurrAsmList,hl);
+              end;
             hp:=taicpu.op_reg_reg(A_CMOVcc,tcgsize2opsize[opsize],hregister,location.register);
             hp:=taicpu.op_reg_reg(A_CMOVcc,tcgsize2opsize[opsize],hregister,location.register);
             hp.condition:=C_NS;
             hp.condition:=C_NS;
+            cg.a_reg_dealloc(current_asmdata.CurrAsmList, NR_DEFAULTFLAGS);
             current_asmdata.CurrAsmList.concat(hp);
             current_asmdata.CurrAsmList.concat(hp);
           end;
           end;
       end;
       end;