#include "t.h" void blk128_inc_one() { blk128_t x = {0,0}; blk128_inc(&x); assert_true(x.lo == 1 && x.hi == 0); } void blk128_inc_overflow() { blk128_t x = {0,u64(~0)}; blk128_inc(&x); blk128_t e; e.hi = 1; e.lo = 0; assert_blk128_eq(e, x); } void blk128_mul_1() { blk128_t x = {0, 1}; blk256_t r, e; blk256_set(&e, 0, u64(0), u64(0), u64(0), u64(1)); blk128_mul(&r, &x, &x); assert_blk256_eq(e, r); } void blk128_mul_2() { blk128_t x = {0, 1}; blk128_t y = {0, 1}; blk256_t r, e; blk256_set(&e, 0, u64(0), u64(0), u64(0), u64(1)); blk128_mul(&r, &x, &y); assert_blk256_eq(e, r); } void blk128_mul_3() { blk128_t x = {UINT64_MAX, 0}; blk128_t y = {0, UINT64_MAX}; blk256_t r, e; blk256_set(&e, 0, 0, u64c(18446744073709551614), 1, 0); blk128_mul(&r, &x, &y); assert_blk256_eq(e, r); } void blk128_mul_max() { blk128_t x = {UINT64_MAX, UINT64_MAX}; blk256_t r, e; blk256_set(&e, 0, u64c(18446744073709551615), u64c(18446744073709551614), 0, 1); blk128_mul(&r, &x, &x); assert_blk256_eq(e, r); } void blk128_tests() { test_fixture_start(); run_test(blk128_inc_one); run_test(blk128_inc_overflow); run_test(blk128_mul_1); run_test(blk128_mul_2); run_test(blk128_mul_3); run_test(blk128_mul_max); test_fixture_end(); }