1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#[derive(Default, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
#[repr(transparent)]
pub struct X87FloatingPointUnitControlWord(u16);
impl X87FloatingPointUnitControlWord
{
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[inline(always)]
pub fn save_after_raising_any_pending_unmasked_floating_point_exceptions() -> Self
{
let mut control_word: u16 = unsafe { uninitialized() };
let control_word_pointer = &mut control_word;
unsafe
{
asm!
(
"fstcw $0"
:
"=*m"(control_word_pointer)
:
:
:
"volatile"
);
}
Self(control_word)
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[inline(always)]
pub fn save() -> Self
{
let mut control_word: u16 = unsafe { uninitialized() };
let control_word_pointer = &mut control_word;
unsafe
{
asm!
(
"fnstcw $0"
:
"=*m"(control_word_pointer)
:
:
:
"volatile"
);
}
Self(control_word)
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[inline(always)]
pub fn restore(mut self)
{
let control_word_pointer = &mut self.0;
unsafe
{
asm!
(
"fnstcw $0"
:
:
"*m"(control_word_pointer)
:
:
"volatile"
);
}
}
#[inline(always)]
pub fn exception_flag_mask_bit_invalid_operation(self) -> bool
{
self.0 & 0b0000_0000_0000_0001 != 0
}
#[inline(always)]
pub fn exception_flag_mask_bit_denormal_operation(self) -> bool
{
self.0 & 0b0000_0000_0000_0010 != 0
}
#[inline(always)]
pub fn exception_flag_mask_bit_zero_divide(self) -> bool
{
self.0 & 0b0000_0000_0000_0100 != 0
}
#[inline(always)]
pub fn exception_flag_mask_bit_overflow(self) -> bool
{
self.0 & 0b0000_0000_0000_1000 != 0
}
#[inline(always)]
pub fn exception_flag_mask_bit_underflow(self) -> bool
{
self.0 & 0b0000_0000_0001_0000 != 0
}
#[inline(always)]
pub fn exception_flag_mask_bit_precision(self) -> bool
{
self.0 & 0b0000_0000_0010_0000 != 0
}
#[inline(always)]
pub fn precision_control(self) -> PrecisionControl
{
unsafe { transmute(self.0 & 0b0000_0011_0000_0000) }
}
#[inline(always)]
pub fn rounding_control(self) -> RoundingControl
{
unsafe { transmute((self.0 & 0b0000_1100_0000_0000 >> 10) as u8) }
}
#[inline(always)]
pub fn infinity_control(self) -> bool
{
self.0 & 0b0001_0000_0000_0000 != 0
}
}