MAD

Arithmetic

fixed bit field field the encoding fixes should be

Encoding

313029282726252423222120191817161514131211109876543210
111destaddrsrc1src2src3desc

bits 31:0: 111x xxxx xxxx xxxx xxxx xxxx xxxx xxxx

Its format is @mad: format 5: MAD, src2 takes the address register. 5i: MADI, src3 takes it.

Runs execute_MAD with Form() 0.

Fields

Its operation is 2 opcodes' (Form() tells them apart), so it may read the fields of their layouts too.

FieldBitsThe Sail reads it in
dest28:24execute_MAD
addr23:22execute_MAD
src121:17execute_MAD
src216:10execute_MAD (16:12), execute_MAD
c11:5execute_MAD (not a field of the file)
src39:5execute_MAD
desc4:0execute_MAD

Operation Sail

MAD and MADI (format 5: the destination at 24, the address register at 22, src1 the 5-bit register at 17, src2 at 10 and src3 at 5, the operand descriptor the 5 bits at 0; MAD's src2 is 7 bits and the address register offsets it, MADI's src3): a * b + c

let inverted = Form() == 1;
let p = Pattern(UInt(Field(0, 5)));
let a = Source(UInt(Field(17, 5)), 0, p, 1);
let b = if inverted then Source(UInt(Field(12, 5)), 0, p, 2) else Source(UInt(Field(10, 7)), UInt(Field(22, 2)), p, 2);
let c = if inverted then Source(UInt(Field(5, 7)), UInt(Field(22, 2)), p, 3) else Source(UInt(Field(5, 5)), 0, p, 3);
let product = V4FMul(a, b);
let d = DestVar(UInt(Field(24, 5)));
SetDest(p, d, V4FAdd(product, c))

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 nihstro's shader_bytecode.h (BSD-3-Clause), as Azahar reads them.