r/AskComputerScience • u/Successful_Box_1007 • Sep 26 '25
Why is Logism so slow at arithmetic compared to using an emulator of logism circuit that uses our actual computer’s cpu?
Hi everyone. Hoping to get alittle help; So this guy in this video made his own 16 bit cpu; now as someone just beginning his journey, a lot went over my head:
https://m.youtube.com/watch?v=Zt0JfmV7CyI&pp=ygUPMTYgYml0IGNvbXB1dGVy
But one thing really confuses me: just after 11:00 he says of this color changing video he made on the cpu: "it only will run 1 frame per second; and its not an issue with the program I made, the program is perfectly fine: the problem is Logisism needs to simulate all of the different logic relationships and logic gates and that actually takes alot of processing to do" - so my question is - what flaw is in the Logisism program that causes it to be so much slower than his emulator that he used to solve the slowness problem?
Thanks so much!
10
u/ghjm MSCS, CS Pro (20+) Sep 26 '25
There's no flaw in the Logisim program. The reason it runs his CPU slowly is exactly what he said - it's simulating all the logic, down to the individual signals and traces. The emulator he wrote doesn't do this.
What he should really do is export his Logisim design to HDL, then program it into an FPGA and run it as real hardware.
4
u/khedoros Sep 26 '25
Since you posted this in like 3 or 4 places, I'm going to grab some of the follow-up questions that you asked.
They're talking about levels of abstraction.
Logisim is a program simulating the behavior of the CPU at a logic gate level. It's actually tracking the propagation of signals over "wires" between logic gates.
The emulator is a lot more likely to be a program simulating the behavior of the CPU at more like the instruction level. It's using the physical hardware of the host computer to replicate the virtual CPU's behavior directly.
So: Why isn't Logisim simulating individual electrons, collapsing quantum wave functions, etc to do an actual physical simulation of the behavior of the electronics? It's mostly unnecessary; the simulation can occur at a higher level of abstraction. A level higher than the detailed physics simulation might still track voltage levels and activation curves for the transistors. A higher level just deals with "on" and "off", but still simulates individual transistors (gates are made up of several). Higher level? Simulates gates. Higher level again: maybe chunks of circuits, with the behavior defined by a truth table...and at that point, you're already beyond a simulation that uses logic gates.
The emulator would be a few abstractions above that. Like, here's the add instruction (ADC is "Add with Carry") in my NES emulator: https://github.com/khedoros/khednes/blob/master/cpu2.cpp#L436
3
u/No-Let-6057 Sep 26 '25
Logisim is a simulator, that simulates the transistors that comprise a CPU. An emulator does not simulation and will use the real HW of the real CPU where appropriat.
If you don’t know how an adder works, it’s kind of hard to explain the difference.
Basically an adder takes two 16 bit values and adds them, yeah? For simplicity I’ll use 4 bit values
0110 + 0011 = 1001 (6 + 3 = 9)
With a simulator you have to implement every transistor to perform the calculation, which is slow, inefficient, and slow.
With an emulater you use the real adding HW, which can complete the addition in one clock cycle. With a simulator you might spend a clock for every logic gate in the adder (as a naive implementation):
https://en.wikipedia.org/wiki/Adder_(electronics)#Full_adder
5 logic gates, 16 bits, and therefore 80 cycles to perform a single addition.