home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / arch / 10784 < prev    next >
Encoding:
Internet Message Format  |  1992-11-16  |  4.1 KB

  1. Path: sparky!uunet!spool.mu.edu!sol.ctr.columbia.edu!ira.uka.de!uka!uka!news
  2. From: S_JUFFA@iravcl.ira.uka.de (|S| Norbert Juffa)
  3. Newsgroups: comp.arch
  4. Subject: Re: how to advocate new software/hardware features (Re: Hard
  5. Date: 16 Nov 1992 13:48:47 GMT
  6. Organization: University of Karlsruhe (FRG) - Informatik Rechnerabt.
  7. Lines: 77
  8. Distribution: world
  9. Message-ID: <1e88rvINNm9q@iraul1.ira.uka.de>
  10. References: <1992Nov13.155126.3660@linus.mitre.org> <TMB.92Nov14145619@pollux.idiap.ch> <7899@charon.cwi.nl> <1992Nov15.193356.1549@sal.wisc.edu>
  11. NNTP-Posting-Host: irav1.ira.uka.de
  12. X-News-Reader: VMS NEWS 1.23
  13. In-Reply-To: alan@sal.wisc.edu's message of Sun, 15 Nov 1992 19:33:56 GMT
  14.  
  15. In <1992Nov15.193356.1549@sal.wisc.edu> alan@sal.wisc.edu writes:
  16.  
  17. > In article <7899@charon.cwi.nl> dik@cwi.nl (Dik T. Winter) writes:
  18. > >But wait.  SPARC version 7 does not have an integer multiply instruction,
  19. > >it uses multiply step.  When you code the multiply in assembly you will
  20. > >find that you get a 64 bit result, but in C it is not possible to
  21. > >retrieve that result.  Doing it with inline assembly is not what you
  22. > >want in general (>32 instructions inline assembly), so you do it
  23. > >out-of-line.  Hence it is not sufficient to have good inliners, on
  24. > >some platforms you need out of line assembly routines to do what you
  25. > >want, and no, the compilers do not help.  (The same holds for HP-PA 1,
  26. > >IBM PC-RT, AMD 29k and a few more.)  So the operation is available but
  27. > >you do not get it.
  28. > >
  29. > >So let's see.  You promote the GCC interface with asm.  How do you
  30. > >code the 32x32->64 multiply on the SPARC in GCC?
  31. > Include the following in every source file:
  32. >     static inline long long mul32to64 (long i, long j)
  33. >     {
  34. >         whatever asm magic one requires
  35. >     }
  36. > This terribly inelegant; if you want elegance BUY a compiler for the
  37. > machine which has 64 bit longs and use:
  38. >     long i64;
  39. >     int i32, j32;
  40. >     i64 = (long) i32 * (long) j32;
  41. > If the compiler insists on promoting i32 and j32 to 64 bits before the
  42. > multiplication, ask for your money back.
  43. > Solutions exists for many of the specific problems which have been
  44. > discussed in this thread: most of the free ones are inelegant and most
  45. > of the elegant ones are expensive.
  46.  
  47. I would think that most compilers with optimizers can generate a n-bit * n-bit
  48. -> 2n-bit multiply instruction if it is available in HW. A while back, I tried
  49. this with an 8086 (which has 16x16->32 multiply) and the lowly MS-FORTRAN 5.0 
  50. optimizing compiler. What I wanted to do is multiply to INTEGER*4 numbers, the
  51. result being an INTEGER*4 (32-bit integer), and I knew that the inputs fit into
  52. 16 bits each, so I didn't want the compiler to call the 32x32->32 bit mul
  53. routine. So I tried:
  54.  
  55. INTEGER*4 I,J,K
  56. INTEGER*2 TEMP1, TEMP2
  57.  
  58. TEMP1=I
  59. TEMP2=J
  60. K=TEMP1*TEMP2
  61.  
  62. I ran it thru the compiler with max. optimization and took a look at the 
  63. assembly output. I was amazed that the compiler had produced exactly the result
  64. I wanted:
  65.  
  66. MOV   AX, WORD PTR [I]      ; load least significant 16 bits of I
  67. MOV   DX, WORD PTR [J]      ; load least significant 16 bits of J
  68. MUL   DX                    ; multiply I*J (result in regs DX,AX)
  69. MOV   WORD PTR [K], AX      ; store 32-bit
  70. MOV   WORD PTR [K+2], DX    ;  result
  71.  
  72. I haven't checked the 32/16->16 bit divide, but I wouldn't be surprised if it
  73. works as well. I'll admit though that there are instructions that are difficult
  74. to generate from a HLL: adding loooong integers with ADD/ADC, or shifting them
  75. using the 80386 double shift instructions SHLD, SHRD (these allow you to shift
  76. crossing register boundaries, actually the asm-notation for the functionality
  77. of a funnel-shifter), etc. The problem here is that the code to do the equi-
  78. valent operations in a HLL does not map to these instructions in very obvious
  79. ways (think about generating a HW bitcount instruction from the HLL code for a
  80. bitcount!). A human can see what is really intended, but today's compilers can't
  81. (I would be pleased to be proved wrong on this one).
  82.  
  83. Norbert
  84. -------------------------------------------------------------------------------
  85. Norbert Juffa        email: S_JUFFA@IRAVCL.IRA.UKA.DE        Live and let live!
  86.