1 #include "tests/malloc.h"
2 #include "pub_core_basics.h"
6 __attribute__((noinline
))
7 static int my_ffsll ( ULong x
)
10 for (i
= 0; i
< 64; i
++) {
11 if ((x
& 1ULL) == 1ULL)
18 /* Find length of string, assuming it is aligned and shorter than 8
19 characters. Little-endian only. */
20 __attribute__((noinline
))
21 static int aligned_strlen(char *s
)
23 /* This is for 64-bit platforms */
24 assert(sizeof(ULong
) == 8);
25 /* ..and only works for aligned input */
26 assert(((unsigned long)s
& 0x7) == 0);
29 ULong val
= *(ULong
*)s
;
30 /* Subtract one from each byte */
31 ULong val2
= val
- 0x0101010101010101ULL
;
32 /* Find lowest byte whose high bit changed */
34 val2
&= 0x8080808080808080ULL
;
36 return (my_ffsll(val2
) / 8) - 1;
39 __attribute__((noinline
)) void foo ( int x
)
41 __asm__
__volatile__("":::"memory");
45 main(int argc
, char *argv
[])
47 char *buf
= memalign16(5);
54 /* --partial-loads-ok=no: expect addr error (here) */
55 /* --partial-loads-ok=yes: expect no error */
56 if (aligned_strlen(buf
) == 4)
59 /* --partial-loads-ok=no: expect addr error (here) */
60 /* --partial-loads-ok=yes: expect value error (in my_ffsll) */
62 if (aligned_strlen(buf
) == 0)
67 /* Also, we need to check that a completely out-of-range,
68 word-sized load gives an addressing error regardless of the
69 start of --partial-loads-ok=. *And* that the resulting
70 value is completely defined. */
71 RegWord
* words
= malloc(3 * sizeof(RegWord
));
74 /* Should ALWAYS give an addr error. */
77 /* Should NEVER give an error (you might expect a value one, but no.) */
78 if (w
== 0x31415927) {
80 "Elvis is alive and well and living in Milton Keynes.\n");