[GHC] #9159: cmm case, binary search instead of jump table
GHC
ghc-devs at haskell.org
Fri Jul 4 14:43:01 UTC 2014
#9159: cmm case, binary search instead of jump table
--------------------------------------------+------------------------------
Reporter: wojteknar | Owner:
Type: feature request | Status: new
Priority: lowest | Milestone:
Component: Compiler | Version: 7.8.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Runtime performance bug | Unknown/Multiple
Test Case: | Difficulty: Unknown
Blocking: | Blocked By:
| Related Tickets:
--------------------------------------------+------------------------------
Comment (by arotenberg):
For comparison: The Java Virtual Machine has two instructions called
`tableswitch` and `lookupswitch`, which are normally implemented as a
lookup table and a binary search, respectively.
[http://cr.openjdk.java.net/~forax/lambda/src/share/classes/com/sun/tools/javac/jvm/Gen.java.html
Here] is the code javac uses to decide whether to generate a `tableswitch`
or `lookupswitch` for a `switch` statement:
{{{
// Determine whether to issue a tableswitch or a lookupswitch
// instruction.
long table_space_cost = 4 + ((long) hi - lo + 1); // words
long table_time_cost = 3; // comparisons
long lookup_space_cost = 3 + 2 * (long) nlabels;
long lookup_time_cost = nlabels;
int opcode =
nlabels > 0 &&
table_space_cost + 3 * table_time_cost <=
lookup_space_cost + 3 * lookup_time_cost
?
tableswitch : lookupswitch;
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9159#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list