Dik T. Winter said:
Actually the high order 16 bits. The low order 48 bits are the memory
address.
I just ran an experiment on a Cray SV1. For a char* pointer, the
3-bit byte offset is in the high-order 3 bits of the 64-bit word.
I can believe, though, that the word address occupies only the 48
low-order bits, and the other 13 bits are always zero.
It's tempting to suggest that it would have made more sense to use the
entire upper 16 bits as a byte offset, but I suppose it's no more
difficult to extract the high-order 3 bits than to extract the
high-order 16 bits.
Here's the program:
========================================
#include <stdio.h>
int main(void)
{
char buf[100];
int i;
for (i = 0; i <= 8; i ++) {
printf("buf+%d = [%022p]\n", i, (void*)(buf + i));
}
return 0;
}
========================================
Here's the output:
========================================
buf+0 = [0000000000000000107531]
buf+1 = [0200000000000000107531]
buf+2 = [0400000000000000107531]
buf+3 = [0600000000000000107531]
buf+4 = [1000000000000000107531]
buf+5 = [1200000000000000107531]
buf+6 = [1400000000000000107531]
buf+7 = [1600000000000000107531]
buf+8 = [0000000000000000107532]
========================================
The "%p" conversion specifier formats addresses in octal. I used
"%022p" to make everything line up nicely; I'm not sure how portable
it is, but it works here.
None at all. There is *no* hardware support for 8 bit quantities.
Thanks, that's an interesting thing to know. I tried looking at an
assembly listing to figure out how the operations are implemented, but
Cray's assembler syntax is a bit odd, and I've never taken the time to
learn it.
This would be with Cray's C compiler. I do not know whether there is gcc
support for the Cray. It would be a bit foolish to look for gcc on the
Cray as it certainly does not support vectorisation.
Right, but not everything that runs on a Cray uses vectorization.
There's an entire Unix-like operating system with all the usual
utilities. But porting gcc to Cray vector machines, even without
vector support, apparently is more work than anyone has been willing
to do. (Since I'm not willing or able to do the work myself, I'm
certainly not criticizing anyone else for not doing it.)
There's also no gcc for the Cray T3E, even though it uses Alpha CPUs
rather than one of Cray's custom vector thingies.
Interesting though all this stuff is (at least to me), the only really
topical point being made is that some C implementations are weirder
than most poeple would expect. If you stick to what's guaranteed by
the standard, you can write code that's portable even to exotic
implementations. If you make implicit assumptions that happen to be
correct for every machine you've ever used (like "incrementing the
integer representation of a pointer makes it point to the next byte in
memory"), you can get into trouble.
(Arguably, it would actually have made a lot more sense for Cray's C
implementation to have CHAR_BIT==64, but that would have broken a lot
more existing software than the funny byte pointers did. I doubt that
the Unix port would have been as successful.)