Annotation of coherent/b/lib/libc/crt/i386/fdcvt.s, revision 1.1

1.1     ! root        1: //////////
        !             2: / libc/crt/i386/fdcvt.s
        !             3: / i386 C runtime library.
        !             4: / IEEE software floating point support.
        !             5: //////////
        !             6: 
        !             7: //////////
        !             8: / "float" _fdcvt()
        !             9: / Convert double in %edx:%eax to float, return in %eax.
        !            10: //////////
        !            11: 
        !            12: BIAS           .equ    1023
        !            13: FBIAS          .equ    127
        !            14: SGNMASK                .equ    0x80000000
        !            15: EXPMASK                .equ    0x7FF00000
        !            16: MANMASK                .equ    0x000FFFFF
        !            17: FEXPMASK       .equ    0x7F800000
        !            18: FMANMASK       .equ    0x007FFFFF
        !            19: FHIDDEN                .equ    0x00800000
        !            20: FMAXEXP                .equ    255
        !            21: 
        !            22:        .globl  _fdcvt
        !            23: 
        !            24: _fdcvt:
        !            25:        push    %ecx
        !            26:        mov     %ecx, %edx
        !            27:        andl    %ecx, $EXPMASK          / extract exponent in ECX
        !            28:        jz      ?zero                   / return 0.0, ignoring denormals
        !            29:        orl     %edx, %edx
        !            30:        pushfl                          / save arg sign
        !            31:        shrl    %ecx, $20               / biased double exponent in ECX
        !            32:        subl    %ecx, $BIAS-FBIAS       / adjust to float exponent bias
        !            33:        jle     ?zerof                  / underflow, return 0.0
        !            34:        cmpl    %ecx, $FMAXEXP
        !            35:        jge     ?inf                    / overflow, return +-infinity
        !            36:        andl    %edx, $MANMASK          / high mantissa bits in EDX, hidden bit implicit
        !            37:        shrd    %eax, %edx, $29         / float mantissa in EAX, hidden bit implicit
        !            38:        jnc     ?pack                   / no rounding required
        !            39:        incl    %eax                    / round up float mantissa
        !            40:        testl   %eax, $FHIDDEN          / check for carry past hidden bit
        !            41:        jz      ?pack                   / ok as is
        !            42:        xorl    %eax, %eax              / clear hidden bit in mantissa, now 0
        !            43:        incl    %ecx                    / adjust the exponent
        !            44:        cmpl    %ecx, $FMAXEXP
        !            45:        jge     ?inf                    / overflow, return +-infinity
        !            46: ?pack:
        !            47:        shll    %ecx, $23               / position float exponent
        !            48:        orl     %eax, %ecx              / combine exponent and mantissa
        !            49: ?setsign:
        !            50:        popfl                           / restore arg sign
        !            51:        jns     ?done
        !            52:        orl     %eax, $SGNMASK          / set result sign
        !            53: ?done:
        !            54:        pop     %ecx
        !            55:        ret
        !            56: 
        !            57: ?inf:
        !            58:        movl    %eax, $FEXPMASK
        !            59:        jmp     ?setsign                / return +-infinity
        !            60: 
        !            61: ?zerof:
        !            62:        popfl
        !            63: ?zero:
        !            64:        subl    %eax, %eax              / return 0.0
        !            65:        pop     %ecx
        !            66:        ret
        !            67: 
        !            68: / end of libc/crt/i386/fdcvt.s

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.