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