From 4b2dd73e796cf7de54b4adde1d5cd2d8cbeeaac8 Mon Sep 17 00:00:00 2001 From: Lioncache Date: Wed, 10 Jan 2024 08:03:13 -0500 Subject: [PATCH] assembler: Simplify FLIImpl table We can just use the iterator to derive the index instead of making it a table entry (in hindsight, I don't know why I didn't do this to begin with). --- src/assembler.cpp | 73 ++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/src/assembler.cpp b/src/assembler.cpp index 55f3d71..1d4d210 100644 --- a/src/assembler.cpp +++ b/src/assembler.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include namespace biscuit { namespace { @@ -1524,49 +1524,50 @@ void Assembler::FCVT_H_LU(FPR rd, GPR rs1, RMode rmode) noexcept { static void FLIImpl(CodeBuffer& buffer, uint32_t funct7, FPR rd, double value) noexcept { static constexpr std::array fli_table{ - std::pair{0xBFF0000000000000ULL, 0U}, // -1.0 - std::pair{0x0010000000000000ULL, 1U}, // Minimum positive normal - std::pair{0x3EF0000000000000ULL, 2U}, // 1.0 * 2^-16 - std::pair{0x3F00000000000000ULL, 3U}, // 1.0 * 2^-15 - std::pair{0x3F70000000000000ULL, 4U}, // 1.0 * 2^-8 - std::pair{0x3F80000000000000ULL, 5U}, // 1.0 * 2^-7 - std::pair{0x3FB0000000000000ULL, 6U}, // 1.0 * 2^-4 - std::pair{0x3FC0000000000000ULL, 7U}, // 1.0 * 2^-3 - std::pair{0x3FD0000000000000ULL, 8U}, // 0.25 - std::pair{0x3FD4000000000000ULL, 9U}, // 0.3125 - std::pair{0x3FD8000000000000ULL, 10U}, // 0.375 - std::pair{0x3FDC000000000000ULL, 11U}, // 0.4375 - std::pair{0x3FE0000000000000ULL, 12U}, // 0.5 - std::pair{0x3FE4000000000000ULL, 13U}, // 0.625 - std::pair{0x3FE8000000000000ULL, 14U}, // 0.75 - std::pair{0x3FEC000000000000ULL, 15U}, // 0.875 - std::pair{0x3FF0000000000000ULL, 16U}, // 1.0 - std::pair{0x3FF4000000000000ULL, 17U}, // 1.25 - std::pair{0x3FF8000000000000ULL, 18U}, // 1.5 - std::pair{0x3FFC000000000000ULL, 19U}, // 1.75 - std::pair{0x4000000000000000ULL, 20U}, // 2.0 - std::pair{0x4004000000000000ULL, 21U}, // 2.5 - std::pair{0x4008000000000000ULL, 22U}, // 3 - std::pair{0x4010000000000000ULL, 23U}, // 4 - std::pair{0x4020000000000000ULL, 24U}, // 8 - std::pair{0x4030000000000000ULL, 25U}, // 16 - std::pair{0x4060000000000000ULL, 26U}, // 2^7 - std::pair{0x4070000000000000ULL, 27U}, // 2^8 - std::pair{0x40E0000000000000ULL, 28U}, // 2^15 - std::pair{0x40F0000000000000ULL, 29U}, // 2^16 - std::pair{0x7FF0000000000000ULL, 30U}, // +inf - std::pair{0x7FF8000000000000ULL, 31U}, // Canonical NaN + 0xBFF0000000000000ULL, // -1.0 + 0x0010000000000000ULL, // Minimum positive normal + 0x3EF0000000000000ULL, // 1.0 * 2^-16 + 0x3F00000000000000ULL, // 1.0 * 2^-15 + 0x3F70000000000000ULL, // 1.0 * 2^-8 + 0x3F80000000000000ULL, // 1.0 * 2^-7 + 0x3FB0000000000000ULL, // 1.0 * 2^-4 + 0x3FC0000000000000ULL, // 1.0 * 2^-3 + 0x3FD0000000000000ULL, // 0.25 + 0x3FD4000000000000ULL, // 0.3125 + 0x3FD8000000000000ULL, // 0.375 + 0x3FDC000000000000ULL, // 0.4375 + 0x3FE0000000000000ULL, // 0.5 + 0x3FE4000000000000ULL, // 0.625 + 0x3FE8000000000000ULL, // 0.75 + 0x3FEC000000000000ULL, // 0.875 + 0x3FF0000000000000ULL, // 1.0 + 0x3FF4000000000000ULL, // 1.25 + 0x3FF8000000000000ULL, // 1.5 + 0x3FFC000000000000ULL, // 1.75 + 0x4000000000000000ULL, // 2.0 + 0x4004000000000000ULL, // 2.5 + 0x4008000000000000ULL, // 3 + 0x4010000000000000ULL, // 4 + 0x4020000000000000ULL, // 8 + 0x4030000000000000ULL, // 16 + 0x4060000000000000ULL, // 2^7 + 0x4070000000000000ULL, // 2^8 + 0x40E0000000000000ULL, // 2^15 + 0x40F0000000000000ULL, // 2^16 + 0x7FF0000000000000ULL, // +inf + 0x7FF8000000000000ULL, // Canonical NaN }; uint64_t ivalue{}; std::memcpy(&ivalue, &value, sizeof(uint64_t)); - const auto iter = std::find_if(fli_table.cbegin(), fli_table.cend(), [ivalue](const auto& entry) { - return entry.first == ivalue; + const auto iter = std::find_if(fli_table.cbegin(), fli_table.cend(), [ivalue](uint64_t entry) { + return entry == ivalue; }); BISCUIT_ASSERT(iter != fli_table.cend()); - EmitRType(buffer, funct7, f1, GPR{iter->second}, 0b000, rd, 0b1010011); + const auto index = static_cast(std::distance(fli_table.cbegin(), iter)); + EmitRType(buffer, funct7, f1, GPR{index}, 0b000, rd, 0b1010011); } void Assembler::FLI_D(FPR rd, double value) noexcept {