From c5b6e6e28c9cb00d3ea5e6b095578b1b8ac2d3db Mon Sep 17 00:00:00 2001 From: Veikko Sariola Date: Wed, 27 May 2020 17:08:35 +0300 Subject: [PATCH] Move su_load_gmdls into the responsibility of the intro to call, anticipating multicore rendering so it is called once before all the cores are spun up. --- src/sointu.asm | 3 --- src/win32/gmdls_win32.asm | 16 ++++++++-------- src/win64/gmdls_win64.asm | 22 ++++++++++++---------- tests/CMakeLists.txt | 2 ++ tests/test_oscillat_sample.asm | 1 - tests/test_oscillat_sample_stereo.asm | 1 - tests/test_renderer.c | 8 ++++++++ 7 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/sointu.asm b/src/sointu.asm index 0745d08..509bd53 100644 --- a/src/sointu.asm +++ b/src/sointu.asm @@ -339,9 +339,6 @@ SECT_TEXT(surender) EXPORT MANGLE_FUNC(su_render,PTRSIZE) ; Stack: ptr render_prologue -%ifdef INCLUDE_GMDLS - call su_gmdls_load -%endif xor eax, eax %ifdef INCLUDE_MULTIVOICE_TRACKS push VOICETRACK_BITMASK diff --git a/src/win32/gmdls_win32.asm b/src/win32/gmdls_win32.asm index b43850f..429f606 100644 --- a/src/win32/gmdls_win32.asm +++ b/src/win32/gmdls_win32.asm @@ -7,21 +7,21 @@ extern _ReadFile@20 ; requires windows SECT_TEXT(sugmdls) -su_gmdls_load: - mov edi, MANGLE_DATA(su_sample_table) - mov esi, su_gmdls_path1 +EXPORT MANGLE_FUNC(su_load_gmdls,0) + mov edx, MANGLE_DATA(su_sample_table) + mov ecx, su_gmdls_path1 su_gmdls_pathloop: push 0 ; OF_READ - push edi ; &ofstruct, blatantly reuse the sample table - push esi ; path + push edx ; &ofstruct, blatantly reuse the sample table + push ecx ; path call _OpenFile@12 ; eax = OpenFile(path,&ofstruct,OF_READ) - add esi, su_gmdls_path2 - su_gmdls_path1 ; if we ever get to third, then crash + add ecx, su_gmdls_path2 - su_gmdls_path1 ; if we ever get to third, then crash cmp eax, -1 ; eax == INVALID? je su_gmdls_pathloop push 0 ; NULL - push edi ; &bytes_read, reusing sample table again; it does not matter that the first four bytes are trashed + push edx ; &bytes_read, reusing sample table again; it does not matter that the first four bytes are trashed push SAMPLE_TABLE_SIZE ; number of bytes to read - push edi ; here we actually pass the sample table to readfile + push edx ; here we actually pass the sample table to readfile push eax ; handle to file call _ReadFile@20 ; Readfile(handle,&su_sample_table,SAMPLE_TABLE_SIZE,&bytes_read,NULL) ret diff --git a/src/win64/gmdls_win64.asm b/src/win64/gmdls_win64.asm index 43fd208..11f7eae 100644 --- a/src/win64/gmdls_win64.asm +++ b/src/win64/gmdls_win64.asm @@ -6,24 +6,26 @@ extern OpenFile ; requires windows extern ReadFile ; requires windows SECT_TEXT(sugmdls) + +EXPORT MANGLE_FUNC(su_load_gmdls,0) ; Win64 ABI: RCX, RDX, R8, and R9 -su_gmdls_load: sub rsp, 40 ; Win64 ABI requires "shadow space" + space for one parameter. - mov rdi, PTRWORD MANGLE_DATA(su_sample_table) - mov rsi, PTRWORD su_gmdls_path1 + mov rdx, PTRWORD MANGLE_DATA(su_sample_table) + mov rcx, PTRWORD su_gmdls_path1 su_gmdls_pathloop: xor r8,r8 ; OF_READ - mov rdx, rdi ; &ofstruct, blatantly reuse the sample table - mov rcx, rsi ; path + push rdx ; &ofstruct, blatantly reuse the sample table + push rcx call OpenFile ; eax = OpenFile(path,&ofstruct,OF_READ) - add rsi, su_gmdls_path2 - su_gmdls_path1 ; if we ever get to third, then crash - movsxd rcx,eax - cmp rcx, -1 ; ecx == INVALID? + pop rcx + add rcx, su_gmdls_path2 - su_gmdls_path1 ; if we ever get to third, then crash + pop rdx + cmp eax, -1 ; ecx == INVALID? je su_gmdls_pathloop + movsxd rcx, eax mov qword [rsp+32],0 - mov r9, rdi + mov r9, rdx mov r8d, SAMPLE_TABLE_SIZE ; number of bytes to read - mov rdx, rdi call ReadFile ; Readfile(handle,&su_sample_table,SAMPLE_TABLE_SIZE,&bytes_read,NULL) add rsp, 40 ; shadow space, as required by Win64 ABI ret diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 804de30..a7fcc0b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -93,7 +93,9 @@ regression_test(test_oscillat_gate ENVELOPE) regression_test(test_oscillat_stereo ENVELOPE) if(WIN32) # The samples are currently only GMDLs based, and thus require Windows. regression_test(test_oscillat_sample ENVELOPE) + target_compile_definitions(test_oscillat_sample PUBLIC INCLUDE_GMDLS) regression_test(test_oscillat_sample_stereo ENVELOPE) + target_compile_definitions(test_oscillat_sample_stereo PUBLIC INCLUDE_GMDLS) endif() regression_test(test_oscillat_unison ENVELOPE) regression_test(test_oscillat_unison_stereo ENVELOPE) diff --git a/tests/test_oscillat_sample.asm b/tests/test_oscillat_sample.asm index a331f29..7f14942 100644 --- a/tests/test_oscillat_sample.asm +++ b/tests/test_oscillat_sample.asm @@ -1,5 +1,4 @@ %define BPM 100 -%define INCLUDE_GMDLS %include "../src/sointu.inc" diff --git a/tests/test_oscillat_sample_stereo.asm b/tests/test_oscillat_sample_stereo.asm index 0ad12ec..1f4f4c4 100644 --- a/tests/test_oscillat_sample_stereo.asm +++ b/tests/test_oscillat_sample_stereo.asm @@ -1,5 +1,4 @@ %define BPM 100 -%define INCLUDE_GMDLS %include "../src/sointu.inc" diff --git a/tests/test_renderer.c b/tests/test_renderer.c index d90d44b..c2c88f2 100644 --- a/tests/test_renderer.c +++ b/tests/test_renderer.c @@ -26,6 +26,10 @@ #endif extern void CALLCONV su_render(void *); +#ifdef INCLUDE_GMDLS +extern void CALLCONV su_load_gmdls(void); +#endif + extern int su_max_samples; int main(int argc, char* argv[]) { @@ -59,6 +63,10 @@ int main(int argc, char* argv[]) { return 1; } + #ifdef INCLUDE_GMDLS + su_load_gmdls(); + #endif + su_render(buf); snprintf(filename, sizeof filename, "%s%s%s", expected_output_folder, test_name, ".raw");