2017-10-12 17:36:46 +11:00
|
|
|
#include "tap.hpp"
|
|
|
|
|
|
|
|
#include "endian.hpp"
|
|
|
|
|
2018-05-03 18:32:08 +10:00
|
|
|
#include <cstdint>
|
|
|
|
|
2017-10-12 17:36:46 +11:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2017-10-12 17:36:46 +11:00
|
|
|
|
|
|
|
{
|
|
|
|
uint32_t a = 0x12345678, b = 0x78563412;
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect_eq (a, cruft::bswap (b), "u32 byteswap");
|
2017-10-12 17:36:46 +11:00
|
|
|
}
|
|
|
|
|
2018-05-03 18:32:08 +10:00
|
|
|
{
|
|
|
|
static std::uint8_t const bytes[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect_eq (cruft::readle<std::uint64_t> (bytes), 0xefcdab8967452301, "readle<u64>");
|
2018-05-03 18:32:08 +10:00
|
|
|
}
|
|
|
|
|
2022-02-07 13:14:45 +11:00
|
|
|
{
|
|
|
|
static constexpr u32 A = 0x11223344;
|
|
|
|
static constexpr u32 B = 0x44332211;
|
|
|
|
|
|
|
|
f32 const a_f = cruft::cast::bit<f32> (A);
|
|
|
|
f32 const b_f = cruft::bswap (a_f);
|
|
|
|
u32 const b_u = cruft::cast::bit<u32> (b_f);
|
|
|
|
|
|
|
|
tap.expect_eq (b_u, B, "f32 bswap");
|
|
|
|
}
|
2018-05-03 18:32:08 +10:00
|
|
|
|
2017-10-12 17:36:46 +11:00
|
|
|
{
|
2022-02-07 13:14:45 +11:00
|
|
|
static constexpr u64 A = 0x1122334455667788;
|
|
|
|
static constexpr u64 B = 0x8877665544332211;
|
|
|
|
|
|
|
|
f64 const a_f = cruft::cast::bit<f64> (A);
|
|
|
|
f64 const b_f = cruft::bswap (a_f);
|
|
|
|
u64 const b_u = cruft::cast::bit<u64> (b_f);
|
|
|
|
|
|
|
|
tap.expect_eq (b_u, B, "u64 bswap");
|
|
|
|
}
|
2017-10-12 17:36:46 +11:00
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|