Home | History | Annotate | Download | only in arm
      1 
      2 #include <stdio.h>
      3 
      4 __attribute__((noinline)) float s_to_f32_imm1(int x)
      5 {
      6     float y;
      7     __asm__ ("vcvt.f32.s32 %0, %1, #1" : "=w"(y) : "0"(x));
      8     return y;
      9 }
     10 
     11 __attribute__((noinline)) float s_to_f32_imm32(int x)
     12 {
     13     float y;
     14     __asm__ ("vcvt.f32.s32 %0, %1, #32" : "=w"(y) : "0"(x));
     15     return y;
     16 }
     17 
     18 void try_s_to_f32 ( int x )
     19 {
     20   float f32 = s_to_f32_imm32(x);
     21   printf("s_to_f32_imm32:  %11d  ->  %18.14e\n", x, (double)f32);
     22   f32 = s_to_f32_imm1(x);
     23   printf("s_to_f32_imm1:   %11d  ->  %18.14e\n", x, (double)f32);
     24 }
     25 
     26 
     27 
     28 __attribute__((noinline)) float u_to_f32_imm1(int x)
     29 {
     30     float y;
     31     __asm__ ("vcvt.f32.u32 %0, %1, #1" : "=w"(y) : "0"(x));
     32     return y;
     33 }
     34 
     35 __attribute__((noinline)) float u_to_f32_imm32(int x)
     36 {
     37     float y;
     38     __asm__ ("vcvt.f32.u32 %0, %1, #32" : "=w"(y) : "0"(x));
     39     return y;
     40 }
     41 
     42 void try_u_to_f32 ( unsigned int x )
     43 {
     44   float f32 = u_to_f32_imm32(x);
     45   printf("u_to_f32_imm32:  %11u  ->  %18.14e\n", x, (double)f32);
     46   f32 = u_to_f32_imm1(x);
     47   printf("u_to_f32_imm1:   %11u  ->  %18.14e\n", x, (double)f32);
     48 }
     49 
     50 
     51 //__attribute__((noinline)) double s_to_f64_imm1(int x)
     52 //{
     53 //    double y;
     54 //    __asm__ ("vcvt.f64.s32 %P0, %1, #4" : "=w"(y) : "0"((long long)x));
     55 //    return y;
     56 //}
     57 
     58 
     59 
     60 
     61 int main ( void  )
     62 {
     63   int i;
     64   //float f = foo(1);
     65   //__asm__ __volatile__("" : : "r"(f) : "cc","memory");
     66   try_s_to_f32(0);
     67   try_s_to_f32(1);
     68   for (i = 100; i < 200; i++) {
     69      try_s_to_f32(i);
     70   }
     71   try_s_to_f32(0x7FFFFFFE);
     72   try_s_to_f32(0x7FFFFFFF);
     73   try_s_to_f32(0x80000000);
     74   try_s_to_f32(0x80000001);
     75   try_s_to_f32(0xFFFFFFFE);
     76   try_s_to_f32(0xFFFFFFFF);
     77   printf("\n");
     78   try_u_to_f32(0);
     79   try_u_to_f32(1);
     80   for (i = 100; i < 200; i++) {
     81      try_u_to_f32(i);
     82   }
     83   try_u_to_f32(0x7FFFFFFE);
     84   try_u_to_f32(0x7FFFFFFF);
     85   try_u_to_f32(0x80000000);
     86   try_u_to_f32(0x80000001);
     87   try_u_to_f32(0xFFFFFFFE);
     88   try_u_to_f32(0xFFFFFFFF);
     89   return 0;
     90 }
     91