1 /* Funtional setmem test.  */
2 
3 /* { dg-do run } */
4 /* { dg-options "-O3" } */
5 
6 #define MAX_LEN (8 * 1000)
7 
8 __attribute__ ((noinline))
9 int
check_mem(char * mem,int val,int len)10 check_mem (char *mem, int val, int len)
11 {
12   int i;
13 
14   if (mem[0] != 0x71)
15     __builtin_abort();
16   for (i = 1; i <= len; i++)
17     if (mem[i] != val)
18       __builtin_abort();
19   if (mem[len + 1] != 0x71 + (len + 1) % 4)
20     __builtin_abort();
21 }
22 
23 __attribute__ ((noinline))
24 void
init_mem(char * mem)25 init_mem (char *mem)
26 {
27   unsigned int *p;
28   int i;
29 
30   p = (unsigned int *)mem;
31   for (i = 0; i < MAX_LEN / sizeof(unsigned int); i++)
32     p[i] = 0x71727374;
33 }
34 
35 #define MEMSET_CHECK(VAL, SIZE)			\
36   init_mem (mem1);				\
37   __builtin_memset (mem1 + 1, 0, (SIZE));	\
38   check_mem (mem1, 0, SIZE);			\
39   init_mem (mem2);				\
40   __builtin_memset (mem2 + 1, (VAL), (SIZE));	\
41   check_mem (mem2, VAL, SIZE);
42 
43 char mem1[MAX_LEN + 2];
44 char mem2[MAX_LEN + 2];
45 
main(int argc,char ** argv)46 int main(int argc, char **argv)
47 {
48   int lens[] =
49     {
50       256, 257, 258, 259,
51       512, 513, 514, 515,
52       768, 769, 770, 771,
53       1024, 1025, 1026, 1027,
54       1280, 1281, 1282, 1283,
55       -999
56     };
57   int t;
58 
59   /* variable length */
60   for (t = 0; lens[t] != -999; t++)
61     {
62       MEMSET_CHECK (argc + 0x10, lens[t]);
63     }
64 
65   /* constant length */
66   MEMSET_CHECK (argc + 0x10, 0);
67   MEMSET_CHECK (argc + 0x10, 1);
68   MEMSET_CHECK (argc + 0x10, 2);
69   MEMSET_CHECK (argc + 0x10, 3);
70   MEMSET_CHECK (argc + 0x10, 256);
71   MEMSET_CHECK (argc + 0x10, 257);
72   MEMSET_CHECK (argc + 0x10, 258);
73   MEMSET_CHECK (argc + 0x10, 259);
74   MEMSET_CHECK (argc + 0x10, 512);
75   MEMSET_CHECK (argc + 0x10, 513);
76   MEMSET_CHECK (argc + 0x10, 514);
77   MEMSET_CHECK (argc + 0x10, 515);
78   MEMSET_CHECK (argc + 0x10, 768);
79   MEMSET_CHECK (argc + 0x10, 769);
80   MEMSET_CHECK (argc + 0x10, 770);
81   MEMSET_CHECK (argc + 0x10, 771);
82   MEMSET_CHECK (argc + 0x10, 1024);
83   MEMSET_CHECK (argc + 0x10, 1025);
84   MEMSET_CHECK (argc + 0x10, 1026);
85   MEMSET_CHECK (argc + 0x10, 1027);
86   MEMSET_CHECK (argc + 0x10, 1280);
87   MEMSET_CHECK (argc + 0x10, 1281);
88   MEMSET_CHECK (argc + 0x10, 1282);
89   MEMSET_CHECK (argc + 0x10, 1283);
90 
91   return 0;
92 }
93