27 #include <fpu_control.h>
36 return fegetenv (&fenv) ? -1 : (fenv.__control & FE_ALL_EXCEPT);
40 feenableexcept (
unsigned int excepts) {
42 unsigned int new_excepts = excepts & FE_ALL_EXCEPT,
45 if(fegetenv (&fenv))
return -1;
46 old_excepts = fenv.__control & FE_ALL_EXCEPT;
49 fenv.__control &= ~new_excepts;
50 fenv.__mxcsr &= ~(new_excepts << 7);
52 return (fesetenv (&fenv) ? -1 : old_excepts);
56 fedisableexcept (
unsigned int excepts) {
58 unsigned int new_excepts = excepts & FE_ALL_EXCEPT,
61 if(fegetenv (&fenv))
return -1;
62 old_excepts = fenv.__control & FE_ALL_EXCEPT;
65 fenv.__control |= new_excepts;
66 fenv.__mxcsr |= new_excepts << 7;
68 return (fesetenv (&fenv) ? -1 : old_excepts);
84 reportSettings_(
false) {
90 LogVerbatim(
"FPE_Enable") <<
"\nSettings in EnableFloatingPointExceptions constructor";
133 typedef std::vector<std::string> VString;
137 VString
const empty_VString;
140 for(VString::const_iterator it(moduleNames.begin()), itEnd = moduleNames.end(); it != itEnd; ++it) {
148 if(enableDivByZeroEx) flags |= FE_DIVBYZERO;
149 if(enableInvalidEx) flags |= FE_INVALID;
150 if(enableOverFlowEx) flags |= FE_OVERFLOW;
151 if(enableUnderFlowEx) flags |= FE_UNDERFLOW;
158 LogVerbatim(
"FPE_Enable") <<
"\nSettings for module " << *it;
174 LogVerbatim(
"FPE_Enable") <<
"\nSettings after endJob ";
268 desc.
addUntracked<
bool>(
"reportSettings",
false)->setComment(
269 "Log FPE settings at different phases of the job.");
270 desc.
addUntracked<
bool>(
"setPrecisionDouble",
true)->setComment(
271 "Set the FPU to use double precision");
274 validator.
setComment(
"FPU exceptions to enable/disable for the requested module");
275 validator.
addUntracked<
bool>(
"enableDivByZeroEx",
false)->setComment(
276 "Enable/disable exception for 'divide by zero'");
277 validator.
addUntracked<
bool>(
"enableInvalidEx",
false)->setComment(
278 "Enable/disable exception for 'invalid' math operations (e.g. sqrt(-1))");
279 validator.
addUntracked<
bool>(
"enableOverFlowEx",
false)->setComment(
280 "Enable/disable exception for numeric 'overflow' (value to big for type)");
281 validator.
addUntracked<
bool>(
"enableUnderFlowEx",
false)->setComment(
282 "Enable/disable exception for numeric 'underflow' (value to small to be represented accurately)");
285 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");
288 descriptions.
add(
"EnableFloatingPointExceptions", desc);
289 descriptions.
setComment(
"This service allows you to control the FPU and its exceptions on a per module basis.");
296 char const* debugInfo) {
303 std::map<std::string, fpu_flags_type>::const_iterator iModule =
stateMap_.find(moduleLabel);
316 <<
"\nSettings for module label \""
335 <<
"\nSettings for module label \""
347 if(precisionDouble) {
351 cw = (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;
368 feclearexcept(FE_ALL_EXCEPT);
374 if(exceptionsToModify & FE_DIVBYZERO) {
375 if(target & FE_DIVBYZERO) {
376 exceptionsToEnable |= FE_DIVBYZERO;
379 exceptionsToDisable |= FE_DIVBYZERO;
382 if(exceptionsToModify & FE_INVALID) {
383 if(target & FE_INVALID) {
384 exceptionsToEnable |= FE_INVALID;
387 exceptionsToDisable |= FE_INVALID;
390 if(exceptionsToModify & FE_OVERFLOW) {
391 if(target & FE_OVERFLOW) {
392 exceptionsToEnable |= FE_OVERFLOW;
395 exceptionsToDisable |= FE_OVERFLOW;
398 if(exceptionsToModify & FE_UNDERFLOW) {
399 if(target & FE_UNDERFLOW) {
400 exceptionsToEnable |= FE_UNDERFLOW;
403 exceptionsToDisable |= FE_UNDERFLOW;
406 if(exceptionsToEnable != 0) {
407 feenableexcept(exceptionsToEnable);
409 if(exceptionsToDisable != 0) {
410 fedisableexcept(exceptionsToDisable);
416 feclearexcept(FE_ALL_EXCEPT);
418 LogVerbatim(
"FPE_Enable") <<
"Floating point exception mask is "
419 << std::showbase << std::hex << femask;
421 if(femask & FE_DIVBYZERO)
422 LogVerbatim(
"FPE_Enable") <<
"\tDivByZero exception is on";
424 LogVerbatim(
"FPE_Enable") <<
"\tDivByZero exception is off";
426 if(femask & FE_INVALID)
427 LogVerbatim(
"FPE_Enable") <<
"\tInvalid exception is on";
429 LogVerbatim(
"FPE_Enable") <<
"\tInvalid exception is off";
431 if(femask & FE_OVERFLOW)
432 LogVerbatim(
"FPE_Enable") <<
"\tOverFlow exception is on";
434 LogVerbatim(
"FPE_Enable") <<
"\tOverflow exception is off";
436 if(femask & FE_UNDERFLOW)
437 LogVerbatim(
"FPE_Enable") <<
"\tUnderFlow exception is on";
439 LogVerbatim(
"FPE_Enable") <<
"\tUnderFlow exception is off";
void preModuleEndRun(ModuleDescription const &description)
void setComment(std::string const &value)
T getUntrackedParameter(std::string const &, T const &) const
void watchPostModuleBeginLumi(PostModuleBeginLumi::slot_type const &iSlot)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void postModuleEndLumi(ModuleDescription const &description)
void watchPostModule(PostModule::slot_type const &iSlot)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
std::vector< Variable::Flags > flags
void enableAndDisableExcept(fpu_flags_type target)
void postModuleEndRun(ModuleDescription const &description)
void postModuleBeginJob(ModuleDescription const &description)
void watchPreModuleEndLumi(PreModuleEndLumi::slot_type const &iSlot)
void establishModuleEnvironments(ParameterSet const &pset)
std::string const & moduleLabel() const
void preModuleEndJob(ModuleDescription const &description)
void watchPreModule(PreModule::slot_type const &iSlot)
void preModuleBeginJob(ModuleDescription const &description)
void setComment(std::string const &value)
void watchPreModuleEndRun(PreModuleEndRun::slot_type const &iSlot)
void postActions(ModuleDescription const &description, char const *debugInfo)
void postModuleBeginLumi(ModuleDescription const &description)
fpu_flags_type defaultState_
std::map< std::string, fpu_flags_type > stateMap_
ParameterSet const & getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
void watchPostModuleEndRun(PostModuleEndRun::slot_type const &iSlot)
void watchPreModuleEndJob(PreModuleEndJob::slot_type const &iSlot)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void preModuleBeginLumi(ModuleDescription const &description)
void watchPreModuleBeginJob(PreModuleBeginJob::slot_type const &iSlot)
void watchPostModuleBeginRun(PostModuleBeginRun::slot_type const &iSlot)
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void postModule(ModuleDescription const &description)
void preModuleBeginRun(ModuleDescription const &description)
void preModule(ModuleDescription const &description)
void postModuleBeginRun(ModuleDescription const &description)
void watchPostModuleBeginJob(PostModuleBeginJob::slot_type const &iSlot)
void preModuleEndLumi(ModuleDescription const &description)
void watchPreModuleBeginLumi(PreModuleBeginLumi::slot_type const &iSlot)
void postModuleEndJob(ModuleDescription const &description)
void watchPostModuleEndJob(PostModuleEndJob::slot_type const &iSlot)
void watchPreModuleBeginRun(PreModuleBeginRun::slot_type const &iSlot)
void watchPostModuleEndLumi(PostModuleEndLumi::slot_type const &iSlot)
std::stack< fpu_flags_type > stateStack_
void setPrecision(bool precisionDouble)
void preActions(ModuleDescription const &description, char const *debugInfo)
EnableFloatingPointExceptions(ParameterSet const &pset, ActivityRegistry ®istry)