This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8788a2b
commit 83d15bb
Showing
9 changed files
with
262 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ MANIFEST= \ | |
README.txt \ | ||
posix.mak \ | ||
win32.mak \ | ||
win64.mak \ | ||
\ | ||
src/object_.d \ | ||
src/object.di \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,11 +138,19 @@ extern (C) void* __alloca(int nbytes) | |
} | ||
else version (D_InlineAsm_X86_64) | ||
{ | ||
version (Win64) | ||
{ | ||
asm | ||
{ | ||
/* RCX nbytes | ||
* RDX address of variable with # of bytes in locals | ||
* Must save registers RBX,RDI,RSI,R12..R15 | ||
*/ | ||
naked ; | ||
mov RDX,RCX ; | ||
mov RAX,RDI ; // get nbytes | ||
push RBX ; | ||
push RDI ; | ||
push RSI ; | ||
mov RAX,RCX ; // get nbytes | ||
add RAX,15 ; | ||
and AL,0xF0 ; // round up to 16 byte boundary | ||
test RAX,RAX ; | ||
|
@@ -153,11 +161,7 @@ extern (C) void* __alloca(int nbytes) | |
neg RAX ; | ||
add RAX,RSP ; // RAX is now what the new RSP will be. | ||
jae Aoverflow ; | ||
} | ||
version (Win64) | ||
{ | ||
asm | ||
{ | ||
|
||
// We need to be careful about the guard page | ||
// Thus, for every 4k page, touch it to cause the OS to load it in. | ||
mov RCX,RAX ; // RCX is new location for stack | ||
|
@@ -167,8 +171,54 @@ extern (C) void* __alloca(int nbytes) | |
sub RBX,0x1000 ; // next 4K page down | ||
jae L1 ; // if more pages | ||
test [RCX],RBX ; // bring in last page | ||
|
||
// Copy down to [RSP] the temps on the stack. | ||
// The number of temps is (RBP - RSP - locals). | ||
mov RCX,RBP ; | ||
sub RCX,RSP ; | ||
sub RCX,[RDX] ; // RCX = number of temps (bytes) to move. | ||
add [RDX],RSI ; // adjust locals by nbytes for next call to alloca() | ||
mov RSP,RAX ; // Set up new stack pointer. | ||
add RAX,RCX ; // Return value = RSP + temps. | ||
mov RDI,RSP ; // Destination of copy of temps. | ||
add RSI,RSP ; // Source of copy. | ||
shr RCX,3 ; // RCX to count of qwords in temps | ||
rep ; | ||
movsq ; | ||
jmp done ; | ||
|
||
Aoverflow: | ||
// Overflowed the stack. Return null | ||
xor RAX,RAX ; | ||
|
||
done: | ||
pop RSI ; | ||
pop RDI ; | ||
pop RBX ; | ||
ret ; | ||
} | ||
} | ||
else | ||
{ | ||
asm | ||
{ | ||
/* Parameter is passed in RDI | ||
* Must save registers RBX,R12..R15 | ||
*/ | ||
naked ; | ||
mov RDX,RCX ; | ||
mov RAX,RDI ; // get nbytes | ||
add RAX,15 ; | ||
and AL,0xF0 ; // round up to 16 byte boundary | ||
test RAX,RAX ; | ||
jnz Abegin ; | ||
mov RAX,16 ; // allow zero bytes allocation | ||
Abegin: | ||
mov RSI,RAX ; // RSI = nbytes | ||
neg RAX ; | ||
add RAX,RSP ; // RAX is now what the new RSP will be. | ||
jae Aoverflow ; | ||
} | ||
version (Unix) | ||
{ | ||
asm | ||
|
@@ -201,6 +251,7 @@ extern (C) void* __alloca(int nbytes) | |
done: | ||
ret ; | ||
} | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jmdavis
Member
|
||
} | ||
else | ||
static assert(0); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Is some indentation off here?