hi-tech-c lite generates slow code on purpose?

Page: 12 > Showing page 1 of 2
Author
dimaqq
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2012/05/16 06:09:10
  • Location: 0
  • Status: offline
2012/06/05 08:10:36 (permalink)
0

hi-tech-c lite generates slow code on purpose?

so when you run hi-tech-c lite it tells you:
(1273) Omniscient Code Generation not available in Lite mode (warning)
I wondered what it meant. Until I saw what sort of code it generated for this simple function:
void r0s0(void)
{
    if (PORTCbits.RC1) return;
    /* withheld */
}
And the generated assembly is:
    btfss   ((c:3970)),c,1  ;volatile
    goto    u3611
    goto    u3610
u3611:
    goto    l3863
u3610:
    goto    l201
l3861:
    goto    l201
l3863:
    /* withheld */
l201:
    return
Disassembled hex confirms this is exactly what ends up being executed.
Is this on purpose?
Is this a hint to buy hi-tech's paid compiler?
Why am I penalized with 2 goto's on either execution path of every if() statement?
 
 
 
#1

34 Replies Related Threads

    leon_heller
    Super Member
    • Total Posts : 6411
    • Reward points : 0
    • Joined: 2004/08/17 13:19:45
    • Location: St. Leonards-on-Sea, E. Sussex, UK.
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/05 09:21:14 (permalink)
    0
    You have to buy the compiler if you want it to generate efficient code.

    Leon Heller
    G1HSM

    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 15947
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/05 13:03:49 (permalink)
    0
    Did you not see the message that the compiler output about how much bigger and slower the code is compared to the paid version.
    #3
    dimaqq
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2012/05/16 06:09:10
    • Location: 0
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/05 15:38:41 (permalink)
    +1 (1)
    oh I did see that message, I just didn't think the ratio was artificially inflated by generating rubbish gotos.
     
    if someone has paid compiler and could post the assembly it generates on this code sample for pic18 for comparison I would be most glad.
    #4
    threedog
    Super Member
    • Total Posts : 998
    • Reward points : 0
    • Joined: 2009/12/04 12:28:11
    • Location: Boise
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/05 16:14:22 (permalink)
    +1 (1)
    dimaqq
     oh I did see that message, I just didn't think the ratio was artificially inflated by generating rubbish gotos.
     if someone has paid compiler and could post the assembly it generates on this code sample for pic18 for comparison I would be most glad.

    I kind of agree.  It is fine for the compiler to not do heroics to generate good machine code when not optimized.
    But to artificially insert a bunch of garbage ASM just to justify purchase of the compiler?  Crap.  Just pain Crappy Crap.
     
    It wasn't like this in the past.  Only since MC purchased HighTek did it all go down hill.
     
    Oh well, just another reason to go with an ARM CM0.
    #5
    NKurzman
    A Guy on the Net
    • Total Posts : 15947
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/05 16:52:42 (permalink)
    0
    Huh?
    If they gave away the Fully optimized compiler, why would anyone pay for it.  You could just get a bigger chip with a faster clock if you want to beat it.
    Hi-Tech did this before Microchip bought them.  It replaced the old free version that only workred on a few chips.  IAR and Keil are not giving the full ARM compiler away for free either.
     
    You can activate the 45 evaluation period if you need to evaluate the code before paying for it.  Note the New XC cmpiler is for PIC12 to PIC18 so it is not two separate products anymore.
    If you what it built post the Project.
     
    #6
    mad_c
    Super Member
    • Total Posts : 1067
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/05 17:37:38 (permalink)
    0
    threedog 
    But to artificially insert a bunch of garbage ASM just to justify purchase of the compiler?  Crap.  Just pain Crappy Crap. 

     
    This is not an accurate statement. There is no code inserted into the Free product. It is simply a case of not removing it. Try building in PRO mode with the optimisers off. You will see the goto instructions present. That output is a generic way of generating a branch without having to know if there is an else case. The assembler optimiser tidies it up once the code is down. In Free mode, the tidy-up simply does not occur.
     
    Jeff.
     
    #7
    ytlee
    Super Member
    • Total Posts : 1135
    • Reward points : 0
    • Joined: 2003/11/07 12:44:25
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/05 17:48:30 (permalink)
    0
    threedog

    dimaqq
    oh I did see that message, I just didn't think the ratio was artificially inflated by generating rubbish gotos.
    if someone has paid compiler and could post the assembly it generates on this code sample for pic18 for comparison I would be most glad.

    I kind of agree.  It is fine for the compiler to not do heroics to generate good machine code when not optimized.
    But to artificially insert a bunch of garbage ASM just to justify purchase of the compiler?  Crap.  Just pain Crappy Crap.

    It wasn't like this in the past.  Only since MC purchased HighTek did it all go down hill.

    Oh well, just another reason to go with an ARM CM0.

     
    They are not artificially inserted, they are place holder
    For the pro version, the optimizer take care them.
    #8
    1and0
    Access is Denied
    • Total Posts : 8004
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/05 21:12:04 (permalink)
    0
    mad_c
    There is no code inserted into the Free product. It is simply a case of not removing it. [...] That output is a generic way of generating a branch without having to know if there is an else case.

    ytlee
    They are not artificially inserted, they are place holder

    Okay, I am still not convinced it is not intentional bloatware.  Here's OP's generated assembly with added comments:
      
        btfss   ((c:3970)),c,1  ;         btfss   file,bit
        goto    u3611           ;         goto    false
        goto    u3610           ;         goto    true
    u3611:                      ; false:  <insert false conditional code>
        goto    l3863           ;         goto    ifend
    u3610:                      ; true:   <insert true  conditional code>
        goto    l201            ;         goto    ifret
    l3861:                      ;     ??? it seems the code will never reach here ??? [?]
        goto    l201            ;     ??? so what is the reason for this GOTO     ??? [?]
    l3863:                      ; ifend:
        /* withheld */          ;
    l201:                       ; ifret:
        return                  ;         return
        
       
    I'd think a generic if-else statement takes four GOTO at the most:
     
            btfss   file,bit
            goto    false
            goto    true
    false: 
            ; insert false code
            goto    ifend
    true:  
            ; insert true code
            goto    ifend
    ifend:
     
    ... or three GOTO ...
     
            btfss   file,bit
            goto    false
    true:  
            ; insert true code
            goto    ifend
    false: 
            ; insert false code
            goto    ifend
    ifend:
     
    ... or even just two GOTO ...
     
            btfss   file,bit
            goto    false
    true:  
            ; insert true code
            goto    ifend
    false: 
            ; insert false code
    ifend:
      
    Or did I miss something?  Place holder for what? [?][?][?]
    post edited by 1and0 - 2012/06/05 21:15:38
    #9
    mad_c
    Super Member
    • Total Posts : 1067
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/05 22:22:50 (permalink)
    0
    1and0
    Okay, I am still not convinced it is not intentional bloatware.

    I just tried a simple if() in PRO mode with the assembler optimisers off and there was 3 gotos in a row. Depending on your surrounding code, there could be more. There are also other optimisations that generate the tree representation of the C code which are disabled in Free mode, so it is difficult to compare. It's not what I would call bloating code on purpose.
    Microchip has clearly stated that the code size will be larger in Standard and Free modes. The percentages indicated in the message and documentation are purely based on test cases and are nominal only -- you may see more or less reduction in PRO mode. The Free compiler is, as its name suggests, free. You cannot expect it to perform as well as a compiler which is has cost associated with it.
    The Free compiler allows you to use all the devices, and allows you to use all the memory on each device. It even has the OCG benefits of its bigger brothers. If it suits your needs, you are most welcome to use it, even in commercial applications.
     
    Jeff.
     
    #10
    1and0
    Access is Denied
    • Total Posts : 8004
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/05 23:30:55 (permalink)
    0
    mad_c
    I just tried a simple if() in PRO mode with the assembler optimisers off and there was 3 gotos in a row. Depending on your surrounding code, there could be more. There are also other optimisations that generate the tree representation of the C code which are disabled in Free mode, so it is difficult to compare. It's not what I would call bloating code on purpose.
    So PRO mode with the optimizers off generates code similar to Free mode:
     
    5:                     if (PORTBbits.RB0 == 1)
      07F5    1C06     BTFSS 0x6, 0
      07F6    2FF8     GOTO 0x7f8
      07F7    2FF9     GOTO 0x7f9
      07F8    2FFB     GOTO 0x7fb
    6:                         PORTCbits.RC0 = 1;
      07F9    1407     BSF 0x7, 0
      07FA    2FFD     GOTO 0x7fd
    7:                     else
    8:                         PORTCbits.RC0 = 0;
      07FB    1007     BCF 0x7, 0
      07FC    2FFD     GOTO 0x7fd
     
    Why the branch takes two GOTO's (GOTO 0x7f8/GOTO 0x7fb) when one should work?  What else would you call having generated code that never executed or code that is basically GOTO $+1?

    #11
    DarioG
    Allmächtig.
    • Total Posts : 53416
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/06 00:37:51 (permalink)
    0
    Actually, when writing a C parser (compiler, interpreter) the code that will be generated "at first draft" will be really bloated and full of useless GOTOs and else (I've been playing with my own compiler back in 1989 and then again in the years).
    It will all depend on how it was designed. Then, a good optimizer will improve things a lot.

    Andiamo a Berlino!

    #12
    Antipodean
    Super Member
    • Total Posts : 1581
    • Reward points : 0
    • Joined: 2008/12/09 10:19:08
    • Location: Didcot, United Kingdom
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/06 03:17:58 (permalink)
    0
    threedog
    But to artificially insert a bunch of garbage ASM just to justify purchase of the compiler?  Crap.  Just pain Crappy Crap.
    It wasn't like this in the past.  Only since MC purchased HighTek did it all go down hill.


    The Hi-Tech compilers have been doing this for years, long before Microchip took them over.

    Do not use my alias in your message body when replying, your message will disappear ...

    Alan
    #13
    1and0
    Access is Denied
    • Total Posts : 8004
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/06 08:38:47 (permalink)
    +2 (1)
    DarioG
    Actually, when writing a C parser (compiler, interpreter) the code that will be generated "at first draft" will be really bloated and full of useless GOTOs and else (I've been playing with my own compiler back in 1989 and then again in the years).
    Why this "first draft" has to be so bloated?  I like to learn and understand the process behind the parser in building a tree structure like, for example, in Post #11 for an if-else construct instead of this hand-generated one:
     
    5:                     if (PORTBbits.RB0 == 1)
      07F5    1C06     BTFSS 0x6, 0
      07F6    2FFA     GOTO 0x7fa
      07F7    2FF8     GOTO 0x7f8
    6:                         PORTCbits.RC0 = 1;
      07F8    1407     BSF 0x7, 0
      07F9    2FFC     GOTO 0x7fc
    7:                     else
    8:                         PORTCbits.RC0 = 0;
      07FA    1007     BCF 0x7, 0
      07FB    2FFC     GOTO 0x7fc
     
    ... or better yet this one ...
     
    5:                     if (PORTBbits.RB0 == 1)
      07F5    1C06     BTFSS 0x6, 0
      07F6    2FF9     GOTO 0x7f9
    6:                         PORTCbits.RC0 = 1;
      07F7    1407     BSF 0x7, 0
      07F8    2FFA     GOTO 0x7fa
    7:                     else
    8:                         PORTCbits.RC0 = 0;
      07F9    1007     BCF 0x7, 0
      
    That is, why can't the "first draft" for
     
        if ( expression )
            program statement 1
        else
            program statement 2
     
    generates this pseudo code structure
     
            evaluate the expression
            btfss true-condition
            goto else-case
    then-case:
            program statement 1
            goto end-if
    else-case:
            program statement 2
    end-if:
     
    and without full of useless GOTOs.  I do not expect the Free compiler to perform as well as a paid compiler, but I also do not expect it to generate such "anti-optimization" code.  As someone has mentioned recently, does the Free mode mean "please-slow-down-my-code" mode ?? LoLLoLLoL
     


    #14
    mad_c
    Super Member
    • Total Posts : 1067
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/06 15:25:31 (permalink)
    0
    1and0
    Why the branch takes two GOTO's (GOTO 0x7f8/GOTO 0x7fb) when one should work?

     
    But after optimising there is only one.
     
    You are probably looking at this the wrong way. Compilers do not attempt to produce fully optimised code in one step. While that is possible, the resources it would need, time it would take, and the multitude of bugs that it would lead to are just not worth it. Compilers try to use simple, generic steps to assemble the code. You have to remember, also, that the compiler generates code for one node in the statement tree with no knowledge of the other nodes in the tree, with the exception of its immediate child nodes. It is not until code is generated for that expression does it move on and look to see what is 'coming next'. Humans, when looking at code, look at the entire statement -- provided it is not too complicated -- and 'work ahead'. It is far easier for a compiler to put down a generic code sequence -- even if it is bloated -- and then use a subsequent optimiser to clean it up, since at that point all the code is generated and the optimiser can 'look ahead' to see what's coming up next. So a simple, two-step process is far more efficient than a convoluted hang-on-to-your-hats but-single-step process.
     
    However, I think I am getting off topic. The Free compiler does not look at code sizes and start adding code if it thinks it is not bloated enough. Whatever is generated first pass is what goes. If that is only a couple of percent larger than PRO mode, so be it. If it is 50% larger than PRO mode, so be it. The quoted figures for code size increases are averages taken over several test projects. And since the Free compiler does not perform a lot of optimisations, it usually compiles a little faster. Microchip has a range of price points and a range of code optimisations; it is up to you to decide which is best for you.
     
    Jeff.
     
    #15
    DarioG
    Allmächtig.
    • Total Posts : 53416
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/06 15:27:35 (permalink)
    0
    Smile Of course I may agree with you - I am not in the minds of that compiler' writers!
    I could show my code-generator, but for PICs it was not complete yet Smile it was working on Z80 and Acorn Archimedes.. and to some extent for 8086. If you don't have a special CPU in mind, but rather try to use a "generic" CPU engine as a target, then you may not have "BTFSC" rather "MOV AL, AL / JNZ xxx" so that could be a reason...

    Andiamo a Berlino!

    #16
    mad_c
    Super Member
    • Total Posts : 1067
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/06 15:52:30 (permalink)
    0
    DarioG
    Smile Of course I may agree with you - I am not in the minds of that compiler' writers!
    I could show my code-generator, but for PICs it was not complete yet Smile it was working on Z80 and Acorn Archimedes..

    An Acorn? I had several of those. In fact I still have my Risc PC -- brilliant machine and OS.

    If you don't have a special CPU in mind, but rather try to use a "generic" CPU engine as a target, then you may not have "BTFSC" rather "MOV AL, AL / JNZ xxx" so that could be a reason...

    Absolutely.
     
    Jeff.
     
    #17
    ytlee
    Super Member
    • Total Posts : 1135
    • Reward points : 0
    • Joined: 2003/11/07 12:44:25
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/06 17:16:47 (permalink)
    0
    the compiler has to prepare for
    if-then-else statement, therefore it generate all the possible placeholders in case it is needed. Please read the red dragon book, or get the source code for SmallC to have a basic understanding how the compiler operates.
     
    BTW, if you want to, you can modify SmallC to generate Microchip assembly code and then use microchip assembler for the compilation.
    #18
    1and0
    Access is Denied
    • Total Posts : 8004
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/06 19:59:28 (permalink)
    0
    mad_c
    You are probably looking at this the wrong way.
    Thank you for shedding more light on the subject.  I know the optimizer will clean up the code and I understand the two-pass process.  But could you elaborate more on why the three GOTOs in a row is a generic way of encoding branches?  I'd had expected the if() statement to use two GOTOs ('if' and 'else' branches) on the first pass -- why the three GOTOs?
     
    #19
    dhenry
    Super Member
    • Total Posts : 4994
    • Reward points : 0
    • Joined: 2003/11/07 12:35:12
    • Location: Colorado
    • Status: offline
    Re:hi-tech-c lite generates slow code on purpose? 2012/06/06 21:24:02 (permalink)
    +2 (1)
    1and0
    But could you elaborate more on why the three GOTOs ...

    On the other hand, non-optimized code production has already been addressed here, so if redundantly elaborating why non-optimized patterns are produced dilutes your effort that would otherwise be spent advancing the product, my vote would be to not elaborate and put that time to better use.  Do we really care enough how non-optimized code production could be better optimized to justify asking for the reason behind non-optimally non-optimized code production?
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2018 APG vNext Commercial Version 4.5