mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 15:04:10 +01:00
ircd::simd: De-inline output sink portion of print template.
This commit is contained in:
parent
628141c78d
commit
41c6c35b4c
2 changed files with 48 additions and 30 deletions
|
@ -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<class T,
|
||||
class F = decltype(print_mem<T>)>
|
||||
bool
|
||||
print(const T,
|
||||
F&& printer = print_mem<T>,
|
||||
const uint &fmt = 0,
|
||||
const bool &lf = true);
|
||||
}
|
||||
};
|
||||
|
||||
/// Developer convenience. Reference another print_*() in the template. All
|
||||
/// arguments are passed thru.
|
||||
template<class T,
|
||||
class F>
|
||||
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;
|
||||
}
|
||||
|
|
30
ircd/simd.cc
30
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
|
||||
|
|
Loading…
Reference in a new issue