Browse Source

+ support for fpc_aarch64_yield and fpc_arm_yield

  + intrinsics unit for aarch64 and arm
florian 2 weeks ago
parent
commit
fb577a9175

+ 17 - 0
compiler/aarch64/ccpuinnr.inc

@@ -0,0 +1,17 @@
+{
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2025 by the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+  in_a64_fcadd  = in_cpu_first,
+  in_a64_yield = in_cpu_first+1
+

+ 41 - 0
compiler/aarch64/ncpuinl.pas

@@ -51,6 +51,9 @@ interface
         procedure second_fma; override;
         procedure second_prefetch; override;
         procedure second_minmax; override;
+        procedure pass_generate_code_cpu; override;
+        function pass_typecheck_cpu: tnode; override;
+        function first_cpu: tnode; override;
       private
         procedure load_fpu_location;
       end;
@@ -71,6 +74,44 @@ implementation
                               taarch64inlinenode
 *****************************************************************************}
 
+     function taarch64inlinenode.pass_typecheck_cpu: tnode;
+       begin
+         Result:=nil;
+         case inlinenumber of
+           in_a64_yield:
+             resultdef:=voidtype;
+           else
+             result:=inherited;
+         end;
+       end;
+
+
+    function taarch64inlinenode.first_cpu : tnode;
+      begin
+        Result:=nil;
+        case inlinenumber of
+          in_a64_yield:
+            begin
+              expectloc:=LOC_VOID;
+              resultdef:=voidtype;
+            end;
+          else
+            Result:=inherited first_cpu;
+        end;
+      end;
+
+
+     procedure taarch64inlinenode.pass_generate_code_cpu;
+       begin
+         case inlinenumber of
+           in_a64_yield:
+             current_asmdata.CurrAsmList.concat(taicpu.op_none(A_YIELD));
+           else
+             inherited pass_generate_code_cpu;
+         end;
+       end;
+
+
     procedure taarch64inlinenode.load_fpu_location;
       begin
         secondpass(left);

+ 16 - 0
compiler/arm/ccpuinnr.inc

@@ -0,0 +1,16 @@
+{
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2025 by the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+  in_arm_yield  = in_cpu_first
+

+ 43 - 1
compiler/arm/narminl.pas

@@ -52,6 +52,10 @@ interface
         procedure second_prefetch; override;
         procedure second_abs_long; override;
         procedure second_fma; override;
+
+        function first_cpu: tnode; override;
+        procedure pass_generate_code_cpu; override;
+        function pass_typecheck_cpu: tnode; override;
       private
         procedure load_fpu_location(out singleprec: boolean);
       end;
@@ -62,7 +66,7 @@ implementation
     uses
       globtype,verbose,globals,
       procinfo,
-      cpuinfo, defutil,symdef,aasmdata,aasmcpu,
+      compinnr,cpuinfo,defutil,symdef,aasmdata,aasmcpu,
       cgbase,cgutils,pass_1,pass_2,
       cpubase,ncgutil,cgobj,cgcpu, hlcgobj,
       nutils,ncal;
@@ -71,6 +75,44 @@ implementation
                               tarminlinenode
 *****************************************************************************}
 
+     function tarminlinenode.pass_typecheck_cpu: tnode;
+       begin
+         Result:=nil;
+         case inlinenumber of
+           in_arm_yield:
+             resultdef:=voidtype;
+           else
+             result:=inherited;
+         end;
+       end;
+
+
+    function tarminlinenode.first_cpu : tnode;
+      begin
+        Result:=nil;
+        case inlinenumber of
+          in_arm_yield:
+            begin
+              expectloc:=LOC_VOID;
+              resultdef:=voidtype;
+            end;
+          else
+            Result:=inherited first_cpu;
+        end;
+      end;
+
+
+     procedure tarminlinenode.pass_generate_code_cpu;
+       begin
+         case inlinenumber of
+           in_arm_yield:
+             current_asmdata.CurrAsmList.concat(taicpu.op_none(A_YIELD));
+           else
+             inherited pass_generate_code_cpu;
+         end;
+       end;
+
+
     procedure tarminlinenode.load_fpu_location(out singleprec: boolean);
       begin
         secondpass(left);

+ 8 - 0
compiler/compinnr.pas

@@ -218,6 +218,14 @@ type
 {$if defined(WASM32)}
      ,
      {$i ccpuinnr.inc}
+{$endif}
+{$if defined(ARM)}
+     ,
+     {$i ccpuinnr.inc}
+{$endif}
+{$if defined(AARCH64)}
+     ,
+     {$i ccpuinnr.inc}
 {$endif}
    );
 

+ 1 - 0
rtl/aarch64/cpuinnr.inc

@@ -14,3 +14,4 @@
  **********************************************************************}
 
 fpc_in_aarch64_fcadd = fpc_in_cpu_first+0;
+fpc_in_aarch64_yield = fpc_in_cpu_first+1;

+ 2 - 0
rtl/aarch64/cpuprocs.inc

@@ -12,3 +12,5 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
  **********************************************************************}
+
+procedure fpc_aarch64_yield;[internproc:fpc_in_aarch64_yield];

+ 16 - 0
rtl/arm/cpuinnr.inc

@@ -0,0 +1,16 @@
+  {
+    Defines CPU intrinsic indicies for ARM
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2021 by the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+fpc_in_arm_yield = fpc_in_cpu_first+0;

+ 16 - 0
rtl/arm/cpuprocs.inc

@@ -0,0 +1,16 @@
+{
+    Defines CPU intrinsics for ARM
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2025 by the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+procedure fpc_arm_yield;[internproc:fpc_in_arm_yield];

+ 28 - 0
rtl/arm/intrinsics.pp

@@ -0,0 +1,28 @@
+{
+    Provides CPU intrinsics for ARM
+
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2021 by the Free Pascal development team.
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+{$IFNDEF FPC_DOTTEDUNITS}
+unit intrinsics;
+{$ENDIF FPC_DOTTEDUNITS}
+
+  interface
+
+    const
+    {$i cpuinnr.inc}
+
+    {$i cpuprocs.inc}
+
+  implementation
+
+end.

+ 10 - 0
rtl/darwin/Makefile

@@ -919,6 +919,9 @@ endif
 ifeq ($(ARCH),x86_64)
 CPU_UNITS=$(CPUUNIT)
 endif
+ifeq ($(ARCH),aarch64)
+CPU_UNITS=$(INTRINSICSUNIT)
+endif
 RTL=..
 INC=$(RTL)/inc
 COMMON=$(RTL)/common
@@ -2696,6 +2699,13 @@ mmx$(PPUEXT) : $(MMX_DEPS)
 	$(COMPILER) $(MMX_OPT) $<
 System.CPU.MMX$(PPUEXT) : $(NSINC)/System.CPU.MMX.pp $(MMX_DEPS)
 	$(COMPILER) $(MMX_OPT) $<
+INTRINSICS_DEPS=$(PROCINC)/intrinsics.pp \
+	 $(SYSTEMUNIT)$(PPUEXT) \
+	 $(INTRINSICS_DEPS_OS) $(INTRINSICS_DEPS_CPU)
+intrinsics$(PPUEXT) : $(INTRINSICS_DEPS)
+	$(COMPILER) $(INTRINSICS_OPT) $<
+System.Intrinsics$(PPUEXT) : $(NSINC)/System.Intrinsics.pp $(INTRINSICS_DEPS)
+	$(COMPILER) $(INTRINSICS_OPT) $<
 ifeq ($(filter -dFPC_USE_LIBC,$(FPCOPT)),)
   X86_DEPS_OS+=$(SYSCALLUNIT)$(PPUEXT)
 endif

+ 4 - 0
rtl/darwin/Makefile.fpc

@@ -55,6 +55,10 @@ ifeq ($(ARCH),x86_64)
 CPU_UNITS=$(CPUUNIT)
 endif
 
+ifeq ($(ARCH),aarch64)
+CPU_UNITS=$(INTRINSICSUNIT)
+endif
+
 RTL=..
 INC=$(RTL)/inc
 COMMON=$(RTL)/common

+ 15 - 0
rtl/inc/Makefile.rtl

@@ -1203,6 +1203,21 @@ mmx$(PPUEXT) : $(MMX_DEPS)
 System.CPU.MMX$(PPUEXT) : $(NSINC)/System.CPU.MMX.pp $(MMX_DEPS)
 	$(COMPILER) $(MMX_OPT) $<
 
+
+#
+# Intrinsics
+#
+
+INTRINSICS_DEPS=$(PROCINC)/intrinsics.pp \
+         $(SYSTEMUNIT)$(PPUEXT) \
+         $(INTRINSICS_DEPS_OS) $(INTRINSICS_DEPS_CPU)
+
+intrinsics$(PPUEXT) : $(INTRINSICS_DEPS)
+	$(COMPILER) $(INTRINSICS_OPT) $<
+
+System.Intrinsics$(PPUEXT) : $(NSINC)/System.Intrinsics.pp $(INTRINSICS_DEPS)
+	$(COMPILER) $(INTRINSICS_OPT) $<
+
 #
 # X86
 #

+ 11 - 1
rtl/linux/Makefile

@@ -957,6 +957,9 @@ CPU_UNITS=$(X86UNIT) $(PORTSUNIT) $(CPUUNIT)
 SYSINIT_UNITS=si_prc si_c si_g si_dll
 override LOADERS=abitag
 endif
+ifeq ($(ARCH),aarch64)
+CPU_UNITS=$(INTRINSICSUNIT)
+endif
 ifeq ($(ARCH),powerpc64)
 override LOADERS=
 SYSINIT_UNITS=si_prc si_c si_g si_dll
@@ -986,7 +989,7 @@ override FPCOPT+=-Ur
 endif
 ifeq ($(ARCH),arm)
 override LOADERS+=ucprt0
-CPU_UNITS=$(CPUUNIT)
+CPU_UNITS=$(CPUUNIT) $(INTRINSICSUNIT)
 endif
 ifeq ($(ARCH),sparc)
   override FPCOPT+=-Fisparcgen
@@ -3191,6 +3194,13 @@ mmx$(PPUEXT) : $(MMX_DEPS)
 	$(COMPILER) $(MMX_OPT) $<
 System.CPU.MMX$(PPUEXT) : $(NSINC)/System.CPU.MMX.pp $(MMX_DEPS)
 	$(COMPILER) $(MMX_OPT) $<
+INTRINSICS_DEPS=$(PROCINC)/intrinsics.pp \
+	 $(SYSTEMUNIT)$(PPUEXT) \
+	 $(INTRINSICS_DEPS_OS) $(INTRINSICS_DEPS_CPU)
+intrinsics$(PPUEXT) : $(INTRINSICS_DEPS)
+	$(COMPILER) $(INTRINSICS_OPT) $<
+System.Intrinsics$(PPUEXT) : $(NSINC)/System.Intrinsics.pp $(INTRINSICS_DEPS)
+	$(COMPILER) $(INTRINSICS_OPT) $<
 ifeq ($(filter -dFPC_USE_LIBC,$(FPCOPT)),)
   X86_DEPS_OS+=$(SYSCALLUNIT)$(PPUEXT)
 endif

+ 5 - 1
rtl/linux/Makefile.fpc

@@ -103,6 +103,10 @@ SYSINIT_UNITS=si_prc si_c si_g si_dll
 override LOADERS=abitag
 endif
 
+ifeq ($(ARCH),aarch64)
+CPU_UNITS=$(INTRINSICSUNIT)
+endif
+
 ifeq ($(ARCH),powerpc64)
 override LOADERS=
 SYSINIT_UNITS=si_prc si_c si_g si_dll
@@ -143,7 +147,7 @@ endif
 
 ifeq ($(ARCH),arm)
 override LOADERS+=ucprt0
-CPU_UNITS=$(CPUUNIT)
+CPU_UNITS=$(CPUUNIT) $(INTRINSICSUNIT)
 endif
 
 ifeq ($(ARCH),sparc)