Răsfoiți Sursa

Merge branch source:main into main

Curtis Hamilton 1 lună în urmă
părinte
comite
34a4af7a52
77 a modificat fișierele cu 485 adăugiri și 97 ștergeri
  1. 2 0
      .gitignore
  2. 4 0
      compiler/compinnr.pas
  3. 10 2
      compiler/powerpc64/cpuinfo.pas
  4. 16 0
      compiler/ppcgen/ccpuinnr.inc
  5. 41 0
      compiler/ppcgen/ngppcinl.pas
  6. 2 0
      packages/fcl-passrc/src/paswrite.pp
  7. 19 8
      packages/vcl-compat/src/system.ioutils.pp
  8. 5 6
      rtl/aix/Makefile
  9. 4 5
      rtl/aix/Makefile.fpc
  10. 27 2
      rtl/amicommon/classes.pp
  11. 1 1
      rtl/amiga/Makefile
  12. 1 1
      rtl/android/Makefile
  13. 1 1
      rtl/aros/Makefile
  14. 1 1
      rtl/atari/Makefile
  15. 1 1
      rtl/beos/Makefile
  16. 1 1
      rtl/darwin/Makefile
  17. 1 1
      rtl/dragonfly/Makefile
  18. 1 1
      rtl/embedded/Makefile
  19. 27 2
      rtl/embedded/classes.pp
  20. 1 1
      rtl/emx/Makefile
  21. 1 1
      rtl/freebsd/Makefile
  22. 1 1
      rtl/freertos/Makefile
  23. 27 2
      rtl/freertos/classes.pp
  24. 1 1
      rtl/gba/Makefile
  25. 0 3
      rtl/gba/classes.pp
  26. 1 1
      rtl/go32v2/Makefile
  27. 1 1
      rtl/haiku/Makefile
  28. 1 1
      rtl/human68k/Makefile
  29. 5 2
      rtl/inc/Makefile.rtl
  30. 1 1
      rtl/java/Makefile
  31. 5 1
      rtl/linux/Makefile
  32. 5 0
      rtl/linux/Makefile.fpc
  33. 1 1
      rtl/macos/Makefile
  34. 1 1
      rtl/morphos/Makefile
  35. 1 1
      rtl/msdos/Makefile
  36. 1 1
      rtl/msxdos/Makefile
  37. 1 1
      rtl/nativent/Makefile
  38. 1 1
      rtl/nds/Makefile
  39. 0 3
      rtl/nds/classes.pp
  40. 4 1
      rtl/netbsd/Makefile
  41. 3 0
      rtl/netbsd/Makefile.fpc
  42. 1 1
      rtl/netware/Makefile
  43. 1 1
      rtl/netwlibc/Makefile
  44. 4 4
      rtl/objpas/classes/classes.inc
  45. 1 1
      rtl/openbsd/Makefile
  46. 1 1
      rtl/os2/Makefile
  47. 1 1
      rtl/palmos/Makefile
  48. 16 0
      rtl/powerpc/cpuinnr.inc
  49. 16 0
      rtl/powerpc/cpuprocs.inc
  50. 28 0
      rtl/powerpc/intrinsics.pp
  51. 16 0
      rtl/powerpc64/cpuinnr.inc
  52. 16 0
      rtl/powerpc64/cpuprocs.inc
  53. 28 0
      rtl/powerpc64/intrinsics.pp
  54. 1 1
      rtl/ps1/Makefile
  55. 1 1
      rtl/sinclairql/Makefile
  56. 1 1
      rtl/solaris/Makefile
  57. 1 1
      rtl/symbian/Makefile
  58. 0 3
      rtl/symbian/classes.pp
  59. 28 3
      rtl/unix/classes.pp
  60. 1 1
      rtl/wasip1/Makefile
  61. 1 1
      rtl/wasip1threads/Makefile
  62. 1 1
      rtl/wasip2/Makefile
  63. 1 1
      rtl/watcom/Makefile
  64. 1 1
      rtl/wii/Makefile
  65. 1 1
      rtl/win16/Makefile
  66. 1 1
      rtl/win32/Makefile
  67. 29 2
      rtl/win32/classes.pp
  68. 1 1
      rtl/win64/Makefile
  69. 27 2
      rtl/win64/classes.pp
  70. 1 1
      rtl/wince/Makefile
  71. 27 2
      rtl/wince/classes.pp
  72. 1 1
      rtl/zxspectrum/Makefile
  73. BIN
      tests/test/cg/obj/linux/i386/tcext7.o
  74. BIN
      tests/test/cg/obj/linux/powerpc/tcext7.o
  75. BIN
      tests/test/cg/obj/linux/powerpc64-le/tcext7.o
  76. BIN
      tests/test/cg/obj/linux/powerpc64/tcext7.o
  77. 3 3
      tests/test/cg/obj/readme.txt

+ 2 - 0
.gitignore

