From b4e2bdce4a68e6e125a3f2cdad9147c72e3b6258 Mon Sep 17 00:00:00 2001 From: tecodev Date: Sun, 25 Jun 2006 22:17:57 +0000 Subject: [PATCH] * device/lib/pic/libm: NEW, added math library functions * device/lib/pic/libsdcc: NEW; added float support functions * device/lib/pic/{Makefile.in,configure.in,configure}: added libm/ * device/include/pic/{limits.h,errno.h,sdcc-lib.h,float.h,math.h}: NEW, added math related headers * device/include/asm/pic/features.h: NEW * src/pic/gen.c (emitpcode_real): emit warning on NULL pCodeOp, (popGet): allow larger offsets for AOP_PCODE, (genDataPointerSet): handle literals explicitly, more debug output, (genAssign): fixed for float using aopLiteral ;-) * src/pic/glue.c (pic14createInterruptVect): inserted pagesel before GOTO initialisation routine * src/pic/pcoderegs.c (pCodeRegMapLiveRangesInFlow): set wasUsed flag on registers, fixes #1469043 (local variables do not work) * src/pic/main.c (_pic14_do_link), * src/pic16/main.c (_pic16_linkEdit): use fullDstFileName if available git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4250 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 21 ++++++ device/include/asm/pic/features.h | 30 +++++++++ device/include/pic/errno.h | 37 +++++++++++ device/include/pic/float.h | 85 +++++++++++++++++++++++++ device/include/pic/limits.h | 51 +++++++++++++++ device/include/pic/math.h | 89 ++++++++++++++++++++++++++ device/include/pic/sdcc-lib.h | 26 ++++++++ device/lib/pic/Makefile.in | 2 +- device/lib/pic/configure | 16 +++-- device/lib/pic/configure.in | 3 +- device/lib/pic/libm/Makefile.in | 10 +++ device/lib/pic/libm/acosf.c | 35 ++++++++++ device/lib/pic/libm/asincosf.c | 86 +++++++++++++++++++++++++ device/lib/pic/libm/asinf.c | 36 +++++++++++ device/lib/pic/libm/atan2f.c | 49 ++++++++++++++ device/lib/pic/libm/atanf.c | 74 ++++++++++++++++++++++ device/lib/pic/libm/ceilf.c | 35 ++++++++++ device/lib/pic/libm/cosf.c | 33 ++++++++++ device/lib/pic/libm/coshf.c | 32 ++++++++++ device/lib/pic/libm/cotf.c | 45 +++++++++++++ device/lib/pic/libm/errno.c | 25 ++++++++ device/lib/pic/libm/expf.c | 90 ++++++++++++++++++++++++++ device/lib/pic/libm/fabsf.c | 36 +++++++++++ device/lib/pic/libm/floorf.c | 35 ++++++++++ device/lib/pic/libm/frexpf.c | 42 ++++++++++++ device/lib/pic/libm/ldexpf.c | 41 ++++++++++++ device/lib/pic/libm/log10f.c | 31 +++++++++ device/lib/pic/libm/logf.c | 71 +++++++++++++++++++++ device/lib/pic/libm/modff.c | 31 +++++++++ device/lib/pic/libm/powf.c | 35 ++++++++++ device/lib/pic/libm/sincosf.c | 90 ++++++++++++++++++++++++++ device/lib/pic/libm/sincoshf.c | 93 +++++++++++++++++++++++++++ device/lib/pic/libm/sinf.c | 33 ++++++++++ device/lib/pic/libm/sinhf.c | 32 ++++++++++ device/lib/pic/libm/sqrtf.c | 56 ++++++++++++++++ device/lib/pic/libm/tancotf.c | 89 ++++++++++++++++++++++++++ device/lib/pic/libm/tanf.c | 33 ++++++++++ device/lib/pic/libm/tanhf.c | 64 +++++++++++++++++++ device/lib/pic/libsdcc/fs2schar.c | 44 +++++++++++++ device/lib/pic/libsdcc/fs2sint.c | 45 +++++++++++++ device/lib/pic/libsdcc/fs2slong.c | 46 ++++++++++++++ device/lib/pic/libsdcc/fs2uchar.c | 41 ++++++++++++ device/lib/pic/libsdcc/fs2uint.c | 43 +++++++++++++ device/lib/pic/libsdcc/fs2ulong.c | 49 ++++++++++++++ device/lib/pic/libsdcc/fsadd.c | 102 ++++++++++++++++++++++++++++++ device/lib/pic/libsdcc/fsdiv.c | 99 +++++++++++++++++++++++++++++ device/lib/pic/libsdcc/fseq.c | 43 +++++++++++++ device/lib/pic/libsdcc/fsgt.c | 48 ++++++++++++++ device/lib/pic/libsdcc/fslt.c | 48 ++++++++++++++ device/lib/pic/libsdcc/fsmul.c | 81 ++++++++++++++++++++++++ device/lib/pic/libsdcc/fsneq.c | 50 +++++++++++++++ device/lib/pic/libsdcc/fssub.c | 48 ++++++++++++++ device/lib/pic/libsdcc/schar2fs.c | 38 +++++++++++ device/lib/pic/libsdcc/sint2fs.c | 38 +++++++++++ device/lib/pic/libsdcc/slong2fs.c | 41 ++++++++++++ device/lib/pic/libsdcc/uchar2fs.c | 38 +++++++++++ device/lib/pic/libsdcc/uint2fs.c | 38 +++++++++++ device/lib/pic/libsdcc/ulong2fs.c | 75 ++++++++++++++++++++++ src/pic/gen.c | 30 ++++++--- src/pic/glue.c | 1 + src/pic/main.c | 4 +- src/pic/pcoderegs.c | 1 + src/pic16/main.c | 4 +- 63 files changed, 2795 insertions(+), 22 deletions(-) create mode 100644 device/include/asm/pic/features.h create mode 100644 device/include/pic/errno.h create mode 100644 device/include/pic/float.h create mode 100644 device/include/pic/limits.h create mode 100644 device/include/pic/math.h create mode 100644 device/include/pic/sdcc-lib.h create mode 100644 device/lib/pic/libm/Makefile.in create mode 100644 device/lib/pic/libm/acosf.c create mode 100644 device/lib/pic/libm/asincosf.c create mode 100644 device/lib/pic/libm/asinf.c create mode 100644 device/lib/pic/libm/atan2f.c create mode 100644 device/lib/pic/libm/atanf.c create mode 100644 device/lib/pic/libm/ceilf.c create mode 100644 device/lib/pic/libm/cosf.c create mode 100644 device/lib/pic/libm/coshf.c create mode 100644 device/lib/pic/libm/cotf.c create mode 100644 device/lib/pic/libm/errno.c create mode 100644 device/lib/pic/libm/expf.c create mode 100644 device/lib/pic/libm/fabsf.c create mode 100644 device/lib/pic/libm/floorf.c create mode 100644 device/lib/pic/libm/frexpf.c create mode 100644 device/lib/pic/libm/ldexpf.c create mode 100644 device/lib/pic/libm/log10f.c create mode 100644 device/lib/pic/libm/logf.c create mode 100644 device/lib/pic/libm/modff.c create mode 100644 device/lib/pic/libm/powf.c create mode 100644 device/lib/pic/libm/sincosf.c create mode 100644 device/lib/pic/libm/sincoshf.c create mode 100644 device/lib/pic/libm/sinf.c create mode 100644 device/lib/pic/libm/sinhf.c create mode 100644 device/lib/pic/libm/sqrtf.c create mode 100644 device/lib/pic/libm/tancotf.c create mode 100644 device/lib/pic/libm/tanf.c create mode 100644 device/lib/pic/libm/tanhf.c create mode 100644 device/lib/pic/libsdcc/fs2schar.c create mode 100644 device/lib/pic/libsdcc/fs2sint.c create mode 100644 device/lib/pic/libsdcc/fs2slong.c create mode 100644 device/lib/pic/libsdcc/fs2uchar.c create mode 100644 device/lib/pic/libsdcc/fs2uint.c create mode 100644 device/lib/pic/libsdcc/fs2ulong.c create mode 100644 device/lib/pic/libsdcc/fsadd.c create mode 100644 device/lib/pic/libsdcc/fsdiv.c create mode 100644 device/lib/pic/libsdcc/fseq.c create mode 100644 device/lib/pic/libsdcc/fsgt.c create mode 100644 device/lib/pic/libsdcc/fslt.c create mode 100644 device/lib/pic/libsdcc/fsmul.c create mode 100644 device/lib/pic/libsdcc/fsneq.c create mode 100644 device/lib/pic/libsdcc/fssub.c create mode 100644 device/lib/pic/libsdcc/schar2fs.c create mode 100644 device/lib/pic/libsdcc/sint2fs.c create mode 100644 device/lib/pic/libsdcc/slong2fs.c create mode 100644 device/lib/pic/libsdcc/uchar2fs.c create mode 100644 device/lib/pic/libsdcc/uint2fs.c create mode 100644 device/lib/pic/libsdcc/ulong2fs.c diff --git a/ChangeLog b/ChangeLog index 7d2d2df6..8a261bd3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2006-06-25 Raphael Neider + + * device/lib/pic/libm: NEW, added math library functions + * device/lib/pic/libsdcc: NEW; added float support functions + * device/lib/pic/{Makefile.in,configure.in,configure}: added libm/ + * device/include/pic/{limits.h,errno.h,sdcc-lib.h,float.h,math.h}: + NEW, added math related headers + * device/include/asm/pic/features.h: NEW + * src/pic/gen.c (emitpcode_real): emit warning on NULL pCodeOp, + (popGet): allow larger offsets for AOP_PCODE, + (genDataPointerSet): handle literals explicitly, more debug output, + (genAssign): fixed for float using aopLiteral ;-) + * src/pic/glue.c (pic14createInterruptVect): inserted pagesel before + GOTO initialisation routine + * src/pic/pcoderegs.c (pCodeRegMapLiveRangesInFlow): set wasUsed + flag on registers, fixes #1469043 (local variables do not work) + * src/pic/main.c (_pic14_do_link), + * src/pic16/main.c (_pic16_linkEdit): use fullDstFileName if + available + 2006-06-25 Borut Razem * device/lib/pic16/libc/stdio/sprintf.c: return the number of @@ -29,6 +49,7 @@ * support/regression/ports/pic16/support.c: use gpsim usart module from libgpsim_modules library +>>>>>>> .r4249 2006-06-21 Jesus Calvino-Fraga * device/include/mcs51/at89c51ed2.h: Fixed bug 1510144 changed diff --git a/device/include/asm/pic/features.h b/device/include/asm/pic/features.h new file mode 100644 index 00000000..7bee4ec7 --- /dev/null +++ b/device/include/asm/pic/features.h @@ -0,0 +1,30 @@ +/* + * PIC14 port features. + * + * This file is part of the GNU PIC Library. + * + * June, 2006: adopted for pic14 + * Raphael Neider + * + * January, 2004 + * The GNU PIC Library is maintained by, + * Vangelis Rokas + * + * $Id: features.h 3714 2005-04-02 13:13:53Z vrokas $ + * + */ +#ifndef __PIC14_ASM_FEATURES_H +#define __PIC14_ASM_FEATURES_H 1 + +#define _REENTRANT + +#define _IL_REENTRANT +#define _FS_REENTRANT +#define _MATH_REENTRANT + +#define _CODE __code +#define _DATA __data +#define _AUTOMEM +#define _STATMEM + +#endif /* __PIC14_ASM_FEATURES_H */ diff --git a/device/include/pic/errno.h b/device/include/pic/errno.h new file mode 100644 index 00000000..93e72d62 --- /dev/null +++ b/device/include/pic/errno.h @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + errno.h: Error codes used in the math functions + + Ported to PIC16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr) + + Copyright (C) 2001 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------*/ + +/* +** $Id: errno.h 3912 2005-10-26 11:08:11Z tecodev $ +*/ + +#ifndef _PIC14_ERRNO_H +#define _PIC14_ERRNO_H + +extern int errno; + +/* Error Codes: */ + +#define EDOM 33 /* Math argument out of domain of functions */ +#define ERANGE 34 /* Math result not representable */ + +#endif /* _PIC14_ERRNO_H */ diff --git a/device/include/pic/float.h b/device/include/pic/float.h new file mode 100644 index 00000000..03d358b9 --- /dev/null +++ b/device/include/pic/float.h @@ -0,0 +1,85 @@ +/*------------------------------------------------------------------------- + float.h - ANSI functions forward declarations + + Adopted for pic16 port library by Vangelis Rokas + [vrokas at otenet.gr] (2004) + + Adopted for pic14 port library by Raphael Neider + [rneider at web.de] (2006) + + Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998) + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + 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. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! +-------------------------------------------------------------------------*/ + +#ifndef __PIC14_FLOAT_H +#define __PIC14_FLOAT_H 1 + +#include +#include + +#define FLT_RADIX 2 +#define FLT_MANT_DIG 24 +#define FLT_EPSILON 1.192092896E-07F +#define FLT_DIG 6 +#define FLT_MIN_EXP (-125) +#define FLT_MIN 1.175494351E-38F +#define FLT_MIN_10_EXP (-37) +#define FLT_MAX_EXP (+128) +#define FLT_MAX 3.402823466E+38F +#define FLT_MAX_10_EXP (+38) + +/* the following deal with IEEE single-precision numbers */ +#define EXCESS 126 +#define SIGNBIT ((unsigned long)0x80000000) +#define HIDDEN (unsigned long)(1ul << 23) +#define SIGN(fp) (((unsigned long)(fp) >> (8*sizeof(fp)-1)) & 1) +#define EXP(fp) (((unsigned long)(fp) >> 23) & (unsigned int) 0x00FF) +#define MANT(fp) (((fp) & (unsigned long)0x007FFFFF) | HIDDEN) +#define NORM 0xff000000 +#define PACK(s,e,m) ((s) | ((unsigned long)(e) << 23) | (m)) + +/* Workaround for unhandled local variables. */ +#define FS_STATIC /*static*/ + + +float __uchar2fs (unsigned char) _FS_REENTRANT; +float __schar2fs (signed char) _FS_REENTRANT; +float __uint2fs (unsigned int) _FS_REENTRANT; +float __sint2fs (signed int) _FS_REENTRANT; +float __ulong2fs (unsigned long) _FS_REENTRANT; +float __slong2fs (signed long) _FS_REENTRANT; +unsigned char __fs2uchar (float) _FS_REENTRANT; +signed char __fs2schar (float) _FS_REENTRANT; +unsigned int __fs2uint (float) _FS_REENTRANT; +signed int __fs2sint (float) _FS_REENTRANT; +unsigned long __fs2ulong (float) _FS_REENTRANT; +signed long __fs2slong (float) _FS_REENTRANT; + +float __fsadd (float, float) _FS_REENTRANT; +float __fssub (float, float) _FS_REENTRANT; +float __fsmul (float, float) _FS_REENTRANT; +float __fsdiv (float, float) _FS_REENTRANT; + +char __fslt (float, float) _FS_REENTRANT; +char __fseq (float, float) _FS_REENTRANT; +char __fsneq (float, float) _FS_REENTRANT; +char __fsgt (float, float) _FS_REENTRANT; + +#endif /* __PIC14_FLOAT_H */ diff --git a/device/include/pic/limits.h b/device/include/pic/limits.h new file mode 100644 index 00000000..c928ff45 --- /dev/null +++ b/device/include/pic/limits.h @@ -0,0 +1,51 @@ +/*------------------------------------------------------------------------- + limits.h - ANSI defines constants for sizes of integral types + + Adopted for the pic16 port by Vangelis Rokas + [ vrokas at otenet.gr ] 2004 + + Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999) + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + 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. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! +-------------------------------------------------------------------------*/ + +#ifndef __LIMITS_H +#define __LIMITS_H 1 + +#define CHAR_BIT 8 /* bits in a char */ +#define CHAR_MAX 127 +#define CHAR_MIN -128 +#define SCHAR_MAX CHAR_MAX +#define SCHAR_MIN CHAR_MIN +#define UCHAR_MAX 0xff +#define UCHAR_MIN 0 +#define INT_MIN -32768 +#define INT_MAX 32767 +#define SHRT_MAX INT_MAX +#define SHRT_MIN INT_MIN +#define UINT_MAX 0xffff +#define UINT_MIN 0 +#define USHRT_MAX UINT_MAX +#define USHRT_MIN UINT_MIN +#define LONG_MIN -2147483648 +#define LONG_MAX 2147483647 +#define ULONG_MAX 0xffffffff +#define ULONG_MIN 0 + +#endif diff --git a/device/include/pic/math.h b/device/include/pic/math.h new file mode 100644 index 00000000..b93d4123 --- /dev/null +++ b/device/include/pic/math.h @@ -0,0 +1,89 @@ +/*------------------------------------------------------------------------- + math.h: Floating point math function declarations + + Ported to PIC16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr) + Adopted for the PIC14 port 2006 by Raphael Neider + + Copyright (C) 2001 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------*/ + +/* +** $Id: math.h 3648 2005-01-22 18:02:16Z vrokas $ +*/ + + +#ifndef __PIC14_MATH_H +#define __PIC14_MATH_H 1 + +#include + +#define PI 3.1415926536 +#define TWO_PI 6.2831853071 +#define HALF_PI 1.5707963268 +#define QUART_PI 0.7853981634 +#define iPI 0.3183098862 +#define iTWO_PI 0.1591549431 +#define TWO_O_PI 0.6366197724 + +// EPS=B**(-t/2), where B is the radix of the floating-point representation +// and there are t base-B digits in the significand. Therefore, for floats +// EPS=2**(-12). Also define EPS2=EPS*EPS. +#define EPS 244.14062E-6 +#define EPS2 59.6046E-9 +#define XMAX 3.402823466E+38 + +union float_long +{ + float f; + long l; +}; + +/********************************************** + * Prototypes for float ANSI C math functions * + **********************************************/ + +/* Trigonometric functions */ +float sinf(const float x) _MATH_REENTRANT; +float cosf(const float x) _MATH_REENTRANT; +float tanf(const float x) _MATH_REENTRANT; +float cotf(const float x) _MATH_REENTRANT; +float asinf(const float x) _MATH_REENTRANT; +float acosf(const float x) _MATH_REENTRANT; +float atanf(const float x) _MATH_REENTRANT; +float atan2f(const float x, const float y); + +/* Hyperbolic functions */ +float sinhf(const float x) _MATH_REENTRANT; +float coshf(const float x) _MATH_REENTRANT; +float tanhf(const float x) _MATH_REENTRANT; + +/* Exponential, logarithmic and power functions */ +float expf(const float x); +float logf(const float x) _MATH_REENTRANT; +float log10f(const float x) _MATH_REENTRANT; +float powf(const float x, const float y); +float sqrtf(const float a) _MATH_REENTRANT; + +/* Nearest integer, absolute value, and remainder functions */ +float fabsf(const float x) _MATH_REENTRANT; +float frexpf(const float x, int *pw2); +float ldexpf(const float x, const int pw2); +float ceilf(float x) _MATH_REENTRANT; +float floorf(float x) _MATH_REENTRANT; +float modff(float x, float * y); + +#endif /* __PIC14_MATH_H */ diff --git a/device/include/pic/sdcc-lib.h b/device/include/pic/sdcc-lib.h new file mode 100644 index 00000000..df9f8ed7 --- /dev/null +++ b/device/include/pic/sdcc-lib.h @@ -0,0 +1,26 @@ + +/* + * sdcc-lib.h - SDCC Library Main Header + * + * This file is part of the GNU PIC Library. + * + * June, 2600: adopted for pic14 + * Raphael Neider + * + * January, 2004 + * The GNU PIC Library is maintained by, + * Vangelis Rokas + * + * $Id: sdcc-lib.h 3512 2004-10-01 14:32:06Z vrokas $ + * + */ + +/** Top level header file for the sdcc libraries that enables target + specific features. +*/ +#ifndef __PIC14_SDCC_LIB_H +#define __PIC14_SDCC_LIB_H 1 + +#include <../asm/pic/features.h> + +#endif /* __PIC14_SDCC_LIB_H */ diff --git a/device/lib/pic/Makefile.in b/device/lib/pic/Makefile.in index 98b59546..d0b549e1 100644 --- a/device/lib/pic/Makefile.in +++ b/device/lib/pic/Makefile.in @@ -29,7 +29,7 @@ all % : else -SUBDIRS = libsdcc libdev +SUBDIRS = libsdcc libdev libm builddir = build installdir = bin export installdir diff --git a/device/lib/pic/configure b/device/lib/pic/configure index ec95ff66..c13ef764 100755 --- a/device/lib/pic/configure +++ b/device/lib/pic/configure @@ -867,7 +867,7 @@ esac else echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi - cd $ac_popdir + cd "$ac_popdir" done fi @@ -1634,7 +1634,7 @@ fi # Checks for library functions. - ac_config_files="$ac_config_files Makefile Makefile.common libdev/Makefile libsdcc/Makefile" + ac_config_files="$ac_config_files Makefile Makefile.common libdev/Makefile libsdcc/Makefile libm/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -2190,6 +2190,7 @@ do "Makefile.common" ) CONFIG_FILES="$CONFIG_FILES Makefile.common" ;; "libdev/Makefile" ) CONFIG_FILES="$CONFIG_FILES libdev/Makefile" ;; "libsdcc/Makefile" ) CONFIG_FILES="$CONFIG_FILES libsdcc/Makefile" ;; + "libm/Makefile" ) CONFIG_FILES="$CONFIG_FILES libm/Makefile" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 echo "$as_me: error: invalid argument: $ac_config_target" >&2;} { (exit 1); exit 1; }; };; @@ -2449,11 +2450,6 @@ esac - if test x"$ac_file" != x-; then - { echo "$as_me:$LINENO: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - rm -f "$ac_file" - fi # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ @@ -2492,6 +2488,12 @@ echo "$as_me: error: cannot find input file: $f" >&2;} fi;; esac done` || { (exit 1); exit 1; } + + if test x"$ac_file" != x-; then + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + rm -f "$ac_file" + fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF sed "$ac_vpsub diff --git a/device/lib/pic/configure.in b/device/lib/pic/configure.in index 53fe3b79..7b22ec84 100644 --- a/device/lib/pic/configure.in +++ b/device/lib/pic/configure.in @@ -47,5 +47,6 @@ AC_PROG_MAKE_SET AC_CONFIG_FILES([Makefile Makefile.common libdev/Makefile - libsdcc/Makefile]) + libsdcc/Makefile + libm/Makefile]) AC_OUTPUT diff --git a/device/lib/pic/libm/Makefile.in b/device/lib/pic/libm/Makefile.in new file mode 100644 index 00000000..ec178a60 --- /dev/null +++ b/device/lib/pic/libm/Makefile.in @@ -0,0 +1,10 @@ +top_builddir=@top_builddir@ +top_srcdir=@top_srcdir@ + +VPATH = @srcdir@ +srcdir = @srcdir@ + +SUBDIRS = +MKLIB = libm.lib + +include $(top_srcdir)/Makefile.subdir diff --git a/device/lib/pic/libm/acosf.c b/device/lib/pic/libm/acosf.c new file mode 100644 index 00000000..c6993805 --- /dev/null +++ b/device/lib/pic/libm/acosf.c @@ -0,0 +1,35 @@ +/* acosf.c: Computes arc cosine of a 32-bit float + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: acosf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include + +float asincosf(const float x, const int isacos); + +float acosf(const float x) _MATH_REENTRANT +{ + if(x== 1.0) return 0.0; + else if(x==-1.0) return PI; + else if(x== 0.0) return HALF_PI; + return asincosf(x,1); +} diff --git a/device/lib/pic/libm/asincosf.c b/device/lib/pic/libm/asincosf.c new file mode 100644 index 00000000..cad72b75 --- /dev/null +++ b/device/lib/pic/libm/asincosf.c @@ -0,0 +1,86 @@ +/* asincosf.c: Computes asin or acos of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: asincosf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + + +#include +#include + +#define P1 0.933935835E+0 +#define P2 -0.504400557E+0 +#define Q0 0.560363004E+1 +#define Q1 -0.554846723E+1 +#define Q2 0.100000000E+1 + +#define P(g) (P2*g+P1) +#define Q(g) ((Q2*g+Q1)*g+Q0) + +float asincosf(const float x, const int isacos) +{ + float y, g, r; + int i; + + static const float a[2]={ 0.0, QUART_PI }; + static const float b[2]={ HALF_PI, QUART_PI }; + + y=fabsf(x); + i=isacos; + if (y < EPS) r=y; + else + { + if (y > 0.5) + { + i=1-i; + if (y > 1.0) + { + errno=EDOM; + return 0.0; + } + g=(0.5-y)+0.5; + g=ldexpf(g,-1); + y=sqrtf(g); + y=-(y+y); + } + else + { + g=y*y; + } + r=y+y*((P(g)*g)/Q(g)); + } + if (isacos) + { + if (x < 0.0) + r=(b[i]+r)+b[i]; + else + r=(a[i]-r)+a[i]; + } + else + { + r=(a[i]+r)+a[i]; + if (x<0.0) r=-r; + } + return r; +} diff --git a/device/lib/pic/libm/asinf.c b/device/lib/pic/libm/asinf.c new file mode 100644 index 00000000..869e0f50 --- /dev/null +++ b/device/lib/pic/libm/asinf.c @@ -0,0 +1,36 @@ +/* asinf.c: Computes asin(x) + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: asinf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include + +float asincosf(const float x, const int isacos); + +float asinf(const float x) _MATH_REENTRANT +{ + if(x== 1.0) return HALF_PI; + else if(x==-1.0) return -HALF_PI; + else if(x== 0.0) return 0.0; + else return asincosf(x,0); +} + diff --git a/device/lib/pic/libm/atan2f.c b/device/lib/pic/libm/atan2f.c new file mode 100644 index 00000000..2e0a4fbb --- /dev/null +++ b/device/lib/pic/libm/atan2f.c @@ -0,0 +1,49 @@ +/* atan2f.c: Computes atan2(x) where x is a 32-bit float. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: atan2f.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include + +float atan2f(const float x, const float y) +{ + float r; + + if ((x==0.0) && (y==0.0)) + { + errno=EDOM; + return 0.0; + } + + if(fabsf(y)>=fabsf(x)) + { + r=atanf(x/y); + if(y<0.0) r+=(x>=0?PI:-PI); + } + else + { + r=-atanf(y/x); + r+=(x<0.0?-HALF_PI:HALF_PI); + } + return r; +} diff --git a/device/lib/pic/libm/atanf.c b/device/lib/pic/libm/atanf.c new file mode 100644 index 00000000..5192e2a6 --- /dev/null +++ b/device/lib/pic/libm/atanf.c @@ -0,0 +1,74 @@ +/* atanf.c: Computes arctan of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: atanf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include + +#define P0 -0.4708325141E+0 +#define P1 -0.5090958253E-1 +#define Q0 0.1412500740E+1 +#define Q1 0.1000000000E+1 + +#define P(g,f) ((P1*g+P0)*g*f) +#define Q(g) (Q1*g+Q0) + +#define K1 0.2679491924 /* 2-sqrt(3) */ +#define K2 0.7320508076 /* sqrt(3)-1 */ +#define K3 1.7320508076 /* sqrt(3) */ + +float atanf(const float x) _MATH_REENTRANT +{ + float f, r, g; + int n=0; + static float a[]={ 0.0, 0.5235987756, 1.5707963268, 1.0471975512 }; + + f=fabsf(x); + if(f>1.0) + { + f=1.0/f; + n=2; + } + if(f>K1) + { + f=((K2*f-1.0)+f)/(K3+f); + // What it is actually wanted is this more accurate formula, + // but SDCC optimizes it and then it does not work: + // f=(((K2*f-0.5)-0.5)+f)/(K3+f); + n++; + } + if(fabsf(f)1) r=-r; + r+=a[n]; + if(x<0.0) r=-r; + return r; +} + diff --git a/device/lib/pic/libm/ceilf.c b/device/lib/pic/libm/ceilf.c new file mode 100644 index 00000000..598630e6 --- /dev/null +++ b/device/lib/pic/libm/ceilf.c @@ -0,0 +1,35 @@ +/* ceilf.c: Returns the integer larger or equal than x + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: ceilf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include + +float ceilf(float x) _MATH_REENTRANT +{ + long r; + r=x; + if (r<0) + return r; + else + return (r+((r + +float sincosf(float x, int iscos); + +float cosf(float x) _MATH_REENTRANT +{ + if (x==0.0) return 1.0; + return sincosf(x, 1); +} diff --git a/device/lib/pic/libm/coshf.c b/device/lib/pic/libm/coshf.c new file mode 100644 index 00000000..1acdf2e1 --- /dev/null +++ b/device/lib/pic/libm/coshf.c @@ -0,0 +1,32 @@ +/* coshf.c: Computes cosh(x) where x is a 32-bit float. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: coshf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include + +float sincoshf(const float x, const int iscosh); + +float coshf(const float x) _MATH_REENTRANT +{ + return sincoshf(x, 1); +} diff --git a/device/lib/pic/libm/cotf.c b/device/lib/pic/libm/cotf.c new file mode 100644 index 00000000..ae3090b1 --- /dev/null +++ b/device/lib/pic/libm/cotf.c @@ -0,0 +1,45 @@ +/* cotf.c: Computes cot(x) where x is a 32-bit float. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: cotf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include + +float tancotf(const float x, const int iscot); + +float cotf(const float x) _MATH_REENTRANT +{ + float y; + + y=fabsf(x); + if (y<1.0E-30) //This one requires more thinking... + { + errno = ERANGE; + if (x<0.0) + return -XMAX; + else + return XMAX; + } + return tancotf(x, 1); +} + diff --git a/device/lib/pic/libm/errno.c b/device/lib/pic/libm/errno.c new file mode 100644 index 00000000..2a33a842 --- /dev/null +++ b/device/lib/pic/libm/errno.c @@ -0,0 +1,25 @@ +/*------------------------------------------------------------------------- + + errno.c :- just declares errno as a variable + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library 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. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +-------------------------------------------------------------------------*/ + +/* +** $Id: errno.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +int errno; diff --git a/device/lib/pic/libm/expf.c b/device/lib/pic/libm/expf.c new file mode 100644 index 00000000..6f74e935 --- /dev/null +++ b/device/lib/pic/libm/expf.c @@ -0,0 +1,90 @@ +/* expf.c: Computes e**x of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: expf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include + +#define P0 0.2499999995E+0 +#define P1 0.4160288626E-2 +#define Q0 0.5000000000E+0 +#define Q1 0.4998717877E-1 + +#define P(z) ((P1*z)+P0) +#define Q(z) ((Q1*z)+Q0) + +#define C1 0.693359375 +#define C2 -2.1219444005469058277e-4 + +#define BIGX 88.72283911 /* ln(XMAX) */ +#define EXPEPS 1.0E-7 /* exp(1.0E-7)=0.0000001 */ +#define K1 1.4426950409 /* 1/ln(2) */ + +float expf(const float x) +{ + int n; + float xn, g, r, z, y; + char sign; + + if(x>=0.0) + { y=x; sign=0; } + else + { y=-x; sign=1; } + + if(yBIGX) + { + if(sign) + { + errno=ERANGE; + return XMAX; + } + else + { + return 0.0; + } + } + + z=y*K1; + n=z; + + if(n<0) --n; + if(z-n>=0.5) ++n; + xn=n; + g=((y-xn*C1))-xn*C2; + z=g*g; + r=P(z)*g; + r=0.5+(r/(Q(z)-r)); + + n++; + z=ldexpf(r, n); + if(sign) + return 1.0/z; + else + return z; +} + diff --git a/device/lib/pic/libm/fabsf.c b/device/lib/pic/libm/fabsf.c new file mode 100644 index 00000000..2d4fe796 --- /dev/null +++ b/device/lib/pic/libm/fabsf.c @@ -0,0 +1,36 @@ +/* fabsf.c: Returns the absolute value of a 32-bit float. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: fabsf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include +#include + +float fabsf(const float x) _MATH_REENTRANT +{ + FS_STATIC union float_long fl; + + fl.f = x; + fl.l &= 0x7fffffff; + return fl.f; +} diff --git a/device/lib/pic/libm/floorf.c b/device/lib/pic/libm/floorf.c new file mode 100644 index 00000000..6eeb708b --- /dev/null +++ b/device/lib/pic/libm/floorf.c @@ -0,0 +1,35 @@ +/* floorf.c: Returns the integer smaller or equal than x + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: floorf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include + +float floorf (float x) _MATH_REENTRANT +{ + long r; + r=x; + if (r<=0) + return (r+((r>x)?-1:0)); + else + return r; +} diff --git a/device/lib/pic/libm/frexpf.c b/device/lib/pic/libm/frexpf.c new file mode 100644 index 00000000..36fe3503 --- /dev/null +++ b/device/lib/pic/libm/frexpf.c @@ -0,0 +1,42 @@ +/* frexpf.c: Returns the exponent and mantisa of a 32 bit float. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: frexpf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include +#include + +float frexpf(const float x, int *pw2) +{ + FS_STATIC union float_long fl; + long int i; + + fl.f=x; + /* Find the exponent (power of 2) */ + i = ( fl.l >> 23) & 0x000000ff; + i -= 0x7e; + *pw2 = i; + fl.l &= 0x807fffff; /* strip all exponent bits */ + fl.l |= 0x3f000000; /* mantissa between 0.5 and 1 */ + return(fl.f); +} diff --git a/device/lib/pic/libm/ldexpf.c b/device/lib/pic/libm/ldexpf.c new file mode 100644 index 00000000..014dec54 --- /dev/null +++ b/device/lib/pic/libm/ldexpf.c @@ -0,0 +1,41 @@ +/* ldexpf.c: Build a float from a mantisa and exponent. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: ldexpf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include +#include + +float ldexpf(const float x, const int pw2) +{ + FS_STATIC union float_long fl; + long e; + + fl.f = x; + + e=(fl.l >> 23) & 0x000000ff; + e+=pw2; + fl.l= ((e & 0xff) << 23) | (fl.l & 0x807fffff); + + return(fl.f); +} diff --git a/device/lib/pic/libm/log10f.c b/device/lib/pic/libm/log10f.c new file mode 100644 index 00000000..03d50443 --- /dev/null +++ b/device/lib/pic/libm/log10f.c @@ -0,0 +1,31 @@ +/* log10f.c: Computes the base 10 log of a 32 bit float. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: log10f.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include + +float log10f(const float x) _MATH_REENTRANT +{ + return logf(x)*0.4342944819; +} diff --git a/device/lib/pic/libm/logf.c b/device/lib/pic/libm/logf.c new file mode 100644 index 00000000..0ba3f8b3 --- /dev/null +++ b/device/lib/pic/libm/logf.c @@ -0,0 +1,71 @@ +/* logf.c: Computes the natural log of a 32 bit float as outlined in [1]. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: logf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include +#include + +/*Constans for 24 bits or less (8 decimal digits)*/ +#define A0 -0.5527074855E+0 +#define B0 -0.6632718214E+1 +#define A(w) (A0) +#define B(w) (w+B0) + +#define C0 0.70710678118654752440 +#define C1 0.693359375 /*355.0/512.0*/ +#define C2 -2.121944400546905827679E-4 + +float logf(const float x) _MATH_REENTRANT +{ + float Rz; + float f, z, w, znum, zden, xn; + FS_STATIC int n; + + if (x<=0.0) + { + errno=EDOM; + return 0.0; + } + f=frexpf(x, &n); + znum=f-0.5; + if (f>C0) + { + znum-=0.5; + zden=(f*0.5)+0.5; + } + else + { + n--; + zden=znum*0.5+0.5; + } + z=znum/zden; + w=z*z; + + Rz=z+z*(w*A(w)/B(w)); + xn=n; + return ((xn*C2+Rz)+xn*C1); +} diff --git a/device/lib/pic/libm/modff.c b/device/lib/pic/libm/modff.c new file mode 100644 index 00000000..3aae5fd1 --- /dev/null +++ b/device/lib/pic/libm/modff.c @@ -0,0 +1,31 @@ +/* modff.c: Returns both the integer and fraction of a float. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: modff.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include + +float modff(float x, float * y) +{ + *y=((int)x); + return (x-*y); +} diff --git a/device/lib/pic/libm/powf.c b/device/lib/pic/libm/powf.c new file mode 100644 index 00000000..b6b941eb --- /dev/null +++ b/device/lib/pic/libm/powf.c @@ -0,0 +1,35 @@ +/* powf.c: Computes x**y where x and y are 32-bit floats. + WARNING: less that 6 digits accuracy. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: powf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include + +float powf(const float x, const float y) +{ + if(y == 0.0) return 1.0; + if(y==1.0) return x; + if(x <= 0.0) return 0.0; + return expf(logf(x) * y); +} diff --git a/device/lib/pic/libm/sincosf.c b/device/lib/pic/libm/sincosf.c new file mode 100644 index 00000000..5a741567 --- /dev/null +++ b/device/lib/pic/libm/sincosf.c @@ -0,0 +1,90 @@ +/* sincosf.c: Computes sin or cos of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: sincosf.c 3714 2005-04-02 13:13:53Z vrokas $ +*/ + +#include +#include + +#define r1 (-0.1666665668E+0) +#define r2 (0.8333025139E-2) +#define r3 (-0.1980741872E-3) +#define r4 (0.2601903036E-5) + +/* PI=C1+C2 */ +#define C1 3.140625 +#define C2 9.676535897E-4 + +/*A reasonable value for YMAX is the int part of PI*B**(t/2)=3.1416*2**(12)*/ +#define YMAX 12867.0 + +float sincosf(float x, int iscos) +{ + float y, f, r, g, XN; + int N; + char sign; + + if(iscos) + { + y=fabsf(x)+HALF_PI; + sign=0; + } + else + { + if(x<0.0) + { y=-x; sign=1; } + else + { y=x; sign=0; } + } + + if(y>YMAX) + { + errno=ERANGE; + return 0.0; + } + + /*Round y/PI to the nearest integer*/ + N=((y*iPI)+0.5); /*y is positive*/ + + /*If N is odd change sign*/ + if(N&1) sign=!sign; + + XN=N; + /*Cosine required? (is done here to keep accuracy)*/ + if(iscos) XN-=0.5; + + y=fabsf(x); + r=(int)y; + g=y-r; + f=((r-XN*C1)+g)-XN*C2; + + g=f*f; + if(g>EPS2) //Used to be if(fabsf(f)>EPS) + { + r=(((r4*g+r3)*g+r2)*g+r1)*g; + f+=f*r; + } + return (sign?-f:f); +} diff --git a/device/lib/pic/libm/sincoshf.c b/device/lib/pic/libm/sincoshf.c new file mode 100644 index 00000000..1043bdc2 --- /dev/null +++ b/device/lib/pic/libm/sincoshf.c @@ -0,0 +1,93 @@ +/* sincoshf.c: Computes sinh or cosh of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: sincoshf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include + +#define P0 -0.713793159E+1 +#define P1 -0.190333999E+0 +#define Q0 -0.428277109E+2 +#define Q1 0.100000000E+1 + +#define P(z) (P1*z+P0) +#define Q(z) (Q1*z+Q0) + +#define K1 0.69316101074218750000E+0 /* ln(v) */ +#define K2 0.24999308500451499336E+0 /* v**(-2) */ +#define K3 0.13830277879601902638E-4 /* v/2-1 */ + +//WMAX is defined as ln(XMAX)-ln(v)+0.69 +#define WMAX 44.93535952E+0 +//WBAR 0.35*(b+1) +#define WBAR 1.05 +#define YBAR 9.0 /*Works for me*/ + +float sincoshf(const float x, const int iscosh) +{ + float y, w, z; + char sign; + + if (x<0.0) { y=-x; sign=1; } + else { y=x; sign=0; } + + if ((y>1.0) || iscosh) + { + if(y>YBAR) + { + w=y-K1; + if (w>WMAX) + { + errno=ERANGE; + z=XMAX; + } + else + { + z=expf(w); + z+=K3*z; + } + } + else + { + z=expf(y); + w=1.0/z; + if(!iscosh) w=-w; + z=(z+w)*0.5; + } + if(sign) z=-z; + } + else + { + if (y + +float sincosf(float x, int iscos); + +float sinf(float x) _MATH_REENTRANT +{ + if (x==0.0) return 0.0; + return sincosf(x, 0); +} diff --git a/device/lib/pic/libm/sinhf.c b/device/lib/pic/libm/sinhf.c new file mode 100644 index 00000000..5d81c5fa --- /dev/null +++ b/device/lib/pic/libm/sinhf.c @@ -0,0 +1,32 @@ +/* sinhf.c: Computes sinh(x) where x is a 32-bit float. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: sinhf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include + +float sincoshf(const float x, const int iscosh); + +float sinhf(const float x) _MATH_REENTRANT +{ + return sincoshf(x, 0); +} diff --git a/device/lib/pic/libm/sqrtf.c b/device/lib/pic/libm/sqrtf.c new file mode 100644 index 00000000..a35e6009 --- /dev/null +++ b/device/lib/pic/libm/sqrtf.c @@ -0,0 +1,56 @@ +/* sqrtf.c: Computes square root of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: sqrtf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include +#include + +float sqrtf(const float x) _MATH_REENTRANT +{ + float f, y; + FS_STATIC int n; + + if (x==0.0) return x; + else if (x==1.0) return 1.0; + else if (x<0.0) + { + errno=EDOM; + return 0.0; + } + f=frexpf(x, &n); + y=0.41731+0.59016*f; /*Educated guess*/ + /*For a 24 bit mantisa (float), two iterations are sufficient*/ + y+=f/y; + y=ldexpf(y, -2) + f/y; /*Faster version of 0.25 * y + f/y*/ + + if (n&1) + { + y*=0.7071067812; + ++n; + } + return ldexpf(y, n/2); +} diff --git a/device/lib/pic/libm/tancotf.c b/device/lib/pic/libm/tancotf.c new file mode 100644 index 00000000..60e3ada7 --- /dev/null +++ b/device/lib/pic/libm/tancotf.c @@ -0,0 +1,89 @@ +/* tancotf.c: Computes tan or cot of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: tancotf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include + +#define P0 0.100000000E+1 +#define P1 -0.958017723E-1 +#define Q0 0.100000000E+1 +#define Q1 -0.429135777E+0 +#define Q2 0.971685835E-2 + +#define C1 1.5703125 +#define C2 4.83826794897E-4 + +#define P(f,g) (P1*g*f+f) +#define Q(g) ((Q2*g+Q1)*g+Q0) + +//A reasonable choice for YMAX is the integer part of B**(t/2)*PI/2: +#define YMAX 6433.0 + +float tancotf(const float x, const int iscotan) +{ + float f, g, xn, xnum, xden; + int n; + + if (fabsf(x) > YMAX) + { + errno = ERANGE; + return 0.0; + } + + /*Round x*2*PI to the nearest integer*/ + n=(x*TWO_O_PI+(x>0.0?0.5:-0.5)); /*works for +-x*/ + xn=n; + + xnum=(int)x; + xden=x-xnum; + f=((xnum-xn*C1)+xden)-xn*C2; + + if (fabsf(f) < EPS) + { + xnum = f; + xden = 1.0; + } + else + { + g = f*f; + xnum = P(f,g); + xden = Q(g); + } + + if(n&1) + //xn is odd + { + if(iscotan) return (-xnum/xden); + else return (-xden/xnum); + } + else + { + if(iscotan) return (xden/xnum); + else return (xnum/xden); + } +} + diff --git a/device/lib/pic/libm/tanf.c b/device/lib/pic/libm/tanf.c new file mode 100644 index 00000000..4e1bcfa2 --- /dev/null +++ b/device/lib/pic/libm/tanf.c @@ -0,0 +1,33 @@ +/* tanf.c: Computes tan(x) where x is a 32-bit float. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: tanf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include + +float tancotf(const float x, const int iscot); + +float tanf(const float x) _MATH_REENTRANT +{ + return tancotf(x, 0); +} + diff --git a/device/lib/pic/libm/tanhf.c b/device/lib/pic/libm/tanhf.c new file mode 100644 index 00000000..d46a8b01 --- /dev/null +++ b/device/lib/pic/libm/tanhf.c @@ -0,0 +1,64 @@ +/* tanhf.c: Computes tanh(x) where x is a 32-bit float as outlined in [1]. + + Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +/* +** $Id: tanhf.c 3654 2005-01-24 10:38:53Z vrokas $ +*/ + +#include +#include + +#define P0 -0.8237728127E+0 +#define P1 -0.3831010665E-2 +#define Q0 0.2471319654E+1 +#define Q1 0.1000000000E+1 + +/* ln(3)/2 */ +#define K1 0.5493061443E+0 +/* SBIG=[ln(2)+(t+1)*ln(B)]/2 */ +#define SBIG 9.01091 + +#define P(g) ((P1*g+P0)*g) +#define Q(g) (Q1*g+Q0) + +float tanhf(const float x) _MATH_REENTRANT +{ + float f, g, r; + + f=fabsf(x); + if(f>SBIG) r=1.0; + else if(f>K1) + { + r=0.5-1.0/(expf(f+f)+1.0); + r+=r; + } + else if(f + +/* convert float to signed char */ +signed char __fs2schar (float f) _FS_REENTRANT +{ + signed long sl=__fs2slong(f); + if (sl>=CHAR_MAX) + return CHAR_MAX; + if (sl<=CHAR_MIN) + return -CHAR_MIN; + return sl; +} diff --git a/device/lib/pic/libsdcc/fs2sint.c b/device/lib/pic/libsdcc/fs2sint.c new file mode 100644 index 00000000..e6fe0e95 --- /dev/null +++ b/device/lib/pic/libsdcc/fs2sint.c @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + fs2sint.c :- + + Adopted for float and pic16 port by + - Vangelis Rokas, vrokas@otenet.gr (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library 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. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! + + +-------------------------------------------------------------------------*/ + + +/* +** $Id: fs2sint.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + + +#include + +/* convert float to signed int */ +signed int __fs2sint (float f) _FS_REENTRANT +{ + signed long sl=__fs2slong(f); + if (sl>=INT_MAX) + return INT_MAX; + if (sl<=INT_MIN) + return -INT_MIN; + return sl; +} diff --git a/device/lib/pic/libsdcc/fs2slong.c b/device/lib/pic/libsdcc/fs2slong.c new file mode 100644 index 00000000..ef46b6c3 --- /dev/null +++ b/device/lib/pic/libsdcc/fs2slong.c @@ -0,0 +1,46 @@ +/*------------------------------------------------------------------------- + fs2slong.c :- + + Adopted for float and pic16 port by + - Vangelis Rokas, vrokas@otenet.gr (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library 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. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! + + +-------------------------------------------------------------------------*/ + +/* +** $Id: fs2slong.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +#include + +/* convert float to signed long */ +signed long __fs2slong (float f) _FS_REENTRANT +{ + + if (!f) + return 0; + + if (f<0) { + return -__fs2ulong(-f); + } else { + return __fs2ulong(f); + } +} diff --git a/device/lib/pic/libsdcc/fs2uchar.c b/device/lib/pic/libsdcc/fs2uchar.c new file mode 100644 index 00000000..cf963716 --- /dev/null +++ b/device/lib/pic/libsdcc/fs2uchar.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + fs2uchar.c :- + + Adopted for float and pic16 port by + - Vangelis Rokas, vrokas@otenet.gr (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library 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. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! + + +-------------------------------------------------------------------------*/ + +/* +** $Id: fs2uchar.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +#include + +/* convert float to unsigned char */ +unsigned char __fs2uchar (float f) _FS_REENTRANT +{ + unsigned long ul=__fs2ulong(f); + if (ul>=UCHAR_MAX) return UCHAR_MAX; + return ul; +} + diff --git a/device/lib/pic/libsdcc/fs2uint.c b/device/lib/pic/libsdcc/fs2uint.c new file mode 100644 index 00000000..16084456 --- /dev/null +++ b/device/lib/pic/libsdcc/fs2uint.c @@ -0,0 +1,43 @@ +/*------------------------------------------------------------------------- + fs2uint.c :- + + Adopted for float and pic16 port by + - Vangelis Rokas, vrokas@otenet.gr (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library 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. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! + + +-------------------------------------------------------------------------*/ + +/* +** $Id: fs2uint.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +#include + +unsigned long __fs2ulong (float a1); + +/* convert float to unsigned int */ +unsigned int __fs2uint (float f) _FS_REENTRANT +{ + unsigned long ul=__fs2ulong(f); + if (ul>=UINT_MAX) return UINT_MAX; + return ul; +} + diff --git a/device/lib/pic/libsdcc/fs2ulong.c b/device/lib/pic/libsdcc/fs2ulong.c new file mode 100644 index 00000000..fd34c445 --- /dev/null +++ b/device/lib/pic/libsdcc/fs2ulong.c @@ -0,0 +1,49 @@ +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* +** $Id: fs2ulong.c 3711 2005-03-31 16:25:17Z vrokas $ +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +#include + +union float_long +{ + float f; + long l; +}; + +/* convert float to unsigned long */ +unsigned long __fs2ulong (float a1) _FS_REENTRANT +{ + FS_STATIC volatile union float_long fl1; + int exp; + long l; + + fl1.f = a1; + + if (!fl1.l || SIGN(fl1.l)) + return (0); + + exp = EXP (fl1.l) - EXCESS - 24; + l = MANT (fl1.l); + + l >>= -exp; + + return l; +} diff --git a/device/lib/pic/libsdcc/fsadd.c b/device/lib/pic/libsdcc/fsadd.c new file mode 100644 index 00000000..bda18264 --- /dev/null +++ b/device/lib/pic/libsdcc/fsadd.c @@ -0,0 +1,102 @@ +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* +** $Id: fsadd.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +#include + +union float_long + { + float f; + unsigned long l; + }; + +/* add two floats */ +float __fsadd (float a1, float a2) _FS_REENTRANT +{ + FS_STATIC volatile union float_long fl1, fl2; + unsigned long mant1, mant2; + int exp1, exp2; + unsigned long sign = 0; + + fl1.f = a1; + fl2.f = a2; + + /* check for zero args */ + if (!fl1.l) + return (fl2.f); + if (!fl2.l) + return (fl1.f); + + exp1 = EXP (fl1.l); + exp2 = EXP (fl2.l); + + if (exp1 > exp2 + 25) + return (fl1.f); + if (exp2 > exp1 + 25) + return (fl2.f); + + mant1 = MANT (fl1.l); + mant2 = MANT (fl2.l); + + if (SIGN (fl1.l)) + mant1 = -mant1; + if (SIGN (fl2.l)) + mant2 = -mant2; + + if (exp1 > exp2) + { + mant2 >>= exp1 - exp2; + } + else + { + mant1 >>= exp2 - exp1; + exp1 = exp2; + } + mant1 += mant2; + + if ((long)mant1 < 0) + { + mant1 = -mant1; + sign = SIGNBIT; + } + else if (!mant1) + return (0); + + /* normalize */ + while (mant1>= 1 ; + exp1++; + } + + /* turn off hidden bit */ + mant1 &= ~HIDDEN; + + /* pack up and go home */ + fl1.l = PACK (sign, (unsigned long) exp1, mant1); + + return (fl1.f); +} diff --git a/device/lib/pic/libsdcc/fsdiv.c b/device/lib/pic/libsdcc/fsdiv.c new file mode 100644 index 00000000..7b5b4f50 --- /dev/null +++ b/device/lib/pic/libsdcc/fsdiv.c @@ -0,0 +1,99 @@ +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* +** $Id: fsdiv.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +#include + +union float_long + { + float f; + long l; + }; + +/* divide two floats */ +float __fsdiv (float a1, float a2) _FS_REENTRANT +{ + FS_STATIC volatile union float_long fl1, fl2; + long result; + unsigned long mask; + long mant1, mant2; + int exp ; + char sign; + + fl1.f = a1; + fl2.f = a2; + + /* subtract exponents */ + exp = EXP (fl1.l) ; + exp -= EXP (fl2.l); + exp += EXCESS; + + /* compute sign */ + sign = SIGN (fl1.l) ^ SIGN (fl2.l); + + /* divide by zero??? */ + if (!fl2.l) + /* return NaN or -NaN */ + return (-1.0); + + /* numerator zero??? */ + if (!fl1.l) + return (0); + + /* now get mantissas */ + mant1 = MANT (fl1.l); + mant2 = MANT (fl2.l); + + /* this assures we have 25 bits of precision in the end */ + if (mant1 < mant2) + { + mant1 <<= 1; + exp--; + } + + /* now we perform repeated subtraction of fl2.l from fl1.l */ + mask = 0x1000000; + result = 0; + while (mask) + { + if (mant1 >= mant2) + { + result |= mask; + mant1 -= mant2; + } + mant1 <<= 1; + mask >>= 1; + } + + /* round */ + result += 1; + + /* normalize down */ + exp++; + result >>= 1; + + result &= ~HIDDEN; + + /* pack up and go home */ + fl1.l = PACK (sign ? 1ul<<31 : 0, (unsigned long) exp, result); + return (fl1.f); +} + diff --git a/device/lib/pic/libsdcc/fseq.c b/device/lib/pic/libsdcc/fseq.c new file mode 100644 index 00000000..4bea7bbb --- /dev/null +++ b/device/lib/pic/libsdcc/fseq.c @@ -0,0 +1,43 @@ +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* +** $Id: fseq.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +#include + +union float_long + { + float f; + long l; + }; + +/* compare two floats */ +char __fseq (float a1, float a2) _FS_REENTRANT +{ + FS_STATIC volatile union float_long fl1, fl2; + + fl1.f = a1; + fl2.f = a2; + + if (fl1.l == fl2.l) + return (1); + return (0); +} + diff --git a/device/lib/pic/libsdcc/fsgt.c b/device/lib/pic/libsdcc/fsgt.c new file mode 100644 index 00000000..634619b6 --- /dev/null +++ b/device/lib/pic/libsdcc/fsgt.c @@ -0,0 +1,48 @@ +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* +** $Id: fsgt.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +#include + +union float_long + { + float f; + long l; + }; + +/* compare two floats */ +char __fsgt (float a1, float a2) _FS_REENTRANT +{ + FS_STATIC volatile union float_long fl1, fl2; + + fl1.f = a1; + fl2.f = a2; + + if (fl1.l<0 && fl2.l<0) { + if (fl2.l > fl1.l) + return (1); + return (0); + } + + if (fl1.l > fl2.l) + return (1); + return (0); +} diff --git a/device/lib/pic/libsdcc/fslt.c b/device/lib/pic/libsdcc/fslt.c new file mode 100644 index 00000000..9956717b --- /dev/null +++ b/device/lib/pic/libsdcc/fslt.c @@ -0,0 +1,48 @@ +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* +** $Id: fslt.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +#include + +union float_long + { + float f; + long l; + }; + +/* compare two floats */ +char __fslt (float a1, float a2) _FS_REENTRANT +{ + FS_STATIC volatile union float_long fl1, fl2; + + fl1.f = a1; + fl2.f = a2; + + if (fl1.l<0 && fl2.l<0) { + if (fl2.l < fl1.l) + return (1); + return (0); + } + + if (fl1.l < fl2.l) + return (1); + return (0); +} diff --git a/device/lib/pic/libsdcc/fsmul.c b/device/lib/pic/libsdcc/fsmul.c new file mode 100644 index 00000000..93cc9ccc --- /dev/null +++ b/device/lib/pic/libsdcc/fsmul.c @@ -0,0 +1,81 @@ +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* +** $Id: fsmul.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +#include + +union float_long + { + float f; + unsigned long l; + }; + +/* multiply two floats */ +float __fsmul (float a1, float a2) _FS_REENTRANT +{ + FS_STATIC volatile union float_long fl1, fl2; + unsigned long result; + int exp; + char sign; + + fl1.f = a1; + fl2.f = a2; + + if (!fl1.l || !fl2.l) + return (0); + + /* compute sign and exponent */ + sign = SIGN (fl1.l) ^ SIGN (fl2.l); + exp = EXP (fl1.l) - EXCESS; + exp += EXP (fl2.l); + + fl1.l = MANT (fl1.l); + fl2.l = MANT (fl2.l); + + /* the multiply is done as one 16x16 multiply and two 16x8 multiples */ + result = (fl1.l >> 8) * (fl2.l >> 8); + result += ((fl1.l & (unsigned long) 0xFF) * (fl2.l >> 8)) >> 8; + result += ((fl2.l & (unsigned long) 0xFF) * (fl1.l >> 8)) >> 8; + + if (0 != (result & SIGNBIT)) + { + /* round */ + result += 0x80; + result >>= 8; + } + else + { + /* round */ + result += 0x40; + result >>= 7; + exp--; + } + + result &= ~HIDDEN; + + /* pack up and go home */ + fl1.l = PACK (sign ? SIGNBIT : 0 , (unsigned long)exp, result); + return (fl1.f); +} + + + + diff --git a/device/lib/pic/libsdcc/fsneq.c b/device/lib/pic/libsdcc/fsneq.c new file mode 100644 index 00000000..8178cee2 --- /dev/null +++ b/device/lib/pic/libsdcc/fsneq.c @@ -0,0 +1,50 @@ +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* +** $Id: fsneq.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +#include + +union float_long + { + float f; + long l; + }; + +/* compare two floats */ +char __fsneq (float a1, float a2) _FS_REENTRANT +{ + FS_STATIC volatile union float_long fl1, fl2; + + fl1.f = a1; + fl2.f = a2; + +#if 0 + if (fl1.l<0 && fl2.l<0) + { + fl1.l ^= SIGNBIT; + fl2.l ^= SIGNBIT; + } +#endif + + if (fl1.l == fl2.l) + return (0); + return (1); +} diff --git a/device/lib/pic/libsdcc/fssub.c b/device/lib/pic/libsdcc/fssub.c new file mode 100644 index 00000000..0265e98e --- /dev/null +++ b/device/lib/pic/libsdcc/fssub.c @@ -0,0 +1,48 @@ +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* +** $Id: fssub.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +#include + +union float_long + { + float f; + long l; + }; + +/* subtract two floats */ +float __fssub (float a1, float a2) _FS_REENTRANT +{ + FS_STATIC volatile union float_long fl1, fl2; + + fl1.f = a1; + fl2.f = a2; + + /* check for zero args */ + if (!fl2.l) + return (fl1.f); + if (!fl1.l) + return (-fl2.f); + + /* twiddle sign bit and add */ + fl2.l ^= SIGNBIT; + return fl1.f + fl2.f; +} diff --git a/device/lib/pic/libsdcc/schar2fs.c b/device/lib/pic/libsdcc/schar2fs.c new file mode 100644 index 00000000..8153b367 --- /dev/null +++ b/device/lib/pic/libsdcc/schar2fs.c @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + schar2fs.c :- + + Adopted for float and pic16 port by + - Vangelis Rokas, vrokas@otenet.gr (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library 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. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! + + +-------------------------------------------------------------------------*/ + +/* +** $Id: schar2fs.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +#include + +/* convert signed char to float */ +float __schar2fs (signed char sc) _FS_REENTRANT +{ + return __slong2fs(sc); +} diff --git a/device/lib/pic/libsdcc/sint2fs.c b/device/lib/pic/libsdcc/sint2fs.c new file mode 100644 index 00000000..b0d714a0 --- /dev/null +++ b/device/lib/pic/libsdcc/sint2fs.c @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + sint2fs.c :- + + Adopted for float and pic16 port by + - Vangelis Rokas, vrokas@otenet.gr (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library 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. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! + + +-------------------------------------------------------------------------*/ + +/* +** $Id: sint2fs.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +#include + +/* convert signed int to float */ +float __sint2fs (signed int si) _FS_REENTRANT +{ + return __slong2fs(si); +} diff --git a/device/lib/pic/libsdcc/slong2fs.c b/device/lib/pic/libsdcc/slong2fs.c new file mode 100644 index 00000000..255d4d3e --- /dev/null +++ b/device/lib/pic/libsdcc/slong2fs.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + slong2fs.c :- + + Adopted for float and pic16 port by + - Vangelis Rokas, vrokas@otenet.gr (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library 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. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! + + +-------------------------------------------------------------------------*/ + +/* +** $Id: slong2fs.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +#include + +/* convert signed long to float */ +float __slong2fs (signed long sl) _FS_REENTRANT +{ + if (sl<0) + return -__ulong2fs(-sl); + else + return __ulong2fs(sl); +} diff --git a/device/lib/pic/libsdcc/uchar2fs.c b/device/lib/pic/libsdcc/uchar2fs.c new file mode 100644 index 00000000..4b42a5cd --- /dev/null +++ b/device/lib/pic/libsdcc/uchar2fs.c @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + uchar2fs.c :- + + Adopted for float and pic16 port by + - Vangelis Rokas, vrokas@otenet.gr (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library 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. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! + + +-------------------------------------------------------------------------*/ + +/* +** $Id: uchar2fs.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +#include + +/* convert unsigned char to float */ +float __uchar2fs (unsigned char uc) _FS_REENTRANT +{ + return __ulong2fs(uc); +} diff --git a/device/lib/pic/libsdcc/uint2fs.c b/device/lib/pic/libsdcc/uint2fs.c new file mode 100644 index 00000000..a1b8de43 --- /dev/null +++ b/device/lib/pic/libsdcc/uint2fs.c @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + uint2fs.c :- + + Adopted for float and pic16 port by + - Vangelis Rokas, vrokas@otenet.gr (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library 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. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! + + +-------------------------------------------------------------------------*/ + +/* +** $Id: uint2fs.c 3513 2004-10-01 14:49:51Z vrokas $ +*/ + +#include + +/* convert unsigned int to float */ +float __uint2fs (unsigned int ui) _FS_REENTRANT +{ + return __ulong2fs(ui); +} diff --git a/device/lib/pic/libsdcc/ulong2fs.c b/device/lib/pic/libsdcc/ulong2fs.c new file mode 100644 index 00000000..a2dc3613 --- /dev/null +++ b/device/lib/pic/libsdcc/ulong2fs.c @@ -0,0 +1,75 @@ +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* +** $Id: ulong2fs.c 3607 2004-12-20 21:48:32Z vrokas $ +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +#include + +union float_long + { + float f; + long l; + }; + +float __ulong2fs (unsigned long a ) _FS_REENTRANT +{ + int exp = 24 + EXCESS; + FS_STATIC volatile union float_long fl; + + if (!a) + { + return 0.0; + } + + while (a & NORM) + { + // we lose accuracy here + a >>= 1; + exp++; + } + + + if(a < HIDDEN) { + do { + a<<=1; + exp--; + } while (a < HIDDEN); + } + +#if 0 + while (a < HIDDEN) { + a <<= 1; + exp--; + } +#endif + +#if 1 + if ((a&0x7fffff)==0x7fffff) { + a=0; + exp++; + } +#endif + + a &= ~HIDDEN ; + /* pack up and go home */ + fl.l = PACK(0,(unsigned long)exp, a); + + return (fl.f); +} diff --git a/src/pic/gen.c b/src/pic/gen.c index bed1cb46..b5232930 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -274,8 +274,15 @@ void emitpcode_real(PIC_OPCODE poc, pCodeOp *pcop) { if(pcop) addpCode2pBlock(pb,newpCode(poc,pcop)); - else + else { + static int has_warned = 0; + DEBUGpic14_emitcode(";","%s ignoring NULL pcop",__FUNCTION__); + if (!has_warned) { + has_warned = 1; + fprintf( stderr, "WARNING: encountered NULL pcop--this is probably a compiler bug...\n" ); + } + } } void emitpcodeNULLop(PIC_OPCODE poc) @@ -1435,10 +1442,15 @@ pCodeOp *popGet (asmop *aop, int offset) //, bool bit16, bool dname) assert (aop); + /* XXX: still needed for BIT operands (AOP_CRY) */ if (offset > (aop->size - 1) && - aop->type != AOP_LIT) + aop->type != AOP_LIT && + aop->type != AOP_PCODE) + { + printf( "%s: (offset[%d] > AOP_SIZE(op)[%d]-1) && AOP_TYPE(op) != AOP_LIT)\n", __FUNCTION__, offset, aop->size); return NULL; //zero; + } /* depending on type */ switch (aop->type) { @@ -9376,7 +9388,10 @@ static void genDataPointerSet(operand *right, assert (IS_SYMOP(result)); assert (IS_PTR(OP_SYM_TYPE(result))); - size = AOP_SIZE(right); + if (AOP_TYPE(right) == AOP_LIT) + size = 4; + else + size = AOP_SIZE(right); ressize = getSize(OP_SYM_ETYPE(result)); if (size > ressize) size = ressize; //fprintf (stderr, "%s:%u: size(right): %d, size(result): %d\n", __FUNCTION__,__LINE__, AOP_SIZE(right), ressize); @@ -9393,7 +9408,7 @@ static void genDataPointerSet(operand *right, // tsd, was l+1 - the underline `_' prefix was being stripped while (size--) { - emitpComment ("%s:%u: size=%d/%d, offset=%i", __FILE__,__LINE__, size, ressize, offset); + emitpComment ("%s:%u: size=%d/%d, offset=%d, AOP_TYPE(res)=%d", __FILE__,__LINE__, size, ressize, offset, AOP_TYPE(result)); if (AOP_TYPE(right) == AOP_LIT) { unsigned int lit = pic14aopLiteral(AOP(IC_RIGHT(ic))->aopu.aop_lit, offset); @@ -10058,9 +10073,6 @@ static void genAssign (iCode *ic) /* general case */ size = AOP_SIZE(result); offset = 0 ; - if(AOP_TYPE(right) == AOP_LIT) - lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit); - if( AOP_TYPE(right) == AOP_DIR && (AOP_TYPE(result) == AOP_REG) && size==1) { DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); if(aopIdx(AOP(result),0) == 4) { @@ -10074,8 +10086,10 @@ static void genAssign (iCode *ic) know_W=-1; while (size--) { + DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); if(AOP_TYPE(right) == AOP_LIT) { + lit = (unsigned long)pic14aopLiteral(AOP(right)->aopu.aop_lit, offset) & 0x0ff; if(lit&0xff) { if(know_W != (int)(lit&0xff)) emitpcode(POC_MOVLW,popGetLit(lit&0xff)); @@ -10084,8 +10098,6 @@ static void genAssign (iCode *ic) } else emitpcode(POC_CLRF, popGet(AOP(result),offset)); - lit >>= 8; - } else if (AOP_TYPE(right) == AOP_CRY) { emitpcode(POC_CLRF, popGet(AOP(result),offset)); if(offset == 0) { diff --git a/src/pic/glue.c b/src/pic/glue.c index c5f491e1..b468ba0d 100644 --- a/src/pic/glue.c +++ b/src/pic/glue.c @@ -1010,6 +1010,7 @@ pic14createInterruptVect (FILE * vFile) fprintf (vFile, "%s", iComments2); fprintf (vFile, "STARTUP\t%s\n", CODE_NAME); // Lkr file should place section STARTUP at address 0x0 fprintf (vFile, "\tnop\n"); /* first location for used by incircuit debugger */ + fprintf( vFile, "\tpagesel __sdcc_gsinit_startup\n"); fprintf (vFile, "\tgoto\t__sdcc_gsinit_startup\n"); } diff --git a/src/pic/main.c b/src/pic/main.c index 760ad9a0..7881c1c6 100644 --- a/src/pic/main.c +++ b/src/pic/main.c @@ -468,10 +468,10 @@ static void _pic14_do_link (void) shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet)); - shash_add(&linkValues, "outfile", dstFileName); + shash_add(&linkValues, "outfile", fullDstFileName ? fullDstFileName : dstFileName); if(fullSrcFileName) { - sprintf(temp, "%s.o", dstFileName); + sprintf(temp, "%s.o", fullDstFileName ? fullDstFileName : dstFileName ); shash_add(&linkValues, "user_ofile", temp); } diff --git a/src/pic/pcoderegs.c b/src/pic/pcoderegs.c index 0c8f4beb..5c1b8d18 100644 --- a/src/pic/pcoderegs.c +++ b/src/pic/pcoderegs.c @@ -192,6 +192,7 @@ void pCodeRegMapLiveRangesInFlow(pCodeFlow *pcfl) addSetIfnotP(& (reg->reglives.assignedpFlows), pcfl); addSetIfnotP(& (reg->reglives.usedpCodes), pc); + reg->wasUsed = 1; } diff --git a/src/pic16/main.c b/src/pic16/main.c index 5886b349..c091aa2d 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -674,10 +674,10 @@ static void _pic16_linkEdit(void) shash_add(&linkValues, "incdirs", joinStrSet( appendStrSet(tSet, "-I\"", "\""))); shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet)); - shash_add(&linkValues, "outfile", dstFileName); + shash_add(&linkValues, "outfile", fullDstFileName ? fullDstFileName : dstFileName); if(fullSrcFileName) { - sprintf(temp, "%s.o", dstFileName); + sprintf(temp, "%s.o", fullDstFileName ? fullDstFileName : dstFileName); // addSetHead(&relFilesSet, Safe_strdup(temp)); shash_add(&linkValues, "user_ofile", temp); } -- 2.30.2