A cross-platform simulator for the GreenArrays GA144 multi-computer chip.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

keep track of execution time

+11 -8
+11 -8
src/f18.zig
··· 127 127 // keeps track of current slot to help address decoding 128 128 slot: u2, 129 129 130 + execution_time: f32, 131 + 130 132 pub fn step(self: *Computer) void { 131 133 var instruction: Instruction = undefined; 132 134 ··· 143 145 self.state = .execution; 144 146 current_slot: switch (self.slot) { 145 147 0...2 => { 146 - _ = self.execute(instruction.getSlot(self.slot)); 148 + self.execute(instruction.getSlot(self.slot)); 147 149 if (self.state != .execution) continue :current_state self.state; 148 150 continue :current_slot self.slot; 149 151 }, 150 152 3 => { 151 - _ = self.execute(Opcode.fromInt(instruction.slot_3)); 153 + self.execute(instruction.getSlot(self.slot)); 152 154 if (self.state != .execution) continue :current_state self.state; 153 155 break :current_state; 154 156 }, ··· 167 169 } 168 170 } 169 171 170 - pub fn execute(self: *Computer, opcode: Opcode) f64 { 172 + pub fn execute(self: *Computer, opcode: Opcode) void { 171 173 const code: u5 = @intCast(@intFromEnum(opcode)); 172 - switch (code) { 174 + self.execution_time += time: switch (code) { 173 175 0x00...0x03, 0x05...0x07 => { 174 176 self.state = .next; 175 177 opcodes.opcodes[code](self); 176 178 177 - return 5.1; 179 + break :time 5.1; 178 180 }, 179 181 0x04 => { 180 182 self.state = .unext; 181 183 opcodes.opcodes[code](self); 182 184 183 - return 2.0; 185 + break :time 2.0; 184 186 }, 185 187 else => { 186 188 self.state = .execution; 187 189 self.slot +%= 1; 188 190 opcodes.opcodes[code](self); 189 191 190 - return 1.5; 192 + break :time 1.5; 191 193 }, 192 - } 194 + }; 193 195 } 194 196 195 197 pub fn fetch(self: Computer, address: Address) Word { ··· 229 231 230 232 .state = .fetch, 231 233 .slot = 0, 234 + .execution_time = 0.0, 232 235 }; 233 236 }; 234 237