Waldek Hebisch wrote:
Frank Heckenbach wrote:
(And, BTW, if you want it included in the GPC distribution, please note the GPC Coding Standards. If I'd have to reformat the code or do other significant work with it, I won't do it, see above. Also, please don't change `* $10' to `shl 4' etc., as you did. Write high-level code and leave the low-level optimizations to the compiler.)
AFAIKS intended operation is a shift. So `shl 4' is a high-level specification and `* $10' buys nothing. I can understand that uglyfication to `* 16' gives more portable code,
Well, since I wrote the code, I may say that my intention was a multiplication, not a shift. The code in question is essentially a base conversion. Integer bases are defined in terms of multiplications. In the case where the base is a power of two, it can be optimized to a shift, but since this optimization does not apply to other bases, multiplication is the more general, and therefore higher-level representation.
but the unit uses shifts anyway.
That doesn't mean anything. The fact that shifts are low-level here doesn't mean they're unappropriate everywhere. (Most obviously, they're useful with a variable right argument, but not only there.)
<rant> I remenber a guy who wanted to use floating point in Linux kernel. He claimed that he have complicated formula very hard to do using integers. It turned out that the formula was turning on/off bits -- floting point was used to do that in BASIC
</rant>
Nice story, even though completely unrelated. (This is about bits, and the natural operations on bits are `and', `or' etc. In our case, we're talking about integers and the natural operations for integers include `*' and `div' much more than they do `shl' and `shr'.)
So I would say: write what you mean. If it is multiplication, use multiplication, if it is shift, use shift.
That's what I did, thanks.
Frank