Can't implement conformant memset/memcpy without compiler -ffreestanding support

Zheng Luo (Vic) vicluo96 at gmail.com
Wed Jul 25 09:48:08 UTC 2018


On Wednesday, 25 July 2018 at 09:37:56 UTC, rikki cattermole 
wrote:

> You misunderstand.
> It isn't optimizing anything.
> You requested the call to memcpy, explicitly when you said 'I 
> want this copied ASAP'.
> 
> By the looks, the spec doesn't clearly explain this properly.

Well, it seems that this is not a good example to show. I didn't 
notice its semantics :)

>> 
>> A naive implementation of memset also lead to "call memset": 
>> https://run.dlang.io/is/k3Hl04
>
> Okay yup, that is an optimization.
>
> This won't optimize:
>
> extern(C) void* memset(ubyte* dest, int val, size_t count) {
>     immutable c = cast(ubyte)val;
>     foreach(i; 0..count) {
>         dest[i] = c;
>     }
>     return dest;
> }
>
> And yes the name is important :)

First, IIRC, the name hacking is a technique used to bypass llvm 
optimizers, I'm not sure if it also applies to gdc. Moreover, I 
think this *is* a hack around compiler because this forces memset 
implementer to write all code in that function.



More information about the Digitalmars-d mailing list