1 #include "tests/malloc.h"
5 typedef unsigned long long int ULong
;
6 typedef unsigned long int UWord
;
8 __attribute__((noinline
))
9 static int my_ffsll ( ULong x
)
12 for (i
= 0; i
< 64; i
++) {
13 if ((x
& 1ULL) == 1ULL)
20 /* Find length of string, assuming it is aligned and shorter than 8
21 characters. Little-endian only. */
22 __attribute__((noinline
))
23 static int aligned_strlen(char *s
)
25 /* This is for 64-bit platforms */
26 assert(sizeof(ULong
) == 8);
27 /* ..and only works for aligned input */
28 assert(((unsigned long)s
& 0x7) == 0);
31 ULong val
= *(ULong
*)s
;
32 /* Subtract one from each byte */
33 ULong val2
= val
- 0x0101010101010101ULL
;
34 /* Find lowest byte whose high bit changed */
36 val2
&= 0x8080808080808080ULL
;
38 return (my_ffsll(val2
) / 8) - 1;
41 __attribute__((noinline
)) void foo ( int x
)
43 __asm__
__volatile__("":::"memory");
47 main(int argc
, char *argv
[])
49 char *buf
= memalign16(5);
56 /* --partial-loads-ok=no: expect addr error (here) */
57 /* --partial-loads-ok=yes: expect no error */
58 if (aligned_strlen(buf
) == 4)
61 /* --partial-loads-ok=no: expect addr error (here) */
62 /* --partial-loads-ok=yes: expect value error (in my_ffsll) */
64 if (aligned_strlen(buf
) == 0)
69 /* Also, we need to check that a completely out-of-range,
70 word-sized load gives an addressing error regardless of the
71 start of --partial-loads-ok=. *And* that the resulting
72 value is completely defined. */
73 UWord
* words
= malloc(3 * sizeof(UWord
));
76 /* Should ALWAYS give an addr error. */
79 /* Should NEVER give an error (you might expect a value one, but no.) */
80 if (w
== 0x31415927) {
82 "Elvis is alive and well and living in Milton Keynes.\n");