26 #include <fpu_control.h>
36 return fegetenv (&fenv) ? -1 : (fenv.__control & FE_ALL_EXCEPT);
40 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)
60 unsigned int new_excepts = excepts & FE_ALL_EXCEPT,
63 if ( fegetenv (&fenv) )
return -1;
64 old_excepts = fenv.__control & FE_ALL_EXCEPT;
67 fenv.__control |= new_excepts;
68 fenv.__mxcsr |= new_excepts << 7;
70 return ( fesetenv (&fenv) ? -1 : old_excepts );
86 reportSettings_(
false) {
92 edm::LogVerbatim(
"FPE_Enable") <<
"\nSettings in EnableFloatingPointExceptions constructor";
135 typedef std::vector<std::string> VString;
137 std::string
const def(
"default");
139 VString
const empty_VString;
142 for (VString::const_iterator it(moduleNames.begin()), itEnd = moduleNames.end(); it != itEnd; ++it) {
150 if (enableDivByZeroEx) flags |= FE_DIVBYZERO;
151 if (enableInvalidEx) flags |= FE_INVALID;
152 if (enableOverFlowEx) flags |= FE_OVERFLOW;
153 if (enableUnderFlowEx) flags |= FE_UNDERFLOW;
270 desc.
addUntracked<
bool>(
"reportSettings",
false)->setComment(
271 "Log FPE settings at different phases of the job."
273 desc.
addUntracked<
bool>(
"setPrecisionDouble",
true)->setComment(
274 "Set the FPU to use double precision");
277 validator.
setComment(
"FPU exceptions to enable/disable for the requested module");
278 validator.
addUntracked<
bool>(
"enableDivByZeroEx",
false)->setComment(
279 "Enable/disable exception for 'divide by zero'");
280 validator.
addUntracked<
bool>(
"enableInvalidEx",
false)->setComment(
281 "Enable/disable exception for 'invalid' math operations (e.g. sqrt(-1))");
282 validator.
addUntracked<
bool>(
"enableOverFlowEx",
false)->setComment(
283 "Enable/disable exception for numeric 'overflow' (value to big for type)");
284 validator.
addUntracked<
bool>(
"enableUnderFlowEx",
false)->setComment(
285 "Enable/disable exception for numeric 'underflow' (value to small to be represented accurately)");
288 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");
291 descriptions.
add(
"EnableFloatingPointExceptions", desc);
292 descriptions.
setComment(
"This service allows you to control the FPU and its exceptions on a per module basis.");
299 char const* debugInfo) {
306 std::map<std::string, fpu_flags_type>::const_iterator iModule =
stateMap_.find(moduleLabel);
319 <<
"\nSettings for module label \""
338 <<
"\nSettings for module label \""
350 if (precisionDouble) {
354 cw = (cw & ~_FPU_EXTENDED) | _FPU_DOUBLE;
363 feclearexcept(FE_ALL_EXCEPT);
369 if (exceptionsToModify & FE_DIVBYZERO) {
370 if (target & FE_DIVBYZERO) {
371 exceptionsToEnable |= FE_DIVBYZERO;
374 exceptionsToDisable |= FE_DIVBYZERO;
377 if (exceptionsToModify & FE_INVALID) {
378 if (target & FE_INVALID) {
379 exceptionsToEnable |= FE_INVALID;
382 exceptionsToDisable |= FE_INVALID;
385 if (exceptionsToModify & FE_OVERFLOW) {
386 if (target & FE_OVERFLOW) {
387 exceptionsToEnable |= FE_OVERFLOW;
390 exceptionsToDisable |= FE_OVERFLOW;
393 if (exceptionsToModify & FE_UNDERFLOW) {
394 if (target & FE_UNDERFLOW) {
395 exceptionsToEnable |= FE_UNDERFLOW;
398 exceptionsToDisable |= FE_UNDERFLOW;
401 if (exceptionsToEnable != 0) {
402 feenableexcept(exceptionsToEnable);
404 if (exceptionsToDisable != 0) {
405 fedisableexcept(exceptionsToDisable);
411 feclearexcept(FE_ALL_EXCEPT);
414 << std::showbase << std::hex << femask;
416 if (femask & FE_DIVBYZERO)
421 if (femask & FE_INVALID)
426 if (femask & FE_OVERFLOW)
431 if (femask & FE_UNDERFLOW)
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)
const std::string * moduleLabel() const