#ifndef NON_REENTRANT_FPU /* Make the code re-entrant by putting
local storage on the stack: */
#define FPU_bits_lost (%esp)
#define FPU_denormal 1(%esp)
#else /* Not re-entrant, so we can gain speed by putting
local storage in a static area: */
.data
.align4,0
FPU_bits_lost:
.byte 0
FPU_denormal:
.byte 0
#endif /* NON_REENTRANT_FPU */
.text
.globl fpu_reg_round
.globl fpu_Arith_exit
/* Entry point when called from C */
SYM_FUNC_START(FPU_round)
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
pushl %ebx
#ifdef PARANOID /* Cannot use this here yet */ /* orl %eax,%eax */ /* jns L_entry_bugged */
#endif /* PARANOID */
cmpw EXP_UNDER,EXP(%edi)
jle L_Make_denorm /* The number is a de-normal */
movb $0,FPU_denormal /* 0 -> not a de-normal */
Denorm_done:
movb $0,FPU_bits_lost /* No bits yet lost in rounding */
movl %ecx,%esi
andl CW_PC,%ecx
cmpl PR_64_BITS,%ecx
je LRound_To_64
cmpl PR_53_BITS,%ecx
je LRound_To_53
cmpl PR_24_BITS,%ecx
je LRound_To_24
#ifdef PECULIAR_486 /* With the precision control bits set to 01 "(reserved)", a real 80486
behaves as if the precision control bits were set to 11 "64 bits" */
cmpl PR_RESERVED_BITS,%ecx
je LRound_To_64
#ifdef PARANOID
jmp L_bugged_denorm_486
#endif /* PARANOID */
#else
#ifdef PARANOID
jmp L_bugged_denorm /* There is no bug, just a bad control word */
#endif /* PARANOID */
#endif /* PECULIAR_486 */
/* Round etc to 24 bit precision */
LRound_To_24:
movl %esi,%ecx
andl CW_RC,%ecx
cmpl RC_RND,%ecx
je LRound_nearest_24
cmpl RC_CHOP,%ecx
je LCheck_truncate_24
cmpl RC_UP,%ecx /* Towards +infinity */
je LUp_24
cmpl RC_DOWN,%ecx /* Towards -infinity */
je LDown_24
LRound_nearest_24: /* Do rounding of the 24th bit if needed (nearest or even) */
movl %eax,%ecx
andl $0x000000ff,%ecx
cmpl $0x00000080,%ecx
jc LCheck_truncate_24 /* less than half, no increment needed */
jne LGreater_Half_24 /* greater than half, increment needed */
/* Possibly half, we need to check the ls bits */
orl %ebx,%ebx
jnz LGreater_Half_24 /* greater than half, increment needed */
LRound_nearest_53: /* Do rounding of the 53rd bit if needed (nearest or even) */
movl %ebx,%ecx
andl $0x000007ff,%ecx
cmpl $0x00000400,%ecx
jc LCheck_truncate_53 /* less than half, no increment needed */
jnz LGreater_Half_53 /* greater than half, increment needed */
/* Possibly half, we need to check the ls bits */
orl %edx,%edx
jnz LGreater_Half_53 /* greater than half, increment needed */
/* Exactly half, increment only if 53rd bit is 1 (round to even) */
testl $0x00000800,%ebx
jz LTruncate_53
LGreater_Half_53: /* Rounding: increment at the 53rd bit */
LDo_53_round_up:
movb LOST_UP,FPU_bits_lost
andl $0xfffff800,%ebx /* Truncate to 53 bits */
addl $0x00000800,%ebx
adcl $0,%eax
jmp LCheck_Round_Overflow
/* *Thenumberisadenormal(whichmightgetroundeduptoanormal) *Shiftthenumberrighttherequirednumberofbits,whichwill *havetobeundonelater...
*/
L_Make_denorm: /* The action to be taken depends upon whether the underflow
exception is masked */
testb CW_Underflow,%cl /* Underflow mask. */
jz Unmasked_underflow /* Do not make a denormal. */
movb DENORMAL,FPU_denormal
pushl %ecx /* Save */
movw EXP_UNDER+1,%cx
subw EXP(%edi),%cx
cmpw $64,%cx /* shrd only works for 0..31 bits */
jnc Denorm_shift_more_than_63
cmpw $32,%cx /* shrd only works for 0..31 bits */
jnc Denorm_shift_more_than_32
/* Undo the de-normalisation. */
Normalise_result:
cmpb UNMASKED_UNDERFLOW,FPU_denormal
je Signal_underflow
/* The number must be a denormal if we got here. */
#ifdef PARANOID /* But check it... just in case. */
cmpw EXP_UNDER+1,EXP(%edi)
jne L_norm_bugged
#endif /* PARANOID */
#ifdef PECULIAR_486 /* *Thisimplementsaspecialfeatureof80486behaviour. *Underflowwillbesignaledevenifthenumberis *notadenormalafterrounding. *Thisdifferenceoccursonlyformaskedunderflow,andnot *intheunmaskedcase. *Actual80486behaviourdiffersfromthisinsomecircumstances.
*/
orl %eax,%eax /* ms bits */
js LPseudoDenormal /* Will be masked underflow */
#else
orl %eax,%eax /* ms bits */
js L_Normalised /* No longer a denormal */
#endif /* PECULIAR_486 */
jnz LDenormal_adj_exponent
orl %ebx,%ebx
jz L_underflow_to_zero /* The contents are zero */
/* Reduce the exponent to EXP_UNDER */
movw EXP_UNDER,EXP(%edi)
movl TAG_Zero,%edx
jmp L_Store_significand
/* The operations resulted in a number too large to represent. */
L_overflow:
addw EXTENDED_Ebias,EXP(%edi) /* Set for unmasked response. */
push %edi
call arith_overflow
pop %edi
jmp fpu_reg_round_signed_special_exit
Signal_underflow: /* The number may have been changed to a non-denormal */ /* by the rounding operations. */
cmpw EXP_UNDER,EXP(%edi)
jle Do_unmasked_underflow
jmp L_Normalised
Do_unmasked_underflow: /* Increase the exponent by the magic number */
addw $(3*(1<<13)),EXP(%edi)
push %eax
pushl EX_Underflow
call EXCEPTION
popl %eax
popl %eax
jmp L_Normalised
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.