?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*-------------------------------------------------------------------------
  2.    _fs2slong.c - Floating point library in optimized assembly for 8051
  3.  
  4.    Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com
  5.  
  6.    This library is free software; you can redistribute it and/or modify it
  7.    under the terms of the GNU General Public License as published by the
  8.    Free Software Foundation; either version 2, or (at your option) any
  9.    later version.
  10.  
  11.    This library is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this library; see the file COPYING. If not, write to the
  18.    Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
  19.    MA 02110-1301, USA.
  20.  
  21.    As a special exception, if you link this library with other files,
  22.    some of which are compiled with SDCC, to produce an executable,
  23.    this library does not by itself cause the resulting executable to
  24.    be covered by the GNU General Public License. This exception does
  25.    not however invalidate any other reasons why the executable file
  26.    might be covered by the GNU General Public License.
  27. -------------------------------------------------------------------------*/
  28.  
  29.  
  30. #define __SDCC_FLOAT_LIB
  31. #include <float.h>
  32.  
  33.  
  34. #ifdef FLOAT_ASM_MCS51
  35.  
  36. // long __fs2slong (float x)
  37. static void dummy(void) __naked
  38. {
  39.         __asm
  40.         .globl  ___fs2slong
  41. ___fs2slong:
  42.         lcall   fsgetarg
  43.         clr     c
  44.         mov     a, #158
  45.         subb    a, exp_a
  46.         jc      fs2slong_maxval         //  |x| >= 2^32
  47. fs2slong_int_ok:
  48.         mov     r1, #0
  49.         lcall   fs_rshift_a
  50.         jnb     sign_a, fs2slong_pos
  51. fs2slong_neg:
  52.         mov     a, r1
  53.         cpl     a
  54.         add     a, #1
  55.         mov     dpl, a
  56.         mov     a, r2
  57.         cpl     a
  58.         addc    a, #0
  59.         mov     dph, a
  60.         mov     a, r3
  61.         cpl     a
  62.         addc    a, #0
  63.         mov     b, a
  64.         mov     a, r4
  65.         cpl     a
  66.         addc    a, #0
  67.         //Check for zero
  68.         jnz fs2slong_not_zero
  69.         mov a, dpl
  70.         orl a, dph
  71.         orl a, b
  72.         jnz fs2slong_clr_a
  73.         ret
  74. fs2slong_clr_a:
  75.         clr a
  76. fs2slong_not_zero:
  77.         jnb acc.7, fs2slong_maxval_neg  // x < -0x80000000
  78.         ret
  79. fs2slong_pos:
  80.         mov     a, r4
  81.         jb      acc.7, fs2slong_maxval_pos  //  x > 0x7FFFFFFF
  82.         mov     dpl, r1
  83.         mov     dph, r2
  84.         mov     b, r3
  85.         ret
  86. fs2slong_maxval:
  87.         jnb     sign_a, fs2slong_maxval_pos
  88. fs2slong_maxval_neg:
  89.         clr     a
  90.         mov     dpl, a
  91.         mov     dph, a
  92.         mov     b, a
  93.         mov     a, #0x80
  94.         ret
  95. fs2slong_maxval_pos:
  96.         mov     a, #0xFF
  97.         mov     dpl, a
  98.         mov     dph, a
  99.         mov     b, a
  100.         mov     a, #0x7F
  101.         ret
  102.         __endasm;
  103. }
  104.  
  105. #else
  106.  
  107. /* convert float to signed long */
  108. signed long __fs2slong (float f)
  109. {
  110.  
  111.   if (!f)
  112.     return 0;
  113.  
  114.   if (f<0) {
  115.     return -__fs2ulong(-f);
  116.   } else {
  117.     return __fs2ulong(f);
  118.   }
  119. }
  120.  
  121. #endif
  122.