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

Problem is:

_ExtInt(16) + _ExtInt(15) => ExtInt(17)

_ExtInt(17) + _ExtInt(15) => ExtInt(18)

So let's say we have a,b and c. a is 16 bits, b and c are 14bits.

a + (b + c) => ExtInt(17) (a + b) + c => ExtInt(18)

Now obviously this a trivial example, but it highlights the fact that unless you're actually willing to carry the true ranges around in your type system, your calculation of bit widths are going to vary due to the details of which operations are done in which order with which intermediary variables.



I see, it's now the same problem as with floats. addition is not commutative anymore. But isn't that the same problem in HW also? With the right order you are saving transistors.


Well, it's not quite a problem with whether the operations are commutative - both of those phrasings of the problem will give the correct answer in hardware 100% of the time. The only difference is one made an efficient decision about the order of operations with knowledge of how bit growth rules work and the ranges of the inputs.

You do have the same problem in hardware, which is hardware designers job. The difference RTLs don't claim to be high level languages. This is an instance where there's a high level intention and a low level implementation, and the high level synthesis tool has just ported new language constructs into the high level language to do low level optimisation, rather than actually doing the synthesis optimisations that are expected.




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

Search: