I have a thought that would make many processes much more effective and, being only one voice, I would like to know if there is a demand before I propose it to Keil. This is the result of me having to change a switch statement to a series of IFs to make an ISR process fast enough. I realize, and thus do not complain, that Keil caould not implemet an ANSI-C switch more efficient than the way it is done. 'n' below will be either 2 or 3 (if Keil decide to implement, they can choose) a Proposal: if #pragma QUICKSWITCH then a) no case value can be more than 255 b) all case values must be multiples of n c) the switch will be implemented as a jump table Erik
I have to agree with Erik on this one. Jump tables and their assocaited jmp @a+dptr are a fundamental instruction in the 51 for achieving efficiency, particularly within interrupts where the desire is to keep processing time to a minimum. However, I don't see why a pragma would even be necessary. Let's assume the pragma is implemented, but the code violates the required case values (i.e. byte size, increments of 2 or 3). In this case, the compiler's going to have to validate the case values to ensure compliance with the pragma anyway, so why not simply have the compiler check for "jump table possible" case values and render a direct jump table if found ???
I have to agree with Erik on this one. thanks However, I don't see why a pragma would even be necessary The advantage of a #pragma as I see it would be that you effectively told the compiler "tell me if you can not do this". If an 'automatic' were implemented, you would never know (except through investigating the assembler) if you had achieved the goal. Of course, a possibility would be a #pragma TELL_IF_SWITCH_CAN_NOT_BE_JUMP_TABLE which would satisfy both approaches. Anyhow, I STILL can not see why this has anything to do with optimization. as I see it, the compiler should do the best it can without disrupting the flow, and leave 'worthless' statements (inserted to provide a breakpoint opportunity) in the code. Then, if desired, optimization (which may/should disrupt the flow and skip dead code) can be implemented. Using jump tables has NOTHING to do with optimization (except to make the result of optimizing look better) Erik
The advantage of a #pragma as I see it would be that you effectively told the compiler "tell me if you can not do this". If an 'automatic' were implemented, you would never know (except through investigating the assembler) if you had achieved the goal. Good point. And I agree, the compiler should take every opportunity, regardless of OT level, to leverage direct jump tables if possible...IMO ;)