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

  1. Xref: sparky comp.arch:11021 comp.lang.misc:3839
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!tamsun.tamu.edu!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!tmb
  3. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  4. Newsgroups: comp.arch,comp.lang.misc
  5. Subject: Re: how to advocate new software/hardware features (Re: Hardware Support for Numeric Algorithms)
  6. Date: 23 Nov 92 10:05:25
  7. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  8.     Perceptive)
  9. Lines: 41
  10. Message-ID: <TMB.92Nov23100525@arolla.idiap.ch>
  11. References: <Bxr8vG.IpI@mentor.cc.purdue.edu> <martin.721995695@bert>
  12.     <martin.722176263@bert>
  13.     <1992Nov20.135747.4642@sun0.urz.uni-heidelberg.de>
  14. Reply-To: tmb@idiap.ch
  15. NNTP-Posting-Host: arolla.idiap.ch
  16. In-reply-to: dentzer@clio.iwr.uni-heidelberg.de's message of Fri, 20 Nov 92 13:57:47 GMT
  17.  
  18. In article <1992Nov20.135747.4642@sun0.urz.uni-heidelberg.de> dentzer@clio.iwr.uni-heidelberg.de (Ralf Dentzer) writes:
  19.  
  20.    As some sort of compromise between portability and efficiency I would make
  21.    the following proposal for a set of basic functions to deal with multiple
  22.    digit integers. The main restriction for them is the imposition to have a 
  23.    C-function interface, but only thus portability can be guaranteed.
  24.  
  25. Good; that's the right way to go.
  26.  
  27.    First there should be a data type "Digit_t" e.g., usually unsigned long
  28.    or what else fits into one register, and a constant BitsPerDigit.
  29.    Then come six functions for calculating with Digits, these provide
  30.    access to carrys, the higher digit of a product and a division
  31.    with two digit dividend:
  32.  
  33.    Digit_t DigitAdd(Digit_t *sum, Digit_t a, Digit_t b, Digit_t carry);
  34.        /* *sum=LOW-DIGIT(a+b+carry);
  35.           return HIGH-DIGIT(a+b+carry); 
  36.        */
  37.    [...]
  38.  
  39.    These functions are sufficient to build a multiple digit arithmetic,
  40.    but due to function call overhead they are too slow.
  41.    (More or less, depending on the processor; on a Sparc their
  42.    performance is not that bad.)
  43.  
  44. You could standardize these as macros, not functions.  The main
  45. user-visible difference would be in not being able to take the
  46. address. Even if you do define these as functions, your compiler
  47. could (and should) inline them.
  48.  
  49. Also, a slightly better interface might be to turn this into a
  50. conditional construct, conditional on the carry bit:
  51.  
  52.     CPU_WORD result,a,b;
  53.     ...
  54.     ADD_WITH_CARRY(result,a,b) { /* carry==1 */ }
  55.     else { /* carry==0 */ }
  56.  
  57.  
  58.                     Thomas.
  59.