Probleme d'alignement des entiers 64 bits sur certaines architectures (MIPS/Irix en particulier)

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2941 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 2000-03-10 17:36:31 +00:00
parent 3410c07271
commit 484e2ce778
5 changed files with 111 additions and 2 deletions

View File

@ -245,6 +245,28 @@ value int32_of_string(value s) /* ML */
#ifdef ARCH_INT64_TYPE
#ifdef ARCH_ALIGN_INT64
int64 Int64_val(value v)
{
union { int32 i[2]; int64 j; } buffer;
buffer.i[0] = ((int32 *) Data_custom_val(v))[0];
buffer.i[1] = ((int32 *) Data_custom_val(v))[1];
return buffer.j;
}
void Store_int64_val(value v, int64 n)
{
union { int32 i[2]; int64 j; } buffer;
buffer.j = n;
((int32 *) Data_custom_val(v))[0] = buffer.i[0];
((int32 *) Data_custom_val(v))[1] = buffer.i[1];
}
#endif
#endif
static int int64_compare(value v1, value v2)
{
int64 i1 = Int64_val(v1);

View File

@ -224,8 +224,14 @@ struct custom_operations; /* defined in [custom.h] */
/* Int32.t, Int64.t and Nativeint.t are represented as custom blocks. */
#define Int32_val(v) (*((int32 *) Data_custom_val(v)))
#define Int64_val(v) (*((int64 *) Data_custom_val(v)))
#define Nativeint_val(v) (*((long *) Data_custom_val(v)))
#ifndef ARCH_ALIGN_INT64
#define Int64_val(v) (*((int64 *) Data_custom_val(v)))
#define Store_int64_val(v,i) (*((int64 *) Data_custom_val(v)) = (i))
#else
extern int64 Int64_val(value v);
extern void Store_int64_val(value v, int64 i);
#endif
/* 3- Atoms are 0-tuples. They are statically allocated once and for all. */

View File

@ -0,0 +1,55 @@
/***********************************************************************/
/* */
/* Objective Caml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 2000 Institut National de Recherche en Informatique et */
/* en Automatique. All rights reserved. This file is distributed */
/* under the terms of the GNU Library General Public License. */
/* */
/***********************************************************************/
/* $Id$ */
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
#include "m.h"
ARCH_INT64_TYPE foo;
void access_int64(ARCH_INT64_TYPE *p)
{
foo = *p;
}
jmp_buf failure;
void sig_handler(int sig)
{
longjmp(failure, 1);
}
int main(void)
{
long n[10];
int res;
signal(SIGSEGV, sig_handler);
#ifdef SIGBUS
signal(SIGBUS, sig_handler);
#endif
if(setjmp(failure) == 0) {
access_int64((ARCH_INT64_TYPE *) n);
access_int64((ARCH_INT64_TYPE *) (n+1));
res = 0;
} else {
res = 1;
}
signal(SIGSEGV, SIG_DFL);
#ifdef SIGBUS
signal(SIGBUS, SIG_DFL);
#endif
exit(res);
}

View File

@ -63,3 +63,11 @@
values of type ARCH_INT64_TYPE. This is usually "ll" on 32-bit
platforms and "l" on 64-bit platforms.
Leave undefined if ARCH_INT64_TYPE is undefined. */
#define ARCH_ALIGN_INT64
/* Define ARCH_ALIGN_INT64 if the processor requires 64-bit integers to be
doubleword-aligned. Leave ARCH_ALIGN_INT64 undefined if the processor
supports word-aligned 64-bit integers. Leave undefined if
64-bit integers are not supported. */

20
configure vendored
View File

@ -263,14 +263,17 @@ if test $2 = 8; then
echo "#define ARCH_INT64_TYPE long" >> m.h
echo "#define ARCH_UINT64_TYPE unsigned long" >> m.h
echo '#define ARCH_INT64_PRINTF_FORMAT "l"' >> m.h
int64_supported=true
else
sh ./runtest longlong.c
case $? in
0) echo "64-bit \"long long\" integer type found."
echo "#define ARCH_INT64_TYPE long long" >> m.h
echo "#define ARCH_UINT64_TYPE unsigned long long" >> m.h
echo '#define ARCH_INT64_PRINTF_FORMAT "ll"' >> m.h;;
echo '#define ARCH_INT64_PRINTF_FORMAT "ll"' >> m.h
int64_supported=true;;
*) echo "No suitable 64-bit integer type found, Int64.t will not be supported."
int64_supported=false;;
esac
fi
@ -305,6 +308,21 @@ case $? in
echo "#define ARCH_ALIGN_DOUBLE" >> m.h;;
esac
if $int64_supported; then
sh ./runtest int64align.c
case $? in
0) echo "64-bit integers can be word-aligned."
echo "#undef ARCH_ALIGN_INT64" >> m.h;;
1) echo "64-bit integers must be doubleword-aligned."
echo "#define ARCH_ALIGN_INT64" >> m.h;;
*) echo "Something went wrong during alignment determination for 64-bit integers."
echo "I'm going to assume this architecture has alignment constraints."
echo "That's a safe bet: Objective Caml will work even if"
echo "this architecture has actually no alignment constraints."
echo "#define ARCH_ALIGN_INT64" >> m.h;;
esac
fi
# Configure the native-code compiler
arch=none