From 67c815bf187881dbebe6debe51d68253572d4efa Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Fri, 24 Jun 2022 23:27:00 +0100 Subject: [PATCH] expand symbol table (#1534) * expand symbol table * ah! * fix minor errors * fix kernel test * fix another test --- common/goal_constants.h | 10 +++++----- game/kernel/kscheme.cpp | 2 +- goal_src/engine/game/generic-obs.gc | 2 +- goal_src/kernel/gcommon.gc | 2 +- test/goalc/test_variables.cpp | 4 ++-- test/test_kernel.cpp | 3 ++- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/common/goal_constants.h b/common/goal_constants.h index a25888ca2d..c9d9ad83dc 100644 --- a/common/goal_constants.h +++ b/common/goal_constants.h @@ -13,10 +13,10 @@ constexpr int ARRAY_DATA_OFFSET = 12; // not including type tag * Here you can change the size of the symbol table! * Make sure to also edit the constant in gcommon.gc */ -constexpr s32 GOAL_MAX_SYMBOLS = 8192; // this MUST be a multiple of 2!! -constexpr s32 SYM_INFO_OFFSET = 8167 * 8 - 4; -// constexpr s32 GOAL_MAX_SYMBOLS = 16384; -// constexpr s32 SYM_INFO_OFFSET = GOAL_MAX_SYMBOLS * 8 - 4; +// constexpr s32 GOAL_MAX_SYMBOLS = 8192; // this MUST be a multiple of 2!! +// constexpr s32 SYM_INFO_OFFSET = 8167 * 8 - 4; +constexpr s32 GOAL_MAX_SYMBOLS = 16384; +constexpr s32 SYM_INFO_OFFSET = GOAL_MAX_SYMBOLS * 8 - 4; constexpr s32 SYM_TABLE_MEM_SIZE = GOAL_MAX_SYMBOLS * 8 * 2; @@ -34,7 +34,7 @@ constexpr int bits_for_sym() { } return b + 1; } -static_assert(bits_for_sym() != 1, "symbol table invalid length"); +static_assert(bits_for_sym() != -1, "symbol table invalid length"); enum class RegClass { GPR_64, FLOAT, INT_128, VECTOR_FLOAT, INVALID }; diff --git a/game/kernel/kscheme.cpp b/game/kernel/kscheme.cpp index ab13763564..932a190261 100644 --- a/game/kernel/kscheme.cpp +++ b/game/kernel/kscheme.cpp @@ -713,7 +713,7 @@ Ptr find_symbol_from_c(const char* name) { auto bits = bits_for_sym() - 1; s32 sh1 = hash << (0x20 - bits); s32 sh2 = sh1 >> (0x20 - bits - 3); - // will be signed, bottom 3 bits 0 (for alignment, symbol are every 8 bytes) + // will be signed, bottom 3 bits 0 (for alignment, symbols are every 8 bytes) // upper 16 bits are the same, so we will reach +/- 8 kb around 0. if (sh2 > 0) { diff --git a/goal_src/engine/game/generic-obs.gc b/goal_src/engine/game/generic-obs.gc index 357b21d8c0..7468eb63d3 100644 --- a/goal_src/engine/game/generic-obs.gc +++ b/goal_src/engine/game/generic-obs.gc @@ -1396,7 +1396,7 @@ ) ) ((= (-> s2-0 -1) symbol) - (set! s4-0 (-> (&+ s2-0 #xff38) 0)) + (set! s4-0 (symbol->string (the-as symbol s2-0))) (set! s3-0 (lookup-part-group-pointer-by-name (the-as string s4-0))) (if s3-0 (set! (-> s5-1 0) s3-0) diff --git a/goal_src/kernel/gcommon.gc b/goal_src/kernel/gcommon.gc index 5e103a136b..186e8a1c3a 100644 --- a/goal_src/kernel/gcommon.gc +++ b/goal_src/kernel/gcommon.gc @@ -35,7 +35,7 @@ ;; distance from a symbol pointer to a (pointer string) ;; this relies on the memory layout of the symbol table ;; this must match SYM_INFO_OFFSET in goal_constants.h + offset of the str field in struct SymUpper. -(defconstant SYM_TO_STRING_OFFSET #xff38) +(defconstant SYM_TO_STRING_OFFSET #x20000) ;; changed from #xff38 ;; pointers larger than this are invalid by valid? (defconstant END_OF_MEMORY #x8000000) diff --git a/test/goalc/test_variables.cpp b/test/goalc/test_variables.cpp index 0e1022793c..d04cd4beed 100644 --- a/test/goalc/test_variables.cpp +++ b/test/goalc/test_variables.cpp @@ -103,9 +103,9 @@ TEST_F(VariableTests, StackStructureAlignment) { TEST_F(VariableTests, GetSymbol) { shared_compiler->runner.run_static_test(env, testCategory, "get-symbol-1.static.gc", - {"1342756\n"}); // 0x147d24 in hex + {"1375524\n"}); // 0x14fd24 in hex shared_compiler->runner.run_static_test(env, testCategory, "get-symbol-2.static.gc", - {"1342764\n"}); // 0x147d2c in hex + {"1375532\n"}); // 0x14fd2c in hex } TEST_F(VariableTests, Constants) { diff --git a/test/test_kernel.cpp b/test/test_kernel.cpp index a39d490cba..1308253cec 100644 --- a/test/test_kernel.cpp +++ b/test/test_kernel.cpp @@ -304,7 +304,8 @@ void setup_hack_heaps(void* mem, int size) { init_crc(); // create a fake symbol table - auto symbol_table = kmalloc(kglobalheap, 0x20000, KMALLOC_MEMSET, "symbol-table").cast(); + auto symbol_table = + kmalloc(kglobalheap, SYM_TABLE_MEM_SIZE, KMALLOC_MEMSET, "symbol-table").cast(); s7 = symbol_table + (GOAL_MAX_SYMBOLS / 2) * 8 + BASIC_OFFSET; SymbolTable2 = symbol_table + BASIC_OFFSET; LastSymbol = symbol_table + 0xff00;