home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / gnu / gcc / bug / 2653 < prev    next >
Encoding:
Text File  |  1992-11-08  |  4.3 KB  |  119 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!nvr.com!toddb
  3. From: toddb@nvr.com (Todd Brunhoff)
  4. Subject: passing arguments in registers
  5. Message-ID: <9211070112.AA06367@nvr.com>
  6. Sender: gnulists@ai.mit.edu
  7. Reply-To: toddb@nvr.com
  8. Organization: GNUs Not Usenet
  9. Distribution: gnu
  10. Date: Fri, 6 Nov 1992 11:12:02 GMT
  11. Approved: bug-gcc@prep.ai.mit.edu
  12. Lines: 105
  13.  
  14. [There are 3 problems here, all related.  I'd be glad to split them up if
  15.  that's more appropriate...]
  16.  
  17. Gcc version: 2.2.2
  18. Host machine: Sun SPARCstation 2
  19. Host OS: SunOS 4.1.2 (aka Solaris 1.0.1)
  20. Environment: Cshell.
  21.  
  22. Problem 1:
  23.  
  24. I am using the asm() constructs to pass more than six arguments in registers
  25. to a function.  Most of the time I can move values into place in %g1, %g2,
  26. etc. and then force the compiler to leave them there with a local block
  27. surrounding the call to the function, like this (normally hidden in a
  28. macro):
  29.  
  30.         {
  31.                 register long reg7 asm("%g2");
  32.                 register long reg8 asm("%g3");
  33.                 register long reg9 asm("%g1");
  34.                 reg7 = (long) C67;
  35.                 reg8 = (long) C77;
  36.                 reg9 = (long) 6;
  37.                 asm volatile ("! (%0) reg7 is live" : : "r" ((long)reg7));
  38.                 asm volatile ("! (%0) reg8 is live" : : "r" ((long)reg8));
  39.                 asm volatile ("! (%0) reg9 is live" : : "r" ((long)reg9));
  40.                 function( c70,  c71,  c72,  c73,  c74,  c75);
  41.         }
  42.  
  43. This produces code like below, which looks right.
  44.  
  45.         mov %l2,%g2
  46.         mov %g5,%g3
  47.         mov 6,%g1
  48.         ! (%g2) reg7 is live
  49.         ! (%g3) reg8 is live
  50.         ! (%g1) reg9 is live
  51.         mov %i2,%o0
  52.         mov %i4,%o1
  53.         mov %i1,%o2
  54.         mov %l6,%o3
  55.         mov %l3,%o4
  56.         call _function,0
  57.         mov %l2,%o5
  58.  
  59. This doesn't seem to be sufficient, although I don't have evidence for
  60. this.  I think I am just plain lucky that the compiler didn't decide that
  61. the lifetimes for the register variables were up just before the
  62. function call, and clobber them.  Is there a way to assure myself
  63. that the registers stay put?
  64.  
  65. (related) Problem 2:
  66.  
  67. The called function needs to recognize the presence of the arguments
  68. in registers, of course.  I can't just say they are there, because
  69. the compiler either thinks they are dead or that they are generated
  70. in the routine, and hence uses the argument registers freely for
  71. other purposes.  I seem to be able to get around this with another
  72. local block in which I overwrite the declared arguments with the
  73. values in the registers.  Like this
  74.         {
  75.             register long reg7 asm("%g2"), reg8 asm("%g3");    
  76.             asm volatile ("! reg7,8 are %0 %1" : "=r" (reg7), "=r" (reg8));    
  77.             asm volatile ("! bypass c6@%0 & c7@%1" : : "o" (c6), "o" ( c7));    
  78.             c6 = reg7;   
  79.             c7 = reg8;  
  80.             asm volatile ("! now: c6 in %0, c7 in %1" : : "r" (c6), "r" ( c7));
  81.         }
  82.  
  83. Sometimes this produces code like:
  84.         !#PROLOGUE# 0
  85.         save %sp,-112,%sp
  86.         !#PROLOGUE# 1
  87.         ! reg7,8 are %g2 %g3
  88.         ! bypass c6@[%fp+92] & c7@[%fp+96]
  89.     *   mov %g2,%o7
  90.     *   mov %g3,%o0
  91.         ! now: c6 in %o7, c7 in %o0
  92.  
  93. Note that it did an explicit move (marked with *).  Looking at the code that
  94. follows, there doesn't seem to be a reason for this... it could have just as
  95. easily left them in %g2 and %g3.  Other times, the compiler leaves them
  96. in place.  What I really want to do is say, "here is argument 7".  I don't
  97. I want to explicitly declare them as %g2 and %g3, for two reasons:
  98.   - I like to be able to lint the code, because it helps me find where
  99.     I might have misplaced a variable.  This whole mechanism is done in
  100.     macros such that there is a machine-dependent version and a machine-
  101.     independent version, depending on how it is compiled.  Makes debugging
  102.     more reasonable.
  103.   - I want the compiler to reallocate and use the registers as it sees fit.
  104.     All I want to do is tell it where to start.
  105.  
  106. Problem 3:
  107.  
  108. What program do I use to peruse the gcc.info-* files.  Besides vi :-)
  109.  
  110. Can you help me?  Thanks either way.
  111.  
  112. ---------------
  113. internet: toddb@nvr.com                                             c--Q Q
  114. US:       Todd Brunhoff; North Valley Research;                         `
  115.           15262 NW Greenbriar Pkwy; Beaverton, OR  97006                -
  116. Phone:    (503) 531-5707
  117. Fax:      (503) 690-2320
  118.  
  119.