28 #include <fpu_control.h>
37 return fegetenv (&fenv) ? -1 : (fenv.__control & FE_ALL_EXCEPT);
41 feenableexcept (
unsigned int excepts) {
43 unsigned int new_excepts = excepts & FE_ALL_EXCEPT,
46 if(fegetenv (&fenv))
return -1;
47 old_excepts = fenv.__control & FE_ALL_EXCEPT;
50 fenv.__control &= ~new_excepts;
51 fenv.__mxcsr &= ~(new_excepts << 7);
53 return (fesetenv (&fenv) ? -1 : old_excepts);
57 fedisableexcept (
unsigned int excepts) {
59 unsigned int new_excepts = excepts & FE_ALL_EXCEPT,
62 if(fegetenv (&fenv))
return -1;
63 old_excepts = fenv.__control & FE_ALL_EXCEPT;
66 fenv.__control |= new_excepts;
67 fenv.__mxcsr |= new_excepts << 7;
69 return (fesetenv (&fenv) ? -1 : old_excepts);
83 reportSettings_(
false) {
89 LogVerbatim(
"FPE_Enable") <<
"\nSettings in EnableFloatingPointExceptions constructor";
150 typedef std::vector<std::string> VString;
154 VString
const empty_VString;
157 for(VString::const_iterator it(moduleNames.begin()), itEnd = moduleNames.end(); it != itEnd; ++it) {
165 if(enableDivByZeroEx) flags |= FE_DIVBYZERO;
166 if(enableInvalidEx) flags |= FE_INVALID;
167 if(enableOverFlowEx) flags |= FE_OVERFLOW;
168 if(enableUnderFlowEx) flags |= FE_UNDERFLOW;
172 assert(flags == fpuState);
175 LogVerbatim(
"FPE_Enable") <<
"\nSettings for module " << *it;
191 LogVerbatim(
"FPE_Enable") <<
"\nSettings after endJob ";
369 desc.
addUntracked<
bool>(
"reportSettings",
false)->setComment(
370 "Log FPE settings at different phases of the job.");
371 desc.
addUntracked<
bool>(
"setPrecisionDouble",
true)->setComment(
372 "Set the FPU to use double precision");
375 validator.
setComment(
"FPU exceptions to enable/disable for the requested module");
376 validator.
addUntracked<
bool>(
"enableDivByZeroEx",
false)->setComment(
377 "Enable/disable exception for 'divide by zero'");
378 validator.
addUntracked<
bool>(
"enableInvalidEx",
false)->setComment(
379 "Enable/disable exception for 'invalid' math operations (e.g. sqrt(-1))");
380 validator.
addUntracked<
bool>(
"enableOverFlowEx",
false)->setComment(
381 "Enable/disable exception for numeric 'overflow' (value to big for type)");
382 validator.
addUntracked<
bool>(
"enableUnderFlowEx",
false)->setComment(
383 "Enable/disable exception for numeric 'underflow' (value to small to be represented accurately)");
386 node.
setComment(
"Contains the names for PSets where the PSet name matches the label of a module for which you want to modify the FPE");
389 descriptions.
add(
"EnableFloatingPointExceptions", desc);
390 descriptions.
setComment(
"This service allows you to control the FPU and its exceptions on a per module basis.");
397 char const* debugInfo) {
400 std::map<std::string, fpu_flags_type>::const_iterator iModule =
stateMap_.find(moduleLabel);
405 fpuState = iModule->second;
411 <<
"\nSettings for module label \""
427 <<
"\nSettings for module label \""
438 char const* debugInfo) {
441 std::map<std::string, fpu_flags_type>::const_iterator iModule =
stateMap_.find(moduleLabel);
446 fpuState = iModule->second;
452 <<
"\nSettings for module label \""
470 fpuState = iModule->second;
477 <<
"\nSettings for module label \""
512 if(precisionDouble) {
516 cw = (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;
533 feclearexcept(FE_ALL_EXCEPT);
539 if(exceptionsToModify & FE_DIVBYZERO) {
540 if(target & FE_DIVBYZERO) {
541 exceptionsToEnable |= FE_DIVBYZERO;
544 exceptionsToDisable |= FE_DIVBYZERO;
547 if(exceptionsToModify & FE_INVALID) {
548 if(target & FE_INVALID) {
549 exceptionsToEnable |= FE_INVALID;
552 exceptionsToDisable |= FE_INVALID;
555 if(exceptionsToModify & FE_OVERFLOW) {
556 if(target & FE_OVERFLOW) {
557 exceptionsToEnable |= FE_OVERFLOW;
560 exceptionsToDisable |= FE_OVERFLOW;
563 if(exceptionsToModify & FE_UNDERFLOW) {
564 if(target & FE_UNDERFLOW) {
565 exceptionsToEnable |= FE_UNDERFLOW;
568 exceptionsToDisable |= FE_UNDERFLOW;
571 if(exceptionsToEnable != 0) {
572 feenableexcept(exceptionsToEnable);
574 if(exceptionsToDisable != 0) {
575 fedisableexcept(exceptionsToDisable);
581 feclearexcept(FE_ALL_EXCEPT);
583 LogVerbatim(
"FPE_Enable") <<
"Floating point exception mask is "
584 << std::showbase << std::hex << femask;
586 if(femask & FE_DIVBYZERO)
587 LogVerbatim(
"FPE_Enable") <<
"\tDivByZero exception is on";
589 LogVerbatim(
"FPE_Enable") <<
"\tDivByZero exception is off";
591 if(femask & FE_INVALID)
592 LogVerbatim(
"FPE_Enable") <<
"\tInvalid exception is on";
594 LogVerbatim(
"FPE_Enable") <<
"\tInvalid exception is off";
596 if(femask & FE_OVERFLOW)
597 LogVerbatim(
"FPE_Enable") <<
"\tOverFlow exception is on";
599 LogVerbatim(
"FPE_Enable") <<
"\tOverflow exception is off";
601 if(femask & FE_UNDERFLOW)
602 LogVerbatim(
"FPE_Enable") <<
"\tUnderFlow exception is on";
604 LogVerbatim(
"FPE_Enable") <<
"\tUnderFlow exception is off";
void preModuleGlobalEndLumi(GlobalContext const &, ModuleCallingContext const &)
void watchPostModuleGlobalEndLumi(PostModuleGlobalEndLumi::slot_type const &iSlot)
void watchPostModuleConstruction(PostModuleConstruction::slot_type const &iSlot)
void preModuleGlobalBeginLumi(GlobalContext const &, ModuleCallingContext const &)
void watchPreModuleGlobalBeginRun(PreModuleGlobalBeginRun::slot_type const &iSlot)
void setComment(std::string const &value)
T getUntrackedParameter(std::string const &, T const &) const
int def(FILE *, FILE *, int)
void preModuleConstruction(ModuleDescription const &)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void postModuleGlobalBeginLumi(GlobalContext const &, ModuleCallingContext const &)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void preModuleEvent(StreamContext const &, ModuleCallingContext const &)
void preActions(ModuleDescription const &, char const *debugInfo)
void watchPostModuleEndStream(PostModuleEndStream::slot_type const &iSlot)
void preModuleBeginJob(ModuleDescription const &)
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void watchPreModuleConstruction(PreModuleConstruction::slot_type const &iSlot)
void preModuleStreamEndRun(StreamContext const &, ModuleCallingContext const &)
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
void establishModuleEnvironments(ParameterSet const &)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
void watchPostModuleGlobalBeginLumi(PostModuleGlobalBeginLumi::slot_type const &iSlot)
void watchPostModuleStreamEndLumi(PostModuleStreamEndLumi::slot_type const &iSlot)
std::vector< Variable::Flags > flags
void watchPostModuleStreamBeginRun(PostModuleStreamBeginRun::slot_type const &iSlot)
void preModuleStreamEndLumi(StreamContext const &, ModuleCallingContext const &)
void enableAndDisableExcept(fpu_flags_type target)
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
void postModuleBeginStream(StreamContext const &, ModuleCallingContext const &)
void watchPreModuleBeginStream(PreModuleBeginStream::slot_type const &iSlot)
std::string const & moduleLabel() const
void watchPreModuleGlobalEndRun(PreModuleGlobalEndRun::slot_type const &iSlot)
void preModuleStreamBeginLumi(StreamContext const &, ModuleCallingContext const &)
void postModuleStreamBeginLumi(StreamContext const &, ModuleCallingContext const &)
void setComment(std::string const &value)
fpu_flags_type defaultState_
std::map< std::string, fpu_flags_type > stateMap_
ModuleDescription const * moduleDescription() const
void watchPreModuleEndJob(PreModuleEndJob::slot_type const &iSlot)
void postModuleGlobalEndLumi(GlobalContext const &, ModuleCallingContext const &)
void postModuleStreamEndLumi(StreamContext const &, ModuleCallingContext const &)
void postModuleStreamBeginRun(StreamContext const &, ModuleCallingContext const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void postModuleEndJob(ModuleDescription const &md)
void watchPreModuleBeginJob(PreModuleBeginJob::slot_type const &iSlot)
void postModuleGlobalEndRun(GlobalContext const &, ModuleCallingContext const &)
void watchPreModuleGlobalBeginLumi(PreModuleGlobalBeginLumi::slot_type const &iSlot)
void watchPostModuleStreamEndRun(PostModuleStreamEndRun::slot_type const &iSlot)
void watchPreModuleStreamBeginLumi(PreModuleStreamBeginLumi::slot_type const &iSlot)
void preModuleBeginStream(StreamContext const &, ModuleCallingContext const &)
void setComment(std::string const &value)
void watchPostModuleBeginStream(PostModuleBeginStream::slot_type const &iSlot)
void postModuleConstruction(ModuleDescription const &)
void postModuleBeginJob(ModuleDescription const &)
void watchPostModuleGlobalEndRun(PostModuleGlobalEndRun::slot_type const &iSlot)
void watchPostModuleStreamBeginLumi(PostModuleStreamBeginLumi::slot_type const &iSlot)
void watchPreModuleStreamEndLumi(PreModuleStreamEndLumi::slot_type const &iSlot)
void watchPreModuleStreamBeginRun(PreModuleStreamBeginRun::slot_type const &iSlot)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void watchPreModuleEndStream(PreModuleEndStream::slot_type const &iSlot)
void preModuleEndStream(StreamContext const &, ModuleCallingContext const &)
void postModuleGlobalBeginRun(GlobalContext const &, ModuleCallingContext const &)
void preModuleStreamBeginRun(StreamContext const &, ModuleCallingContext const &)
ModuleCallingContext const * previousModuleOnThread() const
void postModuleEndStream(StreamContext const &, ModuleCallingContext const &)
void postModuleEvent(StreamContext const &, ModuleCallingContext const &)
void watchPreModuleStreamEndRun(PreModuleStreamEndRun::slot_type const &iSlot)
void watchPostModuleBeginJob(PostModuleBeginJob::slot_type const &iSlot)
void watchPostModuleGlobalBeginRun(PostModuleGlobalBeginRun::slot_type const &iSlot)
void preModuleGlobalBeginRun(GlobalContext const &, ModuleCallingContext const &)
void postActions(ModuleDescription const &, char const *debugInfo)
volatile std::atomic< bool > shutdown_flag false
void preModuleGlobalEndRun(GlobalContext const &, ModuleCallingContext const &)
void watchPostModuleEndJob(PostModuleEndJob::slot_type const &iSlot)
void postModuleStreamEndRun(StreamContext const &, ModuleCallingContext const &)
void watchPreModuleGlobalEndLumi(PreModuleGlobalEndLumi::slot_type const &iSlot)
void setPrecision(bool precisionDouble)
void preModuleEndJob(ModuleDescription const &md)
EnableFloatingPointExceptions(ParameterSet const &pset, ActivityRegistry ®istry)