H1 2015 Priorities and Bare-Metal Programming

Johannes Pfau via Digitalmars-d digitalmars-d at puremagic.com
Mon Feb 2 13:24:08 PST 2015


Am Mon, 02 Feb 2015 13:15:13 -0800
schrieb Walter Bright <newshound2 at digitalmars.com>:

> On 2/2/2015 9:15 AM, Johannes Pfau wrote:
> > It's also necessary that the compiler
> > knows after inlining that the address is a literal. Loading data
> > from fixed literal addresses produces different, more efficient
> > code than loading from an runtime address. As the function code
> > will generally be written for runtime values the compiler must
> > optimize after inlining to recognize the inlined code deals with
> > literals.
> 
> 
>    import core.bitop;
>    uint test() {
>      return volatileLoad(cast(uint *)0x1234);
>    }
>    ---
>    dmd -c foo
>    ---
>    _D3foo4testFZkL:
>          mov     EAX,01234h
>          mov     EAX,[EAX]
>          ret
> 
> Note that was an unoptimized build.

What's your argument?
That it still generates 2 instructions in the simplest case? That's an
X86 specific detail. On ARM and other RISC architectures there is a
difference between loading a literal (code into the instruction) or
loading a runtime value. On AVR gcc can even rewrite bit-sized stores
into set-bit and loads into read-bit instructions, but it needs to
know the addresses at compile time. If you don't believe me get an
AVR/ARM compiler and try it.


More information about the Digitalmars-d mailing list