Re: code optimization in embedded systems
- From: "robertwessel2@xxxxxxxxx" <robertwessel2@xxxxxxxxx>
- Date: Thu, 15 Nov 2007 20:14:30 -0800 (PST)
On Nov 15, 4:30 pm, "Wilco Dijkstra" <Wilco_dot_Dijks...@xxxxxxxxxxxx>
wrote:
All of this can be done in a machine independent way. If you
have 20+ non-dense cases it is pretty obvious that linear search
is much worse than binary search. If you want to do better, then
the traditional way is to let the backend decide when the linear
search becomes better. This may depend not only on the target but
also on the actual case values or the optimization goal.
Indeed: The usual approach is to turn a sparse tree into a hard coded
binary search for the upper part of the tree, and then a linear search
for the lower part. The point where you switch depends on the cost of
mispredicted branches. In the binary tree part, about half the
branches will mispredict (not counting the branch-eq leg of the common
compare / branch-gt / branch-eq construction), in the sequential part,
only one (the one that's actually taken) will mispredict. Each extra
layer of the binary search adds a compare, and half each of a
predicted and mispredicted branch, but halves the number of compares
and correctly predicted branches in the sequential part.
And of course switches with both spares and dense sections often
generate code that does computed branches in the dense parts of the
tree.
.
- References:
- code optimization in embedded systems
- From: yusibin
- Re: code optimization in embedded systems
- From: Jyrki Saarinen
- Re: code optimization in embedded systems
- From: Niklas Holsti
- Re: code optimization in embedded systems
- From: Jyrki Saarinen
- Re: code optimization in embedded systems
- From: Niklas Holsti
- Re: code optimization in embedded systems
- From: Jyrki Saarinen
- Re: code optimization in embedded systems
- From: Wilco Dijkstra
- code optimization in embedded systems
- Prev by Date: Re: code optimization in embedded systems
- Next by Date: Re: code optimization in embedded systems
- Previous by thread: Re: code optimization in embedded systems
- Next by thread: Re: code optimization in embedded systems
- Index(es):
Relevant Pages
|