/* SPDX-License-Identifier: GPL-2.0 */1/*---------------------------------------------------------------------------+2| reg_norm.S |3| |4| Copyright (C) 1992,1993,1994,1995,1997 |5| W. Metzenthen, 22 Parker St, Ormond, Vic 3163, |6| Australia. E-mail [email protected] |7| |8| Normalize the value in a FPU_REG. |9| |10| Call from C as: |11| int FPU_normalize(FPU_REG *n) |12| |13| int FPU_normalize_nuo(FPU_REG *n) |14| |15| Return value is the tag of the answer, or-ed with FPU_Exception if |16| one was raised, or -1 on internal error. |17| |18+---------------------------------------------------------------------------*/1920#include "fpu_emu.h"212223.text24SYM_FUNC_START(FPU_normalize)25pushl %ebp26movl %esp,%ebp27pushl %ebx2829movl PARAM1,%ebx3031movl SIGH(%ebx),%edx32movl SIGL(%ebx),%eax3334orl %edx,%edx /* ms bits */35js L_done /* Already normalized */36jnz L_shift_1 /* Shift left 1 - 31 bits */3738orl %eax,%eax39jz L_zero /* The contents are zero */4041movl %eax,%edx42xorl %eax,%eax43subw $32,EXP(%ebx) /* This can cause an underflow */4445/* We need to shift left by 1 - 31 bits */46L_shift_1:47bsrl %edx,%ecx /* get the required shift in %ecx */48subl $31,%ecx49negl %ecx50shld %cl,%eax,%edx51shl %cl,%eax52subw %cx,EXP(%ebx) /* This can cause an underflow */5354movl %edx,SIGH(%ebx)55movl %eax,SIGL(%ebx)5657L_done:58cmpw EXP_OVER,EXP(%ebx)59jge L_overflow6061cmpw EXP_UNDER,EXP(%ebx)62jle L_underflow6364L_exit_valid:65movl TAG_Valid,%eax6667/* Convert the exponent to 80x87 form. */68addw EXTENDED_Ebias,EXP(%ebx)69andw $0x7fff,EXP(%ebx)7071L_exit:72popl %ebx73leave74RET757677L_zero:78movw $0,EXP(%ebx)79movl TAG_Zero,%eax80jmp L_exit8182L_underflow:83/* Convert the exponent to 80x87 form. */84addw EXTENDED_Ebias,EXP(%ebx)85push %ebx86call arith_underflow87pop %ebx88jmp L_exit8990L_overflow:91/* Convert the exponent to 80x87 form. */92addw EXTENDED_Ebias,EXP(%ebx)93push %ebx94call arith_overflow95pop %ebx96jmp L_exit97SYM_FUNC_END(FPU_normalize)9899100101/* Normalise without reporting underflow or overflow */102SYM_FUNC_START(FPU_normalize_nuo)103pushl %ebp104movl %esp,%ebp105pushl %ebx106107movl PARAM1,%ebx108109movl SIGH(%ebx),%edx110movl SIGL(%ebx),%eax111112orl %edx,%edx /* ms bits */113js L_exit_nuo_valid /* Already normalized */114jnz L_nuo_shift_1 /* Shift left 1 - 31 bits */115116orl %eax,%eax117jz L_exit_nuo_zero /* The contents are zero */118119movl %eax,%edx120xorl %eax,%eax121subw $32,EXP(%ebx) /* This can cause an underflow */122123/* We need to shift left by 1 - 31 bits */124L_nuo_shift_1:125bsrl %edx,%ecx /* get the required shift in %ecx */126subl $31,%ecx127negl %ecx128shld %cl,%eax,%edx129shl %cl,%eax130subw %cx,EXP(%ebx) /* This can cause an underflow */131132movl %edx,SIGH(%ebx)133movl %eax,SIGL(%ebx)134135L_exit_nuo_valid:136movl TAG_Valid,%eax137138popl %ebx139leave140RET141142L_exit_nuo_zero:143movl TAG_Zero,%eax144movw EXP_UNDER,EXP(%ebx)145146popl %ebx147leave148RET149SYM_FUNC_END(FPU_normalize_nuo)150151152