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=1.6 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 2D949BBE1 for ; Thu, 12 Oct 2006 07:53:13 +0200 (CEST) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.226]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id k9C5rCa6021744 for ; Thu, 12 Oct 2006 07:53:12 +0200 Received: by wx-out-0506.google.com with SMTP id s6so481007wxc for ; Wed, 11 Oct 2006 22:53:09 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=P72IBsVxrWcqICFAvO2f/O2kXgesCORSpc+XpZd6XB6z3S2ps+IqYrGyIbkp/T7PrmTWgDMZfbxWvyFPW0ZbUiruC8TLLUIX5nJOPk9CWvM1lj/WBvfnEy39DlqsXE9hnqYjajwvbTwJYF822wAQ5sgHuncSQAn7NKyFlDud4v0= Received: by 10.70.29.7 with SMTP id c7mr2224226wxc; Wed, 11 Oct 2006 22:53:09 -0700 (PDT) Received: by 10.70.122.8 with HTTP; Wed, 11 Oct 2006 22:53:09 -0700 (PDT) Message-ID: Date: Thu, 12 Oct 2006 18:53:09 +1300 From: "Jonathan Roewen" To: "Carlos Pita" Subject: Re: [Caml-list] Why + vs +. but "fake" parametric polymorphism for < Cc: caml-list@yquem.inria.fr In-Reply-To: <1160631680.7649.27.camel@monad> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1160630365.7649.20.camel@monad> <1160631680.7649.27.camel@monad> X-j-chkmail-Score: MSGID : 452DD848.000 on discorde : j-chkmail score : X : 0/20 1 X-Miltered: at discorde with ID 452DD848.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; parametric:01 polymorphism:01 umh:01 compiler:01 val:01 ocaml:01 ocamlopt:01 wrote:01 caml-list:01 int:01 int:01 caml:02 asm:02 types:03 let:03 On 10/12/06, Carlos Pita 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. It is not an int comparison! max here would work on lists and probably most other non-abstract types in expected ways. Try: let int_max a b : int = if a > b then a else b ocamlopt -S will help you see what it generates for yourself. e.g.: camlTest__int_max_57: .L101: cmpl %ebx, %eax jle .L100 ret .align 16 .L100: movl %ebx, %eax ret .text .align 16 Jonathan