On Thu, Nov 24, 2022 at 3:16 PM twp...@gmail.com <twpa...@gmail.com> wrote:
>
> tl;dr: on 64-bit little-endian machines, does
>
>     x := math.Float64frombits(binary.LittleEndian.Uint64(byteSlice[:8]))
>
> get optimized to a single move instruction from byteSlice[:8] to x?
>
>
> Background info:
>
> I'm currently writing a bunch of code that unmarshals binary data. A small 
> example is this that unmarshals eight float64s, and a longer example is this 
> that unmarshals an arbitrary number of float64s. In theory, when the 
> endianness of the binary data matches the endianness of the architecture, 
> these should become simple memory copies. Does Go 1.19 do this?
>
> Although this is a performance question, performance is not a concern in my 
> use case. This is just an idle "can Go do this yet?" question and I'm curious 
> about the answer.


The godbolt.org website is a good way to play with this kind of
question.  For example https://godbolt.org/z/fasvKa3dx shows, on lines
43 and 44, that, ignoring the check that the slice bounds check, this
code boils down to two instructions.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVHKbsddHx%2BM%2B2_8pYGdu1y2D%2BJGQd9dKPC%2BeM8Bc%2BM1A%40mail.gmail.com.

Reply via email to