1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-18 07:29:36 +00:00

fix division and multiplication for intvar vs floatvar

This commit is contained in:
mrdudz 2023-09-02 06:53:33 +02:00
parent f0eadc69e1
commit c48cf428e9
4 changed files with 57 additions and 12 deletions

View File

@ -93,7 +93,7 @@ NOT WORKING YET:
/test/val/float-basic-var-intconst.c *, /, +=, -=, *=, /=
/test/val/float-basic-intvar-const.c +=, -=, *=, /=
/test/val/float-basic-intvar-var.c *, /, +=, /=
/test/val/float-basic-intvar-var.c +=, /=
/test/val/float-basic-intconst-var.c *, /
/test/val/float-cmp-const-intvar.c

View File

@ -4,7 +4,7 @@
** 2020-11-20, Greg King
*/
//#define DEBUG
#define DEBUG
#include <stdio.h>
#include <stdlib.h>
@ -2475,15 +2475,48 @@ LOG(("hie_internal Expr->Type:%s Expr2->Type:%s\n",
ltype |= CF_PRIMARY; /* Value is in register */
}
}
LOG(("hie_internal ?2a ltype:%4x rconst: %d rtype:%4x\n", ltype, rconst, rtype));
/* Determine the type of the operation result. */
type |= g_typeadjust (ltype, rtype);
LOG(("hie_internal ?2b ltype:%4x rconst: %d rtype:%4x type:%04x .Expr.Type:%04x Expr2.Type:%04x\n", ltype, rconst, rtype, type, TypeOf (Expr->Type), TypeOf (Expr2.Type)));
Expr->Type = ArithmeticConvert (Expr->Type, Expr2.Type);
LOG(("hie_internal ?2c Expr->Type:%4x\n", TypeOf (Expr->Type)));
/* Generate code */
if (TypeOf (Expr2.Type) == CF_FLOAT) {
#if 0
Gen->Func (type, FP_D_As32bitRaw(Expr2.V.FVal));
#else
// right side is float
LOG(("hie_internal ?2 rhs float:%x\n", FP_D_As32bitRaw(Expr2.V.FVal)));
if (((ltype & CF_TYPEMASK) != CF_FLOAT) && (!(rtype & CF_CONST))) {
// left side is not float, right side is float
LOG(("hie_internal ?2 lhs not float: %ld ltype const?:%d\n", Expr->IVal, ltype & CF_CONST));
RemoveCode (&Mark2);
LoadExpr(ltype, Expr);
/* Adjust lhs primary if needed */
// type = typeadjust (&Expr2, Expr, 0);
// type = typeadjust (Expr, &Expr2, 1);
// Expr->Type = type_float;
g_regfloat(ltype);
// g_push_float(type & ~CF_CONST, FP_D_As32bitRaw(FP_D_FromInt(Expr->IVal)));
// g_push_float(type & ~CF_CONST, 0);
// RemoveCode (&Mark2);
g_push(type, 0);
LoadExpr(CF_FLOAT, &Expr2);
// left side is not float, right side is float
Gen->Func (type, FP_D_As32bitRaw(Expr2.V.FVal));
} else {
// left side is float, right side is float
LOG(("hie_internal ?2 lhs is float: %08x\n", FP_D_As32bitRaw(Expr2.V.FVal)));
Gen->Func (type, FP_D_As32bitRaw(Expr2.V.FVal));
}
// Gen->Func (CF_FLOAT, FP_D_As32bitRaw(Expr2.V.FVal));
// Gen->Func (type, Expr2.IVal);
#endif
} else {
// right side is not float
Gen->Func (type, Expr2.IVal);
}

View File

@ -72,7 +72,7 @@ void intconstvar(void)
{
var_float = 11.123f;
#if 1
fp1 = 47;
printf("fp1:0x%08lx [?] %s (47)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
fp1 = var_float;
@ -87,7 +87,7 @@ void intconstvar(void)
fp1 = 47 - var_float;
printf("fp1:0x%08lx [?] %s (35.877)", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "420f820c");
#endif
#if 0 // compiles, but wrong result
fp1 = 47 * var_float;
printf("fp1:0x%08lx [?] %s (522.781)", *((uint32_t*)&fp1), _ftostr(buf, fp1));

View File

@ -39,6 +39,7 @@ unsigned char var_char;
unsigned int var_int;
float var_float;
#if 1
// returns 1 if value in f matches the string
// the string is a hex value without leading "0x"
int compare(float f, char *str)
@ -82,6 +83,7 @@ void intfloat(void)
{
var_int = 47;
var_float = 11.123f;
#if 1
fp1 = var_int;
printf("fp1:0x%08lx [42687df4] %s (47)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
fp1 = var_float;
@ -95,16 +97,16 @@ void intfloat(void)
fp1 = var_int - var_float;
printf("fp1:0x%08lx [420f820c] %s (35.877)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "420f820c");
#if 0 // Internal compiler error
fp1 = var_int * var_float;
printf("fp1:0x%08lx [42687df4] %s (58.123)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "42687df4");
#endif
#if 0 // Internal compiler error
#if 1
fp1 = var_int * var_float;
printf("fp1:0x%08lx [4402b1fc] %s (522.781)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "4402b1fc");
#endif
#if 1
fp1 = var_int / var_float;
printf("fp1:0x%08lx [42687df4] %s (58.123)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "42687df4");
printf("fp1:0x%08lx [4087371f] %s (4.225)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "4087371f");
#endif
}
@ -161,3 +163,13 @@ int main(void)
printf("\nfloat-basic-intvar-var (res:%d)\n", result);
return result;
}
#else
int main(void)
{
var_int = 47;
var_float = 11.123f;
fp1 = var_int * var_float;
printf("fp1:0x%08lx [42687df4] %s (58.123)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
return result;
}
#endif