Linked by Thom Holwerda on Tue 15th Jan 2013 22:29 UTC
Hardware, Embedded Systems "In this article, I show at the transistor and silicon level. I've discussed the mathematics of the 6502 overflow flag earlier and thought it would be interesting to look at the actual chip-level implementation. Even though the overflow flag is a slightly obscure feature, its circuit is simple enough that it can be explained at the silicon level."
Permalink for comment 549019
To read all comments associated with this story, please click here.
Optimization
by Alfman on Wed 16th Jan 2013 15:47 UTC
Alfman
Member since:
2011-01-28

A lot of optimizations can be done with the CPU flags. The trouble is that high level programming languages don't expose them, I'm looking at you C. The C language for it's part assumes the flags don't exist so that it doesn't have to emulate them on architectures which don't have them.

Something as basic as determining whether A+B has overflowed is non-trivial in C, especially considering how overflow logic gets optimized away, see this heated discussion in GCC's bug tracker:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30475

IMHO the lack of overflow flags is a deficiency of most high level languages.

Another flag we don't see much of is the parity flag, but I've found a very interesting way to use parity bits to optimize multi-word multiplication algorithms. An efficient population count function would do the trick too since the least significant bit represents parity. Even though C is thought to be the best low level language, there still exists a gap between it and assembly language.

Edited 2013-01-16 15:52 UTC

Reply Score: 6