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