udiv

SVE Unsigned Divide

UDIV <Zdn>.<T>, <Pg>/M, <Zdn>.<T>, <Zm>.<T>

Divides unsigned integers.

Details

SVE unsigned integer divide: divides each active element of Zdn (dividend) by the corresponding element of Zm (divisor) as unsigned values, storing the quotient back in Zdn. Elements where the predicate is false are left unchanged. No condition flags are affected. This is an SVE-only instruction and does not raise exceptions on division by zero.

Pseudocode Operation

for i = 0 to VL-1
  if Pg[i] == '1' then
    Zdn[i] ← UnsignedDivide(Zdn[i], Zm[i])
  // else Zdn[i] unchanged

Example

UDIV z0.s.T, p0/m/M, z0.s.T, z2.s.T

Encoding

Binary Layout
00000100
size
0101
0
1
000
Pg
Zm
Zdn
 
Format SVE Integer Binary
Opcode 0x04150000
Extension SVE

Operands

  • Zdn
    Dest/Dividend
  • Pg
    Mask
  • Zm
    Divisor

Reference (Arm A64 ISA)

Instruction Forms

Encoding Instruction ISA Bit pattern
0x1AC00800 UDIV <Wd>, <Wn>, <Wm> A64 0 | 0 | 0 | 11010110 | Rm | 00001 | 0 | Rn | Rd
0x9AC00800 UDIV <Xd>, <Xn>, <Xm> A64 1 | 0 | 0 | 11010110 | Rm | 00001 | 0 | Rn | Rd
0x04150000 UDIV <Zdn>.<T>, <Pg>/M, <Zdn>.<T>, <Zm>.<T> A64 00000100 | size | 0101 | 0 | 1 | 000 | Pg | Zm | Zdn

Description

Unsigned divide active elements of the first source vector by corresponding elements of the second source vector and destructively place the quotient in the corresponding elements of the first source vector. Inactive elements in the destination vector register remain unmodified.

Operation

CheckSVEEnabled();
constant integer VL = CurrentVL;
constant integer PL = VL DIV 8;
constant integer elements = VL DIV esize;
bits(PL) mask = P[g, PL];
bits(VL) operand1 = Z[dn, VL];
bits(VL) operand2 = if AnyActiveElement(mask, esize) then Z[m, VL] else Zeros(VL);
bits(VL) result;

for e = 0 to elements-1
    integer element1 = Int(Elem[operand1, e, esize], unsigned);
    if ActivePredicateElement(mask, e, esize) then
        integer element2 = Int(Elem[operand2, e, esize], unsigned);
        integer quotient;
        if element2 == 0 then
            quotient = 0;
        else
            quotient = RoundTowardsZero(Real(element1) / Real(element2));
        Elem[result, e, esize] = quotient<esize-1:0>;
    else
        Elem[result, e, esize] = Elem[operand1, e, esize];

Z[dn, VL] = result;