mirror of
https://github.com/corda/corda.git
synced 2025-01-05 20:54:13 +00:00
move bitmap helper functions to common.h; preserve callee-saved registers in vmInvoke()
This commit is contained in:
parent
201a658941
commit
3e1dbab0f0
18
src/common.h
18
src/common.h
@ -127,6 +127,24 @@ indexOf(unsigned word, unsigned bit)
|
|||||||
return (word * BitsPerWord) + bit;
|
return (word * BitsPerWord) + bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
markBit(uintptr_t* map, unsigned i)
|
||||||
|
{
|
||||||
|
map[wordOf(i)] |= static_cast<uintptr_t>(1) << bitOf(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
clearBit(uintptr_t* map, unsigned i)
|
||||||
|
{
|
||||||
|
map[wordOf(i)] &= ~(static_cast<uintptr_t>(1) << bitOf(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned
|
||||||
|
getBit(uintptr_t* map, unsigned i)
|
||||||
|
{
|
||||||
|
return map[wordOf(i)] & (static_cast<uintptr_t>(1) << bitOf(i));
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
inline T&
|
inline T&
|
||||||
cast(void* p, unsigned offset)
|
cast(void* p, unsigned offset)
|
||||||
|
@ -9,12 +9,16 @@ vmInvoke:
|
|||||||
pushq %rbp
|
pushq %rbp
|
||||||
movq %rsp,%rbp
|
movq %rsp,%rbp
|
||||||
|
|
||||||
|
// rbx is a callee-saved register (so are r12-r15, but we don't use those)
|
||||||
|
pushq %rbx
|
||||||
|
|
||||||
// %rdi: function
|
// %rdi: function
|
||||||
// %rsi: stack
|
// %rsi: stack
|
||||||
// %rdx: stackSize
|
// %rdx: stackSize
|
||||||
// %rcx: returnType
|
// %rcx: returnType
|
||||||
|
|
||||||
// reserve space for arguments
|
// reserve space for arguments
|
||||||
|
pushq %rdx
|
||||||
subq %rdx,%rsp
|
subq %rdx,%rsp
|
||||||
|
|
||||||
// copy memory arguments into place
|
// copy memory arguments into place
|
||||||
@ -36,7 +40,12 @@ test:
|
|||||||
|
|
||||||
// call function
|
// call function
|
||||||
call *%rdi
|
call *%rdi
|
||||||
|
|
||||||
|
// pop arguments
|
||||||
|
addq -16(%rbp),%rsp
|
||||||
|
addq $8,%rsp
|
||||||
|
|
||||||
|
popq %rbx
|
||||||
movq %rbp,%rsp
|
movq %rbp,%rsp
|
||||||
popq %rbp
|
popq %rbp
|
||||||
ret
|
ret
|
||||||
@ -54,15 +63,18 @@ vmInvoke:
|
|||||||
pushl %ebp
|
pushl %ebp
|
||||||
movl %esp,%ebp
|
movl %esp,%ebp
|
||||||
|
|
||||||
|
// ebx, esi and edi are callee-saved registers
|
||||||
|
pushl %ebx
|
||||||
|
pushl %esi
|
||||||
|
pushl %edi
|
||||||
|
|
||||||
// 8(%ebp): function
|
// 8(%ebp): function
|
||||||
// 12(%ebp): stack
|
// 12(%ebp): stack
|
||||||
// 16(%ebp): stackSize
|
// 16(%ebp): stackSize
|
||||||
// 20(%ebp): returnType
|
// 20(%ebp): returnType
|
||||||
|
|
||||||
// reserve space for arguments
|
// reserve space for arguments
|
||||||
movl 16(%ebp),%ecx
|
subl 16(%ebp),%esp
|
||||||
|
|
||||||
subl %ecx,%esp
|
|
||||||
|
|
||||||
// copy arguments into place
|
// copy arguments into place
|
||||||
movl $0,%ecx
|
movl $0,%ecx
|
||||||
@ -84,6 +96,9 @@ test:
|
|||||||
// call function
|
// call function
|
||||||
call *8(%ebp)
|
call *8(%ebp)
|
||||||
|
|
||||||
|
// pop arguments
|
||||||
|
addl 16(%ebp),%esp
|
||||||
|
|
||||||
// handle return value based on expected type
|
// handle return value based on expected type
|
||||||
movl 20(%ebp),%ecx
|
movl 20(%ebp),%ecx
|
||||||
|
|
||||||
@ -101,6 +116,9 @@ int32:
|
|||||||
movl $0,%edx
|
movl $0,%edx
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
popl %edi
|
||||||
|
popl %esi
|
||||||
|
popl %ebx
|
||||||
movl %ebp,%esp
|
movl %ebp,%esp
|
||||||
popl %ebp
|
popl %ebp
|
||||||
ret
|
ret
|
||||||
|
@ -28,24 +28,6 @@ const unsigned FrameFootprint = BytesPerWord * 3;
|
|||||||
|
|
||||||
class ArgumentList;
|
class ArgumentList;
|
||||||
|
|
||||||
inline void
|
|
||||||
markBit(uintptr_t* map, unsigned i)
|
|
||||||
{
|
|
||||||
map[wordOf(i)] |= static_cast<uintptr_t>(1) << bitOf(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void
|
|
||||||
clearBit(uintptr_t* map, unsigned i)
|
|
||||||
{
|
|
||||||
map[wordOf(i)] &= ~(static_cast<uintptr_t>(1) << bitOf(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline unsigned
|
|
||||||
getBit(uintptr_t* map, unsigned i)
|
|
||||||
{
|
|
||||||
return map[wordOf(i)] & (static_cast<uintptr_t>(1) << bitOf(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
class Buffer {
|
class Buffer {
|
||||||
public:
|
public:
|
||||||
Buffer(System* s, unsigned minimumCapacity):
|
Buffer(System* s, unsigned minimumCapacity):
|
||||||
@ -318,8 +300,8 @@ class StackMapper {
|
|||||||
|
|
||||||
unsigned i = index[ip];
|
unsigned i = index[ip];
|
||||||
while (true) {
|
while (true) {
|
||||||
fprintf(stderr, "event %d; ip %d; sp %d; local size %d; map size %d\n",
|
// fprintf(stderr, "event %d; ip %d; sp %d; local size %d; map size %d\n",
|
||||||
log.get(i), ip, sp, localSize(), mapSize());
|
// log.get(i), ip, sp, localSize(), mapSize());
|
||||||
|
|
||||||
switch (log.get(i++)) {
|
switch (log.get(i++)) {
|
||||||
case Call: {
|
case Call: {
|
||||||
|
@ -206,13 +206,13 @@ class Segment {
|
|||||||
void clearBit(unsigned i) {
|
void clearBit(unsigned i) {
|
||||||
assert(segment->context, wordOf(i) < size());
|
assert(segment->context, wordOf(i) < size());
|
||||||
|
|
||||||
data()[wordOf(i)] &= ~(static_cast<uintptr_t>(1) << bitOf(i));
|
vm::clearBit(data(), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBit(unsigned i) {
|
void setBit(unsigned i) {
|
||||||
assert(segment->context, wordOf(i) < size());
|
assert(segment->context, wordOf(i) < size());
|
||||||
|
|
||||||
data()[wordOf(i)] |= static_cast<uintptr_t>(1) << bitOf(i);
|
vm::markBit(data(), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearOnlyIndex(unsigned index) {
|
void clearOnlyIndex(unsigned index) {
|
||||||
@ -738,9 +738,9 @@ bitsetSet(uintptr_t* p, unsigned i, bool v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (v) {
|
if (v) {
|
||||||
p[wordOf(i)] |= static_cast<uintptr_t>(1) << bitOf(i);
|
markBit(p, i);
|
||||||
} else {
|
} else {
|
||||||
p[wordOf(i)] &= ~(static_cast<uintptr_t>(1) << bitOf(i));
|
clearBit(p, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user