Skip to content

Commit c698be4

Browse files
author
Siva Chandra Reddy
committed
[libc] Raise denormal exception if the libc defines __FE_DENORM.
Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D106604
1 parent d12ee28 commit c698be4

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

libc/utils/FPUtil/x86_64/FEnvImpl.h

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -251,41 +251,29 @@ static inline int raiseExcept(int excepts) {
251251
// ensure that the writes by the exception handler are maintained
252252
// when raising the next exception.
253253

254-
if (statusValue & internal::ExceptionFlags::Invalid) {
254+
auto raiseHelper = [](uint16_t singleExceptFlag) {
255255
internal::X87StateDescriptor state;
256256
internal::getX87StateDescriptor(state);
257-
state.StatusWord |= internal::ExceptionFlags::Invalid;
258-
internal::writeX87StateDescriptor(state);
259-
internal::fwait();
260-
}
261-
if (statusValue & internal::ExceptionFlags::DivByZero) {
262-
internal::X87StateDescriptor state;
263-
internal::getX87StateDescriptor(state);
264-
state.StatusWord |= internal::ExceptionFlags::DivByZero;
265-
internal::writeX87StateDescriptor(state);
266-
internal::fwait();
267-
}
268-
if (statusValue & internal::ExceptionFlags::Overflow) {
269-
internal::X87StateDescriptor state;
270-
internal::getX87StateDescriptor(state);
271-
state.StatusWord |= internal::ExceptionFlags::Overflow;
272-
internal::writeX87StateDescriptor(state);
273-
internal::fwait();
274-
}
275-
if (statusValue & internal::ExceptionFlags::Underflow) {
276-
internal::X87StateDescriptor state;
277-
internal::getX87StateDescriptor(state);
278-
state.StatusWord |= internal::ExceptionFlags::Underflow;
279-
internal::writeX87StateDescriptor(state);
280-
internal::fwait();
281-
}
282-
if (statusValue & internal::ExceptionFlags::Inexact) {
283-
internal::X87StateDescriptor state;
284-
internal::getX87StateDescriptor(state);
285-
state.StatusWord |= internal::ExceptionFlags::Inexact;
257+
state.StatusWord |= singleExceptFlag;
286258
internal::writeX87StateDescriptor(state);
287259
internal::fwait();
260+
};
261+
262+
if (statusValue & internal::ExceptionFlags::Invalid)
263+
raiseHelper(internal::ExceptionFlags::Invalid);
264+
if (statusValue & internal::ExceptionFlags::DivByZero)
265+
raiseHelper(internal::ExceptionFlags::DivByZero);
266+
if (statusValue & internal::ExceptionFlags::Overflow)
267+
raiseHelper(internal::ExceptionFlags::Overflow);
268+
if (statusValue & internal::ExceptionFlags::Underflow)
269+
raiseHelper(internal::ExceptionFlags::Underflow);
270+
if (statusValue & internal::ExceptionFlags::Inexact)
271+
raiseHelper(internal::ExceptionFlags::Inexact);
272+
#ifdef __FE_DENORM
273+
if (statusValue & internal::ExceptionFlags::Denormal) {
274+
raiseHelper(internal::ExceptionFlags::Denormal);
288275
}
276+
#endif // __FE_DENORM
289277

290278
// There is no special synchronization scheme available to
291279
// raise SEE exceptions. So, we will ignore that for now.

0 commit comments

Comments
 (0)