Use symbolic names instead of magic values for the position parameter of get_irn_n().
[libfirm] / ir / be / test / ll.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 typedef long long int ll_t;
5 typedef unsigned long long int ull_t;
6
7 #ifdef __GNUC__
8 ll_t mul_ll(ll_t a, ll_t b) __attribute__((noinline));
9 ll_t shl_ll(ll_t a, ll_t b) __attribute__((noinline));
10 ll_t shr_ll(ll_t a, ll_t b) __attribute__((noinline));
11 ll_t add_ll(ll_t a, ll_t b) __attribute__((noinline));
12 ll_t sub_ll(ll_t a, ll_t b) __attribute__((noinline));
13 ll_t div_ll(ll_t a, ll_t b) __attribute__((noinline));
14 ll_t mod_ll(ll_t a, ll_t b) __attribute__((noinline));
15 ll_t divmod_ll(ll_t a, ll_t b) __attribute__((noinline));
16 ll_t abs_ll(ll_t a) __attribute__((noinline));
17 ll_t neg_ll(ll_t a) __attribute__((noinline));
18
19 ull_t mul_ull(ull_t a, ull_t b) __attribute__((noinline));
20 ull_t shl_ull(ull_t a, ull_t b) __attribute__((noinline));
21 ull_t shr_ull(ull_t a, ull_t b) __attribute__((noinline));
22 ull_t add_ull(ull_t a, ull_t b) __attribute__((noinline));
23 ull_t sub_ull(ull_t a, ull_t b) __attribute__((noinline));
24 ull_t div_ull(ull_t a, ull_t b) __attribute__((noinline));
25 ull_t mod_ull(ull_t a, ull_t b) __attribute__((noinline));
26 ull_t divmod_ull(ull_t a, ull_t b) __attribute__((noinline));
27 ull_t neg_ull(ull_t a) __attribute__((noinline));
28 #endif
29
30 ll_t mul_ll(ll_t a, ll_t b) {
31         return a * b;
32 }
33
34 ll_t shl_ll(ll_t a, ll_t b) {
35         return a << b;
36 }
37
38 ll_t shr_ll(ll_t a, ll_t b) {
39         return a >> b;
40 }
41
42 ll_t add_ll(ll_t a, ll_t b) {
43         return a + b;
44 }
45
46 ll_t sub_ll(ll_t a, ll_t b) {
47         return a - b;
48 }
49
50 ll_t div_ll(ll_t a, ll_t b) {
51         return a / b;
52 }
53
54 ll_t mod_ll(ll_t a, ll_t b) {
55         return a % b;
56 }
57
58 ll_t divmod_ll(ll_t a, ll_t b) {
59         return (a / b) + (a % b);
60 }
61
62 ll_t neg_ll(ll_t a) {
63         return -a;
64 }
65
66 ll_t abs_ll(ll_t a) {
67         return a < 0 ? -a : a;
68 }
69
70 double conv_ll_d(ll_t a) {
71         return (double)a;
72 }
73
74 ll_t conv_d_ll(double a) {
75         return (ll_t)a;
76 }
77
78 /* unsigned */
79
80 ull_t mul_ull(ull_t a, ull_t b) {
81         return a * b;
82 }
83
84 ull_t shl_ull(ull_t a, ull_t b) {
85         return a << b;
86 }
87
88 ull_t shr_ull(ull_t a, ull_t b) {
89         return a >> b;
90 }
91
92 ull_t add_ull(ull_t a, ull_t b) {
93         return a + b;
94 }
95
96 ull_t sub_ull(ull_t a, ull_t b) {
97         return a - b;
98 }
99
100 ull_t div_ull(ull_t a, ull_t b) {
101         return a / b;
102 }
103
104 ull_t mod_ull(ull_t a, ull_t b) {
105         return a % b;
106 }
107
108 ull_t divmod_ull(ull_t a, ull_t b) {
109         return (a / b) + (a % b);
110 }
111
112 ull_t neg_ull(ull_t a) {
113         return -a;
114 }
115
116 #if 0
117 double conv_ull_d(ull_t a) {
118         return (double)a;
119 }
120
121 ull_t conv_d_ull(double a) {
122         return (ull_t)a;
123 }
124 #endif
125
126 int main(void) {
127         ll_t a = 0xff;
128         ll_t b = 0x123456789LL;
129         ll_t c = 0x8001023000002460LL;
130         double d = (double)c;
131
132         ull_t ua = 0xff;
133         ull_t ub = 0x123456789ULL;
134         ull_t uc = 0x8001023000002460ULL;
135
136         printf("%lld * %lld  = %lld\n", a, b, mul_ll(a, b));
137         printf("%lld + %lld  = %lld\n", a, b, add_ll(a, b));
138         printf("%lld - %lld  = %lld\n", a, b, sub_ll(a, b));
139         printf("%lld / %lld  = %lld\n", b, a, div_ll(b, a));
140         printf("%lld %% %lld  = %lld\n", b, a, mod_ll(b, a));
141         printf("%lld / + %% %lld  = %lld\n", b, a, divmod_ll(b, a));
142         printf("%lld << %d = %lld\n", a, 2, shl_ll(a, 2));
143         printf("%lld << %d = %lld\n", a, 33, shl_ll(a, 33));
144         printf("%lld >> %d = %lld\n", a, 2, shr_ll(a, 2));
145         printf("%lld >> %d = %lld\n", c, 33, shr_ll(c, 33));
146         printf("abs(%lld)    = %lld\n", c, abs_ll(c));
147         printf("neg(%lld)    = %lld\n", b, neg_ll(b));
148         printf("conv(%lld)   = %lf\n",  c, conv_ll_d(c));
149         printf("conv(%lf)    = %lld\n", d, conv_d_ll(d));
150
151         printf("%llu * %llu  = %llu\n", ua, ub, mul_ull(ua, ub));
152         printf("%llu + %llu  = %llu\n", ua, ub, add_ull(ua, ub));
153         printf("%llu - %llu  = %llu\n", ua, ub, sub_ull(ua, ub));
154         printf("%llu / %llu  = %llu\n", ub, ua, div_ull(ub, ua));
155         printf("%llu %% %llu  = %llu\n", ub, ua, mod_ull(ub, ua));
156         printf("%llu / + %% %llu  = %llu\n", ub, ua, divmod_ull(ub, ua));
157         printf("%llu << %d = %llu\n", ua, 2, shl_ull(ua, 2));
158         printf("%llu << %d = %llu\n", ua, 33, shl_ull(ua, 33));
159         printf("%llu >> %d = %llu\n", ua, 2, shr_ull(ua, 2));
160         printf("%llu >> %d = %llu\n", uc, 33, shr_ll(uc, 33));
161         printf("neg(%llu)    = %llu\n", ub, neg_ull(ub));
162 #if 0
163         printf("conv(%llu)   = %lf\n",  uc, conv_ull_d(uc));
164         printf("conv(%lf)    = %llu\n", d, conv_d_ull(d));
165 #endif
166         return 0;
167 }