/*
 * Licensed Materials - Property of IBM
 * IBM Developer Kit, Java(TM) Tech Edition
 * (c) Copyright IBM Corp. 1996, 1999. All rights reserved.
 *
 * US Government Users Restricted Rights - Use,
 * duplication or disclosure restricted by GSA
 * ADP Schedule Contract with IBM Corp.
 */
/*
 * @(#)typedefs.h       1.15 96/12/22
 *
 * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
 *
 */

#ifndef _TYPEDEFS_H_
#define _TYPEDEFS_H_

#include "typedefs_md.h"        /* for int64_t */

/*
 * Macros to deal with the JavaVM's stack alignment. Many machines
 * require doublewords to be double aligned.  This union is used by
 * code in math.h as a more portable way do alingnment on machines
 * that require it.  This union and the macros that use it came from
 * Netscape.
 */

typedef union Java8Str {
    int32_t x[2];
    double_t d;                                                 /*ibm.1229*/
    int64_t l;
    void *p;
} Java8;


#ifdef HAVE_ALIGNED_LONGLONGS
#define GET_INT64(_t,_addr) ( ((_t).x[0] = ((int32_t*)(_addr))[0]), \
                              ((_t).x[1] = ((int32_t*)(_addr))[1]), \
                              (_t).l )
#define SET_INT64(_t, _addr, _v) ( (_t).l = (_v),                    \
                                   ((int32_t*)(_addr))[0] = (_t).x[0], \
                                   ((int32_t*)(_addr))[1] = (_t).x[1] )
#if defined(IBM_MIXED_MODE) && !defined(IBM_MVS)                    /*ibm.6205*/
#define SET_INT64_REVERSE(_t, _addr, _v) ( (_t).l = (_v),               \
                                   ((int32_t*)(_addr))[0] = (_t).x[1],  \
                                   ((int32_t*)(_addr))[1] = (_t).x[0] )
#endif /* +IBM_MIXED_MODE */                                        /*ibm.6205*/
#else
#define GET_INT64(_t,_addr) (*(int64_t*)(_addr))
#define SET_INT64(_t, _addr, _v) (*(int64_t*)(_addr) = (_v))
#if defined(IBM_MIXED_MODE) && !defined(IBM_MVS)                    /*ibm.6205*/
#define SET_INT64_REVERSE(_t, _addr, _v) ( (_t).l = (_v),               \
                                   ((int32_t*)(_addr))[0] = (_t).x[1],  \
                                   ((int32_t*)(_addr))[1] = (_t).x[0] )
#endif /* +IBM_MIXED_MODE */                                        /*ibm.6205*/
#endif

/* If double's must be aligned on doubleword boundaries then define this */
#ifdef HAVE_ALIGNED_DOUBLES
#define GET_DOUBLE(_t,_addr) ( ((_t).x[0] = ((int32_t*)(_addr))[0]), \
                               ((_t).x[1] = ((int32_t*)(_addr))[1]), \
                               (_t).d )
#define SET_DOUBLE(_t, _addr, _v) ( (_t).d = (_v),                    \
                                    ((int32_t*)(_addr))[0] = (_t).x[0], \
                                    ((int32_t*)(_addr))[1] = (_t).x[1] )
#if defined(IBM_MIXED_MODE) && !defined(IBM_MVS)                    /*ibm.6205*/
#define SET_DOUBLE_REVERSE(_t, _addr, _v) ( (_t).d = (_v),              \
                                    ((int32_t*)(_addr))[0] = (_t).x[1], \
                                    ((int32_t*)(_addr))[1] = (_t).x[0] )
#endif /* +IBM_MIXED_MODE */                                        /*ibm.6205*/
#else
#define GET_DOUBLE(_t,_addr) (*(double_t*)(_addr))                      /*ibm.1229*/
#define SET_DOUBLE(_t, _addr, _v) (*(double_t*)(_addr) = (_v))          /*ibm.1229*/
#if defined(IBM_MIXED_MODE) && !defined(IBM_MVS)                    /*ibm.6205*/
#define SET_DOUBLE_REVERSE(_t, _addr, _v) ( (_t).d = (_v),              \
                                    ((int32_t*)(_addr))[0] = (_t).x[1], \
                                    ((int32_t*)(_addr))[1] = (_t).x[0] )
#endif /* +IBM_MIXED_MODE */                                        /*ibm.6205*/
#endif

/* If pointers are 64bits then define this */
#ifdef HAVE_64BIT_POINTERS
#define GET_HANDLE(_t,_addr) ( ((_t).x[0] = ((int32_t*)(_addr))[0]), \
                               ((_t).x[1] = ((int32_t*)(_addr))[1]), \
                               (_t).p )
#define SET_HANDLE(_t, _addr, _v) ( (_t).p = (_v),                    \
                                    ((int32_t*)(_addr))[0] = (_t).x[0], \
                                    ((int32_t*)(_addr))[1] = (_t).x[1] )
#else
#define GET_HANDLE(_t,_addr) (*(JHandle*)(_addr))
#define SET_HANDLE(_t, _addr, _v) (*(JHandle*)(_addr) = (_v))
#endif


#endif  /* !_TYPEDEFS_H_ */
