Browse Source

* avoid to generate bts/r with memory operand
+ thlcgx86.a_bit_set_reg_reg

florian 1 year ago
parent
commit
12176d3683
2 changed files with 18 additions and 6 deletions
  1. 11 4
      compiler/x86/hlcgx86.pas
  2. 7 2
      compiler/x86/nx86inl.pas

+ 11 - 4
compiler/x86/hlcgx86.pas

@@ -31,20 +31,19 @@ interface
   uses
     globtype,
     aasmdata,
+    cgbase,
     symtype,symdef,
     parabase,
     hlcgobj, hlcg2ll;
 
   type
-
-    { thlcgx86 }
-
     thlcgx86 = class(thlcg2ll)
      protected
       procedure gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara); override;
       procedure a_jmp_external_name(list: TAsmList; const externalname: TSymStr); override;
      public
       procedure a_load_undefined_cgpara(list: TAsmList; size: tdef; const cgpara: TCGPara); override;
+      procedure a_bit_set_reg_reg(list: TAsmList; doset: boolean; bitnumbersize, destsize: tdef; bitnumber, dest: tregister); override;
     end;
 
 implementation
@@ -52,7 +51,7 @@ implementation
   uses
     globals,systems,
     aasmbase,
-    cgbase,cgutils,
+    cgutils,
     cpubase,aasmcpu;
 
 { thlcgx86 }
@@ -101,4 +100,12 @@ implementation
         inherited;
     end;
 
+  procedure thlcgx86.a_bit_set_reg_reg(list: TAsmList; doset: boolean; bitnumbersize, destsize: tdef; bitnumber, dest: tregister);
+    const
+      bit_set_clr_instr: array[boolean] of tasmop = (A_BTR,A_BTS);
+    begin
+      list.concat(taicpu.op_reg_reg(bit_set_clr_instr[doset],S_NO,bitnumber,dest));
+    end;
+
+
 end.

+ 7 - 2
compiler/x86/nx86inl.pas

@@ -1143,11 +1143,16 @@ implementation
 {$ifdef i8086}
           { BTS and BTR are 386+ }
           if current_settings.cputype < cpu_386 then
+{$else i8086}
+          { bts on memory locations is very slow, so even the default code is faster }
+          if not(cs_opt_size in current_settings.optimizerswitches) and (tcallparanode(tcallparanode(left).right).left.expectloc<>LOC_CONSTANT) and
+            (tcallparanode(left).left.expectloc=LOC_REFERENCE) then
+{$endif i8086}
             begin
               inherited;
               exit;
             end;
-{$endif i8086}
+
           if is_smallset(tcallparanode(left).resultdef) then
             begin
               opdef:=tcallparanode(left).resultdef;
@@ -1206,7 +1211,7 @@ implementation
               hlcg.location_force_reg(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.location,tcallparanode(tcallparanode(left).right).left.resultdef,opdef,true);
               register_maybe_adjust_setbase(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.resultdef,tcallparanode(tcallparanode(left).right).left.location,setbase);
               hregister:=tcallparanode(tcallparanode(left).right).left.location.register;
-              if (tcallparanode(left).left.location.loc=LOC_REFERENCE) then
+              if tcallparanode(left).left.location.loc=LOC_REFERENCE then
                 emit_reg_ref(asmop,tcgsize2opsize[opsize],hregister,tcallparanode(left).left.location.reference)
               else
                 begin