From: "Jonathan Roewen" <jonathan.roewen@gmail.com>
To: "Carlos Pita" <cpitadev@yahoo.com.ar>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Why + vs +. but "fake" parametric polymorphism for <
Date: Thu, 12 Oct 2006 18:53:09 +1300 [thread overview]
Message-ID: <ad8cfe7e0610112253t5898f697o5550271aee548bf5@mail.gmail.com> (raw)
In-Reply-To: <1160631680.7649.27.camel@monad>
On 10/12/06, Carlos Pita <cpitadev@yahoo.com.ar> 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 = <fun>
>
> ===>
> [...]
> ; 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 <source> 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
next prev parent reply other threads:[~2006-10-12 5:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-12 5:19 Carlos Pita
2006-10-12 5:41 ` [Caml-list] " Carlos Pita
2006-10-12 5:49 ` Basile STARYNKEVITCH
2006-10-12 5:53 ` Jonathan Roewen [this message]
2006-10-12 6:10 ` Carlos Pita
-- strict thread matches above, loose matches on Subject: below --
2006-10-12 5:18 Carlos Pita
2006-10-12 5:45 ` [Caml-list] " Jacques Garrigue
2006-10-12 5:58 ` Carlos Pita
2006-10-12 6:08 ` Jonathan Roewen
[not found] ` <452DF46C.802@fmf.uni-lj.si>
2006-10-12 14:26 ` Carlos Pita
2006-10-13 11:56 ` Diego Olivier FERNANDEZ PONS
2006-10-13 12:14 ` Gerd Stolpmann
2006-10-13 12:46 ` Diego Olivier FERNANDEZ PONS
2006-10-13 13:01 ` Luc Maranget
2006-10-13 13:15 ` Diego Olivier FERNANDEZ PONS
2006-10-13 13:15 ` skaller
2006-10-13 13:36 ` Luc Maranget
2006-10-13 13:53 ` Gerd Stolpmann
2006-10-13 14:16 ` Luc Maranget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ad8cfe7e0610112253t5898f697o5550271aee548bf5@mail.gmail.com \
--to=jonathan.roewen@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=cpitadev@yahoo.com.ar \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox