From 592a612777648f0b095b78b9f4163d421d660f45 Mon Sep 17 00:00:00 2001 From: Janneke Nieuwenhuizen Date: Sun, 30 Jul 2023 09:51:08 +0200 Subject: [PATCH] DRAFT mescc: Consider truncate after each shift operation. * module/mescc/compile.scm (expr->register): After lshift and rshift, use convert-r0. Tuncate on largest of default/int or size of first operand. --- module/mescc/compile.scm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/module/mescc/compile.scm b/module/mescc/compile.scm index 06d5dc24..2797baac 100644 --- a/module/mescc/compile.scm +++ b/module/mescc/compile.scm @@ -1215,8 +1215,20 @@ (append-text info (wrap-as (as info 'not-r))))) ((bitwise-or ,a ,b) ((binop->r info) a b 'r0-or-r1)) ((bitwise-xor ,a ,b) ((binop->r info) a b 'r0-xor-r1)) - ((lshift ,a ,b) ((binop->r info) a b 'r0<r info) a b 'r0>>r1)) + ((lshift ,a ,b) + (let* ((type-a (ast->type a info)) + (default (get-type "default" info)) + (type (if (> (->size type-a info) (->size default info)) type-a + default)) + (info ((binop->r info) a b 'r0<type a info)) + (default (get-type "default" info)) + (type (if (> (->size type-a info) (->size default info)) type-a + default)) + (info ((binop->r info) a b 'r0>>r1))) + (append-text info (convert-r0 info type)))) ((div ,a ,b) ((binop->r info) a b 'r0/r1 (signed? (ast->type a info))))