Re: Learning to use PICS

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


Date: Sun, 28 Nov 2004 16:58:56 -0000


CBarn24050 <cbarn24050@aol.com> wrote in message
news:20041128040554.06333.00001058@mb-m18.aol.com...
> >Subject: Re: Learning to use PICS
> >From: "Sergio Masci" sergio@NO.SPAM.xcprod.com
> >Date: 28/11/2004 03:06 GMT Standard Time
> >Message-id: <41a93fe9$0$1063$db0fefd9@news.zen.co.uk>
> >
> >
> >john jardine <john@jjdesigns.fsnet.co.uk> wrote in message
> >news:coac45$hvg$1@newsg3.svr.pol.co.uk...
> >>
> >> "Sergio Masci" <sergio@NO.SPAM.xcprod.com> wrote in message
> >> news:41a89667$0$1067$db0fefd9@news.zen.co.uk...
> >>
> >> >[clip]
>
> >> > The XCSB compiler will convert the following to just 6 machine code
> >> > instructions:
> >> >
> >> > proc inline set_bit(ubyte *addr, ubyte id)
> >> > *addr = *addr | (1 << id)
> >> > endproc
> >> >
> >> > proc inline clear_bit(ubyte *addr, ubyte id)
> >> > *addr = *addr & ~(1 << id)
> >> > endproc
> >> >
> >> > proc inline ubyte test_bit(ubyte *addr, ubyte id)
> >> > return (*addr & (1 << id) != 0)
> >> > endproc
> >> >
> >> > proc main()
> >> >
>
> >> > ubyte a, b
> >> >
> >> > if (test_bit(&a, 1) then
> >> > set_bit(&b, 2)
> >> > else
> >> > clear_bit(&b, 2)
> >> > endif
> >> > endproc
> >>
> >> Looks like "C" to me.
> >> I know this must be so, as I can't understand it :-).
> >> Yet I can easily read the 'Proton','CH-flash', 'iL_Bas16' etc Basics.
> >> regards
> >> john
>
> >
> >It supports pointers like "C" but unlike many C compilers for the PIC it
> >doesn't generate a ton of code to build and pass the pointers and then
> >dereference them if it can determine the address at compile time. PEEK
and
> >POKE would be more in keeping with other BASIC dialects but pointers
allow
> >the programmer to give the compiler more information which in turn helps
the
> >compiler trap silly errors and generate better code.
> >
> >The reason I chose the above example is because it shows how the compiler
> >converts some very complex functionality into very tight code
> >
>
> Assembly language programmers do that in 3 instructions.

No they could not.

They could rearrange the code to give the equivalent of:

                 clear_bit(&b, 2)

                 if test_bit(&a, 1) then
                         set_bit(&b, 2)
                 endif

Then yes the assembler programmer could reduce it to 3 machine code
instructions but in this case the XCSB compiler would then generate 4
machine code instructions (still infinately better than many other PIC
compilers).

BUT THIS IS NOT THE SAME AS THE ORIGINAL CODE

In the original, bit 2 of "b" follows bit 1 of "a" exactly, in the
rearranged code bit 2 of "b" will glitch (temporarily change from 1 to 0
and back to 1) when bit 1 of "a" is 1. If "b" is used to send messages
to an interrupt service routine this may cause you problems, also if
"b" is an alias of an I/O ports this WILL cause you problems.

The XCSB compiler will not perform this kind of optimisation behind your
back because there are MANY ways that it could cause problems.

Regards
Sergio Masci

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



Relevant Pages

  • Re: new IL: C (sort of...).
    ... only for "recent" Pascals, ... far pointers weren't really limited, ... in my compiler, I made wchar_t a builtin type (in most cases, aliased to ... I could very well include builtin "managed strings" in the new IL. ...
    (comp.lang.misc)
  • Re: new IL: C (sort of...).
    ... and the frontend compiler needs to be able ... Having very limited pointers is a fact of life in a VM language though, ... vague claims about Pascal's pointer support. ... That is pretty normal for standards (the ...
    (comp.lang.misc)
  • Re: Learning to use PICS
    ... the BASIC compiler and the complexity of the problem. ... by an experienced assembler programmer. ... multiple BASIC instructions and generate fewer machine code instructions. ...
    (sci.electronics.basics)
  • Re: code optimiation
    ... Given that the compiler can often optimise the generated code to use the best sized types available, it's seldom worth specifying "fast" types explicitly. ... pointers and floating point types whose "zero value" might not be all- ... instruction, so the assembler produced for *p++ when used as the ... It will do the same job, and let you write the source code using proper array constructs. ...
    (comp.arch.embedded)
  • Re: Pointer of Reference ?
    ... the problem is that pnly "traditionally trained C programmers" as a class see pointers ... If the compiler has to dereference a pointer to achieve that goal, ... ASSERT wants a Boolean value, ... the programmer is forced to actually READ THE DOCUMENTATION OR THE FUNCTION DEFINITION, ...
    (microsoft.public.vc.mfc)

Loading