0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 08:13:46 +02:00

ircd::simd: De-inline output sink portion of print template.

This commit is contained in:
Jason Volk 2022-04-30 13:57:29 -07:00
parent 628141c78d
commit 41c6c35b4c
2 changed files with 48 additions and 30 deletions

View file

@ -13,6 +13,8 @@
namespace ircd::simd namespace ircd::simd
{ {
struct print;
/// Print the contents of the vector in "register layout" which are /// Print the contents of the vector in "register layout" which are
/// little-endian hex integer preceded by '0x' with each lane being /// little-endian hex integer preceded by '0x' with each lane being
/// space-separated. The fmt argument is reserved to offer some additional /// space-separated. The fmt argument is reserved to offer some additional
@ -44,28 +46,33 @@ namespace ircd::simd
const T, const T,
const uint &fmt = 0) const uint &fmt = 0)
noexcept; noexcept;
}
/// Print the contents of the vector to stdout; developer convenience. /// Print the contents of the vector to stdout; developer convenience.
/// One of the other functions in this suite must be selected by this /// One of the other functions in this suite must be selected by this
/// template to generate the desired string. /// template to generate the desired string.
class ircd::simd::print
{
bool output(const mutable_buffer &, const string_view &, const bool lf);
public:
template<class T, template<class T,
class F = decltype(print_mem<T>)> class F = decltype(print_mem<T>)>
bool
print(const T, print(const T,
F&& printer = print_mem<T>, F&& printer = print_mem<T>,
const uint &fmt = 0, const uint &fmt = 0,
const bool &lf = true); const bool &lf = true);
} };
/// Developer convenience. Reference another print_*() in the template. All /// Developer convenience. Reference another print_*() in the template. All
/// arguments are passed thru. /// arguments are passed thru.
template<class T, template<class T,
class F> class F>
inline bool inline
ircd::simd::print(const T vec, ircd::simd::print::print(const T vec,
F&& printer, F&& printer,
const uint &fmt, const uint &fmt,
const bool &lf) const bool &lf)
{ {
thread_local char buf[1024]; thread_local char buf[1024];
const string_view str const string_view str
@ -73,25 +80,8 @@ ircd::simd::print(const T vec,
printer(buf, vec, fmt) 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;
} }

View file

@ -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. // Stringify into native integer (register) hex format value for each lane.
// Note that each value is prepended with '0x' by convention to indicate an // Note that each value is prepended with '0x' by convention to indicate an