DSPRelated.com
Forums

C6000 assembler optimizer is optimizing too much

Started by Martin Eckel September 16, 2003
Hello,

Not only once I have had the problem, that the C6000 assembler optimizer
is optimizing to much.

Sometimes I have to read a memory location or memory mapped register -
and then throw the value away, because reading of the register already
makes the wanted effect.

But the assembler optimizer thinks, if the value is thrown away, the
whole read command is unneccessary - and the command is just deleted.

Is there any way to tell the assembler optimizer "don't optimize this
line"?

I don't want to program direct in parallel assembler, I like the serial
assembler ;-)

Best regards,
Martin

Martin Eckel wrote:
> Hello, > > Not only once I have had the problem, that the C6000 assembler optimizer > is optimizing to much. > > Sometimes I have to read a memory location or memory mapped register - > and then throw the value away, because reading of the register already > makes the wanted effect. > > But the assembler optimizer thinks, if the value is thrown away, the > whole read command is unneccessary - and the command is just deleted. > > Is there any way to tell the assembler optimizer "don't optimize this > line"?
Read up on C's "volatile" directive. In short, you want to do this: volatile int control_register; "volatile" tells the optimizer that the value can change outside the program (i.e., it's a hardware register or it's changed by an ISR, or it's in shared memory and another program changes it, etc...) -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas@bittware.com http://www.bittware.com (703) 779-7770 Things could be a lot better around here, but worse is more likely - Calvin
On Tue, 16 Sep 2003 16:36:59 -0400, Jim Thomas <jthomas@bittware.com>
wrote:

>Read up on C's "volatile" directive. In short, you want to do this: > >volatile int control_register; > >"volatile" tells the optimizer that the value can change outside the >program (i.e., it's a hardware register or it's changed by an ISR, or >it's in shared memory and another program changes it, etc...)
Can you declare locations as volatile using assembler then? Best Regards John McCabe To reply by email replace 'nospam' with 'assen'

John McCabe wrote:

> On Tue, 16 Sep 2003 16:36:59 -0400, Jim Thomas <jthomas@bittware.com> > wrote: >=20 >=20 >>Read up on C's "volatile" directive. In short, you want to do this: >> >>volatile int control_register; >> >>"volatile" tells the optimizer that the value can change outside the=20 >>program (i.e., it's a hardware register or it's changed by an ISR, or=20 >>it's in shared memory and another program changes it, etc...) >=20 >=20 > Can you declare locations as volatile using assembler then? >=20 >=20 > Best Regards > John McCabe >=20 > To reply by email replace 'nospam' with 'assen'
"Volatile" declares that the data at the location may have changed=20 without program intervention, and so muse be read afresh each time. It=20 doesn't declare that the value must be read even though it is unused.=20 Storing it to a dummy variable might be an [expensive] workaround. Jerry --=20 Engineering is the art of making what you want from things you can get. =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF
On Fri, 19 Sep 2003 00:52:58 -0400, Jerry Avins <jya@ieee.org> wrote:

