a VDUAL operation of its sources (operands base, base + 1, base + 2), into value out: 0 and 8 a * b + c, 1 and 2 the dot products a.b and a.a, 3 and 10 a * b, 4 and 9 a + b, 11 FRC (a - floor(b)), 5 a, 6 the reciprocal square root, 7 the reciprocal, 12 the base 2 exponential (of a NaN 1), 13 the base 2 logarithm
function DualAlu(code : int, base : int, count : int, write_mask : int, cct : int, out : int) -> unit = {
let dot = code == 1 | code == 2;
let source_mask = if DualVectorLoad(code) then (if dot then (if cct == 1 then 15 else 7) else write_mask) else 1;
Load(A, base, source_mask, 0);
if count > 1 then Load(B, base + 1, source_mask, 0) else Reset(B, 0, K_FLOAT);
if count > 2 then Load(C, base + 2, source_mask, 0) else Reset(C, 0, K_FLOAT);
Reset(out, Count(A), K_FLOAT);
if not_bool(Failed()) then {
if code == 1 | code == 2 then {
var sum : bits(32) = FMul(At(A, 0), if code == 1 then At(B, 0) else At(A, 0));
foreach (i from 1 to Count(A) - 1) { sum = FFma(At(A, i), if code == 1 then At(B, i) else At(A, i), sum) };
Reset(out, 1, K_FLOAT);
Put(out, 0, sum)
} else if code == 5 then CopyValue(out, A)
else {
foreach (i from 0 to Count(A) - 1) {
let a = At(A, i);
if code == 0 | code == 8 then {
let product = FMul(a, At(B, i));
Put(out, i, FAdd(product, At(C, i)))
} else if code == 3 | code == 10 then Put(out, i, FMul(a, At(B, i)))
else if code == 4 | code == 9 then Put(out, i, FAdd(a, At(B, i)))
else if code == 11 then Put(out, i, FSub(a, FRound(1, At(B, i))))
else if code == 6 then Put(out, i, FInvSqrt(a))
else if code == 7 then Put(out, i, FDiv(One(), a))
else if code == 12 then {
let e = FExp2(a);
let nan = FIsNaN(e);
let one = One();
Put(out, i, if nan then one else e)
} else Put(out, i, FLog2(a))
}
}
}
}Made from ScarletNX's Sail at 166ad3910f80. The Sail and the encodings' file are ScarletNX's (GPL-3.0-or-later); its encodings are from Vita3K's usse_translator_entry.cpp (GPL-2.0-or-later).