mescc: Another attempt at divide.

* module/mescc/i386/as.scm (i386:r0/r1): Never be signed.  Use div for unsigned.
(i386:r0%r1): Likewise.
* module/mescc/x86_64/as.scm (x86_64:r0/r1): Likewise.
(x86_64:r0%r1): Likewise.
* lib/x86-mes/x86.M1: Add div.
* lib/x86_64-mes/x86_64.M1: Likewise.
This commit is contained in:
Jan Nieuwenhuizen 2018-10-07 15:15:45 +02:00
parent a8a32a5280
commit 9a36cf22d0
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
4 changed files with 20 additions and 14 deletions

View File

@ -17,7 +17,7 @@
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
# reduced instruction set: eax, ebx (some ecx for shift, edx for mul, div)
# 191 instructions
# 193 instructions
DEFINE add____$i32,%eax 05
DEFINE add____$i32,%ebx 81c3
@ -53,6 +53,7 @@ DEFINE cltd 99
DEFINE cmp____$0x32,%eax 3d
DEFINE cmp____$i32,%eax 3d
DEFINE cmp____$i8,%eax 83f8
DEFINE div___%ebx f7f3
DEFINE hlt f4
DEFINE idiv___%ebx f7fb
DEFINE int cd

View File

@ -18,7 +18,7 @@
# reduced instruction set: rax, rdi (some rcx for shift, rdx for mul, div)
# and r10 as i64 immediate helper
# 211 instructions
# 212 instructions
DEFINE add____$i32,%rax 4805
DEFINE add____$i32,%rbp 4881c5
@ -57,6 +57,7 @@ DEFINE cmp____$i8,%rax 4883f8
DEFINE cmp____%r15,%rax 4c39f8
DEFINE cmp____%r15,%rdi 4c39ff
DEFINE cqto 4899
DEFINE div___%rdi 48f7f7
DEFINE hlt f4
DEFINE idiv___%rdi 48f7ff
DEFINE ja32 0f87

View File

@ -355,7 +355,8 @@
`((,(string-append "and____%" r1 ",%" r0)))))
(define (i386:r0/r1 info signed?)
(let ((allocated (.allocated info))
(let ((signed? #f) ; nobody knows, -- all advice are belong to us?
(allocated (.allocated info))
(r0 (get-r0 info))
(r1 (get-r1 info)))
(if (not (member "edx" allocated))
@ -363,7 +364,7 @@
`(("push___%eax")
(,(string-append "mov____%" r0 ",%eax"))))
,(if signed? '("cltd") '("xor____%edx,%edx"))
(,(string-append "idiv___%" r1))
,(if signed? `(,(string-append "idiv___%" r1)) `(,(string-append "div___%" r1)))
,@(if (equal? r0 "eax") '()
`((,(string-append "mov____%eax,%" r0))
("pop____%eax"))))
@ -373,14 +374,15 @@
(,(string-append "mov____%" r1 ",%ebx"))
(,(string-append "mov____%" r0 ",%eax"))
,(if signed? '("cltd") '("xor____%edx,%edx"))
(,(string-append "idiv___%ebx"))
,(if signed? `(,(string-append "idiv___%ebx")) `(,(string-append "div___%ebx")))
("pop____%edx")
("pop____%ebx")
(,(string-append "mov____%eax,%" r0))
("pop____%eax")))))
(define (i386:r0%r1 info signed?)
(let ((allocated (.allocated info))
(let ((signed? #f) ; nobody knows, -- all advice are belong to us?
(allocated (.allocated info))
(r0 (get-r0 info))
(r1 (get-r1 info)))
(if (not (member "edx" allocated))
@ -388,7 +390,7 @@
`(("push___%eax")
(,(string-append "mov____%" r0 ",%eax"))))
,(if signed? '("cltd") '("xor____%edx,%edx"))
(,(string-append "idiv___%" r1))
,(if signed? `(,(string-append "idiv___%" r1)) `(,(string-append "div___%" r1)))
(,(string-append "mov____%edx,%" r0)))
`(("push___%eax")
("push___%ebx")
@ -396,7 +398,7 @@
(,(string-append "mov____%" r1 ",%ebx"))
(,(string-append "mov____%" r0 ",%eax"))
,(if signed? '("cltd") '("xor____%edx,%edx"))
(,(string-append "idiv___%ebx"))
,(if signed? `(,(string-append "idiv___%ebx")) `(,(string-append "div___%ebx")))
("pop____%edx")
("pop____%ebx")
(,(string-append "mov____%edx,%" r0))

View File

@ -435,7 +435,8 @@
`((,(string-append "and____%" r1 ",%" r0)))))
(define (x86_64:r0/r1 info signed?)
(let ((allocated (.allocated info))
(let ((signed? #f) ; nobody knows, -- all advice are belong to us?
(allocated (.allocated info))
(r0 (get-r0 info))
(r1 (get-r1 info)))
(if (not (member "rdx" allocated))
@ -443,7 +444,7 @@
`(("push___%rax")
(,(string-append "mov____%" r0 ",%rax"))))
,(if signed? '("cqto") '("xor____%rdx,%rdx"))
(,(string-append "idiv___%" r1))
,(if signed? `(,(string-append "idiv___%" r1)) `(,(string-append "div___%" r1)))
,@(if (equal? r0 "rax") '()
`((,(string-append "mov____%rax,%" r0))
("pop____%rax"))))
@ -453,14 +454,15 @@
(,(string-append "mov____%" r1 ",%rdi"))
(,(string-append "mov____%" r0 ",%rax"))
,(if signed? '("cqto") '("xor____%rdx,%rdx"))
(,(string-append "idiv___%rdi"))
,(if signed? `(,(string-append "idiv___%rdi")) `(,(string-append "div___%rdi")))
("pop____%rdx")
("pop____%rdi")
(,(string-append "mov____%rax,%" r0))
("pop____%rax")))))
(define (x86_64:r0%r1 info signed?)
(let ((allocated (.allocated info))
(let ((signed? #f) ; nobody knows, -- all advice are belong to us?
(allocated (.allocated info))
(r0 (get-r0 info))
(r1 (get-r1 info)))
(if (not (member "rdx" allocated))
@ -468,7 +470,7 @@
`(("push___%rax")
(,(string-append "mov____%" r0 ",%rax"))))
,(if signed? '("cqto") '("xor____%rdx,%rdx"))
(,(string-append "idiv___%" r1))
,(if signed? `(,(string-append "idiv___%" r1)) `(,(string-append "div___%" r1)))
(,(string-append "mov____%rdx,%" r0)))
`(("push___%rax")
("push___%rdi")
@ -476,7 +478,7 @@
(,(string-append "mov____%" r1 ",%rdi"))
(,(string-append "mov____%" r0 ",%rax"))
,(if signed? '("cqto") '("xor____%rdx,%rdx"))
(,(string-append "idiv___%rdi"))
,(if signed? `(,(string-append "idiv___%rdi")) `(,(string-append "div___%rdi")))
("pop____%rdx")
("pop____%rdi")
(,(string-append "mov____%rdx,%" r0))