Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
art::FloatingPointControl Class Reference

#include <FloatingPointControl.h>

Classes

struct  Config
 

Public Types

using precision_t = fp_detail::precision_t
 
using mask_t = unsigned short int
 
using Parameters = ServiceTable< Config >
 

Public Member Functions

 FloatingPointControl (Parameters const &, ActivityRegistry &)
 
 FloatingPointControl (FloatingPointControl const &)=delete
 
FloatingPointControloperator= (FloatingPointControl const &)=delete
 
precision_t getPrecision () const
 
mask_t getMask () const
 

Private Member Functions

void postEndJob ()
 

Private Attributes

bool enableDivByZeroEx_
 
bool enableInvalidEx_
 
bool enableOverFlowEx_
 
bool enableUnderFlowEx_
 
bool setPrecisionDouble_
 
bool reportSettings_
 
fp_detail::fp_control_t OSdefault_ {}
 

Detailed Description

Definition at line 51 of file FloatingPointControl.h.

Member Typedef Documentation

using art::FloatingPointControl::mask_t = unsigned short int

Definition at line 54 of file FloatingPointControl.h.

Definition at line 68 of file FloatingPointControl.h.

Definition at line 53 of file FloatingPointControl.h.

Constructor & Destructor Documentation

art::FloatingPointControl::FloatingPointControl ( Parameters const &  c,
ActivityRegistry reg 
)
explicit

Definition at line 29 of file FloatingPointControl.cc.

31  : enableDivByZeroEx_{c().enableDivByZeroEx()}
32  , enableInvalidEx_{c().enableInvalidEx()}
33  , enableOverFlowEx_{c().enableOverFlowEx()}
34  , enableUnderFlowEx_{c().enableUnderFlowEx()}
35  , setPrecisionDouble_{c().setPrecisionDouble()}
36  , reportSettings_{c().reportSettings()}
38  {
39  reg.sPostEndJob.watch(this, &FloatingPointControl::postEndJob);
40  if (reportSettings_) {
41  mf::LogVerbatim("FPE_Enable") << "\nOS's FP settings";
42  echoState();
43  }
44  // Update the state according to the user's configuration
45  {
46  // NB: We do not let users configure signaling of denormalized operand
47  // (fpControl_DENORMALOPERAND) or inexact (FE_INEXACT), both of which
48  // are suppressed.
49  unsigned short int enable_except{};
50  unsigned short int enable_sse{};
51  if (enableDivByZeroEx_) {
52  enable_except |= FE_DIVBYZERO;
53  enable_sse |= fpControl_ZM_MASK;
54  }
55  if (enableInvalidEx_) {
56  enable_except |= FE_INVALID;
57  enable_sse |= fpControl_IM_MASK;
58  }
59  if (enableOverFlowEx_) {
60  enable_except |= FE_OVERFLOW;
61  enable_sse |= fpControl_OM_MASK;
62  }
63  if (enableUnderFlowEx_) {
64  enable_except |= FE_UNDERFLOW;
65  enable_sse |= fpControl_UM_MASK;
66  }
67  auto fpControl = getFPControl();
68  // Reset exception mask before clearing the bits we care about.
69  fpControl.fpcw = (fpControl.fpcw | FE_ALL_EXCEPT) & (~enable_except);
70  if (setPrecisionDouble_) {
71  // Clear precision bits before setting only the ones we care about.
72  fpControl.fpcw =
73  (fpControl.fpcw & (~fpControl_ALL_PREC)) | fpControl_DOUBLE_PREC;
74  }
75 #ifdef fpControl_HAVE_MXCSR
76  // Reset exception mask before clearing the bits we care about.
77  fpControl.mxcsr =
78  (fpControl.mxcsr | fpControl_ALL_SSE_EXCEPT) & (~enable_sse);
79 #endif
80  // Write back.
81  (void)setFPControl(fpControl);
82  }
83  if (reportSettings_) {
84  mf::LogVerbatim("FPE_Enable")
85  << "\nUpdated FP settings per user's configuration";
86  if (reportSettings_) {
87  echoState();
88  }
89  }
90  }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
fp_detail::fp_control_t OSdefault_
fp_control_t getFPControl()
Definition: fpControl.h:130
fp_control_t setFPControl(fp_control_t const &fpControl)
Definition: fpControl.h:142
art::FloatingPointControl::FloatingPointControl ( FloatingPointControl const &  )
delete

Member Function Documentation

auto art::FloatingPointControl::getMask ( ) const

Definition at line 109 of file FloatingPointControl.cc.

110  {
111  return static_cast<mask_t>(getFPCW() & FE_ALL_EXCEPT);
112  }
fpcw_t getFPCW()
Definition: fpControl.cc:28
auto art::FloatingPointControl::getPrecision ( ) const

Definition at line 103 of file FloatingPointControl.cc.

104  {
105  return static_cast<precision_t>(getFPCW() & fpControl_ALL_PREC);
106  }
fpcw_t getFPCW()
Definition: fpControl.cc:28
FloatingPointControl& art::FloatingPointControl::operator= ( FloatingPointControl const &  )
delete
void art::FloatingPointControl::postEndJob ( )
private

Definition at line 93 of file FloatingPointControl.cc.

94  {
95  (void)setFPControl(OSdefault_);
96  if (reportSettings_) {
97  mf::LogVerbatim("FPE_Enable") << "\nRestored to OS's FPE settings";
98  echoState();
99  }
100  }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
fp_detail::fp_control_t OSdefault_
fp_control_t setFPControl(fp_control_t const &fpControl)
Definition: fpControl.h:142

Member Data Documentation

bool art::FloatingPointControl::enableDivByZeroEx_
private

Definition at line 82 of file FloatingPointControl.h.

bool art::FloatingPointControl::enableInvalidEx_
private

Definition at line 83 of file FloatingPointControl.h.

bool art::FloatingPointControl::enableOverFlowEx_
private

Definition at line 84 of file FloatingPointControl.h.

bool art::FloatingPointControl::enableUnderFlowEx_
private

Definition at line 85 of file FloatingPointControl.h.

fp_detail::fp_control_t art::FloatingPointControl::OSdefault_ {}
private

Definition at line 89 of file FloatingPointControl.h.

bool art::FloatingPointControl::reportSettings_
private

Definition at line 87 of file FloatingPointControl.h.

bool art::FloatingPointControl::setPrecisionDouble_
private

Definition at line 86 of file FloatingPointControl.h.


The documentation for this class was generated from the following files: