1995-11-06 05:09:04 -08:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-11-06 05:09:04 -08:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../LICENSE. */
|
1995-11-06 05:09:04 -08:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include "alloc.h"
|
2005-03-24 09:20:54 -08:00
|
|
|
#include "config.h"
|
2000-02-10 06:04:59 -08:00
|
|
|
#include "custom.h"
|
|
|
|
#include "intext.h"
|
2000-04-20 09:20:59 -07:00
|
|
|
#include "fail.h"
|
1995-11-06 05:09:04 -08:00
|
|
|
#include "memory.h"
|
1998-10-07 12:01:42 -07:00
|
|
|
#include "mlvalues.h"
|
1995-11-06 05:09:04 -08:00
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
#include "bng.h"
|
|
|
|
#include "nat.h"
|
1998-10-07 12:01:42 -07:00
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
/* Stub code for the Nat module. */
|
1995-11-06 05:09:04 -08:00
|
|
|
|
2005-09-22 07:21:50 -07:00
|
|
|
static void serialize_nat(value, uintnat *, uintnat *);
|
|
|
|
static uintnat deserialize_nat(void * dst);
|
2000-02-10 06:04:59 -08:00
|
|
|
|
|
|
|
static struct custom_operations nat_operations = {
|
|
|
|
"_nat",
|
|
|
|
custom_finalize_default,
|
|
|
|
custom_compare_default,
|
|
|
|
custom_hash_default,
|
|
|
|
serialize_nat,
|
|
|
|
deserialize_nat
|
|
|
|
};
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value initialize_nat(value unit)
|
2000-02-10 06:04:59 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
bng_init();
|
2000-02-10 06:04:59 -08:00
|
|
|
register_custom_operations(&nat_operations);
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value create_nat(value size)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
mlsize_t sz = Long_val(size);
|
|
|
|
|
2000-02-10 06:04:59 -08:00
|
|
|
return alloc_custom(&nat_operations, sz * sizeof(value), 0, 1);
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value length_nat(value nat)
|
2000-02-10 06:04:59 -08:00
|
|
|
{
|
|
|
|
return Val_long(Wosize_val(nat) - 1);
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value set_to_zero_nat(value nat, value ofs, value len)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
bng_zero(&Digit_val(nat, Long_val(ofs)), Long_val(len));
|
1995-11-06 05:09:04 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
CAMLprim value blit_nat(value nat1, value ofs1,
|
|
|
|
value nat2, value ofs2,
|
|
|
|
value len)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
bng_assign(&Digit_val(nat1, Long_val(ofs1)),
|
|
|
|
&Digit_val(nat2, Long_val(ofs2)),
|
|
|
|
Long_val(len));
|
1995-11-06 05:09:04 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value set_digit_nat(value nat, value ofs, value digit)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
Digit_val(nat, Long_val(ofs)) = Long_val(digit);
|
1995-11-06 05:09:04 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value nth_digit_nat(value nat, value ofs)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
return Val_long(Digit_val(nat, Long_val(ofs)));
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2008-01-04 05:15:52 -08:00
|
|
|
CAMLprim value set_digit_nat_native(value nat, value ofs, value digit)
|
|
|
|
{
|
|
|
|
Digit_val(nat, Long_val(ofs)) = Nativeint_val(digit);
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
CAMLprim value nth_digit_nat_native(value nat, value ofs)
|
|
|
|
{
|
|
|
|
return caml_copy_nativeint(Digit_val(nat, Long_val(ofs)));
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value num_digits_nat(value nat, value ofs, value len)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
return Val_long(bng_num_digits(&Digit_val(nat, Long_val(ofs)),
|
|
|
|
Long_val(len)));
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value num_leading_zero_bits_in_digit(value nat, value ofs)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return
|
2003-10-24 02:18:01 -07:00
|
|
|
Val_long(bng_leading_zero_bits(Digit_val(nat, Long_val(ofs))));
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value is_digit_int(value nat, value ofs)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
return Val_bool(Digit_val(nat, Long_val(ofs)) <= Max_long);
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value is_digit_zero(value nat, value ofs)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
return Val_bool(Digit_val(nat, Long_val(ofs)) == 0);
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value is_digit_normalized(value nat, value ofs)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
return
|
2008-01-11 08:13:18 -08:00
|
|
|
Val_bool(Digit_val(nat, Long_val(ofs)) & ((bngdigit)1 << (BNG_BITS_PER_DIGIT-1)));
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value is_digit_odd(value nat, value ofs)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
return Val_bool(Digit_val(nat, Long_val(ofs)) & 1);
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value incr_nat(value nat, value ofs, value len, value carry_in)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
return Val_long(bng_add_carry(&Digit_val(nat, Long_val(ofs)),
|
|
|
|
Long_val(len), Long_val(carry_in)));
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
value add_nat_native(value nat1, value ofs1, value len1,
|
|
|
|
value nat2, value ofs2, value len2, value carry_in)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
return Val_long(bng_add(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1),
|
|
|
|
&Digit_val(nat2, Long_val(ofs2)), Long_val(len2),
|
|
|
|
Long_val(carry_in)));
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value add_nat(value *argv, int argn)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return add_nat_native(argv[0], argv[1], argv[2], argv[3],
|
|
|
|
argv[4], argv[5], argv[6]);
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value complement_nat(value nat, value ofs, value len)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
bng_complement(&Digit_val(nat, Long_val(ofs)), Long_val(len));
|
1995-11-06 05:09:04 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value decr_nat(value nat, value ofs, value len, value carry_in)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
return Val_long(1 ^ bng_sub_carry(&Digit_val(nat, Long_val(ofs)),
|
|
|
|
Long_val(len), 1 ^ Long_val(carry_in)));
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
value sub_nat_native(value nat1, value ofs1, value len1,
|
|
|
|
value nat2, value ofs2, value len2, value carry_in)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
return Val_long(1 ^ bng_sub(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1),
|
|
|
|
&Digit_val(nat2, Long_val(ofs2)), Long_val(len2),
|
|
|
|
1 ^ Long_val(carry_in)));
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value sub_nat(value *argv, int argn)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return sub_nat_native(argv[0], argv[1], argv[2], argv[3],
|
|
|
|
argv[4], argv[5], argv[6]);
|
|
|
|
}
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
value mult_digit_nat_native(value nat1, value ofs1, value len1,
|
|
|
|
value nat2, value ofs2, value len2,
|
|
|
|
value nat3, value ofs3)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return
|
2003-10-24 02:18:01 -07:00
|
|
|
Val_long(bng_mult_add_digit(
|
|
|
|
&Digit_val(nat1, Long_val(ofs1)), Long_val(len1),
|
|
|
|
&Digit_val(nat2, Long_val(ofs2)), Long_val(len2),
|
|
|
|
Digit_val(nat3, Long_val(ofs3))));
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value mult_digit_nat(value *argv, int argn)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return mult_digit_nat_native(argv[0], argv[1], argv[2], argv[3],
|
|
|
|
argv[4], argv[5], argv[6], argv[7]);
|
|
|
|
}
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
value mult_nat_native(value nat1, value ofs1, value len1,
|
|
|
|
value nat2, value ofs2, value len2,
|
|
|
|
value nat3, value ofs3, value len3)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return
|
2003-10-24 02:18:01 -07:00
|
|
|
Val_long(bng_mult_add(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1),
|
|
|
|
&Digit_val(nat2, Long_val(ofs2)), Long_val(len2),
|
|
|
|
&Digit_val(nat3, Long_val(ofs3)), Long_val(len3)));
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value mult_nat(value *argv, int argn)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return mult_nat_native(argv[0], argv[1], argv[2], argv[3],
|
|
|
|
argv[4], argv[5], argv[6], argv[7], argv[8]);
|
|
|
|
}
|
|
|
|
|
2003-11-06 23:59:10 -08:00
|
|
|
value square_nat_native(value nat1, value ofs1, value len1,
|
|
|
|
value nat2, value ofs2, value len2)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
Val_long(bng_square_add(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1),
|
|
|
|
&Digit_val(nat2, Long_val(ofs2)), Long_val(len2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
CAMLprim value square_nat(value *argv, int argn)
|
|
|
|
{
|
|
|
|
return square_nat_native(argv[0], argv[1], argv[2],
|
|
|
|
argv[3], argv[4], argv[5]);
|
|
|
|
}
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
value shift_left_nat_native(value nat1, value ofs1, value len1,
|
|
|
|
value nat2, value ofs2, value nbits)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
Digit_val(nat2, Long_val(ofs2)) =
|
|
|
|
bng_shift_left(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1),
|
|
|
|
Long_val(nbits));
|
1995-11-06 05:09:04 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value shift_left_nat(value *argv, int argn)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return shift_left_nat_native(argv[0], argv[1], argv[2],
|
|
|
|
argv[3], argv[4], argv[5]);
|
|
|
|
}
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
value div_digit_nat_native(value natq, value ofsq,
|
|
|
|
value natr, value ofsr,
|
|
|
|
value nat1, value ofs1, value len1,
|
|
|
|
value nat2, value ofs2)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
Digit_val(natr, Long_val(ofsr)) =
|
|
|
|
bng_div_rem_digit(&Digit_val(natq, Long_val(ofsq)),
|
|
|
|
&Digit_val(nat1, Long_val(ofs1)), Long_val(len1),
|
|
|
|
Digit_val(nat2, Long_val(ofs2)));
|
1995-11-06 05:09:04 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value div_digit_nat(value *argv, int argn)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return div_digit_nat_native(argv[0], argv[1], argv[2], argv[3],
|
|
|
|
argv[4], argv[5], argv[6], argv[7], argv[8]);
|
|
|
|
}
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
value div_nat_native(value nat1, value ofs1, value len1,
|
|
|
|
value nat2, value ofs2, value len2)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
bng_div_rem(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1),
|
|
|
|
&Digit_val(nat2, Long_val(ofs2)), Long_val(len2));
|
1995-11-06 05:09:04 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value div_nat(value *argv, int argn)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return div_nat_native(argv[0], argv[1], argv[2],
|
|
|
|
argv[3], argv[4], argv[5]);
|
|
|
|
}
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
value shift_right_nat_native(value nat1, value ofs1, value len1,
|
|
|
|
value nat2, value ofs2, value nbits)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
Digit_val(nat2, Long_val(ofs2)) =
|
|
|
|
bng_shift_right(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1),
|
|
|
|
Long_val(nbits));
|
1995-11-06 05:09:04 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value shift_right_nat(value *argv, int argn)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return shift_right_nat_native(argv[0], argv[1], argv[2],
|
2003-10-24 02:18:01 -07:00
|
|
|
argv[3], argv[4], argv[5]);
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
CAMLprim value compare_digits_nat(value nat1, value ofs1,
|
|
|
|
value nat2, value ofs2)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
bngdigit d1 = Digit_val(nat1, Long_val(ofs1));
|
|
|
|
bngdigit d2 = Digit_val(nat2, Long_val(ofs2));
|
|
|
|
if (d1 > d2) return Val_int(1);
|
|
|
|
if (d1 < d2) return Val_int(-1);
|
|
|
|
return Val_int(0);
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2003-10-24 02:18:01 -07:00
|
|
|
value compare_nat_native(value nat1, value ofs1, value len1,
|
|
|
|
value nat2, value ofs2, value len2)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
return
|
|
|
|
Val_int(bng_compare(&Digit_val(nat1, Long_val(ofs1)), Long_val(len1),
|
|
|
|
&Digit_val(nat2, Long_val(ofs2)), Long_val(len2)));
|
1995-11-06 05:09:04 -08:00
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value compare_nat(value *argv, int argn)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
|
|
|
return compare_nat_native(argv[0], argv[1], argv[2],
|
|
|
|
argv[3], argv[4], argv[5]);
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value land_digit_nat(value nat1, value ofs1, value nat2, value ofs2)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
Digit_val(nat1, Long_val(ofs1)) &= Digit_val(nat2, Long_val(ofs2));
|
1995-11-06 05:09:04 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value lor_digit_nat(value nat1, value ofs1, value nat2, value ofs2)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
Digit_val(nat1, Long_val(ofs1)) |= Digit_val(nat2, Long_val(ofs2));
|
1995-11-06 05:09:04 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value lxor_digit_nat(value nat1, value ofs1, value nat2, value ofs2)
|
1995-11-06 05:09:04 -08:00
|
|
|
{
|
2003-10-24 02:18:01 -07:00
|
|
|
Digit_val(nat1, Long_val(ofs1)) ^= Digit_val(nat2, Long_val(ofs2));
|
1995-11-06 05:09:04 -08:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
2000-02-10 06:04:59 -08:00
|
|
|
/* The wire format for a nat is:
|
|
|
|
- 32-bit word: number of 32-bit words in nat
|
|
|
|
- N 32-bit words (big-endian format)
|
|
|
|
For little-endian platforms, the memory layout between 32-bit and 64-bit
|
|
|
|
machines is identical, so we can write the nat using serialize_block_4.
|
|
|
|
For big-endian 64-bit platforms, we need to swap the two 32-bit halves
|
|
|
|
of 64-bit words to obtain the correct behavior. */
|
|
|
|
|
|
|
|
static void serialize_nat(value nat,
|
2005-09-22 07:21:50 -07:00
|
|
|
uintnat * wsize_32,
|
|
|
|
uintnat * wsize_64)
|
2000-02-10 06:04:59 -08:00
|
|
|
{
|
|
|
|
mlsize_t len = Wosize_val(nat) - 1;
|
|
|
|
|
|
|
|
#ifdef ARCH_SIXTYFOUR
|
|
|
|
len = len * 2; /* two 32-bit words per 64-bit digit */
|
2008-01-11 08:13:18 -08:00
|
|
|
if (len >= ((mlsize_t)1 << 32))
|
2000-02-10 06:04:59 -08:00
|
|
|
failwith("output_value: nat too big");
|
|
|
|
#endif
|
|
|
|
serialize_int_4((int32) len);
|
|
|
|
#if defined(ARCH_SIXTYFOUR) && defined(ARCH_BIG_ENDIAN)
|
|
|
|
{ int32 * p;
|
|
|
|
mlsize_t i;
|
|
|
|
for (i = len, p = Data_custom_val(nat); i > 0; i -= 2, p += 2) {
|
|
|
|
serialize_int_4(p[1]); /* low 32 bits of 64-bit digit */
|
|
|
|
serialize_int_4(p[0]); /* high 32 bits of 64-bit digit */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
serialize_block_4(Data_custom_val(nat), len);
|
|
|
|
#endif
|
|
|
|
*wsize_32 = len * 4;
|
|
|
|
*wsize_64 = len * 4;
|
|
|
|
}
|
|
|
|
|
2005-09-22 07:21:50 -07:00
|
|
|
static uintnat deserialize_nat(void * dst)
|
2000-02-10 06:04:59 -08:00
|
|
|
{
|
|
|
|
mlsize_t len;
|
|
|
|
|
|
|
|
len = deserialize_uint_4();
|
|
|
|
#if defined(ARCH_SIXTYFOUR) && defined(ARCH_BIG_ENDIAN)
|
|
|
|
{ uint32 * p;
|
|
|
|
mlsize_t i;
|
|
|
|
for (i = len, p = dst; i > 0; i -= 2, p += 2) {
|
|
|
|
p[1] = deserialize_uint_4(); /* low 32 bits of 64-bit digit */
|
|
|
|
p[0] = deserialize_uint_4(); /* high 32 bits of 64-bit digit */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
deserialize_block_4(dst, len);
|
|
|
|
#endif
|
|
|
|
return len * 4;
|
|
|
|
}
|
|
|
|
|