10#include <cuda_runtime.h>
43 requires(((
static_cast<__uint128_t
>(mod.
high) << 64) | mod.
low) > 0 &&
44 ((
static_cast<__uint128_t
>(mod.
high) << 64) | mod.
low) <=
static_cast<__uint128_t
>(1) << 127)
50 __host__ __device__ Uint128 operator+(Uint128 rhs)
const {
51 if (val_ >= kMod - rhs.val_)
return {val_ + rhs.val_ - kMod};
52 else return {val_ + rhs.val_};
56 __host__ __device__ Uint128 operator-()
const {
57 if (val_ == 0)
return {0};
58 else return {kMod - val_};
62 __host__ __device__ Uint128() : val_(0) {}
65 __host__ __device__
static Uint128 From(int4 buf) {
66 assert((buf.w & 1) == 0);
68 __uint128_t value =
static_cast<__uint128_t
>(
static_cast<unsigned int>(buf.x)) |
69 static_cast<__uint128_t
>(
static_cast<unsigned int>(buf.y)) << 32 |
70 static_cast<__uint128_t
>(
static_cast<unsigned int>(buf.z)) << 64 |
72 static_cast<__uint128_t
>(
static_cast<unsigned int>(buf.w) >> 1) << 96;
74 return {value % kMod};
78 __host__ __device__ int4 Into()
const {
79 int4 buf = {0, 0, 0, 0};
80 buf.x =
static_cast<int>(val_ & 0xffffffff);
81 buf.y =
static_cast<int>((val_ >> 32) & 0xffffffff);
82 buf.z =
static_cast<int>((val_ >> 64) & 0xffffffff);
84 buf.w =
static_cast<int>((val_ >> 96) << 1);
90 __host__ __device__ __uint128_t Value()
const {
return val_; }
93 static constexpr __uint128_t kMod = (
static_cast<__uint128_t
>(mod.
high) << 64) | mod.
low;
97 __host__ __device__ Uint128(__uint128_t v) : val_(v) {}
99static_assert(Groupable<Uint128<>>);
100static_assert(Groupable<Uint128<
Uint128Modulus{.low = 0xffffffffffffffff, .high = 0x3fffffff}>>);
The modulus of a Uint128 group, split into two 64-bit halves: the structural form keeps host stubs fr...
Definition uint128.cuh:21
uint64_t high
High 64 bits of the modulus, i.e., the modulus is .
Definition uint128.cuh:23
uint64_t low
Low 64 bits of the modulus.
Definition uint128.cuh:22