1) is there any way to force gcc to inline a function/method, when i declare
it as "inline"? seemingly it's up to gcc to decide if the function is to
be inlined or not...
2) i reference code without having control flow, that reaches this code:
int codesize() {
return ((unsigned int) &&Lend) - ((unsigned int) &&Lstart);
Lstart:
__asm__ __volatile__ (" ... ");
Lend:
(void)0;
}
now some versions of gcc (the RH gcc 2.96, to be precise) removes the code
because it is dead. arguable... its not reachable, but referenced. so is
it still dead? anyway, my workaround is ugly
bool phony = false;
int codesize() {
if (phony) goto Lstart;
else return ((unsigned int) &&Lend) - ((unsigned int) &&Lstart);
Lstart:
__asm__ __volatile__ (" ... ");
Lend:
(void)0;
}
is there any other way to prevent the code from being removed? i thought
this is the purpose of __volatile__ but obviously not.
cheers,
jens
--
Jens Tröger Ph: +61 7 3864-9342
Programming Languages & Systems Research Center
School of Computing Science j.tr...@qut.edu.au
QUT, Brisbane, Australia http://www.fit.qut.edu.au/~troger
> 1) is there any way to force gcc to inline a function/method, when i declare
> it as "inline"? seemingly it's up to gcc to decide if the function is to
> be inlined or not...
I believe that is true for all C++ compilers -- 'inline' is just like 'register'.
If you want it *guaranteed* inlined, #define it ...
> 2) i reference code without having control flow, that reaches this code:
>
> int codesize() {
> return ((unsigned int) &&Lend) - ((unsigned int) &&Lstart);
>
> Lstart:
> __asm__ __volatile__ (" ... ");
> Lend:
> (void)0;
> }
>
> now some versions of gcc (the RH gcc 2.96, to be precise) removes the code
> because it is dead. arguable... its not reachable, but referenced.
It's not even referenced, just the distance is computed ...
> it still dead? anyway, my workaround is ugly
>
I've tried compiling your workaround with 'gcc-3.0 -O6', and
while it doesn't optimize away the asm, it *doesn't* compute
correct size either:
...
movl $.L5, %eax
subl $.L4, %eax
popl %ebp
ret
.L4:
.L5:
movl $ 99,%eax ## this is what I put into __asm__
I suggest simply coding the whole thing in Assembly.
Cheers,
--
In order to understand recursion you must first understand recursion.
I do it with a little more assembly (this is for an ARM):
-----
static int codesize(void)
{
unsigned int retval;
asm (
"mov %0,=Lend-Lstart\n\t" /* get length */
"b skip_it\n" /* skip the code piece */
"Lstart:\t"
" ... your code here ...\n"
"Lend:\n\t"
"skip_it:\n"
: "=r" (retval)
);
return retval;
}
-----
HTH
Tauno Voipio
tauno voipio @ iki fi
what do you mean with #define it?
> > 2) i reference code without having control flow, that reaches this code:
> >
> > int codesize() {
> > return ((unsigned int) &&Lend) - ((unsigned int) &&Lstart);
> >
> > Lstart:
> > __asm__ __volatile__ (" ... ");
> > Lend:
> > (void)0;
> > }
> >
> > now some versions of gcc (the RH gcc 2.96, to be precise) removes the code
> > because it is dead. arguable... its not reachable, but referenced.
>
> It's not even referenced, just the distance is computed ...
i reference two labels, isn't this "referenced"?
> > it still dead? anyway, my workaround is ugly
> >
>
> I've tried compiling your workaround with 'gcc-3.0 -O6', and
> while it doesn't optimize away the asm, it *doesn't* compute
> correct size either:
>
> ...
> movl $.L5, %eax
> subl $.L4, %eax
> popl %ebp
> ret
> .L4:
> .L5:
> movl $ 99,%eax ## this is what I put into __asm__
>
> I suggest simply coding the whole thing in Assembly.
whops!? even though the code is reachable AND it is declared as volatile,
gcc removes it! that is weird, or a bug. have you tried gcc3.1?
hm, since i use asm anyway i might take that approach. although i'd like to
limit the amount of asm to an absolute minimum...
> > I believe that is true for all C++ compilers -- 'inline' is just like 'register'.
> > If you want it *guaranteed* inlined, #define it ...
>
> what do you mean with #define it?
I mean instead of this:
inline int min(int a, int b) { return a < b ? a : b; }
write this:
#define MIN(a, b) (a) < (b) ? (a) : (b)
This MIN is *guaranteed* to be inlined ;-)
> > It's not even referenced, just the distance is computed ...
>
> i reference two labels, isn't this "referenced"?
Computing label address is a gcc-extension to begin with.
You can't say something is *broken* if there is no
standard by which you can judge the implementation, can you?