From: Dominik Vogt Date: Thu, 5 Jan 2017 10:05:47 +0000 (+0000) Subject: S/390: Additional memset/memcpy runtime tests. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3db705650b723f5777940e9ff9485de90e1b81f9;p=gcc.git S/390: Additional memset/memcpy runtime tests. These were provided by Dominik to check more of the corner case in our memset/memcpy inline code. gcc/testsuite/ChangeLog: 2017-01-05 Dominik Vogt * gcc.target/s390/memcpy-2.c: New test. * gcc.target/s390/memset-2.c: New test. From-SVN: r244099 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 46734e9cab4..86dee20ddb8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-01-05 Dominik Vogt + + * gcc.target/s390/memcpy-2.c: New test. + * gcc.target/s390/memset-2.c: New test. + 2017-01-05 Andreas Krebbel * gcc.target/s390/memcpy-1.c: New test. diff --git a/gcc/testsuite/gcc.target/s390/memcpy-2.c b/gcc/testsuite/gcc.target/s390/memcpy-2.c new file mode 100644 index 00000000000..b9568ec6b7a --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/memcpy-2.c @@ -0,0 +1,94 @@ +/* Funtional memmov test. */ + +/* { dg-do run } */ +/* { dg-options "-O3" } */ + +#define MAX_LEN (8 * 1000) +#define X 0x11 + +char gsrc[MAX_LEN + 2]; +char gdst[MAX_LEN + 2]; + +__attribute__ ((noinline)) +int +compare_mem (int len) +{ + int i; + + if (gdst[0] != 0x61) + __builtin_abort(); + for (i = 1; i <= len; i++) + if (gsrc[i] != gdst[i]) + __builtin_abort(); + for (i = len + 1; i < MAX_LEN; i++) + if (gdst[i] != 0x61 + i % 4) + __builtin_abort(); +} + +__attribute__ ((noinline)) +void +init_mem (void) +{ + unsigned int *p1; + unsigned int *p2; + int i; + + p1 = (unsigned int *)gsrc; + p2 = (unsigned int *)gdst; + for (i = 0; i < MAX_LEN / sizeof(unsigned int); i++) + { + p1[i] = 0x71727374; + p2[i] = 0x61626364; + } +} + +#define MEMCPY_CHECK(DST, SRC, LEN) \ + init_mem (); \ + __builtin_memcpy ((DST) + 1, (SRC) + 1, (LEN)); \ + compare_mem ((LEN)); + + +int main(void) +{ + int lens[] = + { + 255, 256, 257, + 511, 512, 513, + 767, 768, 769, + 1023, 1024, 1025, + 1279, 1280, 1281, + 1535, 1536, 1537, + -999 + }; + int t; + + /* variable length */ + for (t = 0; lens[t] != -999; t++) + { + MEMCPY_CHECK (gdst, gsrc, lens[t]); + } + /* constant length */ + MEMCPY_CHECK (gdst, gsrc, 0); + MEMCPY_CHECK (gdst, gsrc, 1); + MEMCPY_CHECK (gdst, gsrc, 2); + MEMCPY_CHECK (gdst, gsrc, 3); + MEMCPY_CHECK (gdst, gsrc, 256); + MEMCPY_CHECK (gdst, gsrc, 257); + MEMCPY_CHECK (gdst, gsrc, 511); + MEMCPY_CHECK (gdst, gsrc, 512); + MEMCPY_CHECK (gdst, gsrc, 513); + MEMCPY_CHECK (gdst, gsrc, 767); + MEMCPY_CHECK (gdst, gsrc, 768); + MEMCPY_CHECK (gdst, gsrc, 769); + MEMCPY_CHECK (gdst, gsrc, 1023); + MEMCPY_CHECK (gdst, gsrc, 1024); + MEMCPY_CHECK (gdst, gsrc, 1025); + MEMCPY_CHECK (gdst, gsrc, 1279); + MEMCPY_CHECK (gdst, gsrc, 1280); + MEMCPY_CHECK (gdst, gsrc, 1281); + MEMCPY_CHECK (gdst, gsrc, 1535); + MEMCPY_CHECK (gdst, gsrc, 1536); + MEMCPY_CHECK (gdst, gsrc, 1537); + + return 0; +} diff --git a/gcc/testsuite/gcc.target/s390/memset-2.c b/gcc/testsuite/gcc.target/s390/memset-2.c new file mode 100644 index 00000000000..e1af7fe30d8 --- /dev/null +++ b/gcc/testsuite/gcc.target/s390/memset-2.c @@ -0,0 +1,92 @@ +/* Funtional setmem test. */ + +/* { dg-do run } */ +/* { dg-options "-O3" } */ + +#define MAX_LEN (8 * 1000) + +__attribute__ ((noinline)) +int +check_mem (char *mem, int val, int len) +{ + int i; + + if (mem[0] != 0x71) + __builtin_abort(); + for (i = 1; i <= len; i++) + if (mem[i] != val) + __builtin_abort(); + if (mem[len + 1] != 0x71 + (len + 1) % 4) + __builtin_abort(); +} + +__attribute__ ((noinline)) +void +init_mem (char *mem) +{ + unsigned int *p; + int i; + + p = (unsigned int *)mem; + for (i = 0; i < MAX_LEN / sizeof(unsigned int); i++) + p[i] = 0x71727374; +} + +#define MEMSET_CHECK(VAL, SIZE) \ + init_mem (mem1); \ + __builtin_memset (mem1 + 1, 0, (SIZE)); \ + check_mem (mem1, 0, SIZE); \ + init_mem (mem2); \ + __builtin_memset (mem2 + 1, (VAL), (SIZE)); \ + check_mem (mem2, VAL, SIZE); + +char mem1[MAX_LEN + 2]; +char mem2[MAX_LEN + 2]; + +int main(int argc, char **argv) +{ + int lens[] = + { + 256, 257, 258, 259, + 512, 513, 514, 515, + 768, 769, 770, 771, + 1024, 1025, 1026, 1027, + 1280, 1281, 1282, 1283, + -999 + }; + int t; + + /* variable length */ + for (t = 0; lens[t] != -999; t++) + { + MEMSET_CHECK (argc + 0x10, lens[t]); + } + + /* constant length */ + MEMSET_CHECK (argc + 0x10, 0); + MEMSET_CHECK (argc + 0x10, 1); + MEMSET_CHECK (argc + 0x10, 2); + MEMSET_CHECK (argc + 0x10, 3); + MEMSET_CHECK (argc + 0x10, 256); + MEMSET_CHECK (argc + 0x10, 257); + MEMSET_CHECK (argc + 0x10, 258); + MEMSET_CHECK (argc + 0x10, 259); + MEMSET_CHECK (argc + 0x10, 512); + MEMSET_CHECK (argc + 0x10, 513); + MEMSET_CHECK (argc + 0x10, 514); + MEMSET_CHECK (argc + 0x10, 515); + MEMSET_CHECK (argc + 0x10, 768); + MEMSET_CHECK (argc + 0x10, 769); + MEMSET_CHECK (argc + 0x10, 770); + MEMSET_CHECK (argc + 0x10, 771); + MEMSET_CHECK (argc + 0x10, 1024); + MEMSET_CHECK (argc + 0x10, 1025); + MEMSET_CHECK (argc + 0x10, 1026); + MEMSET_CHECK (argc + 0x10, 1027); + MEMSET_CHECK (argc + 0x10, 1280); + MEMSET_CHECK (argc + 0x10, 1281); + MEMSET_CHECK (argc + 0x10, 1282); + MEMSET_CHECK (argc + 0x10, 1283); + + return 0; +}