This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

a proposal ?

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

Parents
  • portability my a..

    The one and only interest in the means of execution of any statement is throughput. If you are throughput critical, then there is no 'portability'.

    Should you use #pragma QUICKSWITCH for any reason other that throughput, it does not matter one iota what 'that other compiler' does with it.

    The very exisience of the verb 'portinng' is proof that portability is a myth. Reuse, template, basis sure - but 'portable' spare me.

    Yes, where there is no timing concerns and memory is ample you may have a case for 'portability' but from a '51 to a HC08 come on!

    Erik

Reply
  • portability my a..

    The one and only interest in the means of execution of any statement is throughput. If you are throughput critical, then there is no 'portability'.

    Should you use #pragma QUICKSWITCH for any reason other that throughput, it does not matter one iota what 'that other compiler' does with it.

    The very exisience of the verb 'portinng' is proof that portability is a myth. Reuse, template, basis sure - but 'portable' spare me.

    Yes, where there is no timing concerns and memory is ample you may have a case for 'portability' but from a '51 to a HC08 come on!

    Erik

Children
  • "If you are throughput critical, ..."

    then write it in assembly language.

  • "If you are throughput critical, ..."

    then write it in assembly language.


    I do, but if there is a way I can do it ib C that would still be preferable.

    The statement "then write it in assembly language" sure does kill the argument re portability :)

    Have a great weekend

    Erik

  • Those two compilers won't agree on the meaning of some language extension either.

    True, but it does at least give you a common place to put the toolchain-specific notes. #pragma itself is standard. So, you'd wind up with

    #if __C51__
    #pragma Keils_pragma_for_jumptable
    #endif
    #if __GCC___
    #pragma GCCs_pragma_for_jump_table
    #endif

    // common code for the actual "C" part.

    If you really hate #ifs in your code, you could make that series a single file so that the change in the actual .c file reduces to

    #include "pragma_jumptable"

    The pragma also documents the requirement that this particular switch must be a jump table much more clearly than relying on a source formatting convention. (Might as well say all function declarations have to start in column 8, while all statements have to start in column 12.)

    As for using the C source proper, consider the worst case -- one compiler decides that in order, ascending values secretly means "jump table", while the other compiler decides it means if-then-else. You're exactly right that this contract is one per compiler, which is exactly why it can't be in the source itself. That source has to be fed to all of the compilers. You can't both order the switch labels ascending and order them descending at the same time.

    So, the magic signal to convey these sorts of wishes has to be something other than the source itself. That's what #pragma was invented to do.

    Standardizing the pragmas themselves would be nice as well. Pragmas also could use a per-vendor "namespace". Lots of compilers, for example, support "#pragma pack", but they don't all mean the same thing by it. Compilers can ignore #pragmas they don't recognize, but there's not a good way to make sure they don't misinterpret a pragma they do recognize, but with different semantics.