Xref: utzoo comp.arch:10523 comp.lang.misc:3043 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!ames!ncar!ico!ism780c!haddock!suitti From: suitti@haddock.ima.isc.com (Stephen Uitti) Newsgroups: comp.arch,comp.lang.misc Subject: Re: Double Width Integer Multiplication and Division Message-ID: <13961@haddock.ima.isc.com> Date: 7 Jul 89 04:43:06 GMT References: <57125@linus.UUCP> <1989Jun24.230056.27774@utzoo.uucp> <13946@haddock.ima.isc.com> <1388@l.cc.purdue.edu> Reply-To: suitti@haddock.ima.isc.com (Stephen Uitti) Organization: Interactive Systems, Boston Lines: 92 In article <1388@l.cc.purdue.edu> cik@l.cc.purdue.edu (Herman Rubin) writes: >> >What languages, other than Lisp and some similar ones, have >> >the idea that an operation or function can return a string of values? >> C. One can pass structures and unions back & forth by name or >> value. >NO!. For the n-th time, a list is not a struct. It presumes a >particular "physical" ordering of the items. LISP does not actually pass whole lists around - it uses pointers and linked lists. In C, linked lists are typically implemented with a struct for each node. There are no lists in C, but structs can be lists. You wanted to have a function be able to return more than one item. I suggested two syntactic solutions: returning a struct, or having the caller specify where to put the answers. When it comes down to it, you don't want the compiler to necessarily generate a function with call/return overhead. You really want functions or intrinsics that the compiler can turn into inline code. You are thinking of inline code as a single instruction, though i'm not limiting this to anything that simple. Is there anything really evil with this: q = divrem(top, bottom, &remainder); Divrem can "return" q, and stuff "remainder" where it is supposed to go. Compilers are getting smart enough to do this the way you want it. This is documentable. This is manageable. Type checking can be done everywhere to reduce the error rate. Let's say you have a '205 and a VAX. You want to develop your code on the VAX, because it has better debuggers, faster response, and it is much cheaper than '205 time. If you break the grammer of your standard language, then you have to break it for both machines. The above 'divrem' function can be written in real C, and a (slow) version can run, and be debugged on the VAX. Then, the very same code can be run on the target machine. The way '205 C's vector stuff was actually done broke all sorts of things. Writing portable high speed code required heavy ifdefs for each application. It could have been done in a manner that a simple library could be written for the VAX (etc.) that would allow the code to be just run. >I want to write > q,r = x/y; Unfortunately, this already means something in C. >On the VAX, for example, q could be in register 3 and r in register 10. The syntax i suggested above would not require things to be in any given place. The compiler should be able to figure this sort of thing out. >Since the hardware allows simple things like this, the language should. The language does. It just doesn't allow you to do it with the syntax you want. This is (by comparison to register allocation and procedure inlining) a hard problem. Languages that have fixed syntax are difficult enough to prove unambiguous. If the language allows free redefinition, it is easy for the user to generate something that can't be parsed. It took years to get a real Ada compiler to work. >At the present time and in the future, loads and stores must slow things >down unless they can be overlapped. Or optimized out. >The stupid use of the word "typedef" in C rather than the more >accurater "typealias" is responsible for this. OK, so the terminology for C is a little broken. I've used languages that have (for example) German words for keywords. That didn't mean that i felt the need to change the language's syntax or terminology. >As a simple case, >I should be able to tell the compiler that \ is the bit clear operation, >which &~ may or may not handle properly, and has the same machine >structure as OR on the VAX. How do you want to tell it what the operator means? Do you want to give it an assembler template? Do you want to give it an algorithm already expressible in the language? If it is assembler, you probably want gcc's asm feature that allows symbolic names to be given to assembler arguments. Then, if it turns out to be more complicated, you might try preprocessor macros. If it turns out to be more complicated than that, you might put it into an inlineable function. Otherwise, it should probably be a true function. You may already have the tools you need. Stephen.