diff --git a/include/ircd/simd/print.h b/include/ircd/simd/print.h index 1a2dfe49d..962432707 100644 --- a/include/ircd/simd/print.h +++ b/include/ircd/simd/print.h @@ -13,6 +13,8 @@ namespace ircd::simd { + struct print; + /// Print the contents of the vector in "register layout" which are /// little-endian hex integer preceded by '0x' with each lane being /// space-separated. The fmt argument is reserved to offer some additional @@ -44,28 +46,33 @@ namespace ircd::simd const T, const uint &fmt = 0) noexcept; +} - /// Print the contents of the vector to stdout; developer convenience. - /// One of the other functions in this suite must be selected by this - /// template to generate the desired string. +/// Print the contents of the vector to stdout; developer convenience. +/// One of the other functions in this suite must be selected by this +/// template to generate the desired string. +class ircd::simd::print +{ + bool output(const mutable_buffer &, const string_view &, const bool lf); + + public: template)> - bool print(const T, F&& printer = print_mem, const uint &fmt = 0, const bool &lf = true); -} +}; /// Developer convenience. Reference another print_*() in the template. All /// arguments are passed thru. template -inline bool -ircd::simd::print(const T vec, - F&& printer, - const uint &fmt, - const bool &lf) +inline +ircd::simd::print::print(const T vec, + F&& printer, + const uint &fmt, + const bool &lf) { thread_local char buf[1024]; const string_view str @@ -73,25 +80,8 @@ ircd::simd::print(const T vec, printer(buf, vec, fmt) }; - const auto term + const bool done { - std::min(str.size(), sizeof(buf) - 1) + output(buf, str, lf) }; - - assert(buf[term] == 0x0); - buf[term] = lf? '\n': buf[term]; - const auto len - { - size(str) + lf - }; - - size_t wrote {0}, last {0}; do - { - last = ::fwrite(data(str) + wrote, 1, len - wrote, ::stdout); - wrote += last; - } - while(wrote < len && last > 0); // ensure last!=0 or break for error. - - assert(wrote <= len); - return wrote == len; } diff --git a/ircd/simd.cc b/ircd/simd.cc index cfb70c598..3c8fbfe7d 100644 --- a/ircd/simd.cc +++ b/ircd/simd.cc @@ -121,9 +121,37 @@ ircd::simd::u512x1_lane_id /////////////////////////////////////////////////////////////////////////////// // -// simd/debug.h +// simd/print.h // +bool +ircd::simd::print::output(const mutable_buffer &buf, + const string_view &str, + const bool lf) +{ + const auto term + { + std::min(str.size(), size(buf) - 1) + }; + + assert(buf[term] == 0x0); + buf[term] = lf? '\n': buf[term]; + const auto len + { + size(str) + lf + }; + + size_t wrote {0}, last {0}; do + { + last = ::fwrite(data(str) + wrote, 1, len - wrote, ::stdout); + wrote += last; + } + while(wrote < len && last > 0); // ensure last!=0 or break for error. + + assert(wrote <= len); + return wrote == len; +} + // // Stringify into native integer (register) hex format value for each lane. // Note that each value is prepended with '0x' by convention to indicate an