1#include <stdio.h>
2#include <stdlib.h>
3
4char b1[23] ="0123456789abcdefghijklm";
5char b2[23] ="mlkjihgfedcba9876543210";
6char b3[23] ="mmmmmmmmmmmmmmmmmmmmmmm";
7char b4[23] ="00000000000000000000000";
8char longbuf[17000000];
9
10static int clcle(unsigned long *_a1, unsigned long *_l1, unsigned long *_a3, unsigned long *_l3, char _pad)
11{
12	register unsigned long a1 asm ("2") = *_a1;
13	register unsigned long l1 asm ("3") = *_l1;
14	register unsigned long a3 asm ("4") = *_a3;
15	register unsigned long l3 asm ("5") = *_l3;
16	register unsigned long pad asm ("6") = _pad;
17	register unsigned long cc asm ("7");
18
19	asm volatile(	"0: clcle 2,4,0(6)\n\t"
20			"jo 0b\n\t"
21			"ipm %0\n\t"
22			"srl %0,28\n\t"
23			:"=d" (cc), "+d" (a1),"+d" (l1), "+d" (a3), "+d" (l3)
24			: "d" (pad)
25			: "memory", "cc");
26	*_a1 = a1;
27	*_a3 = a3;
28	*_l1 = l1;
29	*_l3 = l3;
30
31	return cc;
32}
33
34
35void testrun(void *_a1, unsigned long _l1, void *_a3, unsigned long _l3, char pad)
36{
37	unsigned long a1,a3,l1,l3;
38	int cc;
39
40	a1 = (unsigned long) _a1; l1 = _l1; a3 = (unsigned long) _a3; l3 = _l3;
41	cc = clcle(&a1, &l1,  &a3, &l3, pad);
42	printf("cc: %d, l1: %lu(%lu) l3: %lu(%lu) diff1: %lu diff3: %lu\n",
43                cc, l1, _l1, l3, _l3, a1-(unsigned long) _a1, a3-(unsigned long) _a3);
44}
45
46
47void multiplex(unsigned long l1, unsigned long l3, char pad)
48{
49	testrun(b1, l1, b1, l3, pad);
50	testrun(b1, l1, b2, l3, pad);
51	testrun(b1, l1, b3, l3, pad);
52	testrun(b1, l1, b4, l3, pad);
53	testrun(b2, l1, b2, l3, pad);
54	testrun(b2, l1, b3, l3, pad);
55	testrun(b2, l1, b4, l3, pad);
56	testrun(b3, l1, b3, l3, pad);
57	testrun(b3, l1, b4, l3, pad);
58	testrun(b4, l1, b4, l3, pad);
59}
60
61int main()
62{
63	multiplex(0,0,9);
64	multiplex(1,0,9);
65	multiplex(0,1,9);
66	multiplex(1,1,9);
67	multiplex(5,23,9);
68	multiplex(23,5,9);
69	testrun(longbuf,10000,longbuf,100000,0);
70	testrun(longbuf,10000,longbuf,100000,128);
71	testrun(longbuf,10000,longbuf,100000,255);
72	exit(0);
73}
74
75