Home | History | Annotate | Download | only in mips32
      1 #include <stdio.h>
      2 
      3 typedef enum {
      4    ABSS=0, ABSD,
      5    ADDS, ADDD,
      6    DIVS, DIVD,
      7    MULS, MULD,
      8    NEGS, NEGD,
      9    SQRTS, SQRTD,
     10    SUBS, SUBD,
     11    RECIPS, RECIPD,
     12    RSQRTS, RSQRTD
     13 } flt_art_op_t;
     14 
     15 const char *flt_art_op_names[] = {
     16    "abs.s", "abs.d",
     17    "add.s", "add.d",
     18    "div.s", "div.d",
     19    "mul.s", "mul.d",
     20    "neg.s", "neg.d",
     21    "sqrt.s", "sqrt.d",
     22    "sub.s", "sub.d",
     23    "recip.s", "recip.d",
     24    "rsqrt.s", "rsqrt.d"
     25 };
     26 
     27 const double fs_d[] = {
     28    0, 456.2489562, 3, -1,
     29    1384.6, -7.2945676, 1000000000, -5786.47,
     30    1752, 0.0024575, 0.00000001, -248562.76,
     31    -45786.476, 456.2489562, 34.00046, 45786.476,
     32    1752065, 107, -45667.24, -7.2945676,
     33    -347856.475, 356047.56, -1.0, 23.04
     34 };
     35 
     36 const double ft_d[] = {
     37    -45786.476, 456.2489562, 34.00046, 45786.476,
     38    1752065, 107, -45667.24, -7.2945676,
     39    -347856.475, 356047.56, -1.0, 23.04,
     40    0, 456.2489562, 3, -1,
     41    1384.6, -7.2945676, 1000000000, -5786.47,
     42    1752, 0.0024575, 0.00000001, -248562.76
     43 };
     44 
     45 const float fs_f[] = {
     46    0, 456.2489562, 3, -1,
     47    1384.6, -7.2945676, 1000000000, -5786.47,
     48    1752, 0.0024575, 0.00000001, -248562.76,
     49    -45786.476, 456.2489562, 34.00046, 45786.476,
     50    1752065, 107, -45667.24, -7.2945676,
     51    -347856.475, 356047.56, -1.0, 23.04
     52 };
     53 
     54 const float ft_f[] = {
     55    -45786.476, 456.2489562, 34.00046, 45786.476,
     56    1752065, 107, -45667.24, -7.2945676,
     57    -347856.475, 356047.56, -1.0, 23.04,
     58    0, 456.2489562, 3, -1,
     59    1384.6, -7.2945676, 1000000000, -5786.47,
     60    1752, 0.0024575, 0.00000001, -248562.76
     61 };
     62 
     63 #define UNOPdd(op) \
     64         fd_d = 0;  \
     65         __asm__ volatile( \
     66 					op" %0, %1\n\t" \
     67 					: "=f"(fd_d) : "f"(fs_d[i]));
     68 
     69 #define UNOPff(op) \
     70         fd_f = 0;  \
     71         __asm__ volatile( \
     72 					op" %0, %1\n\t" \
     73 					: "=f"(fd_f) : "f"(fs_f[i]));
     74 
     75 #define BINOPf(op) \
     76         fd_f = 0;  \
     77         __asm__ volatile( \
     78 					op" %0, %1, %2\n\t" \
     79 					: "=f"(fd_f) : "f"(fs_f[i]) , "f"(ft_f[i]));
     80 
     81 #define BINOPd(op) \
     82         fd_d = 0;  \
     83         __asm__ volatile( \
     84 					op" %0, %1, %2\n\t" \
     85 					: "=f"(fd_d) : "f"(fs_d[i]) , "f"(ft_d[i]));
     86 
     87 int arithmeticOperations(flt_art_op_t op)
     88 {
     89    double fd_d = 0;
     90    float fd_f = 0;
     91    int i = 0;
     92    for (i = 0; i < 24; i++)
     93    {
     94       switch(op) {
     95          case ABSS:
     96               UNOPff("abs.s");
     97               printf("%s %f %f\n", flt_art_op_names[op], fd_f, fs_f[i]);
     98               break;
     99          case ABSD:
    100               UNOPdd("abs.d");
    101               printf("%s %lf %lf\n", flt_art_op_names[op], fd_d, fs_d[i]);
    102               break;
    103          case ADDS:
    104               BINOPf("add.s");
    105               printf("%s %f %f %f\n", flt_art_op_names[op], fd_f, fs_f[i], ft_f[i]);
    106               break;
    107          case ADDD:
    108               BINOPd("add.d");
    109               printf("%s %lf %lf %lf\n", flt_art_op_names[op], fd_d, fs_d[i], ft_d[i]);
    110               break;
    111          case DIVS:
    112               BINOPf("div.s");
    113               printf("%s %f %f %f\n", flt_art_op_names[op], fd_f, fs_f[i], ft_f[i]);
    114               break;
    115          case DIVD:
    116               BINOPd("div.d");
    117               printf("%s %lf %lf %lf\n", flt_art_op_names[op], fd_d, fs_d[i], ft_d[i]);
    118               break;
    119          case MULS:
    120               BINOPf("mul.s");
    121               printf("%s %f %f %f\n", flt_art_op_names[op], fd_f, fs_f[i], ft_f[i]);
    122               break;
    123          case MULD:
    124               BINOPd("mul.d");
    125               printf("%s %lf %lf %lf\n", flt_art_op_names[op], fd_d, fs_d[i], ft_d[i]);
    126               break;
    127          case NEGS:
    128               UNOPff("neg.s");
    129               printf("%s %f %f\n", flt_art_op_names[op], fd_f, fs_f[i]);
    130               break;
    131          case NEGD:
    132               UNOPdd("neg.d");
    133               printf("%s %lf %lf\n", flt_art_op_names[op], fd_d, fs_d[i]);
    134               break;
    135          case SQRTS:
    136               UNOPff("sqrt.s");
    137               printf("%s %f %f\n", flt_art_op_names[op], fd_f, fs_f[i]);
    138               break;
    139          case SQRTD:
    140               UNOPdd("sqrt.d");
    141               printf("%s %lf %lf\n", flt_art_op_names[op], fd_d, fs_d[i]);
    142               break;
    143          case SUBS:
    144               BINOPf("sub.s");
    145               printf("%s %f %f %f\n", flt_art_op_names[op], fd_f, fs_f[i], ft_f[i]);
    146               break;
    147          case SUBD:
    148               BINOPd("sub.d");
    149               printf("%s %lf %lf %lf\n", flt_art_op_names[op], fd_d, fs_d[i], ft_d[i]);
    150               break;
    151          case RECIPS:
    152 #if (__mips==32) && (__mips_isa_rev>=2)
    153               UNOPff("recip.s");
    154               printf("%s %f %f\n", flt_art_op_names[op], fd_f, fs_f[i]);
    155 #endif
    156               break;
    157          case RECIPD:
    158 #if (__mips==32) && (__mips_isa_rev>=2)
    159               UNOPdd("recip.d");
    160               printf("%s %lf %lf\n", flt_art_op_names[op], fd_d, fs_d[i]);
    161 #endif
    162               break;
    163          case RSQRTS:
    164 #if (__mips==32) && (__mips_isa_rev>=2)
    165               UNOPff("rsqrt.s");
    166               printf("%s %f %f\n", flt_art_op_names[op], fd_f, fs_f[i]);
    167 #endif
    168               break;
    169          case RSQRTD:
    170 #if (__mips==32) && (__mips_isa_rev>=2)
    171               UNOPdd("rsqrt.d");
    172               printf("%s %lf %lf\n", flt_art_op_names[op], fd_d, fs_d[i]);
    173 #endif
    174               break;
    175 		default:
    176 			printf("error\n");
    177 			break;
    178 		}
    179    }
    180    return 0;
    181 }
    182 
    183 int main()
    184 {
    185    flt_art_op_t op;
    186 
    187    printf("-------------------------- %s --------------------------\n",
    188         "test FPU Arithmetic Operations");
    189    for (op = ABSS; op <= RECIPD; op++) {
    190       arithmeticOperations(op);
    191    }
    192 
    193    return 0;
    194 }
    195 
    196