Skip to content

Commit 7767dac

Browse files
author
Dániel Buga
committed
Implement bit manipulation methods
1 parent 3cb2102 commit 7767dac

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

src/register/fpscr.rs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,105 @@ impl Fpscr {
3939
self.bits & (1 << 31) != 0
4040
}
4141

42+
/// Sets the Negative condition code flag
43+
pub fn set_n(&mut self, n: bool) {
44+
let mask = 1 << 31;
45+
match n {
46+
true => self.bits |= mask,
47+
false => self.bits &= !mask,
48+
}
49+
}
50+
4251
/// Read the Zero condition code flag
4352
#[inline]
4453
pub fn z(self) -> bool {
4554
self.bits & (1 << 30) != 0
4655
}
4756

57+
/// Sets the Zero condition code flag
58+
pub fn set_z(&mut self, z: bool) {
59+
let mask = 1 << 30;
60+
match z {
61+
true => self.bits |= mask,
62+
false => self.bits &= !mask,
63+
}
64+
}
65+
4866
/// Read the Carry condition code flag
4967
#[inline]
5068
pub fn c(self) -> bool {
5169
self.bits & (1 << 29) != 0
5270
}
5371

72+
/// Sets the Carry condition code flag
73+
pub fn set_c(&mut self, c: bool) {
74+
let mask = 1 << 29;
75+
match c {
76+
true => self.bits |= mask,
77+
false => self.bits &= !mask,
78+
}
79+
}
80+
5481
/// Read the Overflow condition code flag
5582
#[inline]
5683
pub fn v(self) -> bool {
5784
self.bits & (1 << 28) != 0
5885
}
5986

87+
/// Sets the Zero condition code flag
88+
pub fn set_v(&mut self, v: bool) {
89+
let mask = 1 << 28;
90+
match v {
91+
true => self.bits |= mask,
92+
false => self.bits &= !mask,
93+
}
94+
}
95+
6096
/// Read the Alternative Half Precision bit
6197
#[inline]
6298
pub fn ahp(self) -> bool {
6399
self.bits & (1 << 26) != 0
64100
}
65101

102+
/// Sets the Alternative Half Precision bit
103+
pub fn set_ahp(&mut self, ahp: bool) {
104+
let mask = 1 << 26;
105+
match ahp {
106+
true => self.bits |= mask,
107+
false => self.bits &= !mask,
108+
}
109+
}
110+
66111
/// Read the Default NaN mode bit
67112
#[inline]
68113
pub fn dn(self) -> bool {
69114
self.bits & (1 << 25) != 0
70115
}
71116

117+
/// Sets the Default NaN mode bit
118+
pub fn set_dn(&mut self, dn: bool) {
119+
let mask = 1 << 25;
120+
match dn {
121+
true => self.bits |= mask,
122+
false => self.bits &= !mask,
123+
}
124+
}
125+
72126
/// Read the Flush to Zero mode bit
73127
#[inline]
74128
pub fn fz(self) -> bool {
75129
self.bits & (1 << 24) != 0
76130
}
77131

132+
/// Sets the Flush to Zero mode bit
133+
pub fn set_fz(&mut self, fz: bool) {
134+
let mask = 1 << 24;
135+
match fz {
136+
true => self.bits |= mask,
137+
false => self.bits &= !mask,
138+
}
139+
}
140+
78141
/// Read the Rounding Mode control field
79142
#[inline]
80143
pub fn rmode(self) -> RMode {
@@ -86,41 +149,106 @@ impl Fpscr {
86149
}
87150
}
88151

152+
/// Sets the Rounding Mode control field
153+
pub fn set_rmode(&mut self, rmode: RMode) {
154+
let mask = 3 << 22;
155+
match rmode {
156+
RMode::Nearest => self.bits = (self.bits & !mask),
157+
RMode::Nearest => self.bits = (self.bits & !mask) | (1 << 22),
158+
RMode::Nearest => self.bits = (self.bits & !mask) | (2 << 22),
159+
RMode::Nearest => self.bits = self.bits | mask,
160+
}
161+
}
162+
89163
/// Read the Input Denormal cumulative exception bit
90164
#[inline]
91165
pub fn idc(self) -> bool {
92166
self.bits & (1 << 7) != 0
93167
}
94168

169+
/// Sets the Input Denormal cumulative exception bit
170+
pub fn set_idc(&mut self, idc: bool) {
171+
let mask = 1 << 7;
172+
match idc {
173+
true => self.bits |= mask,
174+
false => self.bits &= !mask,
175+
}
176+
}
177+
95178
/// Read the Inexact cumulative exception bit
96179
#[inline]
97180
pub fn ixc(self) -> bool {
98181
self.bits & (1 << 4) != 0
99182
}
100183

184+
/// Sets the Inexact cumulative exception bit
185+
pub fn set_ixc(&mut self, ixc: bool) {
186+
let mask = 1 << 4;
187+
match ixc {
188+
true => self.bits |= mask,
189+
false => self.bits &= !mask,
190+
}
191+
}
192+
101193
/// Read the Underflow cumulative exception bit
102194
#[inline]
103195
pub fn ufc(self) -> bool {
104196
self.bits & (1 << 3) != 0
105197
}
106198

199+
/// Sets the Underflow cumulative exception bit
200+
pub fn set_ufc(&mut self, ufc: bool) {
201+
let mask = 1 << 3;
202+
match ufc {
203+
true => self.bits |= mask,
204+
false => self.bits &= !mask,
205+
}
206+
}
207+
107208
/// Read the Overflow cumulative exception bit
108209
#[inline]
109210
pub fn ofc(self) -> bool {
110211
self.bits & (1 << 2) != 0
111212
}
112213

214+
/// Sets the Overflow cumulative exception bit
215+
pub fn set_ofc(&mut self, ofc: bool) {
216+
let mask = 1 << 2;
217+
match ofc {
218+
true => self.bits |= mask,
219+
false => self.bits &= !mask,
220+
}
221+
}
222+
113223
/// Read the Division by Zero cumulative exception bit
114224
#[inline]
115225
pub fn dzc(self) -> bool {
116226
self.bits & (1 << 1) != 0
117227
}
118228

229+
/// Sets the Division by Zero cumulative exception bit
230+
pub fn set_dzc(&mut self, dzc: bool) {
231+
let mask = 1 << 1;
232+
match dzc {
233+
true => self.bits |= mask,
234+
false => self.bits &= !mask,
235+
}
236+
}
237+
119238
/// Read the Invalid Operation cumulative exception bit
120239
#[inline]
121240
pub fn ioc(self) -> bool {
122241
self.bits & (1 << 0) != 0
123242
}
243+
244+
/// Sets the Invalid Operation cumulative exception bit
245+
pub fn set_ioc(&mut self, ioc: bool) {
246+
let mask = 1 << 0;
247+
match ioc {
248+
true => self.bits |= mask,
249+
false => self.bits &= !mask,
250+
}
251+
}
124252
}
125253

126254
/// Read the FPSCR register

0 commit comments

Comments
 (0)