Browse Source

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

Nikolay Nikolov 2 months ago
parent
commit
ac45a5389f
1 changed files with 54 additions and 4 deletions
  1. 54 4
      rtl/mos6502/mos6502.inc

+ 54 - 4
rtl/mos6502/mos6502.inc

@@ -44,7 +44,12 @@ Function Sptr : pointer;
   end;
 
 
+{$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
@@ -67,7 +72,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
@@ -90,7 +100,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
@@ -113,7 +128,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
@@ -125,7 +145,7 @@ function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comp
 {$endif FPC_MOS6502_INTERLOCKED_OPERATIONS_BLOCK_INTERRUPTS}
 
     Result:=Target;
-    if Target=Comperand then
+    if Target={$ifdef VER3_2}Comperand{$else}Comparand{$endif} then
       Target:=NewValue;
 
 {$ifdef FPC_MOS6502_INTERLOCKED_OPERATIONS_BLOCK_INTERRUPTS}
@@ -137,7 +157,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
@@ -149,7 +174,7 @@ function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint
 {$endif FPC_MOS6502_INTERLOCKED_OPERATIONS_BLOCK_INTERRUPTS}
 
     Result:=Target;
-    inc(Target,Source);
+    inc(Target,{$ifdef VER3_2}Source{$else}Value{$endif});
 
 {$ifdef FPC_MOS6502_INTERLOCKED_OPERATIONS_BLOCK_INTERRUPTS}
     { release interrupts }
@@ -160,7 +185,12 @@ function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint
   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
@@ -183,7 +213,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
@@ -206,7 +241,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
@@ -229,7 +269,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
@@ -241,7 +286,7 @@ function InterlockedCompareExchange(var Target: smallint; NewValue: smallint; Co
 {$endif FPC_MOS6502_INTERLOCKED_OPERATIONS_BLOCK_INTERRUPTS}
 
     Result:=Target;
-    if Target=Comperand then
+    if Target={$ifdef VER3_2}Comperand{$else}Comparand{$endif} then
       Target:=NewValue;
 
 {$ifdef FPC_MOS6502_INTERLOCKED_OPERATIONS_BLOCK_INTERRUPTS}
@@ -253,7 +298,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
@@ -265,7 +315,7 @@ function InterLockedExchangeAdd (var Target: smallint;Source : smallint) : small
 {$endif FPC_MOS6502_INTERLOCKED_OPERATIONS_BLOCK_INTERRUPTS}
 
     Result:=Target;
-    inc(Target,Source);
+    inc(Target,{$ifdef VER3_2}Source{$else}Value{$endif});
 
 {$ifdef FPC_MOS6502_INTERLOCKED_OPERATIONS_BLOCK_INTERRUPTS}
     { release interrupts }