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:           FDFS                                            ==
  35. ;==     Operation:      Float double to float single conversion         ==
  36. ;==     Inputs:         EDX:EAX         double precision float          ==
  37. ;==     Outputs:        EAX             single precision float          ==
  38. ;==     Volatile:       EDX destroyed                                   ==
  39. ;=========================================================================
  40. include mdef.inc
  41. include struct.inc
  42.  
  43.         modstart        fdfs386
  44.  
  45.         xdefp   __FDFS
  46.  
  47.         defpe   __FDFS
  48.         push    EBX             ; save EBX
  49.         test    EDX,07ff00000h  ; check exponent
  50.         je      short retzero   ; if exponent = 0 then just return 0
  51.         sub     EBX,EBX         ; set to 0
  52.         _shl    EAX,1           ; shift number over
  53.         _rcl    EDX,1           ; ...
  54.         rcr     EBX,1           ; save sign
  55.         add     EAX,20000000h   ; round floating point number
  56.         adc     EDX,0           ; ...
  57.         je      oflow           ; overflow if exponent went to 0
  58.         cmp     EDX,(03ffh+80h) shl 21 ; check for maximum exponent
  59.         jae     oflow           ; overflow if above or equal
  60.         cmp     EDX,(03ffh-7eh) shl 21 ; check for minimum exponent
  61.         jb      uflow           ; underflow if below
  62.         sub     EDX,(03ffh-7fh) shl 21 ; correct bias
  63.         _shl    EAX,1           ; do rest of shift
  64.         _rcl    EDX,1           ; ...
  65.         _shl    EAX,1           ; ...
  66.         _rcl    EDX,1           ; ...
  67.         or      EDX,EBX         ; put in sign bit
  68.         mov     EAX,EDX         ; get result into EAX
  69.         pop     EBX             ; restore EBX
  70.         ret                     ; return
  71.  
  72. oflow:  mov     EAX,7F800000h   ; return maximum possible number
  73.         or      EAX,EBX         ; put in sign bit
  74.         pop     EBX             ; restore EBX
  75.         ret                     ; and return
  76.  
  77. uflow:
  78. retzero:sub     EAX,EAX         ; set result to 0
  79.         pop     EBX             ; restore EBX
  80.         ret
  81.         endproc __FDFS
  82.  
  83.         endmod
  84.         end
  85.