Browse Source

* switch AVR RTL to provide atomic intrinsic helpers instead of Interlocked* functions

Sven/Sarah Barth 8 months ago
parent
commit
128a87a2dc
1 changed files with 59 additions and 4 deletions
  1. 59 4
      rtl/avr/avr.inc

+ 59 - 4
rtl/avr/avr.inc

@@ -128,7 +128,17 @@ Function Sptr : pointer;assembler;nostackframe;
   end;
 
 
+{$ifndef VER3_2}
+{$define FPC_SYSTEM_INTERLOCKED_USE_INTRIN}
+{$endif VER3_2}
+
+
+{$ifdef VER3_2}
 function InterLockedDecrement (var Target: longint) : longint;
+{$else VER3_2}
+{$define FPC_SYSTEM_HAS_ATOMIC_DEC_32}
+function fpc_atomic_dec_32 (var Target: longint) : longint;
+{$endif VER3_2}
   var
     temp_sreg : byte;
   begin
@@ -143,7 +153,12 @@ function InterLockedDecrement (var Target: longint) : longint;
   end;
 
 
+{$ifdef VER3_2}
 function InterLockedIncrement (var Target: longint) : longint;
+{$else VER3_2}
+{$define FPC_SYSTEM_HAS_ATOMIC_INC_32}
+function fpc_atomic_inc_32 (var Target: longint) : longint;
+{$endif VER3_2}
   var
     temp_sreg : byte;
   begin
@@ -158,7 +173,12 @@ function InterLockedIncrement (var Target: longint) : longint;
   end;
 
 
+{$ifdef VER3_2}
 function InterLockedExchange (var Target: longint;Source : longint) : longint;
+{$else VER3_2}
+{$define FPC_SYSTEM_HAS_ATOMIC_XCHG_32}
+function fpc_atomic_xchg_32 (var Target: longint;Source : longint) : longint;
+{$endif VER3_2}
   var
     temp_sreg : byte;
   begin
@@ -173,7 +193,12 @@ function InterLockedExchange (var Target: longint;Source : longint) : longint;
   end;
 
 
+{$ifdef VER3_2}
 function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint;
+{$else VER3_2}
+{$define FPC_SYSTEM_HAS_ATOMIC_CMP_XCHG_32}
+function fpc_atomic_cmp_xchg_32 (var Target: longint; NewValue: longint; Comparand: longint) : longint;
+{$endif VER3_2}
   var
     temp_sreg : byte;
   begin
@@ -181,7 +206,7 @@ function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comp
     temp_sreg:=avr_save();
 
     Result:=Target;
-    if Result=Comperand then
+    if Result={$ifdef VER3_2}Comperand{$else}Comparand{$endif} then
       Target:=NewValue;
 
     { release interrupts }
@@ -189,7 +214,12 @@ function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comp
   end;
 
 
+{$ifdef VER3_2}
 function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint;
+{$else VER3_2}
+{$define FPC_SYSTEM_HAS_ATOMIC_ADD_32}
+function fpc_atomic_add_32 (var Target: longint;Value : longint) : longint;
+{$endif VER3_2}
   var
     temp_sreg : byte;
   begin
@@ -197,14 +227,19 @@ function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint
     temp_sreg:=avr_save();
 
     Result:=Target;
-    Target:=Result+Source;
+    Target:=Result+{$ifdef VER3_2}Source{$else}Value{$endif};
 
     { release interrupts }
     avr_restore(temp_sreg);
   end;
 
 
+{$ifdef VER3_2}
 function InterLockedDecrement (var Target: smallint) : smallint;
+{$else VER3_2}
+{$define FPC_SYSTEM_HAS_ATOMIC_DEC_16}
+function fpc_atomic_dec_16 (var Target: smallint) : smallint;
+{$endif VER3_2}
   var
     temp_sreg : byte;
   begin
@@ -219,7 +254,12 @@ function InterLockedDecrement (var Target: smallint) : smallint;
   end;
 
 
+{$ifdef VER3_2}
 function InterLockedIncrement (var Target: smallint) : smallint;
+{$else VER3_2}
+{$define FPC_SYSTEM_HAS_ATOMIC_INC_16}
+function fpc_atomic_inc_16 (var Target: smallint) : smallint;
+{$endif VER3_2}
   var
     temp_sreg : byte;
   begin
@@ -234,7 +274,12 @@ function InterLockedIncrement (var Target: smallint) : smallint;
   end;
 
 
+{$ifdef VER3_2}
 function InterLockedExchange (var Target: smallint;Source : smallint) : smallint;
+{$else VER3_2}
+{$define FPC_SYSTEM_HAS_ATOMIC_XCHG_16}
+function fpc_atomic_xchg_16 (var Target: smallint;Source : smallint) : smallint;
+{$endif VER3_2}
   var
     temp_sreg : byte;
   begin
@@ -249,7 +294,12 @@ function InterLockedExchange (var Target: smallint;Source : smallint) : smallint
   end;
 
 
+{$ifdef VER3_2}
 function InterlockedCompareExchange(var Target: smallint; NewValue: smallint; Comperand: smallint): smallint;
+{$else VER3_2}
+{$define FPC_SYSTEM_HAS_ATOMIC_CMP_XCHG_16}
+function fpc_atomic_cmp_xchg_16 (var Target: smallint; NewValue: smallint; Comparand: smallint) : smallint; [public,alias:'FPC_ATOMIC_CMP_XCHG_16'];
+{$endif VER3_2}
   var
     temp_sreg : byte;
   begin
@@ -257,7 +307,7 @@ function InterlockedCompareExchange(var Target: smallint; NewValue: smallint; Co
     temp_sreg:=avr_save();
 
     Result:=Target;
-    if Result=Comperand then
+    if Result={$ifdef VER3_2}Comperand{$else}Comparand{$endif} then
       Target:=NewValue;
 
     { release interrupts }
@@ -265,7 +315,12 @@ function InterlockedCompareExchange(var Target: smallint; NewValue: smallint; Co
   end;
 
 
+{$ifdef VER3_2}
 function InterLockedExchangeAdd (var Target: smallint;Source : smallint) : smallint;
+{$else VER3_2}
+{$define FPC_SYSTEM_HAS_ATOMIC_ADD_16}
+function fpc_atomic_add_16 (var Target: smallint;Value : smallint) : smallint;
+{$endif VER3_2}
   var
     temp_sreg : byte;
   begin
@@ -273,7 +328,7 @@ function InterLockedExchangeAdd (var Target: smallint;Source : smallint) : small
     temp_sreg:=avr_save();
 
     Result:=Target;
-    Target:=Result+Source;
+    Target:=Result+{$ifdef VER3_2}Source{$else}Value{$endif};
 
     { release interrupts }
     avr_restore(temp_sreg);