Changeset c0c38c7c in mainline
- Timestamp:
- 2015-03-14T21:36:44Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7f9d97f3
- Parents:
- 2c7fdaa
- Location:
- uspace
- Files:
-
- 2 added
- 3 deleted
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/float/softfloat1.c
r2c7fdaa rc0c38c7c 29 29 #include <stdio.h> 30 30 #include <stdlib.h> 31 #include < sftypes.h>31 #include <mathtypes.h> 32 32 #include <add.h> 33 33 #include <sub.h> … … 39 39 #include "../tester.h" 40 40 41 #define add_float __addsf3 42 #define sub_float __subsf3 43 #define mul_float __mulsf3 44 #define div_float __divsf3 45 46 #define is_float_lt __ltsf2 47 #define is_float_gt __gtsf2 48 #define is_float_eq __eqsf2 49 50 #define add_double __adddf3 51 #define sub_double __subdf3 52 #define mul_double __muldf3 53 #define div_double __divdf3 54 55 #define is_double_lt __ltdf2 56 #define is_double_gt __gtdf2 57 #define is_double_eq __eqdf2 58 59 #define uint_to_double __floatsidf 60 #define double_to_uint __fixunsdfsi 61 #define double_to_int __fixdfsi 62 41 63 #define OPERANDS 10 42 #define PRECISION 1000 064 #define PRECISION 1000 43 65 44 66 #define PRIdCMPTYPE PRId32 … … 46 68 typedef int32_t cmptype_t; 47 69 48 typedef void (* uint_to_double_op_t)(unsigned int, double *, double _t*);70 typedef void (* uint_to_double_op_t)(unsigned int, double *, double *); 49 71 typedef void (* double_to_uint_op_t)(double, unsigned int *, unsigned int *); 50 typedef void (* float_binary_op_t)(float, float, float *, float_t *); 51 typedef void (* double_binary_op_t)(double, double, double *, double_t *); 72 typedef void (* float_binary_op_t)(float, float, float *, float *); 73 typedef void (* float_cmp_op_t)(float, float, cmptype_t *, cmptype_t *); 74 typedef void (* double_binary_op_t)(double, double, double *, double *); 52 75 typedef void (* double_cmp_op_t)(double, double, cmptype_t *, cmptype_t *); 53 76 … … 68 91 69 92 static unsigned int uop_a[OPERANDS] = { 70 4, -100, 100, 50, 1024, 0, 1000000, -1U, 0x80000000U, 50093 4, 2, 100, 50, 1024, 0, 1000000, 1, 0x8000000, 500 71 94 }; 72 95 73 static cmptype_t cmpabs(cmptype_t a) 74 { 75 if (a >= 0) 76 return a; 77 78 return -a; 79 } 80 81 static int dcmp(double a, double b) 96 static int fcmp(float a, float b) 82 97 { 83 98 if (a < b) … … 90 105 } 91 106 107 static int dcmp(double a, double b) 108 { 109 if (a < b) 110 return -1; 111 112 if (a > b) 113 return 1; 114 115 return 0; 116 } 117 92 118 static void uint_to_double_template(void *f, unsigned i, cmptype_t *pic, 93 119 cmptype_t *pisc) … … 96 122 97 123 double c; 98 double _tsc;124 double sc; 99 125 op(uop_a[i], &c, &sc); 100 126 101 127 *pic = (cmptype_t) (c * PRECISION); 102 *pisc = (cmptype_t) (sc .val* PRECISION);128 *pisc = (cmptype_t) (sc * PRECISION); 103 129 } 104 130 … … 116 142 } 117 143 118 119 144 static void float_template_binary(void *f, unsigned i, unsigned j, 120 145 cmptype_t *pic, cmptype_t *pisc) … … 123 148 124 149 float c; 125 float _tsc;150 float sc; 126 151 op(fop_a[i], fop_a[j], &c, &sc); 127 152 128 153 *pic = (cmptype_t) (c * PRECISION); 129 *pisc = (cmptype_t) (sc.val * PRECISION); 154 *pisc = (cmptype_t) (sc * PRECISION); 155 } 156 157 static void float_compare_template(void *f, unsigned i, unsigned j, 158 cmptype_t *pis, cmptype_t *piss) 159 { 160 float_cmp_op_t op = (float_cmp_op_t) f; 161 162 op(dop_a[i], dop_a[j], pis, piss); 130 163 } 131 164 … … 136 169 137 170 double c; 138 double _tsc;171 double sc; 139 172 op(dop_a[i], dop_a[j], &c, &sc); 140 173 141 174 *pic = (cmptype_t) (c * PRECISION); 142 *pisc = (cmptype_t) (sc .val* PRECISION);175 *pisc = (cmptype_t) (sc * PRECISION); 143 176 } 144 177 … … 160 193 161 194 template(f, i, &ic, &isc); 162 cmptype_t diff = cmpabs(ic - isc);195 cmptype_t diff = ic - isc; 163 196 164 197 if (diff != 0) { 165 TPRINTF("i=%u diff=%" PRIdCMPTYPE "\n", i, diff); 198 TPRINTF("i=%u ic=%" PRIdCMPTYPE " isc=%" PRIdCMPTYPE "\n", 199 i, ic, isc); 166 200 correct = false; 167 201 } … … 181 215 182 216 template(f, i, j, &ic, &isc); 183 cmptype_t diff = cmpabs(ic - isc);217 cmptype_t diff = ic - isc; 184 218 185 219 if (diff != 0) { 186 TPRINTF("i=%u, j=%u diff=%" PRIdCMPTYPE "\n",187 i, j, diff);220 TPRINTF("i=%u, j=%u ic=%" PRIdCMPTYPE 221 " isc=%" PRIdCMPTYPE "\n", i, j, ic, isc); 188 222 correct = false; 189 223 } … … 194 228 } 195 229 196 static void uint_to_double_operator(unsigned int a, double *pc, double _t*psc)230 static void uint_to_double_operator(unsigned int a, double *pc, double *psc) 197 231 { 198 232 *pc = (double) a; 199 psc->data= uint_to_double(a);233 *psc = uint_to_double(a); 200 234 } 201 235 … … 203 237 unsigned int *psc) 204 238 { 205 double_t sa;206 207 sa.val = a;208 209 239 *pc = (unsigned int) a; 210 *psc = double_to_uint( sa.data);240 *psc = double_to_uint(a); 211 241 } 212 242 … … 214 244 unsigned int *psc) 215 245 { 216 double_t sa;217 218 sa.val = a;219 220 246 *pc = (int) a; 221 *psc = double_to_int( sa.data);222 } 223 224 static void float_add_operator(float a, float b, float *pc, float _t*psc)247 *psc = double_to_int(a); 248 } 249 250 static void float_add_operator(float a, float b, float *pc, float *psc) 225 251 { 226 252 *pc = a + b; 227 228 float_t sa; 229 float_t sb; 230 231 sa.val = a; 232 sb.val = b; 233 234 if (sa.data.parts.sign == sb.data.parts.sign) { 235 psc->data = add_float(sa.data, sb.data); 236 } else if (sa.data.parts.sign) { 237 sa.data.parts.sign = 0; 238 psc->data = sub_float(sb.data, sa.data); 239 } else { 240 sb.data.parts.sign = 0; 241 psc->data = sub_float(sa.data, sb.data); 242 } 243 } 244 245 static void float_mul_operator(float a, float b, float *pc, float_t *psc) 253 *psc = add_float(a, b); 254 } 255 256 static void float_sub_operator(float a, float b, float *pc, float *psc) 257 { 258 *pc = a - b; 259 *psc = sub_float(a, b); 260 } 261 262 static void float_mul_operator(float a, float b, float *pc, float *psc) 246 263 { 247 264 *pc = a * b; 248 249 float_t sa; 250 float_t sb; 251 252 sa.val = a; 253 sb.val = b; 254 psc->data = mul_float(sa.data, sb.data); 255 } 256 257 static void float_div_operator(float a, float b, float *pc, float_t *psc) 265 *psc = mul_float(a, b); 266 } 267 268 static void float_div_operator(float a, float b, float *pc, float *psc) 258 269 { 259 270 if ((cmptype_t) b == 0) { 260 271 *pc = 0.0; 261 psc->val= 0.0;272 *psc = 0.0; 262 273 return; 263 274 } 264 275 265 276 *pc = a / b; 266 267 float_t sa; 268 float_t sb; 269 270 sa.val = a; 271 sb.val = b; 272 psc->data = div_float(sa.data, sb.data); 273 } 274 275 static void double_add_operator(double a, double b, double *pc, double_t *psc) 276 { 277 *pc = a + b; 278 279 double_t sa; 280 double_t sb; 281 282 sa.val = a; 283 sb.val = b; 284 285 if (sa.data.parts.sign == sb.data.parts.sign) { 286 psc->data = add_double(sa.data, sb.data); 287 } else if (sa.data.parts.sign) { 288 sa.data.parts.sign = 0; 289 psc->data = sub_double(sb.data, sa.data); 290 } else { 291 sb.data.parts.sign = 0; 292 psc->data = sub_double(sa.data, sb.data); 293 } 294 } 295 296 static void double_mul_operator(double a, double b, double *pc, double_t *psc) 297 { 298 *pc = a * b; 299 300 double_t sa; 301 double_t sb; 302 303 sa.val = a; 304 sb.val = b; 305 psc->data = mul_double(sa.data, sb.data); 306 } 307 308 static void double_div_operator(double a, double b, double *pc, double_t *psc) 309 { 310 if ((cmptype_t) b == 0) { 311 *pc = 0.0; 312 psc->val = 0.0; 313 return; 314 } 315 316 *pc = a / b; 317 318 double_t sa; 319 double_t sb; 320 321 sa.val = a; 322 sb.val = b; 323 psc->data = div_double(sa.data, sb.data); 324 } 325 326 static void double_cmp_operator(double a, double b, cmptype_t *pis, 277 *psc = div_float(a, b); 278 } 279 280 static void float_cmp_operator(float a, float b, cmptype_t *pis, 327 281 cmptype_t *piss) 328 282 { 329 *pis = dcmp(a, b); 330 331 double_t sa; 332 double_t sb; 333 334 sa.val = a; 335 sb.val = b; 336 337 if (is_double_lt(sa.data, sb.data)) 283 *pis = fcmp(a, b); 284 285 if (is_float_lt(a, b) == -1) 338 286 *piss = -1; 339 else if (is_ double_gt(sa.data, sb.data))287 else if (is_float_gt(a, b) == 1) 340 288 *piss = 1; 341 else if (is_ double_eq(sa.data, sb.data))289 else if (is_float_eq(a, b) == 0) 342 290 *piss = 0; 343 291 else … … 345 293 } 346 294 295 static void double_add_operator(double a, double b, double *pc, double *psc) 296 { 297 *pc = a + b; 298 *psc = add_double(a, b); 299 } 300 301 static void double_sub_operator(double a, double b, double *pc, double *psc) 302 { 303 *pc = a - b; 304 *psc = sub_double(a, b); 305 } 306 307 static void double_mul_operator(double a, double b, double *pc, double *psc) 308 { 309 *pc = a * b; 310 *psc = mul_double(a, b); 311 } 312 313 static void double_div_operator(double a, double b, double *pc, double *psc) 314 { 315 if ((cmptype_t) b == 0) { 316 *pc = 0.0; 317 *psc = 0.0; 318 return; 319 } 320 321 *pc = a / b; 322 *psc = div_double(a, b); 323 } 324 325 static void double_cmp_operator(double a, double b, cmptype_t *pis, 326 cmptype_t *piss) 327 { 328 *pis = dcmp(a, b); 329 330 if (is_double_lt(a, b) == -1) 331 *piss = -1; 332 else if (is_double_gt(a, b) == 1) 333 *piss = 1; 334 else if (is_double_eq(a, b) == 0) 335 *piss = 0; 336 else 337 *piss = 42; 338 } 339 347 340 const char *test_softfloat1(void) 348 341 { 349 const char *err = NULL;342 bool err = false; 350 343 351 344 if (!test_template_binary(float_template_binary, float_add_operator)) { 352 err = "Float addition failed"; 353 TPRINTF("%s\n", err); 345 err = true; 346 TPRINTF("%s\n", "Float addition failed"); 347 } 348 349 if (!test_template_binary(float_template_binary, float_sub_operator)) { 350 err = true; 351 TPRINTF("%s\n", "Float addition failed"); 354 352 } 355 353 356 354 if (!test_template_binary(float_template_binary, float_mul_operator)) { 357 err = "Float multiplication failed";358 TPRINTF("%s\n", err);355 err = true; 356 TPRINTF("%s\n", "Float multiplication failed"); 359 357 } 360 358 361 359 if (!test_template_binary(float_template_binary, float_div_operator)) { 362 err = "Float division failed"; 363 TPRINTF("%s\n", err); 360 err = true; 361 TPRINTF("%s\n", "Float division failed"); 362 } 363 364 if (!test_template_binary(float_compare_template, float_cmp_operator)) { 365 err = true; 366 TPRINTF("%s\n", "Float comparison failed"); 364 367 } 365 368 366 369 if (!test_template_binary(double_template_binary, double_add_operator)) { 367 err = "Double addition failed"; 368 TPRINTF("%s\n", err); 370 err = true; 371 TPRINTF("%s\n", "Double addition failed"); 372 } 373 374 if (!test_template_binary(double_template_binary, double_sub_operator)) { 375 err = true; 376 TPRINTF("%s\n", "Double addition failed"); 369 377 } 370 378 371 379 if (!test_template_binary(double_template_binary, double_mul_operator)) { 372 err = "Double multiplication failed";373 TPRINTF("%s\n", err);380 err = true; 381 TPRINTF("%s\n", "Double multiplication failed"); 374 382 } 375 383 376 384 if (!test_template_binary(double_template_binary, double_div_operator)) { 377 err = "Double division failed";378 TPRINTF("%s\n", err);385 err = true; 386 TPRINTF("%s\n", "Double division failed"); 379 387 } 380 388 381 389 if (!test_template_binary(double_compare_template, double_cmp_operator)) { 382 err = "Double comparison failed";383 TPRINTF("%s\n", err);390 err = true; 391 TPRINTF("%s\n", "Double comparison failed"); 384 392 } 385 393 386 394 if (!test_template_unary(uint_to_double_template, 387 395 uint_to_double_operator)) { 388 err = "Conversion from unsigned int to double failed";389 TPRINTF("%s\n", err);396 err = true; 397 TPRINTF("%s\n", "Conversion from unsigned int to double failed"); 390 398 } 391 399 392 400 if (!test_template_unary(double_to_uint_template, 393 401 double_to_uint_operator)) { 394 err = "Conversion from double to unsigned int failed";395 TPRINTF("%s\n", err);402 err = true; 403 TPRINTF("%s\n", "Conversion from double to unsigned int failed"); 396 404 } 397 405 398 406 if (!test_template_unary(double_to_uint_template, 399 407 double_to_int_operator)) { 400 err = "Conversion from double to signed int failed"; 401 TPRINTF("%s\n", err); 402 } 403 404 return err; 405 } 408 err = true; 409 TPRINTF("%s\n", "Conversion from double to signed int failed"); 410 } 411 412 if (err) 413 return "Software floating point imprecision"; 414 415 return NULL; 416 } -
uspace/lib/math/arch/abs32le/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/amd64/include/libarch/math.h
r2c7fdaa rc0c38c7c 36 36 #define LIBMATH_amd64_MATH_H_ 37 37 38 #include <mathtypes.h> 38 39 #include <mod.h> 39 40 40 static inline double fmod(double dividend, doubledivisor)41 static inline float64_t fmod(float64_t dividend, float64_t divisor) 41 42 { 42 return double_mod(dividend, divisor);43 return float64_mod(dividend, divisor); 43 44 } 44 45 45 extern double sin(double);46 extern double cos(double);47 extern double trunc(double);46 extern float64_t sin(float64_t); 47 extern float64_t cos(float64_t); 48 extern float64_t trunc(float64_t); 48 49 49 50 #endif -
uspace/lib/math/arch/arm32/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/ia32/include/libarch/math.h
r2c7fdaa rc0c38c7c 36 36 #define LIBMATH_ia32_MATH_H_ 37 37 38 #include <mathtypes.h> 38 39 #include <mod.h> 39 40 40 static inline double fmod(double dividend, doubledivisor)41 static inline float64_t fmod(float64_t dividend, float64_t divisor) 41 42 { 42 return double_mod(dividend, divisor);43 return float64_mod(dividend, divisor); 43 44 } 44 45 45 extern double sin(double);46 extern double cos(double);47 extern double trunc(double);46 extern float64_t sin(float64_t); 47 extern float64_t cos(float64_t); 48 extern float64_t trunc(float64_t); 48 49 49 50 #endif -
uspace/lib/math/arch/ia64/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/mips32/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/mips32eb/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/ppc32/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 48 static inline double trunc(double val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/sparc32/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/sparc64/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/generic/mod.c
r2c7fdaa rc0c38c7c 52 52 * 53 53 */ 54 double double_mod(double dividend, doubledivisor)54 float64_t float64_mod(float64_t dividend, float64_t divisor) 55 55 { 56 56 // FIXME: replace with exact arithmetics 57 57 58 doublequotient = trunc(dividend / divisor);58 float64_t quotient = trunc(dividend / divisor); 59 59 60 60 return (dividend - quotient * divisor); -
uspace/lib/math/generic/trig.c
r2c7fdaa rc0c38c7c 39 39 40 40 /** Precomputed values for factorial (starting from 1!) */ 41 static doublefactorials[TAYLOR_DEGREE] = {41 static float64_t factorials[TAYLOR_DEGREE] = { 42 42 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 43 43 479001600, 6227020800 … … 56 56 * 57 57 */ 58 static double taylor_sin(doublearg)59 { 60 doubleret = 0;61 doublenom = 1;58 static float64_t taylor_sin(float64_t arg) 59 { 60 float64_t ret = 0; 61 float64_t nom = 1; 62 62 63 63 for (unsigned int i = 0; i < TAYLOR_DEGREE; i++) { … … 85 85 * 86 86 */ 87 static double taylor_cos(doublearg)88 { 89 doubleret = 1;90 doublenom = 1;87 static float64_t taylor_cos(float64_t arg) 88 { 89 float64_t ret = 1; 90 float64_t nom = 1; 91 91 92 92 for (unsigned int i = 0; i < TAYLOR_DEGREE; i++) { … … 114 114 * 115 115 */ 116 static double base_sin(doublearg)116 static float64_t base_sin(float64_t arg) 117 117 { 118 118 unsigned int period = arg / (M_PI / 4); … … 147 147 * 148 148 */ 149 static double base_cos(doublearg)149 static float64_t base_cos(float64_t arg) 150 150 { 151 151 unsigned int period = arg / (M_PI / 4); … … 156 156 case 1: 157 157 case 2: 158 return taylor_sin(arg - M_PI / 2);158 return -taylor_sin(arg - M_PI / 2); 159 159 case 3: 160 160 case 4: … … 162 162 case 5: 163 163 case 6: 164 return -taylor_sin(arg - 3 * M_PI / 2);164 return taylor_sin(arg - 3 * M_PI / 2); 165 165 default: 166 166 return taylor_cos(arg - 2 * M_PI); … … 177 177 * 178 178 */ 179 double double_sin(doublearg)180 { 181 doublebase_arg = fmod(arg, 2 * M_PI);179 float64_t float64_sin(float64_t arg) 180 { 181 float64_t base_arg = fmod(arg, 2 * M_PI); 182 182 183 183 if (base_arg < 0) … … 196 196 * 197 197 */ 198 double double_cos(doublearg)199 { 200 doublebase_arg = fmod(arg, 2 * M_PI);198 float64_t float64_cos(float64_t arg) 199 { 200 float64_t base_arg = fmod(arg, 2 * M_PI); 201 201 202 202 if (base_arg < 0) -
uspace/lib/math/include/mathtypes.h
r2c7fdaa rc0c38c7c 191 191 #endif 192 192 193 typedef union { 194 float val; 195 193 196 194 #if defined(FLOAT_SIZE_32) 195 196 #ifndef float32_t 197 #define float32_t float 198 #endif 199 200 #elif defined(FLOAT_SIZE_64) 201 202 #ifndef float64_t 203 #define float64_t float 204 #endif 205 206 #elif defined(FLOAT_SIZE_96) 207 208 #ifndef float96_t 209 #define float96_t float 210 #endif 211 212 #elif defined(FLOAT_SIZE_128) 213 214 #ifndef float128_t 215 #define float128_t float 216 #endif 217 218 #endif 219 220 221 #if defined(DOUBLE_SIZE_32) 222 223 #ifndef float32_t 224 #define float32_t double 225 #endif 226 227 #elif defined(DOUBLE_SIZE_64) 228 229 #ifndef float64_t 230 #define float64_t double 231 #endif 232 233 #elif defined(DOUBLE_SIZE_96) 234 235 #ifndef float96_t 236 #define float96_t double 237 #endif 238 239 #elif defined(DOUBLE_SIZE_128) 240 241 #ifndef float128_t 242 #define float128_t double 243 #endif 244 245 #endif 246 247 248 #if defined(LONG_DOUBLE_SIZE_32) 249 250 #ifndef float32_t 251 #define float32_t long double 252 #endif 253 254 #elif defined(LONG_DOUBLE_SIZE_64) 255 256 #ifndef float64_t 257 #define float64_t long double 258 #endif 259 260 #elif defined(LONG_DOUBLE_SIZE_96) 261 262 #ifndef float96_t 263 #define float96_t long double 264 #endif 265 266 #elif defined(LONG_DOUBLE_SIZE_128) 267 268 #ifndef float128_t 269 #define float128_t long double 270 #endif 271 272 #endif 273 274 275 #ifdef float32_t 276 277 typedef union { 278 float32_t val; 197 279 float32 data; 198 #elif defined(FLOAT_SIZE_64) 280 } float32_u; 281 282 #endif 283 284 #ifdef float64_t 285 286 typedef union { 287 float64_t val; 199 288 float64 data; 200 #elif defined(FLOAT_SIZE_96) 289 } float64_u; 290 291 #endif 292 293 #ifdef float96_t 294 295 typedef union { 296 float96_t val; 201 297 float96 data; 202 #elif defined(FLOAT_SIZE_128) 298 } float96_u; 299 300 #endif 301 302 #ifdef float128_t 303 304 typedef union { 305 float128_t val; 203 306 float128 data; 204 #else 205 #error Unsupported float size 206 #endif 207 } float_t; 208 209 typedef union { 210 double val; 211 212 #if defined(DOUBLE_SIZE_32) 213 float32 data; 214 #elif defined(DOUBLE_SIZE_64) 215 float64 data; 216 #elif defined(DOUBLE_SIZE_96) 217 float96 data; 218 #elif defined(DOUBLE_SIZE_128) 219 float128 data; 220 #else 221 #error Unsupported double size 222 #endif 223 } double_t; 224 225 typedef union { 226 long double val; 227 228 #if defined(LONG_DOUBLE_SIZE_32) 229 float32 data; 230 #elif defined(LONG_DOUBLE_SIZE_64) 231 float64 data; 232 #elif defined(LONG_DOUBLE_SIZE_96) 233 float96 data; 234 #elif defined(LONG_DOUBLE_SIZE_128) 235 float128 data; 236 #else 237 #error Unsupported long double size 238 #endif 239 } long_double_t; 307 } float128_u; 308 309 #endif 240 310 241 311 #endif -
uspace/lib/math/include/mod.h
r2c7fdaa rc0c38c7c 36 36 #define LIBMATH_MOD_H_ 37 37 38 extern double double_mod(double, double);38 extern float64_t float64_mod(float64_t, float64_t); 39 39 40 40 #endif -
uspace/lib/math/include/trig.h
r2c7fdaa rc0c38c7c 36 36 #define LIBMATH_TRIG_H_ 37 37 38 extern double double_sin(double);39 extern double double_cos(double);38 extern float64_t float64_sin(float64_t); 39 extern float64_t float64_cos(float64_t); 40 40 41 41 #endif -
uspace/lib/softfloat/Makefile
r2c7fdaa rc0c38c7c 33 33 34 34 SOURCES = \ 35 softfloat.c \36 35 common.c \ 37 36 add.c \ … … 39 38 div.c \ 40 39 mul.c \ 40 neg.c \ 41 41 comparison.c \ 42 42 conversion.c -
uspace/lib/softfloat/add.c
r2c7fdaa rc0c38c7c 34 34 */ 35 35 36 #include "sftypes.h"37 36 #include "add.h" 38 37 #include "comparison.h" 39 38 #include "common.h" 39 #include "sub.h" 40 40 41 41 /** Add two single-precision floats with the same sign. … … 413 413 } 414 414 415 #ifdef float32_t 416 417 float32_t __addsf3(float32_t a, float32_t b) 418 { 419 float32_u ua; 420 ua.val = a; 421 422 float32_u ub; 423 ub.val = b; 424 425 float32_u res; 426 427 if (ua.data.parts.sign != ub.data.parts.sign) { 428 if (ua.data.parts.sign) { 429 ua.data.parts.sign = 0; 430 res.data = sub_float32(ub.data, ua.data); 431 } else { 432 ub.data.parts.sign = 0; 433 res.data = sub_float32(ua.data, ub.data); 434 } 435 } else 436 res.data = add_float32(ua.data, ub.data); 437 438 return res.val; 439 } 440 441 float32_t __aeabi_fadd(float32_t a, float32_t b) 442 { 443 float32_u ua; 444 ua.val = a; 445 446 float32_u ub; 447 ub.val = b; 448 449 float32_u res; 450 451 if (ua.data.parts.sign != ub.data.parts.sign) { 452 if (ua.data.parts.sign) { 453 ua.data.parts.sign = 0; 454 res.data = sub_float32(ub.data, ua.data); 455 } else { 456 ub.data.parts.sign = 0; 457 res.data = sub_float32(ua.data, ub.data); 458 } 459 } else 460 res.data = add_float32(ua.data, ub.data); 461 462 return res.val; 463 } 464 465 #endif 466 467 #ifdef float64_t 468 469 float64_t __adddf3(float64_t a, float64_t b) 470 { 471 float64_u ua; 472 ua.val = a; 473 474 float64_u ub; 475 ub.val = b; 476 477 float64_u res; 478 479 if (ua.data.parts.sign != ub.data.parts.sign) { 480 if (ua.data.parts.sign) { 481 ua.data.parts.sign = 0; 482 res.data = sub_float64(ub.data, ua.data); 483 } else { 484 ub.data.parts.sign = 0; 485 res.data = sub_float64(ua.data, ub.data); 486 } 487 } else 488 res.data = add_float64(ua.data, ub.data); 489 490 return res.val; 491 } 492 493 float64_t __aeabi_dadd(float64_t a, float64_t b) 494 { 495 float64_u ua; 496 ua.val = a; 497 498 float64_u ub; 499 ub.val = b; 500 501 float64_u res; 502 503 if (ua.data.parts.sign != ub.data.parts.sign) { 504 if (ua.data.parts.sign) { 505 ua.data.parts.sign = 0; 506 res.data = sub_float64(ub.data, ua.data); 507 } else { 508 ub.data.parts.sign = 0; 509 res.data = sub_float64(ua.data, ub.data); 510 } 511 } else 512 res.data = add_float64(ua.data, ub.data); 513 514 return res.val; 515 } 516 517 #endif 518 519 #ifdef float128_t 520 521 float128_t __addtf3(float128_t a, float128_t b) 522 { 523 float128_u ua; 524 ua.val = a; 525 526 float128_u ub; 527 ub.val = b; 528 529 float128_u res; 530 531 if (ua.data.parts.sign != ub.data.parts.sign) { 532 if (ua.data.parts.sign) { 533 ua.data.parts.sign = 0; 534 res.data = sub_float128(ub.data, ua.data); 535 } else { 536 ub.data.parts.sign = 0; 537 res.data = sub_float128(ua.data, ub.data); 538 } 539 } else 540 res.data = add_float128(ua.data, ub.data); 541 542 return res.val; 543 } 544 545 void _Qp_add(float128_t *c, float128_t *a, float128_t *b) 546 { 547 *c = __addtf3(*a, *b); 548 } 549 550 #endif 551 415 552 /** @} 416 553 */ -
uspace/lib/softfloat/add.h
r2c7fdaa rc0c38c7c 37 37 #define __ADD_H__ 38 38 39 #include <mathtypes.h> 40 39 41 extern float32 add_float32(float32, float32); 40 42 extern float64 add_float64(float64, float64); … … 42 44 extern float128 add_float128(float128, float128); 43 45 46 #ifdef float32_t 47 extern float32_t __addsf3(float32_t, float32_t); 48 extern float32_t __aeabi_fadd(float32_t, float32_t); 49 #endif 50 51 #ifdef float64_t 52 extern float64_t __adddf3(float64_t, float64_t); 53 extern float64_t __aeabi_dadd(float64_t, float64_t); 54 #endif 55 56 #ifdef float128_t 57 extern float128_t __addtf3(float128_t, float128_t); 58 extern void _Qp_add(float128_t *, float128_t *, float128_t *); 59 #endif 60 44 61 #endif 45 62 -
uspace/lib/softfloat/common.c
r2c7fdaa rc0c38c7c 34 34 */ 35 35 36 #include "sftypes.h"37 36 #include "common.h" 38 37 -
uspace/lib/softfloat/common.h
r2c7fdaa rc0c38c7c 37 37 #define __COMMON_H__ 38 38 39 #include "sftypes.h"39 #include <mathtypes.h> 40 40 41 41 extern float64 finish_float64(int32_t, uint64_t, char); … … 53 53 extern void rshift128(uint64_t, uint64_t, int, uint64_t *, uint64_t *); 54 54 55 extern void and128(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t *, uint64_t *); 56 extern void or128(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t *, uint64_t *); 57 extern void xor128(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t *, uint64_t *); 55 extern void and128(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t *, 56 uint64_t *); 57 extern void or128(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t *, 58 uint64_t *); 59 extern void xor128(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t *, 60 uint64_t *); 58 61 extern void not128(uint64_t, uint64_t, uint64_t *, uint64_t *); 59 62 … … 62 65 extern int lt128(uint64_t, uint64_t, uint64_t, uint64_t); 63 66 64 extern void add128(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t *, uint64_t *); 65 extern void sub128(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t *, uint64_t *); 67 extern void add128(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t *, 68 uint64_t *); 69 extern void sub128(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t *, 70 uint64_t *); 66 71 67 72 extern void mul64(uint64_t, uint64_t, uint64_t *, uint64_t *); -
uspace/lib/softfloat/comparison.c
r2c7fdaa rc0c38c7c 34 34 */ 35 35 36 #include "sftypes.h"37 36 #include "comparison.h" 38 37 #include "common.h" … … 439 438 } 440 439 440 #ifdef float32_t 441 442 int __gtsf2(float32_t a, float32_t b) 443 { 444 float32_u ua; 445 ua.val = a; 446 447 float32_u ub; 448 ub.val = b; 449 450 if ((is_float32_nan(ua.data)) || (is_float32_nan(ub.data))) { 451 // TODO: sigNaNs 452 return -1; 453 } 454 455 if (is_float32_gt(ua.data, ub.data)) 456 return 1; 457 458 return 0; 459 } 460 461 int __gesf2(float32_t a, float32_t b) 462 { 463 float32_u ua; 464 ua.val = a; 465 466 float32_u ub; 467 ub.val = b; 468 469 if ((is_float32_nan(ua.data)) || (is_float32_nan(ub.data))) { 470 // TODO: sigNaNs 471 return -1; 472 } 473 474 if (is_float32_eq(ua.data, ub.data)) 475 return 0; 476 477 if (is_float32_gt(ua.data, ub.data)) 478 return 1; 479 480 return -1; 481 } 482 483 int __ltsf2(float32_t a, float32_t b) 484 { 485 float32_u ua; 486 ua.val = a; 487 488 float32_u ub; 489 ub.val = b; 490 491 if ((is_float32_nan(ua.data)) || (is_float32_nan(ub.data))) { 492 // TODO: sigNaNs 493 return 1; 494 } 495 496 if (is_float32_lt(ua.data, ub.data)) 497 return -1; 498 499 return 0; 500 } 501 502 int __lesf2(float32_t a, float32_t b) 503 { 504 float32_u ua; 505 ua.val = a; 506 507 float32_u ub; 508 ub.val = b; 509 510 if ((is_float32_nan(ua.data)) || (is_float32_nan(ub.data))) { 511 // TODO: sigNaNs 512 return 1; 513 } 514 515 if (is_float32_eq(ua.data, ub.data)) 516 return 0; 517 518 if (is_float32_lt(ua.data, ub.data)) 519 return -1; 520 521 return 1; 522 } 523 524 int __eqsf2(float32_t a, float32_t b) 525 { 526 float32_u ua; 527 ua.val = a; 528 529 float32_u ub; 530 ub.val = b; 531 532 if ((is_float32_nan(ua.data)) || (is_float32_nan(ub.data))) { 533 // TODO: sigNaNs 534 return 1; 535 } 536 537 return is_float32_eq(ua.data, ub.data) - 1; 538 } 539 540 int __nesf2(float32_t a, float32_t b) 541 { 542 /* Strange, but according to GCC documentation */ 543 return __eqsf2(a, b); 544 } 545 546 int __cmpsf2(float32_t a, float32_t b) 547 { 548 float32_u ua; 549 ua.val = a; 550 551 float32_u ub; 552 ub.val = b; 553 554 if ((is_float32_nan(ua.data)) || (is_float32_nan(ub.data))) { 555 /* No special constant for unordered - maybe signaled? */ 556 return 1; 557 } 558 559 if (is_float32_eq(ua.data, ub.data)) 560 return 0; 561 562 if (is_float32_lt(ua.data, ub.data)) 563 return -1; 564 565 return 1; 566 } 567 568 int __unordsf2(float32_t a, float32_t b) 569 { 570 float32_u ua; 571 ua.val = a; 572 573 float32_u ub; 574 ub.val = b; 575 576 return ((is_float32_nan(ua.data)) || (is_float32_nan(ub.data))); 577 } 578 579 int __aeabi_fcmpgt(float32_t a, float32_t b) 580 { 581 float32_u ua; 582 ua.val = a; 583 584 float32_u ub; 585 ub.val = b; 586 587 if ((is_float32_nan(ua.data)) || (is_float32_nan(ub.data))) { 588 // TODO: sigNaNs 589 return -1; 590 } 591 592 if (is_float32_gt(ua.data, ub.data)) 593 return 1; 594 595 return 0; 596 } 597 598 int __aeabi_fcmplt(float32_t a, float32_t b) 599 { 600 float32_u ua; 601 ua.val = a; 602 603 float32_u ub; 604 ub.val = b; 605 606 if ((is_float32_nan(ua.data)) || (is_float32_nan(ub.data))) { 607 // TODO: sigNaNs 608 return 1; 609 } 610 611 if (is_float32_lt(ua.data, ub.data)) 612 return -1; 613 614 return 0; 615 } 616 617 int __aeabi_fcmpge(float32_t a, float32_t b) 618 { 619 float32_u ua; 620 ua.val = a; 621 622 float32_u ub; 623 ub.val = b; 624 625 if ((is_float32_nan(ua.data)) || (is_float32_nan(ub.data))) { 626 // TODO: sigNaNs 627 return -1; 628 } 629 630 if (is_float32_eq(ua.data, ub.data)) 631 return 0; 632 633 if (is_float32_gt(ua.data, ub.data)) 634 return 1; 635 636 return -1; 637 } 638 639 int __aeabi_fcmpeq(float32_t a, float32_t b) 640 { 641 float32_u ua; 642 ua.val = a; 643 644 float32_u ub; 645 ub.val = b; 646 647 if ((is_float32_nan(ua.data)) || (is_float32_nan(ub.data))) { 648 // TODO: sigNaNs 649 return 1; 650 } 651 652 return is_float32_eq(ua.data, ub.data) - 1; 653 } 654 655 #endif 656 657 #ifdef float64_t 658 659 int __gtdf2(float64_t a, float64_t b) 660 { 661 float64_u ua; 662 ua.val = a; 663 664 float64_u ub; 665 ub.val = b; 666 667 if ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))) { 668 // TODO: sigNaNs 669 return -1; 670 } 671 672 if (is_float64_gt(ua.data, ub.data)) 673 return 1; 674 675 return 0; 676 } 677 678 int __gedf2(float64_t a, float64_t b) 679 { 680 float64_u ua; 681 ua.val = a; 682 683 float64_u ub; 684 ub.val = b; 685 686 if ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))) { 687 // TODO: sigNaNs 688 return -1; 689 } 690 691 if (is_float64_eq(ua.data, ub.data)) 692 return 0; 693 694 if (is_float64_gt(ua.data, ub.data)) 695 return 1; 696 697 return -1; 698 } 699 700 int __ltdf2(float64_t a, float64_t b) 701 { 702 float64_u ua; 703 ua.val = a; 704 705 float64_u ub; 706 ub.val = b; 707 708 if ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))) { 709 // TODO: sigNaNs 710 return 1; 711 } 712 713 if (is_float64_lt(ua.data, ub.data)) 714 return -1; 715 716 return 0; 717 } 718 719 int __ledf2(float64_t a, float64_t b) 720 { 721 float64_u ua; 722 ua.val = a; 723 724 float64_u ub; 725 ub.val = b; 726 727 if ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))) { 728 // TODO: sigNaNs 729 return 1; 730 } 731 732 if (is_float64_eq(ua.data, ub.data)) 733 return 0; 734 735 if (is_float64_lt(ua.data, ub.data)) 736 return -1; 737 738 return 1; 739 } 740 741 int __eqdf2(float64_t a, float64_t b) 742 { 743 float64_u ua; 744 ua.val = a; 745 746 float64_u ub; 747 ub.val = b; 748 749 if ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))) { 750 // TODO: sigNaNs 751 return 1; 752 } 753 754 return is_float64_eq(ua.data, ub.data) - 1; 755 } 756 757 int __nedf2(float64_t a, float64_t b) 758 { 759 /* Strange, but according to GCC documentation */ 760 return __eqdf2(a, b); 761 } 762 763 int __cmpdf2(float64_t a, float64_t b) 764 { 765 float64_u ua; 766 ua.val = a; 767 768 float64_u ub; 769 ub.val = b; 770 771 if ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))) { 772 /* No special constant for unordered - maybe signaled? */ 773 return 1; 774 } 775 776 if (is_float64_eq(ua.data, ub.data)) 777 return 0; 778 779 if (is_float64_lt(ua.data, ub.data)) 780 return -1; 781 782 return 1; 783 } 784 785 int __unorddf2(float64_t a, float64_t b) 786 { 787 float64_u ua; 788 ua.val = a; 789 790 float64_u ub; 791 ub.val = b; 792 793 return ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))); 794 } 795 796 int __aeabi_dcmplt(float64_t a, float64_t b) 797 { 798 float64_u ua; 799 ua.val = a; 800 801 float64_u ub; 802 ub.val = b; 803 804 if ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))) { 805 // TODO: sigNaNs 806 return 1; 807 } 808 809 if (is_float64_lt(ua.data, ub.data)) 810 return -1; 811 812 return 0; 813 } 814 815 int __aeabi_dcmpeq(float64_t a, float64_t b) 816 { 817 float64_u ua; 818 ua.val = a; 819 820 float64_u ub; 821 ub.val = b; 822 823 if ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))) { 824 // TODO: sigNaNs 825 return 1; 826 } 827 828 return is_float64_eq(ua.data, ub.data) - 1; 829 } 830 831 int __aeabi_dcmpgt(float64_t a, float64_t b) 832 { 833 float64_u ua; 834 ua.val = a; 835 836 float64_u ub; 837 ub.val = b; 838 839 if ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))) { 840 // TODO: sigNaNs 841 return -1; 842 } 843 844 if (is_float64_gt(ua.data, ub.data)) 845 return 1; 846 847 return 0; 848 } 849 850 int __aeabi_dcmpge(float64_t a, float64_t b) 851 { 852 float64_u ua; 853 ua.val = a; 854 855 float64_u ub; 856 ub.val = b; 857 858 if ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))) { 859 // TODO: sigNaNs 860 return -1; 861 } 862 863 if (is_float64_eq(ua.data, ub.data)) 864 return 0; 865 866 if (is_float64_gt(ua.data, ub.data)) 867 return 1; 868 869 return -1; 870 } 871 872 int __aeabi_dcmple(float64_t a, float64_t b) 873 { 874 float64_u ua; 875 ua.val = a; 876 877 float64_u ub; 878 ub.val = b; 879 880 if ((is_float64_nan(ua.data)) || (is_float64_nan(ub.data))) { 881 // TODO: sigNaNs 882 return 1; 883 } 884 885 if (is_float64_eq(ua.data, ub.data)) 886 return 0; 887 888 if (is_float64_lt(ua.data, ub.data)) 889 return -1; 890 891 return 1; 892 } 893 894 #endif 895 896 #ifdef float128_t 897 898 int __gttf2(float128_t a, float128_t b) 899 { 900 float128_u ua; 901 ua.val = a; 902 903 float128_u ub; 904 ub.val = b; 905 906 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) { 907 // TODO: sigNaNs 908 return -1; 909 } 910 911 if (is_float128_gt(ua.data, ub.data)) 912 return 1; 913 914 return 0; 915 } 916 917 int __getf2(float128_t a, float128_t b) 918 { 919 float128_u ua; 920 ua.val = a; 921 922 float128_u ub; 923 ub.val = b; 924 925 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) { 926 // TODO: sigNaNs 927 return -1; 928 } 929 930 if (is_float128_eq(ua.data, ub.data)) 931 return 0; 932 933 if (is_float128_gt(ua.data, ub.data)) 934 return 1; 935 936 return -1; 937 } 938 939 int __lttf2(float128_t a, float128_t b) 940 { 941 float128_u ua; 942 ua.val = a; 943 944 float128_u ub; 945 ub.val = b; 946 947 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) { 948 // TODO: sigNaNs 949 return 1; 950 } 951 952 if (is_float128_lt(ua.data, ub.data)) 953 return -1; 954 955 return 0; 956 } 957 958 int __letf2(float128_t a, float128_t b) 959 { 960 float128_u ua; 961 ua.val = a; 962 963 float128_u ub; 964 ub.val = b; 965 966 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) { 967 // TODO: sigNaNs 968 return 1; 969 } 970 971 if (is_float128_eq(ua.data, ub.data)) 972 return 0; 973 974 if (is_float128_lt(ua.data, ub.data)) 975 return -1; 976 977 return 1; 978 } 979 980 int __eqtf2(float128_t a, float128_t b) 981 { 982 float128_u ua; 983 ua.val = a; 984 985 float128_u ub; 986 ub.val = b; 987 988 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) { 989 // TODO: sigNaNs 990 return 1; 991 } 992 993 return is_float128_eq(ua.data, ub.data) - 1; 994 } 995 996 int __netf2(float128_t a, float128_t b) 997 { 998 /* Strange, but according to GCC documentation */ 999 return __eqtf2(a, b); 1000 } 1001 1002 int __cmptf2(float128_t a, float128_t b) 1003 { 1004 float128_u ua; 1005 ua.val = a; 1006 1007 float128_u ub; 1008 ub.val = b; 1009 1010 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) { 1011 /* No special constant for unordered - maybe signaled? */ 1012 return 1; 1013 } 1014 1015 if (is_float128_eq(ua.data, ub.data)) 1016 return 0; 1017 1018 if (is_float128_lt(ua.data, ub.data)) 1019 return -1; 1020 1021 return 1; 1022 } 1023 1024 int __unordtf2(float128_t a, float128_t b) 1025 { 1026 float128_u ua; 1027 ua.val = a; 1028 1029 float128_u ub; 1030 ub.val = b; 1031 1032 return ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))); 1033 } 1034 1035 int _Qp_cmp(float128_t *a, float128_t *b) 1036 { 1037 float128_u ua; 1038 ua.val = *a; 1039 1040 float128_u ub; 1041 ub.val = *b; 1042 1043 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) 1044 return 3; 1045 1046 if (is_float128_eq(ua.data, ub.data)) 1047 return 0; 1048 1049 if (is_float128_lt(ua.data, ub.data)) 1050 return 1; 1051 1052 return 2; 1053 } 1054 1055 int _Qp_cmpe(float128_t *a, float128_t *b) 1056 { 1057 /* Strange, but according to SPARC Compliance Definition */ 1058 return _Qp_cmp(a, b); 1059 } 1060 1061 int _Qp_fgt(float128_t *a, float128_t *b) 1062 { 1063 float128_u ua; 1064 ua.val = *a; 1065 1066 float128_u ub; 1067 ub.val = *b; 1068 1069 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) 1070 return 0; 1071 1072 return is_float128_gt(ua.data, ub.data); 1073 } 1074 1075 int _Qp_fge(float128_t *a, float128_t *b) 1076 { 1077 float128_u ua; 1078 ua.val = *a; 1079 1080 float128_u ub; 1081 ub.val = *b; 1082 1083 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) 1084 return 0; 1085 1086 return is_float128_eq(ua.data, ub.data) || 1087 is_float128_gt(ua.data, ub.data); 1088 } 1089 1090 int _Qp_flt(float128_t *a, float128_t *b) 1091 { 1092 float128_u ua; 1093 ua.val = *a; 1094 1095 float128_u ub; 1096 ub.val = *b; 1097 1098 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) 1099 return 0; 1100 1101 return is_float128_lt(ua.data, ub.data); 1102 } 1103 1104 int _Qp_fle(float128_t *a, float128_t *b) 1105 { 1106 float128_u ua; 1107 ua.val = *a; 1108 1109 float128_u ub; 1110 ub.val = *b; 1111 1112 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) 1113 return 0; 1114 1115 return is_float128_eq(ua.data, ub.data) || 1116 is_float128_lt(ua.data, ub.data); 1117 } 1118 1119 int _Qp_feq(float128_t *a, float128_t *b) 1120 { 1121 float128_u ua; 1122 ua.val = *a; 1123 1124 float128_u ub; 1125 ub.val = *b; 1126 1127 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) 1128 return 0; 1129 1130 return is_float128_eq(ua.data, ub.data); 1131 } 1132 1133 int _Qp_fne(float128_t *a, float128_t *b) 1134 { 1135 float128_u ua; 1136 ua.val = *a; 1137 1138 float128_u ub; 1139 ub.val = *b; 1140 1141 if ((is_float128_nan(ua.data)) || (is_float128_nan(ub.data))) 1142 return 0; 1143 1144 return !is_float128_eq(ua.data, ub.data); 1145 } 1146 1147 #endif 1148 441 1149 /** @} 442 1150 */ -
uspace/lib/softfloat/comparison.h
r2c7fdaa rc0c38c7c 36 36 #ifndef __COMPARISON_H__ 37 37 #define __COMPARISON_H__ 38 39 #include <mathtypes.h> 38 40 39 41 extern int is_float32_nan(float32); … … 77 79 extern int is_float128_gt(float128, float128); 78 80 81 #ifdef float32_t 82 extern int __gtsf2(float32_t, float32_t); 83 extern int __gesf2(float32_t, float32_t); 84 extern int __ltsf2(float32_t, float32_t); 85 extern int __lesf2(float32_t, float32_t); 86 extern int __eqsf2(float32_t, float32_t); 87 extern int __nesf2(float32_t, float32_t); 88 extern int __cmpsf2(float32_t, float32_t); 89 extern int __unordsf2(float32_t, float32_t); 90 extern int __aeabi_fcmpgt(float32_t, float32_t); 91 extern int __aeabi_fcmplt(float32_t, float32_t); 92 extern int __aeabi_fcmpge(float32_t, float32_t); 93 extern int __aeabi_fcmpeq(float32_t, float32_t); 94 #endif 95 96 #ifdef float64_t 97 extern int __gtdf2(float64_t, float64_t); 98 extern int __gedf2(float64_t, float64_t); 99 extern int __ltdf2(float64_t, float64_t); 100 extern int __ledf2(float64_t, float64_t); 101 extern int __eqdf2(float64_t, float64_t); 102 extern int __nedf2(float64_t, float64_t); 103 extern int __cmpdf2(float64_t, float64_t); 104 extern int __unorddf2(float64_t, float64_t); 105 extern int __aeabi_dcmplt(float64_t, float64_t); 106 extern int __aeabi_dcmpeq(float64_t, float64_t); 107 extern int __aeabi_dcmpgt(float64_t, float64_t); 108 extern int __aeabi_dcmpge(float64_t, float64_t); 109 extern int __aeabi_dcmple(float64_t, float64_t); 110 #endif 111 112 #ifdef float128_t 113 extern int __gttf2(float128_t, float128_t); 114 extern int __getf2(float128_t, float128_t); 115 extern int __lttf2(float128_t, float128_t); 116 extern int __letf2(float128_t, float128_t); 117 extern int __eqtf2(float128_t, float128_t); 118 extern int __netf2(float128_t, float128_t); 119 extern int __cmptf2(float128_t, float128_t); 120 extern int __unordtf2(float128_t, float128_t); 121 extern int _Qp_cmp(float128_t *, float128_t *); 122 extern int _Qp_cmpe(float128_t *, float128_t *); 123 extern int _Qp_fgt(float128_t *, float128_t *); 124 extern int _Qp_fge(float128_t *, float128_t *); 125 extern int _Qp_flt(float128_t *, float128_t *); 126 extern int _Qp_fle(float128_t *, float128_t *); 127 extern int _Qp_feq(float128_t *, float128_t *); 128 extern int _Qp_fne(float128_t *, float128_t *); 129 130 #endif 131 79 132 #endif 80 133 -
uspace/lib/softfloat/conversion.c
r2c7fdaa rc0c38c7c 34 34 */ 35 35 36 #include "sftypes.h"37 36 #include "conversion.h" 38 37 #include "comparison.h" … … 1037 1036 } 1038 1037 1038 #ifdef float32_t 1039 1040 float32_t __floatsisf(int32_t i) 1041 { 1042 float32_u res; 1043 res.data = int32_to_float32(i); 1044 1045 return res.val; 1046 } 1047 1048 float32_t __floatdisf(int64_t i) 1049 { 1050 float32_u res; 1051 res.data = int64_to_float32(i); 1052 1053 return res.val; 1054 } 1055 1056 float32_t __floatunsisf(uint32_t i) 1057 { 1058 float32_u res; 1059 res.data = uint32_to_float32(i); 1060 1061 return res.val; 1062 } 1063 1064 float32_t __floatundisf(uint64_t i) 1065 { 1066 float32_u res; 1067 res.data = uint64_to_float32(i); 1068 1069 return res.val; 1070 } 1071 1072 int32_t __fixsfsi(float32_t a) 1073 { 1074 float32_u ua; 1075 ua.val = a; 1076 1077 return float32_to_int32(ua.data); 1078 } 1079 1080 int64_t __fixsfdi(float32_t a) 1081 { 1082 float32_u ua; 1083 ua.val = a; 1084 1085 return float32_to_int64(ua.data); 1086 } 1087 1088 uint32_t __fixunssfsi(float32_t a) 1089 { 1090 float32_u ua; 1091 ua.val = a; 1092 1093 return float32_to_uint32(ua.data); 1094 } 1095 1096 uint64_t __fixunssfdi(float32_t a) 1097 { 1098 float32_u ua; 1099 ua.val = a; 1100 1101 return float32_to_uint64(ua.data); 1102 } 1103 1104 int32_t __aeabi_f2iz(float32_t a) 1105 { 1106 float32_u ua; 1107 ua.val = a; 1108 1109 return float32_to_int32(ua.data); 1110 } 1111 1112 uint32_t __aeabi_f2uiz(float32_t a) 1113 { 1114 float32_u ua; 1115 ua.val = a; 1116 1117 return float32_to_uint32(ua.data); 1118 } 1119 1120 float32_t __aeabi_i2f(int32_t i) 1121 { 1122 float32_u res; 1123 res.data = int32_to_float32(i); 1124 1125 return res.val; 1126 } 1127 1128 float32_t __aeabi_l2f(int64_t i) 1129 { 1130 float32_u res; 1131 res.data = int64_to_float32(i); 1132 1133 return res.val; 1134 } 1135 1136 float32_t __aeabi_ui2f(uint32_t i) 1137 { 1138 float32_u res; 1139 res.data = uint32_to_float32(i); 1140 1141 return res.val; 1142 } 1143 1144 float32_t __aeabi_ul2f(uint64_t i) 1145 { 1146 float32_u res; 1147 res.data = uint64_to_float32(i); 1148 1149 return res.val; 1150 } 1151 1152 #endif 1153 1154 #ifdef float64_t 1155 1156 float64_t __floatsidf(int32_t i) 1157 { 1158 float64_u res; 1159 res.data = int32_to_float64(i); 1160 1161 return res.val; 1162 } 1163 1164 float64_t __floatdidf(int64_t i) 1165 { 1166 float64_u res; 1167 res.data = int64_to_float64(i); 1168 1169 return res.val; 1170 } 1171 1172 float64_t __floatunsidf(uint32_t i) 1173 { 1174 float64_u res; 1175 res.data = uint32_to_float64(i); 1176 1177 return res.val; 1178 } 1179 1180 float64_t __floatundidf(uint64_t i) 1181 { 1182 float64_u res; 1183 res.data = uint64_to_float64(i); 1184 1185 return res.val; 1186 } 1187 1188 uint32_t __fixunsdfsi(float64_t a) 1189 { 1190 float64_u ua; 1191 ua.val = a; 1192 1193 return float64_to_uint32(ua.data); 1194 } 1195 1196 uint64_t __fixunsdfdi(float64_t a) 1197 { 1198 float64_u ua; 1199 ua.val = a; 1200 1201 return float64_to_uint64(ua.data); 1202 } 1203 1204 int32_t __fixdfsi(float64_t a) 1205 { 1206 float64_u ua; 1207 ua.val = a; 1208 1209 return float64_to_int32(ua.data); 1210 } 1211 1212 int64_t __fixdfdi(float64_t a) 1213 { 1214 float64_u ua; 1215 ua.val = a; 1216 1217 return float64_to_int64(ua.data); 1218 } 1219 1220 float64_t __aeabi_i2d(int32_t i) 1221 { 1222 float64_u res; 1223 res.data = int32_to_float64(i); 1224 1225 return res.val; 1226 } 1227 1228 float64_t __aeabi_ui2d(uint32_t i) 1229 { 1230 float64_u res; 1231 res.data = uint32_to_float64(i); 1232 1233 return res.val; 1234 } 1235 1236 float64_t __aeabi_l2d(int64_t i) 1237 { 1238 float64_u res; 1239 res.data = int64_to_float64(i); 1240 1241 return res.val; 1242 } 1243 1244 int32_t __aeabi_d2iz(float64_t a) 1245 { 1246 float64_u ua; 1247 ua.val = a; 1248 1249 return float64_to_int32(ua.data); 1250 } 1251 1252 int64_t __aeabi_d2lz(float64_t a) 1253 { 1254 float64_u ua; 1255 ua.val = a; 1256 1257 return float64_to_int64(ua.data); 1258 } 1259 1260 uint32_t __aeabi_d2uiz(float64_t a) 1261 { 1262 float64_u ua; 1263 ua.val = a; 1264 1265 return float64_to_uint32(ua.data); 1266 } 1267 1268 #endif 1269 1270 #ifdef float128_t 1271 1272 float128_t __floatsitf(int32_t i) 1273 { 1274 float128_u res; 1275 res.data = int32_to_float128(i); 1276 1277 return res.val; 1278 } 1279 1280 float128_t __floatditf(int64_t i) 1281 { 1282 float128_u res; 1283 res.data = int64_to_float128(i); 1284 1285 return res.val; 1286 } 1287 1288 float128_t __floatunsitf(uint32_t i) 1289 { 1290 float128_u res; 1291 res.data = uint32_to_float128(i); 1292 1293 return res.val; 1294 } 1295 1296 float128_t __floatunditf(uint64_t i) 1297 { 1298 float128_u res; 1299 res.data = uint64_to_float128(i); 1300 1301 return res.val; 1302 } 1303 1304 int32_t __fixtfsi(float128_t a) 1305 { 1306 float128_u ua; 1307 ua.val = a; 1308 1309 return float128_to_int32(ua.data); 1310 } 1311 1312 int64_t __fixtfdi(float128_t a) 1313 { 1314 float128_u ua; 1315 ua.val = a; 1316 1317 return float128_to_uint64(ua.data); 1318 } 1319 1320 uint32_t __fixunstfsi(float128_t a) 1321 { 1322 float128_u ua; 1323 ua.val = a; 1324 1325 return float128_to_uint32(ua.data); 1326 } 1327 1328 uint64_t __fixunstfdi(float128_t a) 1329 { 1330 float128_u ua; 1331 ua.val = a; 1332 1333 return float128_to_uint64(ua.data); 1334 } 1335 1336 int32_t _Qp_qtoi(float128_t *a) 1337 { 1338 return __fixtfsi(*a); 1339 } 1340 1341 int64_t _Qp_qtox(float128_t *a) 1342 { 1343 return __fixunstfdi(*a); 1344 } 1345 1346 uint32_t _Qp_qtoui(float128_t *a) 1347 { 1348 return __fixunstfsi(*a); 1349 } 1350 1351 uint64_t _Qp_qtoux(float128_t *a) 1352 { 1353 return __fixunstfdi(*a); 1354 } 1355 1356 void _Qp_itoq(float128_t *c, int32_t a) 1357 { 1358 *c = __floatsitf(a); 1359 } 1360 1361 void _Qp_xtoq(float128_t *c, int64_t a) 1362 { 1363 *c = __floatditf(a); 1364 } 1365 1366 void _Qp_uitoq(float128_t *c, uint32_t a) 1367 { 1368 *c = __floatunsitf(a); 1369 } 1370 1371 void _Qp_uxtoq(float128_t *c, uint64_t a) 1372 { 1373 *c = __floatunditf(a); 1374 } 1375 1376 #endif 1377 1378 #if (defined(float32_t) && defined(float64_t)) 1379 1380 float32_t __truncdfsf2(float64_t a) 1381 { 1382 float64_u ua; 1383 ua.val = a; 1384 1385 float32_u res; 1386 res.data = float64_to_float32(ua.data); 1387 1388 return res.val; 1389 } 1390 1391 float64_t __extendsfdf2(float32_t a) 1392 { 1393 float32_u ua; 1394 ua.val = a; 1395 1396 float64_u res; 1397 res.data = float32_to_float64(ua.data); 1398 1399 return res.val; 1400 } 1401 1402 float64_t __aeabi_f2d(float32_t a) 1403 { 1404 float32_u ua; 1405 ua.val = a; 1406 1407 float64_u res; 1408 res.data = float32_to_float64(ua.data); 1409 1410 return res.val; 1411 } 1412 1413 float32_t __aeabi_d2f(float64_t a) 1414 { 1415 float64_u ua; 1416 ua.val = a; 1417 1418 float32_u res; 1419 res.data = float64_to_float32(ua.data); 1420 1421 return res.val; 1422 } 1423 1424 #endif 1425 1426 #if (defined(float32_t) && defined(float128_t)) 1427 1428 float32_t __trunctfsf2(float128_t a) 1429 { 1430 float128_u ua; 1431 ua.val = a; 1432 1433 float32_u res; 1434 res.data = float128_to_float32(ua.data); 1435 1436 return res.val; 1437 } 1438 1439 float128_t __extendsftf2(float32_t a) 1440 { 1441 float32_u ua; 1442 ua.val = a; 1443 1444 float128_u res; 1445 res.data = float32_to_float128(ua.data); 1446 1447 return res.val; 1448 } 1449 1450 void _Qp_stoq(float128_t *c, float32_t a) 1451 { 1452 *c = __extendsftf2(a); 1453 } 1454 1455 float32_t _Qp_qtos(float128_t *a) 1456 { 1457 return __trunctfsf2(*a); 1458 } 1459 1460 #endif 1461 1462 #if (defined(float64_t) && defined(float128_t)) 1463 1464 float64_t __trunctfdf2(float128_t a) 1465 { 1466 float128_u ua; 1467 ua.val = a; 1468 1469 float64_u res; 1470 res.data = float128_to_float64(ua.data); 1471 1472 return res.val; 1473 } 1474 1475 float128_t __extenddftf2(float64_t a) 1476 { 1477 float64_u ua; 1478 ua.val = a; 1479 1480 float128_u res; 1481 res.data = float64_to_float128(ua.data); 1482 1483 return res.val; 1484 } 1485 1486 void _Qp_dtoq(float128_t *c, float64_t a) 1487 { 1488 *c = __extenddftf2(a); 1489 } 1490 1491 float64_t _Qp_qtod(float128_t *a) 1492 { 1493 return __trunctfdf2(*a); 1494 } 1495 1496 #endif 1497 1039 1498 /** @} 1040 1499 */ -
uspace/lib/softfloat/conversion.h
r2c7fdaa rc0c38c7c 36 36 #ifndef __CONVERSION_H__ 37 37 #define __CONVERSION_H__ 38 39 #include <mathtypes.h> 38 40 39 41 extern float64 float32_to_float64(float32); … … 99 101 extern float128 int64_to_float128(int64_t); 100 102 103 #ifdef float32_t 104 extern float32_t __floatsisf(int32_t); 105 extern float32_t __floatdisf(int64_t); 106 extern float32_t __floatunsisf(uint32_t); 107 extern float32_t __floatundisf(uint64_t); 108 extern int32_t __fixsfsi(float32_t); 109 extern int64_t __fixsfdi(float32_t); 110 extern uint32_t __fixunssfsi(float32_t); 111 extern uint64_t __fixunssfdi(float32_t); 112 extern int32_t __aeabi_f2iz(float32_t); 113 extern uint32_t __aeabi_f2uiz(float32_t); 114 extern float32_t __aeabi_i2f(int32_t); 115 extern float32_t __aeabi_l2f(int64_t); 116 extern float32_t __aeabi_ui2f(uint32_t); 117 extern float32_t __aeabi_ul2f(uint64_t); 118 #endif 119 120 #ifdef float64_t 121 extern float64_t __floatsidf(int32_t); 122 extern float64_t __floatdidf(int64_t); 123 extern float64_t __floatunsidf(uint32_t); 124 extern float64_t __floatundidf(uint64_t); 125 extern int32_t __fixdfsi(float64_t); 126 extern int64_t __fixdfdi(float64_t); 127 extern uint32_t __fixunsdfsi(float64_t); 128 extern uint64_t __fixunsdfdi(float64_t); 129 extern float64_t __aeabi_i2d(int32_t); 130 extern float64_t __aeabi_ui2d(uint32_t); 131 extern float64_t __aeabi_l2d(int64_t); 132 extern int32_t __aeabi_d2iz(float64_t); 133 extern int64_t __aeabi_d2lz(float64_t); 134 extern uint32_t __aeabi_d2uiz(float64_t); 135 #endif 136 137 #ifdef float128_t 138 extern float128_t __floatsitf(int32_t); 139 extern float128_t __floatditf(int64_t); 140 extern float128_t __floatunsitf(uint32_t); 141 extern float128_t __floatunditf(uint64_t); 142 extern int32_t __fixtfsi(float128_t); 143 extern int64_t __fixtfdi(float128_t); 144 extern uint32_t __fixunstfsi(float128_t); 145 extern uint64_t __fixunstfdi(float128_t); 146 extern int32_t _Qp_qtoi(float128_t *); 147 extern int64_t _Qp_qtox(float128_t *); 148 extern uint32_t _Qp_qtoui(float128_t *); 149 extern uint64_t _Qp_qtoux(float128_t *); 150 extern void _Qp_itoq(float128_t *, int32_t); 151 extern void _Qp_xtoq(float128_t *, int64_t); 152 extern void _Qp_uitoq(float128_t *, uint32_t); 153 extern void _Qp_uxtoq(float128_t *, uint64_t); 154 #endif 155 156 #if (defined(float32_t) && defined(float64_t)) 157 extern float32_t __truncdfsf2(float64_t); 158 extern float64_t __extendsfdf2(float32_t); 159 extern float64_t __aeabi_f2d(float32_t); 160 extern float32_t __aeabi_d2f(float64_t); 161 #endif 162 163 #if (defined(float32_t) && defined(float128_t)) 164 extern float32_t __trunctfsf2(float128_t); 165 extern float128_t __extendsftf2(float32_t); 166 extern void _Qp_stoq(float128_t *, float32_t); 167 extern float32_t _Qp_qtos(float128_t *); 168 #endif 169 170 #if (defined(float64_t) && defined(float128_t)) 171 extern float64_t __trunctfdf2(float128_t); 172 extern float128_t __extenddftf2(float64_t); 173 extern void _Qp_dtoq(float128_t *, float64_t); 174 extern float64_t _Qp_qtod(float128_t *); 175 #endif 176 101 177 #endif 102 178 -
uspace/lib/softfloat/div.c
r2c7fdaa rc0c38c7c 34 34 */ 35 35 36 #include "sftypes.h"37 36 #include "add.h" 38 37 #include "div.h" … … 539 538 } 540 539 540 #ifdef float32_t 541 542 float32_t __divsf3(float32_t a, float32_t b) 543 { 544 float32_u ua; 545 ua.val = a; 546 547 float32_u ub; 548 ub.val = b; 549 550 float32_u res; 551 res.data = div_float32(ua.data, ub.data); 552 553 return res.val; 554 } 555 556 float32_t __aeabi_fdiv(float32_t a, float32_t b) 557 { 558 float32_u ua; 559 ua.val = a; 560 561 float32_u ub; 562 ub.val = b; 563 564 float32_u res; 565 res.data = div_float32(ua.data, ub.data); 566 567 return res.val; 568 } 569 570 #endif 571 572 #ifdef float64_t 573 574 float64_t __divdf3(float64_t a, float64_t b) 575 { 576 float64_u ua; 577 ua.val = a; 578 579 float64_u ub; 580 ub.val = b; 581 582 float64_u res; 583 res.data = div_float64(ua.data, ub.data); 584 585 return res.val; 586 } 587 588 float64_t __aeabi_ddiv(float64_t a, float64_t b) 589 { 590 float64_u ua; 591 ua.val = a; 592 593 float64_u ub; 594 ub.val = b; 595 596 float64_u res; 597 res.data = div_float64(ua.data, ub.data); 598 599 return res.val; 600 } 601 602 #endif 603 604 #ifdef float128_t 605 606 float128_t __divtf3(float128_t a, float128_t b) 607 { 608 float128_u ua; 609 ua.val = a; 610 611 float128_u ub; 612 ub.val = b; 613 614 float128_u res; 615 res.data = div_float128(ua.data, ub.data); 616 617 return res.val; 618 } 619 620 void _Qp_div(float128_t *c, float128_t *a, float128_t *b) 621 { 622 *c = __divtf3(*a, *b); 623 } 624 625 #endif 626 541 627 /** @} 542 628 */ -
uspace/lib/softfloat/div.h
r2c7fdaa rc0c38c7c 42 42 extern float128 div_float128(float128, float128); 43 43 44 #ifdef float32_t 45 extern float32_t __divsf3(float32_t, float32_t); 46 extern float32_t __aeabi_fdiv(float32_t, float32_t); 47 #endif 48 49 #ifdef float64_t 50 extern float64_t __divdf3(float64_t, float64_t); 51 extern float64_t __aeabi_ddiv(float64_t, float64_t); 52 #endif 53 54 #ifdef float128_t 55 extern float128_t __divtf3(float128_t, float128_t); 56 extern void _Qp_div(float128_t *, float128_t *, float128_t *); 57 #endif 58 44 59 #endif 45 60 -
uspace/lib/softfloat/mul.c
r2c7fdaa rc0c38c7c 34 34 */ 35 35 36 #include "sftypes.h"37 36 #include "mul.h" 38 37 #include "comparison.h" … … 62 61 return result; 63 62 } 63 64 64 if (is_float32_signan(b)) { /* TODO: fix SigNaN */ 65 65 result.parts.fraction = b.parts.fraction; … … 67 67 return result; 68 68 } 69 69 70 /* set NaN as result */ 70 71 result.bin = FLOAT32_NAN; … … 78 79 return result; 79 80 } 81 80 82 result.parts.fraction = a.parts.fraction; 81 83 result.parts.exp = a.parts.exp; … … 89 91 return result; 90 92 } 93 91 94 result.parts.fraction = b.parts.fraction; 92 95 result.parts.exp = b.parts.exp; … … 106 109 } 107 110 108 if (exp < 0) { 111 if (exp < 0) { 109 112 /* FIXME: underflow */ 110 113 /* return signed zero */ … … 164 167 /* denormalized number */ 165 168 frac1 >>= 1; /* denormalize */ 169 166 170 while ((frac1 > 0) && (exp < 0)) { 167 171 frac1 >>= 1; 168 172 ++exp; 169 173 } 174 170 175 if (frac1 == 0) { 171 176 /* FIXME : underflow */ … … 175 180 } 176 181 } 182 177 183 result.parts.exp = exp; 178 184 result.parts.fraction = frac1 & ((1 << FLOAT32_FRACTION_SIZE) - 1); … … 380 386 } 381 387 388 #ifdef float32_t 389 390 float32_t __mulsf3(float32_t a, float32_t b) 391 { 392 float32_u ua; 393 ua.val = a; 394 395 float32_u ub; 396 ub.val = b; 397 398 float32_u res; 399 res.data = mul_float32(ua.data, ub.data); 400 401 return res.val; 402 } 403 404 float32_t __aeabi_fmul(float32_t a, float32_t b) 405 { 406 float32_u ua; 407 ua.val = a; 408 409 float32_u ub; 410 ub.val = b; 411 412 float32_u res; 413 res.data = mul_float32(ua.data, ub.data); 414 415 return res.val; 416 } 417 418 #endif 419 420 #ifdef float64_t 421 422 float64_t __muldf3(float64_t a, float64_t b) 423 { 424 float64_u ua; 425 ua.val = a; 426 427 float64_u ub; 428 ub.val = b; 429 430 float64_u res; 431 res.data = mul_float64(ua.data, ub.data); 432 433 return res.val; 434 } 435 436 float64_t __aeabi_dmul(float64_t a, float64_t b) 437 { 438 float64_u ua; 439 ua.val = a; 440 441 float64_u ub; 442 ub.val = b; 443 444 float64_u res; 445 res.data = mul_float64(ua.data, ub.data); 446 447 return res.val; 448 } 449 450 #endif 451 452 #ifdef float128_t 453 454 float128_t __multf3(float128_t a, float128_t b) 455 { 456 float128_u ua; 457 ua.val = a; 458 459 float128_u ub; 460 ub.val = b; 461 462 float128_u res; 463 res.data = mul_float128(ua.data, ub.data); 464 465 return res.val; 466 } 467 468 void _Qp_mul(float128_t *c, float128_t *a, float128_t *b) 469 { 470 *c = __multf3(*a, *b); 471 } 472 473 #endif 474 382 475 /** @} 383 476 */ -
uspace/lib/softfloat/mul.h
r2c7fdaa rc0c38c7c 37 37 #define __MUL_H__ 38 38 39 #include <mathtypes.h> 40 39 41 extern float32 mul_float32(float32, float32); 40 42 extern float64 mul_float64(float64, float64); … … 42 44 extern float128 mul_float128(float128, float128); 43 45 46 #ifdef float32_t 47 extern float32_t __mulsf3(float32_t, float32_t); 48 extern float32_t __aeabi_fmul(float32_t, float32_t); 49 #endif 50 51 #ifdef float64_t 52 extern float64_t __muldf3(float64_t, float64_t); 53 extern float64_t __aeabi_dmul(float64_t, float64_t); 54 #endif 55 56 #ifdef float128_t 57 extern float128_t __multf3(float128_t, float128_t); 58 extern void _Qp_mul(float128_t *, float128_t *, float128_t *); 59 #endif 60 44 61 #endif 45 62 -
uspace/lib/softfloat/sub.c
r2c7fdaa rc0c38c7c 34 34 */ 35 35 36 #include "sftypes.h"37 36 #include "sub.h" 38 37 #include "comparison.h" 39 38 #include "common.h" 39 #include "add.h" 40 40 41 41 /** Subtract two single-precision floats with the same sign. … … 438 438 } 439 439 440 #ifdef float32_t 441 442 float32_t __subsf3(float32_t a, float32_t b) 443 { 444 float32_u ua; 445 ua.val = a; 446 447 float32_u ub; 448 ub.val = b; 449 450 float32_u res; 451 452 if (ua.data.parts.sign != ub.data.parts.sign) { 453 ub.data.parts.sign = !ub.data.parts.sign; 454 res.data = add_float32(ua.data, ub.data); 455 } else 456 res.data = sub_float32(ua.data, ub.data); 457 458 return res.val; 459 } 460 461 float32_t __aeabi_fsub(float32_t a, float32_t b) 462 { 463 float32_u ua; 464 ua.val = a; 465 466 float32_u ub; 467 ub.val = b; 468 469 float32_u res; 470 471 if (ua.data.parts.sign != ub.data.parts.sign) { 472 ub.data.parts.sign = !ub.data.parts.sign; 473 res.data = add_float32(ua.data, ub.data); 474 } else 475 res.data = sub_float32(ua.data, ub.data); 476 477 return res.val; 478 } 479 480 #endif 481 482 #ifdef float64_t 483 484 float64_t __subdf3(float64_t a, float64_t b) 485 { 486 float64_u ua; 487 ua.val = a; 488 489 float64_u ub; 490 ub.val = b; 491 492 float64_u res; 493 494 if (ua.data.parts.sign != ub.data.parts.sign) { 495 ub.data.parts.sign = !ub.data.parts.sign; 496 res.data = add_float64(ua.data, ub.data); 497 } else 498 res.data = sub_float64(ua.data, ub.data); 499 500 return res.val; 501 } 502 503 float64_t __aeabi_dsub(float64_t a, float64_t b) 504 { 505 float64_u ua; 506 ua.val = a; 507 508 float64_u ub; 509 ub.val = b; 510 511 float64_u res; 512 513 if (ua.data.parts.sign != ub.data.parts.sign) { 514 ub.data.parts.sign = !ub.data.parts.sign; 515 res.data = add_float64(ua.data, ub.data); 516 } else 517 res.data = sub_float64(ua.data, ub.data); 518 519 return res.val; 520 } 521 522 #endif 523 524 #ifdef float128_t 525 526 float128_t __subtf3(float128_t a, float128_t b) 527 { 528 float128_u ua; 529 ua.val = a; 530 531 float128_u ub; 532 ub.val = b; 533 534 float128_u res; 535 536 if (ua.data.parts.sign != ub.data.parts.sign) { 537 ub.data.parts.sign = !ub.data.parts.sign; 538 res.data = add_float128(ua.data, ub.data); 539 } else 540 res.data = sub_float128(ua.data, ub.data); 541 542 return res.val; 543 } 544 545 void _Qp_sub(float128_t *c, float128_t *a, float128_t *b) 546 { 547 *c = __subtf3(*a, *b); 548 } 549 550 #endif 551 440 552 /** @} 441 553 */ -
uspace/lib/softfloat/sub.h
r2c7fdaa rc0c38c7c 37 37 #define __SUB_H__ 38 38 39 #include <mathtypes.h> 40 39 41 extern float32 sub_float32(float32, float32); 40 42 extern float64 sub_float64(float64, float64); … … 42 44 extern float128 sub_float128(float128, float128); 43 45 46 #ifdef float32_t 47 extern float32_t __subsf3(float32_t, float32_t); 48 extern float32_t __aeabi_fsub(float32_t, float32_t); 49 #endif 50 51 #ifdef float64_t 52 extern float64_t __subdf3(float64_t, float64_t); 53 extern float64_t __aeabi_dsub(float64_t, float64_t); 54 #endif 55 56 #ifdef float128_t 57 extern float128_t __subtf3(float128_t, float128_t); 58 extern void _Qp_sub(float128_t *, float128_t *, float128_t *); 59 #endif 60 44 61 #endif 45 62
Note:
See TracChangeset
for help on using the changeset viewer.