Non standart nnumber types

Can I specify some non standard number memory layouts for example Int 10 or 7 or of any arbitrary bit size?

Can you do it in C or C++? If so, providing an example of that would probably help guide the discussion.

CUDA claims to be mostly C++ compliant.

1 Like

Generally, in C++ all data types are allocated in multiples of char, where char comprises CHAR_BIT bits. On all modern systems (in particular all systems supported by CUDA), CHAR_BIT = 8.

For narrow integer types, one could use bit fields, which allow specification of the exact bit width. However, my experience over decades of programming in C and C++ is that from a performance perspective, it is usually better to use plaint int or unsigned int and mask as needed.

If this is for hardware description, Verilog style, the standard practice I am familiar with is to name the user type according to the bit width, but simply map (in particular, typedef) it to the smallest built-in integer type that can fully contain it. This means that care needs to be taken not to inadvertently utilize the “extra” bits, but allows for straightforward conversion to proper Verilog for synthesis.

1 Like