home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / gcc / help / 2551 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  2.4 KB

  1. Path: sparky!uunet!think.com!news!mob
  2. From: mob@strident.think.com (Mario O. Bourgoin)
  3. Newsgroups: gnu.gcc.help
  4. Subject: Getting GCC to optimize handling of doubles.
  5. Date: 18 Nov 92 09:09:52
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 75
  8. Distribution: gnu
  9. Message-ID: <MOB.92Nov18090952@strident.think.com>
  10. NNTP-Posting-Host: strident.think.com
  11.  
  12.  
  13. Hello,
  14.  
  15. I'm using the GCC cast to union type to get at the bits that make up floats
  16. and doubles (but this is not a problem of cast to union.)  Here's a trivial
  17. example, if you want to try:
  18.  
  19.   test (array) unsigned *array;
  20.   {
  21.     *(array + 0) = ((union {unsigned u; float f;}) (float) 3.1).u;
  22.     *(array + 1) = ((union {unsigned u; double f;}) (double) 3.1).u;
  23.   }
  24.  
  25. When compiled optimized, the first line yields:
  26.  
  27.     sethi %hi(1078355558),%g2
  28.     or %g2,%lo(1078355558),%g2
  29.     st %g2,[%i0]
  30.  
  31. but the second line yields:
  32.  
  33.     sethi %hi(1074318540),%g2
  34.     or %g2,%lo(1074318540),%g2
  35.     sethi %hi(-858993459),%g3
  36.     or %g3,%lo(-858993459),%g3
  37.     st %g2,[%i0+4]
  38.  
  39. which is twice the work requested (I only need the most significant part of
  40. the double.)
  41.  
  42. How do I go about finding what to change in GCC to optimize the double
  43. case?
  44.  
  45. --Mario
  46.  
  47. P.S.  Some additional information that might be of use:
  48.  
  49. - I'm compiling with:
  50.  
  51.   % gcc -v -S -O -o main.s main.c
  52.   Reading specs from /usr/local/lib/gcc-lib/sun4/2.2.2/specs
  53.   gcc version 2.2.2
  54.    /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
  55.   GNU CPP version 2.2.2 (sparc)
  56.    /usr/local/lib/gcc-lib/sun4/2.2.2/cc1 /usr/tmp/cca07596.i -quiet -dumpbase main.c -O -version -o main.s
  57.   GNU C version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
  58.  
  59.  
  60. - The optimized code generated is the same when the cast to union is not
  61. used, so this is a general problem.
  62.  
  63.   test (array) unsigned *array;
  64.   {
  65.     {
  66.       union {unsigned u; float f;} single_precision;
  67.       single_precision.f = (float) 3.1;
  68.       *(array + 0) = single_precision.u;
  69.     }
  70.  
  71.     {
  72.       union {unsigned u; double f;} double_precision;
  73.       double_precision.f = (double) 3.1;
  74.       *(array + 1) = double_precision.u;
  75.     }
  76.   }
  77.  
  78. - The unoptimized code produces a double load (LDD) in the second case of
  79. the cast to union:
  80.  
  81.     sethi %hi(LC1),%o1
  82.     ldd [%o1+%lo(LC1)],%o2
  83.     st %o2,[%o0]
  84.  
  85. Is making this be a single load (LD) a good place where to begin getting
  86. the optimization to be better?
  87.