From 3e1dbab0f019cdb87b9df360be0ad44ca727d69f Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 11 Oct 2007 20:52:16 -0600 Subject: [PATCH] move bitmap helper functions to common.h; preserve callee-saved registers in vmInvoke() --- src/common.h | 18 ++++++++++++++++++ src/compile.S | 24 +++++++++++++++++++++--- src/compile.cpp | 22 ++-------------------- src/heap.cpp | 8 ++++---- 4 files changed, 45 insertions(+), 27 deletions(-) diff --git a/src/common.h b/src/common.h index c1011c6cd7..f80c455057 100644 --- a/src/common.h +++ b/src/common.h @@ -127,6 +127,24 @@ indexOf(unsigned word, unsigned bit) return (word * BitsPerWord) + bit; } +inline void +markBit(uintptr_t* map, unsigned i) +{ + map[wordOf(i)] |= static_cast(1) << bitOf(i); +} + +inline void +clearBit(uintptr_t* map, unsigned i) +{ + map[wordOf(i)] &= ~(static_cast(1) << bitOf(i)); +} + +inline unsigned +getBit(uintptr_t* map, unsigned i) +{ + return map[wordOf(i)] & (static_cast(1) << bitOf(i)); +} + template inline T& cast(void* p, unsigned offset) diff --git a/src/compile.S b/src/compile.S index 40f6630e06..328685e374 100644 --- a/src/compile.S +++ b/src/compile.S @@ -9,12 +9,16 @@ vmInvoke: pushq %rbp movq %rsp,%rbp + // rbx is a callee-saved register (so are r12-r15, but we don't use those) + pushq %rbx + // %rdi: function // %rsi: stack // %rdx: stackSize // %rcx: returnType // reserve space for arguments + pushq %rdx subq %rdx,%rsp // copy memory arguments into place @@ -36,7 +40,12 @@ test: // call function call *%rdi + + // pop arguments + addq -16(%rbp),%rsp + addq $8,%rsp + popq %rbx movq %rbp,%rsp popq %rbp ret @@ -54,15 +63,18 @@ vmInvoke: pushl %ebp movl %esp,%ebp + // ebx, esi and edi are callee-saved registers + pushl %ebx + pushl %esi + pushl %edi + // 8(%ebp): function // 12(%ebp): stack // 16(%ebp): stackSize // 20(%ebp): returnType // reserve space for arguments - movl 16(%ebp),%ecx - - subl %ecx,%esp + subl 16(%ebp),%esp // copy arguments into place movl $0,%ecx @@ -84,6 +96,9 @@ test: // call function call *8(%ebp) + // pop arguments + addl 16(%ebp),%esp + // handle return value based on expected type movl 20(%ebp),%ecx @@ -101,6 +116,9 @@ int32: movl $0,%edx exit: + popl %edi + popl %esi + popl %ebx movl %ebp,%esp popl %ebp ret diff --git a/src/compile.cpp b/src/compile.cpp index c944aca14d..7d39109c6b 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -28,24 +28,6 @@ const unsigned FrameFootprint = BytesPerWord * 3; class ArgumentList; -inline void -markBit(uintptr_t* map, unsigned i) -{ - map[wordOf(i)] |= static_cast(1) << bitOf(i); -} - -inline void -clearBit(uintptr_t* map, unsigned i) -{ - map[wordOf(i)] &= ~(static_cast(1) << bitOf(i)); -} - -inline unsigned -getBit(uintptr_t* map, unsigned i) -{ - return map[wordOf(i)] & (static_cast(1) << bitOf(i)); -} - class Buffer { public: Buffer(System* s, unsigned minimumCapacity): @@ -318,8 +300,8 @@ class StackMapper { unsigned i = index[ip]; while (true) { - fprintf(stderr, "event %d; ip %d; sp %d; local size %d; map size %d\n", - log.get(i), ip, sp, localSize(), mapSize()); +// fprintf(stderr, "event %d; ip %d; sp %d; local size %d; map size %d\n", +// log.get(i), ip, sp, localSize(), mapSize()); switch (log.get(i++)) { case Call: { diff --git a/src/heap.cpp b/src/heap.cpp index 73e9a9c42e..409edda161 100644 --- a/src/heap.cpp +++ b/src/heap.cpp @@ -206,13 +206,13 @@ class Segment { void clearBit(unsigned i) { assert(segment->context, wordOf(i) < size()); - data()[wordOf(i)] &= ~(static_cast(1) << bitOf(i)); + vm::clearBit(data(), i); } void setBit(unsigned i) { assert(segment->context, wordOf(i) < size()); - data()[wordOf(i)] |= static_cast(1) << bitOf(i); + vm::markBit(data(), i); } void clearOnlyIndex(unsigned index) { @@ -738,9 +738,9 @@ bitsetSet(uintptr_t* p, unsigned i, bool v) } if (v) { - p[wordOf(i)] |= static_cast(1) << bitOf(i); + markBit(p, i); } else { - p[wordOf(i)] &= ~(static_cast(1) << bitOf(i)); + clearBit(p, i); } }