FAQ
Hi all, a few quick questions.

A) does the linux_amd64 gc produce jump tables from iota-const-enum switch statements?
B) are there any major restrictions on this, i.e. no offsets from zero allowed, must be contiguous etc?
C) alas I don't know what I'm looking at in the assembly, if A is true could someone please post some code that compiles to a jump table on aforementioned compiler, I'd like a sane example to study from/experiment with?

Reasons: at this point mainly curiosity, I've been trying to make a big set of conditionals run faster. It checks for a custom entityType byte in each of a slice of objects once per global iteration, then calls a function based on the entityType. Another option I'm toying with is replacing the entityType byte with a function pointer to its update function, which is a closure factory-generated at entity init.

D) lastly, I don't know what performance gains a jump table would get me, but I'm willing to put some work in over xmas and benchmark the results, so don't criticize me for blindly groping. All I remember is from intro to electric circuits :s.

Thanks a-bundle, and a merry christmas(or other if you prefer)

Simon Watt.

--

Search Discussions

  • Rémy Oudompheng at Dec 25, 2012 at 5:17 pm

    2012/12/25 si guy <[email protected]>:
    Hi all, a few quick questions.

    A) does the linux_amd64 gc produce jump tables from iota-const-enum switch statements?
    No, when constants are involved it compiles the switch to a soup of
    ifs that perform a binary search.

    Rémy.

    --
  • Si guy at Dec 25, 2012 at 5:40 pm
    Oh, we'll I guess then I should clarify (oops), right now I'm not using consts and they're not contiguous, but I thought if I switched to them it might force this behaviour. Is said binary search soup faster than a table? I will have to test this. Further to that is there a way to _force_ the creation of a jump table? Is an array of function pointers sufficient? Again, I'm looking for a way to generate assembly that I _know_ produces a jump table. Then work from there.

    Thanks Rémy,

    Simon Watt

    --
  • Kyle Lemons at Dec 25, 2012 at 5:45 pm

    On Tue, Dec 25, 2012 at 12:40 PM, si guy wrote:

    Oh, we'll I guess then I should clarify (oops), right now I'm not using
    consts and they're not contiguous, but I thought if I switched to them it
    might force this behaviour. Is said binary search soup faster than a table?
    No, but it's fast and more general. It works, for instance, with strings
    in addition to numbers.

    I will have to test this. Further to that is there a way to _force_ the
    creation of a jump table? Is an array of function pointers sufficient?
    Again, I'm looking for a way to generate assembly that I _know_ produces a
    jump table. Then work from there.

    Thanks Rémy,

    Simon Watt

    --

    --
  • Kevin Malachowski at Dec 25, 2012 at 11:11 pm

    On Tuesday, 25 December 2012 12:44:39 UTC-5, Kyle Lemons wrote:
    On Tue, Dec 25, 2012 at 12:40 PM, si guy <[email protected] <javascript:>>wrote:
    Oh, we'll I guess then I should clarify (oops), right now I'm not using
    consts and they're not contiguous, but I thought if I switched to them it
    might force this behaviour. Is said binary search soup faster than a table?
    No, but it's fast and more general. It works, for instance, with strings
    in addition to numbers
    Is it not desirable to have the compiler choose which is best at
    compile-time (similar to what gcc does)? For consecutive constant numbers
    in a switch it would generate a jump table and for large, spaced out
    numbers (or other types, eg string) it would use a binary search. The
    switch between the table or the binary soup (a term I've never heard before
    but really enjoy!) would be up to whoever writes it I suppose, but it would
    be a compromise between speed and size.

    Kevin

    --
  • Kyle Lemons at Dec 26, 2012 at 4:57 am

    On Tue, Dec 25, 2012 at 6:10 PM, Kevin Malachowski wrote:
    On Tuesday, 25 December 2012 12:44:39 UTC-5, Kyle Lemons wrote:
    On Tue, Dec 25, 2012 at 12:40 PM, si guy wrote:

    Oh, we'll I guess then I should clarify (oops), right now I'm not using
    consts and they're not contiguous, but I thought if I switched to them it
    might force this behaviour. Is said binary search soup faster than a table?
    No, but it's fast and more general. It works, for instance, with strings
    in addition to numbers
    Is it not desirable to have the compiler choose which is best at
    compile-time (similar to what gcc does)? For consecutive constant numbers
    in a switch it would generate a jump table and for large, spaced out
    numbers (or other types, eg string) it would use a binary search. The
    switch between the table or the binary soup (a term I've never heard before
    but really enjoy!) would be up to whoever writes it I suppose, but it would
    be a compromise between speed and size.
    You're welcome to contribute such an implementation ;-).

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 25, '12 at 5:15p
activeDec 26, '12 at 4:57a
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2023 Grokbase