interface IInteger
Inherits from: IArithmetic, ILogical
Description
Represents a type that can be used for integer arithmetic operations.
Implemented by builtin scalar types: int, uint, int64_t, uint64_t, int8_t, uint8_t, int16_t, uint16_t.
Also implemented by vector<T, N> where T is one of the above scalar types.
Methods
Remarks
This interface can be used to define generic functions that work with integer-like types. See example below.
Example
The following code defines a generic function that computes a*b+1, where a, b can be any integer scalar or vector types.
T compute<T:IInteger>(T a, T b)
{
return a * b + T(1);
}
RWStructuredBuffer<int> outputBuffer;
[numthreads(1,1,1)]
void test()
{
int a = 2;
int b = 3;
outputBuffer[0] = compute(a, b); // result = 2*3 + 1 = 7
int16_t2 a2 = int16_t2(2, 3);
int16_t2 b2 = int16_t2(4, 5);
// result2 = int16_t2(2*4 + 1, 3*5 + 1) = int16_t2(9, 16)
int16_t2 result2 = compute<int16_t2>(a2, b2);
outputBuffer[1] = result2.x;
}