From: pjs Date: Mon, 27 Dec 2004 10:51:44 +0000 (+0000) Subject: Added mcs51 assembly versions for the 12 float/integer conversion functions. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=4e85b590d59de032a494ad439773f94d845db0f4;p=fw%2Fsdcc Added mcs51 assembly versions for the 12 float/integer conversion functions. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3615 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 568e529f..ac10df98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,21 @@ -2004-12-25 Paul Stoffregen +2004-12-27 Paul Stoffregen + + * device/lib/_fs2slong.c: added mcs51 assembly version + * device/lib/_fs2sint.c: added mcs51 assembly version + * device/lib/_fs2schar.c: added mcs51 assembly version + * device/lib/_fs2ulong.c: added mcs51 assembly version + * device/lib/_fs2uint.c: added mcs51 assembly version + * device/lib/_fs2uchar.c: added mcs51 assembly version + * device/lib/_slong2fs.c: added mcs51 assembly version + * device/lib/_sint2fs.c: added mcs51 assembly version + * device/lib/_schar2fs.c: added mcs51 assembly version + * device/lib/_ulong2fs.c: added mcs51 assembly version + * device/lib/_uint2fs.c: added mcs51 assembly version + * device/lib/_uchar2fs.c: added mcs51 assembly version + * device/include/float.h: added #define to select asm vs c + +2004-12-26 Paul Stoffregen + * device/lib/printf_fast.c: improvements to float output * device/include/float.h: add defines for assembly float library * device/lib/_fsget1arg.c: receive 1 float arg diff --git a/device/include/float.h b/device/include/float.h index 1c8292b4..3eea235a 100644 --- a/device/include/float.h +++ b/device/include/float.h @@ -73,6 +73,8 @@ char __fsqt (float, float); #if defined(SDCC_FLOAT_LIB) && defined(SDCC_mcs51) && !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +#define FLOAT_ASM_MCS51 + // This adds extra code for proper round-off, in // an attempt to match the results from gcc. #define FLOAT_FULL_ACCURACY diff --git a/device/lib/_fs2schar.c b/device/lib/_fs2schar.c index 8ccf1ebd..0bf02fe0 100644 --- a/device/lib/_fs2schar.c +++ b/device/lib/_fs2schar.c @@ -1,5 +1,71 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#define SDCC_FLOAT_LIB #include + + +#ifdef FLOAT_ASM_MCS51 + +// char __fs2schar (float x) +static void dummy(void) _naked +{ + _asm + .globl ___fs2schar +___fs2schar: + lcall ___fs2slong + jnb sign_a, fs2schar_pos +fs2schar_neg: + cpl a + jnz fs2schar_maxval_neg + mov a, b + cpl a + jnz fs2schar_maxval_neg + mov a, dph + cpl a + jnz fs2schar_maxval_neg + mov a, dpl + jnb acc.7, fs2schar_maxval_neg + ret +fs2schar_maxval_neg: + mov dpl, #0x80 + ret +fs2schar_pos: + jnz fs2schar_maxval_pos + mov a, b + jnz fs2schar_maxval_pos + mov a, dph + jnz fs2schar_maxval_pos + mov a, dpl + jb acc.7, fs2schar_maxval_pos + ret +fs2schar_maxval_pos: + mov dpl, #0x7F + ret + _endasm; +} + + +#else + + /* convert float to signed char */ signed char __fs2schar (float f) { signed long sl=__fs2slong(f); @@ -9,3 +75,6 @@ signed char __fs2schar (float f) { return -CHAR_MIN; return sl; } + +#endif + diff --git a/device/lib/_fs2sint.c b/device/lib/_fs2sint.c index 78c17983..4a748dad 100644 --- a/device/lib/_fs2sint.c +++ b/device/lib/_fs2sint.c @@ -1,5 +1,66 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#define SDCC_FLOAT_LIB #include + +#ifdef FLOAT_ASM_MCS51 + +// int __fs2sint (float x) +static void dummy(void) _naked +{ + _asm + .globl ___fs2sint +___fs2sint: + lcall ___fs2slong + jnb sign_a, fs2sint_pos +fs2sint_neg: + cpl a + jnz fs2sint_maxval_neg + mov a, b + cpl a + jnz fs2sint_maxval_neg + mov a, dph + jnb acc.7, fs2sint_maxval_neg + ret +fs2sint_maxval_neg: + mov dptr, #0x8000 + ret +fs2sint_pos: + jnz fs2sint_maxval_pos + mov a, b + jnz fs2sint_maxval_pos + mov a, dph + jb acc.7, fs2sint_maxval_pos + ret +fs2sint_maxval_pos: + mov dptr, #0x7FFF + ret + _endasm; +} + + +#else + + + /* convert float to signed int */ signed int __fs2sint (float f) { signed long sl=__fs2slong(f); @@ -9,3 +70,6 @@ signed int __fs2sint (float f) { return -INT_MIN; return sl; } + +#endif + diff --git a/device/lib/_fs2slong.c b/device/lib/_fs2slong.c index 236ef878..65d3d9ac 100644 --- a/device/lib/_fs2slong.c +++ b/device/lib/_fs2slong.c @@ -1,5 +1,90 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#define SDCC_FLOAT_LIB #include + +#ifdef FLOAT_ASM_MCS51 + +// long __fs2slong (float x) +static void dummy(void) _naked +{ + _asm + .globl ___fs2slong +___fs2slong: + lcall fsgetarg + clr c + mov a, #158 + subb a, exp_a + jc fs2slong_maxval // |x| >= 2^32 +fs2slong_int_ok: + mov r1, #0 + lcall fs_rshift_a + jnb sign_a, fs2slong_pos +fs2slong_neg: + mov a, r1 + cpl a + add a, #1 + mov dpl, a + mov a, r2 + cpl a + addc a, #0 + mov dph, a + mov a, r3 + cpl a + addc a, #0 + mov b, a + mov a, r4 + cpl a + addc a, #0 + jnb acc.7, fs2slong_maxval_neg // x < -0x80000000 + ret +fs2slong_pos: + mov a, r4 + jb acc.7, fs2slong_maxval_pos // x > 0x7FFFFFFF + mov dpl, r1 + mov dph, r2 + mov b, r3 + ret +fs2slong_maxval: + jnb sign_a, fs2slong_maxval_pos +fs2slong_maxval_neg: + clr a + mov dpl, a + mov dph, a + mov b, a + mov a, #0x80 + ret +fs2slong_maxval_pos: + mov a, #0xFF + mov dpl, a + mov dph, a + mov b, a + mov a, #0x7F + ret + _endasm; +} + +#else + + /* convert float to signed long */ signed long __fs2slong (float f) { @@ -12,3 +97,5 @@ signed long __fs2slong (float f) { return __fs2ulong(f); } } + +#endif diff --git a/device/lib/_fs2uchar.c b/device/lib/_fs2uchar.c index ce4a9272..2b021fd0 100644 --- a/device/lib/_fs2uchar.c +++ b/device/lib/_fs2uchar.c @@ -1,5 +1,45 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#define SDCC_FLOAT_LIB #include + +#ifdef FLOAT_ASM_MCS51 + +// unsigned char __fs2uchar (float x) +static void dummy(void) _naked +{ + _asm + .globl ___fs2uchar +___fs2uchar: + mov r7, #134 + lcall fs2ulong_begin + mov dpl, a + ret + _endasm; +} + +#else + + + + /* convert float to unsigned char */ unsigned char __fs2uchar (float f) { unsigned long ul=__fs2ulong(f); @@ -7,3 +47,5 @@ unsigned char __fs2uchar (float f) { return ul; } +#endif + diff --git a/device/lib/_fs2uint.c b/device/lib/_fs2uint.c index 186b7f37..0ed5db64 100644 --- a/device/lib/_fs2uint.c +++ b/device/lib/_fs2uint.c @@ -1,5 +1,44 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#define SDCC_FLOAT_LIB #include + +#ifdef FLOAT_ASM_MCS51 + +// unsigned int __fs2uint (float x) +static void dummy(void) _naked +{ + _asm + .globl ___fs2uint +___fs2uint: + mov r7, #142 + lcall fs2ulong_begin + mov dph, a + mov dpl, b + ret + _endasm; +} + +#else + + unsigned long __fs2ulong (float a1); /* convert float to unsigned int */ @@ -9,3 +48,5 @@ unsigned int __fs2uint (float f) { return ul; } +#endif + diff --git a/device/lib/_fs2ulong.c b/device/lib/_fs2ulong.c index 0b746143..4a2da50d 100644 --- a/device/lib/_fs2ulong.c +++ b/device/lib/_fs2ulong.c @@ -1,3 +1,72 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#define SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// unsigned long __fs2ulong (float x) +static void dummy(void) _naked +{ + _asm + .globl ___fs2ulong +___fs2ulong: + mov r7, #158 + .globl fs2ulong_begin +fs2ulong_begin: + lcall fsgetarg + jnb sign_a, fs2ulong_int + ljmp fs_return_zero + +fs2ulong_int: + clr c + mov a, r7 + subb a, exp_a + jnc fs2ulong_int_ok + // if we get here, x >= 2^32 + mov a, #0xFF + mov b, a + mov dph, a + mov dpl, a + ret + +fs2ulong_int_ok: + mov r1, #0 + lcall fs_rshift_a + +fs2ulong_done: + mov dpl, r1 + mov dph, r2 + mov b, r3 + mov a, r4 + ret + _endasm; +} + + +#else + + + + /* ** libgcc support for software floating point. ** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. @@ -16,7 +85,6 @@ /* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ -#include union float_long { @@ -45,6 +113,6 @@ __fs2ulong (float a1) return l; } - +#endif diff --git a/device/lib/_fsget1arg.c b/device/lib/_fsget1arg.c index bee256b9..abf17260 100644 --- a/device/lib/_fsget1arg.c +++ b/device/lib/_fsget1arg.c @@ -1,3 +1,22 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + #define SDCC_FLOAT_LIB #include diff --git a/device/lib/_fsget2args.c b/device/lib/_fsget2args.c index 3a9e9fe4..404b8ad1 100644 --- a/device/lib/_fsget2args.c +++ b/device/lib/_fsget2args.c @@ -1,3 +1,23 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + + #define SDCC_FLOAT_LIB #include @@ -56,76 +76,3 @@ fsgetargs: -#if 0 -// This old version was designed before the change to make all this -// code fully reentrant. What a mess the 2nd parameter turns out to -// be. - -void __fsgetargs (float a, float b) -{ - a; // passed in a,b,dph,dpl - b; // ___fsadd_PARM_2 - - _asm - // extract the two inputs, placing them into: - // sign exponent mantiassa - // ---- -------- --------- - // a: sign_a exp_a r4/r3/r2 - // b: sign_b exp_b r7/r6/r5 - // - mov r2, dpl - mov r3, dph - mov c, b.7 - rlc a - mov sign_a, c - jz 00001$ - setb b.7 -00001$: - mov exp_a, a - mov r4, b -#ifdef SDCC_MODEL_SMALL - mov r5, (___fsadd_PARM_2 + 0) - mov r6, (___fsadd_PARM_2 + 1) - mov b, (___fsadd_PARM_2 + 2) - mov a, (___fsadd_PARM_2 + 3) - mov c, b.7 - rlc a - mov sign_b, c - jz 00002$ - setb b.7 -00002$: - mov exp_b, a - mov r7, b -#endif - _endasm; -} - - -#ifdef SDCC_MODEL_LARGE -void __fsgetarglarge2 (void) -{ - _asm - movx a, @dptr - mov r5, a - inc dptr - movx a, @dptr - mov r6, a - inc dptr - movx a, @dptr - mov b, a - inc dptr - movx a, @dptr - mov c, b.7 - rlc a - mov sign_b, c - jz 00002$ - setb b.7 -00002$: - mov exp_b, a - mov r7, b - _endasm; -} -#endif - -#endif - diff --git a/device/lib/_fsnormalize.c b/device/lib/_fsnormalize.c index f985b8bb..f404452c 100644 --- a/device/lib/_fsnormalize.c +++ b/device/lib/_fsnormalize.c @@ -1,3 +1,23 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + + #define SDCC_FLOAT_LIB #include diff --git a/device/lib/_fsreturnval.c b/device/lib/_fsreturnval.c index 95f01e11..798f934b 100644 --- a/device/lib/_fsreturnval.c +++ b/device/lib/_fsreturnval.c @@ -1,3 +1,23 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + + #define SDCC_FLOAT_LIB #include diff --git a/device/lib/_fsrshift.c b/device/lib/_fsrshift.c index 4928fa5f..5e7e7e90 100644 --- a/device/lib/_fsrshift.c +++ b/device/lib/_fsrshift.c @@ -1,3 +1,23 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + + #define SDCC_FLOAT_LIB #include diff --git a/device/lib/_fsswapargs.c b/device/lib/_fsswapargs.c index aba533b4..85404cb4 100644 --- a/device/lib/_fsswapargs.c +++ b/device/lib/_fsswapargs.c @@ -1,3 +1,23 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + + #define SDCC_FLOAT_LIB #include diff --git a/device/lib/_schar2fs.c b/device/lib/_schar2fs.c index 2a8fb438..73066d1b 100644 --- a/device/lib/_schar2fs.c +++ b/device/lib/_schar2fs.c @@ -1,6 +1,51 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#define SDCC_FLOAT_LIB #include + +#ifdef FLOAT_ASM_MCS51 + +// float __schar2fs (char c) +static void dummy(void) _naked +{ + _asm + .globl ___schar2fs +___schar2fs: + mov r4, dpl + clr a + mov r3, a + mov r2, a + mov r1, a + mov a, #134 + ljmp slong2fs_doit + _endasm; +} + +#else + + /* convert signed char to float */ float __schar2fs (signed char sc) { return __slong2fs(sc); } + +#endif + diff --git a/device/lib/_sint2fs.c b/device/lib/_sint2fs.c index 0c86277c..eacde5d5 100644 --- a/device/lib/_sint2fs.c +++ b/device/lib/_sint2fs.c @@ -1,6 +1,50 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#define SDCC_FLOAT_LIB #include + +#ifdef FLOAT_ASM_MCS51 + +// float long __sint2fs (float x) +static void dummy(void) _naked +{ + _asm + .globl ___sint2fs +___sint2fs: + mov r4, dph + mov r3, dpl + mov r2, #0 + mov r1, #0 + mov a, #142 + ljmp slong2fs_doit + _endasm; +} + +#else + + /* convert signed int to float */ float __sint2fs (signed int si) { return __slong2fs(si); } + +#endif + diff --git a/device/lib/_slong2fs.c b/device/lib/_slong2fs.c index 394fba87..da1938d0 100644 --- a/device/lib/_slong2fs.c +++ b/device/lib/_slong2fs.c @@ -1,5 +1,71 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#define SDCC_FLOAT_LIB #include + +#ifdef FLOAT_ASM_MCS51 + +//float __slong2fs (long x) +static void dummy(void) _naked +{ + _asm + .globl ___slong2fs +___slong2fs: + mov r4, a + mov r3, b + mov r2, dph + mov r1, dpl + mov a, #158 + .globl slong2fs_doit +slong2fs_doit: + mov exp_a, a + clr sign_a + mov a, r4 + jnb acc.7, slong2fs_positive + setb sign_a + mov a, r1 + cpl a + add a, #1 + mov r1, a + mov a, r2 + cpl a + addc a, #0 + mov r2, a + mov a, r3 + cpl a + addc a, #0 + mov r3, a + mov a, r4 + cpl a + addc a, #0 + mov r4, a +slong2fs_positive: + lcall fs_normalize_a + ljmp fs_round_and_return + _endasm; +} + +#else + + /* convert signed long to float */ float __slong2fs (signed long sl) { if (sl<0) @@ -7,3 +73,6 @@ float __slong2fs (signed long sl) { else return __ulong2fs(sl); } + +#endif + diff --git a/device/lib/_uchar2fs.c b/device/lib/_uchar2fs.c index 3e919882..31af32d8 100644 --- a/device/lib/_uchar2fs.c +++ b/device/lib/_uchar2fs.c @@ -1,6 +1,51 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#define SDCC_FLOAT_LIB #include + +#ifdef FLOAT_ASM_MCS51 + +// float long __uchar2fs (float x) +static void dummy(void) _naked +{ + _asm + .globl ___uchar2fs +___uchar2fs: + clr a + mov r4, dpl + mov r3, a + mov r2, a + mov r1, a + mov a, #134 + ljmp ulong2fs_doit + _endasm; +} + +#else + + + /* convert unsigned char to float */ float __uchar2fs (unsigned char uc) { return __ulong2fs(uc); } + +#endif diff --git a/device/lib/_uint2fs.c b/device/lib/_uint2fs.c index 9b443fa9..bf752b02 100644 --- a/device/lib/_uint2fs.c +++ b/device/lib/_uint2fs.c @@ -1,6 +1,51 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#define SDCC_FLOAT_LIB #include + +#ifdef FLOAT_ASM_MCS51 + +// float long __uint2fs (float x) +static void dummy(void) _naked +{ + _asm + .globl ___uint2fs +___uint2fs: + clr a + mov r4, dph + mov r3, dpl + mov r2, a + mov r1, a + mov a, #142 + ljmp ulong2fs_doit + _endasm; +} + +#else + + + /* convert unsigned int to float */ float __uint2fs (unsigned int ui) { return __ulong2fs(ui); } + +#endif + diff --git a/device/lib/_ulong2fs.c b/device/lib/_ulong2fs.c index f3794204..1a4d6b58 100644 --- a/device/lib/_ulong2fs.c +++ b/device/lib/_ulong2fs.c @@ -1,3 +1,53 @@ +/* Floating point library in optimized assembly for 8051 + * Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + * + * This program 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 + * 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 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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#define SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// float long __ulong2fs (float x) +static void dummy(void) _naked +{ + _asm + .globl ___ulong2fs +___ulong2fs: + mov r4, a + mov r3, b + mov r2, dph + mov r1, dpl + mov a, #158 + .globl ulong2fs_doit +ulong2fs_doit: + clr sign_a +long2fs_doit: + mov exp_a, a + lcall fs_normalize_a + ljmp fs_round_and_return + _endasm; +} + +#else + + + /* ** libgcc support for software floating point. ** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. @@ -16,8 +66,6 @@ /* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ -#include - union float_long { float f; @@ -60,3 +108,6 @@ float __ulong2fs (unsigned long a ) return (fl.f); } + +#endif +