Subversion Repositories Kolibri OS

Rev

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

  1. ;*****************************************************************************
  2. ;*
  3. ;*                            Open Watcom Project
  4. ;*
  5. ;*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. ;*
  7. ;*  ========================================================================
  8. ;*
  9. ;*    This file contains Original Code and/or Modifications of Original
  10. ;*    Code as defined in and that are subject to the Sybase Open Watcom
  11. ;*    Public License version 1.0 (the 'License'). You may not use this file
  12. ;*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. ;*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. ;*    provided with the Original Code and Modifications, and is also
  15. ;*    available at www.sybase.com/developer/opensource.
  16. ;*
  17. ;*    The Original Code and all software distributed under the License are
  18. ;*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. ;*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. ;*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. ;*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. ;*    NON-INFRINGEMENT. Please see the License for the specific language
  23. ;*    governing rights and limitations under the License.
  24. ;*
  25. ;*  ========================================================================
  26. ;*
  27. ;* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
  28. ;*               DESCRIBE IT HERE!
  29. ;*
  30. ;*****************************************************************************
  31.  
  32.  
  33. ;========================================================================
  34. ;==     Name:           I4FS, U4FS                                     ==
  35. ;==     Operation:      Convert Integer types to single precision      ==
  36. ;==     Inputs:         EAX,   unsigned or signed integer              ==
  37. ;==     Outputs:        EAX   single precision floating point          ==
  38. ;==     Volatile:       none                                           ==
  39. ;==                                                                    ==
  40. ;========================================================================
  41. include mdef.inc
  42. include struct.inc
  43.  
  44.         modstart        i4fs386
  45.  
  46.         xdefp   __I4FS
  47.         xdefp   __U4FS
  48.  
  49.  
  50.         defpe   __U4FS
  51.         or      EAX,EAX         ; if number is not zero
  52.         _if     ne              ; then
  53.           push  ECX             ; - save ECX
  54.           bsr   ECX,EAX         ; - find most significant non-zero bit
  55.           mov   CH,CL           ; - save shift count
  56.           neg   CL              ; - calculate # of bits to rotate by
  57.           add   CL,23           ; - ...
  58.           and   CL,1fh          ; - just keep last 5 bits
  59.           rol   EAX,CL          ; - shift bits into position
  60.           and   EAX,007FFFFFh   ; - mask out sign and exponent bits
  61.           mov   CL,CH           ; - get shift count
  62.           add   CL,7Fh          ; - calculate exponent
  63.           and   ECX,0FFh        ; - isolate exponent
  64.           shl   ECX,23          ; - shift exponent into position
  65.           or    EAX,ECX         ; - place into result
  66.           pop   ECX             ; - restore ECX
  67.         _endif                  ; endif
  68.         ret                     ; return
  69.  
  70.         endproc __U4FS
  71.  
  72.         defpe   __I4FS
  73.         or      EAX,EAX         ; check sign
  74.         jns     __U4FS          ; if positive, just convert
  75.         neg     EAX             ; take absolute value of number
  76.         call    __U4FS          ; convert to FS
  77.         or      EAX,80000000h   ; set sign bit on
  78.         ret                     ; and return
  79.         endproc __I4FS
  80.  
  81.         endmod
  82.         end
  83.