1 #include <stdio.h> 2 #include <math.h> 3 #include "rounding_mode.h" 4 #include "macro_fpu.h" 5 6 #if defined(__mips_hard_float) 7 int arithmeticOperations(flt_art_op_t op) 8 { 9 double fd_d = 0; 10 float fd_f = 0; 11 int i = 0; 12 int fcsr = 0; 13 round_mode_t rm; 14 for (rm = TO_NEAREST; rm <= TO_MINUS_INFINITY; rm ++) { 15 set_rounding_mode(rm); 16 printf("roundig mode: %s\n", round_mode_name[rm]); 17 for (i = 0; i < MAX_ARR; i++) { 18 switch(op) { 19 case ABSS: 20 UNOPff("abs.s"); 21 printf("%s %f %f\n", flt_art_op_names[op], fd_f, fs_f[i]); 22 break; 23 case ABSD: 24 UNOPdd("abs.d"); 25 printf("%s %lf %lf\n", flt_art_op_names[op], fd_d, fs_d[i]); 26 break; 27 case ADDS: 28 BINOPf("add.s"); 29 printf("%s %f %f %f\n", 30 flt_art_op_names[op], fd_f, fs_f[i], ft_f[i]); 31 break; 32 case ADDD: 33 BINOPd("add.d"); 34 printf("%s %lf %lf %lf\n", 35 flt_art_op_names[op], fd_d, fs_d[i], ft_d[i]); 36 break; 37 case DIVS: 38 BINOPf("div.s"); 39 printf("%s %f %f %f\n", 40 flt_art_op_names[op], roundf(fd_f), fs_f[i], ft_f[i]); 41 break; 42 case DIVD: 43 BINOPd("div.d"); 44 printf("%s %lf %lf %lf\n", 45 flt_art_op_names[op], round(fd_d), fs_d[i], ft_d[i]); 46 break; 47 case MULS: 48 BINOPf("mul.s"); 49 printf("%s %f %f %f\n", 50 flt_art_op_names[op], roundf(fd_f), fs_f[i], ft_f[i]); 51 break; 52 case MULD: 53 BINOPd("mul.d"); 54 printf("%s %lf %lf %lf\n", 55 flt_art_op_names[op], round(fd_d), fs_d[i], ft_d[i]); 56 break; 57 case NEGS: 58 UNOPff("neg.s"); 59 printf("%s %f %f\n", flt_art_op_names[op], fd_f, fs_f[i]); 60 break; 61 case NEGD: 62 UNOPdd("neg.d"); 63 printf("%s %lf %lf\n", flt_art_op_names[op], fd_d, fs_d[i]); 64 break; 65 case SQRTS: 66 UNOPff("sqrt.s"); 67 printf("%s %f %f\n", 68 flt_art_op_names[op], roundf(fd_f), fs_f[i]); 69 break; 70 case SQRTD: 71 UNOPdd("sqrt.d"); 72 printf("%s %lf %lf\n", 73 flt_art_op_names[op], round(fd_d), fs_d[i]); 74 break; 75 case SUBS: 76 BINOPf("sub.s"); 77 printf("%s %f %f %f\n", 78 flt_art_op_names[op], fd_f, fs_f[i], ft_f[i]); 79 break; 80 case SUBD: 81 BINOPd("sub.d"); 82 printf("%s %lf %lf %lf\n", 83 flt_art_op_names[op], fd_d, fs_d[i], ft_d[i]); 84 break; 85 case RECIPS: 86 UNOPff("recip.s"); 87 printf("%s %f %f\n", 88 flt_art_op_names[op], roundf(fd_f), fs_f[i]); 89 break; 90 case RECIPD: 91 UNOPdd("recip.d"); 92 printf("%s %lf %lf\n", 93 flt_art_op_names[op], round(fd_d), fs_d[i]); 94 break; 95 case RSQRTS: 96 if (fs_f[i] >= 0) { 97 UNOPff("rsqrt.s"); 98 printf("%s %f %f\n", 99 flt_art_op_names[op], roundf(fd_f), fs_f[i]); 100 } 101 break; 102 case RSQRTD: 103 if (fs_d[i] >= 0) { 104 UNOPdd("rsqrt.d"); 105 printf("%s %lf %lf\n", 106 flt_art_op_names[op], round(fd_d), fs_d[i]); 107 } 108 break; 109 case MSUBS: 110 TRIOPf("msub.s"); 111 printf("%s %f %f %f %f\n",flt_art_op_names[op], roundf(fd_f), 112 fr_f[i], fs_f[i], ft_f[i]); 113 break; 114 case MSUBD: 115 TRIOPd("msub.d"); 116 printf("%s %lf %lf %lf %lf\n", flt_art_op_names[op], round(fd_d), 117 fr_d[i], fs_d[i], ft_d[i]); 118 break; 119 case MADDS: 120 TRIOPf("madd.s"); 121 printf("%s %f %f %f %f\n", flt_art_op_names[op], roundf(fd_f), 122 fr_f[i], fs_f[i], ft_f[i]); 123 break; 124 case MADDD: 125 TRIOPd("madd.d"); 126 printf("%s %lf %lf %lf %lf\n", flt_art_op_names[op], round(fd_d), 127 fr_d[i], fs_d[i], ft_d[i]); 128 break; 129 case NMADDS: 130 TRIOPf("nmadd.s"); 131 printf("%s %f %f %f %f\n", flt_art_op_names[op], roundf(fd_f), 132 fr_f[i], fs_f[i], ft_f[i]); 133 break; 134 case NMADDD: 135 TRIOPd("nmadd.d"); 136 printf("%s %lf %lf %lf %lf\n", flt_art_op_names[op], round(fd_d), 137 fr_d[i], fs_d[i], ft_d[i]); 138 break; 139 case NMSUBS: 140 TRIOPf("nmsub.s"); 141 printf("%s %f %f %f %f\n", flt_art_op_names[op], roundf(fd_f), 142 fr_f[i], fs_f[i], ft_f[i]); 143 break; 144 case NMSUBD: 145 TRIOPd("nmsub.d"); 146 printf("%s 0x%lf %lf %lf %lf\n", flt_art_op_names[op], 147 round(fd_d), fr_d[i], fs_d[i], 148 ft_d[i]); 149 break; 150 default: 151 printf("error\n"); 152 break; 153 } 154 } 155 } 156 return 0; 157 } 158 #endif 159 160 int main() 161 { 162 #if defined(__mips_hard_float) 163 flt_art_op_t op; 164 165 printf("-------------------------- %s --------------------------\n", 166 "test FPU Arithmetic Operations"); 167 for (op = ABSS; op <= NMSUBD; op++) { 168 arithmeticOperations(op); 169 } 170 #endif 171 return 0; 172 } 173