ARM: Avoid using (abs INT_MIN) and (- INT_MIN).

* module/mescc/armv4/as.scm (immediate->r0): Inline abs.
(armv4:value->r): Inline abs.
(armv4:local->r): Inline abs.
(armv4:r->local+n): Inline abs.
(armv4:r-byte-mem-add): Inline abs.
(armv4:r-word-mem-add): Inline abs.
(armv4:local-ptr->r): Inline abs.
(armv4:r+value): Inline abs.
(armv4:r-cmp-value): Inline abs.
(armv4:r0+value): Inline abs.
(armv4:byte-r->local+n): Inline abs.
(armv4:word-r->local+n): Inline abs.
This commit is contained in:
Danny Milosavljevic 2020-06-16 14:08:58 +02:00
parent 073cfca2b4
commit 341682f474
No known key found for this signature in database
GPG key ID: E71A35542C30BAA5

View file

@ -47,19 +47,23 @@
`(,`(,(string-append "mov____%" r ",0x32(%ebp)") (#:immediate ,n)))))
(define (immediate->r0 v)
(if (< (abs v) #x100)
(if (< v 0)
(if (> v #x-100)
`(((#:immediate1 ,(- -1 v)) "mvn____%r0,$i8"))
`(((#:immediate1 ,v) "mov____$i8,%r0")))
`(("mov____$i32,%r0" (#:immediate ,v)))))
`(("mov____$i32,%r0" (#:immediate ,v))))
(if (< v #x100)
`(((#:immediate1 ,v) "mov____$i8,%r0"))
`(("mov____$i32,%r0" (#:immediate ,v))))))
(define (armv4:value->r info v)
(let ((r (get-r info)))
(if (< (abs v) #x100)
(if (< v 0)
(if (> v #x-100)
`(((#:immediate1 ,(- -1 v)) ,(string-append "mvn____%" r ",$i8")))
`(((#:immediate1 ,v) ,(string-append "mov____$i8,%" r))))
`((,(string-append "mov____$i32,%" r) (#:immediate ,v))))))
`((,(string-append "mov____$i32,%" r) (#:immediate ,v))))
(if (< v #x100)
`(((#:immediate1 ,v) ,(string-append "mov____$i8,%" r)))
`((,(string-append "mov____$i32,%" r) (#:immediate ,v)))))))
(define (armv4:ret . rest)
"Note: Pretends to be on x86 a lot"
@ -74,13 +78,15 @@
(define (armv4:local->r info n)
(let ((r (get-r info))
(n (- 0 (* 4 n))))
(if (< (abs n) #x100)
(if (< n 0)
`(((#:immediate1 ,(abs n))
(if (> n #x-100)
`(((#:immediate1 ,(- n))
,(string-append "ldr____%" r ",(%fp,-#$i8)")))
`((,(string-append "mov____0x32(%ebp),%" r) (#:immediate ,n))))
(if (< n #x100)
`(((#:immediate1 ,n)
,(string-append "ldr____%" r ",(%fp,+#$i8)"))))
`((,(string-append "mov____0x32(%ebp),%" r) (#:immediate ,n))))))
,(string-append "ldr____%" r ",(%fp,+#$i8)")))
`((,(string-append "mov____0x32(%ebp),%" r) (#:immediate ,n)))))))
(define (armv4:r0+r1 info)
(let ((r0 (get-r0 info))
@ -122,13 +128,17 @@
(define (armv4:r->local+n info id n)
(let ((n (+ (- 0 (* 4 id)) n))
(r (get-r info)))
`(,(if (< (abs n) #x100)
(if (< n 0)
`((#:immediate1 ,(abs n))
,(string-append "str____%" r ",(%fp,-#$i8)"))
`((#:immediate1 ,n)
(if (> n #x-100)
`(((#:immediate1 ,(- n))
,(string-append "str____%" r ",(%fp,-#$i8)")))
`((,(string-append "mov____%" r ",0x32(%ebp)")
(#:immediate ,n))))
(if (< n #x100)
`(((#:immediate1 ,n)
,(string-append "str____%" r ",(%fp,+#$i8)")))
`(,(string-append "mov____%" r ",0x32(%ebp)") (#:immediate ,n))))))
`((,(string-append "mov____%" r ",0x32(%ebp)")
(#:immediate ,n)))))))
(define (armv4:r-mem-add info v)
(let ((r (get-r info)))
@ -139,7 +149,7 @@
`((,(string-append "push___%r0"))
(,(string-append "ldrb___%r0,(%" r ")"))
,(if (< v 0)
`((#:immediate1 ,(abs v)) ,(string-append "sub____$i8,%r0"))
`((#:immediate1 ,(- v)) ,(string-append "sub____$i8,%r0"))
`((#:immediate1 ,v) ,(string-append "add____$i8,%r0")))
(,(string-append "strb___%r0,(%" r ")"))
(,(string-append "pop____%r0")))))
@ -149,7 +159,7 @@
`((,(string-append "push___%r0"))
(,(string-append "ldrh___%r0,(%" r ")"))
,(if (< v 0)
`((#:immediate1 ,(abs v)) ,(string-append "sub____$i8,%r0"))
`((#:immediate1 ,(- v)) ,(string-append "sub____$i8,%r0"))
`((#:immediate1 ,v) ,(string-append "add____$i8,%r0")))
(,(string-append "strh___%r0,(%" r ")"))
(,(string-append "pop____%r0")))))
@ -158,11 +168,13 @@
(let ((r (get-r info)))
(let ((n (- 0 (* 4 n))))
`((,(string-append "mov____%ebp,%" r))
,(if (< (abs n) #x100)
(if (< n 0)
`((#:immediate1 ,(abs n)) ,(string-append "sub____$i8,%" r))
`((#:immediate1 ,n) ,(string-append "add____$i8,%" r)))
`(,(string-append "add____$i32,%" r) (#:immediate ,n)))))))
,(if (< n 0)
(if (> n #x-100)
`((#:immediate1 ,(- n)) ,(string-append "sub____$i8,%" r))
`(,(string-append "add____$i32,%" r) (#:immediate ,n)))
(if (< n #x100)
`((#:immediate1 ,n) ,(string-append "add____$i8,%" r))
`(,(string-append "add____$i32,%" r) (#:immediate ,n))))))))
(define (armv4:label->r info label)
(let ((r (get-r info)))
@ -381,11 +393,13 @@
(define (armv4:r+value info v)
(let ((r (get-r info)))
(if (< (abs v) #x100)
(if (< v 0)
`(((#:immediate1 ,(abs v)) ,(string-append "sub____$i8,%" r)))
`(((#:immediate1 ,v) ,(string-append "add____$i8,%" r))))
`((,(string-append "add____$i32,%" r) (#:immediate ,v))))))
(if (> v #x-100)
`(((#:immediate1 ,(- v)) ,(string-append "sub____$i8,%" r)))
`((,(string-append "add____$i32,%" r) (#:immediate ,v))))
(if (< v #x100)
`(((#:immediate1 ,v) ,(string-append "add____$i8,%" r)))
`((,(string-append "add____$i32,%" r) (#:immediate ,v)))))))
(define (armv4:r0->r1-mem info)
(let ((r0 (get-r0 info))
@ -404,11 +418,13 @@
(define (armv4:r-cmp-value info v)
(let ((r (get-r info)))
(if (< (abs v) #x100)
(if (< v 0)
`(((#:immediate1 ,(abs v)) ,(string-append "cmn____$i8,%" r)))
`(((#:immediate1 ,v) ,(string-append "cmp____$i8,%" r))))
`((,(string-append "cmp____$i32,%" r) (#:immediate ,v))))))
(if (> v #x-100)
`(((#:immediate1 ,(- v)) ,(string-append "cmn____$i8,%" r)))
`((,(string-append "cmp____$i32,%" r) (#:immediate ,v))))
(if (< v #x100)
`(((#:immediate1 ,v) ,(string-append "cmp____$i8,%" r)))
`((,(string-append "cmp____$i32,%" r) (#:immediate ,v)))))))
(define (armv4:push-register info r)
`((,(string-append "push___%" r))))
@ -469,9 +485,11 @@
(define (armv4:r0+value info v)
(let ((r0 (get-r0 info)))
(if (< (abs v) #x100)
(if (< v 0)
`(((#:immediate1 ,(abs v)) ,(string-append "sub____$i8,%" r0)))
(if (> v #x-100)
`(((#:immediate1 ,(- v)) ,(string-append "sub____$i8,%" r0)))
`((,(string-append "add____$i32,%" r0) (#:immediate ,v))))
(if (< v #x100)
`(((#:immediate1 ,v) ,(string-append "add____$i8,%" r0))))
`((,(string-append "add____$i32,%" r0) (#:immediate ,v))))))
@ -482,24 +500,31 @@
(define (armv4:byte-r->local+n info id n)
(let* ((n (+ (- 0 (* 4 id)) n))
(r (get-r info)))
`(,(if (< (abs n) #x100)
(if (< n 0)
`((#:immediate1 ,(abs n))
`(,(if (< n 0)
(if (> n #x-100)
`((#:immediate1 ,(- n))
,(string-append "strb___%" r ",(%fp,-#$i8)"))
`(,(string-append "strb___%" r ",0x32(%ebp)")
(#:immediate ,n)))
(if (< n #x100)
`((#:immediate1 ,n)
,(string-append "strb___%" r ",(%fp,+#$i8)")))
`(,(string-append "strb___%" r ",0x32(%ebp)") (#:immediate ,n))))))
,(string-append "strb___%" r ",(%fp,+#$i8)"))
`(,(string-append "strb___%" r ",0x32(%ebp)") (#:immediate ,n)))))))
(define (armv4:word-r->local+n info id n)
(let* ((n (+ (- 0 (* 4 id)) n))
(r (get-r info)))
`(,(if (< (abs n) #x100)
(if (< n 0)
`((#:immediate1 ,(abs n))
`(,(if (< n 0)
(if (> n #x-100)
`((#:immediate1 ,(- n))
,(string-append "strh___%" r ",(%fp,-#$i8)"))
`(,(string-append "strh___%" r ",0x32(%ebp)")
(#:immediate ,n)))
(if (< n #x100)
`((#:immediate1 ,n)
,(string-append "strh___%" r ",(%fp,+#$i8)")))
`(,(string-append "strh___%" r ",0x32(%ebp)") (#:immediate ,n))))))
,(string-append "strh___%" r ",(%fp,+#$i8)"))
`(,(string-append "strh___%" r ",0x32(%ebp)")
(#:immediate ,n)))))))
(define (armv4:r-and info v)
(let ((r (get-r info)))