There seems nothing wrong. With int t1 = 176401255; float f = 0.25; int t2 = t1 * f; // 176401255 * 0.25 = 44100313.75 according to the arithmetic conversion rules, the number 176401255 needs to be converted to float, and the compiler can choose either the nearest higher or nearest lower representable number "in an implementation-defined manner". Which may be 176401248 or 176401264. So as result both 44100312 and 44100313 are correct. This reverts commit 664c19ad5ef16f3463087a33ecfe5d5ac24f81ec.
Unified · Split
| @@ -1037,15 +1037,6 @@ ST_FUNC void gen_cvt_itof(int t) · 1036 unmodified lines | ||
| 1037 | 1037 | /* convert fp to int 't' type */ |
| 1038 | 1038 | ST_FUNC void gen_cvt_ftoi(int t) |
| 1039 | 1039 | { |
| 1040 | −#if 1 | |
| 1041 | − gv(RC_FLOAT); | |
| 1042 | − save_reg(TREG_EAX); | |
| 1043 | − save_reg(TREG_EDX); | |
| 1044 | − gen_static_call(TOK___tcc_cvt_ftol); | |
| 1045 | − vtop->r = TREG_EAX; /* mark reg as used */ | |
| 1046 | − if (t == VT_LLONG) | |
| 1047 | − vtop->r2 = TREG_EDX; | |
| 1048 | −#else | |
| 1049 | 1040 | int bt = vtop->type.t & VT_BTYPE; |
| 1050 | 1041 | if (bt == VT_FLOAT) |
| 1051 | 1042 | vpush_global_sym(&func_old_type, TOK___fixsfdi); |
| @@ -1058,7 +1049,6 @@ ST_FUNC void gen_cvt_ftoi(int t) · 6 unmodified lines | ||
| 1058 | 1049 | vpushi(0); |
| 1059 | 1050 | vtop->r = REG_IRET; |
| 1060 | 1051 | vtop->r2 = REG_LRET; |
| 1061 | −#endif | |
| 1062 | 1052 | } |
| 1063 | 1053 | |
| 1064 | 1054 | /* convert from one floating point type to another */ |
| @@ -478,18 +478,6 @@ long long __ashldi3(long long a, int b) · 477 unmodified lines | ||
| 478 | 478 | #endif |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | −long long __tcc_cvt_ftol(long double x) | |
| 482 | −{ | |
| 483 | − unsigned c0, c1; | |
| 484 | − long long ret; | |
| 485 | − __asm__ __volatile__ ("fnstcw %0" : "=m" (c0)); | |
| 486 | − c1 = c0 | 0x0C00; | |
| 487 | − __asm__ __volatile__ ("fldcw %0" : : "m" (c1)); | |
| 488 | − __asm__ __volatile__ ("fistpll %0" : "=m" (ret)); | |
| 489 | − __asm__ __volatile__ ("fldcw %0" : : "m" (c0)); | |
| 490 | − return ret; | |
| 491 | −} | |
| 492 | − | |
| 493 | 481 | #endif /* !__x86_64__ */ |
| 494 | 482 | |
| 495 | 483 | /* XXX: fix tcc's code generator to do this instead */ |
| @@ -243,7 +243,6 @@ · 242 unmodified lines | ||
| 243 | 243 | DEF(TOK___fixsfdi, "__fixsfdi") |
| 244 | 244 | DEF(TOK___fixdfdi, "__fixdfdi") |
| 245 | 245 | DEF(TOK___fixxfdi, "__fixxfdi") |
| 246 | − DEF(TOK___tcc_cvt_ftol, "__tcc_cvt_ftol") | |
| 247 | 246 | #endif |
| 248 | 247 | |
| 249 | 248 | #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 |