Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> the modulo statement doesn't really do any better than a spelled-out conditional statement

Actually, on modern processors the modulo would probably be more efficient than the conditional due to cool stuff they do like pipelining. Pipelining is basically where they execute instructions ahead of time (sort of in pseudo-parallel); and so when there's a branch, there's a fair chance the results from future processing might have to be thrown out.

One of the techniques that's used to go around this is branch prediction[1], where they initially guess whether a branch will be taken or not and then depending on whether the branch was actually taken, they change their guess. This works particularly well for for loops and the kind.

Another development on the ARM side (and MIPS too, I think) are instructions that are embedded with conditionals in them.[2]

[1] http://en.wikipedia.org/wiki/Branch_predictor

[2] http://en.wikipedia.org/wiki/ARM_architecture#Conditional_ex...



Absolutely true. I was talking about the 8051, which is the context of the code I posted.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: