Question

This is an 8 bit architecture, with a word size of 16 bits. I now need to use a 48-bit integer variable. My understanding is that libm implements 8, 16, 32, 64 bit operations (addition, multiplication, signed and unsigned).

So in order to make calculations, I must store the value in a 64-bit signed or unsigned integer. Correct?

If so, what is there to prevent general routines from being used? For example, for addition:

  1. start with the LSB of both variables
  2. add them up
  3. if more bytes are available continue, otherways goto ready
  4. shift both variables 1 byte to the right
  5. goto 1)
Was it helpful?

Solution

libm implements the routines for the standard sizes of types, and the compiler chooses the right one to use for expression.

If you want to implement your own types, you can. If you want to use the usual operators, then you have to get into the compilation process to get the compiler to choose yours.

You could implement the operations as functions, say add(int48_t, int48_t), but then the compiler won't be able to do optimizations like constant folding, etc.

So, there is nothing stopping you from implementing your own custom compiler, but is it really necessary? Do you really need to save that space? If so, then go for it!

OTHER TIPS

That is correct, saving a couple of bits is (in almost all cases) not worth the trouble of implementing your own logic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top