Donal K. Fellows (firstname.lastname@example.org) wrote:
: > the SPARC architecture has several instructions that C compilers doesn't
: > use, but which are convenient with type-tagged languages. the _fact_ is
: > that it has an the instruction, with Sun's recommended mnemonic "taddcctv",
: > that is specifically useful in Lisp, and specifically unused in C. other
: > instructions are also measurably useful in languages _other_ than C.
: What does the instruction do? I've not got a SPARC manual to hand and
: I'm quite sure that there are other people reading this thread who are
: also unaware of the meaning of that instruction.
The Sparc architecture has support for a "tagged integer" data type.
The two low-weight bits of a tagged word contain a tag, the other bits contain
a 30-bit integer. The two provided operations (add and substract) work as
one would expect on words with tag=0. With other values, they generate an
overflow error. taddcctv (resp. tsubcctv) adds (resp. subtracts) two tagged
words, sets the condition codes (cc) and traps on overflow; alternatively,
one may use taddcc/tsubcc, which do not trap.
This is meant for use with dynamically typed languages. Integers are tagged 0,
and the most commonly used operations (add/sub) on them work transparently.
Pointers are tagged with 1, 2 or 3. If a pointer is mistakenly used as an
integer, it generates an error (and maybe a trap). To compensate for the tag,
data is accessed with relative offsets -1, -2 or -3 respectively from a
tagged pointer. As words are 4-byte aligned, addressing data with the wrong
offset generates a bus error. That is, data with one tag used mistakenly
as if it were to bear another tag make the processor trap.
(all this taken from "The Sparc architecture manual, version 8").
The tags may be used by the garbage collection process to see what words
contain integers and what words contain pointers. I do not have examples
of implementations using the Sparc tagged arithmetic, but the only garbage
collecting implementation I know quite well, Objective CAML, tags data
using the lowest weight bit.
Hope this helps.
PS: Sorry, but the overall aggressive tone of the discussions around
("You aren't competent on that topic! - Yes, I am, it's you who don't
know anything about what is talked of!") disturb me.
We should spend more time actually working on improving computer languages,
tools and libraries, and less arguing about, as Xavier Leroy said,
whether angels are male or female. :-)
PS2: I've trimmed the followup-to. If we are to discuss generally upon the
use of processor features for garbage collection and sanity checks in
garbage-collected language, I think we can restrict ourselves to
"If computers worked, it'd be known."
Computer science student at ENS, Lyon, France