From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=INTERRUPTUS autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 2BDCDBBE1 for ; Thu, 12 Oct 2006 07:49:52 +0200 (CEST) Received: from mallaury.nerim.net (smtp-104-thursday.noc.nerim.net [62.4.17.104]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k9C5np43031818 for ; Thu, 12 Oct 2006 07:49:51 +0200 Received: from hector.lesours (ours.starynkevitch.net [213.41.244.95]) by mallaury.nerim.net (Postfix) with ESMTP id 3B7FF4F3D3; Thu, 12 Oct 2006 07:49:35 +0200 (CEST) Received: from basile by hector.lesours with local (Exim 4.63) (envelope-from ) id 1GXtRr-0008Gb-49; Thu, 12 Oct 2006 07:49:39 +0200 Date: Thu, 12 Oct 2006 07:49:39 +0200 To: Carlos Pita Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Why + vs +. but "fake" parametric polymorphism for < Message-ID: <20061012054939.GA31702@ours.starynkevitch.net> References: <1160630365.7649.20.camel@monad> <1160631680.7649.27.camel@monad> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1160631680.7649.27.camel@monad> User-Agent: Mutt/1.5.13 (2006-08-11) From: Basile STARYNKEVITCH X-Miltered: at concorde with ID 452DD77F.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; parametric:01 polymorphism:01 basile:01 basile:01 ecrivait:01 umh:01 compiler:01 val:01 ocaml:01 ocaml:01 globl:01 rax:01 rax:01 faiencerie:01 92340:01 Le Thu, Oct 12, 2006 at 02:41:20AM -0300, Carlos Pita écrivait/wrote: > Umh, soon after writing my previous post I found out an interesting > chapter in the tutorial giving an exact example of asm code generated by > the compiler for comparison operator <: > > # let max a b = > if a > b then a else b;; > val max : 'a -> 'a -> 'a = > > ===> > [...] > ; Call the C "greaterthan" function (in the OCaml library). > pushl %ebx > pushl %eax > movl $greaterthan, %eax > call caml_c_call > .L102: > addl $8, %esp > ; If the C "greaterthan" function returned 1, jump to .L100 > [...] > > Pretty expensive for a simple int comparison I would say. If you explicitly type it as an integer compare let max (a : int) b = if a > b then a else b;; you get much more efficient code (AMD64 linux ocaml 3.09.2 Debian/Sid) .globl camlMaxi__max_57 camlMaxi__max_57: .L101: cmpq %rbx, %rax jle .L100 ret .align 4 .L100: movq %rbx, %rax ret .text -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basilestarynkevitchnet aliases: basiletunesorg = bstarynknerimnet 8, rue de la Faïencerie, 92340 Bourg La Reine, France