@@ -67,6 +67,8 @@ symbol_order*.fpc
 /compiler/gppc*
 /compiler/vppc*
 !/compiler/ppc*.lpi
+!/compiler/ppcgen/*.pas
+!/compiler/ppcgen/*.inc
 !/compiler/ppc*.pas
 /compiler/*/pp
 /compiler/msgidx.inc

+ 4 - 0
compiler/compinnr.pas

@@ -230,6 +230,10 @@ type
 {$if defined(RISCV)}
      ,
      {$i riscv/ccpuinnr.inc}
+{$endif}
+{$if defined(POWERPC) or defined(POWERPC64)}
+     ,
+     {$i ppcgen/ccpuinnr.inc}
 {$endif}
    );
 

+ 10 - 2
compiler/powerpc64/cpuinfo.pas

@@ -34,7 +34,11 @@ type
 
   { possible supported processors for this target }
   tcputype = (cpu_none,
-    cpu_ppc970
+    cpu_power4,
+    cpu_ppc970,
+    cpu_power5,
+    cpu_power6,
+    cpu_power7
     );
 
   tfputype =
@@ -83,7 +87,11 @@ Const
     ];
 
   cputypestr: array[tcputype] of string[10] = ('',
-    '970'
+    'POWER4',
+    '970',
+    'POWER5',
+    'POWER6',
+    'POWER7'
     );
 
   fputypestr: array[tfputype] of string[8] = (

+ 16 - 0
compiler/ppcgen/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_ppc_yield = in_cpu_first
+

+ 41 - 0
compiler/ppcgen/ngppcinl.pas

@@ -46,6 +46,9 @@ interface
           procedure second_trunc_real; override;
           procedure second_round_real; override;
           procedure second_prefetch;override;
+          function pass_typecheck_cpu: tnode; override;
+          function first_cpu: tnode; override;
+          procedure pass_generate_code_cpu; override;
        protected
           procedure load_fpu_location;
           procedure second_trunc_round_real(op: tasmop);
@@ -55,6 +58,7 @@ implementation
 
     uses
       cutils,globals,verbose,globtype,
+      compinnr,
       aasmtai,aasmdata,aasmcpu,
       symconst,symdef,
       defutil,
@@ -67,6 +71,43 @@ implementation
                               tgppcinlinenode
 *****************************************************************************}
 
+     function tgppcinlinenode.pass_typecheck_cpu: tnode;
+       begin
+         Result:=nil;
+         case inlinenumber of
+           in_ppc_yield:
+             resultdef:=voidtype;
+           else
+             result:=inherited;
+         end;
+       end;
+
+
+    function tgppcinlinenode.first_cpu : tnode;
+      begin
+        Result:=nil;
+        case inlinenumber of
+          in_ppc_yield:
+            begin
+              expectloc:=LOC_VOID;
+              resultdef:=voidtype;
+            end;
+          else
+            Result:=inherited first_cpu;
+        end;
+      end;
+
+
+     procedure tgppcinlinenode.pass_generate_code_cpu;
+       begin
+         case inlinenumber of
+           in_ppc_yield:
+             current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_OR,NR_R27,NR_R27,NR_R27));
+           else
+             inherited pass_generate_code_cpu;
+         end;
+       end;
+
     function tgppcinlinenode.first_sqrt_real : tnode;
       begin
         if (current_settings.cputype >= cpu_PPC970) then

+ 2 - 0
packages/fcl-passrc/src/paswrite.pp

@@ -344,6 +344,8 @@ begin
     Add(AType.GetDeclaration(true))
   else if AType is TPasRangeType then
     Add(AType.GetDeclaration(true))
+  else if AType is TPasFileType then
+    Add(AType.GetDeclaration(true))
   else
     raise EPasWriter.CreateFmt('Writing not implemented for %s type nodes',[aType.ElementTypeName]);
   if Full then

+ 19 - 8
packages/vcl-compat/src/system.ioutils.pp

@@ -2180,6 +2180,8 @@ class function TDirectory.GetFilesAndDirectories(const aPath,
   aSearchPattern: string; const aSearchOption: TSearchOption;
   const SearchAttributes: TFileAttributes;
   const aPredicate: TFilterPredicateLocal): TStringDynArray;
+const
+   lfaDirectory = {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}SysUtils.faDirectory;
 
   function FilterPredicate(const aPath: string; const SearchRec: TSearchRec): Boolean;
   begin
@@ -2194,14 +2196,23 @@ begin
   IntPath     :=IncludeTrailingPathDelimiter(aPath);
   Result      :=[];
   if (FindFirst(IntPath + aSearchPattern, TFile.FileAttributesToInteger(SearchAttributes), SearchRec) = 0) then
