1 2 /* Can be compiled both as ARM or Thumb using 3 gcc -Wall -g -O0 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -m{arm,thumb} -o vfp vfp.c 4 */ 5 6 #include <stdio.h> 7 #include <string.h> 8 #include <math.h> 9 10 static unsigned int f2u(float x) { 11 union { 12 float f; 13 unsigned int u; 14 } cvt; 15 cvt.f = x; 16 return cvt.u; 17 } 18 19 static unsigned int f2u0(double x) { 20 union { 21 double f; 22 unsigned int u[2]; 23 } cvt; 24 cvt.f = x; 25 return cvt.u[0]; 26 } 27 28 static unsigned int f2u1(double x) { 29 union { 30 double f; 31 unsigned int u[2]; 32 } cvt; 33 cvt.f = x; 34 return cvt.u[1]; 35 } 36 37 /* test macros to generate and output the result of a single instruction */ 38 39 #define TESTINSN_bin_f64(instruction, QD, QM, QMtype, QMval0, QMval1, QN, QNtype, QNval0, QNval1) \ 40 { \ 41 unsigned int out[2] = { 0x55555555, 0x55555555 }; \ 42 unsigned int block[2]; \ 43 block[0] = block[1] = 0x3f800000; \ 44 \ 45 __asm__ volatile( \ 46 "vldr " #QD ", [%5]\n\t" \ 47 "vmov " #QM ", %1, %2 \n\t" \ 48 "vmov " #QN ", %3, %4 \n\t" \ 49 instruction "\n\t" \ 50 "vstmia %0, {" #QD "}\n\t" \ 51 : \ 52 : "r" (&out[0]), "r" (QMval0), "r" (QMval1), "r" (QNval0), "r" (QNval1), "r"(&block[0]) \ 53 : #QD, #QM, #QN, "memory" \ 54 ); \ 55 printf("%-24s :: Qd 0x%08x 0x%08x Qm 0x%08x %08x" \ 56 " Qn 0x%08x %08x\n", \ 57 instruction, out[1], out[0], QMval1, QMval0, QNval1, QNval0); \ 58 } 59 60 #define TESTINSN_bin_f32(instruction, SD, SM, SMtype, SMval, SN, SNtype, SNval) \ 61 { \ 62 unsigned int out[2] = { 0x55555555, 0x55555555 }; \ 63 \ 64 __asm__ volatile( \ 65 "vmov.f32 " #SM ", %1\n\t" \ 66 "vmov.f32 " #SN ", %2\n\t" \ 67 "vmov.f32 " #SD ", %3\n\t" \ 68 instruction "\n\t" \ 69 "vstmia %0, {" #SD "}\n\t" \ 70 : \ 71 : "r" (&out[0]), "r" (SMval), "r" (SNval), "r" (0xaaaaaaaa) \ 72 : #SD, #SM, #SN, "memory" \ 73 ); \ 74 printf("%-24s :: Qd 0x%08x 0x%08x Sm (" #SMtype ")0x%08x" \ 75 " Sn (" #SNtype ")0x%08x\n", \ 76 instruction, out[1], out[0], SMval, SNval); \ 77 } 78 79 int main(int argc, char **argv) 80 { 81 printf("---- VFMA (fp, VFPv4) ----\n"); 82 TESTINSN_bin_f64("vfma.f64 d0, d11, d12", d0, d11, i32, f2u0(-INFINITY), f2u1(-INFINITY), d12, i32, f2u0(NAN), f2u1(NAN)); 83 TESTINSN_bin_f64("vfma.f64 d7, d1, d6", d7, d1, i32, f2u0(INFINITY), f2u1(INFINITY), d6, i32, f2u0(NAN), f2u1(NAN)); 84 TESTINSN_bin_f64("vfma.f64 d0, d5, d2", d0, d5, i32, f2u0(NAN), f2u1(NAN), d2, i32, f2u0(-1.0), f2u1(-1.0)); 85 TESTINSN_bin_f64("vfma.f64 d10, d13, d15", d10, d13, i32, f2u0(NAN), f2u1(NAN), d15, i32, f2u0(0.0), f2u1(0.0)); 86 TESTINSN_bin_f64("vfma.f64 d10, d13, d15", d10, d13, i32, f2u0(NAN), f2u1(NAN), d15, i32, f2u0(NAN), f2u1(NAN)); 87 TESTINSN_bin_f64("vfma.f64 d20, d25, d22", d20, d25, i32, f2u0(23.04), f2u1(23.04), d22, i32, f2u0(-45.5687), f2u1(-45.5687)); 88 TESTINSN_bin_f64("vfma.f64 d23, d24, d25", d23, d24, i32, f2u0(-347856.475), f2u1(-347856.475), d25, i32, f2u0(1346), f2u1(1346)); 89 TESTINSN_bin_f64("vfma.f64 d20, d31, d12", d20, d31, i32, f2u0(48755), f2u1(48755), d12, i32, f2u0(-45786.476), f2u1(-45786.476)); 90 TESTINSN_bin_f64("vfma.f64 d19, d25, d27", d19, d25, i32, f2u0(95867.76), f2u1(95867.76), d27, i32, f2u0(17065), f2u1(17065)); 91 TESTINSN_bin_f64("vfma.f64 d30, d15, d2", d30, d15, i32, f2u0(-45667.24), f2u1(-45667.24), d2, i32, f2u0(-248562.76), f2u1(-248562.76)); 92 TESTINSN_bin_f64("vfma.f64 d23, d24, d5", d23, d24, i32, f2u0(24), f2u1(24), d5, i32, f2u0(1346), f2u1(1346)); 93 TESTINSN_bin_f64("vfma.f64 d10, d11, d2", d10, d11, i32, f2u0(48755), f2u1(48755), d2, i32, f2u0(1089), f2u1(1089)); 94 TESTINSN_bin_f64("vfma.f64 d29, d15, d7", d29, d15, i32, f2u0(214), f2u1(214), d7, i32, f2u0(1752065), f2u1(1752065)); 95 TESTINSN_bin_f64("vfma.f64 d30, d11, d12", d30, d11, i32, f2u0(356047.56), f2u1(356047.56), d12, i32, f2u0(5867.009), f2u1(5867.009)); 96 TESTINSN_bin_f64("vfma.f64 d27, d21, d6", d27, d21, i32, f2u0(34.00046), f2u1(34.00046), d6, i32, f2u0(0.0024575), f2u1(0.0024575)); 97 TESTINSN_bin_f64("vfma.f64 d30, d31, d2", d30, d31, i32, f2u0(2754), f2u1(2754), d2, i32, f2u0(107), f2u1(107)); 98 TESTINSN_bin_f64("vfma.f64 d13, d24, d5", d13, d24, i32, f2u0(874), f2u1(874), d5, i32, f2u0(1384.6), f2u1(1384.6)); 99 TESTINSN_bin_f64("vfma.f64 d10, d11, d2", d10, d11, i32, f2u0(487.587), f2u1(487.587), d2, i32, f2u0(109), f2u1(109)); 100 TESTINSN_bin_f64("vfma.f64 d29, d25, d7", d29, d25, i32, f2u0(-INFINITY), f2u1(-INFINITY), d7, i32, f2u0(1752), f2u1(1752)); 101 TESTINSN_bin_f64("vfma.f64 d0, d11, d12", d0, d11, i32, f2u0(INFINITY), f2u1(INFINITY), d12, i32, f2u0(-5786.47), f2u1(-5786.47)); 102 TESTINSN_bin_f64("vfma.f64 d27, d21, d16", d27, d21, i32, f2u0(456.2489562), f2u1(456.2489562), d16, i32, f2u0(-7.2945676), f2u1(-7.2945676)); 103 TESTINSN_bin_f64("vfma.f64 d0, d5, d2", d0, d5, i32, f2u0(INFINITY), f2u1(INFINITY), d2, i32, f2u0(-INFINITY), f2u1(-INFINITY)); 104 TESTINSN_bin_f64("vfma.f64 d20, d13, d15", d20, d13, i32, f2u0(-INFINITY), f2u1(-INFINITY), d15, i32, f2u0(0.0), f2u1(0.0)); 105 TESTINSN_bin_f64("vfma.f64 d10, d23, d15", d10, d23, i32, f2u0(INFINITY), f2u1(INFINITY), d15, i32, f2u0(0.0), f2u1(0.0)); 106 TESTINSN_bin_f32("vfma.f32 s0, s11, s12", s0, s11, i32, f2u(-INFINITY), s12, i32, f2u(NAN)); 107 TESTINSN_bin_f32("vfma.f32 s7, s1, s6", s7, s1, i32, f2u(INFINITY), s6, i32, f2u(NAN)); 108 TESTINSN_bin_f32("vfma.f32 s0, s5, s2", s0, s5, i32, f2u(NAN), s2, i32, f2u(-1.0)); 109 TESTINSN_bin_f32("vfma.f32 s10, s13, s15", s10, s13, i32, f2u(NAN), s15, i32, f2u(0.0)); 110 TESTINSN_bin_f32("vfma.f32 s10, s13, s15", s10, s13, i32, f2u(NAN), s15, i32, f2u(NAN)); 111 TESTINSN_bin_f32("vfma.f32 s20, s25, s22", s20, s25, i32, f2u(23.04), s22, i32, f2u(-45.5687)); 112 TESTINSN_bin_f32("vfma.f32 s23, s24, s25", s23, s24, i32, f2u(-347856.475), s25, i32, f2u(1346)); 113 TESTINSN_bin_f32("vfma.f32 s20, s31, s12", s20, s31, i32, f2u(48755), s12, i32, f2u(-45786.476)); 114 TESTINSN_bin_f32("vfma.f32 s19, s25, s27", s19, s25, i32, f2u(95867.76), s27, i32, f2u(17065)); 115 TESTINSN_bin_f32("vfma.f32 s30, s15, s2", s30, s15, i32, f2u(-45667.24), s2, i32, f2u(-248562.76)); 116 TESTINSN_bin_f32("vfma.f32 s23, s24, s5", s23, s24, i32, f2u(24), s5, i32, f2u(1346)); 117 TESTINSN_bin_f32("vfma.f32 s10, s11, s2", s10, s11, i32, f2u(48755), s2, i32, f2u(1089)); 118 TESTINSN_bin_f32("vfma.f32 s29, s15, s7", s29, s15, i32, f2u(214), s7, i32, f2u(1752065)); 119 TESTINSN_bin_f32("vfma.f32 s30, s11, s12", s30, s11, i32, f2u(356047.56), s12, i32, f2u(5867.009)); 120 TESTINSN_bin_f32("vfma.f32 s27, s21, s6", s27, s21, i32, f2u(34.00046), s6, i32, f2u(0.0024575)); 121 TESTINSN_bin_f32("vfma.f32 s30, s31, s2", s30, s31, i32, f2u(2754), s2, i32, f2u(107)); 122 TESTINSN_bin_f32("vfma.f32 s13, s24, s5", s13, s24, i32, f2u(874), s5, i32, f2u(1384.6)); 123 TESTINSN_bin_f32("vfma.f32 s10, s11, s2", s10, s11, i32, f2u(487.587), s2, i32, f2u(109)); 124 TESTINSN_bin_f32("vfma.f32 s29, s25, s7", s29, s25, i32, f2u(-INFINITY), s7, i32, f2u(1752)); 125 TESTINSN_bin_f32("vfma.f32 s0, s11, s12", s0, s11, i32, f2u(INFINITY), s12, i32, f2u(-5786.47)); 126 TESTINSN_bin_f32("vfma.f32 s27, s21, s16", s27, s21, i32, f2u(456.2489562), s16, i32, f2u(-7.2945676)); 127 TESTINSN_bin_f32("vfma.f32 s0, s5, s2", s0, s5, i32, f2u(INFINITY), s2, i32, f2u(-INFINITY)); 128 TESTINSN_bin_f32("vfma.f32 s20, s13, s15", s20, s13, i32, f2u(-INFINITY), s15, i32, f2u(0.0)); 129 TESTINSN_bin_f32("vfma.f32 s10, s23, s15", s10, s23, i32, f2u(INFINITY), s15, i32, f2u(0.0)); 130 131 printf("---- VFMS (fp, VFPv4) ----\n"); 132 TESTINSN_bin_f64("vfms.f64 d0, d11, d12", d0, d11, i32, f2u0(-INFINITY), f2u1(-INFINITY), d12, i32, f2u0(NAN), f2u1(NAN)); 133 TESTINSN_bin_f64("vfms.f64 d7, d1, d6", d7, d1, i32, f2u0(INFINITY), f2u1(INFINITY), d6, i32, f2u0(NAN), f2u1(NAN)); 134 TESTINSN_bin_f64("vfms.f64 d0, d5, d2", d0, d5, i32, f2u0(NAN), f2u1(NAN), d2, i32, f2u0(-1.0), f2u1(-1.0)); 135 TESTINSN_bin_f64("vfms.f64 d10, d13, d15", d10, d13, i32, f2u0(NAN), f2u1(NAN), d15, i32, f2u0(0.0), f2u1(0.0)); 136 TESTINSN_bin_f64("vfms.f64 d10, d13, d15", d10, d13, i32, f2u0(NAN), f2u1(NAN), d15, i32, f2u0(NAN), f2u1(NAN)); 137 TESTINSN_bin_f64("vfms.f64 d20, d25, d22", d20, d25, i32, f2u0(23.04), f2u1(23.04), d22, i32, f2u0(-45.5687), f2u1(-45.5687)); 138 TESTINSN_bin_f64("vfms.f64 d23, d24, d25", d23, d24, i32, f2u0(-347856.475), f2u1(-347856.475), d25, i32, f2u0(1346), f2u1(1346)); 139 TESTINSN_bin_f64("vfms.f64 d20, d31, d12", d20, d31, i32, f2u0(48755), f2u1(48755), d12, i32, f2u0(-45786.476), f2u1(-45786.476)); 140 TESTINSN_bin_f64("vfms.f64 d19, d25, d27", d19, d25, i32, f2u0(95867.76), f2u1(95867.76), d27, i32, f2u0(17065), f2u1(17065)); 141 TESTINSN_bin_f64("vfms.f64 d30, d15, d2", d30, d15, i32, f2u0(-45667.24), f2u1(-45667.24), d2, i32, f2u0(-248562.76), f2u1(-248562.76)); 142 TESTINSN_bin_f64("vfms.f64 d23, d24, d5", d23, d24, i32, f2u0(24), f2u1(24), d5, i32, f2u0(1346), f2u1(1346)); 143 TESTINSN_bin_f64("vfms.f64 d10, d11, d2", d10, d11, i32, f2u0(48755), f2u1(48755), d2, i32, f2u0(1089), f2u1(1089)); 144 TESTINSN_bin_f64("vfms.f64 d29, d15, d7", d29, d15, i32, f2u0(214), f2u1(214), d7, i32, f2u0(1752065), f2u1(1752065)); 145 TESTINSN_bin_f64("vfms.f64 d30, d11, d12", d30, d11, i32, f2u0(356047.56), f2u1(356047.56), d12, i32, f2u0(5867.009), f2u1(5867.009)); 146 TESTINSN_bin_f64("vfms.f64 d27, d21, d6", d27, d21, i32, f2u0(34.00046), f2u1(34.00046), d6, i32, f2u0(0.0024575), f2u1(0.0024575)); 147 TESTINSN_bin_f64("vfms.f64 d30, d31, d2", d30, d31, i32, f2u0(2754), f2u1(2754), d2, i32, f2u0(107), f2u1(107)); 148 TESTINSN_bin_f64("vfms.f64 d13, d24, d5", d13, d24, i32, f2u0(874), f2u1(874), d5, i32, f2u0(1384.6), f2u1(1384.6)); 149 TESTINSN_bin_f64("vfms.f64 d10, d11, d2", d10, d11, i32, f2u0(487.587), f2u1(487.587), d2, i32, f2u0(109), f2u1(109)); 150 TESTINSN_bin_f64("vfms.f64 d29, d25, d7", d29, d25, i32, f2u0(-INFINITY), f2u1(-INFINITY), d7, i32, f2u0(1752), f2u1(1752)); 151 TESTINSN_bin_f64("vfms.f64 d0, d11, d12", d0, d11, i32, f2u0(INFINITY), f2u1(INFINITY), d12, i32, f2u0(-5786.47), f2u1(-5786.47)); 152 TESTINSN_bin_f64("vfms.f64 d27, d21, d16", d27, d21, i32, f2u0(456.2489562), f2u1(456.2489562), d16, i32, f2u0(-7.2945676), f2u1(-7.2945676)); 153 TESTINSN_bin_f64("vfms.f64 d0, d5, d2", d0, d5, i32, f2u0(INFINITY), f2u1(INFINITY), d2, i32, f2u0(-INFINITY), f2u1(-INFINITY)); 154 TESTINSN_bin_f64("vfms.f64 d20, d13, d15", d20, d13, i32, f2u0(-INFINITY), f2u1(-INFINITY), d15, i32, f2u0(0.0), f2u1(0.0)); 155 TESTINSN_bin_f64("vfms.f64 d10, d23, d15", d10, d23, i32, f2u0(INFINITY), f2u1(INFINITY), d15, i32, f2u0(0.0), f2u1(0.0)); 156 TESTINSN_bin_f32("vfms.f32 s0, s11, s12", s0, s11, i32, f2u(-INFINITY), s12, i32, f2u(NAN)); 157 TESTINSN_bin_f32("vfms.f32 s7, s1, s6", s7, s1, i32, f2u(INFINITY), s6, i32, f2u(NAN)); 158 TESTINSN_bin_f32("vfms.f32 s0, s5, s2", s0, s5, i32, f2u(NAN), s2, i32, f2u(-1.0)); 159 TESTINSN_bin_f32("vfms.f32 s10, s13, s15", s10, s13, i32, f2u(NAN), s15, i32, f2u(0.0)); 160 TESTINSN_bin_f32("vfms.f32 s10, s13, s15", s10, s13, i32, f2u(NAN), s15, i32, f2u(NAN)); 161 TESTINSN_bin_f32("vfms.f32 s20, s25, s22", s20, s25, i32, f2u(23.04), s22, i32, f2u(-45.5687)); 162 TESTINSN_bin_f32("vfms.f32 s23, s24, s25", s23, s24, i32, f2u(-347856.475), s25, i32, f2u(1346)); 163 TESTINSN_bin_f32("vfms.f32 s20, s31, s12", s20, s31, i32, f2u(48755), s12, i32, f2u(-45786.476)); 164 TESTINSN_bin_f32("vfms.f32 s19, s25, s27", s19, s25, i32, f2u(95867.76), s27, i32, f2u(17065)); 165 TESTINSN_bin_f32("vfms.f32 s30, s15, s2", s30, s15, i32, f2u(-45667.24), s2, i32, f2u(-248562.76)); 166 TESTINSN_bin_f32("vfms.f32 s23, s24, s5", s23, s24, i32, f2u(24), s5, i32, f2u(1346)); 167 TESTINSN_bin_f32("vfms.f32 s10, s11, s2", s10, s11, i32, f2u(48755), s2, i32, f2u(1089)); 168 TESTINSN_bin_f32("vfms.f32 s29, s15, s7", s29, s15, i32, f2u(214), s7, i32, f2u(1752065)); 169 TESTINSN_bin_f32("vfms.f32 s30, s11, s12", s30, s11, i32, f2u(356047.56), s12, i32, f2u(5867.009)); 170 TESTINSN_bin_f32("vfms.f32 s27, s21, s6", s27, s21, i32, f2u(34.00046), s6, i32, f2u(0.0024575)); 171 TESTINSN_bin_f32("vfms.f32 s30, s31, s2", s30, s31, i32, f2u(2754), s2, i32, f2u(107)); 172 TESTINSN_bin_f32("vfms.f32 s13, s24, s5", s13, s24, i32, f2u(874), s5, i32, f2u(1384.6)); 173 TESTINSN_bin_f32("vfms.f32 s10, s11, s2", s10, s11, i32, f2u(487.587), s2, i32, f2u(109)); 174 TESTINSN_bin_f32("vfms.f32 s29, s25, s7", s29, s25, i32, f2u(-INFINITY), s7, i32, f2u(1752)); 175 TESTINSN_bin_f32("vfms.f32 s0, s11, s12", s0, s11, i32, f2u(INFINITY), s12, i32, f2u(-5786.47)); 176 TESTINSN_bin_f32("vfms.f32 s27, s21, s16", s27, s21, i32, f2u(456.2489562), s16, i32, f2u(-7.2945676)); 177 TESTINSN_bin_f32("vfms.f32 s0, s5, s2", s0, s5, i32, f2u(INFINITY), s2, i32, f2u(-INFINITY)); 178 TESTINSN_bin_f32("vfms.f32 s20, s13, s15", s20, s13, i32, f2u(-INFINITY), s15, i32, f2u(0.0)); 179 TESTINSN_bin_f32("vfms.f32 s10, s23, s15", s10, s23, i32, f2u(INFINITY), s15, i32, f2u(0.0)); 180 181 return 0; 182 } 183