Contents Previous Next

Chapter   9

64-bit Support


We do not require your compiler to support 64-bit arithmetic. However, having a 64-bit capable compiler makes porting much easier.

9.1 Setup

If your compiler supports 64-bit integers, you should define the types long64 and ulong64 in one of your platform-dependent include files. The meaning of these two types is shown below in

TABLE 7  –  64-bit types
Type
Description
long64
A signed 64-bit integer.
ulong64
An unsigned 64-bit integer.

Table 7.

You should consider setting one of the two compiler constants BIG_ENDIAN or LITTLE_ENDIAN to a non-zero value. This is only required if you are using the Java Code Compactor, but KVM can produce better code if it knows the endianness of your machine.

For example, using the Gnu C compiler or the Solaris C compiler, you would write:

    typedef long long long64; 
    typedef unsigned long long ulong64; 

Using Microsoft Visual C/C++, you would write:

    typedef __int64 long64; 
    typedef unsigned __int64 ulong64; 

If Your compiler does not support 64-bit integers,1 you must set the preprocessor constant COMPILER_SUPPORTS_LONG to zero. You must define exactly one of BIG_ENDIAN or LITTLE_ENDIAN2 to have a non-zero value.

The types long64 and ulong64 are defined to be a structure consisting of two fields, each an unsigned long word, named high and low. The high field is first if your machine is big endian; the low field is first if your machine is little endian.

You must define the functions shown in Table 8. If your platform supports floating point, you must also define the functions shown in Table 9.

Any of these functions can be implemented as a macro instead.

TABLE 8  –  Implementing longs
Function or Constant
Java equivalent
long64 ll_mul(long64 a, long64 b);
a * b
long64 ll_div(long64 a, long64 b);
a / b
long64 ll_rem(long64 a, long64 b);
a % b
long64 ll_shl(long64 a, int b);
a << b
long64 ll_shr(long64 a, int b);
a >> b
long64 ll_ushr(long64 a, int b);
a >>> b

TABLE 9  –  Implementing both longs and floats
Function or Constant
Java equivalent
long64   float2ll(float f);
(long)f
long64   double2ll(double d);
(long)d
float    ll2float(long64 a);
(float)a
double   ll2double(long64 a);
(double)a

9.2 Alignment issues

When an object of Java type long or double is on the Java stack or in the constant pool, its address will be a multiple of 4.

Some hardware platforms (such as SPARC) require that 64-bit types be aligned so that their address is a multiple of 8.

If your platform requires that 64-bit integers be aligned on 8-byte boundaries, set

    #define NEED_LONG_ALIGNMENT 1 

If your platform requires double-precision floating point numbers be aligned on 8-byte boundaries, set

    #define NEED_DOUBLE_ALIGNMENT 1 

The compiler can generates better code when these values are 0.

1Or your code must be strictly ANSI C standard.
2See Jonathan Swift, Gulliver’s Travels, Part I: A Voyage to Lilliput, for more information on the big-endian, little-endian controversy.

 


Contents Previous Next KVM Porting Guide
, CLDC 1.1