caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Johannes <adhocrocker@gmail.com>
To: caml-list@inria.fr
Subject: Fwd: [Caml-list] Re: Binary logarithm of a power of 2
Date: Sat, 28 May 2011 23:13:41 +0200	[thread overview]
Message-ID: <BANLkTinVQ+6G9=qW5FHb6UaGRBQM-Y0-FQ@mail.gmail.com> (raw)
In-Reply-To: <BANLkTimtMZvoBKHznBYH91czci=YdiRcog@mail.gmail.com>

A link to the de Bruijn paper can be found on the "Bit Twiddling Hacks" page
linked earlyier in this thread:
http://graphics.stanford.edu/~seander/bithacks.html

I used it myself -- although with JavaScript and did not run any benchmarks --
and I liked the approach, very neat.

2011/5/28 Matteo Frigo <athena@fftw.org>:
> A way exists to compute the binary logarithm with one multiplication and
> a couple of shifts.  See Charles E. Leiserson, Harald Prokop, and Keith
> H. Randall: Using de Bruijn Sequences to Index a 1 in a Computer Word.
>
> The idea is that a magic 64-bit string of zeros and ones exists such
> that all possible strings of 6 bits appear as substrings of the string.
> Such a sequence is called a "de Bruijn Sequence".  Let K be such a
> string interpreted as an int64.  Then K * 2^n shifts K to the left by n
> places, leaving a unique encoding of n in the upper 6 bits of the
> product.
>
> Knuth Vol. 4A remarks that this is an old trick, invented but not
> published by some gentleman at IBM in the late sixties.  (Sorry, I don't
> have Knuth at hand for an exact reference.)  However the 1998 paper by
> Leiserson et al. should be available via google.
>
> Regards,
> Matteo Frigo
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>


  parent reply	other threads:[~2011-05-28 21:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-26 15:51 [Caml-list] " Dario Teixeira
2011-05-26 19:28 ` Goswin von Brederlow
2011-05-27 11:50 ` Dario Teixeira
2011-05-27 13:26   ` [Caml-list] " Sylvain Le Gall
2011-05-27 17:15     ` Xavier Leroy
2011-05-27 18:04       ` Dario Teixeira
2011-05-27 18:37         ` Till Varoquaux
2011-05-27 18:46           ` Till Varoquaux
2011-05-28  0:28             ` Harrison, John R
2011-05-28 15:58         ` Richard W.M. Jones
2011-05-28 16:04           ` Edgar Friendly
2011-05-28 17:50       ` Matteo Frigo
     [not found]         ` <BANLkTimtMZvoBKHznBYH91czci=YdiRcog@mail.gmail.com>
2011-05-28 21:13           ` Johannes [this message]
2011-05-30 11:48         ` Jean-Christophe Filliâtre

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='BANLkTinVQ+6G9=qW5FHb6UaGRBQM-Y0-FQ@mail.gmail.com' \
    --to=adhocrocker@gmail.com \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).