From a83bb54e6d7b0d6340be0de2f7e136a14b953fa1 Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 29 Oct 2024 10:19:44 +0100 Subject: [PATCH] added base64rvv m4 version --- CMakeLists.txt | 1 + src/base64rvv_m4/test_base64rvv.cpp | 51 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/base64rvv_m4/test_base64rvv.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f1a68dc..69498d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,7 @@ aux_source_directory(./src/boost CTR_SOURCES) include_directories(libs/base64rvv/lib/include) aux_source_directory(./src/base64rvv_m1 CTR_SOURCES) aux_source_directory(./src/base64rvv_m2 CTR_SOURCES) +aux_source_directory(./src/base64rvv_m4 CTR_SOURCES) set_source_files_properties( ${CTR_SOURCES} PROPERTIES LANGUAGE CXX ) set_source_files_properties( ${C_SOURCES} PROPERTIES LANGUAGE C ) diff --git a/src/base64rvv_m4/test_base64rvv.cpp b/src/base64rvv_m4/test_base64rvv.cpp new file mode 100644 index 0000000..a7db87a --- /dev/null +++ b/src/base64rvv_m4/test_base64rvv.cpp @@ -0,0 +1,51 @@ +#include +#include "../Base64SurveyRegistry.hpp" +#include "base64rvv/lib/include/libb64rvv.h" + +struct BASE64RVV_Adapt +{ + + static constexpr inline size_t GetDecodeExpectedLen(size_t inLen) noexcept + { + return ((inLen + 3) / 4) * 3; + } + + static constexpr inline size_t GetEncodeLen(size_t inLen) noexcept + { + return ((inLen + 2) / 3) * 4; + } + + static std::string encode(void (*func)(uint8_t *in, char *out, size_t inlen), const std::string &bytes) + { + size_t encLen = GetEncodeLen(bytes.length()); + std::string encoded; + encoded.resize(encLen); + func((uint8_t *)&bytes[0], &encoded[0], bytes.length()); + return encoded; + } + + static std::string decode(size_t (*func)(const char *in, int8_t *out, size_t inlen), const std::string &encoded) + { + std::string decoded; + decoded.resize(GetDecodeExpectedLen(encoded.length())); + size_t dLen = func((const char *)&encoded[0], (int8_t *)&decoded[0], (size_t)encoded.length()); + decoded.resize(dLen); + return decoded; + } +}; + +struct Base64rvv_m4 +{ + std::string encode(const std::string &bytes) + { + return BASE64RVV_Adapt::encode(base64_encode_rvv_m4, bytes); + } + + std::string decode(const std::string &base64) + { + return BASE64RVV_Adapt::decode(base64_decode_rvv_m4, base64); + } +}; + +BASE64_REGISTER_ENCODER(Base64rvv_m4); +BASE64_REGISTER_DECODER(Base64rvv_m4);