Paul Rubin <no.email@nospam.invalid> writes:
All CPython integers are boxed, but small ones (-5 through +250 or
something like that) are pre-allocated. Sounds awful but I think some
Lisps also have done that.
For example, PDP-10 MacLisp. The PDP-10 is a word addressed machine,
where addresses are 18 bits, and words are 36 bits. PDP-10 integers are
36 bits long, so pretty much your only choice for representing fixnums
is as an 18-bit pointer to a 36-bit signed integer, i.e. "boxed".
? If an intermediate fixnum needs to be allocated, say to pass as an
argument to another function, it can be allocated in a special area
of memory that has fixnum type, but that is managed as a stack -- the
GC doesn't touch it. That temporary number is then popped out of
existence after the function call returns. This does mean that the
compiler has to constantly worry that an object that it is about to
store someplace permanent might be a stack allocated "PDL number".
The utility that replaces a potential PDL number with a permanent
number is named "PDLNMK", and every serious MacLisp programmer knows
exactly what it does because it frequently appears in our compiled
code.
There's a paper by Guy Steele titled "Fast Arithmetic in MacLisp" that describes all these techniques in detail: <hdl.handle.net/1721.1/6279>.
Alan Bawden <alan@csail.mit.edu> writes:
For example, PDP-10 MacLisp. The PDP-10 is a word addressed machine,
where addresses are 18 bits, and words are 36 bits. PDP-10 integers are
36 bits long, so pretty much your only choice for representing fixnums
is as an 18-bit pointer to a 36-bit signed integer, i.e. "boxed".
I had no idea! Never having used it, I had always assumed that MACLISP shared the behavior of things like SBCL, Smalltalk, and recent versions
of Python???transparently overflowing from fixnums to bignums.
One advantage of the transparent-overflow approach is that most of the
time users don?t care what the actual fixnum limit is???it?s ?just? a performance optimization, in that your arithmetic starts consing when
you exceed the limit.
Kragen Javier Sitaker <kragen@canonical.org> writes:
I had no idea! Never having used it, I had always assumed that MACLISP
shared the behavior of things like SBCL, Smalltalk, and recent versions
of Python???transparently overflowing from fixnums to bignums.
Note that MacLisp _does_ have "transparent-overflow" arithmetic, you
just have to use `PLUS`, `TIMES` and `DIFFERENCE` instead of `+`, `*`
and `-`. The `+` family is fixnum-only, but the `PLUS` family handles
all types of numbers.
| Sysop: | Jacob Catayoc |
|---|---|
| Location: | Pasay City, Metro Manila, Philippines |
| Users: | 4 |
| Nodes: | 4 (0 / 4) |
| Uptime: | 497100:49:52 |
| Calls: | 182 |
| Files: | 744 |
| D/L today: |
38 files (5,920K bytes) |
| Messages: | 73,594 |