Selaa lähdekoodia

+ added abs(smallint) and abs(shortint) for cpus with 8-bit or 16-bit alu

git-svn-id: trunk@36327 -
nickysn 8 vuotta sitten
vanhempi
commit
fa645dcaf7
3 muutettua tiedostoa jossa 46 lisäystä ja 0 poistoa
  1. 6 0
      compiler/options.pas
  2. 24 0
      rtl/inc/generic.inc
  3. 16 0
      rtl/inc/systemh.inc

+ 6 - 0
compiler/options.pas

@@ -3378,6 +3378,12 @@ begin
   def_system_macro('FPC_VARIANTCOPY_FIXED');
   def_system_macro('FPC_DYNARRAYCOPY_FIXED');
 
+{$if defined(avr)}
+  def_system_macro('FPC_HAS_INTERNAL_ABS_SHORTINT');
+{$endif}
+{$if defined(i8086) or defined(avr)}
+  def_system_macro('FPC_HAS_INTERNAL_ABS_SMALLINT');
+{$endif i8086 or avr}
 { abs(long) is handled internally on all CPUs }
   def_system_macro('FPC_HAS_INTERNAL_ABS_LONG');
 {$if defined(x86_64) or defined(powerpc64) or defined(cpuaarch64)}

+ 24 - 0
rtl/inc/generic.inc

@@ -1889,6 +1889,30 @@ function fpc_mod_shortint(n,z : shortint) : shortint; [public,alias: 'FPC_MOD_SH
 
 {****************************************************************************}
 
+{$if defined(CPUINT8)}
+{$ifndef FPC_SYSTEM_HAS_ABS_SHORTINT}
+function abs(l:shortint):shortint;{$ifdef SYSTEMINLINE}inline;{$endif}
+begin
+   if l<0 then
+     abs:=-l
+   else
+     abs:=l;
+end;
+{$endif not FPC_SYSTEM_HAS_ABS_SMALLINT}
+{$endif CPUINT8}
+
+{$if defined(CPUINT16) or defined(CPUINT8)}
+{$ifndef FPC_SYSTEM_HAS_ABS_SMALLINT}
+function abs(l:smallint):smallint;{$ifdef SYSTEMINLINE}inline;{$endif}
+begin
+   if l<0 then
+     abs:=-l
+   else
+     abs:=l;
+end;
+{$endif not FPC_SYSTEM_HAS_ABS_SMALLINT}
+{$endif CPUINT16 or CPUINT8}
+
 {$ifndef FPC_SYSTEM_HAS_ABS_LONGINT}
 { This is only needed to bootstrap on SPARC targets
   (MIPS and m68k too, but they have no releases, so bootstrapping is not an issue) }

+ 16 - 0
rtl/inc/systemh.inc

@@ -847,6 +847,22 @@ Function  Random: extended;
 Procedure Randomize;
 {$endif FPC_HAS_FEATURE_RANDOM}
 
+{$if defined(CPUINT8)}
+  {$ifdef FPC_HAS_INTERNAL_ABS_SHORTINT}
+  {$define FPC_SYSTEM_HAS_ABS_SHORTINT}
+  Function abs(l:shortint):shortint;[internproc:fpc_in_abs_long];
+  {$else FPC_SYSTEM_HAS_ABS_SHORTINT}
+  Function abs(l:shortint):shortint;[internconst:fpc_in_const_abs];{$ifdef SYSTEMINLINE}inline;{$endif}
+  {$endif FPC_SYSTEM_HAS_ABS_SHORTINT}
+{$endif CPUINT8}
+{$if defined(CPUINT16) or defined(CPUINT8)}
+  {$ifdef FPC_HAS_INTERNAL_ABS_SMALLINT}
+  {$define FPC_SYSTEM_HAS_ABS_SMALLINT}
+  Function abs(l:smallint):smallint;[internproc:fpc_in_abs_long];
+  {$else FPC_HAS_INTERNAL_ABS_LONG}
+  Function abs(l:smallint):smallint;[internconst:fpc_in_const_abs];{$ifdef SYSTEMINLINE}inline;{$endif}
+  {$endif FPC_HAS_INTERNAL_ABS_LONG}
+{$endif CPUINT16 or CPUINT8}
 {$ifdef FPC_HAS_INTERNAL_ABS_LONG}
 {$define FPC_SYSTEM_HAS_ABS_LONGINT}
 Function abs(l:longint):longint;[internproc:fpc_in_abs_long];