9.7.1.14. Integer Arithmetic Instructions: max
max
Find the maximum of two values.
Syntax
max.type1 d, a, b;
max{.relu}.type2 d, a, b;
.type1 = { .u16, .u32, .u64,
.u16x2, .u8x4, .s16, .s64 };
.type2 = { .s16x2, .s32, .s8x4 };Description
Store the maximum of a and b in d.
For .u16x2, .s16x2 instruction types, forms input vectors by half word values from source operands. Half-word operands are then processed in parallel to produce .u16x2, .s16x2 result in destination.
For .u8x4, .s8x4 instruction types, input vectors are formed with quarter-word values from source operands. Quarter-word operands are then processed in parallel to store .u8x4, .s8x4 result in destination.
Operands d, a and b have the same type as the instruction type. For instruction types .u16x2, .s16x2, .u8x4, .s8x4, operands d, a and b have type .b32.
Semantics
if (type == u16x2 || type == s16x2) {
iA[0] = a[0:15];
iA[1] = a[16:31];
iB[0] = b[0:15];
iB[1] = b[16:31];
for (i = 0; i < 2; i++) {
d[i] = (iA[i] > iB[i]) ? iA[i] : iB[i];
}
} else if (type == u8x4 || type == s8x4) {
iA[0] = a[0:7];
iA[1] = a[8:15];
iA[2] = a[16:23];
iA[3] = a[24:31];
iB[0] = b[0:7];
iB[1] = b[8:15];
iB[2] = b[16:23];
iB[3] = b[24:31];
for (i = 0; i < 4; i++) {
d[i] = (iA[i] > iB[i]) ? iA[i] : iB[i];
}
} else {
d = (a > b) ? a : b; // Integer (signed and unsigned)
}Notes
Signed and unsigned differ.
Saturation modifier:
max.relu.{s8x4, s16x2, s32}clamps the result to 0 if negative.
PTX ISA Notes
Introduced in PTX ISA version 1.0.
max.u16x2, max{.relu}.s16x2 and max.relu.s32 introduced in PTX ISA version 8.0.
max.u8x4, max{.relu}.s8x4 introduced in PTX ISA version 9.2.
Target ISA Notes
Supported on all target architectures.
max.u16x2, max{.relu}.s16x2 and max.relu.s32 require sm_90 or higher.
max.u8x4, max{.relu}.s8x4 are supported on following family-specific architectures:
sm_107for higher in the same familysm_120for higher in the same family
Examples
max.u32 d,a,b;
max.s32 q,q,0;
max.relu.s16x2 t,t,u;
max.u8x4 p, q, r;