convert bitfield initializer tarvals before using them
[libfirm] / ir / be / test / asm_test.c
index 5d2df8c..a25e781 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <assert.h>
 
 #ifdef __i386__
 static inline unsigned char inb(const unsigned short port)
@@ -24,11 +25,11 @@ static void sincostest(double arg)
        printf("Arg: %f Sin: %f Cos: %f\n", arg, sin, cos);
 }
 
-static inline int mov(int val)
+static inline int mov_noeax(int val)
 {
        int res;
 
-       __asm__ ("movl %1, %0" : "=r"(res) : "ri" (val));
+       __asm__ ("movl %1, %0" : "=r"(res) : "ri" (val) : "eax");
 
        return res;
 }
@@ -45,6 +46,16 @@ static inline unsigned int swap32(unsigned int x)
        return x;
 }
 
+void inc(int *v)
+{
+       __asm__("incl %0" : "+rm" (*v) : : "cc");
+}
+
+void inc2(int *v)
+{
+       __asm__("incl %0" : "+m" (*v) : : "cc");
+}
+
 #if 1
 typedef struct kernel_fd_set {
        int bla;
@@ -54,17 +65,18 @@ typedef struct kernel_fd_set {
 typedef int kernel_fd_set;
 #endif
 
-void fs_set(int fd, kernel_fd_set* set) {
-       __asm__("btsl %1,%0" : "=m" (*(set+2)) : "r" (fd));
+void fd_set(int fd, kernel_fd_set* set) {
+       __asm__("btsl %1,%0" : "=m" (*(set)) : "r" (fd) : "cc");
 }
 
-void fd_isset(int fd, kernel_fd_set *set) {
+int fd_isset(int fd, kernel_fd_set *set) {
        unsigned char result;
 
        __asm__ __volatile__("btl %1,%2\n"
                          "\tsetb %0"
                        : "=q" (result)
-                       : "r" (fd),  "m" (*set));
+                       : "r" (fd),  "m" (*set)
+                       : "cc");
        return result;
 }
 
@@ -77,13 +89,19 @@ int justcompile(void)
 
 int main()
 {
-       //sincostest(0.5);
-       /*outb(123, 42);
-       outb(12345, 42);*/
+       kernel_fd_set s;
+       int k;
+
+       fd_set(20, &s);
+       assert(fd_isset(20, &s));
 
-       printf("Swap16: %d Swap32: %d\n", swap16(12), swap32(123551235));
+       printf("Swap16(0xAABB): %X Swap32(0xAABBCCDD): %X\n",
+              swap16(0xAABB), swap32(0xAABBCCDD));
+       k = 41;
+       inc(&k);
+       printf("mov(inc(41)): %d\n", mov_noeax(k));
 
-       return mov(0) /*+ inb(12345) + inb(123)*/;
+       return mov_noeax(0);
 }
 
 #else