From fa645dcaf75889fb2804caf2467983133852321b Mon Sep 17 00:00:00 2001 From: nickysn Date: Thu, 25 May 2017 14:14:18 +0000 Subject: [PATCH] + added abs(smallint) and abs(shortint) for cpus with 8-bit or 16-bit alu git-svn-id: trunk@36327 - --- compiler/options.pas | 6 ++++++ rtl/inc/generic.inc | 24 ++++++++++++++++++++++++ rtl/inc/systemh.inc | 16 ++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/compiler/options.pas b/compiler/options.pas index abeace7214..89308603bc 100644 --- a/compiler/options.pas +++ b/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)} diff --git a/rtl/inc/generic.inc b/rtl/inc/generic.inc index bd1c60b783..23e2abc263 100644 --- a/rtl/inc/generic.inc +++ b/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) } diff --git a/rtl/inc/systemh.inc b/rtl/inc/systemh.inc index 31bec25539..b25685a338 100644 --- a/rtl/inc/systemh.inc +++ b/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];