diff --git a/build-aux/check-mescc.sh b/build-aux/check-mescc.sh index 0ac7216c..9789971b 100755 --- a/build-aux/check-mescc.sh +++ b/build-aux/check-mescc.sh @@ -2,6 +2,7 @@ # GNU Mes --- Maxwell Equations of Software # Copyright © 2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen +# Copyright © 2023 Andrius Štikonas # # This file is part of GNU Mes. # @@ -134,6 +135,7 @@ lib/tests/scaffold/63-struct-cell.c lib/tests/scaffold/64-make-cell.c lib/tests/scaffold/65-read.c lib/tests/scaffold/66-local-char-array.c +lib/tests/scaffold/67-m1-overflow-check.c " tcc_tests=" diff --git a/lib/tests/scaffold/67-m1-overflow-check.c b/lib/tests/scaffold/67-m1-overflow-check.c new file mode 100644 index 00000000..b3ea4803 --- /dev/null +++ b/lib/tests/scaffold/67-m1-overflow-check.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2023 Andrius Štikonas + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +int +main () +{ + return (0xe5894855 >> 31) - 1; +} diff --git a/module/mescc/compile.scm b/module/mescc/compile.scm index 65c16b32..06d5dc24 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 © 2023 Andrius Štikonas ;;; ;;; This file is part of GNU Mes. ;;; diff --git a/module/mescc/x86_64/as.scm b/module/mescc/x86_64/as.scm index 7e438c6c..345399c2 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 © 2023 Andrius Štikonas ;;; ;;; This file is part of GNU Mes. ;;; @@ -82,7 +83,7 @@ (or v (error "invalid value: x86_64:value->r: " v)) (let ((r (get-r info))) (if (and (>= v 0) - (< v #xffffffff)) + (< v #x80000000)) `((,(string-append "mov____$i32,%" r) (#:immediate ,v))) `((,(string-append "mov____$i64,%" r) (#:immediate8 ,v)))))) @@ -520,7 +521,7 @@ (cond ((< (abs v) #x80) `((,(string-append "cmp____$i8,%" r) (#:immediate1 ,v)))) ((and (>= v 0) - (< v #xffffffff)) + (< v #x80000000)) `((,(string-append "cmp____$i32,%" r) (#:immediate ,v)))) (else `(,(string-append "mov____$i64,%r15") (#:immediate8 ,v) @@ -608,7 +609,7 @@ (cond ((< (abs v) #x80) `((,(string-append "addl___$i8,(%" r ")") (#:immediate1 ,v)))) ((and (>= v 0) - (< v #xffffffff)) + (< v #x80000000)) `((,(string-append "addl___$i32,(%" r ")") (#:immediate ,v)))) (else `((,(string-append "mov____$i64,%r15") (#:immediate8 ,v)) @@ -638,7 +639,7 @@ (define (x86_64:r-and info v) (let ((r (get-r info))) (if (and (>= v 0) - (< v #xffffffff)) + (< v #x80000000)) `((,(string-append "and____$i32,%" r) (#:immediate ,v))) `((,(string-append "mov____$i64,%r15") (#:immediate8 ,v)) (,(string-append "and____%r15,%" r))))))