[Bug tree-optimization/65424] New: gcc does not recognize byte swaps implemented as loop.
fuz at fuz dot su
gcc-bugzilla@gcc.gnu.org
Sat Mar 14 14:31:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65424
Bug ID: 65424
Summary: gcc does not recognize byte swaps implemented as loop.
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: fuz at fuz dot su
Created attachment 35034
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35034&action=edit
endianess-aware reading / writing macros
gcc (r221432) is able to recognize the following code and implements it with
either a bswap or a straight load on x86.
#include <stdint.h>
extern uint32_t
rbe32(const uint8_t a[4])
{
uint32_t x = 0;
x |= a[0] << 24;
x |= a[1] << 16;
x |= a[2] << 8;
x |= a[3] << 0;
return x;
}
extern uint32_t
rle32(const uint8_t a[4])
{
uint32_t x = 0;
x |= a[0] << 0;
x |= a[1] << 8;
x |= a[2] << 16;
x |= a[3] << 24;
return x;
}
it isn't able to recognize the following two functions which yield identical
results:
extern uint32_t
rle32(const uint8_t a[4])
{
int i;
uint32_t x = 0;
for (i = 0; i < 4; i++)
x |= a[i] << 8 * i;
return x;
}
extern uint32_t
rbe32(const uint8_t a[4])
{
int i;
uint32_t x = 0;
for (i = 0; i < 4; i++)
x |= a[i] << 8 * (3 - i);
return x;
}
It would be great if gcc was able to recognize these implementations of
endianess-aware reads; this kind of code is produced by macros I use to
generate a bunch of read / write functions for differently sized types.
Attached is a file containing the macros I want to use.
More information about the Gcc-bugs
mailing list