common/fp/op/FPRecipExponent: Prevent undefined behavior from shifting a negative value
Due to promotion rules (types < int, even if unsigned, get promoted to int when arithmetic is performed on them), this is a potential spot for undefined behavior.
This commit is contained in:
parent
51fe05a443
commit
46eae8cf2f
1 changed files with 3 additions and 2 deletions
|
@ -48,8 +48,9 @@ FPT FPRecipExponent(FPT op, FPCR fpcr, FPSR& fpsr) {
|
|||
}
|
||||
|
||||
// Infinities and normals
|
||||
const auto negated_exponent = (~exponent << FPInfo<FPT>::explicit_mantissa_width) & FPInfo<FPT>::exponent_mask;
|
||||
return FPT(sign_bits | negated_exponent);
|
||||
const FPT negated_exponent = FPT(~exponent);
|
||||
const FPT adjusted_exponent = FPT(negated_exponent << FPInfo<FPT>::explicit_mantissa_width) & FPInfo<FPT>::exponent_mask;
|
||||
return FPT(sign_bits | adjusted_exponent);
|
||||
}
|
||||
|
||||
template u16 FPRecipExponent<u16>(u16 op, FPCR fpcr, FPSR& fpsr);
|
||||
|
|
Loading…
Reference in a new issue