aboutsummaryrefslogtreecommitdiff
path: root/i386-gen.c
diff options
context:
space:
mode:
authorseyko <seyko2@gmail.com>2015-03-04 16:25:51 +0300
committerseyko <seyko2@gmail.com>2015-03-04 16:25:51 +0300
commit664c19ad5ef16f3463087a33ecfe5d5ac24f81ec (patch)
treeb80af984089291b8f4dd67b9643af8f7e74e14a5 /i386-gen.c
parentbfb7b0d9590d82dfb4f3b142d7d30960567fec43 (diff)
downloadtinycc-664c19ad5ef16f3463087a33ecfe5d5ac24f81ec.tar.gz
tinycc-664c19ad5ef16f3463087a33ecfe5d5ac24f81ec.tar.bz2
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; }
Diffstat (limited to 'i386-gen.c')
-rw-r--r--i386-gen.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/i386-gen.c b/i386-gen.c
index eca4ddd..9bdf998 100644
--- a/i386-gen.c
+++ b/i386-gen.c
@@ -982,6 +982,28 @@ ST_FUNC void gen_cvt_itof(int t)
/* convert fp to int 't' type */
ST_FUNC void gen_cvt_ftoi(int t)
{
+ #ifndef COMMIT_4ad186c5ef61_IS_FIXED
+ /* a good version but it takes a more time to execute */
+ gv(RC_FLOAT);
+ save_reg(TREG_EAX);
+ save_reg(TREG_EDX);
+ gen_static_call(TOK___tcc_cvt_ftol);
+ vtop->r = TREG_EAX; /* mark reg as used */
+ if (t == VT_LLONG)
+ vtop->r2 = TREG_EDX;
+ #else
+ /* a new version with a bug: 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;
+ }
+ */
int bt = vtop->type.t & VT_BTYPE;
if (bt == VT_FLOAT)
vpush_global_sym(&func_old_type, TOK___fixsfdi);
@@ -994,6 +1016,7 @@ ST_FUNC void gen_cvt_ftoi(int t)
vpushi(0);
vtop->r = REG_IRET;
vtop->r2 = REG_LRET;
+ #endif
}
/* convert from one floating point type to another */