1#include <limits.h>
2#include <stdio.h>
3
4int lpr(int org, int *new)
5{
6	int _new, cc;
7	asm volatile(	"lpr %0,%2\n\t"
8			"ipm %1\n\t"
9			"srl %1,28\n\t"
10			: "=d" (_new), "=d" (cc)
11			: "d" (org)
12			: "cc");
13	*new = _new;
14	return cc;
15}
16
17int lpgr(unsigned long org, unsigned long *new)
18{
19	unsigned long _new;
20        int cc;
21	asm volatile(	"lpgr %0,%2\n\t"
22			"ipm %1\n\t"
23			"srl %1,28\n\t"
24			: "=d" (_new), "=d" (cc)
25			: "d" (org)
26			: "cc");
27	*new = _new;
28	return cc;
29}
30
31int lpgfr(unsigned long org, unsigned long *new)
32{
33	unsigned long _new;
34        int cc;
35	asm volatile(	"lpgfr %0,%2\n\t"
36			"ipm %1\n\t"
37			"srl %1,28\n\t"
38			: "=d" (_new), "=d" (cc)
39			: "d" (org)
40			: "cc");
41	*new = _new;
42	return cc;
43}
44
45
46void t32(int value)
47{
48	int n,cc;
49
50	cc = lpr(value, &n);
51
52	printf("new: %d cc: %d\n", n, cc);
53}
54
55void t64(unsigned long value)
56{
57	int cc;
58        unsigned long n;
59
60	cc = lpgr(value, &n);
61
62	printf("new: %ld cc: %d\n", n, cc);
63}
64
65void t3264(unsigned long value)
66{
67	int cc;
68        unsigned long n;
69
70	cc = lpgfr(value, &n);
71
72	printf("new: %ld cc: %d\n", n, cc);
73}
74
75
76
77int main()
78{
79	printf("lpr\n");
80	t32(0); t32(1); t32(-1);
81	t32(INT_MAX); t32(INT_MIN); t32(UINT_MAX);
82
83	printf("lpgr\n");
84	t64(0); t64(1); t64(-1);
85	t64(INT_MAX); t64(INT_MIN); t64(UINT_MAX);
86	t64(LONG_MAX); t64(LONG_MIN); t64(ULONG_MAX);
87
88	printf("lpgfr\n");
89	t3264(0); t3264(1); t64(-1);
90	t3264(INT_MAX); t3264(INT_MIN); t3264(UINT_MAX);
91	t3264(LONG_MAX); t3264(LONG_MIN); t3264(ULONG_MAX);
92
93	return 0;
94}
95
96