41.2 Masks, Comparisons, and Blends

Masks control which lanes participate in operations. Comparisons create masks; blends combine values conditionally.


41.2.1 Comparisons → Masks

import jdk.incubator.vector.*;
static final VectorSpecies<Float> S = FloatVector.SPECIES_PREFERRED;

FloatVector va = FloatVector.fromArray(S, a, i);
FloatVector vb = FloatVector.fromArray(S, b, i);
VectorMask<Float> gt = va.compare(VectorOperators.GT, vb);

gt marks lanes where a[i] > b[i].


41.2.2 Blends (Conditional Select)

FloatVector chosen = va.blend(vb, gt); // lanes from va where gt, else vb

Blend is useful for clamping, thresholding, and conditional updates.


41.2.3 Masked Loads/Stores

VectorMask<Float> m = S.indexInRange(i, a.length);
FloatVector x = FloatVector.fromArray(S, a, i, m);
x.intoArray(out, i, m); // store only active lanes

41.2.4 Min/Max with Masks

FloatVector min = va.min(vb);
FloatVector max = va.max(vb);

Combine with masks for selective updates:

FloatVector outV = outV.blend(min, m);

41.2.5 Common Patterns

  • Thresholding: compare → mask → blend
  • Absolute value: va.abs() lane‑wise
  • Sign extraction: va.compare(GE, 0) to build masks
  • Saturation: combine min/max to bound values