mirror of
https://github.com/drewcassidy/quicktex.git
synced 2024-09-13 06:37:34 +00:00
tweaks and formatting
This commit is contained in:
parent
abfe0b8d10
commit
20305d2ea9
@ -29,6 +29,7 @@
|
||||
|
||||
namespace quicktex {
|
||||
|
||||
#pragma pack(push, 1)
|
||||
template <typename T, size_t N> class Vec {
|
||||
public:
|
||||
typedef T value_type;
|
||||
@ -52,6 +53,7 @@ template <typename T, size_t N> class Vec {
|
||||
* @param rvalue Source vector to copy from
|
||||
*/
|
||||
template <typename S> Vec(std::enable_if_t<std::is_convertible_v<S, T>, const Vec<S, N>> &rvalue) {
|
||||
static_assert(sizeof(Vec) == N * sizeof(T));
|
||||
for (unsigned i = 0; i < N; i++) { at(i) = static_cast<T>(rvalue[i]); }
|
||||
}
|
||||
|
||||
@ -218,5 +220,6 @@ template <typename T, size_t N, typename A = xsimd::default_arch> class BatchVec
|
||||
return val;
|
||||
}
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
} // namespace quicktex
|
@ -84,8 +84,8 @@ size_t unpack_into(P packed, OI begin, OI end, WI widths, bool little_endian = t
|
||||
auto w = *(widths++);
|
||||
assert(w <= std::numeric_limits<U>::digits);
|
||||
|
||||
auto mask = ((1 << w) - 1);
|
||||
*(begin++) = (packed >> offset) & mask;
|
||||
auto mask = ((1 << w) - 1); // least significant w bits all 1
|
||||
*(begin++) = (packed >> offset) & mask; // write to output
|
||||
|
||||
offset += w; // increment offset
|
||||
}
|
||||
@ -103,11 +103,11 @@ size_t unpack_into(P packed, OI begin, OI end, WI widths, bool little_endian = t
|
||||
unsigned offset = total_offset;
|
||||
while (begin < end) {
|
||||
auto w = *(widths++);
|
||||
offset -= w; // decrement offset
|
||||
assert(w < std::numeric_limits<U>::digits);
|
||||
offset -= w; // decrement offset
|
||||
assert(w < std::numeric_limits<U>::digits); // detect an overflow condition
|
||||
|
||||
auto mask = ((1 << w) - 1);
|
||||
*(begin++) = (packed >> offset) & mask;
|
||||
auto mask = ((1 << w) - 1); // least significant w bits all 1
|
||||
*(begin++) = (packed >> offset) & mask; // write to output
|
||||
}
|
||||
|
||||
return total_offset;
|
||||
@ -199,9 +199,9 @@ std::array<U, N> unpack(P packed, const std::array<size_t, N> &widths, bool litt
|
||||
* @return an array of unpacked values
|
||||
*/
|
||||
template <typename U, size_t N, typename P, typename WR>
|
||||
requires std::unsigned_integral<P> && sized_range<WR>
|
||||
requires std::unsigned_integral<P> && range<WR>
|
||||
std::array<U, N> unpack(P packed, const WR &widths, bool little_endian = true) {
|
||||
assert(widths.size() >= N);
|
||||
assert(distance(widths) == N);
|
||||
return unpack<U, N>(packed, widths.begin(), little_endian);
|
||||
}
|
||||
|
||||
|
@ -23,13 +23,27 @@
|
||||
namespace quicktex::util {
|
||||
template <class> struct next_size;
|
||||
template <class T> using next_size_t = typename next_size<T>::type;
|
||||
template <class T> struct next_size_tag { using type = T; };
|
||||
template <class T> struct type_tag { using type = T; };
|
||||
|
||||
template <> struct next_size<int8_t> : next_size_tag<int16_t> {};
|
||||
template <> struct next_size<int16_t> : next_size_tag<int32_t> {};
|
||||
template <> struct next_size<int32_t> : next_size_tag<int64_t> {};
|
||||
template <> struct next_size<int8_t> : type_tag<int16_t> {};
|
||||
template <> struct next_size<int16_t> : type_tag<int32_t> {};
|
||||
template <> struct next_size<int32_t> : type_tag<int64_t> {};
|
||||
|
||||
template <> struct next_size<uint8_t> : next_size_tag<uint16_t> {};
|
||||
template <> struct next_size<uint16_t> : next_size_tag<uint32_t> {};
|
||||
template <> struct next_size<uint32_t> : next_size_tag<uint64_t> {};
|
||||
template <> struct next_size<uint8_t> : type_tag<uint16_t> {};
|
||||
template <> struct next_size<uint16_t> : type_tag<uint32_t> {};
|
||||
template <> struct next_size<uint32_t> : type_tag<uint64_t> {};
|
||||
|
||||
template <auto bitCount>
|
||||
using unsigned_bits =
|
||||
std::conditional_t<bitCount <= 8, std::uint8_t,
|
||||
std::conditional_t<bitCount <= 16, std::uint16_t,
|
||||
std::conditional_t<bitCount <= 32, std::uint32_t,
|
||||
std::conditional_t<bitCount <= 64, std::uint64_t, void>>>>;
|
||||
|
||||
template <auto bitCount>
|
||||
using signed_bits =
|
||||
std::conditional_t<bitCount <= 8, std::int8_t,
|
||||
std::conditional_t<bitCount <= 16, std::int16_t,
|
||||
std::conditional_t<bitCount <= 32, std::int32_t,
|
||||
std::conditional_t<bitCount <= 64, std::int64_t, void>>>>;
|
||||
} // namespace quicktex::util
|
Loading…
Reference in New Issue
Block a user