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. include mdef.inc
  35. include struct.inc
  36.  
  37.         modstart        i4fd386
  38.  
  39.         xdefp   __I4FD
  40.         xdefp   __U4FD
  41.  
  42. ;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
  43. ;[]
  44. ;[] __I4FD      convert signed 32-bit integer in EAX into double float
  45. ;[] __U4FD      convert unsigned 32-bit integer in EAX into double float
  46. ;[]     Input:  EAX         - 32-bit integer
  47. ;[]     Output: EDX:EAX     - double precision representation of integer
  48. ;[]
  49. ;[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
  50.  
  51.         defpe   __I4FD
  52.         or      EAX,EAX         ; if number is negative
  53.         _if     s               ; then
  54.           neg   EAX             ; - negate number
  55.           mov   EDX,00000BFFh   ; - set exponent
  56.         _else                   ; else
  57.  
  58. ;       convert unsigned 32-bit integer to double
  59.  
  60.         defpe   __U4FD
  61.           mov   EDX,000003FFh   ; - set exponent
  62.         _endif                  ; endif
  63.         or      EAX,EAX         ; if number is not zero
  64.         _if     ne              ; then
  65.           push  ECX             ; - save ECX
  66.           bsr   ECX,EAX         ; - find most significant non-zero bit
  67.           mov   CH,CL           ; - save shift count
  68.           mov   CL,31           ; - calculate # of bits to shift by
  69.           sub   CL,CH           ; - ...
  70.           shl   EAX,CL          ; - shift bits into position
  71.           _shl  EAX,1           ; - one more to get rid of implied 1 bit
  72.           mov   CL,CH           ; - get shift count
  73.           movzx ECX,CH          ; - get shift count
  74.           add   ECX,EDX         ; - calculate exponent
  75.           mov   EDX,EAX         ; - get the bits
  76.           and   EDX,0FFFFF000h  ; - keep 20 bits
  77.           or    EDX,ECX         ; - get exponent in there
  78.           ror   EDX,12          ; - rotate into position
  79.           shl   EAX,20          ; - get last 12 bits into place
  80.           pop   ECX             ; - restore ECX
  81.           ret                   ; - return
  82.         _endif                  ; endif
  83.         sub     EDX,EDX         ; zero EDX
  84.         ret                     ; return
  85.  
  86.         endproc __U4FD
  87.         endproc __I4FD
  88.  
  89.         endmod
  90.         end
  91.