LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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

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

Private Member Functions

 FloatingPointControl (FloatingPointControl const &)=delete
 
FloatingPointControloperator= (FloatingPointControl const &)=delete
 
void postEndJob ()
 
void controlFpe ()
 
void echoState ()
 

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 55 of file FloatingPointControl.h.

Member Typedef Documentation

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

Definition at line 63 of file FloatingPointControl.h.

Constructor & Destructor Documentation

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

Definition at line 10 of file FloatingPointControl_service.cc.

References controlFpe(), echoState(), enableInvalidEx_, enableOverFlowEx_, enableUnderFlowEx_, art::fp_detail::getFPControl(), OSdefault_, postEndJob(), reportSettings_, and setPrecisionDouble_.

12  : enableDivByZeroEx_{c().enableDivByZeroEx()}
13  , enableInvalidEx_{c().enableInvalidEx()}
14  , enableOverFlowEx_{c().enableOverFlowEx()}
15  , enableUnderFlowEx_{c().enableUnderFlowEx()}
16  , setPrecisionDouble_{c().setPrecisionDouble()}
17  , reportSettings_{c().reportSettings()}
19 {
20  reg.sPostEndJob.watch(this, &FloatingPointControl::postEndJob);
21 
22  if (reportSettings_) {
23  mf::LogVerbatim("FPE_Enable") << "\nOS's FP settings";
24  echoState();
25  }
26 
27  // Update the state according to the user's configuration
28  controlFpe();
29  if (reportSettings_) {
30  mf::LogVerbatim("FPE_Enable")
31  << "\nUpdated FP settings per user's configuration";
32  echoState();
33  }
34 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
fp_detail::fp_control_t OSdefault_
fp_control_t getFPControl()
Definition: fpControl.h:130

Member Function Documentation

void art::FloatingPointControl::controlFpe ( )
private

Definition at line 61 of file FloatingPointControl_service.cc.

References enableDivByZeroEx_, enableInvalidEx_, enableOverFlowEx_, enableUnderFlowEx_, art::fp_detail::getFPControl(), art::fp_detail::setFPControl(), and setPrecisionDouble_.

Referenced by FloatingPointControl().

62 {
63  // NB: We do not let users configure signaling of denormalized operand
64  // (fpControl_DENORMALOPERAND) or inexact (FE_INEXACT), both of which
65  // are suppressed.
66  unsigned short int enable_except{};
67  unsigned short int enable_sse{};
68 
69  if (enableDivByZeroEx_) {
70  enable_except |= FE_DIVBYZERO;
71  enable_sse |= fpControl_ZM_MASK;
72  }
73 
74  if (enableInvalidEx_) {
75  enable_except |= FE_INVALID;
76  enable_sse |= fpControl_IM_MASK;
77  }
78 
79  if (enableOverFlowEx_) {
80  enable_except |= FE_OVERFLOW;
81  enable_sse |= fpControl_OM_MASK;
82  }
83 
84  if (enableUnderFlowEx_) {
85  enable_except |= FE_UNDERFLOW;
86  enable_sse |= fpControl_UM_MASK;
87  }
88 
89  auto fpControl = getFPControl();
90 
91  // Reset exception mask before clearing the bits we care about.
92  fpControl.fpcw = (fpControl.fpcw | FE_ALL_EXCEPT) & (~enable_except);
93 
94  if (setPrecisionDouble_) {
95  // Clear precision bits before setting only the ones we care about.
96  fpControl.fpcw =
97  (fpControl.fpcw & (~fpControl_ALL_PREC)) | fpControl_DOUBLE_PREC;
98  }
99 
100 #ifdef fpControl_HAVE_MXCSR
101  // Reset exception mask before clearing the bits we care about.
102  fpControl.mxcsr =
103  (fpControl.mxcsr | fpControl_ALL_SSE_EXCEPT) & (~enable_sse);
104 #endif
105 
106  // Write back.
107  (void)setFPControl(fpControl);
108 }
fp_control_t getFPControl()
Definition: fpControl.h:130
fp_control_t setFPControl(fp_control_t const &fpControl)
Definition: fpControl.h:142
void art::FloatingPointControl::echoState ( )
private

Definition at line 113 of file FloatingPointControl_service.cc.

References FHICL_PROVIDE_ALLOWED_CONFIGURATION, art::fp_detail::getFPCW(), art::fp_detail::on_or_off(), and reportSettings_.

Referenced by FloatingPointControl(), and postEndJob().

114 {
115  if (reportSettings_) {
116  auto const femask{getFPCW()};
117  mf::LogVerbatim("FPE_Enable")
118  << "Floating point exception mask is " << std::showbase << std::hex
119  << femask << "\tDivByZero exception is"
120  << on_or_off(femask & FE_DIVBYZERO) << "\tInvalid exception is"
121  << on_or_off(femask & FE_INVALID) << "\tOverFlow exception is"
122  << on_or_off(femask & FE_OVERFLOW) << "\tUnderFlow exception is"
123  << on_or_off(femask & FE_UNDERFLOW);
124  }
125 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
char const * on_or_off(bool const b)
Definition: fpControl.h:154
fpcw_t getFPCW()
Definition: fpControl.cc:28
auto art::FloatingPointControl::getMask ( ) const

Definition at line 43 of file FloatingPointControl_service.cc.

References art::fp_detail::getFPCW().

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

Definition at line 37 of file FloatingPointControl_service.cc.

References art::fp_detail::getFPCW().

38 {
39  return static_cast<precision_t>(getFPCW() & fpControl_ALL_PREC);
40 }
fpcw_t getFPCW()
Definition: fpControl.cc:28
FloatingPointControl& art::FloatingPointControl::operator= ( FloatingPointControl const &  )
privatedelete
void art::FloatingPointControl::postEndJob ( )
private

Definition at line 49 of file FloatingPointControl_service.cc.

References echoState(), OSdefault_, reportSettings_, and art::fp_detail::setFPControl().

Referenced by FloatingPointControl().

50 {
51  (void)setFPControl(OSdefault_);
52  if (reportSettings_) {
53  mf::LogVerbatim("FPE_Enable") << "\nRestored to OS's FPE settings";
54  echoState();
55  }
56 }
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 91 of file FloatingPointControl.h.

Referenced by controlFpe().

bool art::FloatingPointControl::enableInvalidEx_
private

Definition at line 92 of file FloatingPointControl.h.

Referenced by controlFpe(), and FloatingPointControl().

bool art::FloatingPointControl::enableOverFlowEx_
private

Definition at line 93 of file FloatingPointControl.h.

Referenced by controlFpe(), and FloatingPointControl().

bool art::FloatingPointControl::enableUnderFlowEx_
private

Definition at line 94 of file FloatingPointControl.h.

Referenced by controlFpe(), and FloatingPointControl().

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

Definition at line 98 of file FloatingPointControl.h.

Referenced by FloatingPointControl(), and postEndJob().

bool art::FloatingPointControl::reportSettings_
private

Definition at line 96 of file FloatingPointControl.h.

Referenced by echoState(), FloatingPointControl(), and postEndJob().

bool art::FloatingPointControl::setPrecisionDouble_
private

Definition at line 95 of file FloatingPointControl.h.

Referenced by controlFpe(), and FloatingPointControl().


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