From 2da6375b4e456b269a439f2216f30797254d3c9a Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Fri, 1 Jan 2021 10:31:46 +0100 Subject: [PATCH] DRAFT mescc: Only use signed division when numerator is signed. XXX TODO: We are getting stray nondeterministic floating point exceptions when compiling mes using mescc with an m2-planet-compiled mes: recompilation often succeeds. I am suspecting using signed division: CLTD / IDIV is the problem, which were enabled here fa4147a284e4d7b50175e0252bbd4ecf431cb7fd mescc: Use signed division for x86, x86_64 when appropriate. before, we never used signed division. This patch fixed lib/tests/scaffold/36-compare-arithmetic.c lib/tests/scaffold/36-compare-arithmetic-negative.c As a workaround, I have been avoiding using signed division, however, signed division should work just fine. Currently, sign-extension (CLTD vs XOR EDX) and signed division (IDIV vs DIV) selected by setting "signed?". See, module/mescc/x86/as.scm. Possibly we need a signed? based on numerator and denominator, and add a extend-sign? based on the signedness of the numerator? * module/mescc/compile.scm (expr->register): Base "signed?" strictly on signedness of numerator. --- module/mescc/compile.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/mescc/compile.scm b/module/mescc/compile.scm index a846f729..5cb40da9 100644 --- a/module/mescc/compile.scm +++ b/module/mescc/compile.scm @@ -1218,9 +1218,9 @@ ((rshift ,a ,b) ((binop->r info) a b 'r0>>r1)) ((div ,a ,b) ((binop->r info) a b 'r0/r1 - (or (signed? (ast->type a info)) (signed? (ast->type b info))))) + (signed? (ast->type a info)))) ((mod ,a ,b) ((binop->r info) a b 'r0%r1 - (or (signed? (ast->type a info)) (signed? (ast->type b info))))) + (signed? (ast->type a info)))) ((mul ,a ,b) ((binop->r info) a b 'r0*r1)) ((not ,expr) @@ -1361,7 +1361,7 @@ info))) (info (expr->register a info)) (info (append-text info (wrap-as (as info 'swap-r0-r1)))) - (signed? (or (signed? type) (signed? type-b))) + (signed? (signed? type)) (info (append-text info (cond ((equal? op "+=") (wrap-as (as info 'r0+r1))) ((equal? op "-=") (wrap-as (as info 'r0-r1))) ((equal? op "*=") (wrap-as (as info 'r0*r1)))