ARM: Implement division and modulus.

* module/mescc/armv4/as.scm (armv4:r0/r1): Call "__mesabi_uldiv".
(armv4:r0%r1): Call "__mesabi_uldiv".
This commit is contained in:
Danny Milosavljevic 2019-02-22 00:23:23 +01:00 committed by Jan Nieuwenhuizen
parent 26b6db0bbe
commit 311a955b0b
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
1 changed files with 17 additions and 44 deletions

View File

@ -350,55 +350,28 @@
(r1 (get-r1 info)))
`((,(string-append "and____%" r1 ",%" r0)))))
;; FIXME: Signed or not?
(define (armv4:r0/r1 info signed?)
(let ((signed? #f) ; nobody knows, -- all advice are belong to us?
(allocated (.allocated info))
(r0 (get-r0 info))
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
(if (not (member "edx" allocated))
`(,@(if (equal? r0 "r0") '()
`(("push___%r0")
(,(string-append "mov____%" r0 ",%r0"))))
,(if signed? '("cltd") '("xor____%edx,%edx"))
,(if signed? `(,(string-append "idiv___%" r1)) `(,(string-append "div___%" r1)))
,@(if (equal? r0 "r0") '()
`((,(string-append "mov____%r0,%" r0))
("pop____%r0"))))
`(("push___%r0")
("push___%r1")
("push___%edx")
(,(string-append "mov____%" r1 ",%r1"))
(,(string-append "mov____%" r0 ",%r0"))
,(if signed? '("cltd") '("xor____%edx,%edx"))
,(if signed? `(,(string-append "idiv___%r1")) `(,(string-append "div___%r1")))
("pop____%edx")
("pop____%r1")
(,(string-append "mov____%r0,%" r0))
("pop____%r0")))))
;; __mesabi_uldiv(a, b, remainderp)
(cons* `(,(string-append "push___0"))
`(,(string-append "push___%" r1))
`(,(string-append "push___%" r0))
(armv4:call-label #f "__mesabi_uldiv" (* 4 3)))))
(define (armv4:r0%r1 info signed?)
(let ((signed? #f) ; nobody knows, -- all advice are belong to us?
(allocated (.allocated info))
(r0 (get-r0 info))
(let ((r0 (get-r0 info))
(r1 (get-r1 info)))
(if (not (member "edx" allocated))
`(,@(if (equal? r0 "r0") '()
`(("push___%r0")
(,(string-append "mov____%" r0 ",%r0"))))
,(if signed? '("cltd") '("xor____%edx,%edx"))
,(if signed? `(,(string-append "idiv___%" r1)) `(,(string-append "div___%" r1)))
(,(string-append "mov____%edx,%" r0)))
`(("push___%r0")
("push___%r1")
("push___%edx")
(,(string-append "mov____%" r1 ",%r1"))
(,(string-append "mov____%" r0 ",%r0"))
,(if signed? '("cltd") '("xor____%edx,%edx"))
,(if signed? `(,(string-append "idiv___%r1")) `(,(string-append "div___%r1")))
("pop____%edx")
("pop____%r1")
(,(string-append "mov____%edx,%" r0))
("pop____%r0")))))
;; __mesabi_uldiv(a, b, remainderp)
(append `(("push___%r0") ; slot for remainder
("mov____%esp,%r0")
((#:immediate1 4) "add____$i8,%r0")
("push___%r0") ; pointer to remainder
(,(string-append "push___%" r1))
(,(string-append "push___%" r0)))
(armv4:call-label #f "__mesabi_uldiv" (* 4 3))
`(("pop____%r0")))))
(define (armv4:r+value info v)
(let ((r (get-r info)))