Re: [math-fun] intel and bad instruction sets history/philosophy
I'm not going to defend C or any high-level language for not supporting add-with-carry, because I've argued for the same thing myself. I will try to give the traditional side of the argument, tho. The problem with add-with-carry is that the carry bit doesn't fit into the standard syntactical model, so you can no longer use the infix "+" operator. This isn't a problem for Lisp, because Lisp never believed in infix operators in the first place, but it is a huge problem for most other "high level" languages that attempt to utilize infix notations. But even more difficult is the carry _out_ bit (or the high order portion of a single-single multiply operation. By rights, this operation produces _two_ results, and again most "high level" languages don't want to deal with that. Common Lisp follows the Lisp Machine (and Forth-like stack languages) in offering _multiple_ return values. The Common Lisp syntax is unfortunately quite awkward: (multiple-value-bind (low high) (dpmultiply x y) ... do something with 'low' and 'high' ...) I would have preferred something more like: (let ((low high (dpmultiply x y))) ... do something with 'low' and 'high' ...) So it is quite easy to fit add-with-carry, double-precision-multiply, etc., into a Lisp language. If you understand so-called "continuation-passing style" (CPS), then you can do a lot better, and no longer have to rely on a stack: (dpmultiply x y #'(lambda (low high) ... do something with 'low' and 'high' ... )) "dpmultiply" multiplies x*y and then (tail) _calls_ the "continuation" function with the low & high portions. (C languages sometimes calls this type of function argument a "call-back", which is a bit tortured, and also doesn't work very well in C due to C's lack of proper closures.) Believe it or not, with proper type declarations (and/or good type inferencing capabilities) these Lisp expressions can be compiled into essentially optimal assembly code for fixed-precision arithmetic (often called "FIXNUMs"). So a Lisp-like language can be compiled to machine code every bit as good as any C compiler. Hopefully, we'll turn Warren into a Lisper, yet! At 06:33 PM 4/19/2014, Warren D Smith wrote:
What about "add with carry"? Sorry, C pretends that does not exist and so if you want to write multiprecision arithmetic, you cannot use C (unless willing to pay heavy performance price) and must put in some assembler.
All because, the providers of C, *SUCKED.* And practically every high-level language in the universe, pretends add-with-carry does not exist. It is just appalling. What is their problem?
participants (1)
-
Henry Baker