2 ms·
The way processors work, if the single instruction / automatic on interrupt etc method does the same things as do it yourself in your code version, about the on
by toast0 3y ago
The way processors work, if the single instruction / automatic on interrupt etc method does the same things as do it yourself in your code version, about the only thing you're saving is instruction decode bandwidth and compiled code size. But that's usually not a large enough savings to matter.
And then you get the inflexibility: There's a limited number of hardware task slots; I think you can pick which registers to save (or rather how many to save), but you always save all of them: a kernel syscall might be more judicious and only save the registers it uses (of course saving all registers if returning to a different task); it's hard to change because software must run on old and new cpus; etc.
There's exceptions to the rule of thumb. Rep mov can be faster than doing it yourself. It's also quite possible for a combined operation to do two things at the same time rather than one after the other.