/* SDCC should not sort switch cases if it does not
optimize the switch statement
into a jump table
*/
#include <8052.h>
void f( unsigned char c )
{
volatile char t=c;
}
void main(void)
{
while (1) {
#pragma save
#pragma nojtbound
switch (P1 & 0x0c) {
case 0x0c: f(0); break; // this is the most
frequently taken path
// (internal
pullups, no external switch closed)
case 0x00: f(3); break;
case 0x04: f(2); break;
case 0x08: f(1); break;
}
#pragma restore
}
}
I don't see any justification for the assumption about the earlier switch cases being the more frequent ones.
I'd suggest to close this.
Philipp
The provided code snippet provides reasoning for the label 0x0c being used (much) more frequently than the others. (reasoning not assumption:)
By contrast SDCC currently generates code on the assumption that the labels that sort lowest are those which should be tested first.
SDCC's thus overrides the choice of the programmer.
I suggest to keep this request open. Of course C promises no priority, but there also is no reason to sort just because it can,