1 /* Test memcmp/strncmp builtin expansion for compilation and proper execution. */
3 /* { dg-options "-O2" } */
4 /* { dg-require-effective-target ptr32plus } */
11 int lib_memcmp(const void *a
, const void *b
, size_t n
) asm("memcmp");
12 int lib_strncmp(const char *a
, const char *b
, size_t n
) asm("strncmp");
19 static void test_driver_memcmp (void (test_memcmp
)(const char *, const char *, int),
20 void (test_strncmp
)(const char *, const char *, int),
23 char buf1
[MAX_SZ
*2+10],buf2
[MAX_SZ
*2+10];
24 size_t test_sz
= (sz
<MAX_SZ
)?sz
:MAX_SZ
;
25 size_t diff_pos
, zero_pos
;
29 for(i
=0;i
<NRAND
/sz
;i
++) {
31 buf1
[j
] = rand() & 0xff;
35 buf1
[j
] = rand() & 0xff;
36 buf2
[j
] = rand() & 0xff;
39 e
= lib_memcmp(buf1
,buf2
,sz
);
40 (*test_memcmp
)(buf1
,buf2
,e
);
41 e
= lib_strncmp(buf1
,buf2
,sz
);
42 (*test_strncmp
)(buf1
,buf2
,e
);
44 for(diff_pos
= ((test_sz
>10)?(test_sz
-10):0); diff_pos
< test_sz
+10; diff_pos
++)
45 for(zero_pos
= ((test_sz
>10)?(test_sz
-10):0); zero_pos
< test_sz
+10; zero_pos
++)
47 memset(buf1
, 'A', 2*test_sz
);
48 memset(buf2
, 'A', 2*test_sz
);
52 e
= lib_memcmp(buf1
,buf2
,sz
);
53 (*test_memcmp
)(buf1
,buf2
,e
);
54 (*test_memcmp
)(buf2
,buf1
,-e
);
55 (*test_memcmp
)(buf2
,buf2
,0);
56 e
= lib_strncmp(buf1
,buf2
,sz
);
57 (*test_strncmp
)(buf1
,buf2
,e
);
58 (*test_strncmp
)(buf2
,buf1
,-e
);
59 (*test_strncmp
)(buf2
,buf2
,0);
60 /* differing length: */
62 e
= lib_memcmp(buf1
,buf2
,sz
);
63 (*test_memcmp
)(buf1
,buf2
,e
);
64 e
= lib_strncmp(buf1
,buf2
,sz
);
65 (*test_strncmp
)(buf1
,buf2
,e
);
66 memset(buf2
+diff_pos
,'B',sizeof(buf2
)-diff_pos
);
68 e
= lib_memcmp(buf1
,buf2
,sz
);
69 (*test_memcmp
)(buf1
,buf2
,e
);
70 (*test_memcmp
)(buf2
,buf1
,-e
);
71 e
= lib_strncmp(buf1
,buf2
,sz
);
72 (*test_strncmp
)(buf1
,buf2
,e
);
73 (*test_strncmp
)(buf2
,buf1
,-e
);
77 #define RUN_TEST(SZ, ALIGN) test_driver_memcmp (test_memcmp_ ## SZ ## _ ## ALIGN, test_strncmp_ ## SZ ## _ ## ALIGN, SZ, ALIGN);
79 #define DEF_TEST(SZ, ALIGN) \
80 static void test_memcmp_ ## SZ ## _ ## ALIGN (const char *str1, const char *str2, int expect) \
82 char three[8192] __attribute__ ((aligned (4096))); \
83 char four[8192] __attribute__ ((aligned (4096))); \
86 for (j = 0; j < 2; j++) \
88 for (i = 0; i < 2; i++) \
90 a = three+i*ALIGN+j*(4096-2*i*ALIGN); \
91 b = four+i*ALIGN+j*(4096-2*i*ALIGN); \
95 if ( r < 0 && !(expect < 0) ) abort(); \
96 if ( r > 0 && !(expect > 0) ) abort(); \
97 if ( r == 0 && !(expect == 0) ) abort(); \
101 static void test_strncmp_ ## SZ ## _ ## ALIGN (const char *str1, const char *str2, int expect) \
103 char three[8192] __attribute__ ((aligned (4096))); \
104 char four[8192] __attribute__ ((aligned (4096))); \
107 for (j = 0; j < 2; j++) \
109 for (i = 0; i < 2; i++) \
111 a = three+i*ALIGN+j*(4096-2*i*ALIGN); \
112 b = four+i*ALIGN+j*(4096-2*i*ALIGN); \
115 r = strncmp(a,b,SZ); \
116 if ( r < 0 && !(expect < 0) ) abort(); \
117 if ( r > 0 && !(expect > 0) ) abort(); \
118 if ( r == 0 && !(expect == 0) ) abort(); \
395 main(int argc
, char **argv
)