Upstream instruction fixes: 64-bit literals, exact normalized ends, flat offsets, rare forms
Ports of 7d04943 (a signed 64-bit operand sign-extends its literal), 645391b (a normalized buffer format's ends load as exactly 1.0 and -1.0), 40f30be (FLAT offsets ignore bit 11), 3d71ad1, 344704e, 5d6889e, 78c1267, c3a04e2, e3fe5bf and the tests 259ba31, 8610ffb, 41b2472, 45ed8e3, 8d67fa5. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
25f78a079c
commit
a780306f4c
5 files changed
+529
-14
No files matched your search
@@ -235,19 +235,32 @@ impl Instruction {
|
||||
}
|
||||
Encoding::Sopp => Fields::Sopp { imm: w0 as u16 },
|
||||
Encoding::Smem => {
|
||||
let data = match name {
|
||||
"s_gl1_inv" | "s_dcache_inv" | "s_dcache_wb" => None,
|
||||
n if n.starts_with("s_dcache_discard") => None,
|
||||
"s_memtime" | "s_memrealtime" => Some(2),
|
||||
_ => Some(data_dwords(name)),
|
||||
let sdata = (w0 >> 6 & 0x7F) as u8;
|
||||
// s_atc_probe*: SDATA is a 7-bit immediate, not an SGPR. The
|
||||
// buffer form's resource is 4 dwords. GLC and DLC are not operands.
|
||||
let probe = matches!(name, "s_atc_probe" | "s_atc_probe_buffer");
|
||||
let data = if probe {
|
||||
Some(Operand::Literal(u32::from(sdata)))
|
||||
} else {
|
||||
match name {
|
||||
"s_gl1_inv" | "s_dcache_inv" | "s_dcache_wb" => None,
|
||||
n if n.starts_with("s_dcache_discard") => None,
|
||||
"s_memtime" | "s_memrealtime" => Some(scalar(sdata, 2)),
|
||||
_ => Some(scalar(sdata, data_dwords(name))),
|
||||
}
|
||||
};
|
||||
let base = 2 + 2 * u8::from(name.starts_with("s_buffer_"));
|
||||
let base =
|
||||
2 + 2 * u8::from(name.starts_with("s_buffer_") || name == "s_atc_probe_buffer");
|
||||
Fields::Smem {
|
||||
data: data.map(|d| scalar((w0 >> 6 & 0x7F) as u8, d)),
|
||||
data,
|
||||
base: scalar(((w0 & 0x3F) << 1) as u8, base),
|
||||
offset: (w1 << 11) as i32 >> 11,
|
||||
soffset: scalar((w1 >> 25) as u8, 1),
|
||||
cache: cache(bit(w0, 16), false, bit(w0, 14)),
|
||||
cache: if probe {
|
||||
Cache::default()
|
||||
} else {
|
||||
cache(bit(w0, 16), false, bit(w0, 14))
|
||||
},
|
||||
}
|
||||
}
|
||||
Encoding::Vop1 | Encoding::Vop2 | Encoding::Vopc | Encoding::Vop3 | Encoding::Vop3p => {
|
||||
@@ -405,6 +418,8 @@ impl Instruction {
|
||||
saddr: (self.encoding != Encoding::Flat)
|
||||
.then(|| scalar(saddr, 1 + u8::from(self.encoding == Encoding::Global))),
|
||||
offset: match self.encoding {
|
||||
// GFX10 FLAT offsets are 11-bit and unsigned: the
|
||||
// hardware ignores bit 11.
|
||||
Encoding::Flat => (w0 & 0x7FF) as i16,
|
||||
_ => ((w0 << 4) as i16) >> 4,
|
||||
},
|
||||
|
||||
@@ -352,6 +352,21 @@ mod tests {
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flat_offsets_ignore_bit_eleven() {
|
||||
let offset = |word0: u32| {
|
||||
let code = bytes(&[word0, 0x0000_0001, S_ENDPGM]);
|
||||
match decode(&code).unwrap()[0].fields(false) {
|
||||
Fields::Flat { offset, .. } => offset,
|
||||
fields => panic!("{fields:?}"),
|
||||
}
|
||||
};
|
||||
// flat_load_dword v0, v[1:2]: the FLAT offset is 11-bit and
|
||||
// unsigned, so bit 11 is ignored (0x800 -> 0, 0xfff -> 0x7ff).
|
||||
assert_eq!(offset(0xDC30_0800), 0);
|
||||
assert_eq!(offset(0xDC30_0FFF), 0x7FF);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tables_are_sorted() {
|
||||
for t in [
|
||||
|
||||
@@ -137,6 +137,12 @@ fn operands(inst: &Instruction, name: &str, fields: &Fields) -> String {
|
||||
cache,
|
||||
} => {
|
||||
if let Some(data) = data {
|
||||
let data = match (name, data) {
|
||||
("s_atc_probe" | "s_atc_probe_buffer", Operand::Literal(imm)) => {
|
||||
atc_immediate(*imm)
|
||||
}
|
||||
_ => data.to_string(),
|
||||
};
|
||||
let off = match (soffset, offset) {
|
||||
(Operand::Scalar { code: NULL, .. }, 0) => soffset.to_string(),
|
||||
(Operand::Scalar { code: NULL, .. }, _) => {
|
||||
@@ -335,6 +341,15 @@ fn operands(inst: &Instruction, name: &str, fields: &Fields) -> String {
|
||||
out
|
||||
}
|
||||
|
||||
/// `s_atc_probe` immediate: 0..=64 in decimal, larger values in hex.
|
||||
fn atc_immediate(imm: u32) -> String {
|
||||
if imm <= 64 {
|
||||
imm.to_string()
|
||||
} else {
|
||||
format!("0x{imm:x}")
|
||||
}
|
||||
}
|
||||
|
||||
/// Cache flags; images write `dlc` first.
|
||||
fn flags(out: &mut String, cache: &Cache, dlc_first: bool) {
|
||||
let dlc = (cache.dlc, " dlc");
|
||||
@@ -660,7 +675,7 @@ fn valu(name: &str, v: &Valu, encoding: Encoding) -> String {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::gfx10::{Fields, Operand, decode};
|
||||
use crate::gfx10::{Cache, Fields, Operand, decode};
|
||||
|
||||
/// Text of each instruction in `words` (a straight-line program).
|
||||
fn texts(words: &[u32], wave64: bool) -> Vec<String> {
|
||||
@@ -700,6 +715,69 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// `s_atc_probe` / `s_atc_probe_buffer`: SDATA is a 7-bit immediate, the
|
||||
/// buffer resource is 4 dwords, and GLC/DLC are not operands.
|
||||
///
|
||||
/// Words checked with `llvm-mc -arch=amdgcn -mcpu=gfx1030 --disassemble`.
|
||||
/// The offset keeps this printer's 6-digit hex (`0x000064`, not `0x64`).
|
||||
#[test]
|
||||
fn atc_probe_immediate_is_not_a_register() {
|
||||
let cases = [
|
||||
(
|
||||
[0xF498_01C2, 0xFA00_0064],
|
||||
"s_atc_probe 7, s[4:5], 0x000064",
|
||||
Operand::Literal(7),
|
||||
Operand::Scalar { code: 4, dwords: 2 },
|
||||
),
|
||||
(
|
||||
[0xF498_1FF4, 0x0A00_0001],
|
||||
"s_atc_probe 0x7f, s[104:105], s5 offset:0x000001",
|
||||
Operand::Literal(0x7f),
|
||||
Operand::Scalar {
|
||||
code: 104,
|
||||
dwords: 2,
|
||||
},
|
||||
),
|
||||
(
|
||||
[0xF498_0000, 0xFA00_0000],
|
||||
"s_atc_probe 0, s[0:1], null",
|
||||
Operand::Literal(0),
|
||||
Operand::Scalar { code: 0, dwords: 2 },
|
||||
),
|
||||
(
|
||||
[0xF49C_01C4, 0xFA00_0020],
|
||||
"s_atc_probe_buffer 7, s[8:11], 0x000020",
|
||||
Operand::Literal(7),
|
||||
Operand::Scalar { code: 8, dwords: 4 },
|
||||
),
|
||||
(
|
||||
[0xF499_41C2, 0xFA00_0000],
|
||||
"s_atc_probe 7, s[4:5], null",
|
||||
Operand::Literal(7),
|
||||
Operand::Scalar { code: 4, dwords: 2 },
|
||||
),
|
||||
];
|
||||
for (words, text, data, base) in cases {
|
||||
assert_eq!(one(&words, false), text, "{words:08x?}");
|
||||
assert_eq!(one(&words, true), text, "{words:08x?}");
|
||||
let mut code: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect();
|
||||
code.extend(0xBF81_0000u32.to_le_bytes());
|
||||
let inst = &decode(&code).unwrap()[0];
|
||||
let Fields::Smem {
|
||||
data: got,
|
||||
base: got_base,
|
||||
cache,
|
||||
..
|
||||
} = inst.fields(false)
|
||||
else {
|
||||
panic!("not an SMEM instruction");
|
||||
};
|
||||
assert_eq!(got, Some(data), "{words:08x?}");
|
||||
assert_eq!(got_base, base, "{words:08x?}");
|
||||
assert_eq!(cache, Cache::default(), "{words:08x?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lane_masks_follow_the_wave_size() {
|
||||
let cmp = [0x7C08_06F0]; // v_cmp_gt_f32 with 0.5 and v3
|
||||
|
||||
Reference in new issue
Block a user