From: Benedikt Meurer <benedikt.meurer@googlemail.com>
To: Jeffrey Scofield <jeffsco@psellos.com>
Cc: Benedikt Meurer <benedikt.meurer@googlemail.com>,
Caml List <caml-list@inria.fr>
Subject: [Caml-list] Re: ARM code generator problem
Date: Tue, 14 Aug 2012 09:11:53 +0200 [thread overview]
Message-ID: <401723D2-9388-4FFF-8E7A-D741ED111E64@gmail.com> (raw)
In-Reply-To: <D851CF6D-4888-4D48-BFAA-DFC00C5AE572@psellos.com>
On Aug 13, 2012, at 21:21 , Jeffrey Scofield wrote:
> OCamlers, Benedikt:
Hey Jeffrey,
>>> The result is that a value in d7 is sometimes destroyed by a use of s14
>>> as a scratch register. In my code it was a call to float_of_int that
>>> destroyed a float value being kept in d7.
>>
>> If you look at destroyed_at_oper in asmcomp/arm/proc.ml, you'll see that
>> d7 (s14+s15) is marked as destroyed for those operations where it is
>> used as scratch register.
>
> I was able to reproduce this behavior with the stock OCaml 4.00.0 compiler,
> so I really do think there's a problem.
>
> I whittled my code down to just a few lines. Here it is:
>
> let rate_pos scounts : float =
> let m_MIN = -999.0
> in let max1s = Array.make 14 m_MIN
> in let max2s = Array.make_matrix 14 14 m_MIN
> in let try_build (k1: int) (m: float) : unit =
> let denom = 12
> in let try1b (sawk1, xct) k =
> let () =
> if max2s.(k1).(k) > m then
> let adjm = if m <= m_MIN then 0.0 else m
> in let numer =
> if k = k1 then 48
> else if sawk1 then 36
> else 24
> in let f = float_of_int numer /. float_of_int denom
> in let () =
> if max1s.(k1) <= m_MIN then max1s.(k1) <- 0.0
> in
> max1s.(k1) <-
> max1s.(k1) +. (max2s.(k1).(k) -. adjm) *. f
> in
> if k = k1 then
> (true, xct)
> else
> (sawk1, xct + scounts.(k))
> in
> ignore (List.fold_left try1b (false, 0) [])
> in let () = Array.iteri try_build max1s
> in
> 0.0
>
> (This is a heavily hacked up piece of an evaluation function for a card
> game app.)
>
> Here is my OCaml command line (running on Linux/ARM inside Qemu, as you
> suggested--it works!):
>
> $ ocamlopt -ffpu vfpv3 -c -S rate.ml
>
> I'm using vfpv3 because that's what I use for my iOS port. The system
> type is linux_eabihf, which is what you need to get vfpv3 support.
>
> The section that seems to misbehave is these three lines:
>
> in let f = float_of_int numer /. float_of_int denom
> in let () =
> if max1s.(k1) <= m_MIN then max1s.(k1) <- 0.0
>
> Here is the assembly code with added annotations:
>
> ldr r12, [r2, #16] @ r12 <- m_MIN block
> mov r0, r7, asr #1
> ldr r7, [r2, #20]
> movs r6, #0xc @ r6 <- denom
> fmsr s14, r6
> fsitod d10, s14 @ d10 <- float_of_int denom
> ldr r6, [r7, #-4]
> fldd d7, [r12, #0] @ d7 <- m_MIN
> ldr r12, [r2, #28]
> fmsr s14, r0 @ *** d7 is destroyed here ***
> fsitod d9, s14 @ d9 <- float_of_int numer
> cmp r12, r6, lsr #10
> bcs .L111
> add r6, r7, r12, lsl #2
> fldd d6, [r6, #-4] @ d6 <- max1s.(k1)
> fdivd d8, d9, d10
> fcmpd d6, d7 @ *** This comparison fails ***
> fmstat
> bhi .L104
>
> I built the OCaml 4.00.0 compiler from sources inside Qemu. The
> line for configure was just this:
>
> $ ./configure --host armv5tejl-unknown-linux-gnueabihf
>
> After that, I just built as usual.
>
> If you agree that this is a problem, I can create a Mantis
> bug report for it (if you like).
Jep, that's a bug indeed. Somewhow ocamlopt seems to believe that the Ifloatofint instruction preserves d7 although it is marked as destroyed for this operation.
> Best regards,
> Jeffrey
greets,
Benedikt
next prev parent reply other threads:[~2012-08-14 7:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-10 21:41 [Caml-list] " Jeffrey Scofield
2012-08-11 8:00 ` Benedikt Meurer
2012-08-11 8:13 ` Benedikt Meurer
2012-08-11 8:57 ` Jeffrey Scofield
2012-08-11 9:48 ` [Caml-list] " Benedikt Meurer
2012-08-11 8:52 ` [Caml-list] " Jeffrey Scofield
2012-08-13 19:21 ` [Caml-list] " Jeffrey Scofield
2012-08-14 7:11 ` Benedikt Meurer [this message]
2012-08-17 4:26 ` Jeffrey Scofield
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=401723D2-9388-4FFF-8E7A-D741ED111E64@gmail.com \
--to=benedikt.meurer@googlemail.com \
--cc=caml-list@inria.fr \
--cc=jeffsco@psellos.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox