mirror of
https://github.com/cc65/cc65.git
synced 2024-06-17 16:29:32 +00:00
fix comparing float variable agains float constants
This commit is contained in:
parent
af15ce8223
commit
62e211553b
|
@ -39,7 +39,7 @@
|
|||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
//#define DEBUG
|
||||
#define DEBUG
|
||||
|
||||
/* common */
|
||||
#include "addrsize.h"
|
||||
|
@ -700,8 +700,10 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes)
|
|||
/*****************************************************************************/
|
||||
|
||||
#ifdef DEBUG
|
||||
#define g_getimmed(a,b,c) _g_getimmed((a),(b),(c),(__FILE__),(__FUNCTION__),(__LINE__))
|
||||
void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs, char *file, char *func, int line)
|
||||
//#define g_getimmed(a,b,c) _g_getimmed((a),(b),(c),(__FILE__),(__FUNCTION__),(__LINE__))
|
||||
// void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs, char *file, const char *func, int line)
|
||||
#define g_getimmed(a,b,c) _g_getimmed((a),(b),(c))
|
||||
void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs)
|
||||
#else
|
||||
#define g_getimmed(a,b,c) _g_getimmed((a),(b),(c))
|
||||
void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs)
|
||||
|
@ -711,7 +713,13 @@ void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs)
|
|||
unsigned char B1, B2, B3, B4;
|
||||
unsigned Done;
|
||||
|
||||
LOG(("g_getimmed %s:%d:%s Flags:%04x Val: %08x Offs:%04x\n", file, line, func, Flags, Val, Offs));
|
||||
// LOG(("file:%s\n", file ? file : "null"));
|
||||
// LOG(("func:%s\n", func ? func : "null"));
|
||||
|
||||
// LOG(("g_getimmed %s:%d:%s Flags:%04x Val: %08x Offs:%04x\n",
|
||||
// file ? file : "null", line, func ? func : "null", Flags, Val, Offs));
|
||||
LOG(("g_getimmed Flags:%04x Val: %08x Offs:%04x\n",
|
||||
Flags, Val, Offs));
|
||||
|
||||
if ((Flags & CF_CONST) != 0) {
|
||||
|
||||
|
@ -731,7 +739,9 @@ void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs)
|
|||
|
||||
case CF_FLOAT: /* FIXME float - handle like long here */
|
||||
|
||||
LOG(("g_getimmed CF_FLOAT Val: %08lx\n", Val));
|
||||
LOG(("g_getimmed CF_FLOAT Val: %08lx\n", Val));
|
||||
AddCodeLine ("nop\t; g_getimmed FLOAT %08lx\n", Val); // FIXME: remove
|
||||
/* fall through */
|
||||
case CF_LONG:
|
||||
/* Split the value into 4 bytes */
|
||||
B1 = (unsigned char) (Val >> 0);
|
||||
|
@ -1166,7 +1176,7 @@ void g_putlocal (unsigned Flags, int Offs, long Val)
|
|||
break;
|
||||
|
||||
case CF_FLOAT: /* FIXME: float - can we use the same as LONG here? */
|
||||
|
||||
AddCodeLine ("nop ; g_putlocal"); // FIXME: remove
|
||||
case CF_LONG:
|
||||
if (Flags & CF_CONST) {
|
||||
g_getimmed (Flags, Val, 0);
|
||||
|
@ -1508,16 +1518,21 @@ unsigned g_typeadjust (unsigned lhs, unsigned rhs)
|
|||
/* Result is const if both operands are const. */
|
||||
unsigned const_flag = (lhs & CF_CONST) & (rhs & CF_CONST);
|
||||
|
||||
AddCodeLine ("nop ; g_typeadjust ltype:%x rtype:%x", ltype, rtype); // FIXME: remove
|
||||
|
||||
/* FIXME: float - this is is much more complicated */
|
||||
if (ltype == CF_FLOAT && rtype == CF_FLOAT) {
|
||||
AddCodeLine ("nop ; g_typeadjust return:%x float", const_flag | CF_FLOAT); // FIXME: remove
|
||||
return const_flag | CF_FLOAT;
|
||||
}
|
||||
if (ltype == CF_FLOAT) {
|
||||
FIXME(("FIXME: conversion to float format missing\n"));
|
||||
AddCodeLine ("nop ; g_typeadjust return:%x float", (lhs & CF_CONST) | CF_FLOAT); // FIXME: remove
|
||||
return (lhs & CF_CONST) | CF_FLOAT;
|
||||
}
|
||||
if (rtype == CF_FLOAT) {
|
||||
FIXME("FIXME: conversion to float format missing\n");
|
||||
FIXME(("FIXME: conversion to float format missing\n"));
|
||||
AddCodeLine ("nop ; g_typeadjust return:%x float", (rhs & CF_CONST) | CF_FLOAT); // FIXME: remove
|
||||
return (rhs & CF_CONST) | CF_FLOAT;
|
||||
}
|
||||
|
||||
|
@ -1973,6 +1988,7 @@ void g_addeqlocal (unsigned flags, int Offs, unsigned long val)
|
|||
AddCodeLine ("lda (sp),y");
|
||||
}
|
||||
} else {
|
||||
AddCodeLine ("nop ; g_addeqlocal"); // FIXME: remove
|
||||
g_getimmed (flags, val, 0);
|
||||
AddCodeLine ("jsr addeqysp");
|
||||
}
|
||||
|
@ -1983,6 +1999,7 @@ void g_addeqlocal (unsigned flags, int Offs, unsigned long val)
|
|||
|
||||
case CF_LONG:
|
||||
if (flags & CF_CONST) {
|
||||
AddCodeLine ("nop ; g_addeqlocal"); // FIXME: remove
|
||||
g_getimmed (flags, val, 0);
|
||||
}
|
||||
AddCodeLine ("ldy #$%02X", Offs);
|
||||
|
@ -2179,6 +2196,7 @@ void g_subeqlocal (unsigned flags, int Offs, unsigned long val)
|
|||
|
||||
case CF_INT:
|
||||
if (flags & CF_CONST) {
|
||||
AddCodeLine ("nop ; g_subeqlocal"); // FIXME: remove
|
||||
g_getimmed (flags, val, 0);
|
||||
}
|
||||
AddCodeLine ("ldy #$%02X", Offs);
|
||||
|
@ -2187,6 +2205,7 @@ void g_subeqlocal (unsigned flags, int Offs, unsigned long val)
|
|||
|
||||
case CF_LONG:
|
||||
if (flags & CF_CONST) {
|
||||
AddCodeLine ("nop ; g_subeqlocal"); // FIXME: remove
|
||||
g_getimmed (flags, val, 0);
|
||||
}
|
||||
AddCodeLine ("ldy #$%02X", Offs);
|
||||
|
@ -2412,7 +2431,7 @@ void g_cmp (unsigned flags, unsigned long val)
|
|||
#define OPER_IDX_NUM 5
|
||||
|
||||
static void oper (unsigned Flags, unsigned long Val, const char* const* Subs)
|
||||
/* Encode a binary operation. subs is a pointer to four strings:
|
||||
/* Encode a binary operation. subs is a pointer to five strings:
|
||||
** 0 --> Operate on ints
|
||||
** 1 --> Operate on unsigneds
|
||||
** 2 --> Operate on longs
|
||||
|
@ -2421,6 +2440,7 @@ static void oper (unsigned Flags, unsigned long Val, const char* const* Subs)
|
|||
*/
|
||||
{
|
||||
int n = 0;
|
||||
AddCodeLine ("nop ; oper(%2x,%lx)", Flags, Val); // FIXME: remove
|
||||
/* Determine the offset into the array */
|
||||
if (Flags & CF_FLOAT) {
|
||||
n = OPER_IDX_FLOAT;
|
||||
|
@ -2436,6 +2456,7 @@ static void oper (unsigned Flags, unsigned long Val, const char* const* Subs)
|
|||
/* Load the value if it is not already in the primary */
|
||||
if (Flags & CF_CONST) {
|
||||
/* Load value */
|
||||
AddCodeLine ("nop ; oper(%2x,%lx)", Flags, Val); // FIXME: remove
|
||||
g_getimmed (Flags, Val, 0);
|
||||
}
|
||||
|
||||
|
@ -2499,6 +2520,7 @@ void g_push (unsigned flags, unsigned long val)
|
|||
} else {
|
||||
|
||||
/* Handle as 16 bit value */
|
||||
AddCodeLine ("nop ; g_push"); // FIXME: remove
|
||||
g_getimmed (flags, val, 0);
|
||||
AddCodeLine ("jsr pushax");
|
||||
}
|
||||
|
@ -2508,6 +2530,7 @@ void g_push (unsigned flags, unsigned long val)
|
|||
/* Value is not 16 bit or not constant */
|
||||
if (flags & CF_CONST) {
|
||||
/* Constant 32 bit value, load into eax */
|
||||
AddCodeLine ("nop ; g_push"); // FIXME: remove
|
||||
g_getimmed (flags, val, 0);
|
||||
}
|
||||
|
||||
|
@ -2567,6 +2590,7 @@ void g_push_float (unsigned flags, float val)
|
|||
uint32_t *p = ((uint32_t*)&val); /* FIXME: float - we shouldnt do this :) */
|
||||
/* Constant 32 bit value, load into eax */
|
||||
LOG(("g_push_float flags:%04x f:%p\n", flags, *p));
|
||||
AddCodeLine ("nop ; g_push_float"); // FIXME: remove
|
||||
g_getimmed (flags | CF_CONST, *p, 0); // ?? FIXME
|
||||
#endif
|
||||
// g_getimmed (0x41,*p,0);
|
||||
|
@ -2792,6 +2816,7 @@ void g_add (unsigned flags, unsigned long val)
|
|||
flags &= ~CF_FORCECHAR; /* Handle chars as ints */
|
||||
g_push (flags & ~CF_CONST, 0);
|
||||
}
|
||||
AddCodeLine ("nop ; g_add(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
oper (flags, val, ops);
|
||||
}
|
||||
|
||||
|
@ -2812,6 +2837,7 @@ void g_sub (unsigned flags, unsigned long val)
|
|||
flags &= ~CF_FORCECHAR; /* Handle chars as ints */
|
||||
g_push (flags & ~CF_CONST, 0);
|
||||
}
|
||||
AddCodeLine ("nop ; g_sub(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
oper (flags, val, ops);
|
||||
}
|
||||
|
||||
|
@ -2827,6 +2853,7 @@ void g_rsub (unsigned flags, unsigned long val)
|
|||
"tosrsubeax",
|
||||
"ftosrsubeax"
|
||||
};
|
||||
AddCodeLine ("nop ; g_rsub(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
oper (flags, val, ops);
|
||||
}
|
||||
|
||||
|
@ -2953,6 +2980,7 @@ void g_mul (unsigned flags, unsigned long val)
|
|||
g_push (flags & ~CF_CONST, 0);
|
||||
|
||||
}
|
||||
AddCodeLine ("nop ; g_mul(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* Use long way over the stack */
|
||||
oper (flags, val, ops);
|
||||
|
@ -3038,6 +3066,7 @@ void g_div (unsigned flags, unsigned long val)
|
|||
g_restore (flags);
|
||||
AddCodeLine ("bcs %s", LocalLabelName (DoShiftLabel));
|
||||
|
||||
AddCodeLine ("nop ; g_div"); // FIXME: remove
|
||||
/* The result is 0. We can just load 0 and skip the shifting. */
|
||||
g_getimmed (flags | CF_ABSOLUTE, 0, 0);
|
||||
|
||||
|
@ -3069,6 +3098,7 @@ void g_div (unsigned flags, unsigned long val)
|
|||
flags &= ~CF_FORCECHAR; /* Handle chars as ints */
|
||||
g_push (flags & ~CF_CONST, 0);
|
||||
}
|
||||
AddCodeLine ("nop ; g_div(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* Generate a division */
|
||||
oper (flags, val, ops);
|
||||
|
@ -3089,6 +3119,8 @@ void g_mod (unsigned flags, unsigned long val)
|
|||
};
|
||||
int p2;
|
||||
|
||||
AddCodeLine ("nop ; g_mod(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* Check if we can do some cost reduction */
|
||||
if ((flags & CF_CONST) && (flags & CF_UNSIGNED) && val != 0xFFFFFFFF && (p2 = PowerOf2 (val)) >= 0) {
|
||||
/* We can do that with an AND operation */
|
||||
|
@ -3169,6 +3201,7 @@ void g_or (unsigned flags, unsigned long val)
|
|||
flags &= ~CF_FORCECHAR;
|
||||
g_push (flags & ~CF_CONST, 0);
|
||||
}
|
||||
AddCodeLine ("nop ; g_or(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* Use long way over the stack */
|
||||
oper (flags, val, ops);
|
||||
|
@ -3237,6 +3270,7 @@ void g_xor (unsigned flags, unsigned long val)
|
|||
flags &= ~CF_FORCECHAR;
|
||||
g_push (flags & ~CF_CONST, 0);
|
||||
}
|
||||
AddCodeLine ("nop ; g_xor(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* Use long way over the stack */
|
||||
oper (flags, val, ops);
|
||||
|
@ -3329,6 +3363,7 @@ void g_and (unsigned Flags, unsigned long Val)
|
|||
Flags &= ~CF_FORCECHAR;
|
||||
g_push (Flags & ~CF_CONST, 0);
|
||||
}
|
||||
AddCodeLine ("nop ; g_and(flags:%2x,val:%lx)", Flags, Val); // FIXME: remove
|
||||
|
||||
/* Use long way over the stack */
|
||||
oper (Flags, Val, ops);
|
||||
|
@ -3503,6 +3538,7 @@ void g_asr (unsigned flags, unsigned long val)
|
|||
flags &= ~CF_FORCECHAR;
|
||||
g_push (flags & ~CF_CONST, 0);
|
||||
}
|
||||
AddCodeLine ("nop ; g_asr(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* Use long way over the stack */
|
||||
oper (flags, val, ops);
|
||||
|
@ -3619,6 +3655,7 @@ void g_asl (unsigned flags, unsigned long val)
|
|||
flags &= ~CF_FORCECHAR;
|
||||
g_push (flags & ~CF_CONST, 0);
|
||||
}
|
||||
AddCodeLine ("nop ; g_asl(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* Use long way over the stack */
|
||||
oper (flags, val, ops);
|
||||
|
@ -3985,6 +4022,7 @@ void g_eq (unsigned flags, unsigned long val)
|
|||
flags &= ~CF_FORCECHAR;
|
||||
g_push (flags & ~CF_CONST, 0);
|
||||
}
|
||||
AddCodeLine ("nop ; g_eq(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* Use long way over the stack */
|
||||
oper (flags, val, ops);
|
||||
|
@ -4047,6 +4085,7 @@ void g_ne (unsigned flags, unsigned long val)
|
|||
flags &= ~CF_FORCECHAR;
|
||||
g_push (flags & ~CF_CONST, 0);
|
||||
}
|
||||
AddCodeLine ("nop ; g_ne(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* Use long way over the stack */
|
||||
oper (flags, val, ops);
|
||||
|
@ -4066,6 +4105,7 @@ void g_lt (unsigned flags, unsigned long val)
|
|||
};
|
||||
|
||||
unsigned Label;
|
||||
AddCodeLine ("nop ; g_lt(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* If the right hand side is const, the lhs is not on stack but still
|
||||
** in the primary register.
|
||||
|
@ -4239,6 +4279,7 @@ void g_le (unsigned flags, unsigned long val)
|
|||
"ftosleeax"
|
||||
};
|
||||
|
||||
AddCodeLine ("nop ; g_le(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* If the right hand side is const, the lhs is not on stack but still
|
||||
** in the primary register.
|
||||
|
@ -4362,6 +4403,7 @@ void g_gt (unsigned flags, unsigned long val)
|
|||
"ftosgteax"
|
||||
};
|
||||
|
||||
AddCodeLine ("nop ; g_gt(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* If the right hand side is const, the lhs is not on stack but still
|
||||
** in the primary register.
|
||||
|
@ -4503,6 +4545,7 @@ void g_ge (unsigned flags, unsigned long val)
|
|||
|
||||
unsigned Label;
|
||||
|
||||
AddCodeLine ("nop ; g_ge(flags:%2x,val:%lx)", flags, val); // FIXME: remove
|
||||
|
||||
/* If the right hand side is const, the lhs is not on stack but still
|
||||
** in the primary register.
|
||||
|
@ -4880,10 +4923,13 @@ void g_initstatic (unsigned InitLabel, unsigned VarLabel, unsigned Size)
|
|||
AddCodeLine ("bne %s", LocalLabelName (CodeLabel));
|
||||
} else {
|
||||
/* Use the easy way here: memcpy() */
|
||||
AddCodeLine ("nop ; g_initstatic"); // FIXME: remove
|
||||
g_getimmed (CF_STATIC, VarLabel, 0);
|
||||
AddCodeLine ("jsr pushax");
|
||||
AddCodeLine ("nop ; g_initstatic"); // FIXME: remove
|
||||
g_getimmed (CF_STATIC, InitLabel, 0);
|
||||
AddCodeLine ("jsr pushax");
|
||||
AddCodeLine ("nop ; g_initstatic"); // FIXME: remove
|
||||
g_getimmed (CF_INT | CF_UNSIGNED | CF_CONST, Size, 0);
|
||||
AddCodeLine ("jsr %s", GetLabelName (CF_EXTERNAL, (uintptr_t) "memcpy", 0));
|
||||
}
|
||||
|
|
|
@ -271,8 +271,10 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes);
|
|||
|
||||
|
||||
#ifdef DEBUG
|
||||
#define g_getimmed(a,b,c) _g_getimmed((a),(b),(c),(__FILE__),(__FUNCTION__),(__LINE__))
|
||||
void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs, char *file, char *func, int line);
|
||||
// #define g_getimmed(a,b,c) _g_getimmed((a),(b),(c),(__FILE__),(__FUNCTION__),(__LINE__))
|
||||
// void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs, char *file, const char *func, int line);
|
||||
#define g_getimmed(a,b,c) _g_getimmed((a),(b),(c))
|
||||
void _g_getimmed (unsigned Flags, uintptr_t Val, long Offs);
|
||||
#else
|
||||
#define g_getimmed(a,b,c) _g_getimmed((a),(b),(c))
|
||||
void _g_getimmed (unsigned Flags, uintptr_t Val, long Offs);
|
||||
|
|
111
src/cc65/expr.c
111
src/cc65/expr.c
|
@ -4,7 +4,7 @@
|
|||
** 2020-11-20, Greg King
|
||||
*/
|
||||
|
||||
//#define DEBUG
|
||||
#define DEBUG
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -2453,6 +2453,8 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||
unsigned ltype;
|
||||
int rconst; /* Operand is a constant */
|
||||
|
||||
LOG(("hie_compare\n"));
|
||||
|
||||
ExprWithCheck (hienext, Expr);
|
||||
|
||||
while ((Gen = FindGen (CurTok.Tok, Ops)) != 0) {
|
||||
|
@ -2480,7 +2482,11 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||
/* Numeric constant value */
|
||||
GetCodePos (&Mark2);
|
||||
// LOG(("iVal:%08x FVal:%f\n", Expr->IVal, Expr->V.FVal.V));
|
||||
g_push (ltype | CF_CONST, Expr->IVal);
|
||||
if (ltype == CF_FLOAT) {
|
||||
g_push_float (ltype | CF_CONST, Expr->V.FVal.V);
|
||||
} else {
|
||||
g_push (ltype | CF_CONST, Expr->IVal);
|
||||
}
|
||||
} else {
|
||||
/* Value not numeric constant */
|
||||
LoadExpr (CF_NONE, Expr);
|
||||
|
@ -2675,6 +2681,9 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||
int CmpSigned = IsClassInt (Expr->Type) && IsClassInt (Expr2.Type) &&
|
||||
IsSignSigned (ArithmeticConvert (Expr->Type, Expr2.Type));
|
||||
|
||||
LOG(("hie_compare LeftSigned:%d RightSigned:%d CmpSigned:%d %x %x\n",
|
||||
LeftSigned, RightSigned, CmpSigned, Expr2.IVal, Expr->IVal));
|
||||
|
||||
/* If the right hand side is constant, and the generator function
|
||||
** expects the lhs in the primary, remove the push of the primary
|
||||
** now.
|
||||
|
@ -2690,6 +2699,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||
|
||||
/* Determine the type of the operation. */
|
||||
if (IsTypeChar (Expr->Type) && rconst && (!LeftSigned || RightSigned)) {
|
||||
LOG(("hie_compare 1\n"));
|
||||
|
||||
/* Left side is unsigned char, right side is constant.
|
||||
** Determine the minimum and maximum values
|
||||
|
@ -2774,6 +2784,7 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||
|
||||
} else if (IsTypeChar (Expr->Type) && IsTypeChar (Expr2.Type) &&
|
||||
GetSignedness (Expr->Type) == GetSignedness (Expr2.Type)) {
|
||||
LOG(("hie_compare 2\n"));
|
||||
|
||||
/* Both are chars with the same signedness. We can encode the
|
||||
** operation as a char operation.
|
||||
|
@ -2790,7 +2801,9 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||
} else {
|
||||
unsigned rtype = TypeOf (Expr2.Type) | (flags & CF_CONST);
|
||||
flags |= g_typeadjust (ltype, rtype);
|
||||
LOG(("hie_compare 3\n"));
|
||||
}
|
||||
LOG(("hie_compare rconst:%d CmpSigned:%d \n", rconst, CmpSigned));
|
||||
|
||||
/* If the comparison is made as unsigned types and the right is a
|
||||
** constant, we may be able to change the compares to something more
|
||||
|
@ -2798,55 +2811,68 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */
|
|||
*/
|
||||
if (!CmpSigned && rconst) {
|
||||
|
||||
switch (Tok) {
|
||||
/* FIXME: float --- startcode end */
|
||||
if (Expr2.Type == type_float) {
|
||||
LOG(("FIXME: special cases for comparison with float constant"));
|
||||
} else {
|
||||
/* FIXME: float --- newcode end */
|
||||
|
||||
case TOK_LT:
|
||||
if (Expr2.IVal == 1) {
|
||||
/* An unsigned compare to one means that the value
|
||||
** must be zero.
|
||||
*/
|
||||
GenFunc = g_eq;
|
||||
Expr2.IVal = 0;
|
||||
}
|
||||
break;
|
||||
switch (Tok) {
|
||||
|
||||
case TOK_LE:
|
||||
if (Expr2.IVal == 0) {
|
||||
/* An unsigned compare to zero means that the value
|
||||
** must be zero.
|
||||
*/
|
||||
GenFunc = g_eq;
|
||||
}
|
||||
break;
|
||||
case TOK_LT:
|
||||
if (Expr2.IVal == 1) {
|
||||
/* An unsigned compare to one means that the value
|
||||
** must be zero.
|
||||
*/
|
||||
GenFunc = g_eq;
|
||||
Expr2.IVal = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case TOK_GE:
|
||||
if (Expr2.IVal == 1) {
|
||||
/* An unsigned compare to one means that the value
|
||||
** must not be zero.
|
||||
*/
|
||||
GenFunc = g_ne;
|
||||
Expr2.IVal = 0;
|
||||
}
|
||||
break;
|
||||
case TOK_LE:
|
||||
if (Expr2.IVal == 0) {
|
||||
/* An unsigned compare to zero means that the value
|
||||
** must be zero.
|
||||
*/
|
||||
GenFunc = g_eq;
|
||||
}
|
||||
break;
|
||||
|
||||
case TOK_GT:
|
||||
if (Expr2.IVal == 0) {
|
||||
/* An unsigned compare to zero means that the value
|
||||
** must not be zero.
|
||||
*/
|
||||
GenFunc = g_ne;
|
||||
}
|
||||
break;
|
||||
case TOK_GE:
|
||||
if (Expr2.IVal == 1) {
|
||||
/* An unsigned compare to one means that the value
|
||||
** must not be zero.
|
||||
*/
|
||||
GenFunc = g_ne;
|
||||
Expr2.IVal = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
case TOK_GT:
|
||||
if (Expr2.IVal == 0) {
|
||||
/* An unsigned compare to zero means that the value
|
||||
** must not be zero.
|
||||
*/
|
||||
GenFunc = g_ne;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Generate code */
|
||||
GenFunc (flags, Expr2.IVal);
|
||||
/* FIXME: float --- startcode end */
|
||||
if (Expr2.Type == type_float) {
|
||||
/* Generate code */
|
||||
GenFunc (flags, FP_D_As32bitRaw(Expr2.V.FVal));
|
||||
} else {
|
||||
/* Generate code */
|
||||
GenFunc (flags, Expr2.IVal);
|
||||
}
|
||||
/* FIXME: float --- newcode end */
|
||||
|
||||
/* The result is an rvalue in the primary */
|
||||
ED_FinalizeRValLoad (Expr);
|
||||
|
@ -3657,6 +3683,7 @@ static void hie5 (ExprDesc* Expr)
|
|||
{ TOK_NE, GEN_NOPUSH, g_ne },
|
||||
{ TOK_INVALID, 0, 0 }
|
||||
};
|
||||
printf("hie5\n");
|
||||
hie_compare (hie5_ops, Expr, hie6);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ CA65 := $(if $(wildcard ../../bin/ca65*),..$S..$Sbin$Sca65,ca65)
|
|||
LD65 := $(if $(wildcard ../../bin/ld65*),..$S..$Sbin$Sld65,ld65)
|
||||
SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65)
|
||||
|
||||
WORKDIR = ../../testwrk/val
|
||||
WORKDIR = ../../testwrk/todo
|
||||
|
||||
OPTIONS = g O Os Osi Osir Osr Oi Oir Or
|
||||
|
||||
|
@ -49,8 +49,8 @@ $(WORKDIR):
|
|||
define PRG_template
|
||||
|
||||
$(WORKDIR)/%.$1.$2.prg: %.c | $(WORKDIR)
|
||||
$(if $(QUIET),echo val/$$*.$1.$2.prg)
|
||||
$(CC65) -t sim$2 $$(CC65FLAGS) -$1 -o $$(@:.prg=.s) $$< $(NULLERR)
|
||||
$(if $(QUIET),echo todo/$$*.$1.$2.prg)
|
||||
$(CC65) -t sim$2 $$(CC65FLAGS) --add-source -$1 -o $$(@:.prg=.s) $$< $(NULLERR)
|
||||
$(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR)
|
||||
$(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR)
|
||||
$(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT)
|
||||
|
|
|
@ -27,7 +27,7 @@ void dotest1a(uint8_t *s, uint8_t *d)
|
|||
printf("dotest1a\n");
|
||||
while (*s != 0) {
|
||||
*d = (testasm1(*s));
|
||||
// printf("%04x:%02x\n",d,*d);
|
||||
printf("%04x:%02x\n",d,*d);
|
||||
d++;
|
||||
s++;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ void dotest1b(uint8_t *s, uint8_t *d)
|
|||
printf("dotest1b\n");
|
||||
while (*s != 0) {
|
||||
*d = (testasm2(*s));
|
||||
printf("%04x:%02x\n",d,*d);
|
||||
d++;
|
||||
s++;
|
||||
}
|
||||
|
|
|
@ -55,8 +55,17 @@ void test1(float f, char *str)
|
|||
}
|
||||
}
|
||||
|
||||
void SKIPPEDtest1(float f, char *str)
|
||||
{
|
||||
char temp[12];
|
||||
sprintf(temp, "%08lx", *((uint32_t*)&f));
|
||||
printf(" (SKIPPED:%s:%s)\n", temp, str);
|
||||
}
|
||||
|
||||
void constconst(void)
|
||||
{
|
||||
printf("\n*** constant vs constant\n\n");
|
||||
|
||||
// addition
|
||||
printf("\nconstant + constant\n\n");
|
||||
fp1 = 0.1f;
|
||||
|
@ -105,7 +114,7 @@ void constconst(void)
|
|||
|
||||
void varvar(void)
|
||||
{
|
||||
printf("\nvariable vs variable\n\n");
|
||||
printf("\n*** variable vs variable\n\n");
|
||||
|
||||
/* addition, variable + variable */
|
||||
fp1 = 12.34f;
|
||||
|
@ -113,32 +122,32 @@ void varvar(void)
|
|||
fp3 = fp1 + fp2; // = 55.55f
|
||||
printf("addition: %s+%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x425e3333] %s (exp:55.549999)", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
// test1(fp3, "425e3333");
|
||||
SKIPPEDtest1(fp3, "425e3333");
|
||||
|
||||
/* substraction, variable - variable */
|
||||
fp3 = fp1 - fp2;
|
||||
printf("substraction: %s-%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0xc1f6f5c2] %s (exp:-30.869999)", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
// test1(fp3, "c1f6f5c2");
|
||||
SKIPPEDtest1(fp3, "c1f6f5c2");
|
||||
|
||||
fp1 = 25.2f;
|
||||
fp2 = 2.3f;
|
||||
fp3 = fp1 * fp2;
|
||||
printf("multiplication: %s*%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x4267d70a] %s (exp:57.96)", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
// test1(fp3, "4267d70a");
|
||||
SKIPPEDtest1(fp3, "4267d70a");
|
||||
|
||||
fp1 = 25.2f;
|
||||
fp2 = 2.5f;
|
||||
fp3 = fp1 / fp2;
|
||||
printf("division: %s/%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x412147ae] %s (exp:10.08)", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
// test1(fp3, "412147ae");
|
||||
SKIPPEDtest1(fp3, "412147ae");
|
||||
}
|
||||
|
||||
void varconst(void)
|
||||
{
|
||||
printf("\nvariable vs constant\n\n");
|
||||
printf("\n*** variable vs constant\n\n");
|
||||
/* addition, variable + constant */
|
||||
fp1 = 55.549999f;
|
||||
fp3 = fp1 + 0.05f;
|
||||
|
@ -152,60 +161,60 @@ void varconst(void)
|
|||
fp3 = fp1 - 11.5f; // FIXME: Invalid operands for binary operator '-'
|
||||
printf("substraction: %s-%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, 11.5f), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x3f570a40] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
// test1(fp3, "3f570a40");
|
||||
SKIPPEDtest1(fp3, "3f570a40");
|
||||
#endif
|
||||
|
||||
fp1 = 25.2f;
|
||||
fp3 = fp1 * 2.3f;
|
||||
printf("multiplication: %s*%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, 2.3f), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x4267d70a] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
// test1(fp3, "4267d70a");
|
||||
SKIPPEDtest1(fp3, "4267d70a");
|
||||
|
||||
#if 0
|
||||
fp1 = 25.2f;
|
||||
fp3 = fp1 / 2.3f; // FIXME: division by zero
|
||||
printf("division: %s/%s=%s\n", _ftostr(buf, fp1), _ftostr(buf2, 2.3f), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x412f4dea] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
// test1(fp3, "412f4dea");
|
||||
SKIPPEDtest1(fp3, "412f4dea");
|
||||
#endif
|
||||
}
|
||||
|
||||
void constvar(void)
|
||||
{
|
||||
printf("\nconstant vs variable\n\n");
|
||||
printf("\n*** constant vs variable\n\n");
|
||||
|
||||
/* addition, constant + variable */
|
||||
fp2 = 43.21f;
|
||||
fp3 = 12.7f + fp2; // FIXME: wrong, the add is dropped?
|
||||
printf("addition: %s+%s=%s\n", _ftostr(buf, 12.7f), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x425fa3d7] %s", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
// test1(fp3, "425fa3d7");
|
||||
SKIPPEDtest1(fp3, "425fa3d7");
|
||||
|
||||
/* substraction, constant - variable */
|
||||
fp2 = 12.34;
|
||||
fp3 = 11.5f - fp2; // FIXME: wrong, fp2 appears to become 0?
|
||||
printf("substraction: %s-%s=%s\n", _ftostr(buf, 11.5f), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0xbf570a40] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
// test1(fp3, "bf570a40");
|
||||
SKIPPEDtest1(fp3, "bf570a40");
|
||||
|
||||
fp2 = 2.3f;
|
||||
fp3 = 25.2f * fp2; // FIXME: wrong, fp3 appears to become 0?
|
||||
printf("multiplication: %s*%s=%s\n", _ftostr(buf, 25.2f), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x4267d70a] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
// test1(fp3, "4267d70a");
|
||||
SKIPPEDtest1(fp3, "4267d70a");
|
||||
|
||||
fp2 = 2.3f;
|
||||
fp3 = 25.2f / fp2;
|
||||
printf("division: %s/%s=%s\n", _ftostr(buf, 25.2f), _ftostr(buf2, fp2), _ftostr(buf3, fp3));
|
||||
printf(" fp3:0x%08lx [0x412f4dea] %s ()", *((uint32_t*)&fp3), _ftostr(buf, fp3));
|
||||
// test1(fp3, "412f4dea");
|
||||
SKIPPEDtest1(fp3, "412f4dea");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float fp2 = 43.21f;
|
||||
|
||||
printf("float-basic\n");
|
||||
printf("*** float-basic ***\n");
|
||||
printf("fp1:0x%08lx [0x414570a4] %s (12.340000)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
printf("fp2:0x%08lx [0x422cd70a] %s (43.209999)\n", *((uint32_t*)&fp2), _ftostr(buf, fp2));
|
||||
|
||||
|
|
|
@ -76,29 +76,29 @@ void constvar(void)
|
|||
{
|
||||
printf("const vs var\n");
|
||||
|
||||
// expect("1.5f == 1.6f is", 0, (1.5f == fp1));
|
||||
// expect("1.6f == 1.5f is", 0, (1.6f == fp2));
|
||||
// expect("1.6f == 1.6f is", 1, (1.6f == fp1));
|
||||
//
|
||||
// expect("1.5f != 1.6f is", 1, (1.5f != fp1));
|
||||
// expect("1.6f != 1.5f is", 1, (1.6f != fp2));
|
||||
// expect("1.6f != 1.6f is", 0, (1.6f != fp1));
|
||||
//
|
||||
// expect("1.5f < 1.6f is", 1, (1.5f < fp1));
|
||||
// expect("1.6f < 1.5f is", 0, (1.6f < fp2));
|
||||
// expect("1.6f < 1.6f is", 0, (1.6f < fp1));
|
||||
//
|
||||
// expect("1.5f > 1.6f is", 0, (1.5f > fp1));
|
||||
// expect("1.6f > 1.5f is", 1, (1.6f > fp2));
|
||||
// expect("1.6f > 1.6f is", 0, (1.6f > fp1));
|
||||
//
|
||||
// expect("1.5f <= 1.6f is", 1, (1.5f <= fp1));
|
||||
// expect("1.6f <= 1.5f is", 0, (1.6f <= fp2));
|
||||
// expect("1.6f <= 1.6f is", 1, (1.6f <= fp1));
|
||||
//
|
||||
// expect("1.5f >= 1.6f is", 0, (1.5f >= fp1));
|
||||
// expect("1.6f >= 1.5f is", 1, (1.6f >= fp2));
|
||||
// expect("1.6f >= 1.6f is", 1, (1.6f >= fp1));
|
||||
expect("1.5f == 1.6f is", 0, (1.5f == fp1));
|
||||
expect("1.6f == 1.5f is", 0, (1.6f == fp2));
|
||||
expect("1.6f == 1.6f is", 1, (1.6f == fp1));
|
||||
|
||||
expect("1.5f != 1.6f is", 1, (1.5f != fp1));
|
||||
expect("1.6f != 1.5f is", 1, (1.6f != fp2));
|
||||
expect("1.6f != 1.6f is", 0, (1.6f != fp1));
|
||||
|
||||
expect("1.5f < 1.6f is", 1, (1.5f < fp1));
|
||||
expect("1.6f < 1.5f is", 0, (1.6f < fp2));
|
||||
expect("1.6f < 1.6f is", 0, (1.6f < fp1));
|
||||
|
||||
expect("1.5f > 1.6f is", 0, (1.5f > fp1));
|
||||
expect("1.6f > 1.5f is", 1, (1.6f > fp2));
|
||||
expect("1.6f > 1.6f is", 0, (1.6f > fp1));
|
||||
|
||||
expect("1.5f <= 1.6f is", 1, (1.5f <= fp1));
|
||||
expect("1.6f <= 1.5f is", 0, (1.6f <= fp2));
|
||||
expect("1.6f <= 1.6f is", 1, (1.6f <= fp1));
|
||||
|
||||
expect("1.5f >= 1.6f is", 0, (1.5f >= fp1));
|
||||
expect("1.6f >= 1.5f is", 1, (1.6f >= fp2));
|
||||
expect("1.6f >= 1.6f is", 1, (1.6f >= fp1));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -112,25 +112,25 @@ void varconst(void)
|
|||
|
||||
expect("1.5f == 1.6f is", 0, (fp2 == 1.6f));
|
||||
expect("1.6f == 1.5f is", 0, (fp1 == 1.5f));
|
||||
// expect("1.6f == 1.6f is", 1, (fp1 == 1.6f));
|
||||
expect("1.6f == 1.6f is", 1, (fp1 == 1.6f));
|
||||
|
||||
expect("1.5f != 1.6f is", 1, (fp2 != 1.6f));
|
||||
expect("1.6f != 1.5f is", 1, (fp1 != 1.5f));
|
||||
// expect("1.6f != 1.6f is", 0, (fp1 != 1.6f));
|
||||
expect("1.6f != 1.6f is", 0, (fp1 != 1.6f));
|
||||
|
||||
// expect("1.5f < 1.6f is", 1, (fp2 < 1.6f));
|
||||
expect("1.5f < 1.6f is", 1, (fp2 < 1.6f));
|
||||
expect("1.6f < 1.5f is", 0, (fp1 < 1.5f));
|
||||
expect("1.6f < 1.6f is", 0, (fp1 < 1.6f));
|
||||
|
||||
// expect("1.5f > 1.6f is", 0, (fp2 > 1.6f));
|
||||
expect("1.5f > 1.6f is", 0, (fp2 > 1.6f));
|
||||
expect("1.6f > 1.5f is", 1, (fp1 > 1.5f));
|
||||
// expect("1.6f > 1.6f is", 0, (fp1 > 1.6f));
|
||||
expect("1.6f > 1.6f is", 0, (fp1 > 1.6f));
|
||||
|
||||
// expect("1.5f <= 1.6f is", 1, (fp2 <= 1.6f));
|
||||
expect("1.5f <= 1.6f is", 1, (fp2 <= 1.6f));
|
||||
expect("1.6f <= 1.5f is", 0, (fp1 <= 1.5f));
|
||||
// expect("1.6f <= 1.6f is", 1, (fp1 <= 1.6f));
|
||||
expect("1.6f <= 1.6f is", 1, (fp1 <= 1.6f));
|
||||
|
||||
// expect("1.5f >= 1.6f is", 0, (fp2 >= 1.6f));
|
||||
expect("1.5f >= 1.6f is", 0, (fp2 >= 1.6f));
|
||||
expect("1.6f >= 1.5f is", 1, (fp1 >= 1.5f));
|
||||
expect("1.6f >= 1.6f is", 1, (fp1 >= 1.6f));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user