- Evan
Could anyone answer whether there is a genuine reason that this isn't implemented?
Could anyone answer whether there is a genuine reason that this isn't implemented? Or is this on the todo list?
> Could anyone answer whether there is a genuine reason that this isn't
> implemented? Or is this on the todo list?
There is no special reason that this optimization is not implemented.
But as far as I know nobody is actively working on it.
Ian
when you are considering native-client
restrictions, jump tables become impossible.
also note that go switches are different than
c switches. non-constant cases have to be
tested individually no matter what.
having said that, a large (where large depends
on architecture) dense switch would be faster
than what is implemented now. BUT there are
two parameters needed to implement it. how
large and how dense. no matter what is used
for large and dense, there will be a micro-benchmark
on some machine, under some alignment, with
some branch cache that will look wrong.
what is implemented is as follows.
1. in order, all non-constant cases are
compiled and tested as if-elses.
2. groups of larger than 3
constant cases are binary
divided and conquered.
3. 3 or fewer cases are compared
linearly.
i honestly dont think there is a much
better algorithm across all machines.
> i honestly dont think there is a much
> better algorithm across all machines.
Agreed.
Roger Sayles did an interesting analysis of switch algorithms for C/C++
across architectures at the 2008 GCC Summit. It starts on page 103 of
http://gcc.gnu.org/wiki/HomePage?action=AttachFile&do=view&target=gcc-2008-proceedings.pdf
Of course Go is more complex because of non-constant cases.
Ian
what is implemented is as follows.
1. in order, all non-constant cases are
compiled and tested as if-elses.
2. groups of larger than 3
constant cases are binary
divided and conquered.
3. 3 or fewer cases are compared
linearly.i honestly dont think there is a much
better algorithm across all machines.
Ken Thompson <k...@google.com> writes:> i honestly dont think there is a much
> better algorithm across all machines.Agreed.
Roger Sayles did an interesting analysis of switch algorithms for C/C++
across architectures at the 2008 GCC Summit. It starts on page 103 ofhttp://gcc.gnu.org/wiki/HomePage?action=AttachFile&do=view&target=gcc-2008-proceedings.pdf