Thread View: gnu.gcc.help
1 messages
1 total messages
Started by Mario O. Bourgoin
Wed, 18 Nov 1992 09:09
Getting GCC to optimize handling of doubles.
Author: Mario O. Bourgoin
Date: Wed, 18 Nov 1992 09:09
Date: Wed, 18 Nov 1992 09:09
75 lines
2575 bytes
2575 bytes
Hello,
I'm using the GCC cast to union type to get at the bits that make up floats
and doubles (but this is not a problem of cast to union.) Here's a trivial
example, if you want to try:
test (array) unsigned *array;
{
*(array + 0) = ((union {unsigned u; float f;}) (float) 3.1).u;
*(array + 1) = ((union {unsigned u; double f;}) (double) 3.1).u;
}
When compiled optimized, the first line yields:
sethi %hi(1078355558),%g2
or %g2,%lo(1078355558),%g2
st %g2,[%i0]
but the second line yields:
sethi %hi(1074318540),%g2
or %g2,%lo(1074318540),%g2
sethi %hi(-858993459),%g3
or %g3,%lo(-858993459),%g3
st %g2,[%i0+4]
which is twice the work requested (I only need the most significant part of
the double.)
How do I go about finding what to change in GCC to optimize the double
case?
--Mario
P.S. Some additional information that might be of use:
- I'm compiling with:
% gcc -v -S -O -o main.s main.c
Reading specs from /usr/local/lib/gcc-lib/sun4/2.2.2/specs
gcc version 2.2.2
/usr/local/lib/gcc-lib/sun4/2.2.2/cpp -lang-c -v -undef -D__GNUC__=2 -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -D__OPTIMIZE__ main.c /usr/tmp/cca07596.i
GNU CPP version 2.2.2 (sparc)
/usr/local/lib/gcc-lib/sun4/2.2.2/cc1 /usr/tmp/cca07596.i -quiet -dumpbase main.c -O -version -o main.s
GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
- The optimized code generated is the same when the cast to union is not
used, so this is a general problem.
test (array) unsigned *array;
{
{
union {unsigned u; float f;} single_precision;
single_precision.f = (float) 3.1;
*(array + 0) = single_precision.u;
}
{
union {unsigned u; double f;} double_precision;
double_precision.f = (double) 3.1;
*(array + 1) = double_precision.u;
}
}
- The unoptimized code produces a double load (LDD) in the second case of
the cast to union:
sethi %hi(LC1),%o1
ldd [%o1+%lo(LC1)],%o2
st %o2,[%o0]
Is making this be a single load (LD) a good place where to begin getting
the optimization to be better?
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads