On Sat, 22 Apr 2023 at 12:03, Thomas Weißschuh <tho...@t-8ch.de> wrote: > > On 2023-04-22 02:58:07+0200, Ilya Leoshkevich wrote: > > Make sure values are stored in memory as little-endian regardless of > > the host endianness. > > > > Signed-off-by: Ilya Leoshkevich <i...@linux.ibm.com> > > --- > > tests/tcg/multiarch/system/memory.c | 24 ++++++++++++++++++++++++ > > 1 file changed, 24 insertions(+) > > > > diff --git a/tests/tcg/multiarch/system/memory.c > > b/tests/tcg/multiarch/system/memory.c > > index 214f7d4f54b..8ef6666b440 100644 > > --- a/tests/tcg/multiarch/system/memory.c > > +++ b/tests/tcg/multiarch/system/memory.c > > @@ -121,6 +121,9 @@ static void init_test_data_u16(int offset) > > for (i = 0; i < max; i++) { > > uint8_t low = count++, high = count++; > > word = BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0); > > +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ > > + word = __builtin_bswap16(word); > > +#endif > > These looks like a usecase for cpu_to_le16() and friends.
I'm not sure this test code has direct access to those, but the general principle is right. It is particularly odd that we carefully manually put together a word by shifting-and-ORing together the various bytes in it, and then separately do a byteswap. thanks -- PMM