/ control.s (emx+gcc) -- Copyright (c) 1993 by Eberhard Mattes

#if !defined (LONG_DOUBLE)

        .globl  __control87

        .text

        .align  2, 0x90

/ unsigned _control87 (unsigned new, unsigned mask)

#define cw_old          0(%esp)
#define cw_new          2(%esp)
/define ret_addr        4(%esp)
#define new             8(%esp)
#define mask            12(%esp)

__control87:
        pushl   %ecx                    / Dummy (for control word)
        fstcww  cw_old                  / Store control word into memory
        movl    mask, %ecx              / Get mask
        jecxz   1f                      / Do not set cw => done
        movl    new, %edx               / Get new bits
        andl    %ecx, %edx              / Mask new bits by mask bits
        notl    %ecx
        movl    cw_old, %eax            / Get old cw
        andl    %ecx, %eax              / Apply mask to old cw
        orl     %edx, %eax              / Insert new bits
        movw    %ax, cw_new             / Put new cw into memory
        fldcww  cw_new                  / Load control word
1:      popl    %eax                    / Return old cw in lower 16 bits
        movzwl  %ax, %eax               / Clear upper 16 bits
        ret

#endif
