From bf6f6cf752b8248811eb665f2f01939958592cb7 Mon Sep 17 00:00:00 2001 From: vrokas Date: Fri, 9 Jul 2004 23:28:16 +0000 Subject: [PATCH] * sources in device/lib/pic16/libsdcc/float/*.c were empty, contents updated git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3377 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- device/lib/pic16/libsdcc/float/fs2schar.c | 45 ++++++++++ device/lib/pic16/libsdcc/float/fs2sint.c | 46 ++++++++++ device/lib/pic16/libsdcc/float/fs2slong.c | 47 ++++++++++ device/lib/pic16/libsdcc/float/fs2uchar.c | 42 +++++++++ device/lib/pic16/libsdcc/float/fs2uint.c | 44 +++++++++ device/lib/pic16/libsdcc/float/fs2ulong.c | 54 ++++++++++++ device/lib/pic16/libsdcc/float/fsadd.c | 103 ++++++++++++++++++++++ device/lib/pic16/libsdcc/float/fsdiv.c | 100 +++++++++++++++++++++ device/lib/pic16/libsdcc/float/fseq.c | 44 +++++++++ device/lib/pic16/libsdcc/float/fsgt.c | 49 ++++++++++ device/lib/pic16/libsdcc/float/fslt.c | 49 ++++++++++ device/lib/pic16/libsdcc/float/fsmul.c | 82 +++++++++++++++++ device/lib/pic16/libsdcc/float/fsneq.c | 51 +++++++++++ device/lib/pic16/libsdcc/float/fssub.c | 49 ++++++++++ device/lib/pic16/libsdcc/float/schar2fs.c | 39 ++++++++ device/lib/pic16/libsdcc/float/sint2fs.c | 39 ++++++++ device/lib/pic16/libsdcc/float/slong2fs.c | 42 +++++++++ device/lib/pic16/libsdcc/float/uchar2fs.c | 39 ++++++++ device/lib/pic16/libsdcc/float/uint2fs.c | 39 ++++++++ device/lib/pic16/libsdcc/float/ulong2fs.c | 76 ++++++++++++++++ 20 files changed, 1079 insertions(+) diff --git a/device/lib/pic16/libsdcc/float/fs2schar.c b/device/lib/pic16/libsdcc/float/fs2schar.c index e69de29b..17e5ea0d 100644 --- a/device/lib/pic16/libsdcc/float/fs2schar.c +++ b/device/lib/pic16/libsdcc/float/fs2schar.c @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + fs2schar.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$ +*/ + + +#include + +/* convert float to signed char */ +signed char __fs2schar (float f) +// 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/pic16/libsdcc/float/fs2sint.c b/device/lib/pic16/libsdcc/float/fs2sint.c index e69de29b..bcf77030 100644 --- a/device/lib/pic16/libsdcc/float/fs2sint.c +++ b/device/lib/pic16/libsdcc/float/fs2sint.c @@ -0,0 +1,46 @@ +/*------------------------------------------------------------------------- + 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$ +*/ + + +#include + +/* convert float to signed int */ +signed int __fs2sint (float f) +// 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/pic16/libsdcc/float/fs2slong.c b/device/lib/pic16/libsdcc/float/fs2slong.c index e69de29b..dc57c2d7 100644 --- a/device/lib/pic16/libsdcc/float/fs2slong.c +++ b/device/lib/pic16/libsdcc/float/fs2slong.c @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + 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$ +*/ + +#include + +/* convert float to signed long */ +signed long __fs2slong (float f) +// reentrant +{ + + if (!f) + return 0; + + if (f<0) { + return -__fs2ulong(-f); + } else { + return __fs2ulong(f); + } +} diff --git a/device/lib/pic16/libsdcc/float/fs2uchar.c b/device/lib/pic16/libsdcc/float/fs2uchar.c index e69de29b..3d422e1d 100644 --- a/device/lib/pic16/libsdcc/float/fs2uchar.c +++ b/device/lib/pic16/libsdcc/float/fs2uchar.c @@ -0,0 +1,42 @@ +/*------------------------------------------------------------------------- + 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$ +*/ + +#include + +/* convert float to unsigned char */ +unsigned char __fs2uchar (float f) +// reentrant +{ + unsigned long ul=__fs2ulong(f); + if (ul>=UCHAR_MAX) return UCHAR_MAX; + return ul; +} + diff --git a/device/lib/pic16/libsdcc/float/fs2uint.c b/device/lib/pic16/libsdcc/float/fs2uint.c index e69de29b..ac4742d1 100644 --- a/device/lib/pic16/libsdcc/float/fs2uint.c +++ b/device/lib/pic16/libsdcc/float/fs2uint.c @@ -0,0 +1,44 @@ +/*------------------------------------------------------------------------- + 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$ +*/ + +#include + +unsigned long __fs2ulong (float a1); + +/* convert float to unsigned int */ +unsigned int __fs2uint (float f) +// reentrant +{ + unsigned long ul=__fs2ulong(f); + if (ul>=UINT_MAX) return UINT_MAX; + return ul; +} + diff --git a/device/lib/pic16/libsdcc/float/fs2ulong.c b/device/lib/pic16/libsdcc/float/fs2ulong.c index e69de29b..8d290b18 100644 --- a/device/lib/pic16/libsdcc/float/fs2ulong.c +++ b/device/lib/pic16/libsdcc/float/fs2ulong.c @@ -0,0 +1,54 @@ +/* +** 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$ +*/ + +/* (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) +// reentrant +{ + volatile union float_long fl1; + volatile int exp; + volatile 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/pic16/libsdcc/float/fsadd.c b/device/lib/pic16/libsdcc/float/fsadd.c index e69de29b..3b07ce92 100644 --- a/device/lib/pic16/libsdcc/float/fsadd.c +++ b/device/lib/pic16/libsdcc/float/fsadd.c @@ -0,0 +1,103 @@ +/* +** 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$ +*/ + +#include + +union float_long + { + float f; + unsigned long l; + }; + +/* add two floats */ +float __fsadd (float a1, float a2) +// reentrant +{ + volatile long mant1, mant2; + volatile union float_long fl1, fl2; + volatile int exp1, exp2; + volatile 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 (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/pic16/libsdcc/float/fsdiv.c b/device/lib/pic16/libsdcc/float/fsdiv.c index e69de29b..7126216a 100644 --- a/device/lib/pic16/libsdcc/float/fsdiv.c +++ b/device/lib/pic16/libsdcc/float/fsdiv.c @@ -0,0 +1,100 @@ +/* +** 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$ +*/ + +/* (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) +// reentrant +{ + volatile union float_long fl1, fl2; + volatile long result; + volatile unsigned long mask; + volatile long mant1, mant2; + volatile 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/pic16/libsdcc/float/fseq.c b/device/lib/pic16/libsdcc/float/fseq.c index e69de29b..d8ba9333 100644 --- a/device/lib/pic16/libsdcc/float/fseq.c +++ b/device/lib/pic16/libsdcc/float/fseq.c @@ -0,0 +1,44 @@ +/* +** 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$ +*/ + +/* (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) +// reentrant +{ + 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/pic16/libsdcc/float/fsgt.c b/device/lib/pic16/libsdcc/float/fsgt.c index e69de29b..574898c2 100644 --- a/device/lib/pic16/libsdcc/float/fsgt.c +++ b/device/lib/pic16/libsdcc/float/fsgt.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$ +*/ + +/* (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) +//reentrant +{ + 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/pic16/libsdcc/float/fslt.c b/device/lib/pic16/libsdcc/float/fslt.c index e69de29b..45eadf8a 100644 --- a/device/lib/pic16/libsdcc/float/fslt.c +++ b/device/lib/pic16/libsdcc/float/fslt.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$ +*/ + +/* (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) +// reentrant +{ + 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/pic16/libsdcc/float/fsmul.c b/device/lib/pic16/libsdcc/float/fsmul.c index e69de29b..315a04d6 100644 --- a/device/lib/pic16/libsdcc/float/fsmul.c +++ b/device/lib/pic16/libsdcc/float/fsmul.c @@ -0,0 +1,82 @@ +/* +** 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$ +*/ + +/* (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) +// reentrant +{ + volatile union float_long fl1, fl2; + volatile unsigned long result; + volatile 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 (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/pic16/libsdcc/float/fsneq.c b/device/lib/pic16/libsdcc/float/fsneq.c index e69de29b..2ed1b1ec 100644 --- a/device/lib/pic16/libsdcc/float/fsneq.c +++ b/device/lib/pic16/libsdcc/float/fsneq.c @@ -0,0 +1,51 @@ +/* +** 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$ +*/ + +/* (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) +// reentrant +{ + 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/pic16/libsdcc/float/fssub.c b/device/lib/pic16/libsdcc/float/fssub.c index e69de29b..54770b59 100644 --- a/device/lib/pic16/libsdcc/float/fssub.c +++ b/device/lib/pic16/libsdcc/float/fssub.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$ +*/ + +/* (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) +// reentrant +{ + 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/pic16/libsdcc/float/schar2fs.c b/device/lib/pic16/libsdcc/float/schar2fs.c index e69de29b..d0028f68 100644 --- a/device/lib/pic16/libsdcc/float/schar2fs.c +++ b/device/lib/pic16/libsdcc/float/schar2fs.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + 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$ +*/ + +#include + +/* convert signed char to float */ +float __schar2fs (signed char sc) +// reentrant +{ + return __slong2fs(sc); +} diff --git a/device/lib/pic16/libsdcc/float/sint2fs.c b/device/lib/pic16/libsdcc/float/sint2fs.c index e69de29b..4c3d65d7 100644 --- a/device/lib/pic16/libsdcc/float/sint2fs.c +++ b/device/lib/pic16/libsdcc/float/sint2fs.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + 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$ +*/ + +#include + +/* convert signed int to float */ +float __sint2fs (signed int si) +// reentrant +{ + return __slong2fs(si); +} diff --git a/device/lib/pic16/libsdcc/float/slong2fs.c b/device/lib/pic16/libsdcc/float/slong2fs.c index e69de29b..11d38920 100644 --- a/device/lib/pic16/libsdcc/float/slong2fs.c +++ b/device/lib/pic16/libsdcc/float/slong2fs.c @@ -0,0 +1,42 @@ +/*------------------------------------------------------------------------- + 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$ +*/ + +#include + +/* convert signed long to float */ +float __slong2fs (signed long sl) +//reentrant +{ + if (sl<0) + return -__ulong2fs(-sl); + else + return __ulong2fs(sl); +} diff --git a/device/lib/pic16/libsdcc/float/uchar2fs.c b/device/lib/pic16/libsdcc/float/uchar2fs.c index e69de29b..536cf674 100644 --- a/device/lib/pic16/libsdcc/float/uchar2fs.c +++ b/device/lib/pic16/libsdcc/float/uchar2fs.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + 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$ +*/ + +#include + +/* convert unsigned char to float */ +float __uchar2fs (unsigned char uc) +// reentrant +{ + return __ulong2fs(uc); +} diff --git a/device/lib/pic16/libsdcc/float/uint2fs.c b/device/lib/pic16/libsdcc/float/uint2fs.c index e69de29b..2a846d75 100644 --- a/device/lib/pic16/libsdcc/float/uint2fs.c +++ b/device/lib/pic16/libsdcc/float/uint2fs.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + 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$ +*/ + +#include + +/* convert unsigned int to float */ +float __uint2fs (unsigned int ui) +//reentrant +{ + return __ulong2fs(ui); +} diff --git a/device/lib/pic16/libsdcc/float/ulong2fs.c b/device/lib/pic16/libsdcc/float/ulong2fs.c index e69de29b..23123339 100644 --- a/device/lib/pic16/libsdcc/float/ulong2fs.c +++ b/device/lib/pic16/libsdcc/float/ulong2fs.c @@ -0,0 +1,76 @@ +/* +** 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$ +*/ + +/* (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 ) +// reentrant +{ + int exp = 24 + EXCESS; + 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); +} -- 2.30.2