1 #include <stdio.h>
2 
3 /* Dummy variable. Needed to work around GCC code generation bugs */
4 volatile long v;
5 
6 #define INSERT_REG_MEM(insn, s1, s2)			\
7 ({							\
8 	unsigned long tmp = s1;				\
9 	int cc;						\
10 	asm volatile(	#insn " %0, %3\n"		\
11 			"ipm %1\n"			\
12 			"srl %1,28\n"			\
13 			: "+d" (tmp), "=d" (cc)		\
14 			: "d" (tmp), "Q" (s2)		\
15 			: "0", "cc");			\
16 	printf(#insn " %16.16lX <- %16.16lX = %16.16lX\n", s1, s2, tmp); \
17 })
18 
19 #define INSERT_REG_IMM(insn, s1, s2)			\
20 ({							\
21 	register unsigned long tmp asm("2") = s1;	\
22 	int cc;						\
23 	asm volatile(	insn(2,s2)			\
24 			"ipm %1\n"			\
25 			"srl %1,28\n"			\
26 			: "+d" (tmp), "=d" (cc)		\
27 			: "d" (tmp)			\
28 			: "cc");			\
29 	v = tmp; /* work around GCC code gen bug */     \
30 	printf(#insn " %16.16lX <- %16.16lX = %16.16lX\n", s1, (unsigned long) 0x##s2, v); \
31 })
32 
33 
34 #define memsweep(i, s2)					\
35 ({							\
36 	INSERT_REG_MEM(i, 0ul, s2);			\
37 	INSERT_REG_MEM(i, 1ul, s2);			\
38 	INSERT_REG_MEM(i, 0xfffful, s2);		\
39 	INSERT_REG_MEM(i, 0x7ffful, s2);		\
40 	INSERT_REG_MEM(i, 0x8000ul, s2);		\
41 	INSERT_REG_MEM(i, 0xfffffffful, s2);		\
42 	INSERT_REG_MEM(i, 0x80000000ul, s2);		\
43 	INSERT_REG_MEM(i, 0x7ffffffful, s2);		\
44 	INSERT_REG_MEM(i, 0xaaaaaaaaaaaaaaaaul, s2);	\
45 	INSERT_REG_MEM(i, 0x8000000000000000ul, s2);	\
46 	INSERT_REG_MEM(i, 0xfffffffffffffffful, s2);	\
47 	INSERT_REG_MEM(i, 0x5555555555555555ul, s2);	\
48 })
49 
50 #define immsweep(i, s2)					\
51 ({							\
52 	INSERT_REG_IMM(i, 0ul, s2);			\
53 	INSERT_REG_IMM(i, 1ul, s2);			\
54 	INSERT_REG_IMM(i, 0xfffful, s2);		\
55 	INSERT_REG_IMM(i, 0x7ffful, s2);		\
56 	INSERT_REG_IMM(i, 0x8000ul, s2);		\
57 	INSERT_REG_IMM(i, 0xfffffffful, s2);		\
58 	INSERT_REG_IMM(i, 0x80000000ul, s2);		\
59 	INSERT_REG_IMM(i, 0x7ffffffful, s2);		\
60 	INSERT_REG_IMM(i, 0xaaaaaaaaaaaaaaaaul, s2);	\
61 	INSERT_REG_IMM(i, 0x8000000000000000ul, s2);	\
62 	INSERT_REG_IMM(i, 0xfffffffffffffffful, s2);	\
63 	INSERT_REG_IMM(i, 0x5555555555555555ul, s2);	\
64 })
65 
66 #define INSERT_ICY(s1, s2)			       		\
67 ({								\
68 	register unsigned long tmp asm("1") = s1;		\
69 	register unsigned long *addr asm("2") = &s2;		\
70 	int cc;							\
71 	asm volatile(	ICY(1,0,2,000,00)			\
72 			"ipm %1\n"				\
73 			"srl %1,28\n"				\
74 			: "+d" (tmp), "=d" (cc)			\
75 			: "d" (tmp), "Q" (s2), "d" (addr)	\
76 			: "cc");				\
77 	printf("icy %16.16lX <- %16.16lX = %16.16lX\n", s1, s2, tmp); \
78 })
79 
80 #define icysweep(s2)				\
81 ({						\
82 	INSERT_ICY(0ul, s2);			\
83 	INSERT_ICY(1ul, s2);			\
84 	INSERT_ICY(0xfffful, s2);		\
85 	INSERT_ICY(0x7ffful, s2);		\
86 	INSERT_ICY(0x8000ul, s2);		\
87 	INSERT_ICY(0xfffffffful, s2);		\
88 	INSERT_ICY(0x80000000ul, s2);		\
89 	INSERT_ICY(0x7ffffffful, s2);		\
90 	INSERT_ICY(0xaaaaaaaaaaaaaaaaul, s2);	\
91 	INSERT_ICY(0x8000000000000000ul, s2);	\
92 	INSERT_ICY(0xfffffffffffffffful, s2);	\
93 	INSERT_ICY(0x5555555555555555ul, s2);	\
94 })
95