EtchedPixels / Fuzix-Compiler-Kit

Fuzix C Compiler Project
Other
49 stars 14 forks source link

+= and -= operations on floats are calculated as longs. #158

Closed zu2 closed 1 week ago

zu2 commented 2 weeks ago
int main(int argc, char **argv) {
    float e, a;

    e = 1.0;
    a = 1.0;

    e = e+a;
    e += a;

    return 0;
}

The first + calls the helper function __plusf. But += does long arithmetic.

-= calls negatef, then does a long addition.

do_xptrop generates the code, but I don't know where to check for FLOAT

;:rewritten:
;T_PLUSEQ v0 t80 f6 
;    T_LOCAL v0 t81 f1  e
;    T_DEREF v0 t80 f0 
;        T_LOCAL v4 t81 f1      a
;deref r 1203 4
; go via shortcut
;make local ptr off 4, rlim 252 noff 4
        ldaa 6,x
        ldab 7,x
        ldx 4,x
        stx @hireg
;make local ptr off 0, rlim 252 noff 0
        tsx
; do_xeqop
; do_xptrop T_PLUSEQ:
        addb 3,x
        adca 2,x
        pshb
        psha
        ldaa @hireg
        ldab @hireg+1
        adcb 1,x
        adca 0,x
        staa @hireg
        stab @hireg+1
        pula
        pulb
        stb 3,x
        sta 2,x
        pshb
        psha
        ldaa @hireg
        ldab @hireg+1
        stb 1,x
        sta 0,x
        staa @hireg
        stab @hireg+1
        pula
        pulb
EtchedPixels commented 1 week ago
diff --git a/be-codegen-6800.c b/be-codegen-6800.c
index b9bb362..166c6c8 100644
--- a/be-codegen-6800.c
+++ b/be-codegen-6800.c
@@ -905,6 +905,11 @@ unsigned do_xeqop(struct node *n, const char *op)
        unsigned off;
        struct node *l = n->left;
        struct node *r = n->right;
+
+       /* Float always goes via the helper */
+       if (n->type == FLOAT)
+               return 0;
+
        /* Handle simpler cases of -= the other way around */
        if (is_simple(r) && get_size(n->type) <= 2) {
                if (is_simple(l)) {
@@ -942,6 +947,8 @@ unsigned do_xeqop(struct node *n, const char *op)

 unsigned do_stkeqop(struct node *n, const char *op)
 {
+       if (n->type == FLOAT)
+               return 0;
        if (cpu_is_09)
                puts("\tpuls x");
        else if (cpu_has_pshx)

should fix it I think