summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/optimize-bswapsi-4.c
blob: a298486c439fedb12941fa450788f4c09b2ac2f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* { dg-do compile } */
/* { dg-require-effective-target bswap32 } */
/* { dg-options "-O2 -fdump-tree-bswap" } */
/* { dg-additional-options "-march=z900" { target s390-*-* } } */

typedef unsigned char u8;
typedef unsigned int u32;
union __anonunion
{
  u32 value;
  u8 bytes[4];
};

u32
acpi_ut_dword_byte_swap (u32 value)
{
  union __anonunion in;
  in.value = value;
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  return ((in.bytes[0] << 24) | (in.bytes[1] << 16)
	  | (in.bytes[2] << 8) | in.bytes[3]);
#else
  return ((in.bytes[3] << 24) | (in.bytes[2] << 16)
	  | (in.bytes[1] << 8) | in.bytes[0]);
#endif
}

/* { dg-final { scan-tree-dump "32 bit bswap implementation found at" "bswap" } } */