From c08fa9cb6e4eb19739a6a3674c819553f6b78527 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 6 Feb 2010 00:45:06 -0600 Subject: [PATCH 1/2] vm: disable silly nano-count workaround on Win64, fix some indentation issues --- vm/io.cpp | 37 +++++++++++++++---------------------- vm/os-windows-nt.cpp | 14 +++++++++----- vm/os-windows.cpp | 4 ++-- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/vm/io.cpp b/vm/io.cpp index ae27b5a3d8..8eaaa453b5 100755 --- a/vm/io.cpp +++ b/vm/io.cpp @@ -154,7 +154,7 @@ void factor_vm::primitive_fopen() FILE *file; file = safe_fopen((char *)(path.untagged() + 1), - (char *)(mode.untagged() + 1)); + (char *)(mode.untagged() + 1)); ctx->push(allot_alien(file)); } @@ -187,31 +187,24 @@ void factor_vm::primitive_fread() data_root buf(allot_uninitialized_array(size),this); - for(;;) + int c = safe_fread(buf.untagged() + 1,1,size,file); + if(c == 0) { - int c = safe_fread(buf.untagged() + 1,1,size,file); - if(c == 0) - { - if(feof(file)) - { - ctx->push(false_object); - break; - } - else - io_error(); - } + if(feof(file)) + ctx->push(false_object); else + io_error(); + } + else + { + if(feof(file)) { - if(feof(file)) - { - byte_array *new_buf = allot_byte_array(c); - memcpy(new_buf + 1, buf.untagged() + 1,c); - buf = new_buf; - } - - ctx->push(buf.value()); - break; + byte_array *new_buf = allot_byte_array(c); + memcpy(new_buf + 1, buf.untagged() + 1,c); + buf = new_buf; } + + ctx->push(buf.value()); } } diff --git a/vm/os-windows-nt.cpp b/vm/os-windows-nt.cpp index cf5878e5bf..644ff83b44 100755 --- a/vm/os-windows-nt.cpp +++ b/vm/os-windows-nt.cpp @@ -37,8 +37,6 @@ u64 system_micros() - EPOCH_OFFSET) / 10; } -/* On VirtualBox, QueryPerformanceCounter does not increment -the high part every time the low part overflows. Workaround. */ u64 nano_count() { LARGE_INTEGER count; @@ -53,8 +51,14 @@ u64 nano_count() if(ret == 0) fatal_error("QueryPerformanceFrequency", 0); - if(count.LowPart < lo) - hi += 1; +#ifdef FACTOR_64 + hi = count.HighPart; +#else + /* On VirtualBox, QueryPerformanceCounter does not increment + the high part every time the low part overflows. Workaround. */ + if(lo > count.LowPart) + hi++; +#endif lo = count.LowPart; return (u64)((((u64)hi << 32) | (u64)lo)*(1000000000.0/frequency.QuadPart)); @@ -91,7 +95,7 @@ LONG factor_vm::exception_handler(PEXCEPTION_POINTERS pe) case STATUS_FLOAT_UNDERFLOW: case STATUS_FLOAT_MULTIPLE_FAULTS: case STATUS_FLOAT_MULTIPLE_TRAPS: -#ifdef FACTOR_AMD64 +#ifdef FACTOR_64 signal_fpu_status = fpu_status(MXCSR(c)); #else signal_fpu_status = fpu_status(X87SW(c) | MXCSR(c)); diff --git a/vm/os-windows.cpp b/vm/os-windows.cpp index a6914a9f70..08f5932172 100755 --- a/vm/os-windows.cpp +++ b/vm/os-windows.cpp @@ -128,7 +128,7 @@ segment::~segment() long getpagesize() { static long g_pagesize = 0; - if (! g_pagesize) + if(!g_pagesize) { SYSTEM_INFO system_info; GetSystemInfo (&system_info); @@ -139,7 +139,7 @@ long getpagesize() void factor_vm::move_file(const vm_char *path1, const vm_char *path2) { - if(MoveFileEx((path1),(path2),MOVEFILE_REPLACE_EXISTING) == false) + if(MoveFileEx((path1),(path2),MOVEFILE_REPLACE_EXISTING) == false) general_error(ERROR_IO,tag_fixnum(GetLastError()),false_object,NULL); } From d22eb403605bf38c6379571ca237b02defaf8725 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 6 Feb 2010 01:06:26 -0600 Subject: [PATCH 2/2] Fix spaces that crept into vm/ cpp files --- vm/Config.macosx | 2 +- vm/bignumint.hpp | 2 +- vm/cpu-ppc.hpp | 14 +++++++------- vm/cpu-x86.hpp | 14 +++++++------- vm/data_heap.cpp | 2 +- vm/full_collector.cpp | 2 +- vm/gc.hpp | 2 +- vm/jit.hpp | 2 +- vm/math.cpp | 2 +- vm/os-freebsd-x86.32.hpp | 16 ++++++++-------- vm/os-freebsd-x86.64.hpp | 12 ++++++------ vm/os-linux-x86.64.hpp | 12 ++++++------ vm/os-windows-nt.cpp | 8 ++++---- vm/vm.hpp | 14 +++++++------- 14 files changed, 52 insertions(+), 52 deletions(-) diff --git a/vm/Config.macosx b/vm/Config.macosx index 07629f72bb..89fe239668 100644 --- a/vm/Config.macosx +++ b/vm/Config.macosx @@ -11,7 +11,7 @@ SHARED_FLAG = -dynamiclib ifdef X11 LIBS = -lm -framework Cocoa -L/opt/local/lib $(X11_UI_LIBS) -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib else - LIBS = -lm -framework Cocoa -framework AppKit + LIBS = -lm -framework Cocoa -framework AppKit endif LINKER = $(CPP) $(CFLAGS) -dynamiclib -single_module -std=gnu99 \ diff --git a/vm/bignumint.hpp b/vm/bignumint.hpp index 57c71959c3..ff0d86a681 100644 --- a/vm/bignumint.hpp +++ b/vm/bignumint.hpp @@ -96,7 +96,7 @@ typedef fixnum bignum_length_type; #define BIGNUM_ASSERT(expression) \ { \ if (! (expression)) \ - BIGNUM_EXCEPTION (); \ + BIGNUM_EXCEPTION (); \ } #endif /* not BIGNUM_DISABLE_ASSERTION_CHECKS */ diff --git a/vm/cpu-ppc.hpp b/vm/cpu-ppc.hpp index d284cbce78..d09fc173ea 100644 --- a/vm/cpu-ppc.hpp +++ b/vm/cpu-ppc.hpp @@ -58,20 +58,20 @@ inline static bool tail_call_site_p(cell return_address) inline static unsigned int fpu_status(unsigned int status) { - unsigned int r = 0; + unsigned int r = 0; - if (status & 0x20000000) + if (status & 0x20000000) r |= FP_TRAP_INVALID_OPERATION; - if (status & 0x10000000) + if (status & 0x10000000) r |= FP_TRAP_OVERFLOW; - if (status & 0x08000000) + if (status & 0x08000000) r |= FP_TRAP_UNDERFLOW; - if (status & 0x04000000) + if (status & 0x04000000) r |= FP_TRAP_ZERO_DIVIDE; - if (status & 0x02000000) + if (status & 0x02000000) r |= FP_TRAP_INEXACT; - return r; + return r; } /* Defined in assembly */ diff --git a/vm/cpu-x86.hpp b/vm/cpu-x86.hpp index 5f9fa15740..ac8ac51ade 100644 --- a/vm/cpu-x86.hpp +++ b/vm/cpu-x86.hpp @@ -55,20 +55,20 @@ inline static bool tail_call_site_p(cell return_address) inline static unsigned int fpu_status(unsigned int status) { - unsigned int r = 0; + unsigned int r = 0; - if (status & 0x01) + if (status & 0x01) r |= FP_TRAP_INVALID_OPERATION; - if (status & 0x04) + if (status & 0x04) r |= FP_TRAP_ZERO_DIVIDE; - if (status & 0x08) + if (status & 0x08) r |= FP_TRAP_OVERFLOW; - if (status & 0x10) + if (status & 0x10) r |= FP_TRAP_UNDERFLOW; - if (status & 0x20) + if (status & 0x20) r |= FP_TRAP_INEXACT; - return r; + return r; } } diff --git a/vm/data_heap.cpp b/vm/data_heap.cpp index d1809f09ce..22ef39e868 100755 --- a/vm/data_heap.cpp +++ b/vm/data_heap.cpp @@ -201,7 +201,7 @@ cell object::binary_payload_start() const return sizeof(wrapper); default: critical_error("Invalid header",(cell)this); - return 0; /* can't happen */ + return 0; /* can't happen */ } } diff --git a/vm/full_collector.cpp b/vm/full_collector.cpp index ec0972e952..849ef07084 100644 --- a/vm/full_collector.cpp +++ b/vm/full_collector.cpp @@ -67,7 +67,7 @@ void factor_vm::collect_mark_impl(bool trace_contexts_p) data->tenured->clear_mark_bits(); collector.trace_roots(); - if(trace_contexts_p) + if(trace_contexts_p) { collector.trace_contexts(); collector.trace_context_code_blocks(); diff --git a/vm/gc.hpp b/vm/gc.hpp index d80d57dafe..5224dec3e2 100755 --- a/vm/gc.hpp +++ b/vm/gc.hpp @@ -45,7 +45,7 @@ struct gc_event { struct gc_state { gc_op op; u64 start_time; - jmp_buf gc_unwind; + jmp_buf gc_unwind; gc_event *event; explicit gc_state(gc_op op_, factor_vm *parent); diff --git a/vm/jit.hpp b/vm/jit.hpp index 3889d92fc5..a9716cab79 100644 --- a/vm/jit.hpp +++ b/vm/jit.hpp @@ -61,7 +61,7 @@ struct jit { return position; } - void set_position(fixnum position_) + void set_position(fixnum position_) { if(computing_offset_p) position = position_; diff --git a/vm/math.cpp b/vm/math.cpp index ef4a599331..2ff6f28d2a 100755 --- a/vm/math.cpp +++ b/vm/math.cpp @@ -168,7 +168,7 @@ void factor_vm::primitive_bignum_xor() void factor_vm::primitive_bignum_shift() { fixnum y = untag_fixnum(ctx->pop()); - bignum* x = untag(ctx->pop()); + bignum* x = untag(ctx->pop()); ctx->push(tag(bignum_arithmetic_shift(x,y))); } diff --git a/vm/os-freebsd-x86.32.hpp b/vm/os-freebsd-x86.32.hpp index 5ed5cf0e81..664da1e997 100644 --- a/vm/os-freebsd-x86.32.hpp +++ b/vm/os-freebsd-x86.32.hpp @@ -6,35 +6,35 @@ namespace factor inline static unsigned int uap_fpu_status(void *uap) { - ucontext_t *ucontext = (ucontext_t *)uap; - if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_387) + ucontext_t *ucontext = (ucontext_t *)uap; + if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_387) { struct save87 *x87 = (struct save87 *)(&ucontext->uc_mcontext.mc_fpstate); return x87->sv_env.en_sw; - } + } else if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM) { struct savexmm *xmm = (struct savexmm *)(&ucontext->uc_mcontext.mc_fpstate); return xmm->sv_env.en_sw | xmm->sv_env.en_mxcsr; - } + } else return 0; } inline static void uap_clear_fpu_status(void *uap) { - ucontext_t *ucontext = (ucontext_t *)uap; - if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_387) + ucontext_t *ucontext = (ucontext_t *)uap; + if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_387) { struct save87 *x87 = (struct save87 *)(&ucontext->uc_mcontext.mc_fpstate); x87->sv_env.en_sw = 0; - } + } else if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM) { struct savexmm *xmm = (struct savexmm *)(&ucontext->uc_mcontext.mc_fpstate); xmm->sv_env.en_sw = 0; xmm->sv_env.en_mxcsr &= 0xffffffc0; - } + } } diff --git a/vm/os-freebsd-x86.64.hpp b/vm/os-freebsd-x86.64.hpp index 02f7fb3ad2..c691409dd1 100644 --- a/vm/os-freebsd-x86.64.hpp +++ b/vm/os-freebsd-x86.64.hpp @@ -6,25 +6,25 @@ namespace factor inline static unsigned int uap_fpu_status(void *uap) { - ucontext_t *ucontext = (ucontext_t *)uap; - if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM) + ucontext_t *ucontext = (ucontext_t *)uap; + if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM) { struct savefpu *xmm = (struct savefpu *)(&ucontext->uc_mcontext.mc_fpstate); return xmm->sv_env.en_sw | xmm->sv_env.en_mxcsr; - } + } else return 0; } inline static void uap_clear_fpu_status(void *uap) { - ucontext_t *ucontext = (ucontext_t *)uap; - if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM) + ucontext_t *ucontext = (ucontext_t *)uap; + if (ucontext->uc_mcontext.mc_fpformat == _MC_FPFMT_XMM) { struct savefpu *xmm = (struct savefpu *)(&ucontext->uc_mcontext.mc_fpstate); xmm->sv_env.en_sw = 0; xmm->sv_env.en_mxcsr &= 0xffffffc0; - } + } } diff --git a/vm/os-linux-x86.64.hpp b/vm/os-linux-x86.64.hpp index 14ba9fb002..7d764d61e3 100644 --- a/vm/os-linux-x86.64.hpp +++ b/vm/os-linux-x86.64.hpp @@ -5,16 +5,16 @@ namespace factor inline static unsigned int uap_fpu_status(void *uap) { - ucontext_t *ucontext = (ucontext_t *)uap; - return ucontext->uc_mcontext.fpregs->swd - | ucontext->uc_mcontext.fpregs->mxcsr; + ucontext_t *ucontext = (ucontext_t *)uap; + return ucontext->uc_mcontext.fpregs->swd + | ucontext->uc_mcontext.fpregs->mxcsr; } inline static void uap_clear_fpu_status(void *uap) { - ucontext_t *ucontext = (ucontext_t *)uap; - ucontext->uc_mcontext.fpregs->swd = 0; - ucontext->uc_mcontext.fpregs->mxcsr &= 0xffffffc0; + ucontext_t *ucontext = (ucontext_t *)uap; + ucontext->uc_mcontext.fpregs->swd = 0; + ucontext->uc_mcontext.fpregs->mxcsr &= 0xffffffc0; } #define UAP_STACK_POINTER(ucontext) (((ucontext_t *)ucontext)->uc_mcontext.gregs[15]) diff --git a/vm/os-windows-nt.cpp b/vm/os-windows-nt.cpp index 644ff83b44..07d428fb49 100755 --- a/vm/os-windows-nt.cpp +++ b/vm/os-windows-nt.cpp @@ -79,12 +79,12 @@ LONG factor_vm::exception_handler(PEXCEPTION_POINTERS pe) else signal_callstack_top = NULL; - switch (e->ExceptionCode) - { - case EXCEPTION_ACCESS_VIOLATION: + switch (e->ExceptionCode) + { + case EXCEPTION_ACCESS_VIOLATION: signal_fault_addr = e->ExceptionInformation[1]; c->EIP = (cell)factor::memory_signal_handler_impl; - break; + break; case STATUS_FLOAT_DENORMAL_OPERAND: case STATUS_FLOAT_DIVIDE_BY_ZERO: diff --git a/vm/vm.hpp b/vm/vm.hpp index 5d9b3204d3..20a837a58a 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -184,20 +184,20 @@ struct factor_vm void bignum_destructive_add(bignum * bignum, bignum_digit_type n); void bignum_destructive_scale_up(bignum * bignum, bignum_digit_type factor); void bignum_divide_unsigned_large_denominator(bignum * numerator, bignum * denominator, - bignum * * quotient, bignum * * remainder, int q_negative_p, int r_negative_p); + bignum * * quotient, bignum * * remainder, int q_negative_p, int r_negative_p); void bignum_divide_unsigned_normalized(bignum * u, bignum * v, bignum * q); bignum_digit_type bignum_divide_subtract(bignum_digit_type * v_start, bignum_digit_type * v_end, - bignum_digit_type guess, bignum_digit_type * u_start); + bignum_digit_type guess, bignum_digit_type * u_start); void bignum_divide_unsigned_medium_denominator(bignum * numerator,bignum_digit_type denominator, - bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p); + bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p); void bignum_destructive_normalization(bignum * source, bignum * target, int shift_left); void bignum_destructive_unnormalization(bignum * bignum, int shift_right); bignum_digit_type bignum_digit_divide(bignum_digit_type uh, bignum_digit_type ul, - bignum_digit_type v, bignum_digit_type * q) /* return value */; + bignum_digit_type v, bignum_digit_type * q) /* return value */; bignum_digit_type bignum_digit_divide_subtract(bignum_digit_type v1, bignum_digit_type v2, - bignum_digit_type guess, bignum_digit_type * u); + bignum_digit_type guess, bignum_digit_type * u); void bignum_divide_unsigned_small_denominator(bignum * numerator, bignum_digit_type denominator, - bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p); + bignum * * quotient, bignum * * remainder,int q_negative_p, int r_negative_p); bignum_digit_type bignum_destructive_scale_down(bignum * bignum, bignum_digit_type denominator); bignum * bignum_remainder_unsigned_small_denominator(bignum * n, bignum_digit_type d, int negative_p); bignum *bignum_digit_to_bignum(bignum_digit_type digit, int negative_p); @@ -314,7 +314,7 @@ struct factor_vm if(!(current_gc && current_gc->op == collect_growing_heap_op)) { assert((cell)pointer >= data->seg->start - && (cell)pointer < data->seg->end); + && (cell)pointer < data->seg->end); } #endif }