Re: Learning to use PICS

From: Sergio Masci (sergio_at_NO.SPAM.xcprod.com)
Date: 12/04/04


Date: Sat, 4 Dec 2004 14:07:38 -0000


Spehro Pefhany <speffSNIP@interlogDOTyou.knowwhat> wrote in message
news:q7i2r0tfniq7smkrvlai7djkad2gc9pia6@4ax.com...
> On Sat, 4 Dec 2004 00:53:57 -0000, the renowned "Sergio Masci"
> <sergio@NO.SPAM.xcprod.com> wrote:
>
> >
> >
> >I would be interested to see the generated code and to know which
compiler
> >you are using.
>
> I think I have misspoken on the size- the assy file was hiding some of
> the instructions for some reason. Here's the code from the program
> memory (some manual transcription, so it may not be 100% correct).
> It's HitechC for 16F. 27 program words including two bank select
> instructions.
>
>
> 0007E5 MOVLW 0x8
> 0007E6 BCF 0x3, 0x5
> 0007E7 BCF 0x3, 0x6
> 0007E8 MOVWF 0x2E
> 0007E9 MOVF 0x2b,W
> 0007EA MOVWF 0x2d
> 0007EB BCF 0x3, 0
> 0007EC RLF 0x2a, F
> 0007ED RLF 0x2b, F
> 0007EE MOVF 0x2c, W
> 0007EF XORWF 0x2d, W
> 0007F0 MOVWF 0x40
> 0007F1 BTFSS 0x40, 0x7
> 0007F2 GOTO 0x7f7
> 0007F3 MOVLW CRC_LOW
> 0007F4 XORWF 0x2a, F
> 0007F5 MOVLW CRC_HIGH
> 0007F6 XORWF 0x2b, F
> 0007F7 BCF 0x3, 0
> 0007F8 RLF 0x2c,F
> 0007F9 DECFSZ 0x2e,F
> 0007FA GOTO 0x7e9
> 0007FB MOVF 0x2b, W
> 0007FC MOVWF 0x41
> 0007FD MOVF 0x2a, W
> 0007FE MOVWF 0x40
> 0007FF RETURN
>
>
> Best regards,
> Spehro Pefhany

Thank you for that.

It seems that the Hitech C compiler has noticed an optimisation in the "for
loop" that the XCSB compiler missed, essentially converting:

        ;----------
                k = 8
        loop_start
                if k <= 0 then goto loop_end
                ...
                k = k - 1
                goto loop_start
        loop_end
        ;----------

into

        ;----------
                k = 8
        loop_start
                ...
                if (k = k - 1) != 0 then goto loop_start
        ;----------

Even so, it is still reassuring to see how close the output of both
compilers is. 26 machine code instructions for the Hitech C compiler and 31
for the XCSB compiler. If you look back at a previous post in this thread
you will see that I mentioned that the function epilog can actually reduce
the length of the overall code by 4 instructions (depending on optimisation)
So the code generated by the XCSB compiler would be only 27 machine code
instructions.

I will have to put this "for loop" optimisation on my todo list :-)

Regards
Sergio Masci

http://www.xcprod.com/titan/XCSB - optimising PIC compiler
FREE for personal non-commercial use.



Relevant Pages

  • Re: optimation, a black art?
    ... RISC is no less problematic - the MIPS architecture almost failed ... initially because it depended too much on the compiler for scheduling ... instructions regardless of whether the branch was taken. ... blocks and scheduled execution. ...
    (comp.lang.lisp)
  • Re: interpreter vs. compiled
    ... there is a process that runs product instructions, ... the notion that JIT technology compiles code. ... my C implementation a compiler. ... new machine language for each one. ...
    (comp.lang.python)
  • Re: optimation, a black art?
    ... instructions may be completely subsumed by slower running ones. ... Trace scheduling (also called Basic Block ... To do this the compiler has to estimate where the value lies in the ... permutation generate the actual sequence of instructions following ...
    (comp.lang.lisp)
  • Re: What micros do you actually hate to work with?
    ... the compiler was pretty good to start with. ... level optimizations and fine tuning every bit of the compiler. ... emitting fewer instructions in the end. ... as assembler written by an expert. ...
    (comp.arch.embedded)
  • Re: 12 Misconceptions
    ... The difference is that with a HLL like the C++, the compiler does the ... ALU instructions *emulating* one or the other of these two or something ... A lot of programmers who use C and C++ program for the Intel x86 / ... It is possible to write tiny executables with Visual C++, ...
    (alt.lang.asm)