VM: Replace u8-64, s8-64, cell, fixnum with stdint.h equivalents

db4
Erik Charlebois 2013-05-13 00:28:25 -04:00
parent 7ea2150c39
commit 88d7c10d03
35 changed files with 153 additions and 163 deletions

View File

@ -300,8 +300,8 @@ bignum* factor_vm::bignum_remainder(bignum* numerator, bignum* denominator) {
FOO_TO_BIGNUM(cell, cell, fixnum, cell) FOO_TO_BIGNUM(cell, cell, fixnum, cell)
FOO_TO_BIGNUM(fixnum, fixnum, fixnum, cell) FOO_TO_BIGNUM(fixnum, fixnum, fixnum, cell)
FOO_TO_BIGNUM(long_long, s64, s64, u64) FOO_TO_BIGNUM(long_long, int64_t, int64_t, uint64_t)
FOO_TO_BIGNUM(ulong_long, u64, s64, u64) FOO_TO_BIGNUM(ulong_long, uint64_t, int64_t, uint64_t)
/* cannot allocate memory */ /* cannot allocate memory */
/* bignum_to_cell, fixnum_to_cell, long_long_to_cell, ulong_long_to_cell */ /* 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(cell, cell, fixnum, cell)
BIGNUM_TO_FOO(fixnum, fixnum, fixnum, cell) BIGNUM_TO_FOO(fixnum, fixnum, fixnum, cell)
BIGNUM_TO_FOO(long_long, s64, s64, u64) BIGNUM_TO_FOO(long_long, int64_t, int64_t, uint64_t)
BIGNUM_TO_FOO(ulong_long, u64, s64, u64) BIGNUM_TO_FOO(ulong_long, uint64_t, int64_t, uint64_t)
#define DTB_WRITE_DIGIT(factor) \ #define DTB_WRITE_DIGIT(factor) \
{ \ { \

View File

@ -51,7 +51,7 @@ typedef fixnum bignum_length_type;
#ifdef FACTOR_64 #ifdef FACTOR_64
typedef __int128_t bignum_twodigit_type; typedef __int128_t bignum_twodigit_type;
#else #else
typedef s64 bignum_twodigit_type; typedef int64_t bignum_twodigit_type;
#endif #endif
#endif #endif

View File

@ -46,16 +46,16 @@ inline cell popcount(cell x) {
#endif #endif
#else #else
#ifdef FACTOR_64 #ifdef FACTOR_64
u64 k1 = 0x5555555555555555ll; uint64_t k1 = 0x5555555555555555ll;
u64 k2 = 0x3333333333333333ll; uint64_t k2 = 0x3333333333333333ll;
u64 k4 = 0x0f0f0f0f0f0f0f0fll; uint64_t k4 = 0x0f0f0f0f0f0f0f0fll;
u64 kf = 0x0101010101010101ll; uint64_t kf = 0x0101010101010101ll;
cell ks = 56; cell ks = 56;
#else #else
u32 k1 = 0x55555555; uint32_t k1 = 0x55555555;
u32 k2 = 0x33333333; uint32_t k2 = 0x33333333;
u32 k4 = 0xf0f0f0f; uint32_t k4 = 0xf0f0f0f;
u32 kf = 0x1010101; uint32_t kf = 0x1010101;
cell ks = 24; cell ks = 24;
#endif #endif
@ -69,7 +69,7 @@ inline cell popcount(cell x) {
#endif #endif
} }
inline bool bitmap_p(u8* bitmap, cell index) { inline bool bitmap_p(uint8_t* bitmap, cell index) {
cell byte = index >> 3; cell byte = index >> 3;
cell bit = index & 7; cell bit = index & 7;
return (bitmap[byte] & (1 << bit)) != 0; return (bitmap[byte] & (1 << bit)) != 0;

View File

@ -40,7 +40,7 @@ void growable_byte_array::grow_bytes(cell len) {
void growable_byte_array::append_bytes(void* elts, cell len) { void growable_byte_array::append_bytes(void* elts, cell len) {
cell old_count = count; cell old_count = count;
grow_bytes(len); grow_bytes(len);
memcpy(&elements->data<u8>()[old_count], elts, len); memcpy(&elements->data<uint8_t>()[old_count], elts, len);
} }
/* Allocates memory */ /* Allocates memory */
@ -53,7 +53,7 @@ void growable_byte_array::append_byte_array(cell byte_array_) {
if (new_size >= array_capacity(elements.untagged())) if (new_size >= array_capacity(elements.untagged()))
elements = parent->reallot_array(elements.untagged(), new_size * 2); 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; count += len;
} }

View File

