diff --git a/ci-tests/atomics.c b/ci-tests/atomics.c new file mode 100644 index 00000000..ece5a38b --- /dev/null +++ b/ci-tests/atomics.c @@ -0,0 +1,20 @@ +#include +#include + +atomic_int acnt = 0; +atomic_int bcnt = 0; + +int foo() { + for(int n = 0; n < 1000; ++n) { + ++acnt; + if(acnt % 10 == 0) + ++bcnt; + } + return acnt; +} + +int main(void) { + int acnt = foo(); + printf("First atomic counter is %u, second is %u\n", acnt, bcnt); + return 0; +} diff --git a/ci-tests/create-ci-binary-tarball b/ci-tests/create-ci-binary-tarball index 73a549e0..1080d0ab 100755 --- a/ci-tests/create-ci-binary-tarball +++ b/ci-tests/create-ci-binary-tarball @@ -20,10 +20,16 @@ mkdir -p build/dummycsr && cd "$_" riscv64-unknown-elf-gcc -O2 -o customcsr `git rev-parse --show-toplevel`/ci-tests/customcsr.c cd - +mkdir -p build/atomics && cd "$_" +riscv64-unknown-elf-gcc -O2 -o atomics `git rev-parse --show-toplevel`/ci-tests/atomics.c +cd - + + mv build/pk/pk . mv build/hello/hello . mv build/dummy-slliuw/dummy-slliuw . mv build/dummycsr/customcsr . -tar -cf spike-ci.tar pk hello dummy-slliuw customcsr +mv build/atomics/atomics . +tar -cf spike-ci.tar pk hello dummy-slliuw customcsr atomics -rm pk hello dummy-slliuw customcsr +rm pk hello dummy-slliuw customcsr atomics diff --git a/ci-tests/test-spike b/ci-tests/test-spike index 36b748af..6fe5bdb2 100755 --- a/ci-tests/test-spike +++ b/ci-tests/test-spike @@ -11,6 +11,7 @@ cd run wget https://github.com/riscv-software-src/riscv-isa-sim/releases/download/dummy-tag-for-ci-storage/spike-ci.tar tar xf spike-ci.tar time ../install/bin/spike --isa=rv64gc pk hello | grep "Hello, world! Pi is approximately 3.141588." +../install/bin/spike --log-commits --isa=rv64gc pk atomics | grep "First atomic counter is 1000, second is 100" # check that including sim.h in an external project works g++ -std=c++2a -I../install/include -L../install/lib $DIR/testlib.cc -lriscv -o test-libriscv diff --git a/riscv/mmu.cc b/riscv/mmu.cc index 8d6af8d6..30fc47aa 100644 --- a/riscv/mmu.cc +++ b/riscv/mmu.cc @@ -369,7 +369,7 @@ void mmu_t::store_slow_path(reg_t original_addr, reg_t len, const uint8_t* bytes store_slow_path_intrapage(len, bytes, access_info, actually_store); } - if (proc && unlikely(proc->get_log_commits_enabled())) + if (actually_store && proc && unlikely(proc->get_log_commits_enabled())) proc->state.log_mem_write.push_back(std::make_tuple(original_addr, reg_from_bytes(len, bytes), len)); }