>"Volatile" declares that the data at the location may have changed >without program intervention, and so muse be read afresh each time. It >doesn't declare that the value must be read even though it is unused >Storing it to a dummy variable might be an [expensive] workaround.
Oh *I* know exactly what volatile is in C, but my question was whether you can apply a 'volatile' qualifier in C6000 assembler. The OP didn't mention C anywhere so my assumption was that he wasn't using it! Best Regards John McCabe To reply by email replace 'nospam' with 'assen'
john@nospam.demon.co.uk (John McCabe) wrote in message news:<3f6ad5e9.7918416@news.btclick.com>...
> On Fri, 19 Sep 2003 00:52:58 -0400, Jerry Avins <jya@ieee.org> wrote: > > >"Volatile" declares that the data at the location may have changed > >without program intervention, and so muse be read afresh each time. It > >doesn't declare that the value must be read even though it is unused > >Storing it to a dummy variable might be an [expensive] workaround. > > Oh *I* know exactly what volatile is in C, but my question was whether > you can apply a 'volatile' qualifier in C6000 assembler. The OP didn't > mention C anywhere so my assumption was that he wasn't using it! > > > Best Regards > John McCabe >
There is no need for the volatile qualifier in assembler. "volatile" is strictly a compiler directive to make sure that the compiler generates assembly code for the C source lines in question rather than optimizing them away. Assemblers are more or less WYSIWYG, i.e., they don't optimize code. Cheers, Mark Fiedler
Mark Fiedler wrote:
> > There is no need for the volatile qualifier in assembler. "volatile" > is strictly a compiler directive to make sure that the compiler > generates assembly code for the C source lines in question rather than > optimizing them away. Assemblers are more or less WYSIWYG, i.e., they > don't optimize code. >
This is simply not true. I have used a number of assemblers in the past which feature various levels of code optimisation (although this is generally limited to peephole optimisation and scheduling, for obvious reasons). I've never used the C6000 assembler, so I don't know what kind of optimisations it performs, but it may be that it has some kind of "volatile" qualifier to prevent unwanted load/store optimisations. If I were the OP I would be inclined to look at the documentation for the assembler for inspiration. Paul
As far as I know, the "volatile" type is specific to C. Are there=20
optimizing assemblers? What I meant (but didn't write) was that even if=20
"volatile" were available and there was an assembler that second-guessed =

the programmer, it wouldn't address the problem.

Jerry
--=20
Engineering is the art of making what you want from things you can get.


John McCabe wrote:

> On Fri, 19 Sep 2003 00:52:58 -0400, Jerry Avins <jya@ieee.org> wrote: >=20 >=20 >>"Volatile" declares that the data at the location may have changed >>without program intervention, and so muse be read afresh each time. It >>doesn't declare that the value must be read even though it is unused >>Storing it to a dummy variable might be an [expensive] workaround. >=20 >=20 > Oh *I* know exactly what volatile is in C, but my question was whether > you can apply a 'volatile' qualifier in C6000 assembler. The OP didn't > mention C anywhere so my assumption was that he wasn't using it! >=20 >=20 > Best Regards > John McCabe >=20 > To reply by email replace 'nospam' with 'assen'
=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF
Martin,

What if reserve space for a global variable (somewhere in .data or .bss
or whatever else, but declare it global) and store it with the context
you have just loaded, perhaps this way you would "deceive" the optimizer,
show it that the loaded value IS used, although such a solution is certainly
waste of resources.

Let me know if this worked or not; a segment of sa code and the result asm
piece would be much appreciated :)

For other posts: I am not sure that even declaring the location to be
read off as volatile in C code would solve the problem, as this
read is soft of "futile", since the value will not be used afterward,
and the optimizer should be wiping off such reads anyway. Might be
the same trick with storing a "garbage" global location would help.

One more .sa problem: it might be so that I need to write a squence
of memory locations in a certain order, e.g. to start a QDMA transfer.
I do know how to ensure a sertain order in C (use commas and a semicolon
in the end, forgotten the term, whatewer "point"), but it seem to be
no ways to enforce this in a serial assembly code?

Regards,

Andrew

Martin Eckel <martin.eckel@t-online.de> wrote in message
news:<bk7r38$cne$06$1@news.t-online.com>...
> Hello, > > Not only once I have had the problem, that the C6000 assembler optimizer > is optimizing to much. > > Sometimes I have to read a memory location or memory mapped register - > and then throw the value away, because reading of the register already > makes the wanted effect. > > But the assembler optimizer thinks, if the value is thrown away, the > whole read command is unneccessary - and the command is just deleted. > > Is there any way to tell the assembler optimizer "don't optimize this > line"? > > I don't want to program direct in parallel assembler, I like the serial > assembler ;-) > > Best regards, > Martin
Jerry Avins <jya@ieee.org> wrote in message news:<bke23e$h8h$1@bob.news.rcn.net>...
> John McCabe wrote: > > > On Tue, 16 Sep 2003 16:36:59 -0400, Jim Thomas <jthomas@bittware.com> > > wrote: > > > > > >>Read up on C's "volatile" directive. In short, you want to do this: > >> > >>volatile int control register; > >> > >>"volatile" tells the optimizer that the value can change outside the > >>program (i.e., it's a hardware register or it's changed by an ISR, or > >>it's in shared memory and another program changes it, etc...) > > > > > > Can you declare locations as volatile using assembler then? > > > > > > Best Regards > > John McCabe > > > > To reply by email replace 'nospam' with 'assen' > > "Volatile" declares that the data at the location may have changed > without program intervention, and so muse be read afresh each time. It > doesn't declare that the value must be read even though it is unused. > Storing it to a dummy variable might be an [expensive] workaround. > > Jerry
Oops, many apologies Jerry, you have already pointed out what I was going to say! And most unfortunately I have posted it :) Martin, please disregard my post then, Andrew