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. ;                               from float to signed/unsigned int64
  35. ;
  36. include mdef.inc
  37. include struct.inc
  38.  
  39.         modstart        fsi8386
  40.  
  41.         xref    __U8LS
  42.         xref    __U8RS
  43.  
  44. ; Convert single precision float to unsigned 64-bit integer with truncation
  45. ; Input: [EAX] = 32-bit float
  46. ; Output: [EDX, EAX] = 64-bit integer
  47.  
  48.         xdefp   __FSU8
  49.         defp    __FSU8
  50.         push    ECX             ; save ECX
  51.         mov     CL,7fh+64       ; maximum number 2^64-1
  52.         call    __FSU           ; convert float to unsigned __int64
  53.         pop     ECX             ; restore ECX
  54.         ret                     ; return
  55.         endproc __FSU8
  56.  
  57. ; Convert single precision float to signed 64-bit integer with truncation
  58. ; Input: [EAX] = 32-bit float
  59. ; Output: [EDX, EAX] = 64-bit integer
  60.  
  61.         xdefp   __FSI8
  62.         defp    __FSI8
  63.         push    ECX             ; save ECX
  64.         mov     CL,7fh+63       ; maximum number 2^63-1
  65.         call    __FSI           ; convert float to signed __int64
  66.         pop     ECX             ; restore ECX
  67.         ret                     ; return
  68.         endproc __FSI8
  69.  
  70. __FSI   proc    near
  71. __FSU:                          ; what? they both do the same thing
  72.         or      EAX,EAX         ; check sign bit
  73.         jns     short __FSAbs   ; treat as unsigned if positive
  74.         call    __FSAbs         ; otherwise convert number
  75.         neg     EDX             ; negate the result
  76.         neg     EAX             ;
  77.         sbb     EDX,0           ;
  78.         ret                     ; return
  79.         endproc __FSI
  80.  
  81. __FSAbs proc near
  82.         or      EAX,EAX         ; check if number 0
  83.         je      short fltzero   ; if so, just return 0
  84.         _shl    EAX,1           ; shift mantissa over
  85.         rol     EAX,8           ; get exponent to bottom
  86.         cmp     AL,7fh          ; quit if number < 1.0
  87.         jb      short fltuflow  ; ...
  88.         push    EBX             ; save EBX
  89.         mov     CH,AL           ; save exponent
  90.         stc                     ; set carry for implied bit
  91.         rcr     EAX,1           ; put implied '1' bit in
  92.         shr     EAX,8           ; remove exponent and extra bit
  93.         mov     EDX,EAX         ; put into 64-bit hi part
  94.         xor     EAX,EAX         ; zero 64-bit lo part
  95.         cmp     CH,CL           ; check if exponent exceeds maximum
  96.         jae     short fltmax    ; return maximum value if so
  97.         sub     CH,7fh+55       ; calculate amount to shift (+ve -> left)
  98.         jae     short fltm_left ; jump if left shift/no shift
  99.         xchg    CH,CL           ; get shift count
  100.         neg     CL              ; make positive
  101.         mov     BX,CX
  102.         call    __U8RS          ; shift mantissa right
  103.         pop     EBX             ; restore EBX
  104.         ret                     ; return
  105.  
  106. fltm_left:
  107.         _if     ne              ; done if exponent exactly 55
  108.           mov     BL,CH         ; - get shift count
  109.           call    __U8LS        ; - shift mantissa left
  110.         _endif                  ; endif
  111.         pop     EBX             ; restore EBX
  112.         ret                     ; return
  113.  
  114. ; CL = 7fh+64  for unsigned
  115. ;      7fh+63  for signed
  116. fltmax:
  117.         mov     EAX,0FFFFFFFFh  ; return maximum value
  118.         mov     EDX,EAX         ;
  119.         sub     CL,7fh+64       ; subtract bias + 64, results in 0 or -1
  120.         neg     CL              ; get shift count
  121.         mov     BL,CL           ; set shift count
  122.         call    __U8RS          ; shift mantissa right 1 bit for signed
  123.         pop     EBX             ; restore EBX
  124.         ret                     ; return
  125.  
  126. fltuflow:
  127.         sub     EAX,EAX         ; ensure entire number 0
  128. fltzero:
  129.         sub     EDX,EDX         ;
  130.         ret                     ; return
  131.         endproc __FSAbs
  132.  
  133. ; Convert single precision float to unsigned 64-bit integer with rounding
  134. ; Input: [EAX] = 32-bit float
  135.  
  136. ;       xdefp   __RSU8
  137. ;       defp    __RSU8
  138. ; not implemented
  139. ;       endproc __RSU8
  140.  
  141. ; Convert single precision float to signed 64-bit integer with rounding
  142. ; Input: [EAX] = 32-bit float
  143.  
  144. ;       xdefp   __RSI8
  145. ;       defp    __RSI8
  146. ; not implemented
  147. ;       endproc __RSI8
  148.  
  149.         endmod
  150.         end
  151.