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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 8C3E47FA5F for ; Thu, 19 Jan 2017 14:25:59 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=frederic.bour@lakaban.net; spf=Pass smtp.mailfrom=frederic.bour@lakaban.net; spf=None smtp.helo=postmaster@mail.lakaban.net Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of frederic.bour@lakaban.net) identity=pra; client-ip=213.251.185.180; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="frederic.bour@lakaban.net"; x-sender="frederic.bour@lakaban.net"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of frederic.bour@lakaban.net designates 213.251.185.180 as permitted sender) identity=mailfrom; client-ip=213.251.185.180; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="frederic.bour@lakaban.net"; x-sender="frederic.bour@lakaban.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail.lakaban.net) identity=helo; client-ip=213.251.185.180; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="frederic.bour@lakaban.net"; x-sender="postmaster@mail.lakaban.net"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AwzZH3RZUHA85Kqu9HgLUxXb/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZr865bnLW6fgltlLVR4KTs6sC0LuK9fy5EjBeqb+681k6OKRWUBEEjc?= =?us-ascii?q?hE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRo?= =?us-ascii?q?LerpBIHSk9631+ev8JHPfglEnjSwbLd9IRmsogjdq8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ur?= =?us-ascii?q?g97XcxD5+8JYPKRYmnibrH2iqnSM4FLltaA0yBRC+7P76PXO0BPWfLepds?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AHBQDevYBY/7S5+9VeGwEBAQMBAQEJA?= =?us-ascii?q?QEBFgEBAQMBAQEJAQEBgkRQAQEBAQGCCIMLRop6mRSPNIYeAgICgjsVAQEBAQE?= =?us-ascii?q?BAQEBAQFiKIIzGwGCGwYMFwQZAQE3AQ8JAkICAiE2BhOIaAMYBJIZnGZogWs6g?= =?us-ascii?q?wgBAQWEJQ2CfAEBAQEBBQEBAQEBAQEBAQEWCIhQgmmCUYR+LYIxmxE4jWCUc4o?= =?us-ascii?q?bhC6EJzUigSkoRBABghqCAYIMcolkAQEB?= X-IPAS-Result: =?us-ascii?q?A0AHBQDevYBY/7S5+9VeGwEBAQMBAQEJAQEBFgEBAQMBAQE?= =?us-ascii?q?JAQEBgkRQAQEBAQGCCIMLRop6mRSPNIYeAgICgjsVAQEBAQEBAQEBAQFiKIIzG?= =?us-ascii?q?wGCGwYMFwQZAQE3AQ8JAkICAiE2BhOIaAMYBJIZnGZogWs6gwgBAQWEJQ2CfAE?= =?us-ascii?q?BAQEBBQEBAQEBAQEBAQEWCIhQgmmCUYR+LYIxmxE4jWCUc4obhC6EJzUigSkoR?= =?us-ascii?q?BABghqCAYIMcolkAQEB?= X-IronPort-AV: E=Sophos;i="5.33,254,1477954800"; d="scan'208,217";a="209952010" Received: from pepper.lakaban.net (HELO mail.lakaban.net) ([213.251.185.180]) by mail3-smtp-sop.national.inria.fr with ESMTP; 19 Jan 2017 14:25:58 +0100 Received: from client-eduroam770.canalip.upmc.fr (client-eduroam770.canalip.upmc.fr [134.157.123.5]) (Authenticated sender: defre@ygg-drasil.fr) by mail.lakaban.net (Postfix) with ESMTPSA id E5E438A001B; Thu, 19 Jan 2017 13:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=lakaban.net; s=default; t=1484832214; bh=h2knf998OFIxWihn88SnJ+U1Sjl22r2WCos8HUGnYx8=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=Xuqr0/9mqBQGumUh7nrtmvWsjfVznc1o+KzHi0an9O0vdSKUT//IrPHsDWWdu+zey tn5LMK5w9zN0Qk3GW+6TbFEUWwrSUYHMymZEAi//sxTrl69z9uZvhPMkImlWFC+wkA fQ6xhYqgvPzqIPFiOKZ1Wn0Fhczn77Z0hB3I/zwU= From: =?utf-8?B?RnLDqWTDqXJpYyBCb3Vy?= Message-Id: <88AFA979-41BD-4E93-BA6F-604D88427F2C@lakaban.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_A9720B2E-67ED-4FF7-8F2F-4B85CDE927DF" Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Date: Thu, 19 Jan 2017 14:26:02 +0100 In-Reply-To: Cc: Nils Becker , "caml-list@inria.fr" To: Gabriel Scherer References: <2B595CCC-1121-4C8C-8F5F-A235D3AB19BB@yahoo.com> <64e5fca1-a5da-9ff5-ad90-b23343d17360@bioquant.uni-heidelberg.de> X-Mailer: Apple Mail (2.3259) Subject: Re: [Caml-list] Ocaml optimizer pitfalls & work-arounds --Apple-Mail=_A9720B2E-67ED-4FF7-8F2F-4B85CDE927DF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Le 19 janv. 2017 =C3=A0 12:39, Gabriel Scherer = a =C3=A9crit : >=20 >> the min, max issues can be avoided without much trouble by using >> specialized comparison, as provided in standard library extensions. >=20 > Note that min/max are already optimized from generic to specialized > when the type information is known at type-checking time. (It used to > be the case that only fully applied calls were optimized, this was > improved by Fr=C3=A9d=C3=A9ric Bour to extend to non-applied primitives i= n 4.03 > (eg. "let eq : int -> int -> _ =3D (=3D)"). That does not work when those > functions are used inside a functor body at an abstract type (which is > when we want inlining and specialization to interact better), but > there neither do Float.equal or Int.compare. Alas, min/max cannot benefit from this optimisation. In Pervasives, they are defined as: let min x y =3D if x <=3D y then x else y let max x y =3D if x >=3D y then x else y Specialization only happens for primitives, here it is a plain definition. So no specialization unless the definitions are copied and annotated :(.= --Apple-Mail=_A9720B2E-67ED-4FF7-8F2F-4B85CDE927DF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Le 19 janv. 2017 = =C3=A0 12:39, Gabriel Scherer <gabriel.scherer@gmail.com> a =C3=A9crit :

the min, max= issues can be avoided without much trouble by using
speciali= zed comparison, as provided in standard library extensions.
<= /blockquote>
Note that min/max are already optimized from gen= eric to specialized
when the type information is known at typ= e-checking time. (It used to
be the case that only fully appl= ied calls were optimized, this was
improved by Fr=C3=A9d=C3= =A9ric Bour to extend to non-applied primitives in 4.03
(eg. = "let eq : int -> int -> _ =3D (=3D)"). That does not work when those<= br class=3D"">functions are used inside a functor body at an abstract type = (which is
when we want inlining and specialization to interac= t better), but
there neither do Float.equal or Int.compare.

Alas, = min/max cannot benefit from this optimisation.

In Pervasives, they are defined as:

let min x y = =3D if x <=3D y then x else y
let max x y =3D if x >=3D<= span style=3D"font-variant-ligatures: no-common-ligatures" class=3D""> y then x else y
<= div style=3D"margin: 0px; font-size: 11px; line-height: normal; font-family= : Menlo; background-color: rgb(255, 255, 255);" class=3D"">

Specializat= ion only happens for primitives, here it is a plain definition.
So no speciali= zation unless the definitions are copied and annotated :(.
= --Apple-Mail=_A9720B2E-67ED-4FF7-8F2F-4B85CDE927DF--