128 bit integer on cuda?

For best performance, one would want to map the 128-bit type on top of a suitable CUDA vector type, such as uint4, and implement the functionality using PTX inline assembly. The addition would look something like this: typedef uint4 my_uint128_t; __device__ my_uint128_t add_uint128 (my_uint128_t addend, my_uint128_t augend) { my_uint128_t res; asm (“add.cc.u32 %0, %4, %8;\n\t” … Read more

Why is the maximum value of an unsigned n-bit integer 2ⁿ-1 and not 2ⁿ?

The -1 is because integers start at 0, but our counting starts at 1. So, 2^32-1 is the maximum value for a 32-bit unsigned integer (32 binary digits). 2^32 is the number of possible values. To simplify why, look at decimal. 10^2-1 is the maximum value of a 2-digit decimal number (99). Because our intuitive … Read more

Signed versus Unsigned Integers

Unsigned can hold a larger positive value and no negative value. Yes. Unsigned uses the leading bit as a part of the value, while the signed version uses the left-most-bit to identify if the number is positive or negative. There are different ways of representing signed integers. The easiest to visualise is to use the … Read more