version=D_16

Luís Marques via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 13 09:46:12 PDT 2017


On Monday, 10 July 2017 at 21:30:44 UTC, Walter Bright wrote:
> For example, ints in C are 16 bits. In D they are 32. This 
> means that integer operations are expensive.

I just realized something interesting. The same situation happens 
on AVR with C. AVR is 8 bit (but often competes with 16-bit 
microcontrollers), which means that (int8_t x = int8_t a + int8_t 
b) at the C level is computed as (int8_t x = int16_t a + int16_t 
b).

This means that a lot of people (AVR is very popular, in part 
because of Arduino) have been relying on the optimizer. I haven't 
seen complaints or comments about this issue, so as far as I can 
tell this hasn't been a problem in the world at large, at least 
that people have noticed.

BTW, do notice that the addition with carry is optimized away 
even at the -O0 level.

On D side the issue that remains is the ergonomics of having to 
type cast(short) more frequently. I suppose that if this proves 
too inconvenient we can just create a library type that avoids 
this issue, right?




More information about the Digitalmars-d mailing list