Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
art
art
Framework
Services
System
FloatingPointControl.cc
Go to the documentation of this file.
1
#include "
art/Framework/Services/System/FloatingPointControl.h
"
2
// vim: set sw=2 expandtab :
3
4
#include "
art/Framework/Services/Registry/ActivityRegistry.h
"
5
#include "
messagefacility/MessageLogger/MessageLogger.h
"
6
7
using namespace
std
;
8
using namespace
art::fp_detail
;
9
10
namespace
art
{
11
12
namespace
{
13
14
void
15
echoState()
16
{
17
auto
const
femask{
getFPCW
()};
18
mf::LogVerbatim
(
"FPE_Enable"
)
19
<<
"Floating point exception mask is "
<< std::showbase <<
std::hex
20
<< femask <<
"\tDivByZero exception is"
21
<<
on_or_off
(femask & FE_DIVBYZERO) <<
"\tInvalid exception is"
22
<<
on_or_off
(femask & FE_INVALID) <<
"\tOverFlow exception is"
23
<<
on_or_off
(femask & FE_OVERFLOW) <<
"\tUnderFlow exception is"
24
<<
on_or_off
(femask & FE_UNDERFLOW);
25
}
26
27
}
// unnamed namespacde
28
29
FloatingPointControl::FloatingPointControl(
Parameters
const
&
c
,
30
ActivityRegistry
&
reg
)
31
: enableDivByZeroEx_{
c
().enableDivByZeroEx()}
32
,
enableInvalidEx_
{
c
().enableInvalidEx()}
33
,
enableOverFlowEx_
{
c
().enableOverFlowEx()}
34
,
enableUnderFlowEx_
{
c
().enableUnderFlowEx()}
35
,
setPrecisionDouble_
{
c
().setPrecisionDouble()}
36
,
reportSettings_
{
c
().reportSettings()}
37
,
OSdefault_
(
getFPControl
())
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
}
91
92
void
93
FloatingPointControl::postEndJob
()
94
{
95
(void)
setFPControl
(
OSdefault_
);
96
if
(
reportSettings_
) {
97
mf::LogVerbatim
(
"FPE_Enable"
) <<
"\nRestored to OS's FPE settings"
;
98
echoState();
99
}
100
}
101
102
auto
103
FloatingPointControl::getPrecision
()
const
->
precision_t
104
{
105
return
static_cast<
precision_t
>
(
getFPCW
() & fpControl_ALL_PREC);
106
}
107
108
auto
109
FloatingPointControl::getMask
()
const
->
mask_t
110
{
111
return
static_cast<
mask_t
>
(
getFPCW
() & FE_ALL_EXCEPT);
112
}
113
114
}
// namespace art
mf::LogVerbatim
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
Definition:
MessageLogger.h:216
freeze_graph.const
const
Definition:
freeze_graph.py:179
art::FloatingPointControl::enableUnderFlowEx_
bool enableUnderFlowEx_
Definition:
FloatingPointControl.h:85
art::FloatingPointControl::mask_t
unsigned short int mask_t
Definition:
FloatingPointControl.h:54
art::FloatingPointControl::OSdefault_
fp_detail::fp_control_t OSdefault_
Definition:
FloatingPointControl.h:89
std
STL namespace.
hex
QTextStream & hex(QTextStream &s)
Definition:
qtextstream.cpp:2024
MessageLogger.h
FloatingPointControl.h
art::FloatingPointControl::enableOverFlowEx_
bool enableOverFlowEx_
Definition:
FloatingPointControl.h:84
art::FloatingPointControl::getPrecision
precision_t getPrecision() const
Definition:
FloatingPointControl.cc:103
ValidateOpDetSimulation.c
dictionary c
Definition:
ValidateOpDetSimulation.py:57
art::fp_detail::on_or_off
char const * on_or_off(bool const b)
Definition:
fpControl.h:154
art::FloatingPointControl::enableDivByZeroEx_
bool enableDivByZeroEx_
Definition:
FloatingPointControl.h:82
art::FloatingPointControl::reportSettings_
bool reportSettings_
Definition:
FloatingPointControl.h:87
art::FloatingPointControl::getMask
mask_t getMask() const
Definition:
FloatingPointControl.cc:109
art::ActivityRegistry
Definition:
ActivityRegistry.h:52
art::FloatingPointControl::setPrecisionDouble_
bool setPrecisionDouble_
Definition:
FloatingPointControl.h:86
ActivityRegistry.h
art::fp_detail::getFPCW
fpcw_t getFPCW()
Definition:
fpControl.cc:28
art
Definition:
BasicOptionsHandler.h:9
art::FloatingPointControl::postEndJob
void postEndJob()
Definition:
FloatingPointControl.cc:93
art::fp_detail
Definition:
fpControl.h:77
art::FloatingPointControl::enableInvalidEx_
bool enableInvalidEx_
Definition:
FloatingPointControl.h:83
art::fp_detail::getFPControl
fp_control_t getFPControl()
Definition:
fpControl.h:130
art::fp_detail::precision_t
precision_t
Definition:
fpControl.h:79
art::ServiceTable
Definition:
ServiceTable.h:25
cet::registry_via_id
Definition:
registry_via_id.h:19
art::fp_detail::setFPControl
fp_control_t setFPControl(fp_control_t const &fpControl)
Definition:
fpControl.h:142
Generated by
1.8.11