mescc: Do not overflow M1 64bit immediates.
M1 immediates are limited to 31-bit before they become negative. * module/mescc/x86_64/as.scm (x86_64:value->r, x86_64:r-cmp-value, x86_64:r-long-mem-add, x86_64:r-and): Limit M1 immediate to #x80000000. * lib/tests/scaffold/67-m1-overflow-check.c: New test. * build-aux/check-mescc.sh (mes_tests): Add it.
This commit is contained in:
parent
2e13faa3c2
commit
05e945c0a8
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
# GNU Mes --- Maxwell Equations of Software
|
# GNU Mes --- Maxwell Equations of Software
|
||||||
# Copyright © 2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
# Copyright © 2017,2018,2019,2020,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
# Copyright © 2023 Andrius Štikonas <andrius@stikonas.eu>
|
||||||
#
|
#
|
||||||
# This file is part of GNU Mes.
|
# 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/64-make-cell.c
|
||||||
lib/tests/scaffold/65-read.c
|
lib/tests/scaffold/65-read.c
|
||||||
lib/tests/scaffold/66-local-char-array.c
|
lib/tests/scaffold/66-local-char-array.c
|
||||||
|
lib/tests/scaffold/67-m1-overflow-check.c
|
||||||
"
|
"
|
||||||
|
|
||||||
tcc_tests="
|
tcc_tests="
|
||||||
|
|
25
lib/tests/scaffold/67-m1-overflow-check.c
Normal file
25
lib/tests/scaffold/67-m1-overflow-check.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2023 Andrius Štikonas <andrius@stikonas.eu>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
main ()
|
||||||
|
{
|
||||||
|
return (0xe5894855 >> 31) - 1;
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
;;; GNU Mes --- Maxwell Equations of Software
|
;;; GNU Mes --- Maxwell Equations of Software
|
||||||
;;; Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
;;; Copyright © 2016,2017,2018,2019,2020,2021 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
;;; Copyright © 2023 Andrius Štikonas <andrius@stikonas.eu>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Mes.
|
;;; This file is part of GNU Mes.
|
||||||
;;;
|
;;;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
;;; GNU Mes --- Maxwell Equations of Software
|
;;; GNU Mes --- Maxwell Equations of Software
|
||||||
;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
;;; Copyright © 2023 Andrius Štikonas <andrius@stikonas.eu>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Mes.
|
;;; This file is part of GNU Mes.
|
||||||
;;;
|
;;;
|
||||||
|
@ -82,7 +83,7 @@
|
||||||
(or v (error "invalid value: x86_64:value->r: " v))
|
(or v (error "invalid value: x86_64:value->r: " v))
|
||||||
(let ((r (get-r info)))
|
(let ((r (get-r info)))
|
||||||
(if (and (>= v 0)
|
(if (and (>= v 0)
|
||||||
(< v #xffffffff))
|
(< v #x80000000))
|
||||||
`((,(string-append "mov____$i32,%" r) (#:immediate ,v)))
|
`((,(string-append "mov____$i32,%" r) (#:immediate ,v)))
|
||||||
`((,(string-append "mov____$i64,%" r) (#:immediate8 ,v))))))
|
`((,(string-append "mov____$i64,%" r) (#:immediate8 ,v))))))
|
||||||
|
|
||||||
|
@ -520,7 +521,7 @@
|
||||||
(cond ((< (abs v) #x80)
|
(cond ((< (abs v) #x80)
|
||||||
`((,(string-append "cmp____$i8,%" r) (#:immediate1 ,v))))
|
`((,(string-append "cmp____$i8,%" r) (#:immediate1 ,v))))
|
||||||
((and (>= v 0)
|
((and (>= v 0)
|
||||||
(< v #xffffffff))
|
(< v #x80000000))
|
||||||
`((,(string-append "cmp____$i32,%" r) (#:immediate ,v))))
|
`((,(string-append "cmp____$i32,%" r) (#:immediate ,v))))
|
||||||
(else
|
(else
|
||||||
`(,(string-append "mov____$i64,%r15") (#:immediate8 ,v)
|
`(,(string-append "mov____$i64,%r15") (#:immediate8 ,v)
|
||||||
|
@ -608,7 +609,7 @@
|
||||||
(cond ((< (abs v) #x80)
|
(cond ((< (abs v) #x80)
|
||||||
`((,(string-append "addl___$i8,(%" r ")") (#:immediate1 ,v))))
|
`((,(string-append "addl___$i8,(%" r ")") (#:immediate1 ,v))))
|
||||||
((and (>= v 0)
|
((and (>= v 0)
|
||||||
(< v #xffffffff))
|
(< v #x80000000))
|
||||||
`((,(string-append "addl___$i32,(%" r ")") (#:immediate ,v))))
|
`((,(string-append "addl___$i32,(%" r ")") (#:immediate ,v))))
|
||||||
(else
|
(else
|
||||||
`((,(string-append "mov____$i64,%r15") (#:immediate8 ,v))
|
`((,(string-append "mov____$i64,%r15") (#:immediate8 ,v))
|
||||||
|
@ -638,7 +639,7 @@
|
||||||
(define (x86_64:r-and info v)
|
(define (x86_64:r-and info v)
|
||||||
(let ((r (get-r info)))
|
(let ((r (get-r info)))
|
||||||
(if (and (>= v 0)
|
(if (and (>= v 0)
|
||||||
(< v #xffffffff))
|
(< v #x80000000))
|
||||||
`((,(string-append "and____$i32,%" r) (#:immediate ,v)))
|
`((,(string-append "and____$i32,%" r) (#:immediate ,v)))
|
||||||
`((,(string-append "mov____$i64,%r15") (#:immediate8 ,v))
|
`((,(string-append "mov____$i64,%r15") (#:immediate8 ,v))
|
||||||
(,(string-append "and____%r15,%" r))))))
|
(,(string-append "and____%r15,%" r))))))
|
||||||
|
|
Loading…
Reference in a new issue