caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ppc64le behaviour of Int64.min_int ÷ -1
@ 2015-06-29 17:50 Richard W.M. Jones
  2015-06-29 18:00 ` Xavier Leroy
  0 siblings, 1 reply; 4+ messages in thread
From: Richard W.M. Jones @ 2015-06-29 17:50 UTC (permalink / raw)
  To: caml-list

Downstream bug: https://bugzilla.redhat.com/show_bug.cgi?id=1236615

OCaml expects Int64.min_int ÷ -1 to overflow and wrap around
(resulting in Int64.min_int).  There is also a test case in the test
suite for this.  See this previously fixed bug:

http://caml.inria.fr/mantis/view.php?id=5513

The compiler seems to cater for the case where an overflow in the
division throws an exception.

Unfortunately ppc64le does neither of these things: On ppc64le the
result of the computation is explicitly undefined, it sets a flag bit
(OV), but it doesn't throw an exception.

[See page 76 of
https://www.power.org/wp-content/uploads/2013/05/PowerISA_V2.07_PUBLIC.pdf ]

I wonder if there is a way to tell the compiler about this?  I could
add a conditional branch, but that would make the expansion of every
Int64.div and Int64.rem quite large (but maybe that doesn't matter as
these functions are going to be slow anyway?)

Suggestions welcome ...

Rich.

-- 
Richard Jones
Red Hat

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] ppc64le behaviour of Int64.min_int ÷ -1
  2015-06-29 17:50 [Caml-list] ppc64le behaviour of Int64.min_int ÷ -1 Richard W.M. Jones
@ 2015-06-29 18:00 ` Xavier Leroy
  2015-06-29 18:08   ` Richard W.M. Jones
  0 siblings, 1 reply; 4+ messages in thread
From: Xavier Leroy @ 2015-06-29 18:00 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: caml users

[-- Attachment #1: Type: text/plain, Size: 1674 bytes --]

Hi Richard,

You need to put "let division_crashes_on_overflow = true" in asmcomp/$ARCH/
arch.ml, just like in asmcomp/power/arch.ml.  The name of the variable is
perhaps counterintuitive but means "min_int / -1 doesn't do what we want,
so add tests (in cmmgen) for this case".

- Xavier


2015-06-29 19:50 GMT+02:00 Richard W.M. Jones <rich@annexia.org>:

> Downstream bug: https://bugzilla.redhat.com/show_bug.cgi?id=1236615
>
> OCaml expects Int64.min_int ÷ -1 to overflow and wrap around
> (resulting in Int64.min_int).  There is also a test case in the test
> suite for this.  See this previously fixed bug:
>
> http://caml.inria.fr/mantis/view.php?id=5513
>
> The compiler seems to cater for the case where an overflow in the
> division throws an exception.
>
> Unfortunately ppc64le does neither of these things: On ppc64le the
> result of the computation is explicitly undefined, it sets a flag bit
> (OV), but it doesn't throw an exception.
>
> [See page 76 of
> https://www.power.org/wp-content/uploads/2013/05/PowerISA_V2.07_PUBLIC.pdf
> ]
>
> I wonder if there is a way to tell the compiler about this?  I could
> add a conditional branch, but that would make the expansion of every
> Int64.div and Int64.rem quite large (but maybe that doesn't matter as
> these functions are going to be slow anyway?)
>
> Suggestions welcome ...
>
> Rich.
>
> --
> Richard Jones
> Red Hat
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>

[-- Attachment #2: Type: text/html, Size: 2806 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] ppc64le behaviour of Int64.min_int ÷ -1
  2015-06-29 18:00 ` Xavier Leroy
@ 2015-06-29 18:08   ` Richard W.M. Jones
  2015-06-29 18:15     ` Richard W.M. Jones
  0 siblings, 1 reply; 4+ messages in thread
From: Richard W.M. Jones @ 2015-06-29 18:08 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: caml users

On Mon, Jun 29, 2015 at 08:00:30PM +0200, Xavier Leroy wrote:
> Hi Richard,
> 
> You need to put "let division_crashes_on_overflow = true" in asmcomp/$ARCH/
> arch.ml, just like in asmcomp/power/arch.ml.  The name of the variable is
> perhaps counterintuitive but means "min_int / -1 doesn't do what we want,
> so add tests (in cmmgen) for this case".

Thanks - I will try that.

Rich.

-- 
Richard Jones
Red Hat

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] ppc64le behaviour of Int64.min_int ÷ -1
  2015-06-29 18:08   ` Richard W.M. Jones
@ 2015-06-29 18:15     ` Richard W.M. Jones
  0 siblings, 0 replies; 4+ messages in thread
From: Richard W.M. Jones @ 2015-06-29 18:15 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: caml users

On Mon, Jun 29, 2015 at 07:08:39PM +0100, Richard W.M. Jones wrote:
> On Mon, Jun 29, 2015 at 08:00:30PM +0200, Xavier Leroy wrote:
> > Hi Richard,
> > 
> > You need to put "let division_crashes_on_overflow = true" in asmcomp/$ARCH/
> > arch.ml, just like in asmcomp/power/arch.ml.  The name of the variable is
> > perhaps counterintuitive but means "min_int / -1 doesn't do what we want,
> > so add tests (in cmmgen) for this case".
> 
> Thanks - I will try that.

And in fact it works too - great!

Rich.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-06-29 18:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-29 17:50 [Caml-list] ppc64le behaviour of Int64.min_int ÷ -1 Richard W.M. Jones
2015-06-29 18:00 ` Xavier Leroy
2015-06-29 18:08   ` Richard W.M. Jones
2015-06-29 18:15     ` Richard W.M. Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).