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.
This commit is contained in:
W. J. van der Laan 2021-04-22 18:46:16 +00:00 committed by Janneke Nieuwenhuizen
parent 0b5053e4b7
commit 55b42018db
4 changed files with 12 additions and 5 deletions

View File

@ -1,6 +1,7 @@
;;; GNU Mes --- Maxwell Equations of Software
;;; Copyright © 2016,2017,2018,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org>
;;; Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
;;;
;;; 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)

View File

@ -1,6 +1,7 @@
;;; GNU Mes --- Maxwell Equations of Software
;;; Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2023 Andrius Štikonas <andrius@stikonas.eu>
;;; Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
;;;
;;; 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)))))

View File

@ -1,5 +1,6 @@
;;; GNU Mes --- Maxwell Equations of Software
;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
;;;
;;; 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)

View File

@ -1,6 +1,7 @@
;;; GNU Mes --- Maxwell Equations of Software
;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2023 Andrius Štikonas <andrius@stikonas.eu>
;;; Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
;;;
;;; 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)