builtin-bswap-1.c: New.

2006-10-31  Eric Christopher  <echristo@apple.com>
	    Falk Hueffner  <falk@debian.org>

	* gcc.dg/builtin-bswap-1.c: New.
	* gcc.dg/builtin-bswap-2.c: New.
	* gcc.dg/builtin-bswap-3.c: New.
	* gcc.dg/builtin-bswap-4.c: New.
	* gcc.dg/builtin-bswap-5.c: New.
	* gcc.target/i386/builtin-bswap-1.c: New.

Co-Authored-By: Falk Hueffner <falk@debian.org>

From-SVN: r118364
This commit is contained in:
Eric Christopher 2006-11-01 05:20:05 +00:00 committed by Geoffrey Keating
parent 91053e6c25
commit 0e7e09dc1e
7 changed files with 149 additions and 0 deletions

View File

@ -1,3 +1,13 @@
2006-10-31 Eric Christopher <echristo@apple.com>
Falk Hueffner <falk@debian.org>
* gcc.dg/builtin-bswap-1.c: New.
* gcc.dg/builtin-bswap-2.c: New.
* gcc.dg/builtin-bswap-3.c: New.
* gcc.dg/builtin-bswap-4.c: New.
* gcc.dg/builtin-bswap-5.c: New.
* gcc.dg/i386/builtin-bswap-1.c: New.
2006-10-31 Geoffrey Keating <geoffk@apple.com>
* gcc.dg/inline-16.c: New.

View File

@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "" } */
/* { dg-final { scan-assembler-not "__builtin_" } } */
#include <stdint.h>
uint32_t foo (uint32_t a)
{
int b;
b = __builtin_bswap32 (a);
return b;
}

View File

@ -0,0 +1,19 @@
/* { dg-do run } */
/* { dg-options "" } */
#include <stdint.h>
extern void abort (void);
int main (void)
{
uint32_t a = 4;
uint32_t b;
b = __builtin_bswap32 (a);
a = __builtin_bswap32 (b);
if (b == 4 || a != 4)
abort ();
return 0;
}

View File

@ -0,0 +1,19 @@
/* { dg-do run } */
/* { dg-options "" } */
#include <stdint.h>
extern void abort (void);
int main (void)
{
uint32_t a = 0x80000000;
uint32_t b;
b = __builtin_bswap32 (a);
a = __builtin_bswap32 (b);
if (b != 0x80 || a != 0x80000000)
abort ();
return 0;
}

View File

@ -0,0 +1,59 @@
/* { dg-do run } */
/* { dg-options "-Wall" } */
#include <stdint.h>
#define MAKE_FUN(suffix, type) \
type my_bswap##suffix(type x) { \
type result = 0; \
int shift; \
for (shift = 0; shift < 8 * sizeof (type); shift += 8) \
{ \
result <<= 8; \
result |= (x >> shift) & 0xff; \
} \
return result; \
} \
MAKE_FUN(32, uint32_t);
MAKE_FUN(64, uint64_t);
extern void abort (void);
#define NUMS32 \
{ \
0x00000000UL, \
0x11223344UL, \
0xffffffffUL, \
}
#define NUMS64 \
{ \
0x0000000000000000ULL, \
0x1122334455667788ULL, \
0xffffffffffffffffULL, \
}
uint32_t uint32_ts[] =
NUMS32;
uint64_t uint64_ts[] =
NUMS64;
#define N(table) (sizeof (table) / sizeof (table[0]))
int
main (void)
{
int i;
for (i = 0; i < N(uint32_ts); i++)
if (__builtin_bswap32 (uint32_ts[i]) != my_bswap32 (uint32_ts[i]))
abort ();
for (i = 0; i < N(uint64_ts); i++)
if (__builtin_bswap64 (uint64_ts[i]) != my_bswap64 (uint64_ts[i]))
abort ();
return 0;
}

View File

@ -0,0 +1,16 @@
/* { dg-do run } */
/* { dg-options "-O" } */
int
main (void)
{
/* Test constant folding. */
extern void link_error (void);
if (__builtin_bswap32(0xaabbccdd) != 0xddccbbaa)
link_error ();
if (__builtin_bswap64(0x1122334455667788ULL) != 0x8877665544332211ULL)
link_error ();
return 0;
}

View File

@ -0,0 +1,12 @@
/* { dg-do compile } */
/* { dg-options "-march=i486" } */
/* { dg-final { scan-assembler "bswap" } } */
int foo (int a)
{
int b;
b = __builtin_bswap (a);
return b;
}