diff options
author | Jason Thorpe <thorpej@wasabisystems.com> | 2002-11-19 04:27:13 +0000 |
---|---|---|
committer | Jason Thorpe <thorpej@gcc.gnu.org> | 2002-11-19 04:27:13 +0000 |
commit | 3b312ef46fc9f3319b688174a105d5827dd122b1 (patch) | |
tree | 234e4b72677896d4394c8cc46f85801a9ed648c2 | |
parent | 08c42743e01fd59d90aa6c65a92d1085c5f0ef35 (diff) | |
download | gcc-3b312ef46fc9f3319b688174a105d5827dd122b1.zip gcc-3b312ef46fc9f3319b688174a105d5827dd122b1.tar.gz gcc-3b312ef46fc9f3319b688174a105d5827dd122b1.tar.bz2 |
duff-1.c: New test.
* gcc.dg/duff-1.c: New test.
* gcc.dg/duff-2.c: New test.
* gcc.dg/duff-3.c: New test.
From-SVN: r59240
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/duff-1.c | 50 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/duff-2.c | 60 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/duff-3.c | 47 |
4 files changed, 163 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b1448b0..ec205b0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2002-11-19 Jason Thorpe <thorpej@wasabisystems.com> + + * gcc.dg/duff-1.c: New test. + * gcc.dg/duff-2.c: New test. + * gcc.dg/duff-3.c: New test. + 2002-11-18 Neil Booth <neil@daikokuya.co.uk> * gcc.dg/cpp/_Pragma5.c: New test. diff --git a/gcc/testsuite/gcc.dg/duff-1.c b/gcc/testsuite/gcc.dg/duff-1.c new file mode 100644 index 0000000..b718f6c --- /dev/null +++ b/gcc/testsuite/gcc.dg/duff-1.c @@ -0,0 +1,50 @@ +/* Duff's device is legal C; test to make sure the compiler + doesn't complain about it. + + Jason Thorpe <thorpej@wasabisystems.com> + Derived from PR 3846. */ + +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +extern void abort (void); +extern void exit (int); + +typedef __SIZE_TYPE__ size_t; +extern int memcmp (const void *, const void *, size_t); + +void +duffcpy (char *dst, const char *src, unsigned long size) +{ + switch (size & 3) + { + for (;;) + { + *dst++ = *src++; + case 3: + *dst++ = *src++; + case 2: + *dst++ = *src++; + case 1: + *dst++ = *src++; + case 0: + if (size <= 3) + break; + size -= 4; + } + } +} + +const char testpat[] = "The quick brown fox jumped over the lazy dog."; + +int +main() +{ + char buf[64]; + + duffcpy (buf, testpat, sizeof (testpat)); + if (memcmp (buf, testpat, sizeof (testpat)) != 0) + abort (); + + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/duff-2.c b/gcc/testsuite/gcc.dg/duff-2.c new file mode 100644 index 0000000..8b8923e --- /dev/null +++ b/gcc/testsuite/gcc.dg/duff-2.c @@ -0,0 +1,60 @@ +/* Duff's device is legal C; test to make sure the compiler + doesn't complain about it. + + Jason Thorpe <thorpej@wasabisystems.com> + Derived from the BSD Telnet Kerberos 4 checksum routine. + See also PR 5230. */ + +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +extern void abort (void); +extern void exit (int); + +#if __INT_MAX__ >= 2147483647 +/* At least 32-bit integers. */ +typedef int type32; +#else +typedef long type32; +#endif + +type32 +cksum (const unsigned char *src, unsigned long size) +{ + type32 ck = 0; + + switch (size & 3) + { + while (size > 0) + { + case 0: + ck ^= (type32)*src++ << 24; + --size; + case 3: + ck ^= (type32)*src++ << 16; + --size; + case 2: + ck ^= (type32)*src++ << 8; + --size; + case 1: + ck ^= (type32)*src++; + --size; + } + } + + return ck; +} + +const char testpat[] = "The quick brown fox jumped over the lazy dog."; + +int +main() +{ + type32 ck; + + ck = cksum ((const unsigned char *) testpat, sizeof (testpat)); + if (ck != 925902908) + abort (); + + exit (0); +} diff --git a/gcc/testsuite/gcc.dg/duff-3.c b/gcc/testsuite/gcc.dg/duff-3.c new file mode 100644 index 0000000..23cddef --- /dev/null +++ b/gcc/testsuite/gcc.dg/duff-3.c @@ -0,0 +1,47 @@ +/* Duff's device is legal C; test to make sure the compiler + doesn't complain about it. + + Jason Thorpe <thorpej@wasabisystems.com> + Derived from Tom Duff's original usenet message about the device. */ + +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +extern void abort (void); +extern void exit (int); + +typedef __SIZE_TYPE__ size_t; +extern int memcmp (const void *, const void *, size_t); + +void +duffcpy (char *dst, const char *src, unsigned long size) +{ + unsigned long n = (size + 7) / 8; + + switch (size % 8) + { + case 0: do { *dst++ = *src++; + case 7: *dst++ = *src++; + case 6: *dst++ = *src++; + case 5: *dst++ = *src++; + case 4: *dst++ = *src++; + case 3: *dst++ = *src++; + case 2: *dst++ = *src++; + case 1: *dst++ = *src++; + } while (--n > 0); + } +} + +const char testpat[] = "The quick brown fox jumped over the lazy dog."; + +int +main() +{ + char buf[64]; + + duffcpy (buf, testpat, sizeof (testpat)); + if (memcmp (buf, testpat, sizeof (testpat)) != 0) + abort (); + + exit (0); +} |