summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-08-22 15:58:28 -0400
committerGitHub <noreply@github.com>2019-08-22 15:58:28 -0400
commit06a0e3980fd04fa265bd20eb11f2abc18bd6a215 (patch)
treeea664d7f0ecfa4b6948319d4fcfb0bbd1e3af888 /source/core
parentbc392f9dbfb8cb6c359bb890fb85b831e49bfd55 (diff)
WIP: CPU compute coverage (#1030)
* Add support for '=' when defining a name in test. * Add support for double intrinsics. * Add support for asdouble Add findOrAddInst - used instead of findOrEmitHoistableInst, for nominal instructions. Support cloning of string literals. C++ working on more compute tests. * Constant buffer support in reflection. Fixed debugging into source for generated C++. buffer-layout.slang works. * Added cpu test result. * Remove some commented out code. Comment on next fixes. * Improvements to reflection CPU code. * C++ working with ByteAddressBuffer. * Enabled more compute tests for CPU. * Enabled more compute tests on CPU. Added support for [] style access to a vector. * Enabled more CPU compute tests. * Handling of buffer-type-splitting.slang Named buffers can be paths to resources * Fix some warnings, remove some dead code. * Fix problem with verification of number of operands for asuint/asint as they can have 1 or 3 operands. asdouble takes 2. * Fix handling in MemoryArena around aligned allocations. That _allocateAlignedFromNewBlock assumed the block allocated has the aligment that was requested and so did not correct the start address.
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-memory-arena.cpp35
-rw-r--r--source/core/slang-token-reader.h9
2 files changed, 30 insertions, 14 deletions
diff --git a/source/core/slang-memory-arena.cpp b/source/core/slang-memory-arena.cpp
index 99e6261ff..a9fc1ec19 100644
--- a/source/core/slang-memory-arena.cpp
+++ b/source/core/slang-memory-arena.cpp
@@ -42,19 +42,19 @@ void MemoryArena::_initialize(size_t blockPayloadSize, size_t alignment)
// Ensure it's alignment is at least kMinAlignment
alignment = (alignment < kMinAlignment) ? kMinAlignment : alignment;
+ const size_t alignMask = alignment - 1;
+
+ // Make sure the payload is rounded up to the alignment
+ blockPayloadSize = (blockPayloadSize + alignMask) & ~alignMask;
+
m_blockPayloadSize = blockPayloadSize;
- size_t blockAllocSize = blockPayloadSize;
// If alignment required is larger then the backing allocators then
// make larger to ensure when alignment correction takes place it will be aligned
- if (alignment > kMinAlignment)
- {
- blockAllocSize += alignment;
- }
-
+ const size_t blockAllocSize = (alignment > kMinAlignment) ? (blockPayloadSize + alignment) : blockPayloadSize;
+
m_blockAllocSize = blockAllocSize;
m_blockAlignment = alignment;
-
m_availableBlocks = nullptr;
m_blockFreeList.init(sizeof(Block), sizeof(void*), 16);
@@ -217,12 +217,17 @@ MemoryArena::Block* MemoryArena::_newNormalBlock()
return block;
}
- return _newBlock(m_blockAllocSize, m_blockAlignment);
+ Block* block = _newBlock(m_blockAllocSize, m_blockAlignment);
+ // Check that every normal block has m_blockPayloadSize space
+ assert(size_t(block->m_end - block->m_start) >= m_blockPayloadSize);
+ return block;
}
MemoryArena::Block* MemoryArena::_newBlock(size_t allocSize, size_t alignment)
{
assert(alignment >= m_blockAlignment);
+ // Alignment must be a power of 2
+ assert(((alignment - 1) & alignment) == 0);
// Allocate block
Block* block = (Block*)m_blockFreeList.allocate();
@@ -289,9 +294,10 @@ void* MemoryArena::_allocateAlignedFromNewBlock(size_t size, size_t alignment)
//
// An improvement might be to have some abstraction that sits on top that can do this tracking (or have the blocks
// themselves record if they alias over a previously used block - but we don't bother with this here.
- if (allocSize > m_blockAllocSize)
+ // If the alignment is greater than regular alignment we need to handle specially
+ if (allocSize > m_blockPayloadSize || (alignment > m_blockAlignment && allocSize + alignment > m_blockPayloadSize))
{
- // This is an odd-sized block so just allocate the whole thing
+ // This is an odd-sized block so just allocate the whole thing.
block = _newBlock(allocSize, alignment);
}
else
@@ -310,10 +316,11 @@ void* MemoryArena::_allocateAlignedFromNewBlock(size_t size, size_t alignment)
// Make the current block
_addCurrentBlock(block);
- // Allocated memory is just the start of this block
- uint8_t* memory = m_current;
- // It must already be aligned
- assert((size_t(m_current) & alignMask) == 0);
+ // Align the memory
+ uint8_t* memory = (uint8_t*)((size_t(m_current) + alignMask) & ~alignMask);
+
+ // It must be aligned
+ assert((size_t(memory) & alignMask) == 0);
// Do the aligned allocation (which must fit) by aligning the pointer
// It must fit if the previous code is correct...
diff --git a/source/core/slang-token-reader.h b/source/core/slang-token-reader.h
index f8a455452..474db5c4a 100644
--- a/source/core/slang-token-reader.h
+++ b/source/core/slang-token-reader.h
@@ -189,6 +189,15 @@ namespace Slang
{
tokenPtr -= count;
}
+ Token ReadMatchingToken(TokenType type)
+ {
+ auto token = ReadToken();
+ if (token.Type != type)
+ {
+ throw TextFormatException("Text parsing error: unexpected token.");
+ }
+ return token;
+ }
Token ReadToken()
{
if (tokenPtr < (int)tokens.getCount())