From edf397038a187925c503bb1910650ed0da5a59fd 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 2797baac..0d4950d2 100644 --- a/module/mescc/compile.scm +++ b/module/mescc/compile.scm @@ -1,6 +1,7 @@ ;;; GNU Mes --- Maxwell Equations of Software ;;; Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2023 Andrius Štikonas +;;; Copyright © 2021 W. J. van der Laan ;;; ;;; This file is part of GNU Mes. ;;; @@ -1254,13 +1255,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))))) @@ -1269,7 +1270,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))))) @@ -1284,7 +1285,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))))) @@ -1293,7 +1294,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 345399c2..8dbe3476 100644 --- a/module/mescc/x86_64/as.scm +++ b/module/mescc/x86_64/as.scm @@ -1,6 +1,7 @@ ;;; GNU Mes --- Maxwell Equations of Software ;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen ;;; Copyright © 2023 Andrius Štikonas +;;; Copyright © 2021 W. J. van der Laan ;;; ;;; This file is part of GNU Mes. ;;; @@ -752,6 +753,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)