@ -72,7 +72,7 @@ struct code_block {
/* GC info is stored at the end of the block */ /* GC info is stored at the end of the block */
gc_info* block_gc_info() const { 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()); } void flush_icache() { factor::flush_icache((cell) this, size()); }

View File

@ -3,7 +3,7 @@
namespace factor { namespace factor {
code_heap::code_heap(cell size) { 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); fatal_error("Heap too large", size);
seg = new segment(align_page(size), true); seg = new segment(align_page(size), true);
if (!seg) if (!seg)

View File

@ -50,7 +50,7 @@ void context::fix_stacks() {
} }
void context::scrub_stacks(gc_info* info, cell index) { 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); cell base = info->callsite_scrub_d(index);

View File

@ -18,22 +18,22 @@ namespace factor {
static const fixnum xt_tail_pic_offset = 4; static const fixnum xt_tail_pic_offset = 4;
inline static void check_call_site(cell return_address) { 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 */ /* Check that absolute bit is 0 */
FACTOR_ASSERT((insn & 0x2) == 0x0); FACTOR_ASSERT((insn & 0x2) == 0x0);
/* Check that instruction is branch */ /* Check that instruction is branch */
FACTOR_ASSERT((insn >> 26) == 0x12); 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) { inline static void* get_call_target(cell return_address) {
return_address -= 4; return_address -= 4;
check_call_site(return_address); check_call_site(return_address);
u32 insn = *(u32*)return_address; uint32_t insn = *(uint32_t*)return_address;
u32 unsigned_addr = (insn & b_mask); uint32_t unsigned_addr = (insn & b_mask);
s32 signed_addr = (s32)(unsigned_addr << 6) >> 6; int32_t signed_addr = (int32_t)(unsigned_addr << 6) >> 6;
return (void*)(signed_addr + return_address); return (void*)(signed_addr + return_address);
} }
@ -41,11 +41,11 @@ inline static void set_call_target(cell return_address, void* target) {
return_address -= 4; return_address -= 4;
check_call_site(return_address); check_call_site(return_address);
u32 insn = *(u32*)return_address; uint32_t insn = *(uint32_t*)return_address;
fixnum relative_address = ((cell) target - return_address); fixnum relative_address = ((cell) target - return_address);
insn = ((insn & ~b_mask) | (relative_address & b_mask)); 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 */ /* Flush the cache line containing the call we just patched */
__asm__ __volatile__("icbi 0, %0\n" __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) { inline static bool tail_call_site_p(cell return_address) {
return_address -= 4; return_address -= 4;
u32 insn = *(u32*)return_address; uint32_t insn = *(uint32_t*)return_address;
return (insn & 0x1) == 0; return (insn & 0x1) == 0;
} }

View File

@ -44,7 +44,7 @@ inline static void* get_call_target(cell return_address) {
inline static void set_call_target(cell return_address, void* target) { inline static void set_call_target(cell return_address, void* target) {
check_call_site(return_address); 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) { inline static bool tail_call_site_p(cell return_address) {

View File

@ -5,16 +5,16 @@ representations and vice versa */
union double_bits_pun { union double_bits_pun {
double x; 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; double_bits_pun b;
b.x = x; b.x = x;
return b.y; return b.y;
} }
inline static double bits_double(u64 y) { inline static double bits_double(uint64_t y) {
double_bits_pun b; double_bits_pun b;
b.y = y; b.y = y;
return b.x; return b.x;
@ -22,16 +22,16 @@ inline static double bits_double(u64 y) {
union float_bits_pun { union float_bits_pun {
float x; 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; float_bits_pun b;
b.x = x; b.x = x;
return b.y; return b.y;
} }
inline static float bits_float(u32 y) { inline static float bits_float(uint32_t y) {
float_bits_pun b; float_bits_pun b;
b.y = y; b.y = y;
return b.x; return b.x;

View File

@ -18,14 +18,14 @@ struct gc_event {
cell cards_scanned; cell cards_scanned;
cell decks_scanned; cell decks_scanned;
cell code_blocks_scanned; cell code_blocks_scanned;
u64 start_time; uint64_t start_time;
cell total_time; cell total_time;
cell card_scan_time; cell card_scan_time;
cell code_scan_time; cell code_scan_time;
cell data_sweep_time; cell data_sweep_time;
cell code_sweep_time; cell code_sweep_time;
cell compaction_time; cell compaction_time;
u64 temp_time; uint64_t temp_time;
gc_event(gc_op op, factor_vm* parent); gc_event(gc_op op, factor_vm* parent);
void started_card_scan(); void started_card_scan();
@ -43,7 +43,7 @@ struct gc_event {
struct gc_state { struct gc_state {
gc_op op; gc_op op;
u64 start_time; uint64_t start_time;
gc_event* event; gc_event* event;
gc_state(gc_op op, factor_vm* parent); gc_state(gc_op op, factor_vm* parent);

View File

@ -3,7 +3,7 @@
namespace factor { namespace factor {
cell gc_info::return_address_index(cell return_address) { 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++) { for (cell i = 0; i < return_address_count; i++) {
if (return_address == return_address_array[i]) if (return_address == return_address_array[i])

View File

@ -1,11 +1,11 @@
namespace factor { namespace factor {
struct gc_info { struct gc_info {
u32 scrub_d_count; uint32_t scrub_d_count;
u32 scrub_r_count; uint32_t scrub_r_count;
u32 gc_root_count; uint32_t gc_root_count;
u32 derived_root_count; uint32_t derived_root_count;
u32 return_address_count; uint32_t return_address_count;
cell callsite_bitmap_size() { cell callsite_bitmap_size() {
return scrub_d_count + scrub_r_count + gc_root_count; 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); } 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; return return_addresses() - return_address_count * derived_root_count;
} }
u8* gc_info_bitmap() { uint8_t* gc_info_bitmap() {
return (u8*)base_pointer_map() - total_bitmap_bytes(); return (uint8_t*)base_pointer_map() - total_bitmap_bytes();
} }
cell callsite_scrub_d(cell index) { return index * scrub_d_count; } 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; 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]; return base_pointer_map()[index * derived_root_count + derived_root];
} }

View File

@ -11,7 +11,7 @@ instruction_operand::instruction_operand(relocation_entry rel,
/* Load a 32-bit value from a PowerPC LIS/ORI sequence */ /* Load a 32-bit value from a PowerPC LIS/ORI sequence */
fixnum instruction_operand::load_value_2_2() { fixnum instruction_operand::load_value_2_2() {
u32* ptr = (u32*)pointer; uint32_t* ptr = (uint32_t*)pointer;
cell hi = (ptr[-2] & 0xffff); cell hi = (ptr[-2] & 0xffff);
cell lo = (ptr[-1] & 0xffff); cell lo = (ptr[-1] & 0xffff);
return hi << 16 | lo; 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 */ /* Load a 64-bit value from a PowerPC LIS/ORI/SLDI/ORIS/ORI sequence */
fixnum instruction_operand::load_value_2_2_2_2() { fixnum instruction_operand::load_value_2_2_2_2() {
u32* ptr = (u32*)pointer; uint32_t* ptr = (uint32_t*)pointer;
u64 hhi = (ptr[-5] & 0xffff); uint64_t hhi = (ptr[-5] & 0xffff);
u64 hlo = (ptr[-4] & 0xffff); uint64_t hlo = (ptr[-4] & 0xffff);
u64 lhi = (ptr[-2] & 0xffff); uint64_t lhi = (ptr[-2] & 0xffff);
u64 llo = (ptr[-1] & 0xffff); uint64_t llo = (ptr[-1] & 0xffff);
u64 val = hhi << 48 | hlo << 32 | lhi << 16 | llo; uint64_t val = hhi << 48 | hlo << 32 | lhi << 16 | llo;
return (cell) val; return (cell) val;
} }
/* Load a value from a bitfield of a PowerPC instruction */ /* Load a value from a bitfield of a PowerPC instruction */
fixnum instruction_operand::load_value_masked(cell mask, cell bits, fixnum instruction_operand::load_value_masked(cell mask, cell bits,
cell shift) { 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) { fixnum instruction_operand::load_value(cell relative_to) {
@ -41,9 +41,9 @@ fixnum instruction_operand::load_value(cell relative_to) {
case RC_ABSOLUTE_CELL: case RC_ABSOLUTE_CELL:
return *(cell*)(pointer - sizeof(cell)); return *(cell*)(pointer - sizeof(cell));
case RC_ABSOLUTE: case RC_ABSOLUTE:
return *(u32*)(pointer - sizeof(u32)); return *(uint32_t*)(pointer - sizeof(uint32_t));
case RC_RELATIVE: 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: case RC_ABSOLUTE_PPC_2_2:
return load_value_2_2(); return load_value_2_2();
case RC_ABSOLUTE_PPC_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 + return load_value_masked(rel_indirect_arm_mask, 20, 0) + relative_to +
sizeof(cell); sizeof(cell);
case RC_ABSOLUTE_2: case RC_ABSOLUTE_2:
return *(u16*)(pointer - sizeof(u16)); return *(uint16_t*)(pointer - sizeof(uint16_t));
case RC_ABSOLUTE_1: case RC_ABSOLUTE_1:
return *(u8*)(pointer - sizeof(u8)); return *(uint8_t*)(pointer - sizeof(uint8_t));
case RC_ABSOLUTE_PPC_2_2_2_2: case RC_ABSOLUTE_PPC_2_2_2_2:
return load_value_2_2_2_2(); return load_value_2_2_2_2();
default: default:
@ -85,15 +85,15 @@ code_block* instruction_operand::load_code_block() {
/* Store a 32-bit value into a PowerPC LIS/ORI sequence */ /* Store a 32-bit value into a PowerPC LIS/ORI sequence */
void instruction_operand::store_value_2_2(fixnum value) { 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[-2] = ((ptr[-2] & ~0xffff) | ((value >> 16) & 0xffff));
ptr[-1] = ((ptr[-1] & ~0xffff) | (value & 0xffff)); ptr[-1] = ((ptr[-1] & ~0xffff) | (value & 0xffff));
} }
/* Store a 64-bit value into a PowerPC LIS/ORI/SLDI/ORIS/ORI sequence */ /* 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) { void instruction_operand::store_value_2_2_2_2(fixnum value) {
u64 val = value; uint64_t val = value;
u32* ptr = (u32*)pointer; uint32_t* ptr = (uint32_t*)pointer;
ptr[-5] = ((ptr[-5] & ~0xffff) | ((val >> 48) & 0xffff)); ptr[-5] = ((ptr[-5] & ~0xffff) | ((val >> 48) & 0xffff));
ptr[-4] = ((ptr[-4] & ~0xffff) | ((val >> 32) & 0xffff)); ptr[-4] = ((ptr[-4] & ~0xffff) | ((val >> 32) & 0xffff));
ptr[-2] = ((ptr[-2] & ~0xffff) | ((val >> 16) & 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 */ /* Store a value into a bitfield of a PowerPC instruction */
void instruction_operand::store_value_masked(fixnum value, cell mask, void instruction_operand::store_value_masked(fixnum value, cell mask,
cell shift) { cell shift) {
u32* ptr = (u32*)(pointer - sizeof(u32)); uint32_t* ptr = (uint32_t*)(pointer - sizeof(uint32_t));
*ptr = (u32)((*ptr & ~mask) | ((value >> shift) & mask)); *ptr = (uint32_t)((*ptr & ~mask) | ((value >> shift) & mask));
} }
void instruction_operand::store_value(fixnum absolute_value) { 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; *(cell*)(pointer - sizeof(cell)) = absolute_value;
break; break;
case RC_ABSOLUTE: case RC_ABSOLUTE:
*(u32*)(pointer - sizeof(u32)) = (u32) absolute_value; *(uint32_t*)(pointer - sizeof(uint32_t)) = (uint32_t) absolute_value;
break; break;
case RC_RELATIVE: case RC_RELATIVE:
*(s32*)(pointer - sizeof(s32)) = (s32) relative_value; *(int32_t*)(pointer - sizeof(int32_t)) = (int32_t) relative_value;
break; break;
case RC_ABSOLUTE_PPC_2_2: case RC_ABSOLUTE_PPC_2_2:
store_value_2_2(absolute_value); store_value_2_2(absolute_value);
@ -144,10 +144,10 @@ void instruction_operand::store_value(fixnum absolute_value) {
0); 0);
break; break;
case RC_ABSOLUTE_2: case RC_ABSOLUTE_2:
*(u16*)(pointer - sizeof(u16)) = (u16) absolute_value; *(uint16_t*)(pointer - sizeof(uint16_t)) = (uint16_t) absolute_value;
break; break;
case RC_ABSOLUTE_1: case RC_ABSOLUTE_1:
*(u8*)(pointer - sizeof(u8)) = (u8) absolute_value; *(uint8_t*)(pointer - sizeof(uint8_t)) = (uint8_t) absolute_value;
break; break;
case RC_ABSOLUTE_PPC_2_2_2_2: case RC_ABSOLUTE_PPC_2_2_2_2:
store_value_2_2_2_2(absolute_value); store_value_2_2_2_2(absolute_value);

View File

@ -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 */ /* code relocation table consists of a table of entries for each fixup */
struct relocation_entry { 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, relocation_entry(relocation_type rel_type, relocation_class rel_class,
cell offset) { 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() { relocation_type rel_type() {

View File

@ -116,8 +116,8 @@ void jit::compute_position(cell offset_) {
code_block* jit::to_code_block(cell frame_size) { code_block* jit::to_code_block(cell frame_size) {
/* Emit dummy GC info */ /* Emit dummy GC info */
code.grow_bytes(alignment_for(code.count + 4, data_alignment)); code.grow_bytes(alignment_for(code.count + 4, data_alignment));
u32 dummy_gc_info = 0; uint32_t dummy_gc_info = 0;
code.append_bytes(&dummy_gc_info, sizeof(u32)); code.append_bytes(&dummy_gc_info, sizeof(uint32_t));
code.trim(); code.trim();
relocation.trim(); relocation.trim();

View File

@ -1,21 +1,7 @@
namespace factor { namespace factor {
typedef unsigned char u8; typedef intptr_t fixnum;
typedef unsigned short u16; typedef uintptr_t cell;
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
inline static cell align(cell a, cell b) { return (a + (b - 1)) & ~(b - 1); } inline static cell align(cell a, cell b) { return (a + (b - 1)) & ~(b - 1); }
@ -211,7 +197,7 @@ struct string : public object {
/* tagged */ /* tagged */
cell hashcode; cell hashcode;
u8* data() const { return (u8*)(this + 1); } uint8_t* data() const { return (uint8_t*)(this + 1); }
}; };
struct code_block; struct code_block;

View File

@ -20,6 +20,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <wchar.h> #include <wchar.h>
#include <stdint.h>
/* C++ headers */ /* C++ headers */
#include <algorithm> #include <algorithm>

View File

@ -281,7 +281,7 @@ void factor_vm::primitive_float_bits() {
/* Allocates memory */ /* Allocates memory */
void factor_vm::primitive_bits_float() { 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() { void factor_vm::primitive_double_bits() {
@ -327,19 +327,19 @@ VM_C_API cell from_unsigned_cell(cell integer, factor_vm* parent) {
} }
/* Allocates memory */ /* 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) if (n < fixnum_min || n > fixnum_max)
return tag<bignum>(long_long_to_bignum(n)); return tag<bignum>(long_long_to_bignum(n));
else else
return tag_fixnum((fixnum) n); 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); return parent->from_signed_8(n);
} }
/* Cannot allocate */ /* Cannot allocate */
s64 factor_vm::to_signed_8(cell obj) { int64_t factor_vm::to_signed_8(cell obj) {
switch (tagged<object>(obj).type()) { switch (tagged<object>(obj).type()) {
case FIXNUM_TYPE: case FIXNUM_TYPE:
return untag_fixnum(obj); 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); return parent->to_signed_8(obj);
} }
/* Allocates memory */ /* Allocates memory */
cell factor_vm::from_unsigned_8(u64 n) { cell factor_vm::from_unsigned_8(uint64_t n) {
if (n > (u64) fixnum_max) if (n > (uint64_t) fixnum_max)
return tag<bignum>(ulong_long_to_bignum(n)); return tag<bignum>(ulong_long_to_bignum(n));
else else
return tag_fixnum((fixnum) n); 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); return parent->from_unsigned_8(n);
} }
/* Cannot allocate */ /* Cannot allocate */
u64 factor_vm::to_unsigned_8(cell obj) { uint64_t factor_vm::to_unsigned_8(cell obj) {
switch (tagged<object>(obj).type()) { switch (tagged<object>(obj).type()) {
case FIXNUM_TYPE: case FIXNUM_TYPE:
return untag_fixnum(obj); 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); return parent->to_unsigned_8(obj);
} }

View File

@ -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_signed_cell(fixnum integer, factor_vm* vm);
VM_C_API cell from_unsigned_cell(cell 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_signed_8(int64_t n, factor_vm* vm);
VM_C_API cell from_unsigned_8(u64 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 int64_t to_signed_8(cell obj, factor_vm* parent);
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);
VM_C_API fixnum to_fixnum(cell tagged, factor_vm* vm); VM_C_API fixnum to_fixnum(cell tagged, factor_vm* vm);
VM_C_API cell to_cell(cell tagged, factor_vm* vm); VM_C_API cell to_cell(cell tagged, factor_vm* vm);

View File

@ -42,7 +42,7 @@ void object_start_map::clear_object_start_offsets() {
memset(object_start_offsets, card_starts_inside_object, addr_to_card(size)); 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]; cell offset = object_start_offsets[index];
if (offset != card_starts_inside_object) { if (offset != card_starts_inside_object) {
mask >>= (offset / data_alignment); mask >>= (offset / data_alignment);

View File

@ -14,7 +14,7 @@ struct object_start_map {
cell find_object_containing_card(cell card_index); cell find_object_containing_card(cell card_index);
void record_object_start_offset(object* obj); void record_object_start_offset(object* obj);
void clear_object_start_offsets(); 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); void update_for_sweep(mark_bits<object>* state);
}; };

View File

@ -27,12 +27,12 @@ const char* default_image_path() {
return new_path; return new_path;
} }
u64 nano_count() { uint64_t nano_count() {
struct timespec t; struct timespec t;
int ret = clock_gettime(CLOCK_MONOTONIC, &t); int ret = clock_gettime(CLOCK_MONOTONIC, &t);
if (ret != 0) if (ret != 0)
fatal_error("clock_gettime failed", 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;
} }
} }

View File

@ -64,10 +64,10 @@ Protocol* objc_getProtocol(char* name) {
return nil; return nil;
} }
u64 nano_count() { uint64_t nano_count() {
u64 time = mach_absolute_time(); uint64_t time = mach_absolute_time();
static u64 scaling_factor = 0; static uint64_t scaling_factor = 0;
if (!scaling_factor) { if (!scaling_factor) {
mach_timebase_info_data_t info; mach_timebase_info_data_t info;
kern_return_t ret = mach_timebase_info(&info); kern_return_t ret = mach_timebase_info(&info);

View File

@ -17,7 +17,7 @@ THREADHANDLE start_thread(void* (*start_routine)(void*), void* args) {
static void* null_dll; static void* null_dll;
void sleep_nanos(u64 nsec) { void sleep_nanos(uint64_t nsec) {
timespec ts; timespec ts;
timespec ts_rem; timespec ts_rem;
int ret; int ret;

View File

@ -39,8 +39,8 @@ typedef pthread_t THREADHANDLE;
THREADHANDLE start_thread(void* (*start_routine)(void*), void* args); THREADHANDLE start_thread(void* (*start_routine)(void*), void* args);
inline static THREADHANDLE thread_id() { return pthread_self(); } inline static THREADHANDLE thread_id() { return pthread_self(); }
u64 nano_count(); uint64_t nano_count();
void sleep_nanos(u64 nsec); void sleep_nanos(uint64_t nsec);
void move_file(const vm_char* path1, const vm_char* path2); void move_file(const vm_char* path1, const vm_char* path2);

View File

@ -155,11 +155,11 @@ THREADHANDLE start_thread(void* (*start_routine)(void*), void* args) {
args, 0, 0); args, 0, 0);
} }
u64 nano_count() { uint64_t nano_count() {
static double scale_factor; static double scale_factor;
static u32 hi = 0; static uint32_t hi = 0;
static u32 lo = 0; static uint32_t lo = 0;
LARGE_INTEGER count; LARGE_INTEGER count;
BOOL ret = QueryPerformanceCounter(&count); BOOL ret = QueryPerformanceCounter(&count);
@ -184,10 +184,10 @@ u64 nano_count() {
#endif #endif
lo = count.LowPart; 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 { typedef enum _EXCEPTION_DISPOSITION {
ExceptionContinueExecution = 0, ExceptionContinueExecution = 0,

View File

@ -67,8 +67,8 @@ typedef HANDLE THREADHANDLE;
#define OPEN_WRITE(path) _wfopen((path), L"wb") #define OPEN_WRITE(path) _wfopen((path), L"wb")
inline static void early_init() {} inline static void early_init() {}
u64 nano_count(); uint64_t nano_count();
void sleep_nanos(u64 nsec); void sleep_nanos(uint64_t nsec);
long getpagesize(); long getpagesize();
void move_file(const vm_char* path1, const vm_char* path2); void move_file(const vm_char* path1, const vm_char* path2);
VM_C_API LONG exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c, VM_C_API LONG exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c,

View File

@ -36,19 +36,19 @@ namespace factor {
_(tuple_boa) _(unimplemented) _(uninitialized_byte_array) _(word) \ _(tuple_boa) _(unimplemented) _(uninitialized_byte_array) _(word) \
_(word_code) _(wrapper) _(word_code) _(wrapper)
#define EACH_ALIEN_PRIMITIVE(_) \ #define EACH_ALIEN_PRIMITIVE(_) \
_(signed_cell, fixnum, from_signed_cell, to_fixnum) \ _(signed_cell, fixnum, from_signed_cell, to_fixnum) \
_(unsigned_cell, cell, from_unsigned_cell, to_cell) \ _(unsigned_cell, cell, from_unsigned_cell, to_cell) \
_(signed_8, s64, from_signed_8, to_signed_8) \ _(signed_8, int64_t, from_signed_8, to_signed_8) \
_(unsigned_8, u64, from_unsigned_8, to_unsigned_8) \ _(unsigned_8, uint64_t, from_unsigned_8, to_unsigned_8) \
_(signed_4, s32, from_signed_cell, to_fixnum) \ _(signed_4, int32_t, from_signed_cell, to_fixnum) \
_(unsigned_4, u32, from_unsigned_cell, to_cell) \ _(unsigned_4, uint32_t, from_unsigned_cell, to_cell) \
_(signed_2, s16, from_signed_cell, to_fixnum) \ _(signed_2, int16_t, from_signed_cell, to_fixnum) \
_(unsigned_2, u16, from_unsigned_cell, to_cell) \ _(unsigned_2, uint16_t, from_unsigned_cell, to_cell) \
_(signed_1, s8, from_signed_cell, to_fixnum) \ _(signed_1, int8_t, from_signed_cell, to_fixnum) \
_(unsigned_1, u8, from_unsigned_cell, to_cell) \ _(unsigned_1, uint8_t, from_unsigned_cell, to_cell) \
_(float, float, allot_float, to_float) \ _(float, float, allot_float, to_float) \
_(double, double, allot_float, to_double) \ _(double, double, allot_float, to_double) \
_(cell, void*, allot_alien, pinned_alien_offset) _(cell, void*, allot_alien, pinned_alien_offset)
#define DECLARE_PRIMITIVE(name) \ #define DECLARE_PRIMITIVE(name) \

View File

@ -10,7 +10,7 @@ void exit(int status) {
} }
void factor_vm::primitive_nano_count() { void factor_vm::primitive_nano_count() {
u64 nanos = nano_count(); uint64_t nanos = nano_count();
if (nanos < last_nano_count) { if (nanos < last_nano_count) {
std::cout << "Monotonic counter decreased from 0x"; std::cout << "Monotonic counter decreased from 0x";
std::cout << std::hex << last_nano_count; std::cout << std::hex << last_nano_count;

View File

@ -293,13 +293,13 @@ template <typename Fixup> struct call_frame_slot_visitor {
<< return_address << std::endl; << return_address << std::endl;
#endif #endif
cell* stack_pointer = (cell*)frame_top; 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. */ /* Subtract old value of base pointer from every derived pointer. */
for (cell spill_slot = 0; spill_slot < info->derived_root_count; for (cell spill_slot = 0; spill_slot < info->derived_root_count;
spill_slot++) { spill_slot++) {
u32 base_pointer = info->lookup_base_pointer(callsite, spill_slot); uint32_t base_pointer = info->lookup_base_pointer(callsite, spill_slot);
if (base_pointer != (u32) - 1) { if (base_pointer != (uint32_t)-1) {
#ifdef DEBUG_GC_MAPS #ifdef DEBUG_GC_MAPS
std::cout << "visiting derived root " << spill_slot std::cout << "visiting derived root " << spill_slot
<< " with base pointer " << base_pointer << std::endl; << " 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. */ /* Add the base pointers to obtain new derived pointer values. */
for (cell spill_slot = 0; spill_slot < info->derived_root_count; for (cell spill_slot = 0; spill_slot < info->derived_root_count;
spill_slot++) { spill_slot++) {
u32 base_pointer = info->lookup_base_pointer(callsite, spill_slot); uint32_t base_pointer = info->lookup_base_pointer(callsite, spill_slot);
if (base_pointer != (u32) - 1) if (base_pointer != (uint32_t)-1)
stack_pointer[spill_slot] += stack_pointer[base_pointer]; stack_pointer[spill_slot] += stack_pointer[base_pointer];
} }
} }

View File

@ -19,7 +19,7 @@ void factor_vm::fill_string(string* str_, cell start, cell capacity,
data_root<string> str(str_, this); data_root<string> str(str_, this);
if (fill <= 0x7f) if (fill <= 0x7f)
memset(&str->data()[start], (u8) fill, capacity - start); memset(&str->data()[start], (uint8_t)fill, capacity - start);
else { else {
byte_array* aux; byte_array* aux;
if (to_boolean(str->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); write_barrier(&str->aux);
} }
u8 lo_fill = (u8)((fill & 0x7f) | 0x80); uint8_t lo_fill = (uint8_t)((fill & 0x7f) | 0x80);
u16 hi_fill = (u16)((fill >> 7) ^ 0x1); uint16_t hi_fill = (uint16_t)((fill >> 7) ^ 0x1);
memset(&str->data()[start], lo_fill, capacity - start); memset(&str->data()[start], lo_fill, capacity - start);
memset_2(&aux->data<u16>()[start], hi_fill, memset_2(&aux->data<uint16_t>()[start], hi_fill,
(capacity - start) * sizeof(u16)); (capacity - start) * sizeof(uint16_t));
} }
} }
@ -88,7 +88,8 @@ string* factor_vm::reallot_string(string* str_, cell capacity) {
write_barrier(&new_str->aux); write_barrier(&new_str->aux);
byte_array* aux = untag<byte_array>(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'); 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()); string* str = untag<string>(ctx->pop());
cell index = untag_fixnum(ctx->pop()); cell index = untag_fixnum(ctx->pop());
cell value = untag_fixnum(ctx->pop()); cell value = untag_fixnum(ctx->pop());
str->data()[index] = (u8) value; str->data()[index] = (uint8_t)value;
} }
} }

View File

@ -1,6 +1,6 @@
namespace factor { 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__ #ifdef __APPLE__
cell cell_pattern = (pattern | (pattern << 16)); cell cell_pattern = (pattern | (pattern << 16));
memset_pattern4(dst, &cell_pattern, size); 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) if (pattern == 0)
memset(dst, 0, size); memset(dst, 0, size);
else { else {
u16* start = (u16*)dst; uint16_t* start = (uint16_t*)dst;
u16* end = (u16*)((cell) dst + size); uint16_t* end = (uint16_t*)((cell) dst + size);
while (start < end) { while (start < end) {
*start = pattern; *start = pattern;
start++; start++;

View File

@ -137,7 +137,7 @@ struct factor_vm {
cell object_counter; cell object_counter;
/* Sanity check to ensure that monotonic counter doesn't decrease */ /* 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 */ /* Stack for signal handlers, only used on Unix */
segment* signal_callstack_seg; segment* signal_callstack_seg;
@ -239,8 +239,8 @@ struct factor_vm {
bignum* bignum_remainder(bignum* numerator, bignum* denominator); bignum* bignum_remainder(bignum* numerator, bignum* denominator);
cell bignum_to_cell(bignum* bignum); cell bignum_to_cell(bignum* bignum);
fixnum bignum_to_fixnum(bignum* bignum); fixnum bignum_to_fixnum(bignum* bignum);
s64 bignum_to_long_long(bignum* bignum); int64_t bignum_to_long_long(bignum* bignum);
u64 bignum_to_ulong_long(bignum* bignum); uint64_t bignum_to_ulong_long(bignum* bignum);
bignum* double_to_bignum(double x); bignum* double_to_bignum(double x);
int bignum_equal_p_unsigned(bignum* x, bignum* y); int bignum_equal_p_unsigned(bignum* x, bignum* y);
enum bignum_comparison bignum_compare_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(); void primitive_fixnum_divmod();
bignum* fixnum_to_bignum(fixnum); bignum* fixnum_to_bignum(fixnum);
bignum* cell_to_bignum(cell); bignum* cell_to_bignum(cell);
bignum* long_long_to_bignum(s64 n); bignum* long_long_to_bignum(int64_t n);
bignum* ulong_long_to_bignum(u64 n); bignum* ulong_long_to_bignum(uint64_t n);
inline fixnum sign_mask(fixnum x); inline fixnum sign_mask(fixnum x);
inline fixnum branchless_max(fixnum x, fixnum y); inline fixnum branchless_max(fixnum x, fixnum y);
inline fixnum branchless_abs(fixnum x); inline fixnum branchless_abs(fixnum x);
@ -524,10 +524,10 @@ struct factor_vm {
void primitive_bits_double(); void primitive_bits_double();
fixnum to_fixnum(cell tagged); fixnum to_fixnum(cell tagged);
cell to_cell(cell tagged); cell to_cell(cell tagged);
cell from_signed_8(s64 n); cell from_signed_8(int64_t n);
s64 to_signed_8(cell obj); int64_t to_signed_8(cell obj);
cell from_unsigned_8(u64 n); cell from_unsigned_8(uint64_t n);
u64 to_unsigned_8(cell obj); uint64_t to_unsigned_8(cell obj);
float to_float(cell value); float to_float(cell value);
double to_double(cell value); double to_double(cell value);
inline void overflow_fixnum_add(fixnum x, fixnum y); inline void overflow_fixnum_add(fixnum x, fixnum y);

View File

@ -13,13 +13,13 @@ static const cell card_points_to_nursery = 0x80;
static const cell card_points_to_aging = 0x40; static const cell card_points_to_aging = 0x40;
static const cell card_mark_mask = static const cell card_mark_mask =
(card_points_to_nursery | card_points_to_aging); (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_bits = 8;
static const cell card_size = (1 << card_bits); static const cell card_size = (1 << card_bits);
static const cell addr_card_mask = (card_size - 1); 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_bits = (card_bits + 10);
static const cell deck_size = (1 << deck_bits); static const cell deck_size = (1 << deck_bits);