What is the better signature for this?

Bruce Carneal bcarneal at gmail.com
Tue Oct 11 13:24:00 UTC 2022


On Tuesday, 11 October 2022 at 12:51:13 UTC, Kagamin wrote:
> On Monday, 10 October 2022 at 12:44:18 UTC, Guillaume Piolat 
> wrote:
>> That is solution C.
>> It could work.
>
> Static array works like this:
> ```
> int Load4LE(in ref ubyte[4] b) pure
> {
> 	return (b[3]<<24)|(b[2]<<16)|(b[1]<<8)|b[0];
> }
>
> ubyte[] data;
> int val=Load4LE(data[0..4]);
> ```
> It's safe, bound checked, ctfeable, no casts.
>
Yes.  Starting at line 57 you'll find examples of the above for a 
target-adaptive/generic environment: 
https://godbolt.org/z/qW6PYT3Yd

I've not found a way to trigger those one-instruction unaligned 
loads from DMD but ldc and gdc are doing great.



More information about the Digitalmars-d mailing list