On Sun, 28 Dec 2025 at 16:20, Paolo Bonzini <[email protected]> wrote: > > Il dom 28 dic 2025, 17:00 Philippe Mathieu-Daudé <[email protected]> ha > scritto: >> >> On 28/12/25 16:38, Paolo Bonzini wrote: >> > >> > >> > Il dom 28 dic 2025, 16:14 Philippe Mathieu-Daudé <[email protected] >> > <mailto:[email protected]>> ha scritto: >> > >> > > Perhaps the source of the confusion is that they are in bswap.h >> > but they >> > > (quite obviously since it's host endianness) never swap? >> > >> > Hmm, maybe not well named API then. >> > >> > >> > The name is fine, the placement maybe a bit less; they could be moved >> > out of bswap.h but it's not really necessary to do it now. >> >> Indeed not needed now, but already done to figure this API ;) This >> helped me to understand what we don't need is "DO_STN_LDN_P(he)" >> because this is a convoluted expansion to a plain memcpy(). > > > Without having seen your code, I will note that the simple conversion to > memcpy() only works for little endian hosts. On big endian, you also need to > adjust the first byte, like > > memcpy(p, ((uint8_t*)&val) + sizeof(val) - n, n); > > And likewise for ldn_he_p. (Apologize if you had noticed it, just trying to > avoid a possible round trip over the holidays!)
But an inline memcpy() is hard to read and easy to get wrong: we have a pointer-cast and some pointer arithmetic going on here. What we want is to express our intent: "I am doing a load/store of N bytes which are in the host byte order and which might not be aligned". That's what the _he_p() functions are all for. thanks -- PMM
