3 ms·
> Other instructions leave some of the flags in an undefined state, although in some cases they are conditionally undefined. > I’ve heard that the Atom line of
by jamesfinlayson 4y ago
> Other instructions leave some of the flags in an undefined state, although in some cases they are conditionally undefined.
> I’ve heard that the Atom line of CPUs used a cheaper/slower way of doing bit shifts in the ALU, which results in the undefined flags having different values, although I haven’t tested this myself.
That seems... problematic. Do compilers know this and just ignore the flags if/when they use these instructions?
- woodruffw 4y agoYes. In general, compilers only test emit flag testing instructions after instructions that are explicitly defined as having flag-modifying semantics. (This is a common feature of ISAs, and makes sense in terms of component reuse: it allows you to cheaply reuse the ALU, for example, without needing extra wires/control signals telling it not to update the flag state.)
- Someone 4y ago> compilers only emit flag testing instructions after instructions that are explicitly defined as having flag-modifying semantics. I think compiler writers sometimes also have to know that instructions do not modify the flags. Such instructions can be inserted between flag-setting ones and the test of that flag.
- woodruffw 4y agoYes, good point! It would have been more accurate for me to say “the compiler should always have a model of the flags during lowering.”