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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id A33277EEBF for ; Tue, 4 Aug 2015 11:06:12 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.17.12; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of goswin-v-b@web.de designates 212.227.17.12 as permitted sender) identity=mailfrom; client-ip=212.227.17.12; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.17.12; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0D1AADVf8BVnAwR49RbxmaCVgKBMUwBAQEBAQESAQEBAQEGDQkJIS6EJAEBBDIBOQoTCxgJJQ8FKIhMARnENR+FbwEBCAEBAQEBHYtPhFU6F4MBgRQFlHuMToFJhCKCYwyNGYNkhCWDOQEBAQ X-IPAS-Result: A0D1AADVf8BVnAwR49RbxmaCVgKBMUwBAQEBAQESAQEBAQEGDQkJIS6EJAEBBDIBOQoTCxgJJQ8FKIhMARnENR+FbwEBCAEBAQEBHYtPhFU6F4MBgRQFlHuMToFJhCKCYwyNGYNkhCWDOQEBAQ X-IronPort-AV: E=Sophos;i="5.15,607,1432591200"; d="scan'208";a="172602437" Received: from mout.web.de ([212.227.17.12]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 04 Aug 2015 11:06:12 +0200 Received: from frosties.localnet ([95.208.221.151]) by smtp.web.de (mrweb102) with ESMTPSA (Nemesis) id 0MOAnY-1ZS4UJ1bhU-005WXr for ; Tue, 04 Aug 2015 11:06:11 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.84) (envelope-from ) id 1ZMYAk-0001mx-Bw for caml-list@inria.fr; Tue, 04 Aug 2015 11:06:10 +0200 Date: Tue, 4 Aug 2015 11:06:10 +0200 From: Goswin von Brederlow To: caml-list@inria.fr Message-ID: <20150804090609.GA5689@frosties> References: <20150723083517.GA2029@pl-59055.rocqadm.inria.fr> <55B0AD74.2030302@inria.fr> <55B0B9DE.2070609@freenet.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <55B0B9DE.2070609@freenet.de> User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:Ilw2kEeBUVj/P97ifevNwPM4LyZLvzI5hM2xJ1p4vD4eM4qh5OB 3F5nDPDF76k+i+lkIi7UHBDaueCw1y3YustbRsGk/vSzXXEM56Uw9JTDwD1i9JuQWhQQtGF KsBBTjVICVlXOKKeCd6u9rxtpRqZOWBf2LC95jO1s12/dSPsoxSGI0CvI7xIN0CmaMOMutA IvN3yq2OpApG1P9rd+tdA== X-UI-Out-Filterresults: notjunk:1;V01:K0:dZ8L025CT4s=:hIGm2tZlMvsAI7g7m50Dx0 Qay7uESWqLFSReIyJMS/cPPtx0IWJcV87tdVpzC9GZrvXyZ2tGfXaS8+ghSmsGvFA0PWcagTb VtR858rqHhh9R69eSqEan5wlrGLh4BFkHO2IPTbEALb7NQkWKN4hlGqucb260EaEVNI4I/b/S 3gorslDsyRWKrvd+9ouIwW4rknD72BOnFJhW+elCZ//D8UhNFpU3AGFmwqonQ0yHeQ1QbKdbN IexhLR+IzlR8sBAE/S8QdgJmEN4Omz6wx6/CrKP/myOFJryt1K2FF4EONDKBhBCMdLN2zQ7l/ CXvyDjmjLlPg7mAYU6WG/aPLAjOP33S+nzQFXoE0lAnvQYx+FqtYABdzG9kKJ2aWyHxJDAHv9 E0HEQNlxyNxLYrErL48PTMzuPR+4SbI3TA6/qIFXgSGENdShLNLfr8HYnGV+hZ5k9I8bD6Sop kBHPDgsZbwZyXYymenGVAdRuNKI1VUQKY9j+Knr7y5i9UOBpm1fYu0mfWeveqSqXuH4vpPTXm 9JYTydktPXcqXAJG2UeLff9wY+r/tKN6MvKYRfCWWtztmyzUEJ0EjVZm1Mli/yJ+MjsKWVaob l2HRSEkl6X9PcSG0OZWhpztdSW/JvTR1VOfqQzKKJ5gsV1KU1zq0FIpiQnYODmCABUcXTsTl0 +FZsdAujZXdDI3mcrijgoSgX7qGwz3YaSh8u9qzUu/7nNOw== Subject: Re: [Caml-list] Comparing floats On Thu, Jul 23, 2015 at 11:54:38AM +0200, Mr. Herr wrote: > > > On 23.07.2015 11:01, Xavier Leroy wrote: > >On 23/07/2015 10:35, Sébastien Hinderer wrote: > >>What's the most efficient way to compare floats, please? > >>Is it the polymorphic compare function, or is there a more specialized > >>version of it? > >You'll get good performance by type-specializing Pervasives.compare: > > > >let compare_float (x: float) (y: float) = compare x y > > > >If you're absolutely sure your floats are not NaN, you can shave a few > >CPU cycles: > > > >let compare_float (x: float) (y: float) = > > if x < y then -1 else if x > y then 1 else 0 > > > The assembler code says compare_float is directly compiled to a function > that compares the 2 values > in xmm0 and xmm1 registers, while Pervasives.compare is a library function > written in C doing the same thing. > > The assembler code looks very very good. > > But I doubt that you could measure a difference. The type system will always > yield the float_compare function, doesn't it? So far my quickcheck... There are many cases where you have a polymorphic function (as in the code does not allow to infere that the type is float) doing lots of compares or you pass compare as argument to a polymorphic function. By specifically forcing the type to be float you can gain a lot of performance. If the type system already inferes the float type itself then you gain nothing. But that doesn't always happen (at the right time). MfG Goswin