diff --git a/M6502/HarteTest_6502/byte_t.cpp b/M6502/HarteTest_6502/byte_t.cpp index ff8b4de..fcb9d11 100644 --- a/M6502/HarteTest_6502/byte_t.cpp +++ b/M6502/HarteTest_6502/byte_t.cpp @@ -8,21 +8,50 @@ byte_t::byte_t(simdjson::dom::element input) noexcept : byte_t(input.get_array()) {} +#ifdef JSON_ACCESS_DATA_VIA_OBJECT + +byte_t::byte_t(simdjson::dom::array input) noexcept +: m_raw(input) {} + +#else // JSON_ACCESS_DATA_VIA_OBJECT + +#ifdef JSON_PREFER_ITERATOR_TO_INDEX + +byte_t::byte_t(simdjson::dom::array input) noexcept { + assert(input.size() == 2); + auto iterator = input.begin(); + m_address = (uint16_t)(int64_t)*iterator; + m_value = (uint8_t)(int64_t)*++iterator; +} + +#else // JSON_PREFER_ITERATOR_TO_INDEX + byte_t::byte_t(simdjson::dom::array input) noexcept : m_address((uint16_t)(int64_t)input.at(0)), m_value((uint8_t)(int64_t)input.at(1)) { assert(input.size() == 2); } -#endif +#endif // JSON_PREFER_ITERATOR_TO_INDEX + +#endif // JSON_ACCESS_DATA_VIA_OBJECT + +#endif // USE_SIMDJSON_JSON #ifdef USE_RAPIDJSON_JSON +#ifdef JSON_ACCESS_DATA_VIA_OBJECT + +byte_t::byte_t(const rapidjson::Value& input) +: m_raw(input) {} + +#else + byte_t::byte_t(const rapidjson::Value& input) : m_address((uint16_t)input[0].GetInt64()), - m_value((uint8_t)input[1].GetInt64()) { - assert(input.Size() == 2); -} + m_value((uint8_t)input[1].GetInt64()) {} + +#endif #endif @@ -31,26 +60,53 @@ byte_t::byte_t(const rapidjson::Value& input) byte_t::byte_t(const boost::json::value& input) noexcept : byte_t(input.get_array()) {} + +#ifdef JSON_ACCESS_DATA_VIA_OBJECT + +byte_t::byte_t(const boost::json::array& input) noexcept +: m_raw(input) {} + +#else + byte_t::byte_t(const boost::json::array& input) noexcept : m_address((uint16_t)input[0].get_int64()), m_value((uint8_t)input[1].get_int64()) { assert(input.size() == 2); -}; +} + +#endif #endif #ifdef USE_NLOHMANN_JSON +#ifdef JSON_ACCESS_DATA_VIA_OBJECT + +byte_t::byte_t(const nlohmann::json& input) noexcept +: m_raw(input) {} + +#else + byte_t::byte_t(const nlohmann::json& input) noexcept : m_address(input[0].get()), m_value(input[1].get()) { assert(input.size() == 2); } +#endif + + #endif #ifdef USE_JSONCPP_JSON +#ifdef JSON_ACCESS_DATA_VIA_OBJECT + +byte_t::byte_t(const Json::Value& input) +: m_raw(input) {} + +#else + byte_t::byte_t(const Json::Value& input) : m_address((uint16_t)input[0].asInt64()), m_value((uint8_t)input[1].asInt64()) { @@ -58,3 +114,5 @@ byte_t::byte_t(const Json::Value& input) } #endif + +#endif diff --git a/M6502/HarteTest_6502/byte_t.h b/M6502/HarteTest_6502/byte_t.h index 071becb..44dd9ba 100644 --- a/M6502/HarteTest_6502/byte_t.h +++ b/M6502/HarteTest_6502/byte_t.h @@ -24,9 +24,36 @@ class byte_t final { private: + +#ifdef JSON_ACCESS_DATA_VIA_OBJECT + +#ifdef USE_SIMDJSON_JSON + simdjson::dom::array m_raw; +#endif + +#ifdef USE_RAPIDJSON_JSON + const rapidjson::Value& m_raw; +#endif + +#ifdef USE_BOOST_JSON + const boost::json::array& m_raw; +#endif + +#ifdef USE_NLOHMANN_JSON + const nlohmann::json& m_raw; +#endif + +#ifdef USE_JSONCPP_JSON + const Json::Value& m_raw; +#endif + +#else + uint16_t m_address = 0xffff; uint8_t m_value = 0xff; +#endif + public: #ifdef USE_SIMDJSON_JSON @@ -51,7 +78,29 @@ public: byte_t(const Json::Value& input); #endif +#ifdef JSON_ACCESS_DATA_VIA_OBJECT +#ifdef USE_SIMDJSON_JSON + [[nodiscard]] auto address() const noexcept { return (uint16_t)(int64_t)*m_raw.begin(); } + [[nodiscard]] auto value() const noexcept { return (uint8_t)(int64_t)m_raw.at(1); } +#endif +#ifdef USE_RAPIDJSON_JSON + [[nodiscard]] auto address() const noexcept { return (uint16_t)m_raw[0].GetInt64(); } + [[nodiscard]] auto value() const noexcept { return (uint8_t)m_raw[1].GetInt64(); } +#endif +#ifdef USE_BOOST_JSON + [[nodiscard]] auto address() const noexcept { return (uint16_t)m_raw[0].get_int64(); } + [[nodiscard]] auto value() const noexcept { return (uint8_t)m_raw[1].get_int64(); } +#endif +#ifdef USE_NLOHMANN_JSON + [[nodiscard]] auto address() const noexcept { return m_raw[0].get(); } + [[nodiscard]] auto value() const noexcept { return m_raw[1].get(); } +#endif +#ifdef USE_JSONCPP_JSON + [[nodiscard]] auto address() const noexcept { return (uint16_t)m_raw[0].asInt64(); } + [[nodiscard]] auto value() const noexcept { return (uint8_t)m_raw[1].asInt64(); } +#endif +#else [[nodiscard]] constexpr auto address() const noexcept { return m_address; } [[nodiscard]] constexpr auto value() const noexcept { return m_value; } +#endif }; - diff --git a/M6502/HarteTest_6502/cycle_t.cpp b/M6502/HarteTest_6502/cycle_t.cpp index bd0ecef..66160e2 100644 --- a/M6502/HarteTest_6502/cycle_t.cpp +++ b/M6502/HarteTest_6502/cycle_t.cpp @@ -29,6 +29,18 @@ cycle_t::cycle_t(uint16_t address, uint8_t value, action_t action) noexcept cycle_t::cycle_t(simdjson::dom::element input) noexcept : cycle_t(input.get_array()) {} +#ifdef JSON_PREFER_ITERATOR_TO_INDEX + +cycle_t::cycle_t(simdjson::dom::array input) noexcept { + assert(input.size() == 3); + auto iterator = input.begin(); + m_address = (uint16_t)(int64_t)*iterator; + m_value = (uint8_t)(int64_t)*++iterator; + m_action = to_action((std::string)*++iterator); +} + +#else + cycle_t::cycle_t(simdjson::dom::array input) noexcept : m_address((uint16_t)(int64_t)input.at(0)), m_value((uint8_t)(int64_t)input.at(1)), @@ -38,14 +50,14 @@ cycle_t::cycle_t(simdjson::dom::array input) noexcept #endif +#endif + #ifdef USE_RAPIDJSON_JSON cycle_t::cycle_t(const rapidjson::Value& input) : m_address((uint16_t)input[0].GetInt64()), m_value((uint8_t)input[1].GetInt64()), - m_action(to_action(input[2].GetString())) { - assert(input.Size() == 3); -} + m_action(to_action(input[2].GetString())) {} #endif diff --git a/M6502/HarteTest_6502/state_t.cpp b/M6502/HarteTest_6502/state_t.cpp index c078205..f499d1c 100644 --- a/M6502/HarteTest_6502/state_t.cpp +++ b/M6502/HarteTest_6502/state_t.cpp @@ -60,12 +60,12 @@ state_t::state_t(const nlohmann::json& serialised) #ifdef USE_JSONCPP_JSON state_t::state_t(const Json::Value& serialised) -: m_pc(serialised["pc"].asInt64()), - m_s(serialised["s"].asInt64()), - m_a(serialised["a"].asInt64()), - m_x(serialised["x"].asInt64()), - m_y(serialised["y"].asInt64()), - m_p(serialised["p"].asInt64()), +: m_pc((uint16_t)serialised["pc"].asInt64()), + m_s((uint8_t)serialised["s"].asInt64()), + m_a((uint8_t)serialised["a"].asInt64()), + m_x((uint8_t)serialised["x"].asInt64()), + m_y((uint8_t)serialised["y"].asInt64()), + m_p((uint8_t)serialised["p"].asInt64()), m_ram(serialised["ram"]) {} #endif diff --git a/M6502/HarteTest_6502/stdafx.h b/M6502/HarteTest_6502/stdafx.h index 5d1d31e..ee68a04 100644 --- a/M6502/HarteTest_6502/stdafx.h +++ b/M6502/HarteTest_6502/stdafx.h @@ -26,12 +26,14 @@ #define USE_SIMDJSON_JSON // 13 seconds (19) //#define USE_RAPIDJSON_JSON // 19 seconds (22) //#define USE_BOOST_JSON // 26 seconds (32) -//#define USE_NLOHMANN_JSON // 56 seconds (69) -//#define USE_JSONCPP_JSON // 80 seconds (91) +//#define USE_NLOHMANN_JSON // 56 seconds (65) +//#define USE_JSONCPP_JSON // 80 seconds (87) #ifdef USE_SIMDJSON_JSON # define JSON_PREFER_PASS_BY_VALUE # define JSON_PREFER_REUSE_OF_PARSER +# define JSON_PREFER_ITERATOR_TO_INDEX +# define JSON_ACCESS_DATA_VIA_OBJECT # include "simdjson/simdjson.h" #endif @@ -39,19 +41,23 @@ # define RAPIDJSON_HAS_STDSTRING 1 # define RAPIDJSON_SSE42 # define JSON_INSITU_PARSE +# define JSON_ACCESS_DATA_VIA_OBJECT # include "rapidjson/document.h" #endif #ifdef USE_BOOST_JSON +# define JSON_ACCESS_DATA_VIA_OBJECT # include #endif #ifdef USE_NLOHMANN_JSON # define JSON_USE_IMPLICIT_CONVERSIONS 0 +# define JSON_ACCESS_DATA_VIA_OBJECT # include "nlohmann/json.hpp" #endif #ifdef USE_JSONCPP_JSON # define JSON_PREFER_REUSE_OF_PARSER +# define JSON_ACCESS_DATA_VIA_OBJECT # include #endif