[comp.arch] 64 bit C

marc@marc.watson.ibm.com (Marc Auslander) (02/14/91)

Making (C) programs 32/64 portable is one of the major costs of 64 bit
architectures.  The only freedom we have is in deciding what int means
for 64 bit C.  (Of course, we could have half the world do it each
way, but lets not contemplate that!)

If sizeof int == 8 in 64 bit systems, then the pseudo-invariant sizeof int ==
sizeof long == sizeof void* is retained.  

If sizeof int == 4, then the pseudo-invariant sizeof int == 4 is
retained.  (To be less tautological, character/int overlays continue
to work).

It seems hopeless to make sizeof long == 4.

The question is - which breaks more code.

I believe the right answer is the first - and the introduction of new
types which have the same size in all implementations so we can
declare our external protocols in a fixed way.

Anyone out there for sizeof int == 4?



--


Marc Auslander       <marc@ibm.com>

sef@kithrup.COM (Sean Eric Fagan) (02/17/91)

In article <MARC.91Feb14085851@marc.watson.ibm.com> marc@marc.watson.ibm.com (Marc Auslander) writes:
>Anyone out there for sizeof int == 4?

Me.  Rather, I should say that I would like it to be settable via a
command-line switch.  (It would be nice if you could go to 32-bit pointers
also; although I have not been able to confirm this, and none of the
newspaper articles say so directly, it *seems* as if the R4000 will be able
to run R3000 code.)

-- 
Sean Eric Fagan  | "I made the universe, but please don't blame me for it;
sef@kithrup.COM  |  I had a bellyache at the time."
-----------------+           -- The Turtle (Stephen King, _It_)
Any opinions expressed are my own, and generally unpopular with others.

eru@tnvsu1.tele.nokia.fi (Erkki Ruohtula) (02/18/91)

In article <MARC.91Feb14085851@marc.watson.ibm.com> marc@marc.watson.ibm.com (Marc Auslander) writes:
>If sizeof int == 8 in 64 bit systems, then the pseudo-invariant sizeof int ==
>sizeof long == sizeof void* is retained.  

Any code that relies on such an "invariant" deserves to die.

>If sizeof int == 4, then the pseudo-invariant sizeof int == 4 is
>retained.  (To be less tautological, character/int overlays continue
>to work).
>
>It seems hopeless to make sizeof long == 4.
>
>The question is - which breaks more code.
>
>I believe the right answer is the first - and the introduction of new
>types which have the same size in all implementations so we can
>declare our external protocols in a fixed way.

Adding a new type would be wastefull. There already is 4 kinds (or
rather families with a signed and unsigned member) of integers, and a
64-bit machine finally lets C to make good use of them all:

sizeof(char) = 1, sizeof(short) = 2, sizeof(int) = 4, sizeof(long) = 8

Naturally the ANSI size_t would be defined "unsigned long". I think
you are greatly overestimating the difficulty of using C where ints
and pointers are of different sizes. In the 8088/80286 "large memory
model" C (which probably is the horror story that opponents of mixed
sizes are remembering) the problem is not really the difference
between the sizes of int and pointer, but the fact that the pointer
is not coded linearly, the small size of the segment that can be
addressed linearly with an array access or pointer addition (64k),
and the small size of int (16 bits), which runs out in many
applications. The 32-bit int/64-bit pointer would be much, much
easier.

Using ANSI C with prototypes for all functions helps immensely in
getting ints and pointers straight. I have successfully ported some
32-bit code to 8088 large memory model by making prototypes with
automated tools and heeding what the compiler (or lint) says with
maximal warnings. If prototypes are used right from the start and a
checking compiler (or lint) is kept happy, this kind of operation will
not be necessary at all when going from 32 to 64 bits.

>Anyone out there for sizeof int == 4?

Yes!
--
Erkki Ruohtula     / Nokia Telecommunications
eru@tele.nokia.fi / P.O. Box 33 SF-02601 Espoo, Finland
Disclaimer: These are my private opinions and do not represent the position
            of Nokia Telecommunications.

avg@hq.demos.su (Vadim Antonov) (02/19/91)

In <MARC.91Feb14085851@marc.watson.ibm.com> marc@marc.watson.ibm.com (Marc Auslander) writes:

>Anyone out there for sizeof int == 4?

Novosibirsk branch of IPMCE together with DEMOS and CC of Kurchatov
Institute of Atomic Energy has ported Unix v7 to 64bit machine
(Elbrus-B, a successor of BESM-6).

This machine occupies two cabinets: one contains 64Mb of RAM, the second
contains CPU and programmable I/O channels. Benchmarks actually yield
figures about 5-7 MFLOPS.

Integers are represented as unnormalized floating numbers - it significantly
simplifyes ALU and reduces instructions set. Like BESM-6 this machine have
no microprogrammed controlling device - i.e. all instructions are implemented
in hardware. Usually one word contains a pair of instructions; instructions
set includes "even" and "odd" jumps.

The current C implementations (one compiler was designed by Dmitry Volodin,
dvv@hq.demos.su and other - by Sergey Vakulenko vak@kiae.su) support the
following scheme of types:

char    - packed by 8 bytes per word

char *  - [ # of byte ] [  unused  ] [ address of word ]
	    3 bits                        27 bits

int==long     - [ 0000000 ] [sign] [  value   ]
==short           11 bits      1       52 bits
		  (log)

unsigned int==  [ 64 bits of unsigned value ]
unsigned long

float==double   [ log ] [sign] [normalized value]
		   11     1          52

To have a relly short short is quite unreasonable on word-oriented
machine, dereferncing of char* tooks only three operations.

The port was done by a relatively small team (about 10 programmers)
during a couple of years. Now they're working for porting 4.3 BSD.
It can be said for sure that careful design of C-compiler practically
eliminates need to make numerous changes in utilites.

I was not directly involved in this project, so details probably are not
precise, please ask Dmitry or Sergey for additional information.

Vadim Antonov
DEMOS, Moscow, USSR

keith@MIPS.com (Keith Garrett) (02/22/91)

In article <1991Feb17.044608.4268@kithrup.COM> sef@kithrup.COM (Sean Eric Fagan) writes:
>In article <MARC.91Feb14085851@marc.watson.ibm.com> marc@marc.watson.ibm.com (Marc Auslander) writes:
>>Anyone out there for sizeof int == 4?
>
>Me.  Rather, I should say that I would like it to be settable via a
>command-line switch.  (It would be nice if you could go to 32-bit pointers
>also; although I have not been able to confirm this, and none of the
>newspaper articles say so directly, it *seems* as if the R4000 will be able
>to run R3000 code.)

the r4000 supports 32-bit pointers, and it is expected that the majority of
applications will continue to use them. as has be discussed previously, there
also exists an important class of problems that will use 64-bit pointers,
or some kludge to emulate 64-bit pointers. it is also expected that OS's will
move to 64-bit to support these applications.
-- 
Keith Garrett        "This is *MY* opinion, OBVIOUSLY"
      Mips Computer Systems, 930 Arques Ave, Sunnyvale, Ca. 94086
      (408) 524-8110     keith@mips.com  or  {ames,decwrl,prls}!mips!keith