Message ID | 20250417131004.47205-9-philmd@linaro.org |
---|---|
State | New |
Headers | show |
Series | misc: Prefer evaluating TARGET_BIG_ENDIAN in C | expand |
Philippe Mathieu-Daudé <philmd@linaro.org> writes: > Rather than evaluating TARGET_BIG_ENDIAN at preprocessing > time via #ifdef'ry, do it in C at compile time > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Acked-by: Alex Bennée <alex.bennee@linaro.org>
On 4/17/25 06:10, Philippe Mathieu-Daudé wrote: > Rather than evaluating TARGET_BIG_ENDIAN at preprocessing > time via #ifdef'ry, do it in C at compile time > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > include/gdbstub/helpers.h | 11 ++--------- > 1 file changed, 2 insertions(+), 9 deletions(-) > > diff --git a/include/gdbstub/helpers.h b/include/gdbstub/helpers.h > index 6f7cc48adcb..c33d5dfca3e 100644 > --- a/include/gdbstub/helpers.h > +++ b/include/gdbstub/helpers.h > @@ -56,17 +56,10 @@ static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi, > uint64_t val_lo) > { > uint64_t to_quad; > -#if TARGET_BIG_ENDIAN > - to_quad = tswap64(val_hi); > + to_quad = tswap64(TARGET_BIG_ENDIAN ? val_hi : val_lo); > g_byte_array_append(buf, (uint8_t *) &to_quad, 8); > - to_quad = tswap64(val_lo); > + to_quad = tswap64(TARGET_BIG_ENDIAN ? val_lo : val_hi); > g_byte_array_append(buf, (uint8_t *) &to_quad, 8); > -#else > - to_quad = tswap64(val_lo); > - g_byte_array_append(buf, (uint8_t *) &to_quad, 8); > - to_quad = tswap64(val_hi); > - g_byte_array_append(buf, (uint8_t *) &to_quad, 8); > -#endif > return 16; > } > I'm not keen on using both TARGET_BIG_ENDIAN and tswap. I think this ought to be uint64_t v0, v1; if (TARGET_BIG_ENDIAN) { v0 = cpu_to_be64(val_hi); v1 = cpu_to_be64(val_lo); } else { v0 = cpu_to_le64(val_lo); v1 = cpu_to_le64(val_hi); } g_byte_array_append(buf, (uint8_t *)&v0, 8); g_byte_array_append(buf, (uint8_t *)&v1, 8); r~
diff --git a/include/gdbstub/helpers.h b/include/gdbstub/helpers.h index 6f7cc48adcb..c33d5dfca3e 100644 --- a/include/gdbstub/helpers.h +++ b/include/gdbstub/helpers.h @@ -56,17 +56,10 @@ static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi, uint64_t val_lo) { uint64_t to_quad; -#if TARGET_BIG_ENDIAN - to_quad = tswap64(val_hi); + to_quad = tswap64(TARGET_BIG_ENDIAN ? val_hi : val_lo); g_byte_array_append(buf, (uint8_t *) &to_quad, 8); - to_quad = tswap64(val_lo); + to_quad = tswap64(TARGET_BIG_ENDIAN ? val_lo : val_hi); g_byte_array_append(buf, (uint8_t *) &to_quad, 8); -#else - to_quad = tswap64(val_lo); - g_byte_array_append(buf, (uint8_t *) &to_quad, 8); - to_quad = tswap64(val_hi); - g_byte_array_append(buf, (uint8_t *) &to_quad, 8); -#endif return 16; }
Rather than evaluating TARGET_BIG_ENDIAN at preprocessing time via #ifdef'ry, do it in C at compile time Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/gdbstub/helpers.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)