News for hackers. Stuff that matters.
Re:Mispredicted branches can multiply your running times by gpderetta on Wednesday October 16, 2019 @06:45AM (#21268960)
You just reinvented delay slots [1].

Two issues:

- It is not easy for the compiler to always fill up a single delay slot. Filling dozen of them (as required for a deeply pipelined modern processor) would be significantly harder.

- The number of delay slots would depend on the depth of the cpu pipeline. If you do not want to expose microarchitectural details in your ISA, you need either JIT or install time specialization. edit: or stick with a potentially suboptimal number.

[1] https://en.wikipedia.org/wiki/Delay_slot

Re:Mispredicted branches can multiply your running times by planteen on Wednesday October 16, 2019 @12:57PM (#21272595)
Oh this takes me back to a horrible time in my life when I was tracking down a terrible intermittent crash on a LEON (SPARC) processor. I was down at the assembly level, stepping over instructions. It was a bit mind bending to always have an instruction execute AFTER the branch (you wouldn't know if the branch was taken or not until AFTER the delay slot instruction). Often the delay instruction was a NOP, showing the difficulty in filling the delay slots as you mentioned. If you were really lucky, your branch would also result in a register window overflow. By the time handling that was done, you lost your mental context of what was going on. shudder
Re:Mispredicted branches can multiply your running times by gpderetta on Wednesday October 16, 2019 @01:04PM (#21272687)
Right, SPARC has both register windows and branch delay slots, truly a great collection of architectural dead ends :).
Re:Mispredicted branches can multiply your running times by sv_h1b on Wednesday October 16, 2019 @01:32PM (#21272994)
Plus, the delay slots are typically _fixed_ 1-5 cycles depending on CPU architectures. The problem is sometimes the real delay could easily be 200+ cycles (TLB/ cache reload, bus contention etc.) and _variable_.

There's no way you could cover all variable latency scenarios with fixed delay slots, unless you have a highly specific scenario like a GPU where you control all the internals.