So I just had a thought. Most synthesis tools (in VHDL, and I assume in Verilog) will allow you to use the division operator to perform truncating division by a constant in synthesizable code, so long as that constant is a power of 2.
That seems like a reasonable restriction; that you can only divide when it's just a right shift, right up until you think a bit longer. Because I do synthesizable division by a constant all the time, actually, as multiplication by the reciprocal. So I wind up writing things like
y := x * (2**17 / 3) / 2**17.
It obscures the logic a bit, but works. But I was thinking, and not only does it obscure the logic, but it forces assumptions into my code about what the underlying multiplier block looks like. Why 2**17? Because I'm assuming a 18 bit signed multiplier, because that's what happens to be on some architecture (Altera Cyclone4 if I remember right).
It seems trivial for the synthesizer to do that transformation, division by a constant => multiplication by the reciprocal, in a way that is optimized for the underlying hardware. Any non-braindamaged C compiler will do it without being asked. And maybe the synth tools do, it's just been forever since I've actually checked.
Has anyone looked at this in a while? Are any of the synth tools smart enough to handle this on their own these days?