From 4502a86ab0a6be61a22befd266c81ae520f3d4e8 Mon Sep 17 00:00:00 2001 From: "W. J. van der Laan" Date: Thu, 22 Apr 2021 18:46:16 +0000 Subject: [PATCH] mescc: Add r0-cmp-r1 instruction. This instruction is used to compare two registers and set the flags accordingly. In current architectures this is the same as r0-r1, but for RISCV it will be different. RISC-V does not have condition flags so (until a better solution) we are going to emulate them there. * module/mescc/armv4/as.scm (armv4:instructions): Add r0-cmp-r1 as alias of r0-r1. * module/mescc/i386/as.scm: Same. * module/mescc/x86_64/as.scm: Same. * module/mescc/compile.scm (expr->register): Make use of the new r0-cmp-r1 instruction. --- module/mescc/armv4/as.scm | 2 ++ module/mescc/compile.scm | 11 ++++++----- module/mescc/i386/as.scm | 2 ++ module/mescc/x86_64/as.scm | 2 ++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/module/mescc/armv4/as.scm b/module/mescc/armv4/as.scm index 8975cc8f..0ee3383b 100644 --- a/module/mescc/armv4/as.scm +++ b/module/mescc/armv4/as.scm @@ -1,6 +1,7 @@ ;;; GNU Mes --- Maxwell Equations of Software ;;; Copyright © 2016,2017,2018,2020 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2019 Danny Milosavljevic +;;; Copyright © 2021 W. J. van der Laan ;;; ;;; This file is part of GNU Mes. ;;; @@ -618,6 +619,7 @@ (r0->r1 . ,armv4:r0->r1) (r0->r1-mem . ,armv4:r0->r1-mem) (r0-and-r1 . ,armv4:r0-and-r1) + (r0-cmp-r1 . ,armv4:r0-r1) (r0-mem->r1-mem . ,armv4:r0-mem->r1-mem) (r0-or-r1 . ,armv4:r0-or-r1) (r0-r1 . ,armv4:r0-r1) diff --git a/module/mescc/compile.scm b/module/mescc/compile.scm index 65c16b32..1f1f9683 100644 --- a/module/mescc/compile.scm +++ b/module/mescc/compile.scm @@ -1,5 +1,6 @@ ;;; GNU Mes --- Maxwell Equations of Software ;;; Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen +;;; Copyright © 2021 W. J. van der Laan ;;; ;;; This file is part of GNU Mes. ;;; @@ -1241,13 +1242,13 @@ (info (free-register info))) info)) - ((eq ,a ,b) (let ((info ((binop->r info) a b 'r0-r1))) + ((eq ,a ,b) (let ((info ((binop->r info) a b 'r0-cmp-r1))) (append-text info (wrap-as (as info 'zf->r))))) ((ge ,a ,b) (let* ((type-a (ast->type a info)) (type-b (ast->type b info)) - (info ((binop->r info) a b 'r0-r1)) + (info ((binop->r info) a b 'r0-cmp-r1)) (test->r (if (or (unsigned? type-a) (unsigned? type-b)) 'ae?->r 'ge?->r)) (info (append-text info (wrap-as (as info test->r)))) (info (append-text info (wrap-as (as info 'test-r))))) @@ -1256,7 +1257,7 @@ ((gt ,a ,b) (let* ((type-a (ast->type a info)) (type-b (ast->type b info)) - (info ((binop->r info) a b 'r0-r1)) + (info ((binop->r info) a b 'r0-cmp-r1)) (test->r (if (or (unsigned? type-a) (unsigned? type-b)) 'a?->r 'g?->r)) (info (append-text info (wrap-as (as info test->r)))) (info (append-text info (wrap-as (as info 'test-r))))) @@ -1271,7 +1272,7 @@ ((le ,a ,b) (let* ((type-a (ast->type a info)) (type-b (ast->type b info)) - (info ((binop->r info) a b 'r0-r1)) + (info ((binop->r info) a b 'r0-cmp-r1)) (test->r (if (or (unsigned? type-a) (unsigned? type-b)) 'be?->r 'le?->r)) (info (append-text info (wrap-as (as info test->r)))) (info (append-text info (wrap-as (as info 'test-r))))) @@ -1280,7 +1281,7 @@ ((lt ,a ,b) (let* ((type-a (ast->type a info)) (type-b (ast->type b info)) - (info ((binop->r info) a b 'r0-r1)) + (info ((binop->r info) a b 'r0-cmp-r1)) (test->r (if (or (unsigned? type-a) (unsigned? type-b)) 'b?->r 'l?->r)) (info (append-text info (wrap-as (as info test->r)))) (info (append-text info (wrap-as (as info 'test-r))))) diff --git a/module/mescc/i386/as.scm b/module/mescc/i386/as.scm index 0b786e5b..c4427d41 100644 --- a/module/mescc/i386/as.scm +++ b/module/mescc/i386/as.scm @@ -1,5 +1,6 @@ ;;; GNU Mes --- Maxwell Equations of Software ;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen +;;; Copyright © 2021 W. J. van der Laan ;;; ;;; This file is part of GNU Mes. ;;; @@ -617,6 +618,7 @@ (r0->r1 . ,i386:r0->r1) (r0->r1-mem . ,i386:r0->r1-mem) (r0-and-r1 . ,i386:r0-and-r1) + (r0-cmp-r1 . ,i386:r0-r1) (r0-mem->r1-mem . ,i386:r0-mem->r1-mem) (r0-or-r1 . ,i386:r0-or-r1) (r0-r1 . ,i386:r0-r1) diff --git a/module/mescc/x86_64/as.scm b/module/mescc/x86_64/as.scm index 7e438c6c..74fd57ef 100644 --- a/module/mescc/x86_64/as.scm +++ b/module/mescc/x86_64/as.scm @@ -1,5 +1,6 @@ ;;; GNU Mes --- Maxwell Equations of Software ;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen +;;; Copyright © 2021 W. J. van der Laan ;;; ;;; This file is part of GNU Mes. ;;; @@ -751,6 +752,7 @@ (r0->r1 . ,x86_64:r0->r1) (r0->r1-mem . ,x86_64:r0->r1-mem) (r0-and-r1 . ,x86_64:r0-and-r1) + (r0-cmp-r1 . ,x86_64:r0-r1) (r0-mem->r1-mem . ,x86_64:r0-mem->r1-mem) (r0-or-r1 . ,x86_64:r0-or-r1) (r0-r1 . ,x86_64:r0-r1)