History

partial revert of the commit 4ad186c5ef61 A test program:

/* result of the new version inroduced in 4ad186c5ef61: t2a = 44100312 */ #include<stdio.h> int main() { int t1 = 176401255; float f = 0.25f; int t2a = (int)(t1 * f); // must be 44100313 int t2b = (int)(t1 * (float)0.25f); printf("t2a=%d t2b=%d \n",t2a,t2b); return 0; }

seyko committed 11 years ago

Commit 664c19a1 parent bfb7b0d3 files · +41 −0Browse files

Unified · Split

3 files
  1. i386-gen.c +23 −0
  2. lib/libtcc1.c +14 −0
  3. tcctok.h +4 −0
i386-gen.c+23−0
@@ -982,6 +982,28 @@ ST_FUNC void gen_cvt_itof(int t) · 981 unmodified lines
982/* convert fp to int 't' type */982/* convert fp to int 't' type */
983ST_FUNC void gen_cvt_ftoi(int t)983ST_FUNC void gen_cvt_ftoi(int t)
984{984{
985 #ifndef COMMIT_4ad186c5ef61_IS_FIXED
986 /* a good version but it takes a more time to execute */
987 gv(RC_FLOAT);
988 save_reg(TREG_EAX);
989 save_reg(TREG_EDX);
990 gen_static_call(TOK___tcc_cvt_ftol);
991 vtop->r = TREG_EAX; /* mark reg as used */
992 if (t == VT_LLONG)
993 vtop->r2 = TREG_EDX;
994 #else
995 /* a new version with a bug: t2a = 44100312 */
996 /*
997 #include<stdio.h>
998 int main() {
999 int t1 = 176401255;
1000 float f = 0.25f;
1001 int t2a = (int)(t1 * f); // must be 44100313
1002 int t2b = (int)(t1 * (float)0.25f);
1003 printf("t2a=%d t2b=%d \n",t2a,t2b);
1004 return 0;
1005 }
1006 */
985 int bt = vtop->type.t & VT_BTYPE;1007 int bt = vtop->type.t & VT_BTYPE;
986 if (bt == VT_FLOAT)1008 if (bt == VT_FLOAT)
987 vpush_global_sym(&func_old_type, TOK___fixsfdi);1009 vpush_global_sym(&func_old_type, TOK___fixsfdi);
@@ -994,6 +1016,7 @@ ST_FUNC void gen_cvt_ftoi(int t) · 6 unmodified lines
994 vpushi(0);1016 vpushi(0);
995 vtop->r = REG_IRET;1017 vtop->r = REG_IRET;
996 vtop->r2 = REG_LRET;1018 vtop->r2 = REG_LRET;
1019 #endif
997}1020}
998 1021
999/* convert from one floating point type to another */1022/* convert from one floating point type to another */
lib/libtcc1.c+14−0
@@ -480,6 +480,20 @@ long long __ashldi3(long long a, int b) · 479 unmodified lines
480#endif480#endif
481}481}
482 482
483#ifndef COMMIT_4ad186c5ef61_IS_FIXED
484long long __tcc_cvt_ftol(long double x)
485{
486 unsigned c0, c1;
487 long long ret;
488 __asm__ __volatile__ ("fnstcw %0" : "=m" (c0));
489 c1 = c0 | 0x0C00;
490 __asm__ __volatile__ ("fldcw %0" : : "m" (c1));
491 __asm__ __volatile__ ("fistpll %0" : "=m" (ret));
492 __asm__ __volatile__ ("fldcw %0" : : "m" (c0));
493 return ret;
494}
495#endif
496
483#endif /* !__x86_64__ */497#endif /* !__x86_64__ */
484 498
485/* XXX: fix tcc's code generator to do this instead */499/* XXX: fix tcc's code generator to do this instead */
tcctok.h+4−0
@@ -229,6 +229,10 @@ · 228 unmodified lines
229 DEF(TOK___fixsfdi, "__fixsfdi")229 DEF(TOK___fixsfdi, "__fixsfdi")
230 DEF(TOK___fixdfdi, "__fixdfdi")230 DEF(TOK___fixdfdi, "__fixdfdi")
231 DEF(TOK___fixxfdi, "__fixxfdi")231 DEF(TOK___fixxfdi, "__fixxfdi")
232
233 #ifndef COMMIT_4ad186c5ef61_IS_FIXED
234 DEF(TOK___tcc_cvt_ftol, "__tcc_cvt_ftol")
235 #endif
232#endif236#endif
233 237
234#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64238#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t