|
|
|
|
|
|
|
|
|
|
xen-devel
Re: [Xen-devel] [PATCH 10/17] vmx: nest: VMExit handler in L2
At 11:35 +0100 on 21 May (1274441723), Qing He wrote:
> > I understand that. It just seems inefficient to bundle them all
> > together into one clause of the switch statement and then scan an array
> > looking for which one you've hit. Wouldn't it be better to give each
> > one its own clause and then use goto (!) or similar to jump to the
> > common code?
>
> Ok, I'll change it to switch clauses, does it mean to be more friendly to
> the compiler?
No, it's just faster; I don't think GCC can optimize out a while loop,
even scanning a static array with a known limited set of possible inputs
(though i would be delighted to hear otherwise).
Just to be clear, I'm talking about replacing this kind of logic
switch (x) {
case a:
case b:
case c:
for (i = o; i < 3 ; i++)
if ( x == array[i] )
/* do case-specific thing */
/* do common case */
}
with this equivalent:
switch (x) {
case a:
/* do a-specific thing */
goto common;
case b:
/* do b-specific thing */
goto common;
case c:
/* do c-specific thing */
goto common;
common:
/* do common case */
}
Cheers,
Tim.
--
Tim Deegan <Tim.Deegan@xxxxxxxxxx>
Principal Software Engineer, XenServer Engineering
Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|
|
|
|
|