Skip to content

Commit

Permalink
Use thread local state in demo
Browse files Browse the repository at this point in the history
  • Loading branch information
alastairreid committed Jan 7, 2025
1 parent 2fec840 commit 7ba0026
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
6 changes: 3 additions & 3 deletions demo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ CC=clang-16 -std=c2x

.PRECIOUS: simulator_%

simulator_% : simulator.c exports.json demo.asl
simulator_% : simulator.c config.json demo.asl
@ if ${HAVE_GNU_AS}; then \
$(ASL2C) --basename=sim --intermediates=log --backend=$* > sim.prj ; \
env ASL_PATH="${ASL_PATH}" $(ASLI) --nobanner --batchmode --project=sim.prj --configuration=exports.json demo.asl ; \
$(ASL2C) --basename=sim --intermediates=log --split-state --backend=$* > sim.prj ; \
env ASL_PATH="${ASL_PATH}" $(ASLI) --nobanner --batchmode --project=sim.prj --configuration=config.json demo.asl ; \
$(CC) ${CFLAGS} simulator.c -o $@ ${LDFLAGS} ; \
else echo ${REPORT_NOT_GAS}; fi

Expand Down
10 changes: 9 additions & 1 deletion demo/exports.json → demo/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
"ASL_WriteReg64",
"ASL_WriteMemory8",
"PrintState"
]
],

"__comment": [
"Split the variables into shared (global) and thread-local."
],
"split_state": {
"global_state": ["__Memory"],
"threadlocal_state" : [".*"]
}
}

16 changes: 16 additions & 0 deletions demo/simulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ UNUSED static void set_register(const char* name, uint64_t val)
* Simulator
****************************************************************/

// Storage for the thread-local state in a processor.
// (Note that the variables 'threadlocal_state_ptr' and 'global_state_ptr'
// need to point to these structs and their initializers need to be
// called.)
struct threadlocal_state Processor0;
struct global_state Global;

int main(int argc, const char* argv[])
{
ASL_error_file = stderr;
Expand All @@ -240,6 +247,15 @@ int main(int argc, const char* argv[])
exit(1);
}
exception_clear();

// Initialize all the state structs
ASL_initialize_threadlocal_state(&Processor0);
ASL_initialize_global_state(&Global);

// Set the state pointers
threadlocal_state_ptr = &Processor0;
global_state_ptr = &Global;

ASL_Reset_0();
exception_check("ASL_Reset");

Expand Down

0 comments on commit 7ba0026

Please sign in to comment.