-    repeat
-      if (aSearchOption = TSearchOption.soAllDirectories) and ((SearchRec.Attr and {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}SysUtils.faDirectory) <> 0)
-         and (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
-        Result:=Result + GetFilesAndDirectories(IntPath + SearchRec.Name, aSearchPattern, aSearchOption, SearchAttributes, aPredicate)
-      else if FilterPredicate(aPath, SearchRec) then
-        Result:=Result + [IntPath + SearchRec.Name];
-    until FindNext(SearchRec) <> 0;
-  {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}SysUtils.FindClose(SearchRec);
+    try
+      repeat
+        if FilterPredicate(aPath, SearchRec) then
+          Result:=Result + [IntPath + SearchRec.Name];
+      until FindNext(SearchRec) <> 0;
+    finally
+      {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}SysUtils.FindClose(SearchRec);
+    end;
+  if (aSearchOption=TSearchOption.soAllDirectories) and (FindFirst(IntPath + AllFilesMask, lfaDirectory, SearchRec) = 0) then
+    try
+      repeat
+        if SearchRec.IsDirectory and not SearchRec.IsCurrentOrParentDir then
+           Result:=Result + GetFilesAndDirectories(IntPath + SearchRec.Name, aSearchPattern, aSearchOption, SearchAttributes, aPredicate)
+      until FindNext(SearchRec) <> 0;
+   Finally
+     {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}SysUtils.FindClose(SearchRec);
+   end;
 end;
 
 class procedure TDirectory.Copy(const SourceDirName, DestDirName: string);

+ 5 - 6
rtl/aix/Makefile

@@ -930,12 +930,11 @@ TERMIO_DEPS_OS=$(UNIXTYPEUNIT)$(PPUEXT) $(CTYPESUNIT)$(PPUEXT)
 DOSDIR=$(UNIXINC)
 SYSUTILSDIR=$(UNIXINC)
 SYSUTILS_DEPS_OS = $(UNIXUNIT)$(PPUEXT) $(ERRORSUNIT)$(PPUEXT)
-ifeq ($(ARCH),i386)
-CPU_UNITS=$(CPUUNIT) $(MMXUNIT)
+ifeq ($(ARCH),powerpc)
+CPU_UNITS=$(INTRINSICSUNIT)
 endif
-ifeq ($(ARCH),x86_64)
-CPU_UNITS=$(CPUUNIT)
-SYSINIT_UNITS=   # si_prc si_c si_dll
+ifeq ($(ARCH),powerpc64)
+CPU_UNITS=$(INTRINSICSUNIT)
 endif
 override FPCOPT+=-dFPC_USE_LIBC
 OBJPASDIR=$(RTL)/objpas
@@ -2493,7 +2492,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 4 - 5
rtl/aix/Makefile.fpc

@@ -72,13 +72,12 @@ SYSUTILS_DEPS_OS = $(UNIXUNIT)$(PPUEXT) $(ERRORSUNIT)$(PPUEXT)
 
 
 
-ifeq ($(ARCH),i386)
-CPU_UNITS=$(CPUUNIT) $(MMXUNIT)
+ifeq ($(ARCH),powerpc)
+CPU_UNITS=$(INTRINSICSUNIT)
 endif
 
-ifeq ($(ARCH),x86_64)
-CPU_UNITS=$(CPUUNIT)
-SYSINIT_UNITS=   # si_prc si_c si_dll
+ifeq ($(ARCH),powerpc64)
+CPU_UNITS=$(INTRINSICSUNIT)
 endif
 
 

+ 27 - 2
rtl/amicommon/classes.pp

@@ -19,6 +19,17 @@
 {$IF FPC_FULLVERSION>=30301}
 {$modeswitch FUNCTIONREFERENCES}
 {$define FPC_HAS_REFERENCE_PROCEDURE}
+{$ifndef CPULLVM}
+{$if DEFINED(CPUARM) or DEFINED(CPUAARCH64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPUPOWERPC) or defined(CPUPOWERPC64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPURISCV32) or defined(CPURISCV64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
 {$endif}
 
 { determine the type of the resource/form file }
@@ -38,6 +49,9 @@ uses
   System.SortBase,
 {$ifdef FPC_TESTGENERICS}
   System.FGL,
+{$endif}
+{$ifdef FPC_USE_INTRINSICS}
+  System.Intrinsics,
 {$endif}
   System.TypInfo;
 {$ELSE FPC_DOTTEDUNITS}
@@ -49,12 +63,23 @@ uses
 {$ifdef FPC_TESTGENERICS}
   fgl,
 {$endif}
-{$IF DEFINED(CPUARM) or DEFINED(CPUAARCH64) }
+{$ifdef FPC_USE_INTRINSICS}
   intrinsics,
-{$ENDIF}
+{$endif}
   typinfo;
 {$ENDIF FPC_DOTTEDUNITS}
 
+{ Also set FPC_USE_INTRINSICS for i386 and x86_64,
+  but only after _USES clause as there
+  is not intinsics unit for those CPUs }
+{$IF FPC_FULLVERSION>=30301}
+{$ifndef CPULLVM}
+{$if defined(CPUI386) or defined(CPUX86_64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
+{$endif}
+
 {$i classesh.inc}
 
 

+ 1 - 1
rtl/amiga/Makefile

@@ -2520,7 +2520,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/android/Makefile

@@ -2649,7 +2649,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/aros/Makefile

@@ -2538,7 +2538,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/atari/Makefile

@@ -2490,7 +2490,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/beos/Makefile

@@ -2499,7 +2499,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/darwin/Makefile

@@ -2616,7 +2616,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/dragonfly/Makefile

@@ -2507,7 +2507,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/embedded/Makefile

@@ -2916,7 +2916,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 27 - 2
rtl/embedded/classes.pp

@@ -19,6 +19,17 @@
 {$IF FPC_FULLVERSION>=30301}
 {$modeswitch FUNCTIONREFERENCES}
 {$define FPC_HAS_REFERENCE_PROCEDURE}
+{$ifndef CPULLVM}
+{$if DEFINED(CPUARM) or DEFINED(CPUAARCH64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPUPOWERPC) or defined(CPUPOWERPC64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPURISCV32) or defined(CPURISCV64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
 {$endif}
 
 {$IFNDEF FPC_DOTTEDUNITS}
@@ -35,6 +46,9 @@ uses
   System.SortBase,
 {$ifdef FPC_TESTGENERICS}
   System.FGL,
+{$endif}
+{$ifdef FPC_USE_INTRINSICS}
+  System.Intrinsics,
 {$endif}
   System.TypInfo;
 {$ELSE FPC_DOTTEDUNITS}
@@ -46,12 +60,23 @@ uses
 {$ifdef FPC_TESTGENERICS}
   fgl,
 {$endif}
-{$IF DEFINED(CPUARM) or DEFINED(CPUAARCH64) }
+{$ifdef FPC_USE_INTRINSICS}
   intrinsics,
-{$ENDIF}
+{$endif}
   typinfo;
 {$ENDIF FPC_DOTTEDUNITS}
 
+{ Also set FPC_USE_INTRINSICS for i386 and x86_64,
+  but only after _USES clause as there
+  is not intinsics unit for those CPUs }
+{$IF FPC_FULLVERSION>=30301}
+{$ifndef CPULLVM}
+{$if defined(CPUI386) or defined(CPUX86_64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
+{$endif}
+
 {$i classesh.inc}
 
 

+ 1 - 1
rtl/emx/Makefile

@@ -2499,7 +2499,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/freebsd/Makefile

@@ -2575,7 +2575,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/freertos/Makefile

@@ -2595,7 +2595,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 27 - 2
rtl/freertos/classes.pp

@@ -19,6 +19,17 @@
 {$IF FPC_FULLVERSION>=30301}
 {$modeswitch FUNCTIONREFERENCES}
 {$define FPC_HAS_REFERENCE_PROCEDURE}
+{$ifndef CPULLVM}
+{$if DEFINED(CPUARM) or DEFINED(CPUAARCH64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPUPOWERPC) or defined(CPUPOWERPC64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPURISCV32) or defined(CPURISCV64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
 {$endif}
 
 {$IFNDEF FPC_DOTTEDUNITS}
@@ -35,6 +46,9 @@ uses
   System.SortBase,
 {$ifdef FPC_TESTGENERICS}
   System.FGL,
+{$endif}
+{$ifdef FPC_USE_INTRINSICS}
+  System.Intrinsics,
 {$endif}
   System.TypInfo;
 {$ELSE FPC_DOTTEDUNITS}
@@ -46,12 +60,23 @@ uses
 {$ifdef FPC_TESTGENERICS}
   fgl,
 {$endif}
-{$IF DEFINED(CPUARM) or DEFINED(CPUAARCH64) }
+{$ifdef FPC_USE_INTRINSICS}
   intrinsics,
-{$ENDIF}
+{$endif}
   typinfo;
 {$ENDIF FPC_DOTTEDUNITS}
 
+{ Also set FPC_USE_INTRINSICS for i386 and x86_64,
+  but only after _USES clause as there
+  is not intinsics unit for those CPUs }
+{$IF FPC_FULLVERSION>=30301}
+{$ifndef CPULLVM}
+{$if defined(CPUI386) or defined(CPUX86_64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
+{$endif}
+
 {$i classesh.inc}
 
 

+ 1 - 1
rtl/gba/Makefile

@@ -2491,7 +2491,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 0 - 3
rtl/gba/classes.pp

@@ -47,9 +47,6 @@ uses
 {$ifdef FPC_TESTGENERICS}
   fgl,
 {$endif}
-{$IF DEFINED(CPUARM) or DEFINED(CPUAARCH64) }
-  intrinsics,
-{$ENDIF}
   typinfo;
 {$ENDIF FPC_DOTTEDUNITS}
 

+ 1 - 1
rtl/go32v2/Makefile

@@ -2501,7 +2501,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/haiku/Makefile

@@ -2531,7 +2531,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/human68k/Makefile

@@ -2490,7 +2490,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 5 - 2
rtl/inc/Makefile.rtl

@@ -1052,8 +1052,11 @@ System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 #
 # Classes
 #
-# aarch64 and arm classes unit needs intrinsics unit
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+# Add intrinsics unit dependency for all CPUs
+# which use internal CPU dependent compiler inline number
+# as we plan to externalize all such inlined CPU functions
+# into intrinsics unit
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 

+ 1 - 1
rtl/java/Makefile

@@ -2461,7 +2461,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 5 - 1
rtl/linux/Makefile

@@ -960,9 +960,13 @@ endif
 ifeq ($(ARCH),aarch64)
 CPU_UNITS=$(INTRINSICSUNIT)
 endif
+ifeq ($(ARCH),powerpc)
+CPU_UNITS=$(INTRINSICSUNIT)
+endif
 ifeq ($(ARCH),powerpc64)
 override LOADERS=
 SYSINIT_UNITS=si_prc si_c si_g si_dll
+CPU_UNITS=$(INTRINSICSUNIT)
 endif
 ifeq ($(ARCH),sparc64)
 override LOADERS=
@@ -3113,7 +3117,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 5 - 0
rtl/linux/Makefile.fpc

@@ -107,9 +107,14 @@ ifeq ($(ARCH),aarch64)
 CPU_UNITS=$(INTRINSICSUNIT)
 endif
 
+ifeq ($(ARCH),powerpc)
+CPU_UNITS=$(INTRINSICSUNIT)
+endif
+
 ifeq ($(ARCH),powerpc64)
 override LOADERS=
 SYSINIT_UNITS=si_prc si_c si_g si_dll
+CPU_UNITS=$(INTRINSICSUNIT)
 endif
 
 ifeq ($(ARCH),sparc64)

+ 1 - 1
rtl/macos/Makefile

@@ -2479,7 +2479,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/morphos/Makefile

@@ -2462,7 +2462,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/msdos/Makefile

@@ -2493,7 +2493,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/msxdos/Makefile

@@ -2463,7 +2463,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/nativent/Makefile

@@ -2469,7 +2469,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/nds/Makefile

@@ -2494,7 +2494,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 0 - 3
rtl/nds/classes.pp

@@ -47,9 +47,6 @@ uses
 {$ifdef FPC_TESTGENERICS}
   fgl,
 {$endif}
-{$IF DEFINED(CPUARM) or DEFINED(CPUAARCH64) }
-  intrinsics,
-{$ENDIF}
   typinfo;
 {$ENDIF FPC_DOTTEDUNITS}
 

+ 4 - 1
rtl/netbsd/Makefile

@@ -945,6 +945,9 @@ endif
 ifeq ($(ARCH),arm)
 CPU_UNITS=$(INTRINSICSUNIT)
 endif
+ifeq ($(ARCH),powerpc)
+CPU_UNITS=$(INTRINSICSUNIT)
+endif
 ifeq ($(CPU_OS_TARGET),i386-netbsd)
 override TARGET_UNITS+=$(SYSTEMUNIT) $(UUCHARUNIT) $(UNIXTYPEUNIT) $(CTYPESUNIT) $(OBJPASUNIT) $(MACPASUNIT) $(ISO7185UNIT) $(EXTPASUNIT) $(STRINGSUNIT) $(SYSCALLUNIT) $(SYSCTLUNIT)  $(BASEUNIXUNIT) $(UNIXUTILUNIT) $(CHARACTERUNIT) $(UNIXUNIT) $(RTLCONSTSUNIT) $(INITCUNIT) $(CMEMUNIT) $(DLUNIT) $(TERMIOUNIT) $(SYSUTILSUNIT) $(MATHUNIT) $(TYPINFOUNIT) $(TYPESUNIT) $(SORTBASEUNIT) $(CLASSESUNIT) $(FGLUNIT) $(DYNLIBSUNIT) $(CPU_UNITS) $(CHARSETUNIT) $(CPALLUNIT) $(GETOPTSUNIT) $(HEAPTRCUNIT) $(LNFODWRFUNIT) $(LINEINFOUNIT) $(ERRORSUNIT) $(BSDUNIT) $(SYSCONSTUNIT) $(CTHREADSUNIT) $(DOSUNIT) $(CWSTRINGUNIT) $(FPINTRESUNIT) $(UNIXCPUNIT) $(FPWIDESTRINGUNIT) $(SOFTFPUUNIT) $(SFPUX80UNIT) $(UFLOATX80UNIT) $(SFPU128UNIT) $(UFLOAT128UNIT) $(UNIX98PTYUNIT)
 endif
@@ -2604,7 +2607,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 3 - 0
rtl/netbsd/Makefile.fpc

@@ -86,6 +86,9 @@ endif
 ifeq ($(ARCH),arm)
 CPU_UNITS=$(INTRINSICSUNIT)
 endif
+ifeq ($(ARCH),powerpc)
+CPU_UNITS=$(INTRINSICSUNIT)
+endif
 
 [rules]
 .NOTPARALLEL:

+ 1 - 1
rtl/netware/Makefile

@@ -2506,7 +2506,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/netwlibc/Makefile

@@ -2494,7 +2494,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 4 - 4
rtl/objpas/classes/classes.inc

@@ -909,7 +909,7 @@ begin
     as volatile, so the access won't be optimized away by the compiler. (KB) }
   for i:=1 to aIterations do
     begin
-    {$if (FPC_FULLVERSION<30300) or defined(CPULLVM)}
+    {$ifndef FPC_USE_INTRINSICS}
     Inc(SpinWaitDummy); // SpinWaitDummy *MUST* be global
     {$else}
     {$IF defined(CPUX86_64) or Defined(CPUI386)}
@@ -918,12 +918,12 @@ begin
     fpc_arm_yield;
     {$ELSEIF defined(CPUAARCH64)}
     fpc_aarch64_yield;
+    {$ELSEIF defined(CPUPOWERPC64) or defined(CPUPOWERPC)}
+    fpc_ppc_yield;
     {$ELSEIF defined(RISCV) and defined(CPURV_HAS_ZIHINTPAUSE)}
     fpc_riscv_pause;
-    {$ELSE}
-    Inc(SpinWaitDummy); // SpinWaitDummy *MUST* be global
-    {$ENDIF}
     {$ifend}
+    {$endif FPC_USE_INTRINSICS}
     end;
 end;
 

+ 1 - 1
rtl/openbsd/Makefile

@@ -2534,7 +2534,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/os2/Makefile

@@ -2498,7 +2498,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/palmos/Makefile

@@ -2504,7 +2504,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 16 - 0
rtl/powerpc/cpuinnr.inc

@@ -0,0 +1,16 @@
+  {
+    Defines CPU intrinsic indicies for PowerPC
+
+    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_ppc_yield = fpc_in_cpu_first+0;

+ 16 - 0
rtl/powerpc/cpuprocs.inc

@@ -0,0 +1,16 @@
+{
+    Defines CPU intrinsics for PowerPC
+
+    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_ppc_yield;[internproc:fpc_in_ppc_yield];

+ 28 - 0
rtl/powerpc/intrinsics.pp

@@ -0,0 +1,28 @@
+{
+    Provides CPU intrinsics for PowerPC
+
+    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.

+ 16 - 0
rtl/powerpc64/cpuinnr.inc

@@ -0,0 +1,16 @@
+  {
+    Defines CPU intrinsic indicies for PowerPC64
+
+    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_ppc_yield = fpc_in_cpu_first+0;

+ 16 - 0
rtl/powerpc64/cpuprocs.inc

@@ -0,0 +1,16 @@
+{
+    Defines CPU intrinsics for PowerPC64
+
+    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_ppc_yield;[internproc:fpc_in_ppc_yield];

+ 28 - 0
rtl/powerpc64/intrinsics.pp

@@ -0,0 +1,28 @@
+{
+    Provides CPU intrinsics for PowerPC64
+
+    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.

+ 1 - 1
rtl/ps1/Makefile

@@ -2459,7 +2459,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/sinclairql/Makefile

@@ -2490,7 +2490,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/solaris/Makefile

@@ -2506,7 +2506,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/symbian/Makefile

@@ -2484,7 +2484,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 0 - 3
rtl/symbian/classes.pp

@@ -46,9 +46,6 @@ uses
 {$ifdef FPC_TESTGENERICS}
   fgl,
 {$endif}
-{$IF DEFINED(CPUARM) or DEFINED(CPUAARCH64) }
-  intrinsics,
-{$ENDIF}
   typinfo;
 {$ENDIF FPC_DOTTEDUNITS}
 

+ 28 - 3
rtl/unix/classes.pp

@@ -16,9 +16,20 @@
 {$mode objfpc}
 {$h+}
 {$modeswitch advancedrecords}
-{$IF FPC_FULLVERSION>=30301}
+{$if FPC_FULLVERSION>=30301}
 {$modeswitch FUNCTIONREFERENCES}
 {$define FPC_HAS_REFERENCE_PROCEDURE}
+{$ifndef CPULLVM}
+{$if DEFINED(CPUARM) or DEFINED(CPUAARCH64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPUPOWERPC) or defined(CPUPOWERPC64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPURISCV32) or defined(CPURISCV64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
 {$endif}
 { determine the type of the resource/form file }
 {$define Win16Res}
@@ -39,6 +50,9 @@ uses
   System.FGL,
 {$endif}
   System.RtlConsts,
+{$ifdef FPC_USE_INTRINSICS}
+  System.Intrinsics,
+{$endif}
   System.SortBase;
 {$ELSE FPC_DOTTEDUNITS}
 uses
@@ -49,12 +63,23 @@ uses
   fgl,
 {$endif}
   rtlconsts,
-{$IF DEFINED(CPUARM) or DEFINED(CPUAARCH64) }
+{$ifdef FPC_USE_INTRINSICS}
   intrinsics,
-{$ENDIF}
+{$endif}
   sortbase;
 {$ENDIF FPC_DOTTEDUNITS}
 
+{ Also set FPC_USE_INTRINSICS for i386 and x86_64,
+  but only after _USES clause as there
+  is not intinsics unit for those CPUs }
+{$IF FPC_FULLVERSION>=30301}
+{$ifndef CPULLVM}
+{$if defined(CPUI386) or defined(CPUX86_64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
+{$endif}
+
 {$i classesh.inc}
 
 implementation

+ 1 - 1
rtl/wasip1/Makefile

@@ -2470,7 +2470,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/wasip1threads/Makefile

@@ -2470,7 +2470,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/wasip2/Makefile

@@ -2466,7 +2466,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/watcom/Makefile

@@ -2497,7 +2497,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/wii/Makefile

@@ -2460,7 +2460,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/win16/Makefile

@@ -2496,7 +2496,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 1 - 1
rtl/win32/Makefile

@@ -2507,7 +2507,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 29 - 2
rtl/win32/classes.pp

@@ -19,6 +19,17 @@
 {$IF FPC_FULLVERSION>=30301}
 {$modeswitch FUNCTIONREFERENCES}
 {$define FPC_HAS_REFERENCE_PROCEDURE}
+{$ifndef CPULLVM}
+{$if DEFINED(CPUARM) or DEFINED(CPUAARCH64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPUPOWERPC) or defined(CPUPOWERPC64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPURISCV32) or defined(CPURISCV64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
 {$endif}
 
 { determine the type of the resource/form file }
@@ -40,6 +51,9 @@ uses
   System.FGL,
 {$endif}
   System.TypInfo,
+{$ifdef FPC_USE_INTRINSICS}
+  System.Intrinsics,
+{$endif}
   WinApi.Windows;
 {$ELSE FPC_DOTTEDUNITS}
 uses
@@ -51,12 +65,25 @@ uses
   fgl,
 {$endif}
   typinfo,
-{$IF DEFINED(CPUARM) or DEFINED(CPUAARCH64) }
+{$ifdef FPC_USE_INTRINSICS}
   intrinsics,
-{$ENDIF}
+{$endif}
   windows;
 {$ENDIF FPC_DOTTEDUNITS}
 
+{ Also set FPC_USE_INTRINSICS for i386 and x86_64,
+  but only after _USES clause as there
+  is not intinsics unit for those CPUs }
+{$IF FPC_FULLVERSION>=30301}
+{$ifndef CPULLVM}
+{$if defined(CPUI386) or defined(CPUX86_64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
+{$endif}
+
+{$i classesh.inc}
+
 type
   TWndMethod = procedure(var msg : TMessage) of object;
 

+ 1 - 1
rtl/win64/Makefile

@@ -2531,7 +2531,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 27 - 2
rtl/win64/classes.pp

@@ -19,6 +19,17 @@
 {$IF FPC_FULLVERSION>=30301}
 {$modeswitch FUNCTIONREFERENCES}
 {$define FPC_HAS_REFERENCE_PROCEDURE}
+{$ifndef CPULLVM}
+{$if DEFINED(CPUARM) or DEFINED(CPUAARCH64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPUPOWERPC) or defined(CPUPOWERPC64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPURISCV32) or defined(CPURISCV64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
 {$endif}
 
 { determine the type of the resource/form file }
@@ -40,6 +51,9 @@ uses
   System.FGL,
 {$endif}
   System.TypInfo,
+{$ifdef FPC_USE_INTRINSICS}
+  System.Intrinsics,
+{$endif}
   WinApi.Windows;
 {$ELSE FPC_DOTTEDUNITS}
 uses
@@ -51,12 +65,23 @@ uses
   fgl,
 {$endif}
   typinfo,
-{$IF DEFINED(CPUARM) or DEFINED(CPUAARCH64) }
+{$ifdef FPC_USE_INTRINSICS}
   intrinsics,
-{$ENDIF}
+{$endif}
   windows;
 {$ENDIF FPC_DOTTEDUNITS}
 
+{ Also set FPC_USE_INTRINSICS for i386 and x86_64,
+  but only after _USES clause as there
+  is not intinsics unit for those CPUs }
+{$IF FPC_FULLVERSION>=30301}
+{$ifndef CPULLVM}
+{$if defined(CPUI386) or defined(CPUX86_64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
+{$endif}
+
 type
   TWndMethod = procedure(var msg : TMessage) of object;
 

+ 1 - 1
rtl/wince/Makefile

@@ -2489,7 +2489,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

+ 27 - 2
rtl/wince/classes.pp

@@ -19,6 +19,17 @@
 {$IF FPC_FULLVERSION>=30301}
 {$modeswitch FUNCTIONREFERENCES}
 {$define FPC_HAS_REFERENCE_PROCEDURE}
+{$ifndef CPULLVM}
+{$if DEFINED(CPUARM) or DEFINED(CPUAARCH64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPUPOWERPC) or defined(CPUPOWERPC64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$if defined(CPURISCV32) or defined(CPURISCV64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
 {$endif}
 
 
@@ -41,6 +52,9 @@ uses
   System.FGL,
 {$endif}
   System.TypInfo,
+{$ifdef FPC_USE_INTRINSICS}
+  System.Intrinsics,
+{$endif}
   WinApi.Windows;
 {$ELSE FPC_DOTTEDUNITS}
 uses
@@ -52,12 +66,23 @@ uses
   fgl,
 {$endif}
   typinfo,
-{$IF DEFINED(CPUARM) or DEFINED(CPUAARCH64) }
+{$ifdef FPC_USE_INTRINSICS}
   intrinsics,
-{$ENDIF}
+{$endif}
   windows;
 {$ENDIF FPC_DOTTEDUNITS}
 
+{ Also set FPC_USE_INTRINSICS for i386 and x86_64,
+  but only after _USES clause as there
+  is not intinsics unit for those CPUs }
+{$IF FPC_FULLVERSION>=30301}
+{$ifndef CPULLVM}
+{$if defined(CPUI386) or defined(CPUX86_64)}
+   {$define FPC_USE_INTRINSICS}
+{$endif}
+{$endif}
+{$endif}
+
 type
   TWndMethod = procedure(var msg : TMessage) of object;
 

+ 1 - 1
rtl/zxspectrum/Makefile

@@ -2459,7 +2459,7 @@ sysutils$(PPUEXT) : $(SYSUTILS_DEPS)
 	$(COMPILER) -Fi$(OBJPASDIR)/sysutils $<
 System.SysUtils$(PPUEXT) : $(NSINC)/System.SysUtils.pp $(SYSUTILS_DEPS)
 	$(COMPILER) $(SYSUTILS_OPT) -Fi$(OBJPASDIR)/sysutils -Fi$(SYSUTILSDIR) $<
-ifneq ($(findstring $(ARCH),aarch64 arm),)
+ifneq ($(findstring $(ARCH),aarch64 arm powerpc powerpc64 riscv64 riscv32),)
 CLASSES_DEPS_CPU:=$(CLASSES_DEPS_CPU) $(INTRINSICSUNIT)$(PPUEXT)
 endif
 CLASSES_DEPS=$(CLASSESDIR)/classes.pp $(TTHREADINCDIR)/tthread.inc $(wildcard $(OBJPASDIR)/classes/*.inc) \

BIN
tests/test/cg/obj/linux/i386/tcext7.o


BIN
tests/test/cg/obj/linux/powerpc/tcext7.o


BIN
tests/test/cg/obj/linux/powerpc64-le/tcext7.o


BIN
tests/test/cg/obj/linux/powerpc64/tcext7.o


+ 3 - 3
tests/test/cg/obj/readme.txt

@@ -13,7 +13,7 @@ Win32 :  2.95.3-5 (cygwin special)
 Amiga :  GCC 2.91.66
  (long long/double support is buggy in this version of GCC, so it cannot be used)
 Linux-m68k :  GCC 2.95.4 and 3.0.4
-Linux-i386 : GCC 2.95.4 20011002 (Debian prerelease)
+Linux-i386 : GCC: (GNU) 4.4.1 to GCC: (Debian 12.2.0-14+deb12u1) 12.2.0
 
 NetBSD-m68k : GCC 2.95.3 on NetBSD elf 1.6
 
@@ -57,8 +57,8 @@ android-arm-eabi : GCC: (GNU) 4.7.A*
 solaris-sparc : GCC: (GNU) 5.5.0
 linux-arm : GCC: (GNU) 2.95.1 19990816 (release)
 linux-arm-eabi : GCC: (Debian 4.3.2-1) 4.3.2
-linux-powerpc : GCC: (GNU) 2.95.4 20011002 (Debian prerelease)
-linux-powerpc64 : GCC: (GNU) 3.3.3 (SuSE Linux)
+linux-powerpc : GCC: (GNU) 4.0.0 to (GNU) 4.8.5 20150623 (Red Hat 4.8.5-44)
+linux-powerpc64 : GCC: (GNU) 3.3.3 (SuSE Linux) to (GNU) 4.8.5 20150623 (Red Hat 4.8.5-44)
 linux-powerpc64-le : GCC: (Red Hat 4.9.2-1) 4.9.2 20141101
 linux-x86_64 : GCC: (GNU) 3.3.5 (Debian 1:3.3.5-8)
 Data retrieved from Dwarf producer information: