Path: utzoo!mnetor!uunet!husc6!linus!bs From: bs@linus.UUCP (Robert D. Silverman) Newsgroups: comp.lang.c Subject: Re: The need for D-scussion (was Re: D Wishlist) Message-ID: <27143@linus.UUCP> Date: 17 Mar 88 13:51:20 GMT References: <12176@brl-adm.ARPA> <1988Mar11.215238.976@utzoo.uucp> <3732@bloom-beacon.MIT.EDU> <7451@brl-smoke.ARPA> Reply-To: bs@gauss.UUCP (Robert D. Silverman) Organization: The MITRE Corporation, Bedford MA Lines: 47 In article <7451@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In article <3732@bloom-beacon.MIT.EDU> tada@athena.mit.edu (Michael Zehr) writes: >>a function the returns both a % b and a / b at the same time. > >This is the first time I recall in the "D" discussion that an useful >genuine language feature has been proposed. All you need now is a >suitable notation.. I am a computational number theorist who writes a LOT of code requiring that: A*B/C A*B % C be computed where A,B,C are all 30 bit quantities. The difficulty is that even though the algorithm guarantees that the results of the computations fit in 30 bits, the product A*B may not. I therefore need to make extensive use of any 'emul' and 'ediv' facilities that a computer may have. I have written code which spends 25% of its time JUST doing the above computations (and takes 100's of hours to run). Since there is no 'long long' in C I am forced to write an assember routine which does the computations as follows: remainder = mod_mult(A,B,C,"ient) or the equivalent depending on circumstances. It must first emul A and B then ediv by C. Since most machines which have ediv return the quotient and remainder in two different registers no extra work is required to get the remainder after doing the division. Machines which have such instructions should, In my opinion, generate emul/ediv code whenever it sees A*B/C and only return a run-time arithmetic overflow if the quotient doesn't fit in the appropriate word-size. There should at least be some compiler switch which allows this option. What good are emul and ediv if you can't reach them from higher level languages? Especially on a VAX if you have to call an assembler routine to perform the above, the subroutine call itself can take about as much time as the calculations. A calls on the VAX/780 with 4 arguments takes ~ 17usec. The ediv takes 11.9 and the emul takes 6.8usec. UGLY. There is some need (although I will concede not a lot) for multi-precision arithmetic support. Modern languages are woefully inadequate for the task. Bob Silverman