Path: utzoo!mnetor!uunet!husc6!hao!ames!ll-xn!mit-eddie!bloom-beacon!athena.mit.edu!wesommer From: wesommer@athena.mit.edu (William Sommerfeld) Newsgroups: comp.lang.c Subject: Re: The need for D-scussion (was Re: D Wishlist) Message-ID: <3734@bloom-beacon.MIT.EDU> Date: 14 Mar 88 00:49:15 GMT References: <12176@brl-adm.ARPA> <1988Mar11.215238.976@utzoo.uucp> <3732@bloom-beacon.MIT.EDU> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: wesommer@athena.mit.edu (William Sommerfeld) Organization: Massachusetts Institute of Technology Lines: 34 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. > >I know I've had to call those routines with the same values consecutively >in code that needed to run fast, and if i understand the library right, What library? If you've got a CISC processor with integer divide in microcode (such as the VAX), divide is a single instruction. Modulo might be, too. On just about any reasonable processor, if you're computing someething % or / a power of two, you can turn the operation into an `and' (with (2**n)-1) or `shift right' (by n), respectively, which _is_ in hardware >they >both compute the pair of values, but a different one is returned. Why not >give the option of getting them both at the same time? Well, the VAX has this `ediv' instruction which does both a divide and a modulo.. A good compiler would notice the `common subexpression': c = a / b; d = a % b; and generate the one hairy instruction or function call. I think there's some support in the GNU C compiler for this, but it's turned off on the VAX because `ediv' is apparantly a real turkey of an instruction. - Bill