From: "Nicolas Cannasse" <warplayer@free.fr>
To: <skaller@tpg.com.au>, "Jacques Garrigue" <garrigue@kurims.kyoto-u.ac.jp>
Cc: <caml-list@inria.fr>
Subject: Re: [Caml-list] Stupid question
Date: Fri, 16 Jan 2004 06:41:56 +0100 [thread overview]
Message-ID: <002801c3dbf3$74483150$e237fea9@warp> (raw)
In-Reply-To: <20040116094357V.garrigue@kurims.kyoto-u.ac.jp>
> > > 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
prev parent reply other threads:[~2004-01-16 5:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-15 0:03 Brian Hurt
2004-01-15 3:57 ` skaller
2004-01-15 6:13 ` Brian Hurt
2004-01-15 8:37 ` Christophe Raffalli
2004-01-16 0:43 ` Jacques Garrigue
2004-01-16 2:35 ` Brian Hurt
2004-01-16 8:40 ` Hendrik Tews
2004-01-16 10:25 ` Frederic van der Plancke
2004-01-16 12:07 ` Alex Baretta
2004-01-16 5:41 ` Nicolas Cannasse [this message]
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='002801c3dbf3$74483150$e237fea9@warp' \
--to=warplayer@free.fr \
--cc=caml-list@inria.fr \
--cc=garrigue@kurims.kyoto-u.ac.jp \
--cc=skaller@tpg.com.au \
/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