FloatingPointControl.h
Go to the documentation of this file.
1 #ifndef art_Framework_Services_System_FloatingPointControl_h
2 #define art_Framework_Services_System_FloatingPointControl_h
3 // vim: set sw=2 expandtab :
4 
5 // ======================================================================
6 //
7 // FloatingPointControl
8 //
9 // This service gives users the ability to specify the behavior of the
10 // Floating Point (FP) Processor for the job.
11 //
12 // This service can control two separate aspects of the FP environment:
13 // 1. exceptions
14 // 2. precision control on x87 FP processors.
15 //
16 // If the service is not used, floating point exceptions will not be
17 // trapped anywhere (FP exceptions will not cause a crash).
18 //
19 // Enabling exceptions is very useful if you are trying to track down
20 // where a floating point value of 'nan' or 'inf' is being generated
21 // and is even better if the goal is to eliminate them.
22 //
23 // One can also control the precision of floating point operations in
24 // x87 FP processor by specifying:
25 //
26 // setPrecisionDouble: (true|false)
27 //
28 // If set true (the default), the floating precision in the x87 math
29 // processor will be set to round results of addition, subtraction,
30 // multiplication, division, and square root to 64 bits after each
31 // operation instead of the x87 default, which is 80 bits for values
32 // in registers (this is the default you get if this service is not
33 // used at all).
34 //
35 // The precision control only affects Intel and AMD 32 bit CPUs under
36 // LINUX. We have not implemented precision control in the service
37 // for other CPUs (some other CPUs round to 64 bits by default and
38 // often CPUs do not allow control of the precision of floating point
39 // calculations).
40 //
41 // ======================================================================
42 
46 #include "fhiclcpp/types/Atom.h"
47 
48 namespace art {
49  class ActivityRegistry;
50 
52  public:
54  using mask_t = unsigned short int;
55 
56  struct Config {
58  false};
59  fhicl::Atom<bool> enableInvalidEx{fhicl::Name{"enableInvalidEx"}, false};
61  false};
63  false};
65  true};
66  fhicl::Atom<bool> reportSettings{fhicl::Name{"reportSettings"}, false};
67  };
69 
73 
74  // Return the precision as an enum (SINGLE, DOUBLE, EXTENDED).
75  precision_t getPrecision() const;
76  // Return the exception mask (can be ANDed with e.g. FE_DIVBYZERO to
77  // look for specific exception bits).
78  mask_t getMask() const;
79 
80  private:
81  void postEndJob();
88  // OS's fpu state on job startup
90  };
91 
92 } // namespace art
93 
95 
96 #endif /* art_Framework_Services_System_FloatingPointControl_h */
97 
98 // Local Variables:
99 // mode: c++
100 // End:
fp_detail::fp_control_t OSdefault_
precision_t getPrecision() const
#define DECLARE_ART_SYSTEM_SERVICE(svc, scope)
FloatingPointControl & operator=(FloatingPointControl const &)=delete
FloatingPointControl(Parameters const &, ActivityRegistry &)