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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [testsuite/] [gcc.dg/] [duff-3.c] - Blame information for rev 826

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 298 jeremybenn
/* Duff's device is legal C; test to make sure the compiler
2
   doesn't complain about it.
3
 
4
   Jason Thorpe <thorpej@wasabisystems.com>
5
   Derived from Tom Duff's original usenet message about the device.  */
6
 
7
/* { dg-do run } */
8
/* { dg-options "-O2" } */
9
 
10
extern void abort (void);
11
extern void exit (int);
12
 
13
typedef __SIZE_TYPE__ size_t;
14
extern int memcmp (const void *, const void *, size_t);
15
 
16
void
17
duffcpy (char *dst, const char *src, unsigned long size)
18
{
19
  unsigned long n = (size + 7) / 8;
20
 
21
  switch (size % 8)
22
    {
23
    case 0:      do {    *dst++ = *src++;
24
    case 7:             *dst++ = *src++;
25
    case 6:             *dst++ = *src++;
26
    case 5:             *dst++ = *src++;
27
    case 4:             *dst++ = *src++;
28
    case 3:             *dst++ = *src++;
29
    case 2:             *dst++ = *src++;
30
    case 1:             *dst++ = *src++;
31
                } while (--n > 0);
32
    }
33
}
34
 
35
const char testpat[] = "The quick brown fox jumped over the lazy dog.";
36
 
37
int
38
main()
39
{
40
  char buf[64];
41
 
42
  duffcpy (buf, testpat, sizeof (testpat));
43
  if (memcmp (buf, testpat, sizeof (testpat)) != 0)
44
    abort ();
45
 
46
  exit (0);
47
}

powered by: WebSVN 2.1.0

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