VM: Replace u8-64, s8-64, cell, fixnum with stdint.h equivalents
parent
7ea2150c39
commit
88d7c10d03
|
@ -300,8 +300,8 @@ bignum* factor_vm::bignum_remainder(bignum* numerator, bignum* denominator) {
|
|||
|
||||
FOO_TO_BIGNUM(cell, cell, fixnum, cell)
|
||||
FOO_TO_BIGNUM(fixnum, fixnum, fixnum, cell)
|
||||
FOO_TO_BIGNUM(long_long, s64, s64, u64)
|
||||
FOO_TO_BIGNUM(ulong_long, u64, s64, u64)
|
||||
FOO_TO_BIGNUM(long_long, int64_t, int64_t, uint64_t)
|
||||
FOO_TO_BIGNUM(ulong_long, uint64_t, int64_t, uint64_t)
|
||||
|
||||
/* cannot allocate memory */
|
||||
/* bignum_to_cell, fixnum_to_cell, long_long_to_cell, ulong_long_to_cell */
|
||||
|
@ -322,8 +322,8 @@ FOO_TO_BIGNUM(ulong_long, u64, s64, u64)
|
|||
|
||||
BIGNUM_TO_FOO(cell, cell, fixnum, cell)
|
||||
BIGNUM_TO_FOO(fixnum, fixnum, fixnum, cell)
|
||||
BIGNUM_TO_FOO(long_long, s64, s64, u64)
|
||||
BIGNUM_TO_FOO(ulong_long, u64, s64, u64)
|
||||
BIGNUM_TO_FOO(long_long, int64_t, int64_t, uint64_t)
|
||||
BIGNUM_TO_FOO(ulong_long, uint64_t, int64_t, uint64_t)
|
||||
|
||||
#define DTB_WRITE_DIGIT(factor) \
|
||||
{ \
|
||||
|
|
|
@ -51,7 +51,7 @@ typedef fixnum bignum_length_type;
|
|||
#ifdef FACTOR_64
|
||||
typedef __int128_t bignum_twodigit_type;
|
||||
#else
|
||||
typedef s64 bignum_twodigit_type;
|
||||
typedef int64_t bignum_twodigit_type;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -46,16 +46,16 @@ inline cell popcount(cell x) {
|
|||
#endif
|
||||
#else
|
||||
#ifdef FACTOR_64
|
||||
u64 k1 = 0x5555555555555555ll;
|
||||
u64 k2 = 0x3333333333333333ll;
|
||||
u64 k4 = 0x0f0f0f0f0f0f0f0fll;
|
||||
u64 kf = 0x0101010101010101ll;
|
||||
uint64_t k1 = 0x5555555555555555ll;
|
||||
uint64_t k2 = 0x3333333333333333ll;
|
||||
uint64_t k4 = 0x0f0f0f0f0f0f0f0fll;
|
||||
uint64_t kf = 0x0101010101010101ll;
|
||||
cell ks = 56;
|
||||
#else
|
||||
u32 k1 = 0x55555555;
|
||||
u32 k2 = 0x33333333;
|
||||
u32 k4 = 0xf0f0f0f;
|
||||
u32 kf = 0x1010101;
|
||||
uint32_t k1 = 0x55555555;
|
||||
uint32_t k2 = 0x33333333;
|
||||
uint32_t k4 = 0xf0f0f0f;
|
||||
uint32_t kf = 0x1010101;
|
||||
cell ks = 24;
|
||||
#endif
|
||||
|
||||
|
@ -69,7 +69,7 @@ inline cell popcount(cell x) {
|
|||
#endif
|
||||
}
|
||||
|
||||
inline bool bitmap_p(u8* bitmap, cell index) {
|
||||
inline bool bitmap_p(uint8_t* bitmap, cell index) {
|
||||
cell byte = index >> 3;
|
||||
cell bit = index & 7;
|
||||
return (bitmap[byte] & (1 << bit)) != 0;
|
||||
|
|
|
@ -40,7 +40,7 @@ void growable_byte_array::grow_bytes(cell len) {
|
|||
void growable_byte_array::append_bytes(void* elts, cell len) {
|
||||
cell old_count = count;
|
||||
grow_bytes(len);
|
||||
memcpy(&elements->data<u8>()[old_count], elts, len);
|
||||
memcpy(&elements->data<uint8_t>()[old_count], elts, len);
|
||||
}
|
||||
|
||||
/* Allocates memory */
|
||||
|
@ -53,7 +53,7 @@ void growable_byte_array::append_byte_array(cell byte_array_) {
|
|||
if (new_size >= array_capacity(elements.untagged()))
|
||||
elements = parent->reallot_array(elements.untagged(), new_size * 2);
|
||||
|
||||
memcpy(&elements->data<u8>()[count], byte_array->data<u8>(), len);
|
||||
memcpy(&elements->data<uint8_t>()[count], byte_array->data<uint8_t>(), len);
|
||||
|
||||
count += len;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ struct code_block {
|
|||
|
||||
/* GC info is stored at the end of the block */
|
||||
gc_info* block_gc_info() const {
|
||||
return (gc_info*)((u8*)this + size() - sizeof(gc_info));
|
||||
return (gc_info*)((uint8_t*)this + size() - sizeof(gc_info));
|
||||
}
|
||||
|
||||
void flush_icache() { factor::flush_icache((cell) this, size()); }
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace factor {
|
||||
|
||||
code_heap::code_heap(cell size) {
|
||||
if (size > ((u64) 1 << (sizeof(cell) * 8 - 6)))
|
||||
if (size > ((uint64_t)1 << (sizeof(cell) * 8 - 6)))
|
||||
fatal_error("Heap too large", size);
|
||||
seg = new segment(align_page(size), true);
|
||||
if (!seg)
|
||||
|
|
|
@ -50,7 +50,7 @@ void context::fix_stacks() {
|
|||
}
|
||||
|
||||
void context::scrub_stacks(gc_info* info, cell index) {
|
||||
u8* bitmap = info->gc_info_bitmap();
|
||||
uint8_t* bitmap = info->gc_info_bitmap();
|
||||
|
||||
{
|
||||
cell base = info->callsite_scrub_d(index);
|
||||
|
|
|
@ -18,22 +18,22 @@ namespace factor {
|
|||
static const fixnum xt_tail_pic_offset = 4;
|
||||
|
||||
inline static void check_call_site(cell return_address) {
|
||||
u32 insn = *(u32*)return_address;
|
||||
uint32_t insn = *(uint32_t*)return_address;
|
||||
/* Check that absolute bit is 0 */
|
||||
FACTOR_ASSERT((insn & 0x2) == 0x0);
|
||||
/* Check that instruction is branch */
|
||||
FACTOR_ASSERT((insn >> 26) == 0x12);
|
||||
}
|
||||
|
||||
static const u32 b_mask = 0x3fffffc;
|
||||
static const uint32_t b_mask = 0x3fffffc;
|
||||
|
||||
inline static void* get_call_target(cell return_address) {
|
||||
return_address -= 4;
|
||||
check_call_site(return_address);
|
||||
|
||||
u32 insn = *(u32*)return_address;
|
||||
u32 unsigned_addr = (insn & b_mask);
|
||||
s32 signed_addr = (s32)(unsigned_addr << 6) >> 6;
|
||||
uint32_t insn = *(uint32_t*)return_address;
|
||||
uint32_t unsigned_addr = (insn & b_mask);
|
||||
int32_t signed_addr = (int32_t)(unsigned_addr << 6) >> 6;
|
||||
return (void*)(signed_addr + return_address);
|
||||
}
|
||||
|
||||
|
@ -41,11 +41,11 @@ inline static void set_call_target(cell return_address, void* target) {
|
|||
return_address -= 4;
|
||||
check_call_site(return_address);
|
||||
|
||||
u32 insn = *(u32*)return_address;
|
||||
uint32_t insn = *(uint32_t*)return_address;
|
||||
|
||||
fixnum relative_address = ((cell) target - return_address);
|
||||
insn = ((insn & ~b_mask) | (relative_address & b_mask));
|
||||
*(u32*)return_address = insn;
|
||||
*(uint32_t*)return_address = insn;
|
||||
|
||||
/* Flush the cache line containing the call we just patched */
|
||||
__asm__ __volatile__("icbi 0, %0\n"
|
||||
|
@ -55,7 +55,7 @@ inline static void set_call_target(cell return_address, void* target) {
|
|||
|
||||
inline static bool tail_call_site_p(cell return_address) {
|
||||
return_address -= 4;
|
||||
u32 insn = *(u32*)return_address;
|
||||
uint32_t insn = *(uint32_t*)return_address;
|
||||
return (insn & 0x1) == 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ inline static void* get_call_target(cell return_address) {
|
|||
|
||||
inline static void set_call_target(cell return_address, void* target) {
|
||||
check_call_site(return_address);
|
||||
*(int*)(return_address - 4) = (u32)((cell) target - return_address);
|
||||
*(int*)(return_address - 4) = (uint32_t)((cell) target - return_address);
|
||||
}
|
||||
|
||||
inline static bool tail_call_site_p(cell return_address) {
|
||||
|
|
|
@ -5,16 +5,16 @@ representations and vice versa */
|
|||
|
||||
union double_bits_pun {
|
||||
double x;
|
||||
u64 y;
|
||||
uint64_t y;
|
||||
};
|
||||
|
||||
inline static u64 double_bits(double x) {
|
||||
inline static uint64_t double_bits(double x) {
|
||||
double_bits_pun b;
|
||||
b.x = x;
|
||||
return b.y;
|
||||
}
|
||||
|
||||
inline static double bits_double(u64 y) {
|
||||
inline static double bits_double(uint64_t y) {
|
||||
double_bits_pun b;
|
||||
b.y = y;
|
||||
return b.x;
|
||||
|
@ -22,16 +22,16 @@ inline static double bits_double(u64 y) {
|
|||
|
||||
union float_bits_pun {
|
||||
float x;
|
||||
u32 y;
|
||||
uint32_t y;
|
||||
};
|
||||
|
||||
inline static u32 float_bits(float x) {
|
||||
inline static uint32_t float_bits(float x) {
|
||||
float_bits_pun b;
|
||||
b.x = x;
|
||||
return b.y;
|
||||
}
|
||||
|
||||
inline static float bits_float(u32 y) {
|
||||
inline static float bits_float(uint32_t y) {
|
||||
float_bits_pun b;
|
||||
b.y = y;
|
||||
return b.x;
|
||||
|
|
|
@ -18,14 +18,14 @@ struct gc_event {
|
|||
cell cards_scanned;
|
||||
cell decks_scanned;
|
||||
cell code_blocks_scanned;
|
||||
u64 start_time;
|
||||
uint64_t start_time;
|
||||
cell total_time;
|
||||
cell card_scan_time;
|
||||
cell code_scan_time;
|
||||
cell data_sweep_time;
|
||||
cell code_sweep_time;
|
||||
cell compaction_time;
|
||||
u64 temp_time;
|
||||
uint64_t temp_time;
|
||||
|
||||
gc_event(gc_op op, factor_vm* parent);
|
||||
void started_card_scan();
|
||||
|
@ -43,7 +43,7 @@ struct gc_event {
|
|||
|
||||
struct gc_state {
|
||||
gc_op op;
|
||||
u64 start_time;
|
||||
uint64_t start_time;
|
||||
gc_event* event;
|
||||
|
||||
gc_state(gc_op op, factor_vm* parent);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace factor {
|
||||
|
||||
cell gc_info::return_address_index(cell return_address) {
|
||||
u32* return_address_array = return_addresses();
|
||||
uint32_t* return_address_array = return_addresses();
|
||||
|
||||
for (cell i = 0; i < return_address_count; i++) {
|
||||
if (return_address == return_address_array[i])
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
namespace factor {
|
||||
|
||||
struct gc_info {
|
||||
u32 scrub_d_count;
|
||||
u32 scrub_r_count;
|
||||
u32 gc_root_count;
|
||||
u32 derived_root_count;
|
||||
u32 return_address_count;
|
||||
uint32_t scrub_d_count;
|
||||
uint32_t scrub_r_count;
|
||||
uint32_t gc_root_count;
|
||||
uint32_t derived_root_count;
|
||||
uint32_t return_address_count;
|
||||
|
||||
cell callsite_bitmap_size() {
|
||||
return scrub_d_count + scrub_r_count + gc_root_count;
|
||||
|
@ -17,14 +17,16 @@ struct gc_info {
|
|||
|
||||
cell total_bitmap_bytes() { return ((total_bitmap_size() + 7) / 8); }
|
||||
|
||||
u32* return_addresses() { return (u32*)this - return_address_count; }
|
||||
uint32_t* return_addresses() {
|
||||
return (uint32_t*)this - return_address_count;
|
||||
}
|
||||
|
||||
u32* base_pointer_map() {
|
||||
uint32_t* base_pointer_map() {
|
||||
return return_addresses() - return_address_count * derived_root_count;
|
||||
}
|
||||
|
||||
u8* gc_info_bitmap() {
|
||||
return (u8*)base_pointer_map() - total_bitmap_bytes();
|
||||
uint8_t* gc_info_bitmap() {
|
||||
return (uint8_t*)base_pointer_map() - total_bitmap_bytes();
|
||||
}
|
||||
|
||||
cell callsite_scrub_d(cell index) { return index * scrub_d_count; }
|
||||
|
@ -38,7 +40,7 @@ struct gc_info {
|
|||
return_address_count * scrub_r_count + index * gc_root_count;
|
||||
}
|
||||
|
||||
u32 lookup_base_pointer(cell index, cell derived_root) {
|
||||
uint32_t lookup_base_pointer(cell index, cell derived_root) {
|
||||
return base_pointer_map()[index * derived_root_count + derived_root];
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ instruction_operand::instruction_operand(relocation_entry rel,
|
|||
|
||||
/* Load a 32-bit value from a PowerPC LIS/ORI sequence */
|
||||
fixnum instruction_operand::load_value_2_2() {
|
||||
u32* ptr = (u32*)pointer;
|
||||
uint32_t* ptr = (uint32_t*)pointer;
|
||||
cell hi = (ptr[-2] & 0xffff);
|
||||
cell lo = (ptr[-1] & 0xffff);
|
||||
return hi << 16 | lo;
|
||||
|
@ -19,21 +19,21 @@ fixnum instruction_operand::load_value_2_2() {
|
|||
|
||||
/* Load a 64-bit value from a PowerPC LIS/ORI/SLDI/ORIS/ORI sequence */
|
||||
fixnum instruction_operand::load_value_2_2_2_2() {
|
||||
u32* ptr = (u32*)pointer;
|
||||
u64 hhi = (ptr[-5] & 0xffff);
|
||||
u64 hlo = (ptr[-4] & 0xffff);
|
||||
u64 lhi = (ptr[-2] & 0xffff);
|
||||
u64 llo = (ptr[-1] & 0xffff);
|
||||
u64 val = hhi << 48 | hlo << 32 | lhi << 16 | llo;
|
||||
uint32_t* ptr = (uint32_t*)pointer;
|
||||
uint64_t hhi = (ptr[-5] & 0xffff);
|
||||
uint64_t hlo = (ptr[-4] & 0xffff);
|
||||
uint64_t lhi = (ptr[-2] & 0xffff);
|
||||
uint64_t llo = (ptr[-1] & 0xffff);
|
||||
uint64_t val = hhi << 48 | hlo << 32 | lhi << 16 | llo;
|
||||
return (cell) val;
|
||||
}
|
||||
|
||||
/* Load a value from a bitfield of a PowerPC instruction */
|
||||
fixnum instruction_operand::load_value_masked(cell mask, cell bits,
|
||||
cell shift) {
|
||||
s32* ptr = (s32*)(pointer - sizeof(u32));
|
||||
int32_t* ptr = (int32_t*)(pointer - sizeof(uint32_t));
|
||||
|
||||
return (((*ptr & (s32) mask) << bits) >> bits) << shift;
|
||||
return (((*ptr & (int32_t) mask) << bits) >> bits) << shift;
|
||||
}
|
||||
|
||||
fixnum instruction_operand::load_value(cell relative_to) {
|
||||
|
@ -41,9 +41,9 @@ fixnum instruction_operand::load_value(cell relative_to) {
|
|||
case RC_ABSOLUTE_CELL:
|
||||
return *(cell*)(pointer - sizeof(cell));
|
||||
case RC_ABSOLUTE:
|
||||
return *(u32*)(pointer - sizeof(u32));
|
||||
return *(uint32_t*)(pointer - sizeof(uint32_t));
|
||||
case RC_RELATIVE:
|
||||
return *(s32*)(pointer - sizeof(u32)) + relative_to;
|
||||
return *(int32_t*)(pointer - sizeof(uint32_t)) + relative_to;
|
||||
case RC_ABSOLUTE_PPC_2_2:
|
||||
return load_value_2_2();
|
||||
case RC_ABSOLUTE_PPC_2:
|
||||
|
@ -62,9 +62,9 @@ fixnum instruction_operand::load_value(cell relative_to) {
|
|||
return load_value_masked(rel_indirect_arm_mask, 20, 0) + relative_to +
|
||||
sizeof(cell);
|
||||
case RC_ABSOLUTE_2:
|
||||
return *(u16*)(pointer - sizeof(u16));
|
||||
return *(uint16_t*)(pointer - sizeof(uint16_t));
|
||||
case RC_ABSOLUTE_1:
|
||||
return *(u8*)(pointer - sizeof(u8));
|
||||
return *(uint8_t*)(pointer - sizeof(uint8_t));
|
||||
case RC_ABSOLUTE_PPC_2_2_2_2:
|
||||
return load_value_2_2_2_2();
|
||||
default:
|
||||
|
@ -85,15 +85,15 @@ code_block* instruction_operand::load_code_block() {
|
|||
|
||||
/* Store a 32-bit value into a PowerPC LIS/ORI sequence */
|
||||
void instruction_operand::store_value_2_2(fixnum value) {
|
||||
u32* ptr = (u32*)pointer;
|
||||
uint32_t* ptr = (uint32_t*)pointer;
|
||||
ptr[-2] = ((ptr[-2] & ~0xffff) | ((value >> 16) & 0xffff));
|
||||
ptr[-1] = ((ptr[-1] & ~0xffff) | (value & 0xffff));
|
||||
}
|
||||
|
||||
/* Store a 64-bit value into a PowerPC LIS/ORI/SLDI/ORIS/ORI sequence */
|
||||
void instruction_operand::store_value_2_2_2_2(fixnum value) {
|
||||
u64 val = value;
|
||||
u32* ptr = (u32*)pointer;
|
||||
uint64_t val = value;
|
||||
uint32_t* ptr = (uint32_t*)pointer;
|
||||
ptr[-5] = ((ptr[-5] & ~0xffff) | ((val >> 48) & 0xffff));
|
||||
ptr[-4] = ((ptr[-4] & ~0xffff) | ((val >> 32) & 0xffff));
|
||||
ptr[-2] = ((ptr[-2] & ~0xffff) | ((val >> 16) & 0xffff));
|
||||
|
@ -103,8 +103,8 @@ void instruction_operand::store_value_2_2_2_2(fixnum value) {
|
|||
/* Store a value into a bitfield of a PowerPC instruction */
|
||||
void instruction_operand::store_value_masked(fixnum value, cell mask,
|
||||
cell shift) {
|
||||
u32* ptr = (u32*)(pointer - sizeof(u32));
|
||||
*ptr = (u32)((*ptr & ~mask) | ((value >> shift) & mask));
|
||||
uint32_t* ptr = (uint32_t*)(pointer - sizeof(uint32_t));
|
||||
*ptr = (uint32_t)((*ptr & ~mask) | ((value >> shift) & mask));
|
||||
}
|
||||
|
||||
void instruction_operand::store_value(fixnum absolute_value) {
|
||||
|
@ -115,10 +115,10 @@ void instruction_operand::store_value(fixnum absolute_value) {
|
|||
*(cell*)(pointer - sizeof(cell)) = absolute_value;
|
||||
break;
|
||||
case RC_ABSOLUTE:
|
||||
*(u32*)(pointer - sizeof(u32)) = (u32) absolute_value;
|
||||
*(uint32_t*)(pointer - sizeof(uint32_t)) = (uint32_t) absolute_value;
|
||||
break;
|
||||
case RC_RELATIVE:
|
||||
*(s32*)(pointer - sizeof(s32)) = (s32) relative_value;
|
||||
*(int32_t*)(pointer - sizeof(int32_t)) = (int32_t) relative_value;
|
||||
break;
|
||||
case RC_ABSOLUTE_PPC_2_2:
|
||||
store_value_2_2(absolute_value);
|
||||
|
@ -144,10 +144,10 @@ void instruction_operand::store_value(fixnum absolute_value) {
|
|||
0);
|
||||
break;
|
||||
case RC_ABSOLUTE_2:
|
||||
*(u16*)(pointer - sizeof(u16)) = (u16) absolute_value;
|
||||
*(uint16_t*)(pointer - sizeof(uint16_t)) = (uint16_t) absolute_value;
|
||||
break;
|
||||
case RC_ABSOLUTE_1:
|
||||
*(u8*)(pointer - sizeof(u8)) = (u8) absolute_value;
|
||||
*(uint8_t*)(pointer - sizeof(uint8_t)) = (uint8_t) absolute_value;
|
||||
break;
|
||||
case RC_ABSOLUTE_PPC_2_2_2_2:
|
||||
store_value_2_2_2_2(absolute_value);
|
||||
|
|
|
@ -75,13 +75,13 @@ static const cell rel_relative_arm_3_mask = 0x00ffffff;
|
|||
|
||||
/* code relocation table consists of a table of entries for each fixup */
|
||||
struct relocation_entry {
|
||||
u32 value;
|
||||
uint32_t value;
|
||||
|
||||
explicit relocation_entry(u32 value_) : value(value_) {}
|
||||
explicit relocation_entry(uint32_t value) : value(value) {}
|
||||
|
||||
relocation_entry(relocation_type rel_type, relocation_class rel_class,
|
||||
cell offset) {
|
||||
value = (u32)((rel_type << 28) | (rel_class << 24) | offset);
|
||||
value = (uint32_t)((rel_type << 28) | (rel_class << 24) | offset);
|
||||
}
|
||||
|
||||
relocation_type rel_type() {
|
||||
|
|
|
@ -116,8 +116,8 @@ void jit::compute_position(cell offset_) {
|
|||
code_block* jit::to_code_block(cell frame_size) {
|
||||
/* Emit dummy GC info */
|
||||
code.grow_bytes(alignment_for(code.count + 4, data_alignment));
|
||||
u32 dummy_gc_info = 0;
|
||||
code.append_bytes(&dummy_gc_info, sizeof(u32));
|
||||
uint32_t dummy_gc_info = 0;
|
||||
code.append_bytes(&dummy_gc_info, sizeof(uint32_t));
|
||||
|
||||
code.trim();
|
||||
relocation.trim();
|
||||
|
|
|
@ -1,21 +1,7 @@
|
|||
namespace factor {
|
||||
|
||||
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;
|
||||
|
||||
#ifdef _WIN64
|
||||
typedef long long fixnum;
|
||||
typedef unsigned long long cell;
|
||||
#else
|
||||
typedef long fixnum;
|
||||
typedef unsigned long cell;
|
||||
#endif
|
||||
typedef intptr_t fixnum;
|
||||
typedef uintptr_t cell;
|
||||
|
||||
inline static cell align(cell a, cell b) { return (a + (b - 1)) & ~(b - 1); }
|
||||
|
||||
|
@ -211,7 +197,7 @@ struct string : public object {
|
|||
/* tagged */
|
||||
cell hashcode;
|
||||
|
||||
u8* data() const { return (u8*)(this + 1); }
|
||||
uint8_t* data() const { return (uint8_t*)(this + 1); }
|
||||
};
|
||||
|
||||
struct code_block;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <wchar.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* C++ headers */
|
||||
#include <algorithm>
|
||||
|
|
20
vm/math.cpp
20
vm/math.cpp
|
@ -281,7 +281,7 @@ void factor_vm::primitive_float_bits() {
|
|||
|
||||
/* Allocates memory */
|
||||
void factor_vm::primitive_bits_float() {
|
||||
ctx->push(allot_float(bits_float((u32) to_cell(ctx->pop()))));
|
||||
ctx->push(allot_float(bits_float((uint32_t) to_cell(ctx->pop()))));
|
||||
}
|
||||
|
||||
void factor_vm::primitive_double_bits() {
|
||||
|
@ -327,19 +327,19 @@ VM_C_API cell from_unsigned_cell(cell integer, factor_vm* parent) {
|
|||
}
|
||||
|
||||
/* Allocates memory */
|
||||
cell factor_vm::from_signed_8(s64 n) {
|
||||
cell factor_vm::from_signed_8(int64_t n) {
|
||||
if (n < fixnum_min || n > fixnum_max)
|
||||
return tag<bignum>(long_long_to_bignum(n));
|
||||
else
|
||||
return tag_fixnum((fixnum) n);
|
||||
}
|
||||
|
||||
VM_C_API cell from_signed_8(s64 n, factor_vm* parent) {
|
||||
VM_C_API cell from_signed_8(int64_t n, factor_vm* parent) {
|
||||
return parent->from_signed_8(n);
|
||||
}
|
||||
|
||||
/* Cannot allocate */
|
||||
s64 factor_vm::to_signed_8(cell obj) {
|
||||
int64_t factor_vm::to_signed_8(cell obj) {
|
||||
switch (tagged<object>(obj).type()) {
|
||||
case FIXNUM_TYPE:
|
||||
return untag_fixnum(obj);
|
||||
|
@ -351,24 +351,24 @@ s64 factor_vm::to_signed_8(cell obj) {
|
|||
}
|
||||
}
|
||||
|
||||
VM_C_API s64 to_signed_8(cell obj, factor_vm* parent) {
|
||||
VM_C_API int64_t to_signed_8(cell obj, factor_vm* parent) {
|
||||
return parent->to_signed_8(obj);
|
||||
}
|
||||
|
||||
/* Allocates memory */
|
||||
cell factor_vm::from_unsigned_8(u64 n) {
|
||||
if (n > (u64) fixnum_max)
|
||||
cell factor_vm::from_unsigned_8(uint64_t n) {
|
||||
if (n > (uint64_t) fixnum_max)
|
||||
return tag<bignum>(ulong_long_to_bignum(n));
|
||||
else
|
||||
return tag_fixnum((fixnum) n);
|
||||
}
|
||||
|
||||
VM_C_API cell from_unsigned_8(u64 n, factor_vm* parent) {
|
||||
VM_C_API cell from_unsigned_8(uint64_t n, factor_vm* parent) {
|
||||
return parent->from_unsigned_8(n);
|
||||
}
|
||||
|
||||
/* Cannot allocate */
|
||||
u64 factor_vm::to_unsigned_8(cell obj) {
|
||||
uint64_t factor_vm::to_unsigned_8(cell obj) {
|
||||
switch (tagged<object>(obj).type()) {
|
||||
case FIXNUM_TYPE:
|
||||
return untag_fixnum(obj);
|
||||
|
@ -380,7 +380,7 @@ u64 factor_vm::to_unsigned_8(cell obj) {
|
|||
}
|
||||
}
|
||||
|
||||
VM_C_API u64 to_unsigned_8(cell obj, factor_vm* parent) {
|
||||
VM_C_API uint64_t to_unsigned_8(cell obj, factor_vm* parent) {
|
||||
return parent->to_unsigned_8(obj);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,11 +64,11 @@ inline cell factor_vm::unbox_array_size() {
|
|||
|
||||
VM_C_API cell from_signed_cell(fixnum integer, factor_vm* vm);
|
||||
VM_C_API cell from_unsigned_cell(cell integer, factor_vm* vm);
|
||||
VM_C_API cell from_signed_8(s64 n, factor_vm* vm);
|
||||
VM_C_API cell from_unsigned_8(u64 n, factor_vm* vm);
|
||||
VM_C_API cell from_signed_8(int64_t n, factor_vm* vm);
|
||||
VM_C_API cell from_unsigned_8(uint64_t n, factor_vm* vm);
|
||||
|
||||
VM_C_API s64 to_signed_8(cell obj, factor_vm* parent);
|
||||
VM_C_API u64 to_unsigned_8(cell obj, factor_vm* parent);
|
||||
VM_C_API int64_t to_signed_8(cell obj, factor_vm* parent);
|
||||
VM_C_API uint64_t to_unsigned_8(cell obj, factor_vm* parent);
|
||||
|
||||
VM_C_API fixnum to_fixnum(cell tagged, factor_vm* vm);
|
||||
VM_C_API cell to_cell(cell tagged, factor_vm* vm);
|
||||
|
|
|
@ -42,7 +42,7 @@ void object_start_map::clear_object_start_offsets() {
|
|||
memset(object_start_offsets, card_starts_inside_object, addr_to_card(size));
|
||||
}
|
||||
|
||||
void object_start_map::update_card_for_sweep(cell index, u16 mask) {
|
||||
void object_start_map::update_card_for_sweep(cell index, uint16_t mask) {
|
||||
cell offset = object_start_offsets[index];
|
||||
if (offset != card_starts_inside_object) {
|
||||
mask >>= (offset / data_alignment);
|
||||
|
|
|
@ -14,7 +14,7 @@ struct object_start_map {
|
|||
cell find_object_containing_card(cell card_index);
|
||||
void record_object_start_offset(object* obj);
|
||||
void clear_object_start_offsets();
|
||||
void update_card_for_sweep(cell index, u16 mask);
|
||||
void update_card_for_sweep(cell index, uint16_t mask);
|
||||
void update_for_sweep(mark_bits<object>* state);
|
||||
};
|
||||
|
||||
|
|
|
@ -27,12 +27,12 @@ const char* default_image_path() {
|
|||
return new_path;
|
||||
}
|
||||
|
||||
u64 nano_count() {
|
||||
uint64_t nano_count() {
|
||||
struct timespec t;
|
||||
int ret = clock_gettime(CLOCK_MONOTONIC, &t);
|
||||
if (ret != 0)
|
||||
fatal_error("clock_gettime failed", 0);
|
||||
return (u64) t.tv_sec * 1000000000 + t.tv_nsec;
|
||||
return (uint64_t) t.tv_sec * 1000000000 + t.tv_nsec;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,10 +64,10 @@ Protocol* objc_getProtocol(char* name) {
|
|||
return nil;
|
||||
}
|
||||
|
||||
u64 nano_count() {
|
||||
u64 time = mach_absolute_time();
|
||||
uint64_t nano_count() {
|
||||
uint64_t time = mach_absolute_time();
|
||||
|
||||
static u64 scaling_factor = 0;
|
||||
static uint64_t scaling_factor = 0;
|
||||
if (!scaling_factor) {
|
||||
mach_timebase_info_data_t info;
|
||||
kern_return_t ret = mach_timebase_info(&info);
|
||||
|
|
|
@ -17,7 +17,7 @@ THREADHANDLE start_thread(void* (*start_routine)(void*), void* args) {
|
|||
|
||||
static void* null_dll;
|
||||
|
||||
void sleep_nanos(u64 nsec) {
|
||||
void sleep_nanos(uint64_t nsec) {
|
||||
timespec ts;
|
||||
timespec ts_rem;
|
||||
int ret;
|
||||
|
|
|
@ -39,8 +39,8 @@ typedef pthread_t THREADHANDLE;
|
|||
THREADHANDLE start_thread(void* (*start_routine)(void*), void* args);
|
||||
inline static THREADHANDLE thread_id() { return pthread_self(); }
|
||||
|
||||
u64 nano_count();
|
||||
void sleep_nanos(u64 nsec);
|
||||
uint64_t nano_count();
|
||||
void sleep_nanos(uint64_t nsec);
|
||||
|
||||
void move_file(const vm_char* path1, const vm_char* path2);
|
||||
|
||||
|
|
|
@ -155,11 +155,11 @@ THREADHANDLE start_thread(void* (*start_routine)(void*), void* args) {
|
|||
args, 0, 0);
|
||||
}
|
||||
|
||||
u64 nano_count() {
|
||||
uint64_t nano_count() {
|
||||
static double scale_factor;
|
||||
|
||||
static u32 hi = 0;
|
||||
static u32 lo = 0;
|
||||
static uint32_t hi = 0;
|
||||
static uint32_t lo = 0;
|
||||
|
||||
LARGE_INTEGER count;
|
||||
BOOL ret = QueryPerformanceCounter(&count);
|
||||
|
@ -184,10 +184,10 @@ u64 nano_count() {
|
|||
#endif
|
||||
lo = count.LowPart;
|
||||
|
||||
return (u64)((((u64) hi << 32) | (u64) lo) * scale_factor);
|
||||
return (uint64_t)((((uint64_t) hi << 32) | (uint64_t) lo) * scale_factor);
|
||||
}
|
||||
|
||||
void sleep_nanos(u64 nsec) { Sleep((DWORD)(nsec / 1000000)); }
|
||||
void sleep_nanos(uint64_t nsec) { Sleep((DWORD)(nsec / 1000000)); }
|
||||
|
||||
typedef enum _EXCEPTION_DISPOSITION {
|
||||
ExceptionContinueExecution = 0,
|
||||
|
|
|
@ -67,8 +67,8 @@ typedef HANDLE THREADHANDLE;
|
|||
#define OPEN_WRITE(path) _wfopen((path), L"wb")
|
||||
|
||||
inline static void early_init() {}
|
||||
u64 nano_count();
|
||||
void sleep_nanos(u64 nsec);
|
||||
uint64_t nano_count();
|
||||
void sleep_nanos(uint64_t nsec);
|
||||
long getpagesize();
|
||||
void move_file(const vm_char* path1, const vm_char* path2);
|
||||
VM_C_API LONG exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c,
|
||||
|
|
|
@ -36,19 +36,19 @@ namespace factor {
|
|||
_(tuple_boa) _(unimplemented) _(uninitialized_byte_array) _(word) \
|
||||
_(word_code) _(wrapper)
|
||||
|
||||
#define EACH_ALIEN_PRIMITIVE(_) \
|
||||
_(signed_cell, fixnum, from_signed_cell, to_fixnum) \
|
||||
_(unsigned_cell, cell, from_unsigned_cell, to_cell) \
|
||||
_(signed_8, s64, from_signed_8, to_signed_8) \
|
||||
_(unsigned_8, u64, from_unsigned_8, to_unsigned_8) \
|
||||
_(signed_4, s32, from_signed_cell, to_fixnum) \
|
||||
_(unsigned_4, u32, from_unsigned_cell, to_cell) \
|
||||
_(signed_2, s16, from_signed_cell, to_fixnum) \
|
||||
_(unsigned_2, u16, from_unsigned_cell, to_cell) \
|
||||
_(signed_1, s8, from_signed_cell, to_fixnum) \
|
||||
_(unsigned_1, u8, from_unsigned_cell, to_cell) \
|
||||
_(float, float, allot_float, to_float) \
|
||||
_(double, double, allot_float, to_double) \
|
||||
#define EACH_ALIEN_PRIMITIVE(_) \
|
||||
_(signed_cell, fixnum, from_signed_cell, to_fixnum) \
|
||||
_(unsigned_cell, cell, from_unsigned_cell, to_cell) \
|
||||
_(signed_8, int64_t, from_signed_8, to_signed_8) \
|
||||
_(unsigned_8, uint64_t, from_unsigned_8, to_unsigned_8) \
|
||||
_(signed_4, int32_t, from_signed_cell, to_fixnum) \
|
||||
_(unsigned_4, uint32_t, from_unsigned_cell, to_cell) \
|
||||
_(signed_2, int16_t, from_signed_cell, to_fixnum) \
|
||||
_(unsigned_2, uint16_t, from_unsigned_cell, to_cell) \
|
||||
_(signed_1, int8_t, from_signed_cell, to_fixnum) \
|
||||
_(unsigned_1, uint8_t, from_unsigned_cell, to_cell) \
|
||||
_(float, float, allot_float, to_float) \
|
||||
_(double, double, allot_float, to_double) \
|
||||
_(cell, void*, allot_alien, pinned_alien_offset)
|
||||
|
||||
#define DECLARE_PRIMITIVE(name) \
|
||||
|
|
|
@ -10,7 +10,7 @@ void exit(int status) {
|
|||
}
|
||||
|
||||
void factor_vm::primitive_nano_count() {
|
||||
u64 nanos = nano_count();
|
||||
uint64_t nanos = nano_count();
|
||||
if (nanos < last_nano_count) {
|
||||
std::cout << "Monotonic counter decreased from 0x";
|
||||
std::cout << std::hex << last_nano_count;
|
||||
|
|
|
@ -293,13 +293,13 @@ template <typename Fixup> struct call_frame_slot_visitor {
|
|||
<< return_address << std::endl;
|
||||
#endif
|
||||
cell* stack_pointer = (cell*)frame_top;
|
||||
u8* bitmap = info->gc_info_bitmap();
|
||||
uint8_t* bitmap = info->gc_info_bitmap();
|
||||
|
||||
/* Subtract old value of base pointer from every derived pointer. */
|
||||
for (cell spill_slot = 0; spill_slot < info->derived_root_count;
|
||||
spill_slot++) {
|
||||
u32 base_pointer = info->lookup_base_pointer(callsite, spill_slot);
|
||||
if (base_pointer != (u32) - 1) {
|
||||
uint32_t base_pointer = info->lookup_base_pointer(callsite, spill_slot);
|
||||
if (base_pointer != (uint32_t)-1) {
|
||||
#ifdef DEBUG_GC_MAPS
|
||||
std::cout << "visiting derived root " << spill_slot
|
||||
<< " with base pointer " << base_pointer << std::endl;
|
||||
|
@ -323,8 +323,8 @@ template <typename Fixup> struct call_frame_slot_visitor {
|
|||
/* Add the base pointers to obtain new derived pointer values. */
|
||||
for (cell spill_slot = 0; spill_slot < info->derived_root_count;
|
||||
spill_slot++) {
|
||||
u32 base_pointer = info->lookup_base_pointer(callsite, spill_slot);
|
||||
if (base_pointer != (u32) - 1)
|
||||
uint32_t base_pointer = info->lookup_base_pointer(callsite, spill_slot);
|
||||
if (base_pointer != (uint32_t)-1)
|
||||
stack_pointer[spill_slot] += stack_pointer[base_pointer];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ void factor_vm::fill_string(string* str_, cell start, cell capacity,
|
|||
data_root<string> str(str_, this);
|
||||
|
||||
if (fill <= 0x7f)
|
||||
memset(&str->data()[start], (u8) fill, capacity - start);
|
||||
memset(&str->data()[start], (uint8_t)fill, capacity - start);
|
||||
else {
|
||||
byte_array* aux;
|
||||
if (to_boolean(str->aux))
|
||||
|
@ -31,11 +31,11 @@ void factor_vm::fill_string(string* str_, cell start, cell capacity,
|
|||
write_barrier(&str->aux);
|
||||
}
|
||||
|
||||
u8 lo_fill = (u8)((fill & 0x7f) | 0x80);
|
||||
u16 hi_fill = (u16)((fill >> 7) ^ 0x1);
|
||||
uint8_t lo_fill = (uint8_t)((fill & 0x7f) | 0x80);
|
||||
uint16_t hi_fill = (uint16_t)((fill >> 7) ^ 0x1);
|
||||
memset(&str->data()[start], lo_fill, capacity - start);
|
||||
memset_2(&aux->data<u16>()[start], hi_fill,
|
||||
(capacity - start) * sizeof(u16));
|
||||
memset_2(&aux->data<uint16_t>()[start], hi_fill,
|
||||
(capacity - start) * sizeof(uint16_t));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,8 @@ string* factor_vm::reallot_string(string* str_, cell capacity) {
|
|||
write_barrier(&new_str->aux);
|
||||
|
||||
byte_array* aux = untag<byte_array>(str->aux);
|
||||
memcpy(new_aux->data<u16>(), aux->data<u16>(), to_copy * sizeof(u16));
|
||||
memcpy(new_aux->data<uint16_t>(), aux->data<uint16_t>(),
|
||||
to_copy * sizeof(uint16_t));
|
||||
}
|
||||
|
||||
fill_string(new_str.untagged(), to_copy, capacity, '\0');
|
||||
|
@ -108,7 +109,7 @@ void factor_vm::primitive_set_string_nth_fast() {
|
|||
string* str = untag<string>(ctx->pop());
|
||||
cell index = untag_fixnum(ctx->pop());
|
||||
cell value = untag_fixnum(ctx->pop());
|
||||
str->data()[index] = (u8) value;
|
||||
str->data()[index] = (uint8_t)value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace factor {
|
||||
|
||||
inline static void memset_2(void* dst, u16 pattern, size_t size) {
|
||||
inline static void memset_2(void* dst, uint16_t pattern, size_t size) {
|
||||
#ifdef __APPLE__
|
||||
cell cell_pattern = (pattern | (pattern << 16));
|
||||
memset_pattern4(dst, &cell_pattern, size);
|
||||
|
@ -8,8 +8,8 @@ inline static void memset_2(void* dst, u16 pattern, size_t size) {
|
|||
if (pattern == 0)
|
||||
memset(dst, 0, size);
|
||||
else {
|
||||
u16* start = (u16*)dst;
|
||||
u16* end = (u16*)((cell) dst + size);
|
||||
uint16_t* start = (uint16_t*)dst;
|
||||
uint16_t* end = (uint16_t*)((cell) dst + size);
|
||||
while (start < end) {
|
||||
*start = pattern;
|
||||
start++;
|
||||
|
|
18
vm/vm.hpp
18
vm/vm.hpp
|
@ -137,7 +137,7 @@ struct factor_vm {
|
|||
cell object_counter;
|
||||
|
||||
/* Sanity check to ensure that monotonic counter doesn't decrease */
|
||||
u64 last_nano_count;
|
||||
uint64_t last_nano_count;
|
||||
|
||||
/* Stack for signal handlers, only used on Unix */
|
||||
segment* signal_callstack_seg;
|
||||
|
@ -239,8 +239,8 @@ struct factor_vm {
|
|||
bignum* bignum_remainder(bignum* numerator, bignum* denominator);
|
||||
cell bignum_to_cell(bignum* bignum);
|
||||
fixnum bignum_to_fixnum(bignum* bignum);
|
||||
s64 bignum_to_long_long(bignum* bignum);
|
||||
u64 bignum_to_ulong_long(bignum* bignum);
|
||||
int64_t bignum_to_long_long(bignum* bignum);
|
||||
uint64_t bignum_to_ulong_long(bignum* bignum);
|
||||
bignum* double_to_bignum(double x);
|
||||
int bignum_equal_p_unsigned(bignum* x, bignum* y);
|
||||
enum bignum_comparison bignum_compare_unsigned(bignum* x, bignum* y);
|
||||
|
@ -478,8 +478,8 @@ struct factor_vm {
|
|||
void primitive_fixnum_divmod();
|
||||
bignum* fixnum_to_bignum(fixnum);
|
||||
bignum* cell_to_bignum(cell);
|
||||
bignum* long_long_to_bignum(s64 n);
|
||||
bignum* ulong_long_to_bignum(u64 n);
|
||||
bignum* long_long_to_bignum(int64_t n);
|
||||
bignum* ulong_long_to_bignum(uint64_t n);
|
||||
inline fixnum sign_mask(fixnum x);
|
||||
inline fixnum branchless_max(fixnum x, fixnum y);
|
||||
inline fixnum branchless_abs(fixnum x);
|
||||
|
@ -524,10 +524,10 @@ struct factor_vm {
|
|||
void primitive_bits_double();
|
||||
fixnum to_fixnum(cell tagged);
|
||||
cell to_cell(cell tagged);
|
||||
cell from_signed_8(s64 n);
|
||||
s64 to_signed_8(cell obj);
|
||||
cell from_unsigned_8(u64 n);
|
||||
u64 to_unsigned_8(cell obj);
|
||||
cell from_signed_8(int64_t n);
|
||||
int64_t to_signed_8(cell obj);
|
||||
cell from_unsigned_8(uint64_t n);
|
||||
uint64_t to_unsigned_8(cell obj);
|
||||
float to_float(cell value);
|
||||
double to_double(cell value);
|
||||
inline void overflow_fixnum_add(fixnum x, fixnum y);
|
||||
|
|
|
@ -13,13 +13,13 @@ static const cell card_points_to_nursery = 0x80;
|
|||
static const cell card_points_to_aging = 0x40;
|
||||
static const cell card_mark_mask =
|
||||
(card_points_to_nursery | card_points_to_aging);
|
||||
typedef u8 card;
|
||||
typedef uint8_t card;
|
||||
|
||||
static const cell card_bits = 8;
|
||||
static const cell card_size = (1 << card_bits);
|
||||
static const cell addr_card_mask = (card_size - 1);
|
||||
|
||||
typedef u8 card_deck;
|
||||
typedef uint8_t card_deck;
|
||||
|
||||
static const cell deck_bits = (card_bits + 10);
|
||||
static const cell deck_size = (1 << deck_bits);
|
||||
|
|
Loading…
Reference in New Issue