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. include mdef.inc
  34. include struct.inc
  35.  
  36.                 modstart        fsms386
  37.  
  38.                 xdefp   "C",_fieeetomsbin
  39.                 defpe   _fieeetomsbin
  40.  
  41. ifdef __STACK__
  42.                 mov     eax,dword ptr +4H[esp]
  43.                 mov     edx,dword ptr +8H[esp]
  44. endif
  45.  
  46. ; At this point:
  47. ; eax     - ptr to IEEE source float
  48. ; edx     - ptr to MBF dest float
  49.  
  50.                 mov     eax,[eax]       ; load IEEE float
  51.                 test    eax,7fe00000h   ; IEEE exponent != 0 or convertable
  52.                                         ; denormal ?
  53.                 jne     IEEENonZero     ; :
  54.  
  55. ; IEEE Zero or IEEE unconvertable denormal, store MBF Zero
  56.                 xor     eax,eax         ; 0
  57.                 mov     [edx],eax       ; store MBF 0.0F
  58.                 ret                     ; return 0 (no overflow)
  59.  
  60. ; At this point:
  61. ; eax     - IEEE source float
  62. ; edx     - ptr to MBF dest float
  63.  
  64. IEEENonZero:    rol     eax,9           ; rotate for exponent analysis
  65.                 test    al,al           ; IEEE convertable denormal ?
  66.                 je      IEEEDenormal    ; yes, jump
  67.                 add     al,2            ; MBF exponent = IEEE exponent + 2
  68.                 jc      IEEEOverflow    ; jump if overflow
  69.                 shr     eax,1           ; rotate sign bit and exponent
  70.                 adc     al,al           ; :
  71.                 adc     eax,eax         ; :
  72.                 ror     eax,9           ; rotate so MBF float
  73.  
  74. MBFStore:       mov     [edx],eax       ; store MBF float
  75.                 xor     eax,eax         ; 0
  76.                 ret                     ; return 0 (no overflow)
  77.  
  78. ; One of leading 2 bits of mantissa is a 1
  79. IEEEDenormal:
  80. ifndef __STACK__
  81.                 push    ecx             ; save register
  82. endif
  83.                 mov     ecx,eax         ; save sign bit and exponent
  84.                 and     ah,0FEh         ; eliminate sign bit
  85. DenormalLoop:   inc     ecx             ; increment count
  86.                 add     eax,eax         ; shift mantissa
  87.                 jnc     DenormalLoop    ; loop while no implied 1
  88.                 xor     ecx,3h          ; invert count (new exponent)
  89.                 shr     ecx,1           ; rotate exponent and sign bit
  90.                 adc     cl,cl           ; :
  91.                 adc     ecx,ecx         ; :
  92.                 shrd    eax,ecx,9       ; combine mantissa (eax) and
  93.                                         ; exponent& sign bit (ecx)
  94. ifndef __STACK__
  95.                 pop     ecx             ; restore register
  96. endif
  97.                 jmp     MBFStore        ; continue
  98.  
  99. IEEEOverflow:   rol     eax,15          ; rotate sign bit into place
  100.                 or      eax,0FF7FFFFFh  ; set MBF exponent and mantissa to
  101.                                         ; maximum but preserve MBF sign
  102.                 mov     [edx],eax       ; store MBF float
  103.                 and     eax,1           ; 1
  104.                 ret                     ; return 1 (overflow)
  105.  
  106.                 endproc _fieeetomsbin
  107.  
  108.                 endmod
  109.                 end
  110.