Home | History | Annotate | Download | only in mips64
      1 #include <stdio.h>
      2 #include "rounding_mode.h"
      3 #include "macro_fpu.h"
      4 
      5 #if defined(__mips_hard_float)
      6 int directedRoundingMode(flt_dir_op_t op) {
      7    int fd_w = 0;
      8    long long int fd_l = 0;
      9    int i;
     10    int fcsr = 0;
     11    for (i = 0; i < MAX_ARR; i++) {
     12       switch(op) {
     13          case CEILWS:
     14               UNOPfw("ceil.w.s");
     15               printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]);
     16               printf("fcsr: 0x%x\n", fcsr);
     17               break;
     18          case CEILWD:
     19               UNOPdw("ceil.w.d");
     20               printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]);
     21               printf("fcsr: 0x%x\n", fcsr);
     22               break;
     23          case FLOORWS:
     24               UNOPfw("floor.w.s");
     25               printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]);
     26               printf("fcsr: 0x%x\n", fcsr);
     27               break;
     28          case FLOORWD:
     29               UNOPdw("floor.w.d");
     30               printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]);
     31               printf("fcsr: 0x%x\n", fcsr);
     32               break;
     33          case ROUNDWS:
     34               UNOPfw("round.w.s");
     35               printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]);
     36               printf("fcsr: 0x%x\n", fcsr);
     37               break;
     38          case ROUNDWD:
     39               UNOPdw("round.w.d");
     40               printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]);
     41               printf("fcsr: 0x%x\n", fcsr);
     42               break;
     43          case TRUNCWS:
     44               UNOPfw("trunc.w.s");
     45               printf("%s %d %f\n", flt_dir_op_names[op], fd_w, fs_f[i]);
     46               printf("fcsr: 0x%x\n", fcsr);
     47               break;
     48          case TRUNCWD:
     49               UNOPdw("trunc.w.d");
     50               printf("%s %d %lf\n", flt_dir_op_names[op], fd_w, fs_d[i]);
     51               printf("fcsr: 0x%x\n", fcsr);
     52               break;
     53          case CEILLS:
     54               UNOPsl("ceil.l.s");
     55               printf("%s %lld %f\n", flt_dir_op_names[op], fd_l, fs_f[i]);
     56               printf("fcsr: 0x%x\n", fcsr);
     57               break;
     58          case CEILLD:
     59               UNOPdl("ceil.l.d");
     60               printf("%s %lld %lf\n", flt_dir_op_names[op], fd_l, fs_d[i]);
     61               printf("fcsr: 0x%x\n", fcsr);
     62               break;
     63          case FLOORLS:
     64               UNOPsl("floor.l.s");
     65               printf("%s %lld %f\n", flt_dir_op_names[op], fd_l, fs_f[i]);
     66               printf("fcsr: 0x%x\n", fcsr);
     67               break;
     68          case FLOORLD:
     69               UNOPdl("floor.l.d");
     70               printf("%s %lld %lf\n", flt_dir_op_names[op], fd_l, fs_d[i]);
     71               printf("fcsr: 0x%x\n", fcsr);
     72               break;
     73          case ROUNDLS:
     74               UNOPsl("round.l.s");
     75               printf("%s %lld %f\n", flt_dir_op_names[op], fd_l, fs_f[i]);
     76               printf("fcsr: 0x%x\n", fcsr);
     77               break;
     78          case ROUNDLD:
     79               UNOPdl("round.l.d");
     80               printf("%s %lld %lf\n", flt_dir_op_names[op], fd_l, fs_d[i]);
     81               printf("fcsr: 0x%x\n", fcsr);
     82               break;
     83          case TRUNCLS:
     84               UNOPsl("trunc.l.s");
     85               printf("%s %lld %f\n", flt_dir_op_names[op], fd_l, fs_f[i]);
     86               printf("fcsr: 0x%x\n", fcsr);
     87               break;
     88          case TRUNCLD:
     89               UNOPdl("trunc.l.d");
     90               printf("%s %lld %lf\n", flt_dir_op_names[op], fd_l, fs_d[i]);
     91               printf("fcsr: 0x%x\n", fcsr);
     92               break;
     93         default:
     94             printf("error\n");
     95             break;
     96         }
     97     }
     98    return 0;
     99 }
    100 
    101 int FCSRRoundingMode(flt_round_op_t op1)
    102 {
    103    double fd_d = 0;
    104    float fd_f = 0;
    105    int fd_w = 0;
    106    long long int fd_l = 0;
    107    int i;
    108    int fcsr = 0;
    109    round_mode_t rm;
    110    for (rm = TO_NEAREST; rm <= TO_MINUS_INFINITY; rm ++) {
    111       set_rounding_mode(rm);
    112       printf("roundig mode: %s\n", round_mode_name[rm]);
    113       for (i = 0; i < MAX_ARR; i++) {
    114          set_rounding_mode(rm);
    115          switch(op1) {
    116             case CVTDS:
    117                  UNOPfd("cvt.d.s");
    118                  printf("%s %lf %lf\n", flt_round_op_names[op1], fd_d, fs_f[i]);
    119                  printf("fcsr: 0x%x\n", fcsr);
    120                  break;
    121             case CVTDW:
    122                  UNOPwd("cvt.d.w");
    123                  printf("%s %lf %d\n", flt_round_op_names[op1], fd_d, fs_w[i]);
    124                  printf("fcsr: 0x%x\n", fcsr);
    125                  break;
    126             case CVTSD:
    127                  UNOPdf("cvt.s.d");
    128                  printf("%s %f %lf\n", flt_round_op_names[op1], fd_f, fs_d[i]);
    129                  printf("fcsr: 0x%x\n", fcsr);
    130                  break;
    131             case CVTSW:
    132                  UNOPwf("cvt.s.w");
    133                  printf("%s %f %d\n", flt_round_op_names[op1], fd_f, fs_w[i]);
    134                  printf("fcsr: 0x%x\n", fcsr);
    135                  break;
    136             case CVTWS:
    137                  UNOPfw("cvt.w.s");
    138                  printf("%s %d %f\n", flt_round_op_names[op1], fd_w, fs_f[i]);
    139                  printf("fcsr: 0x%x\n", fcsr);
    140                  break;
    141             case CVTWD:
    142                  UNOPdw("cvt.w.d");
    143                  printf("%s %d %lf\n", flt_round_op_names[op1], fd_w, fs_d[i]);
    144                  printf("fcsr: 0x%x\n", fcsr);
    145                  break;
    146             case CVTDL:
    147                  UNOPld("cvt.d.l");
    148                  printf("%s %lf %ld\n", flt_round_op_names[op1], fd_d, fs_l[i]);
    149                  printf("fcsr: 0x%x\n", fcsr);
    150                  break;
    151             case CVTLS:
    152                  UNOPsl("cvt.l.s");
    153                  printf("%s %lld %f\n", flt_round_op_names[op1], fd_l, fs_f[i]);
    154                  printf("fcsr: 0x%x\n", fcsr);
    155                  break;
    156             case CVTLD:
    157                  UNOPdl("cvt.l.d");
    158                  printf("%s %lld %lf\n", flt_round_op_names[op1], fd_l, fs_d[i]);
    159                  printf("fcsr: 0x%x\n", fcsr);
    160                  break;
    161             case CVTSL:
    162                  UNOPls("cvt.s.l");
    163                  printf("%s %f %ld\n", flt_round_op_names[op1], fd_f, fs_l[i]);
    164                  printf("fcsr: 0x%x\n", fcsr);
    165                  break;
    166             default:
    167                  printf("error\n");
    168                  break;
    169          }
    170       }
    171    }
    172    return 0;
    173 }
    174 #endif
    175 
    176 int main()
    177 {
    178 #if defined(__mips_hard_float)
    179    flt_dir_op_t op;
    180    flt_round_op_t op1;
    181 
    182    printf("-------------------------- %s --------------------------\n",
    183         "test FPU Conversion Operations Using a Directed Rounding Mode");
    184    for (op = CEILWS; op <= TRUNCLS; op++) {
    185       directedRoundingMode(op);
    186    }
    187 
    188    printf("-------------------------- %s --------------------------\n",
    189         "test FPU Conversion Operations Using the FCSR Rounding Mode");
    190    for (op1 = CVTDS; op1 <= CVTSL; op1++) {
    191       FCSRRoundingMode(op1);
    192    }
    193 #endif
    194    return 0;
    195 }
    196