From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id 7A1917ED67 for ; Mon, 13 Aug 2012 21:21:44 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of jeffsco@psellos.com) identity=pra; client-ip=174.121.218.178; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="jeffsco@psellos.com"; x-sender="jeffsco@psellos.com"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of jeffsco@psellos.com) identity=mailfrom; client-ip=174.121.218.178; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="jeffsco@psellos.com"; x-sender="jeffsco@psellos.com"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@pse.psellos.com) identity=helo; client-ip=174.121.218.178; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="jeffsco@psellos.com"; x-sender="postmaster@pse.psellos.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAM9SKVCuedqy/2dsb2JhbABFugaBB4IgAQEEATo/EAtGVwaIGga4fpBjYAOITo4RhEiKNIJ/ X-IronPort-AV: E=Sophos;i="4.77,761,1336341600"; d="scan'208";a="153004143" Received: from pse.psellos.com ([174.121.218.178]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 13 Aug 2012 21:21:43 +0200 Received: from [192.168.0.23] (71-212-116-164.tukw.qwest.net [71.212.116.164]) (authenticated bits=0) by pse.psellos.com (8.13.8/8.13.8) with ESMTP id q7DJLXLS008133 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Mon, 13 Aug 2012 14:21:39 -0500 References: <51E93001-B3AB-4B8D-B46C-7ACA11346C38@psellos.com> In-Reply-To: Mime-Version: 1.0 (Apple Message framework v1280) Content-Type: text/plain; charset=us-ascii Message-Id: Content-Transfer-Encoding: 7bit Cc: Jeffrey Scofield , Caml List From: Jeffrey Scofield Date: Mon, 13 Aug 2012 12:21:33 -0700 To: Benedikt Meurer X-Mailer: Apple Mail (2.1280) X-Validation-by: jeffsco@psellos.com Subject: [Caml-list] Re: ARM code generator problem OCamlers, Benedikt: >> 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). Best regards, Jeffrey