more cases added
[libfirm] / ir / be / test / asm_test.c
1 #include <stdio.h>
2
3 #ifdef __i386__
4 static inline unsigned char inb(const unsigned short port)
5 {
6     unsigned char val;
7
8     __asm__ __volatile__ ("inb  %w1, %0" : "=a"(val) : "dN"(port));
9
10     return val;
11 }
12
13 static inline void outb(const unsigned short port, const unsigned char val)
14 {
15         int k = val; /* just here to test the b modifier in %b0 */
16     __asm__ __volatile__ ("outb %b0, %1" : : "a"(k), "dN"(port));
17 }
18
19 static void sincostest(double arg)
20 {
21         double cos, sin;
22
23         __asm__ ("fsincos" : "=t"(cos), "=u"(sin) : "0" (arg));
24         printf("Arg: %f Sin: %f Cos: %f\n", arg, sin, cos);
25 }
26
27 static inline int mov(int val)
28 {
29         int res;
30
31         __asm__ ("movl %1, %0" : "=r"(res) : "ri" (val));
32
33         return res;
34 }
35
36 static inline unsigned short swap16(unsigned short x)
37 {
38         __asm__("xchgb %b0, %h0 /* in: %1 out: %0 */" : "=q" (x) : "0" (x));
39         return x;
40 }
41
42 static inline unsigned int swap32(unsigned int x)
43 {
44         __asm__("bswap %0 /* %1 */" : "=r" (x) : "0" (x));
45         return x;
46 }
47
48 int main()
49 {
50         //sincostest(0.5);
51         /*outb(123, 42);
52         outb(12345, 42);*/
53
54         printf("Swap16: %d Swap32: %d\n", swap16(12), swap32(123551235));
55
56         return mov(0) /*+ inb(12345) + inb(123)*/;
57 }
58
59 #else
60
61 int main()
62 {
63         printf("Warning: asmtest only work on x86\n");
64         return 0;
65 }
66
67 #endif