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