From f8b5045f9987fd18c16dd0d4adf2ea1223017f1a Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sun, 24 Oct 2021 11:15:10 +0100 Subject: [PATCH] Use string_view from simdjson. Interesting speed up. Signed-off-by: Adrian Conlon --- M6502/HarteTest_6502/TestRunner.cpp | 13 ++----------- M6502/HarteTest_6502/TestRunner.h | 12 ++++++++++-- M6502/HarteTest_6502/array_t.h | 4 +--- M6502/HarteTest_6502/byte_t.h | 4 ++++ M6502/HarteTest_6502/cycle_t.h | 2 +- M6502/HarteTest_6502/element_t.h | 4 ++-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/M6502/HarteTest_6502/TestRunner.cpp b/M6502/HarteTest_6502/TestRunner.cpp index 5c6c155..e3c89cf 100644 --- a/M6502/HarteTest_6502/TestRunner.cpp +++ b/M6502/HarteTest_6502/TestRunner.cpp @@ -42,15 +42,6 @@ void TestRunner::addActualWriteCycle(const EightBit::register16_t address, const addActualCycle(address, value, "write"); } -void TestRunner::dumpCycle(const uint16_t address, const uint8_t value, const std::string action) { - os() - << std::setfill('0') << std::hex - << "Address: " << std::setw(4) << (int)address - << ", value: " << std::setw(2) << (int)value - << ", action: " << action; - pushCurrentMessage(); -} - void TestRunner::dumpCycles(const std::string which, const actual_cycles_t& events) { m_messages.push_back(which); dumpCycles(events); @@ -116,7 +107,7 @@ void TestRunner::raise(const std::string what, const uint8_t expected, const uin pushCurrentMessage(); } -void TestRunner::raise(const std::string what, const std::string expected, const std::string actual) { +void TestRunner::raise(const std::string what, const std::string_view expected, const std::string_view actual) { os() << std::setw(0) << std::setfill(' ') << what @@ -164,7 +155,7 @@ bool TestRunner::checkState() { const auto actual = actual_cycles.at(actual_idx++); // actual could be less than expected check("Cycle address", expected.address(), std::get<0>(actual)); check("Cycle value", expected.value(), std::get<1>(actual)); - check("Cycle action", expected.action(), std::get<2>(actual)); + check("Cycle action", expected.action(), std::string_view(std::get<2>(actual))); } const auto final = test().final(); diff --git a/M6502/HarteTest_6502/TestRunner.h b/M6502/HarteTest_6502/TestRunner.h index 986e17b..533e1e3 100644 --- a/M6502/HarteTest_6502/TestRunner.h +++ b/M6502/HarteTest_6502/TestRunner.h @@ -47,7 +47,7 @@ private: void raise(std::string what, uint16_t expected, uint16_t actual); void raise(std::string what, uint8_t expected, uint8_t actual); - void raise(std::string what, std::string expected, std::string actual); + void raise(std::string what, std::string_view expected, std::string_view actual); template bool check(std::string what, T expected, T actual) { @@ -68,7 +68,15 @@ private: void disassemble(uint16_t address); - void dumpCycle(uint16_t address, uint8_t value, std::string action); + template + void dumpCycle(const uint16_t address, const uint8_t value, const T action) { + os() + << std::setfill('0') << std::hex + << "Address: " << std::setw(4) << (int)address + << ", value: " << std::setw(2) << (int)value + << ", action: " << action; + pushCurrentMessage(); + } void dumpCycles(std::string which, cycles_t cycles); void dumpCycles(cycles_t cycles); diff --git a/M6502/HarteTest_6502/array_t.h b/M6502/HarteTest_6502/array_t.h index 959f2fe..fcee1ad 100644 --- a/M6502/HarteTest_6502/array_t.h +++ b/M6502/HarteTest_6502/array_t.h @@ -14,9 +14,7 @@ protected: [[nodiscard]] auto raw() const noexcept { return m_raw; } [[nodiscard]] auto at(size_t idx) const noexcept { return raw().at(idx); } - [[nodiscard]] auto integer_at(size_t idx) const noexcept { return (int64_t)at(idx); } - [[nodiscard]] auto address_at(size_t idx) const noexcept { return (uint16_t)integer_at(idx); } - [[nodiscard]] auto byte_at(size_t idx) const noexcept { return (uint8_t)integer_at(idx); } + [[nodiscard]] auto integer_at(size_t idx) const noexcept { return at(idx).get_int64(); } public: [[nodiscard]] auto begin() const noexcept { return m_raw.begin(); } diff --git a/M6502/HarteTest_6502/byte_t.h b/M6502/HarteTest_6502/byte_t.h index 4e9c99e..858b6a3 100644 --- a/M6502/HarteTest_6502/byte_t.h +++ b/M6502/HarteTest_6502/byte_t.h @@ -5,6 +5,10 @@ #include "array_t.h" class byte_t : public array_t { +protected: + [[nodiscard]] auto address_at(size_t idx) const noexcept { return (uint16_t)integer_at(idx); } + [[nodiscard]] auto byte_at(size_t idx) const noexcept { return (uint8_t)integer_at(idx); } + public: byte_t(simdjson::dom::array input) noexcept; diff --git a/M6502/HarteTest_6502/cycle_t.h b/M6502/HarteTest_6502/cycle_t.h index 0cd6466..3a6de1e 100644 --- a/M6502/HarteTest_6502/cycle_t.h +++ b/M6502/HarteTest_6502/cycle_t.h @@ -10,5 +10,5 @@ class cycle_t final : public byte_t { public: cycle_t(simdjson::dom::array input) noexcept; - [[nodiscard]] auto action() const noexcept { return (std::string)at(2); } + [[nodiscard]] std::string_view action() const noexcept { return at(2).get_string(); } }; diff --git a/M6502/HarteTest_6502/element_t.h b/M6502/HarteTest_6502/element_t.h index 7d9abd1..a7cb435 100644 --- a/M6502/HarteTest_6502/element_t.h +++ b/M6502/HarteTest_6502/element_t.h @@ -12,10 +12,10 @@ private: protected: element_t(simdjson::dom::element input) noexcept; - auto raw() const noexcept { return m_raw; } + [[nodiscard]] auto raw() const noexcept { return m_raw; } [[nodiscard]] auto at(std::string key) const noexcept { return raw()[key]; } [[nodiscard]] auto operator[](std::string key) const noexcept { return at(key); } [[nodiscard]] auto array_at(std::string key) const noexcept { return at(key).get_array(); } - [[nodiscard]] auto integer_at(std::string key) const noexcept { return (int64_t)at(key); } + [[nodiscard]] auto integer_at(std::string key) const noexcept { return at(key).get_int64(); } };