PTX ISA v9.4

9.7.5.2. Mixed Precision Floating Point Instructions: sub

sub

Subtract one value from another.

Syntax

ptx
sub{.rnd}{.sat}.cdtype.atype  d, a, c;
sub{.rnd}.dtype2.atype2.ctype2   d, a, c;
sub.rz.ftz.dtype3.atype3.ctype2  d, a, c;
sub.rz.dtype4.atype3.ctype2      d, a, c;

.atype = { .f16, .bf16 };
.rnd   = { .rn, .rz, .rm, .rp };
.cdtype = { .f32 };
.atype2 = { .f16x2, .bf16x2 };
.dtype2 = .ctype2 = .atype3 = { .f32x2 };
.dtype3 = { .f16x2 };
.dtype4 = { .bf16x2 };

Description

Converts input operands, performing subtraction, a and c to cdtype/dtype. The resulting value is stored in the destination operand d.

Semantics

ptx
if (cdtype == .f32) {  // atype = .f16/.bf16, upconvert
    d = convert(a) - c;
} else if (dtype == .f32x2) {  // atype = .f16x2/.bf16x2, upconvert
    d[0:31]   = convert(a[0:15]) - c[0:31];
    d[32:63]  = convert(a[16:31]) - c[32:63];
} else if (dtype == .f16x2 || dtype == .bf16x2) { // atype = ctype = .f32x2, downconvert
    d[0:15]   = convert(a[0:31] - c[0:31]);   // Apply rz for output
    d[16:31]  = convert(a[32:63] - c[32:63]);  // Apply rz for output
}

Notes

Rounding modifiers:

  • .rn — mantissa LSB rounds to nearest even
  • .rz — mantissa LSB rounds towards zero
  • .rm — mantissa LSB rounds towards negative infinity
  • .rp — mantissa LSB rounds towards positive infinity

The default value of rounding modifier is .rn. Note that an sub instruction with an explicit rounding modifier is treated conservatively by the code optimizer. An sub instruction with no rounding modifier defaults to round-to-nearest-even and may be optimized aggressively by the code optimizer. In particular, mul/sub sequences with no rounding modifiers may be optimized to use fused-multiply-add instructions on the target device.

Subnormal numbers:

  • By default, subnormal numbers are supported.

Saturation modifier:

  • sub.sat clamps the result to [0.0, 1.0]. NaN results are flushed to +0.0f.

PTX ISA Notes

sub.f32.{f16/bf16} introduced in PTX ISA version 8.6.

sub with .f16x2/.bf16x2/.f32x2 types introduced in PTX ISA version 9.4.

Target ISA Notes

sub.f32.{f16/bf16} requires sm_100 or higher.

sub with .f16x2/.bf16x2/.f32x2 types is supported on following family-specific architectures:

  • sm_107f or higher in the same family

Examples

ptx
.reg .f32 fc, fd;
.reg .f16 ha;
sub.rz.f32.f16.sat   fd, ha, fc;
esc
Type to search across all documentation