From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id GAA12524; Fri, 16 Jan 2004 06:37:20 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id GAA12194 for ; Fri, 16 Jan 2004 06:37:19 +0100 (MET) Received: from mwinf0202.wanadoo.fr (smtp2.wanadoo.fr [193.252.22.29]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id i0G5bI515809 for ; Fri, 16 Jan 2004 06:37:18 +0100 (MET) Received: from warp (ABordeaux-103-1-17-100.w81-49.abo.wanadoo.fr [81.49.74.100]) by mwinf0202.wanadoo.fr (SMTP Server) with SMTP id 9DE59A4001AF; Fri, 16 Jan 2004 06:37:17 +0100 (CET) Message-ID: <002801c3dbf3$74483150$e237fea9@warp> From: "Nicolas Cannasse" To: , "Jacques Garrigue" Cc: References: <1074139041.7527.2.camel@localhost.localdomain> <20040116094357V.garrigue@kurims.kyoto-u.ac.jp> Subject: Re: [Caml-list] Stupid question Date: Fri, 16 Jan 2004 06:41:56 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; cannasse:01 warplayer:01 caml-list:01 stupid:01 poking:01 inequality:01 optimised:01 non-constant:01 optimised:01 enumerations:01 cannasse:01 compiler:01 compiler:01 tokens:01 bool:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > > I was poking around in the produced assembly code of some ocaml code of > > > mine, and I noticed something. The construct: > > > if (x < m) <> (y < m) then > > > ... > > > > > > when the compiler knows that x, y, and m are all ints, it calls an > > > external C routine to compare the two booleans. But the construct: > > > > > > if (x < m) != (y < m) then > > > ... > > > > > > does not. Now, this isn't a big deal- I just replaced <> with != and no > > > problem. But I was kind of interested in why the compiler didn't catch > > > and optimize this. Is there some sort of subtle semantic difference I'm > > > too dense to see? > > > > Well, <> is a polymorphic value comparison. > > Whereas != is a physical inequality comparison. > > Yes indeed. > But the compiler is clever enough to use specific comparison functions > when the type is known to be int or float. > Since bool looks like a subset of int, one might expect it to be > optimised also. However, bool is just a normal sum type, and since > some sum types have non-constant constructors, in general sum types > require a recursive comparison operation. > For types where constructors are constant, this might be optimised... You mean that actually comparisons on type t = A | B | C are using polymorphic recursive C function ? That's not nice, especially when working with lexers that generate this kind of tokens. I would expect that such enumerations should be as fast as in C. If someone hasn't posted yet a feature request for improving that, I'll do. Nicolas Cannasse ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners