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

35% smaller, and 14% faster code!

There is a new 8051 C compiler in beta test that beats Keil's compiler by 35% code size, and 14% speed, on the Dhrystone benchmark. And, there is no need to select a memory model or use special keywords to control data placement.

More details here: www.htsoft.com/.../silabs8051beta

Parents Reply Children
  • Given that snippet in isolation I can see no error. Please enlighten me.

    There isn't one (the snippet was all that was necessary to reproduce the error, without any ISRs or multitasking). The programmer made one of two possible errors: Either blindly trusting the compiler to generate correct assembly code, or not religiously sifting through the compilers errata sheets to check for this situation.

    Looking at the assembly code, however, it became quite clear that the compiler generated a completely bogus target address for the looping command used in the for-loop, which caused the microcontroller to jump out of the loop after the first iteration.

    Not calling any names here, but that was the compiler supplied by the manufacturer of the chip, with no alternative compilers available. When presented with the C code and the corresponding assembly, their tech support commented "We do not think this is a compiler bug.". I've not contacted them again after this. Most of the program was written in assembly, anyway, which was probably a good thing.

  • Not calling any names here, but that was the compiler supplied by the manufacturer of the chip, [...]

    I don't know why I so suddenly start to think about Microchip...

  • The programmer made one of two possible errors: Either blindly trusting the compiler to generate correct assembly code, or not religiously sifting through the compilers errata sheets to check for this situation.

    You've missed the point. I was after an example of the sort of error being discussed - a 'C' coding mistake caused by faulty logic or faulty implementation of correct logic. It's a given that one would have to inspect the assembly output if there is in fact no error in the 'C' code.

  • I don't know why I so suddenly start to think about Microchip...

    Never worked with any of their products, sorry. But I think there are alternative compilers available for their architectures.

    In my case, there was no alternative. And I guess the response from tech support would have been much, much different if I hard worked on a large-volume project (millions of units per year, like ... cellphones) instead of one with a paltry 10k to 100k units per year.

    Oh, and nastily enough, the compiler generated completely correct assembly if the debug symbols were turned on (yes, with everything else, including the optimization settings, being unchanged). Took me a while to figure out why I couldn't "reproduce" the error with my debug version, while it was perfectly reproducable with the release version.

  • I was after an example of the sort of error being discussed - a 'C' coding mistake caused by faulty logic or faulty implementation of correct logic.

    Well, any case of lawyer code (e.g. use of code with effects not specified by the C language standard) would suffice there. Even the most competent C programmer cannot tell whether the code will do what it is supposed to do without either knowing the implementation details of the compiler or looking at the generated assembly.

    (And no, I don't consider knowing by heart what

    some_function(++a, ++a);
    

    does on seven different compilers to be part of being a competent C programmer. A competent C programmer will know that this is heavily compiler dependent and avoid such expressions whenever possible. There is no way of knowing whether this will work as intended by just looking at the C code)

  • Regarding the example:

    some_function(++a, ++a);
    

    Who really writes code like this? Are the (questionable) optimizations of any side effects from such a line ever worth it?

    In our case, all people MUST undergo an intial period of training to ensure that the prescribed development rules are understood before they are let loose at writing code. Hence expressions like the above, and any resultant assumptions are avoided.

    Simple.

  • Who really writes code like this?

    People who don't know better (and you might have to debug their code at some point), people who don't care and people who are actively malicious.

    Are the (questionable) optimizations of any side effects from such a line ever worth it?

    Some people may think that writing a program with as few keystrokes as possible is a worthwhile goal.

    Granted, the example was blaringly obvious and should make anyone halfway familiar with C cringe. Any compiler with half a brain should emit a warning. However, MS VC++ doesn't seem to care about a = a++; ... other compilers I use do find this worth a warning.

  • "People who don't know better (and you might have to debug their code at some point), people who don't care and people who are actively malicious."

    I take your point on that one. I have come across similar dubious practice code in legacy projects.

    Not so long ago I was scanning over some code of a (supposedly senior) team member. There was a block of believable code, in a released project, that had a comment just above it stating:

    /* THIS CODE DOES NOT WORK */
    

    Not too surprisingly, the team member wasn't part of my team for much longer!

  • Not too surprisingly, the team member wasn't part of my team for much longer!<p>

    Well, the question is: If the code (obviously) didn't work, why wasn't this caught during testing ? Or was the comment outdated and the code correct ?

  • No, not simple. Besides assuming that you do manage to teach them all to behave, you also assume that you really are in control of all paths of source code onto your table.

    Did you see my example? The library in question wasn't written inhouse, but because of policy reasons (sellers like partnerships, since it looks so nice on the web page...) you sometime have to integrate code you have suddenly got in your knee.

    Sometimes management buy products that you may have to take care of. Sometimes your products needs to be integrated with a customers product. Sometimes, someone decides to buy a magic library that will greatly decrease the development time of a new feature. Many ways to get new and strange code inside the house. Not all written by really competent developers.

  • Well, any case of lawyer code (e.g. use of code with effects not specified by the C language standard) would suffice there.

    A competent 'C' programmer wouldn't do that.

    What this boils down to for me is this:

    If you find yourself reaching for the ICE or stepping through compiler output on a regular basis you are either working with 3rd party junk rather than decent development tools or libraries, or the code you have written is junk. The 'have a go' programmers who 'don't care a hoot' about the standard find themselves unable to get anything to work without constant debugging which they are incapable of doing at source level. Why? Because they cannot tell whether the code they have written *should* work or not. They find out how it *actually* works by experimenting with the compiler, rather than just reading the damn manual.

    This is why the world is full of unreliable, unmaintainable junk.

  • If you find yourself reaching for the ICE or stepping through compiler output on a regular basis you are either working with 3rd party junk rather than decent development tools or libraries, or the code you have written is junk.

    I think I have to agree with that. Most code either works on the first run, or reading the code is enough to see what ails it. A bit of guard code can help in case I have made an incorrect assumption about the value range of the input, or in case I'm inserting the new code in already broken code.

  • I think I have to agree with that. Most code either works on the first run, or reading the code is enough to see what ails it
    Try, for instance to write an interface to a FTDI vinculum and debug it by the above method, you will die before the program runs.

    there are beautiful debugging theories based on all information given is complete and correct just one comment male cow manure.

    Erik

  • ...unable to get anything to work without constant debugging which they are incapable of doing at source level.

    I agree. Among other sins, this approach yields code that is less maintainable and probably less portable.