Use of CLR in generated code
Moderator: Stef
-
- Very interested
- Posts: 292
- Joined: Sat Apr 21, 2007 1:14 am
Use of CLR in generated code
I've noticed when assigning a volatile memory location to zero, gcc will emit a CLR instruction. Is there any way to force it to write a constant zero instead of using a read-modify-write instruction such as CLR?
Also I recall there was some way to suppress the requirement of a percent sign on register names in as, so you could write code like "tst.l d0" instead of "tst.l %d0". There's a reference to this functionality at the Atari ST cross compiler page:
"Registers may be prefixed by % like %d0 but in our binutils configuration this is not mandatory."
http://bus-error.nokturnal.pl/article2- ... C-programs
http://vincent.riviere.free.fr/soft/m68k-atari-mint/
Though they make it sound like an option set when compiling the tools and I recall it was a command line parameter passed to as.exe. Does such a feature still exist? (or did it ever exist :)
Also I recall there was some way to suppress the requirement of a percent sign on register names in as, so you could write code like "tst.l d0" instead of "tst.l %d0". There's a reference to this functionality at the Atari ST cross compiler page:
"Registers may be prefixed by % like %d0 but in our binutils configuration this is not mandatory."
http://bus-error.nokturnal.pl/article2- ... C-programs
http://vincent.riviere.free.fr/soft/m68k-atari-mint/
Though they make it sound like an option set when compiling the tools and I recall it was a command line parameter passed to as.exe. Does such a feature still exist? (or did it ever exist :)
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
-
- Very interested
- Posts: 292
- Joined: Sat Apr 21, 2007 1:14 am
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
No problem. There's not a whole lot of info on gcc options as regards the 68000. Especially on inline assembly. Virtually all inline assembly info is on x86, with a little on ARM. I've had to scour the net and open source along with experimentation to figure out 68000, SH2, PPC, and MIPS. Flags like that one to avoid needing the prefix is another example of something you gotta hunt diligently to find. Even something as straightforward as the ABI for a particular processor can be a pain to track down.
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
To avoid CLR instruction use by GCC i use an infamous trick in SGDK.
I have the following methods :
and so when i need to zero memory i do :
Because getZeroU32() is not a static method it does not optimize it to a constant (and so 0 which result in CLR instruction use).
GCC just store the result of getZeroU32() in a register and use it to fill memory = fast clear.
I have the following methods :
Code: Select all
u8 getZeroU8()
{
return 0;
}
u16 getZeroU16()
{
return 0;
}
u32 getZeroU32()
{
return 0;
}
Code: Select all
u32 fill = getZeroU32();
i = num;
while (i--) *dst++ = fill;
GCC just store the result of getZeroU32() in a register and use it to fill memory = fast clear.
-
- Very interested
- Posts: 292
- Joined: Sat Apr 21, 2007 1:14 am
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
Yes, that is. Using the lack of good global optimization to your own benefit.Charles MacDonald wrote:Ha, that's brilliant. I'll definitely use it.Stef wrote:To avoid CLR instruction use by GCC i use an infamous trick in SGDK.
Perhaps make the function into a common constant table fetch...
Code: Select all
u8 getConstantU8(int constant)
{
switch(constant)
{
case CONST_ZERO:
return 0;
case CONST_ONE:
return 1;
default:
return 255;
}
}
Code: Select all
u8 getValU8(int val)
{
return (u8)val;
}
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Haha, not sure it's brilliant but at least it worksCharles MacDonald wrote:Ha, that's brilliant. I'll definitely use it.Stef wrote:To avoid CLR instruction use by GCC i use an infamous trick in SGDK.
Chilly Willy> Only the 0 constant is a problem, in other case it uses register to store value then fill memory.
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
What? They don't use st for -1? How lazy!Stef wrote:Haha, not sure it's brilliant but at least it worksCharles MacDonald wrote:Ha, that's brilliant. I'll definitely use it.Stef wrote:To avoid CLR instruction use by GCC i use an infamous trick in SGDK.
Chilly Willy> Only the 0 constant is a problem, in other case it uses register to store value then fill memory.