Changeset a9f730a in mainline
- Timestamp:
- 2012-11-24T13:28:13Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d4cd7e5
- Parents:
- 00e3ad2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/float/softfloat1.c
r00e3ad2 ra9f730a 35 35 #include <div.h> 36 36 #include <comparison.h> 37 #include <conversion.h> 37 38 #include <bool.h> 38 39 #include "../tester.h" … … 44 45 45 46 typedef int32_t cmptype_t; 47 48 typedef void (* uint_to_double_op_t)(unsigned int, double *, double_t *); 49 typedef void (* double_to_uint_op_t)(double, unsigned int *, unsigned int *); 46 50 typedef void (* float_binary_op_t)(float, float, float *, float_t *); 47 51 typedef void (* double_binary_op_t)(double, double, double *, double_t *); 48 52 typedef void (* double_cmp_op_t)(double, double, cmptype_t *, cmptype_t *); 53 54 typedef void (* template_unary_t)(void *, unsigned, cmptype_t *, cmptype_t *); 49 55 typedef void (* template_binary_t)(void *, unsigned, unsigned, cmptype_t *, 50 56 cmptype_t *); … … 61 67 static double dop_b[OPERANDS] = 62 68 {-2.1, 100.0, 50.0, -1024.0, 3.5, 0.0}; 69 70 static unsigned int uop_a[OPERANDS] = 71 { 4, 2, 100, 50, 1024, 0 }; 63 72 64 73 static cmptype_t cmpabs(cmptype_t a) … … 81 90 82 91 static void 92 uint_to_double_template(void *f, unsigned i, cmptype_t *pic, cmptype_t *pisc) 93 { 94 double c; 95 double_t sc; 96 97 uint_to_double_op_t op = (uint_to_double_op_t) f; 98 99 op(uop_a[i], &c, &sc); 100 101 *pic = (cmptype_t) (c * PRECISION); 102 *pisc = (cmptype_t) (sc.val * PRECISION); 103 } 104 105 static void 106 double_to_uint_template(void *f, unsigned i, cmptype_t *pic, cmptype_t *pisc) 107 { 108 unsigned int c; 109 unsigned int sc; 110 111 double_to_uint_op_t op = (double_to_uint_op_t) f; 112 113 op(dop_a[i], &c, &sc); 114 115 *pic = (cmptype_t) c; 116 *pisc = (cmptype_t) sc; 117 } 118 119 120 static void 83 121 float_template_binary(void *f, unsigned i, unsigned j, cmptype_t *pic, 84 122 cmptype_t *pisc) … … 117 155 118 156 op(dop_a[i], dop_b[j], pis, piss); 157 } 158 159 static bool test_template_unary(template_unary_t template, void *f) 160 { 161 bool correct = true; 162 163 for (unsigned int i = 0; i < OPERANDS; i++) { 164 cmptype_t ic; 165 cmptype_t isc; 166 167 template(f, i, &ic, &isc); 168 cmptype_t diff = cmpabs(ic - isc); 169 170 if (diff != 0) { 171 TPRINTF("i=%u diff=%" PRIdCMPTYPE "\n", i, diff); 172 correct = false; 173 } 174 } 175 176 return correct; 119 177 } 120 178 … … 142 200 } 143 201 202 static void uint_to_double_operator(unsigned int a, double *pc, double_t *psc) 203 { 204 *pc = (double) a; 205 psc->data = uint_to_double(a); 206 } 207 208 static void 209 double_to_uint_operator(double a, unsigned int *pc, unsigned int *psc) 210 { 211 double_t sa; 212 213 sa.val = a; 214 215 *pc = (unsigned int) a; 216 *psc = double_to_uint(sa.data); 217 } 218 219 static void 220 double_to_int_operator(double a, unsigned int *pc, unsigned int *psc) 221 { 222 double_t sa; 223 224 sa.val = a; 225 226 *pc = (int) a; 227 *psc = double_to_int(sa.data); 228 } 229 144 230 static void float_add_operator(float a, float b, float *pc, float_t *psc) 145 231 { … … 295 381 TPRINTF("%s\n", err); 296 382 } 383 if (!test_template_unary(uint_to_double_template, 384 uint_to_double_operator)) { 385 err = "Conversion from unsigned int to double failed"; 386 TPRINTF("%s\n", err); 387 } 388 if (!test_template_unary(double_to_uint_template, 389 double_to_uint_operator)) { 390 err = "Conversion from double to unsigned int failed"; 391 TPRINTF("%s\n", err); 392 } 393 if (!test_template_unary(double_to_uint_template, 394 double_to_int_operator)) { 395 err = "Conversion from double to signed int failed"; 396 TPRINTF("%s\n", err); 397 } 297 398 298 399 return err;
Note:
See TracChangeset
for help on using the changeset viewer.