Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!think.com!linus!linus!faron!bs From: bs@faron.mitre.org (Robert D. Silverman) Newsgroups: comp.arch Subject: Re: standard extensions Message-ID: <1991Feb26.202547.13388@linus.mitre.org> Date: 26 Feb 91 20:25:47 GMT References: <1991Feb25.201406.18643@bingvaxu.cc.binghamton.edu> <1991Feb26.171338.8362@linus.mitre.org> <1991Feb26.190242.18983@zoo.toronto.edu> Sender: news@linus.mitre.org (News Service) Organization: The MITRE Corporation, Bedford, MA 01730 Lines: 64 Nntp-Posting-Host: faron.mitre.org In article <1991Feb26.190242.18983@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: >In article <1991Feb26.171338.8362@linus.mitre.org> bs@linus.mitre.org (Robert D. Silverman) writes: >>You miss the point. There ARE many processors that provide double >>length multiply and divide with remainder instructions. Most current >>HLL's have no way of generating code that will access these instructions. > >Nonsense. You mean "most current compilers do not recognize situations >where such instructions could be generated". In most any HLL you can >write something like > > x = a / b > y = a % b > >which amply suffices as a way of requesting use of such instructions. >Blame the compiler, not the language, if the generated code doesn't use >the hardware properly. Bull. Both the compiler and the language are to blame. One should have some way of specifying, for example, that c = a*b is to be a 32x32 multiply (and generating the appropriate instruction or calling a routine to do it). One might also want c = a*b to return only 32 bits since the latter operation is a lot faster. What is needed is a facility in the LANGUAGE ITSELF for specifying which type of multiply to perform. short, int, and long are not enough. One also needs a 'long long' for intermediate results. However, If I write the following code: long a,b,c,d; a = (b*c + 1)/d The COMPILER should realize that since the product of two longs can overflow, then it needs to generate code that will perform a 32x32 multiply followed by a 64 / 32 divide. Even on machines that have these instructions in hardware no compilers currently do this. Current compilers default to returning ONLY the low 32 bits and this is clearly wrong from a mathematical standpoint. Now if it should turn out that the true value of a is bigger than 32 bits, then I have made an error in my code. Furthermore, there should be some way of specifying explicitly that I ONLY want the low order bits of a 64 bit product. Currently, all compilers assume this by default. One doesn't even have a way of getting the high 32 bits if wanted. e.g. a = low32(b*c + 1)/d or a = high32(b*c + 1)/d It is still my contention that current languages are woefully inadequate for implementing integer arithmetic in an EXACT mathematical fashion. The operations proposed here are NOT highly specialized and abstract. They are basic arithmetic. -- Bob Silverman #include Mitre Corporation, Bedford, MA 01730 "You can lead a horse's ass to knowledge, but you can't make him think" Brought to you by Super Global Mega Corp .com