2005-02-20 03:18:32 +03:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; -*- */
|
|
|
|
/*
|
2006-02-13 00:03:01 +03:00
|
|
|
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
|
2005-11-05 22:57:48 +03:00
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2006-02-13 00:03:01 +03:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2006-02-13 00:03:01 +03:00
|
|
|
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
|
2005-02-20 03:18:32 +03:00
|
|
|
* University of Stuttgart. All rights reserved.
|
2006-02-13 00:03:01 +03:00
|
|
|
* Copyright (c) 2004-2006 The Regents of the University of California.
|
2005-03-24 15:43:37 +03:00
|
|
|
* All rights reserved.
|
2005-02-20 03:18:32 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
2008-04-18 00:43:56 +04:00
|
|
|
#include "opal_config.h"
|
2005-02-20 02:53:26 +03:00
|
|
|
|
2009-03-13 05:10:32 +03:00
|
|
|
#include "opal/constants.h"
|
2008-04-18 00:43:56 +04:00
|
|
|
#include "opal/util/arch.h"
|
|
|
|
|
2013-01-15 05:27:36 +04:00
|
|
|
uint32_t opal_local_arch = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
static inline int32_t opal_arch_isbigendian ( void )
|
|
|
|
{
|
|
|
|
const uint32_t value = 0x12345678;
|
|
|
|
const char *ptr = (char*)&value;
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
/* if( sizeof(int) == 8 ) x = 4; */
|
|
|
|
if( ptr[x] == 0x12) return 1; /* big endian, true */
|
|
|
|
if( ptr[x] == 0x78 ) return 0; /* little endian, false */
|
|
|
|
assert( 0 ); /* unknown architecture not little nor big endian */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we must find which representation of long double is used
|
|
|
|
* intel or sparc. Both of them represent the long doubles using a close to
|
|
|
|
* IEEE representation (seeeeeee..emmm...m) where the mantissa look like
|
|
|
|
* 1.????. For the intel representaion the 1 is explicit, and for the sparc
|
|
|
|
* the first one is implicit. If we take the number 2.0 the exponent is 1
|
|
|
|
* and the mantissa is 1.0 (the sign of course should be 0). So if we check
|
|
|
|
* for the first one in the binary representation of the number, we will
|
|
|
|
* find the bit from the exponent, so the next one should be the begining
|
|
|
|
* of the mantissa. If it's 1 then we have an intel representaion, if not
|
|
|
|
* we have a sparc one. QED
|
|
|
|
*/
|
|
|
|
static inline int32_t opal_arch_ldisintel( void )
|
2005-02-20 02:53:26 +03:00
|
|
|
{
|
2013-01-15 05:27:36 +04:00
|
|
|
long double ld = 2.0;
|
|
|
|
int i, j;
|
|
|
|
uint32_t* pui = (uint32_t*)(void*)&ld;
|
|
|
|
|
|
|
|
j = LDBL_MANT_DIG / 32;
|
|
|
|
i = (LDBL_MANT_DIG % 32) - 1;
|
|
|
|
if( opal_arch_isbigendian() ) { /* big endian */
|
|
|
|
j = (sizeof(long double) / sizeof(unsigned int)) - j;
|
|
|
|
if( i < 0 ) {
|
|
|
|
i = 31;
|
|
|
|
j = j+1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if( i < 0 ) {
|
|
|
|
i = 31;
|
|
|
|
j = j-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (pui[j] & (1 << i) ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void opal_arch_setmask ( uint32_t *var, uint32_t mask)
|
|
|
|
{
|
|
|
|
*var |= mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
int opal_arch_init(void)
|
|
|
|
{
|
|
|
|
opal_local_arch = (OPAL_ARCH_HEADERMASK | OPAL_ARCH_UNUSEDMASK);
|
2005-02-20 02:53:26 +03:00
|
|
|
|
|
|
|
/* Handle the size of long (can hold a pointer) */
|
|
|
|
if( 8 == sizeof(long) )
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LONGIS64 );
|
2005-02-20 02:53:26 +03:00
|
|
|
|
2006-03-25 05:53:41 +03:00
|
|
|
/* sizeof bool */
|
|
|
|
if (1 == sizeof(bool) ) {
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_BOOLIS8);
|
2006-03-25 05:53:41 +03:00
|
|
|
} else if (2 == sizeof(bool)) {
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_BOOLIS16);
|
2006-03-25 05:53:41 +03:00
|
|
|
} else if (4 == sizeof(bool)) {
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_BOOLIS32);
|
2006-03-25 05:53:41 +03:00
|
|
|
}
|
|
|
|
|
2013-01-15 05:27:36 +04:00
|
|
|
/* Note that fortran logical size is set later, to make
|
|
|
|
abstractions a little less painful... */
|
2006-03-25 05:53:41 +03:00
|
|
|
|
2005-02-20 02:53:26 +03:00
|
|
|
/* Initialize the information regarding the long double */
|
|
|
|
if( 12 == sizeof(long double) )
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LONGDOUBLEIS96 );
|
2005-02-20 02:53:26 +03:00
|
|
|
else if( 16 == sizeof(long double) )
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LONGDOUBLEIS128 );
|
2005-02-20 02:53:26 +03:00
|
|
|
|
|
|
|
/* Big endian or little endian ? That's the question */
|
2008-04-18 00:43:56 +04:00
|
|
|
if( opal_arch_isbigendian() )
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_ISBIGENDIAN );
|
2005-02-20 02:53:26 +03:00
|
|
|
|
|
|
|
/* What's the maximum exponent ? */
|
|
|
|
if ( LDBL_MAX_EXP == 16384 )
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDEXPSIZEIS15 );
|
2005-02-20 02:53:26 +03:00
|
|
|
|
|
|
|
/* How about the length in bits of the mantissa */
|
|
|
|
if ( LDBL_MANT_DIG == 64 )
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDMANTDIGIS64 );
|
2005-02-20 02:53:26 +03:00
|
|
|
else if ( LDBL_MANT_DIG == 105 )
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDMANTDIGIS105 );
|
2005-02-20 02:53:26 +03:00
|
|
|
else if ( LDBL_MANT_DIG == 106 )
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDMANTDIGIS106 );
|
2005-02-20 02:53:26 +03:00
|
|
|
else if ( LDBL_MANT_DIG == 107 )
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDMANTDIGIS107 );
|
2005-02-20 02:53:26 +03:00
|
|
|
else if ( LDBL_MANT_DIG == 113 )
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDMANTDIGIS113 );
|
2005-02-20 02:53:26 +03:00
|
|
|
|
|
|
|
/* Intel data representation or Sparc ? */
|
2008-04-18 00:43:56 +04:00
|
|
|
if( opal_arch_ldisintel() )
|
2013-01-15 05:27:36 +04:00
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LDISINTEL );
|
2005-02-20 02:53:26 +03:00
|
|
|
|
2008-04-18 00:43:56 +04:00
|
|
|
return OPAL_SUCCESS;
|
2005-02-20 02:53:26 +03:00
|
|
|
}
|
|
|
|
|
2008-04-18 00:43:56 +04:00
|
|
|
int32_t opal_arch_checkmask ( uint32_t *var, uint32_t mask )
|
2005-02-20 02:53:26 +03:00
|
|
|
{
|
|
|
|
unsigned int tmpvar = *var;
|
|
|
|
|
|
|
|
/* Check whether the headers are set correctly,
|
|
|
|
or whether this is an erroneous integer */
|
2008-04-18 00:43:56 +04:00
|
|
|
if( !((*var) & OPAL_ARCH_HEADERMASK) ) {
|
|
|
|
if( (*var) & OPAL_ARCH_HEADERMASK2 ) {
|
2005-02-20 02:53:26 +03:00
|
|
|
char* pcDest, *pcSrc;
|
|
|
|
/* Both ends of this integer have the wrong settings,
|
|
|
|
maybe its just the wrong endian-representation. Try
|
|
|
|
to swap it and check again. If it looks now correct,
|
|
|
|
keep this version of the variable
|
|
|
|
*/
|
|
|
|
|
|
|
|
pcDest = (char *) &tmpvar;
|
|
|
|
pcSrc = (char *) var + 3;
|
|
|
|
*pcDest++ = *pcSrc--;
|
|
|
|
*pcDest++ = *pcSrc--;
|
|
|
|
*pcDest++ = *pcSrc--;
|
|
|
|
*pcDest++ = *pcSrc--;
|
|
|
|
|
2008-04-18 00:43:56 +04:00
|
|
|
if( (tmpvar & OPAL_ARCH_HEADERMASK) && (!(tmpvar & OPAL_ARCH_HEADERMASK2)) ) {
|
2005-02-20 02:53:26 +03:00
|
|
|
*var = tmpvar;
|
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Here is the real evaluation of the bitmask */
|
|
|
|
return ( ((*var) & mask) == mask );
|
|
|
|
}
|
2013-01-15 05:27:36 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
opal_arch_set_fortran_logical_size(uint32_t size)
|
|
|
|
{
|
|
|
|
if (1 == size) {
|
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LOGICALIS8);
|
|
|
|
} else if (2 == size) {
|
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LOGICALIS16);
|
|
|
|
} else if (4 == size) {
|
|
|
|
opal_arch_setmask( &opal_local_arch, OPAL_ARCH_LOGICALIS32);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|