OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.dg/] [builtin-bswap-4.c] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 689 jeremybenn
/* { dg-do run } */
2
/* { dg-require-effective-target stdint_types } */
3
/* { dg-options "-Wall" } */
4
 
5
#include <stdint.h>
6
 
7
#define MAKE_FUN(suffix, type)                                          \
8
  type my_bswap##suffix(type x) {                                       \
9
    type result = 0;                                                     \
10
    int shift;                                                          \
11
    for (shift = 0; shift < 8 * sizeof (type); shift += 8)       \
12
      {                                                                 \
13
        result <<= 8;                                                   \
14
        result |= (x >> shift) & 0xff;                                  \
15
      }                                                                 \
16
    return result;                                                      \
17
  }                                                                     \
18
 
19
MAKE_FUN(32, uint32_t);
20
MAKE_FUN(64, uint64_t);
21
 
22
extern void abort (void);
23
 
24
#define NUMS32                                  \
25
  {                                             \
26
    0x00000000UL,                               \
27
    0x11223344UL,                               \
28
    0xffffffffUL,                               \
29
  }
30
 
31
#define NUMS64                                  \
32
  {                                             \
33
    0x0000000000000000ULL,                      \
34
    0x1122334455667788ULL,                      \
35
    0xffffffffffffffffULL,                      \
36
  }
37
 
38
uint32_t uint32_ts[] =
39
  NUMS32;
40
 
41
uint64_t uint64_ts[] =
42
  NUMS64;
43
 
44
#define N(table) (sizeof (table) / sizeof (table[0]))
45
 
46
int
47
main (void)
48
{
49
  int i;
50
 
51
  for (i = 0; i < N(uint32_ts); i++)
52
    if (__builtin_bswap32 (uint32_ts[i]) != my_bswap32 (uint32_ts[i]))
53
      abort ();
54
 
55
  for (i = 0; i < N(uint64_ts); i++)
56
    if (__builtin_bswap64 (uint64_ts[i]) != my_bswap64 (uint64_ts[i]))
57
      abort ();
58
 
59
  return 0;
60
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.