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:
parent
a8a32a5280
commit
9a36cf22d0
|
@ -17,7 +17,7 @@
|
||||||
### along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
### 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)
|
# 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,%eax 05
|
||||||
DEFINE add____$i32,%ebx 81c3
|
DEFINE add____$i32,%ebx 81c3
|
||||||
|
@ -53,6 +53,7 @@ DEFINE cltd 99
|
||||||
DEFINE cmp____$0x32,%eax 3d
|
DEFINE cmp____$0x32,%eax 3d
|
||||||
DEFINE cmp____$i32,%eax 3d
|
DEFINE cmp____$i32,%eax 3d
|
||||||
DEFINE cmp____$i8,%eax 83f8
|
DEFINE cmp____$i8,%eax 83f8
|
||||||
|
DEFINE div___%ebx f7f3
|
||||||
DEFINE hlt f4
|
DEFINE hlt f4
|
||||||
DEFINE idiv___%ebx f7fb
|
DEFINE idiv___%ebx f7fb
|
||||||
DEFINE int cd
|
DEFINE int cd
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
# reduced instruction set: rax, rdi (some rcx for shift, rdx for mul, div)
|
# reduced instruction set: rax, rdi (some rcx for shift, rdx for mul, div)
|
||||||
# and r10 as i64 immediate helper
|
# and r10 as i64 immediate helper
|
||||||
# 211 instructions
|
# 212 instructions
|
||||||
|
|
||||||
DEFINE add____$i32,%rax 4805
|
DEFINE add____$i32,%rax 4805
|
||||||
DEFINE add____$i32,%rbp 4881c5
|
DEFINE add____$i32,%rbp 4881c5
|
||||||
|
@ -57,6 +57,7 @@ DEFINE cmp____$i8,%rax 4883f8
|
||||||
DEFINE cmp____%r15,%rax 4c39f8
|
DEFINE cmp____%r15,%rax 4c39f8
|
||||||
DEFINE cmp____%r15,%rdi 4c39ff
|
DEFINE cmp____%r15,%rdi 4c39ff
|
||||||
DEFINE cqto 4899
|
DEFINE cqto 4899
|
||||||
|
DEFINE div___%rdi 48f7f7
|
||||||
DEFINE hlt f4
|
DEFINE hlt f4
|
||||||
DEFINE idiv___%rdi 48f7ff
|
DEFINE idiv___%rdi 48f7ff
|
||||||
DEFINE ja32 0f87
|
DEFINE ja32 0f87
|
||||||
|
|
|
@ -355,7 +355,8 @@
|
||||||
`((,(string-append "and____%" r1 ",%" r0)))))
|
`((,(string-append "and____%" r1 ",%" r0)))))
|
||||||
|
|
||||||
(define (i386:r0/r1 info signed?)
|
(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))
|
(r0 (get-r0 info))
|
||||||
(r1 (get-r1 info)))
|
(r1 (get-r1 info)))
|
||||||
(if (not (member "edx" allocated))
|
(if (not (member "edx" allocated))
|
||||||
|
@ -363,7 +364,7 @@
|
||||||
`(("push___%eax")
|
`(("push___%eax")
|
||||||
(,(string-append "mov____%" r0 ",%eax"))))
|
(,(string-append "mov____%" r0 ",%eax"))))
|
||||||
,(if signed? '("cltd") '("xor____%edx,%edx"))
|
,(if signed? '("cltd") '("xor____%edx,%edx"))
|
||||||
(,(string-append "idiv___%" r1))
|
,(if signed? `(,(string-append "idiv___%" r1)) `(,(string-append "div___%" r1)))
|
||||||
,@(if (equal? r0 "eax") '()
|
,@(if (equal? r0 "eax") '()
|
||||||
`((,(string-append "mov____%eax,%" r0))
|
`((,(string-append "mov____%eax,%" r0))
|
||||||
("pop____%eax"))))
|
("pop____%eax"))))
|
||||||
|
@ -373,14 +374,15 @@
|
||||||
(,(string-append "mov____%" r1 ",%ebx"))
|
(,(string-append "mov____%" r1 ",%ebx"))
|
||||||
(,(string-append "mov____%" r0 ",%eax"))
|
(,(string-append "mov____%" r0 ",%eax"))
|
||||||
,(if signed? '("cltd") '("xor____%edx,%edx"))
|
,(if signed? '("cltd") '("xor____%edx,%edx"))
|
||||||
(,(string-append "idiv___%ebx"))
|
,(if signed? `(,(string-append "idiv___%ebx")) `(,(string-append "div___%ebx")))
|
||||||
("pop____%edx")
|
("pop____%edx")
|
||||||
("pop____%ebx")
|
("pop____%ebx")
|
||||||
(,(string-append "mov____%eax,%" r0))
|
(,(string-append "mov____%eax,%" r0))
|
||||||
("pop____%eax")))))
|
("pop____%eax")))))
|
||||||
|
|
||||||
(define (i386:r0%r1 info signed?)
|
(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))
|
(r0 (get-r0 info))
|
||||||
(r1 (get-r1 info)))
|
(r1 (get-r1 info)))
|
||||||
(if (not (member "edx" allocated))
|
(if (not (member "edx" allocated))
|
||||||
|
@ -388,7 +390,7 @@
|
||||||
`(("push___%eax")
|
`(("push___%eax")
|
||||||
(,(string-append "mov____%" r0 ",%eax"))))
|
(,(string-append "mov____%" r0 ",%eax"))))
|
||||||
,(if signed? '("cltd") '("xor____%edx,%edx"))
|
,(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)))
|
(,(string-append "mov____%edx,%" r0)))
|
||||||
`(("push___%eax")
|
`(("push___%eax")
|
||||||
("push___%ebx")
|
("push___%ebx")
|
||||||
|
@ -396,7 +398,7 @@
|
||||||
(,(string-append "mov____%" r1 ",%ebx"))
|
(,(string-append "mov____%" r1 ",%ebx"))
|
||||||
(,(string-append "mov____%" r0 ",%eax"))
|
(,(string-append "mov____%" r0 ",%eax"))
|
||||||
,(if signed? '("cltd") '("xor____%edx,%edx"))
|
,(if signed? '("cltd") '("xor____%edx,%edx"))
|
||||||
(,(string-append "idiv___%ebx"))
|
,(if signed? `(,(string-append "idiv___%ebx")) `(,(string-append "div___%ebx")))
|
||||||
("pop____%edx")
|
("pop____%edx")
|
||||||
("pop____%ebx")
|
("pop____%ebx")
|
||||||
(,(string-append "mov____%edx,%" r0))
|
(,(string-append "mov____%edx,%" r0))
|
||||||
|
|
|
@ -435,7 +435,8 @@
|
||||||
`((,(string-append "and____%" r1 ",%" r0)))))
|
`((,(string-append "and____%" r1 ",%" r0)))))
|
||||||
|
|
||||||
(define (x86_64:r0/r1 info signed?)
|
(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))
|
(r0 (get-r0 info))
|
||||||
(r1 (get-r1 info)))
|
(r1 (get-r1 info)))
|
||||||
(if (not (member "rdx" allocated))
|
(if (not (member "rdx" allocated))
|
||||||
|
@ -443,7 +444,7 @@
|
||||||
`(("push___%rax")
|
`(("push___%rax")
|
||||||
(,(string-append "mov____%" r0 ",%rax"))))
|
(,(string-append "mov____%" r0 ",%rax"))))
|
||||||
,(if signed? '("cqto") '("xor____%rdx,%rdx"))
|
,(if signed? '("cqto") '("xor____%rdx,%rdx"))
|
||||||
(,(string-append "idiv___%" r1))
|
,(if signed? `(,(string-append "idiv___%" r1)) `(,(string-append "div___%" r1)))
|
||||||
,@(if (equal? r0 "rax") '()
|
,@(if (equal? r0 "rax") '()
|
||||||
`((,(string-append "mov____%rax,%" r0))
|
`((,(string-append "mov____%rax,%" r0))
|
||||||
("pop____%rax"))))
|
("pop____%rax"))))
|
||||||
|
@ -453,14 +454,15 @@
|
||||||
(,(string-append "mov____%" r1 ",%rdi"))
|
(,(string-append "mov____%" r1 ",%rdi"))
|
||||||
(,(string-append "mov____%" r0 ",%rax"))
|
(,(string-append "mov____%" r0 ",%rax"))
|
||||||
,(if signed? '("cqto") '("xor____%rdx,%rdx"))
|
,(if signed? '("cqto") '("xor____%rdx,%rdx"))
|
||||||
(,(string-append "idiv___%rdi"))
|
,(if signed? `(,(string-append "idiv___%rdi")) `(,(string-append "div___%rdi")))
|
||||||
("pop____%rdx")
|
("pop____%rdx")
|
||||||
("pop____%rdi")
|
("pop____%rdi")
|
||||||
(,(string-append "mov____%rax,%" r0))
|
(,(string-append "mov____%rax,%" r0))
|
||||||
("pop____%rax")))))
|
("pop____%rax")))))
|
||||||
|
|
||||||
(define (x86_64:r0%r1 info signed?)
|
(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))
|
(r0 (get-r0 info))
|
||||||
(r1 (get-r1 info)))
|
(r1 (get-r1 info)))
|
||||||
(if (not (member "rdx" allocated))
|
(if (not (member "rdx" allocated))
|
||||||
|
@ -468,7 +470,7 @@
|
||||||
`(("push___%rax")
|
`(("push___%rax")
|
||||||
(,(string-append "mov____%" r0 ",%rax"))))
|
(,(string-append "mov____%" r0 ",%rax"))))
|
||||||
,(if signed? '("cqto") '("xor____%rdx,%rdx"))
|
,(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)))
|
(,(string-append "mov____%rdx,%" r0)))
|
||||||
`(("push___%rax")
|
`(("push___%rax")
|
||||||
("push___%rdi")
|
("push___%rdi")
|
||||||
|
@ -476,7 +478,7 @@
|
||||||
(,(string-append "mov____%" r1 ",%rdi"))
|
(,(string-append "mov____%" r1 ",%rdi"))
|
||||||
(,(string-append "mov____%" r0 ",%rax"))
|
(,(string-append "mov____%" r0 ",%rax"))
|
||||||
,(if signed? '("cqto") '("xor____%rdx,%rdx"))
|
,(if signed? '("cqto") '("xor____%rdx,%rdx"))
|
||||||
(,(string-append "idiv___%rdi"))
|
,(if signed? `(,(string-append "idiv___%rdi")) `(,(string-append "div___%rdi")))
|
||||||
("pop____%rdx")
|
("pop____%rdx")
|
||||||
("pop____%rdi")
|
("pop____%rdi")
|
||||||
(,(string-append "mov____%rdx,%" r0))
|
(,(string-append "mov____%rdx,%" r0))
|
||||||
|
|
Loading…
Reference in a new issue