Skip to content

Commit c35b3a0

Browse files
committed
remove bitfield overhead
1 parent 8582840 commit c35b3a0

File tree

4 files changed

+44
-122
lines changed

4 files changed

+44
-122
lines changed

Cargo.lock

Lines changed: 0 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ path = "lib.rs"
1313
crate-type = ["staticlib", "rlib"]
1414

1515
[dependencies]
16-
c2rust-bitfields= "0.3"
1716

1817
[profile.test]
1918
opt-level = 3

lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#![allow(unused_assignments)]
55
#![allow(unused_mut)]
66

7-
#[macro_use]
8-
extern crate c2rust_bitfields;
97
pub mod z80;
108

119
#[cfg(test)]

z80.rs

Lines changed: 44 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ SOFTWARE.
2727
2828
*/
2929

30-
use ::c2rust_bitfields;
3130
pub type int8_t = i8;
3231
pub type int32_t = i32;
3332
pub type uint8_t = u8;
@@ -45,8 +44,6 @@ pub trait z80Ctrl {
4544
fn test_finished(&self) -> bool;
4645
}
4746

48-
#[derive(BitfieldStruct)]
49-
#[repr(C)]
5047
pub struct z80 {
5148
pub ctrl: Box<dyn z80Ctrl>,
5249
pub pc: uint16_t,
@@ -69,10 +66,9 @@ pub struct z80 {
6966
pub irq_data: uint8_t,
7067
pub irq_pending: uint8_t,
7168
pub nmi_pending: uint8_t,
72-
#[bitfield(name = "iff1", ty = "bool", bits = "0..=0")]
73-
#[bitfield(name = "iff2", ty = "bool", bits = "1..=1")]
74-
#[bitfield(name = "halted", ty = "bool", bits = "2..=2")]
75-
pub iff1_iff2_halted: [u8; 1],
69+
halted: bool,
70+
iff1: bool,
71+
iff2: bool,
7672
}
7773

7874
impl z80 {
@@ -115,7 +111,10 @@ impl z80 {
115111
irq_data: 0,
116112
irq_pending: 0,
117113
nmi_pending: 0,
118-
iff1_iff2_halted: [0; 1],
114+
// iff1_iff2_halted: [0; 1],
115+
halted: false,
116+
iff1: false,
117+
iff2: false,
119118
}
120119
}
121120
pub fn init(&mut self) {
@@ -136,9 +135,9 @@ impl z80 {
136135
self.r = 0 as i32 as uint8_t;
137136
self.iff_delay = 0 as i32 as uint8_t;
138137
self.interrupt_mode = 0 as i32 as uint8_t;
139-
self.set_iff1(0 as i32 != 0);
140-
self.set_iff2(0 as i32 != 0);
141-
self.set_halted(0 as i32 != 0);
138+
self.iff1 = 0 as i32 != 0;
139+
self.iff2 = 0 as i32 != 0;
140+
self.halted = 0 as i32 != 0;
142141
self.irq_pending = 0 as i32 as uint8_t;
143142
self.nmi_pending = 0 as i32 as uint8_t;
144143
self.irq_data = 0 as i32 as uint8_t;
@@ -175,98 +174,82 @@ impl z80 {
175174
}
176175

177176
#[derive(Copy, Clone)]
178-
#[repr(C)]
179-
pub union C2RustUnnamed_0 {
177+
union C2RustUnnamed_0 {
180178
pub c2rust_unnamed: C2RustUnnamed_1,
181179
pub h_l_: uint16_t,
182180
}
183181
#[derive(Copy, Clone)]
184-
#[repr(C)]
185-
pub struct C2RustUnnamed_1 {
182+
struct C2RustUnnamed_1 {
186183
pub l_: uint8_t,
187184
pub h_: uint8_t,
188185
}
189186
#[derive(Copy, Clone)]
190-
#[repr(C)]
191-
pub union C2RustUnnamed_2 {
187+
union C2RustUnnamed_2 {
192188
pub c2rust_unnamed: C2RustUnnamed_3,
193189
pub d_e_: uint16_t,
194190
}
195191
#[derive(Copy, Clone)]
196-
#[repr(C)]
197-
pub struct C2RustUnnamed_3 {
192+
struct C2RustUnnamed_3 {
198193
pub e_: uint8_t,
199194
pub d_: uint8_t,
200195
}
201196
#[derive(Copy, Clone)]
202-
#[repr(C)]
203-
pub union C2RustUnnamed_4 {
197+
union C2RustUnnamed_4 {
204198
pub c2rust_unnamed: C2RustUnnamed_5,
205199
pub b_c_: uint16_t,
206200
}
207201
#[derive(Copy, Clone)]
208-
#[repr(C)]
209-
pub struct C2RustUnnamed_5 {
202+
struct C2RustUnnamed_5 {
210203
pub c_: uint8_t,
211204
pub b_: uint8_t,
212205
}
213206
#[derive(Copy, Clone)]
214-
#[repr(C)]
215-
pub union C2RustUnnamed_6 {
207+
union C2RustUnnamed_6 {
216208
pub c2rust_unnamed: C2RustUnnamed_7,
217209
pub a_f_: uint16_t,
218210
}
219211
#[derive(Copy, Clone)]
220-
#[repr(C)]
221-
pub struct C2RustUnnamed_7 {
212+
struct C2RustUnnamed_7 {
222213
pub f_: uint8_t,
223214
pub a_: uint8_t,
224215
}
225216
#[derive(Copy, Clone)]
226-
#[repr(C)]
227-
pub union C2RustUnnamed_8 {
217+
union C2RustUnnamed_8 {
228218
pub c2rust_unnamed: C2RustUnnamed_9,
229219
pub hl: uint16_t,
230220
}
231221
#[derive(Copy, Clone)]
232-
#[repr(C)]
233-
pub struct C2RustUnnamed_9 {
222+
struct C2RustUnnamed_9 {
234223
pub l: uint8_t,
235224
pub h: uint8_t,
236225
}
237226
#[derive(Copy, Clone)]
238-
#[repr(C)]
239-
pub union C2RustUnnamed_10 {
227+
union C2RustUnnamed_10 {
240228
pub c2rust_unnamed: C2RustUnnamed_11,
241229
pub de: uint16_t,
242230
}
243231
#[derive(Copy, Clone)]
244-
#[repr(C)]
245-
pub struct C2RustUnnamed_11 {
232+
struct C2RustUnnamed_11 {
246233
pub e: uint8_t,
247234
pub d: uint8_t,
248235
}
249236
#[derive(Copy, Clone)]
250-
#[repr(C)]
251-
pub union C2RustUnnamed_12 {
237+
union C2RustUnnamed_12 {
252238
pub c2rust_unnamed: C2RustUnnamed_13,
253239
pub bc: uint16_t,
254240
}
255241
#[derive(Copy, Clone)]
256-
#[repr(C)]
257-
pub struct C2RustUnnamed_13 {
242+
struct C2RustUnnamed_13 {
258243
pub c: uint8_t,
259244
pub b: uint8_t,
260245
}
261246
#[derive(Copy, Clone)]
262-
#[repr(C)]
263-
pub union C2RustUnnamed_14 {
247+
union C2RustUnnamed_14 {
264248
pub c2rust_unnamed: C2RustUnnamed_15,
265249
pub af: uint16_t,
266250
}
267251
#[derive(Copy, Clone)]
268-
#[repr(C)]
269-
pub struct C2RustUnnamed_15 {
252+
struct C2RustUnnamed_15 {
270253
pub f: uint8_t,
271254
pub a: uint8_t,
272255
}
@@ -1040,29 +1023,29 @@ unsafe fn process_interrupts(z: *mut z80) -> u32 {
10401023
if (*z).iff_delay as i32 > 0 as i32 {
10411024
(*z).iff_delay = ((*z).iff_delay as i32 - 1 as i32) as uint8_t;
10421025
if (*z).iff_delay as i32 == 0 as i32 {
1043-
(*z).set_iff1(1 as i32 != 0);
1044-
(*z).set_iff2(1 as i32 != 0);
1026+
(*z).iff1 = 1 as i32 != 0;
1027+
(*z).iff2 = 1 as i32 != 0;
10451028
}
10461029
return cyc;
10471030
}
10481031
if (*z).nmi_pending != 0 {
10491032
(*z)
10501033
.nmi_pending = ((*z).nmi_pending as i32
10511034
& !(Z80_PULSE as i32)) as uint8_t;
1052-
(*z).set_halted(0 as i32 != 0);
1053-
(*z).set_iff1(0 as i32 != 0);
1035+
(*z).halted = 0 as i32 != 0;
1036+
(*z).iff1 = 0 as i32 != 0;
10541037
inc_r(z);
10551038
cyc = cyc.wrapping_add(11 as i32 as u32);
10561039
call(z, 0x66 as i32 as uint16_t);
10571040
return cyc;
10581041
}
1059-
if (*z).irq_pending as i32 != 0 && (*z).iff1() as i32 != 0 {
1042+
if (*z).irq_pending as i32 != 0 && (*z).iff1 as i32 != 0 {
10601043
(*z)
10611044
.irq_pending = ((*z).irq_pending as i32
10621045
& !(Z80_PULSE as i32)) as uint8_t;
1063-
(*z).set_halted(0 as i32 != 0);
1064-
(*z).set_iff1(0 as i32 != 0);
1065-
(*z).set_iff2(0 as i32 != 0);
1046+
(*z).halted = 0 as i32 != 0;
1047+
(*z).iff1 = 0 as i32 != 0;
1048+
(*z).iff2 = 0 as i32 != 0;
10661049
inc_r(z);
10671050
match (*z).interrupt_mode as i32 {
10681051
0 => {
@@ -1098,14 +1081,14 @@ pub unsafe fn z80_reset(z: *mut z80) {
10981081
(*z).r = 0 as i32 as uint8_t;
10991082
(*z).interrupt_mode = 0 as i32 as uint8_t;
11001083
(*z).iff_delay = 0 as i32 as uint8_t;
1101-
(*z).set_iff1(0 as i32 != 0);
1102-
(*z).set_iff2(0 as i32 != 0);
1103-
(*z).set_halted(0 as i32 != 0);
1084+
(*z).iff1 = 0 as i32 != 0;
1085+
(*z).iff2 = 0 as i32 != 0;
1086+
(*z).halted = 0 as i32 != 0;
11041087
(*z).nmi_pending = 0 as i32 as uint8_t;
11051088
}
11061089
unsafe fn z80_step_s(z: *mut z80) -> u32 {
11071090
let mut cyc: u32 = 0 as i32 as u32;
1108-
if (*z).halted() {
1091+
if (*z).halted {
11091092
cyc = cyc.wrapping_add(exec_opcode(z, 0 as i32 as uint8_t));
11101093
} else {
11111094
let opcode: uint8_t = nextb(z);
@@ -2142,8 +2125,8 @@ unsafe fn exec_opcode(z: *mut z80, mut opcode: uint8_t) -> u32 {
21422125
}
21432126
243 => {
21442127
cyc = cyc.wrapping_add(4 as i32 as u32);
2145-
(*z).set_iff2(0 as i32 != 0);
2146-
(*z).set_iff1((*z).iff2());
2128+
(*z).iff2 = 0 as i32 != 0;
2129+
(*z).iff1 = (*z).iff2;
21472130
}
21482131
251 => {
21492132
cyc = cyc.wrapping_add(4 as i32 as u32);
@@ -2154,7 +2137,7 @@ unsafe fn exec_opcode(z: *mut z80, mut opcode: uint8_t) -> u32 {
21542137
}
21552138
118 => {
21562139
cyc = cyc.wrapping_add(4 as i32 as u32);
2157-
(*z).set_halted(1 as i32 != 0);
2140+
(*z).halted = 1 as i32 != 0;
21582141
}
21592142
60 => {
21602143
cyc = cyc.wrapping_add(4 as i32 as u32);
@@ -3768,7 +3751,7 @@ unsafe fn exec_opcode_ed(z: *mut z80, mut opcode: uint8_t) -> u32 {
37683751
);
37693752
flag_set(z, hf, 0 as i32 != 0);
37703753
flag_set(z, nf, 0 as i32 != 0);
3771-
flag_set(z, pf, (*z).iff2());
3754+
flag_set(z, pf, (*z).iff2);
37723755
}
37733756
95 => {
37743757
cyc = cyc.wrapping_add(9 as i32 as u32);
@@ -3786,11 +3769,11 @@ unsafe fn exec_opcode_ed(z: *mut z80, mut opcode: uint8_t) -> u32 {
37863769
);
37873770
flag_set(z, hf, 0 as i32 != 0);
37883771
flag_set(z, nf, 0 as i32 != 0);
3789-
flag_set(z, pf, (*z).iff2());
3772+
flag_set(z, pf, (*z).iff2);
37903773
}
37913774
69 | 85 | 93 | 101 | 109 | 117 | 125 => {
37923775
cyc = cyc.wrapping_add(14 as i32 as u32);
3793-
(*z).set_iff1((*z).iff2());
3776+
(*z).iff1 = (*z).iff2;
37943777
ret(z);
37953778
}
37963779
77 => {

0 commit comments

Comments
 (0)