From 0342454f8aa6fc55e515bad26425533e10b58085 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 2 Sep 2016 17:36:23 +0200 Subject: [PATCH] optionrom: do not rely on compiler's bswap optimization Recent compilers can detect and inline manually-written bswap code, but GCC 4.2.1 (the last GPLv2 version) cannot and generates really awful code. Depending on how the compiler is configured, it might also not want to generate bswap because it was not in i386. Using asm is fine because TCG knows about bswap and all processors with virtualization extensions also do. Reported-by: Peter Maydell Signed-off-by: Paolo Bonzini --- pc-bios/linuxboot_dma.bin | Bin 1536 -> 1536 bytes pc-bios/optionrom/linuxboot_dma.c | 18 ++++-------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/pc-bios/linuxboot_dma.bin b/pc-bios/linuxboot_dma.bin index 238a195d3869995067f158d243d852778d38a736..218d3ab4a29bfb5ab7125ec7a4d29dad1860c673 100644 GIT binary patch delta 339 zc-m{=Y2cXqTF4ibl!mZGIOmkt_U zgO-q@A&DR|LT?D7O^Cd{_v*VmynLP?-?wU4?c-*Icftn zHAj9b4$E%~vgcBNScWLN7HP$`Ne^6;)N~=<5%6io8t1EN2iw@i9(Hi+w+KDv3fU-% z%JA3S46aR@MX(fW_&bXE5e)>K06mKo2|q{8Wn(ROHkz~?-I`S`(X1FJ-p}8}wX{2< z+!xKc=9c18aXP>e%#V-7-SAT9ZJp1md_(iR=8ocr> 8) | - ((x & 0xff000000U) >> 24); + asm("bswapl %0" : "=r" (x) : "0" (x)); + return x; } static inline uint64_t bswap64(uint64_t x) { - return - ((x & 0x00000000000000ffULL) << 56) | - ((x & 0x000000000000ff00ULL) << 40) | - ((x & 0x0000000000ff0000ULL) << 24) | - ((x & 0x00000000ff000000ULL) << 8) | - ((x & 0x000000ff00000000ULL) >> 8) | - ((x & 0x0000ff0000000000ULL) >> 24) | - ((x & 0x00ff000000000000ULL) >> 40) | - ((x & 0xff00000000000000ULL) >> 56); + asm("bswapl %%eax; bswapl %%edx; xchg %%eax, %%edx" : "=A" (x) : "0" (x)); + return x; } static inline uint64_t cpu_to_be64(uint64_t x) -- 2.39.5