win64 fixes in runtime
parent
a5741f0c70
commit
0e6236e6f6
|
@ -37,7 +37,7 @@ M: %fixnum* generate-node ( vop -- )
|
|||
1 scratch 0 input-operand 1 input-operand MULHW
|
||||
4 1 scratch MR
|
||||
3 0 scratch MR
|
||||
"s48_long_pair_to_bignum" f compile-c-call
|
||||
"s48_fixnum_pair_to_bignum" f compile-c-call
|
||||
! now we have to shift it by three bits to remove the second
|
||||
! tag
|
||||
tag-bits neg 4 LI
|
||||
|
|
|
@ -44,7 +44,7 @@ M: %fixnum* generate-node ( vop -- )
|
|||
0 input-operand IMUL
|
||||
<label> "end" set
|
||||
"end" get JNO
|
||||
"s48_long_pair_to_bignum" f
|
||||
"s48_fixnum_pair_to_bignum" f
|
||||
1 input-operand remainder-reg 2array compile-c-call*
|
||||
! now we have to shift it by three bits to remove the second
|
||||
! tag
|
||||
|
|
|
@ -7,7 +7,7 @@ CELL to_cell(CELL x)
|
|||
case FIXNUM_TYPE:
|
||||
return untag_fixnum_fast(x);
|
||||
case BIGNUM_TYPE:
|
||||
return s48_bignum_to_long(untag_bignum_fast(x));
|
||||
return s48_bignum_to_fixnum(untag_bignum_fast(x));
|
||||
default:
|
||||
type_error(BIGNUM_TYPE,x);
|
||||
return 0;
|
||||
|
@ -24,7 +24,7 @@ F_ARRAY* to_bignum(CELL tagged)
|
|||
switch(type_of(tagged))
|
||||
{
|
||||
case FIXNUM_TYPE:
|
||||
return s48_long_to_bignum(untag_fixnum_fast(tagged));
|
||||
return s48_fixnum_to_bignum(untag_fixnum_fast(tagged));
|
||||
case BIGNUM_TYPE:
|
||||
return (F_ARRAY*)UNTAG(tagged);
|
||||
case RATIO_TYPE:
|
||||
|
|
|
@ -36,7 +36,7 @@ void primitive_bignum_not(void);
|
|||
INLINE CELL tag_integer(F_FIXNUM x)
|
||||
{
|
||||
if(x < FIXNUM_MIN || x > FIXNUM_MAX)
|
||||
return tag_bignum(s48_long_to_bignum(x));
|
||||
return tag_bignum(s48_fixnum_to_bignum(x));
|
||||
else
|
||||
return tag_fixnum(x);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ INLINE CELL tag_integer(F_FIXNUM x)
|
|||
INLINE CELL tag_cell(CELL x)
|
||||
{
|
||||
if(x > FIXNUM_MAX)
|
||||
return tag_bignum(s48_ulong_to_bignum(x));
|
||||
return tag_bignum(s48_cell_to_bignum(x));
|
||||
else
|
||||
return tag_fixnum(x);
|
||||
}
|
||||
|
|
|
@ -3,28 +3,33 @@
|
|||
|
||||
#include "platform.h"
|
||||
|
||||
#define FIXNUM_MAX (LONG_MAX >> TAG_BITS)
|
||||
#define FIXNUM_MIN (LONG_MIN >> TAG_BITS)
|
||||
#ifdef _WIN64
|
||||
typedef long long F_FIXNUM;
|
||||
typedef unsigned long long CELL;
|
||||
#else
|
||||
typedef long F_FIXNUM;
|
||||
typedef unsigned long CELL;
|
||||
#endif
|
||||
|
||||
#define F_FIXNUM long int /* unboxed */
|
||||
#define CELLS ((signed)sizeof(CELL))
|
||||
|
||||
#define WORD_SIZE (CELLS*8)
|
||||
#define HALF_WORD_SIZE (CELLS*4)
|
||||
#define HALF_WORD_MASK (((unsigned long)1<<HALF_WORD_SIZE)-1)
|
||||
|
||||
#define FIXNUM_MAX ((1 << (WORD_SIZE - TAG_BITS - 1)) - 1)
|
||||
#define FIXNUM_MIN (-(1 << (WORD_SIZE - TAG_BITS - 1)))
|
||||
|
||||
/* must always be 16 bits */
|
||||
#define CHARS ((signed)sizeof(u16))
|
||||
|
||||
typedef unsigned long int CELL;
|
||||
#define CELLS ((signed)sizeof(CELL))
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned long long u64;
|
||||
typedef signed char s8;
|
||||
typedef signed short s16;
|
||||
typedef signed int s32;
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned long long u64;
|
||||
typedef signed char s8;
|
||||
typedef signed short s16;
|
||||
typedef signed int s32;
|
||||
typedef signed long long s64;
|
||||
|
||||
/* must always be 8 bits */
|
||||
|
|
|
@ -12,7 +12,7 @@ F_FIXNUM to_fixnum(CELL tagged)
|
|||
case FIXNUM_TYPE:
|
||||
return untag_fixnum_fast(tagged);
|
||||
case BIGNUM_TYPE:
|
||||
return (F_FIXNUM)s48_bignum_to_long((F_ARRAY*)UNTAG(tagged));
|
||||
return (F_FIXNUM)s48_bignum_to_fixnum((F_ARRAY*)UNTAG(tagged));
|
||||
case RATIO_TYPE:
|
||||
r = (F_RATIO*)UNTAG(tagged);
|
||||
x = to_bignum(r->numerator);
|
||||
|
@ -70,8 +70,8 @@ void primitive_fixnum_multiply(void)
|
|||
{
|
||||
dpush(tag_bignum(
|
||||
s48_bignum_multiply(
|
||||
s48_long_to_bignum(x),
|
||||
s48_long_to_bignum(y))));
|
||||
s48_fixnum_to_bignum(x),
|
||||
s48_fixnum_to_bignum(y))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ void primitive_fixnum_shift(void)
|
|||
}
|
||||
|
||||
dpush(tag_bignum(s48_bignum_arithmetic_shift(
|
||||
s48_long_to_bignum(x),y)));
|
||||
s48_fixnum_to_bignum(x),y)));
|
||||
}
|
||||
|
||||
void primitive_fixnum_less(void)
|
||||
|
|
|
@ -133,7 +133,7 @@ void primitive_set_integer_slot(void)
|
|||
|
||||
void primitive_address(void)
|
||||
{
|
||||
drepl(tag_bignum(s48_ulong_to_bignum(dpeek())));
|
||||
drepl(tag_bignum(s48_cell_to_bignum(dpeek())));
|
||||
}
|
||||
|
||||
void primitive_size(void)
|
||||
|
|
|
@ -37,14 +37,14 @@
|
|||
|
||||
#if defined(WIN32)
|
||||
#define DLLEXPORT __declspec(dllexport)
|
||||
#define SETJMP setjmp
|
||||
#define LONGJMP longjmp
|
||||
#define JMP_BUF jmp_buf
|
||||
#define SETJMP setjmp
|
||||
#define LONGJMP longjmp
|
||||
#define JMP_BUF jmp_buf
|
||||
#else
|
||||
#define DLLEXPORT
|
||||
#define SETJMP(jmpbuf) sigsetjmp(jmpbuf,1)
|
||||
#define LONGJMP siglongjmp
|
||||
#define JMP_BUF sigjmp_buf
|
||||
#define SETJMP(jmpbuf) sigsetjmp(jmpbuf,1)
|
||||
#define LONGJMP siglongjmp
|
||||
#define JMP_BUF sigjmp_buf
|
||||
#endif
|
||||
|
||||
#define INLINE inline static
|
||||
|
|
|
@ -69,9 +69,7 @@ INLINE void cpush(CELL top)
|
|||
INLINE void call(CELL quot)
|
||||
{
|
||||
/* tail call optimization */
|
||||
if(callframe == F)
|
||||
/* put(cs - CELLS,executing) */;
|
||||
else
|
||||
if(callframe != F)
|
||||
{
|
||||
cpush(executing);
|
||||
cpush(callframe);
|
||||
|
|
|
@ -376,6 +376,8 @@ s48_bignum_remainder(bignum_type numerator, bignum_type denominator)
|
|||
} \
|
||||
}
|
||||
|
||||
FOO_TO_BIGNUM(cell,CELL,CELL)
|
||||
FOO_TO_BIGNUM(fixnum,F_FIXNUM,CELL)
|
||||
FOO_TO_BIGNUM(long,long,unsigned long)
|
||||
FOO_TO_BIGNUM(ulong,unsigned long,unsigned long)
|
||||
FOO_TO_BIGNUM(long_long,s64,u64)
|
||||
|
@ -383,13 +385,13 @@ FOO_TO_BIGNUM(ulong_long,u64,u64)
|
|||
|
||||
/* this is inefficient; its only used for fixnum multiplication overflow so
|
||||
it probaly does not matter */
|
||||
bignum_type s48_long_pair_to_bignum(unsigned long x, long y)
|
||||
bignum_type s48_fixnum_pair_to_bignum(CELL x, F_FIXNUM y)
|
||||
{
|
||||
return s48_bignum_add(
|
||||
s48_bignum_arithmetic_shift(
|
||||
s48_long_to_bignum(y),
|
||||
s48_fixnum_to_bignum(y),
|
||||
sizeof(unsigned long) * 8),
|
||||
s48_ulong_to_bignum(x));
|
||||
s48_cell_to_bignum(x));
|
||||
}
|
||||
|
||||
#define BIGNUM_TO_FOO(name,type,utype) \
|
||||
|
@ -407,6 +409,8 @@ bignum_type s48_long_pair_to_bignum(unsigned long x, long y)
|
|||
} \
|
||||
}
|
||||
|
||||
BIGNUM_TO_FOO(cell,CELL,CELL);
|
||||
BIGNUM_TO_FOO(fixnum,F_FIXNUM,CELL);
|
||||
BIGNUM_TO_FOO(long,long,unsigned long)
|
||||
BIGNUM_TO_FOO(ulong,unsigned long,unsigned long)
|
||||
BIGNUM_TO_FOO(long_long,s64,u64)
|
||||
|
|
|
@ -65,11 +65,15 @@ s48_bignum_divide(bignum_type numerator, bignum_type denominator,
|
|||
bignum_type * quotient, bignum_type * remainder);
|
||||
bignum_type s48_bignum_quotient(bignum_type, bignum_type);
|
||||
bignum_type s48_bignum_remainder(bignum_type, bignum_type);
|
||||
DLLEXPORT bignum_type s48_fixnum_to_bignum(F_FIXNUM);
|
||||
DLLEXPORT bignum_type s48_cell_to_bignum(CELL);
|
||||
DLLEXPORT bignum_type s48_long_to_bignum(long);
|
||||
DLLEXPORT bignum_type s48_long_long_to_bignum(s64 n);
|
||||
DLLEXPORT bignum_type s48_ulong_long_to_bignum(u64 n);
|
||||
DLLEXPORT bignum_type s48_ulong_to_bignum(unsigned long);
|
||||
DLLEXPORT bignum_type s48_long_pair_to_bignum(unsigned long x, long y);
|
||||
DLLEXPORT bignum_type s48_fixnum_pair_to_bignum(CELL x, F_FIXNUM y);
|
||||
F_FIXNUM s48_bignum_to_fixnum(bignum_type);
|
||||
CELL s48_bignum_to_cell(bignum_type);
|
||||
long s48_bignum_to_long(bignum_type);
|
||||
unsigned long s48_bignum_to_ulong(bignum_type);
|
||||
s64 s48_bignum_to_long_long(bignum_type);
|
||||
|
|
|
@ -42,8 +42,8 @@ MIT in each case. */
|
|||
definition is `CHAR_BIT', which is defined in the Ansi C header
|
||||
file "limits.h". */
|
||||
|
||||
typedef long bignum_digit_type;
|
||||
typedef long bignum_length_type;
|
||||
typedef F_FIXNUM bignum_digit_type;
|
||||
typedef F_FIXNUM bignum_length_type;
|
||||
|
||||
/* BIGNUM_ALLOCATE allocates a (length + 1)-element array of
|
||||
`bignum_digit_type'; deallocation is the responsibility of the
|
||||
|
@ -74,8 +74,8 @@ typedef long bignum_length_type;
|
|||
|
||||
#define BIGNUM_DIGIT_LENGTH (((sizeof (bignum_digit_type)) * CHAR_BIT) - 2)
|
||||
#define BIGNUM_HALF_DIGIT_LENGTH (BIGNUM_DIGIT_LENGTH / 2)
|
||||
#define BIGNUM_RADIX (((unsigned long) 1) << BIGNUM_DIGIT_LENGTH)
|
||||
#define BIGNUM_RADIX_ROOT (((unsigned long) 1) << BIGNUM_HALF_DIGIT_LENGTH)
|
||||
#define BIGNUM_RADIX (((CELL) 1) << BIGNUM_DIGIT_LENGTH)
|
||||
#define BIGNUM_RADIX_ROOT (((CELL) 1) << BIGNUM_HALF_DIGIT_LENGTH)
|
||||
#define BIGNUM_DIGIT_MASK (BIGNUM_RADIX - 1)
|
||||
#define BIGNUM_HALF_DIGIT_MASK (BIGNUM_RADIX_ROOT - 1)
|
||||
|
||||
|
|
Loading…
Reference in New Issue