Debian Codegraph @

src/nouveau/compiler/nak/nvdisasm_tests.rs

raw
1 // Copyright © 2025 Valve Corporation
2 // SPDX-License-Identifier: MIT
3
4 use crate::ir::*;
5 use compiler::cfg::CFGBuilder;
6 use rustc_hash::FxBuildHasher;
7
8 use std::io::Write;
9 use std::process;
10 use std::process::Command;
11 use std::slice;
12 use std::sync::atomic::AtomicUsize;
13 use std::sync::OnceLock;
14
15 static FILE_NUM: AtomicUsize = AtomicUsize::new(0);
16
17 fn run_nvdisasm(s: &Shader) -> String {
18 let code = s.sm.encode_shader(s);
19 // println!("{code:x?}");
20
21 let slice_u8: &[u8] = unsafe {
22 slice::from_raw_parts(
23 code.as_ptr() as *const u8,
24 code.len() * size_of::<u32>(),
25 )
26 };
27
28 let tmp_file = format!(
29 "/tmp/nak_dis_{}_{}",
30 process::id(),
31 FILE_NUM.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
32 );
33 std::fs::write(&tmp_file, slice_u8).expect("Failed to write file");
34
35 let out = Command::new("nvdisasm")
36 .arg("-b")
37 .arg(format!("SM{}", s.sm.sm()))
38 .arg("--print-raw")
39 .arg(&tmp_file)
40 .output()
41 .expect("failed to execute process");
42
43 std::io::stderr().write_all(&out.stderr).expect("IO error");
44 assert!(out.status.success());
45 let stdout = std::str::from_utf8(&out.stdout).unwrap();
46 std::fs::remove_file(tmp_file).unwrap();
47 stdout.into()
48 }
49
50 fn disassemble_instrs(instrs: Vec<Instr>, sm: u8) -> Vec<String> {
51 let mut label_alloc = LabelAllocator::new();
52 let block = BasicBlock {
53 label: label_alloc.alloc(),
54 uniform: true,
55 instrs,
56 };
57
58 let mut cfg = CFGBuilder::<_, _, FxBuildHasher>::new();
59 cfg.add_node(0, block);
60
61 let f = Function {
62 ssa_alloc: SSAValueAllocator::new(),
63 phi_alloc: PhiAllocator::new(),
64 blocks: cfg.as_cfg(),
65 };
66
67 let cs_info = ComputeShaderInfo {
68 local_size: [32, 1, 1],
69 smem_size: 0,
70 };
71 let info = ShaderInfo {
72 max_warps_per_sm: 0,
73 num_gprs: 0,
74 num_control_barriers: 0,
75 num_instrs: 0,
76 num_static_cycles: 0,
77 num_spills_to_mem: 0,
78 num_fills_from_mem: 0,
79 num_spills_to_reg: 0,
80 num_fills_from_reg: 0,
81 slm_size: 0,
82 max_crs_depth: 0,
83 uses_global_mem: true,
84 writes_global_mem: true,
85 uses_fp64: false,
86 stage: ShaderStageInfo::Compute(cs_info),
87 io: ShaderIoInfo::None,
88 };
89
90 let sm = ShaderModelInfo::new(sm, 0);
91 let s = Shader {
92 sm: &sm,
93 info: info,
94 functions: vec![f],
95 };
96 let out = run_nvdisasm(&s);
97 let out: Vec<String> = out
98 .lines()
99 .map(|line| {
100 let mut line: String = line
101 .trim_start_matches(|c| -> bool {
102 match c {
103 '/' | '*' => true,
104 'a'..='f' => true, // Actual instructions are uppercase
105 _ => c.is_numeric() || c.is_whitespace(),
106 }
107 })
108 .trim()
109 .into();
110 line.make_ascii_lowercase();
111 line
112 })
113 .collect();
114
115 out
116 }
117
118 struct DisasmCheck {
119 instrs: Vec<Instr>,
120 expected: Vec<String>,
121 }
122
123 impl DisasmCheck {
124 fn new() -> Self {
125 DisasmCheck {
126 instrs: Vec::new(),
127 expected: Vec::new(),
128 }
129 }
130
131 fn push(&mut self, instr: impl Into<Instr>, expected: impl Into<String>) {
132 self.instrs.push(instr.into());
133 self.expected.push(expected.into());
134 }
135
136 fn check(mut self, sm: u8) {
137 assert!(self.expected.len() > 0);
138 let actual = disassemble_instrs(std::mem::take(&mut self.instrs), sm);
139 assert_eq!(actual.len(), self.expected.len());
140
141 let mut any_different = false;
142 for (a, e) in actual
143 .into_iter()
144 .zip(std::mem::take(&mut self.expected).into_iter())
145 {
146 if a != e {
147 if !any_different {
148 eprintln!("Error: Difference on SM{sm}");
149 any_different = true;
150 }
151 eprintln!("actual: {a}");
152 eprintln!("expect: {e}\n");
153 }
154 }
155 if any_different {
156 panic!("Differences found");
157 }
158 }
159 }
160
161 static SM_LIST_CELL: OnceLock<&'static [u8]> = OnceLock::new();
162
163 fn sm_list() -> &'static [u8] {
164 SM_LIST_CELL.get_or_init(|| {
165 let out = Command::new("nvdisasm")
166 .arg("--version")
167 .output()
168 .expect("failed to execute process");
169
170 std::io::stderr().write_all(&out.stderr).expect("IO error");
171 assert!(out.status.success());
172 let stdout = std::str::from_utf8(&out.stdout).unwrap();
173
174 if stdout.contains("cuda_12") {
175 &[70, 75, 80, 86, 89, 90, 100, 120]
176 } else if stdout.contains("cuda_13") {
177 &[75, 80, 86, 89, 90, 100, 120]
178 } else {
179 panic!("Unknown nvdisasm version. stdout: {stdout}");
180 }
181 })
182 }
183
184 #[test]
185 pub fn test_nop() {
186 for &sm in sm_list() {
187 let mut c = DisasmCheck::new();
188 c.push(OpNop { label: None }, "nop;");
189 c.check(sm);
190 }
191 }
192
193 #[test]
194 pub fn test_ldc() {
195 let reg_files = [RegFile::GPR, RegFile::UGPR];
196
197 let ur2_4 = RegRef::new(RegFile::UGPR, 2, 2);
198 let cbufs = [
199 (CBuf::Binding(5), "c[0x5]"),
200 (CBuf::BindlessUGPR(ur2_4), "cx[ur2]"),
201 ];
202
203 let mem_types = [
204 (MemType::U8, ".u8"),
205 (MemType::I8, ".s8"),
206 (MemType::U16, ".u16"),
207 (MemType::I16, ".s16"),
208 (MemType::B32, ""),
209 (MemType::B64, ".64"),
210 (MemType::B128, ".128"),
211 ];
212
213 for &sm in sm_list() {
214 let mut c = DisasmCheck::new();
215 for reg_file in reg_files {
216 if reg_file == RegFile::UGPR && sm < 73 {
217 continue;
218 }
219
220 let ldc_op_str = match reg_file {
221 RegFile::GPR => "ldc",
222 RegFile::UGPR => {
223 if sm >= 100 {
224 "ldcu"
225 } else {
226 "uldc"
227 }
228 }
229 _ => panic!("Unsupported register file"),
230 };
231
232 for (cbuf, cbuf_str) in &cbufs {
233 if matches!(cbuf, CBuf::BindlessUGPR(_)) && sm < 73 {
234 continue;
235 }
236
237 for (mem_type, mem_type_str) in mem_types {
238 if mem_type == MemType::B128
239 && (reg_file == RegFile::GPR || sm < 100)
240 {
241 continue;
242 }
243
244 let dst_regs = mem_type.bits().div_ceil(32);
245 let r4 = RegRef::new(reg_file, 4, dst_regs as u8);
246 let r4_str = format!("{}4", reg_file.fmt_prefix());
247
248 let cb = CBufRef {
249 buf: cbuf.clone(),
250 offset: 0x248,
251 };
252 let mut instr = OpLdc {
253 dst: r4.into(),
254 cb: cb.into(),
255 offset: 0.into(),
256 mode: LdcMode::Indexed,
257 mem_type,
258 };
259
260 c.push(
261 instr.clone(),
262 format!(
263 "{ldc_op_str}{mem_type_str} {r4_str}, {cbuf_str}[0x248];"
264 ),
265 );
266
267 if reg_file == RegFile::GPR
268 || (sm >= 100 && matches!(cbuf, CBuf::Binding(_)))
269 || sm >= 120
270 {
271 let r6 = RegRef::new(reg_file, 6, 1);
272 instr.offset = r6.into();
273
274 c.push(
275 instr.clone(),
276 format!(
277 "{ldc_op_str}{mem_type_str} {r4_str}, {cbuf_str}[{r6}+0x248];"
278 ),
279 );
280 }
281 }
282 }
283 }
284 c.check(sm);
285 }
286 }
287
288 #[test]
289 pub fn test_ld_st_atom() {
290 let r0 = RegRef::new(RegFile::GPR, 0, 1);
291 let r1 = RegRef::new(RegFile::GPR, 1, 1);
292 let r2 = RegRef::new(RegFile::GPR, 2, 1);
293 let r3 = RegRef::new(RegFile::GPR, 3, 1);
294
295 let order = MemOrder::Strong(MemScope::CTA);
296
297 let atom_types = [
298 (AtomType::F16x2, ".f16x2.rn"),
299 (AtomType::U32, ""),
300 (AtomType::I32, ".s32"),
301 (AtomType::F32, ".f32.ftz.rn"),
302 (AtomType::U64, ".64"),
303 (AtomType::I64, ".s64"),
304 (AtomType::F64, ".f64.rn"),
305 ];
306
307 let spaces = [
308 MemSpace::Global(MemAddrType::A64),
309 MemSpace::Shared,
310 MemSpace::Local,
311 ];
312
313 for &sm in sm_list() {
314 let mut c = DisasmCheck::new();
315 for space in spaces {
316 for (addr_offset, addr_offset_str) in [(0x12, "0x12"), (-1, "-0x1")]
317 {
318 let cta = if sm >= 80 { "sm" } else { "cta" };
319
320 let pri = match space {
321 MemSpace::Global(_) => MemEvictionPriority::First,
322 MemSpace::Shared => MemEvictionPriority::Normal,
323 MemSpace::Local => MemEvictionPriority::Normal,
324 };
325 let access = MemAccess {
326 mem_type: MemType::B32,
327 space,
328 order: order,
329 eviction_priority: pri,
330 };
331
332 let instr = OpLd {
333 dst: Dst::Reg(r0),
334 addr: SrcRef::Reg(r1).into(),
335 offset: addr_offset,
336 access: access.clone(),
337 };
338 let expected = match space {
339 MemSpace::Global(_) => {
340 format!(
341 "ldg.e.ef.strong.{cta} r0, [r1+{addr_offset_str}];"
342 )
343 }
344 MemSpace::Shared => {
345 format!("lds r0, [r1+{addr_offset_str}];")
346 }
347 MemSpace::Local => {
348 format!("ldl r0, [r1+{addr_offset_str}];")
349 }
350 };
351 c.push(instr, expected);
352
353 let instr = OpSt {
354 addr: SrcRef::Reg(r1).into(),
355 data: SrcRef::Reg(r2).into(),
356 offset: addr_offset,
357 access: access.clone(),
358 };
359 let expected = match space {
360 MemSpace::Global(_) => {
361 format!(
362 "stg.e.ef.strong.{cta} [r1+{addr_offset_str}], r2;"
363 )
364 }
365 MemSpace::Shared => {
366 format!("sts [r1+{addr_offset_str}], r2;")
367 }
368 MemSpace::Local => {
369 format!("stl [r1+{addr_offset_str}], r2;")
370 }
371 };
372 c.push(instr, expected);
373
374 for (atom_type, atom_type_str) in atom_types {
375 for use_dst in [true, false] {
376 let instr = OpAtom {
377 dst: if use_dst { Dst::Reg(r0) } else { Dst::None },
378 addr: SrcRef::Reg(r1).into(),
379 data: SrcRef::Reg(r2).into(),
380 atom_op: AtomOp::Add,
381 cmpr: SrcRef::Reg(r3).into(),
382 atom_type,
383
384 addr_offset,
385
386 mem_space: space,
387 mem_order: order,
388 mem_eviction_priority: pri,
389 };
390
391 let expected = match space {
392 MemSpace::Global(_) => {
393 let op = if use_dst {
394 "atomg"
395 } else if sm >= 90 {
396 "redg"
397 } else {
398 "red"
399 };
400 let dst = if use_dst { "pt, r0, " } else { "" };
401 format!("{op}.e.add.ef{atom_type_str}.strong.{cta} {dst}[r1+{addr_offset_str}], r2;")
402 }
403 MemSpace::Shared => {
404 if atom_type.is_float() {
405 continue;
406 }
407 if atom_type.bits() == 64 {
408 continue;
409 }
410 let dst = if use_dst { "r0" } else { "rz" };
411 format!("atoms.add{atom_type_str} {dst}, [r1+{addr_offset_str}], r2;")
412 }
413 MemSpace::Local => continue,
414 };
415
416 c.push(instr, expected);
417 }
418 }
419 }
420 }
421 c.check(sm);
422 }
423 }
424
425 #[test]
426 pub fn test_texture() {
427 let r0 = RegRef::new(RegFile::GPR, 0, 1);
428 let r1 = RegRef::new(RegFile::GPR, 1, 1);
429 let r2 = RegRef::new(RegFile::GPR, 2, 1);
430 let r3 = RegRef::new(RegFile::GPR, 3, 1);
431 let p0 = RegRef::new(RegFile::Pred, 0, 1);
432
433 let lod_modes = [
434 TexLodMode::Auto,
435 TexLodMode::Zero,
436 TexLodMode::Lod,
437 TexLodMode::Bias,
438 TexLodMode::Clamp,
439 TexLodMode::BiasClamp,
440 ];
441
442 let tld4_offset_modes = [
443 TexOffsetMode::None,
444 TexOffsetMode::AddOffI,
445 TexOffsetMode::PerPx,
446 ];
447
448 let tex_queries = [
449 TexQuery::Dimension,
450 TexQuery::TextureType,
451 TexQuery::SamplerPos,
452 ];
453
454 for &sm in sm_list() {
455 let mut c = DisasmCheck::new();
456 for lod_mode in lod_modes {
457 if lod_mode == TexLodMode::BiasClamp && sm >= 100 {
458 continue;
459 }
460
461 let instr = OpTex {
462 dsts: [Dst::Reg(r0), Dst::Reg(r2)],
463 fault: Dst::Reg(p0),
464
465 tex: TexRef::Bindless,
466
467 srcs: [SrcRef::Reg(r1).into(), SrcRef::Reg(r3).into()],
468
469 dim: TexDim::_2D,
470 lod_mode,
471 deriv_mode: TexDerivMode::Auto,
472 z_cmpr: false,
473 offset_mode: TexOffsetMode::None,
474 mem_eviction_priority: MemEvictionPriority::First,
475 nodep: true,
476 channel_mask: ChannelMask::for_comps(3),
477 };
478 c.push(
479 instr,
480 format!(
481 "tex.b{lod_mode}.ef.nodep p0, r2, r0, r1, r3, 2d, 0x7;"
482 ),
483 );
484
485 if lod_mode.is_explicit_lod() {
486 let instr = OpTld {
487 dsts: [Dst::Reg(r0), Dst::Reg(r2)],
488 fault: Dst::Reg(p0),
489
490 tex: TexRef::Bindless,
491
492 srcs: [SrcRef::Reg(r1).into(), SrcRef::Reg(r3).into()],
493
494 dim: TexDim::_2D,
495 is_ms: false,
496 lod_mode,
497 offset_mode: TexOffsetMode::None,
498 mem_eviction_priority: MemEvictionPriority::First,
499 nodep: true,
500 channel_mask: ChannelMask::for_comps(3),
501 };
502 c.push(
503 instr,
504 format!(
505 "tld.b{lod_mode}.ef.nodep p0, r2, r0, r1, r3, 2d, 0x7;"
506 ),
507 );
508 }
509 }
510
511 for offset_mode in tld4_offset_modes {
512 let offset_mode_str = if offset_mode == TexOffsetMode::None {
513 String::new()
514 } else {
515 format!("{offset_mode}")
516 };
517
518 let instr = OpTld4 {
519 dsts: [Dst::Reg(r0), Dst::Reg(r2)],
520 fault: Dst::Reg(p0),
521
522 tex: TexRef::Bindless,
523
524 srcs: [SrcRef::Reg(r1).into(), SrcRef::Reg(r3).into()],
525
526 dim: TexDim::_2D,
527 comp: 1,
528 offset_mode,
529 z_cmpr: false,
530 mem_eviction_priority: MemEvictionPriority::First,
531 nodep: true,
532 channel_mask: ChannelMask::for_comps(3),
533 };
534 c.push(
535 instr,
536 format!("tld4.g.b{offset_mode_str}.ef.nodep p0, r2, r0, r1, r3, 2d, 0x7;"),
537 );
538 }
539
540 let instr = OpTmml {
541 dsts: [Dst::Reg(r0), Dst::Reg(r2)],
542
543 tex: TexRef::Bindless,
544
545 srcs: [SrcRef::Reg(r1).into(), SrcRef::Reg(r3).into()],
546
547 dim: TexDim::_2D,
548 deriv_mode: TexDerivMode::Auto,
549 nodep: true,
550 channel_mask: ChannelMask::for_comps(3),
551 };
552 c.push(
553 instr,
554 "tmml.b.lod.nodep r2, r0, r1, r3, 2d, 0x7;".to_string(),
555 );
556
557 let instr = OpTxd {
558 dsts: [Dst::Reg(r0), Dst::Reg(r2)],
559 fault: Dst::Reg(p0),
560
561 tex: TexRef::Bindless,
562
563 srcs: [SrcRef::Reg(r1).into(), SrcRef::Reg(r3).into()],
564
565 dim: TexDim::_2D,
566 offset_mode: TexOffsetMode::None,
567 mem_eviction_priority: MemEvictionPriority::First,
568 nodep: true,
569 channel_mask: ChannelMask::for_comps(3),
570 };
571 c.push(
572 instr,
573 "txd.b.ef.nodep p0, r2, r0, r1, r3, 2d, 0x7;".to_string(),
574 );
575
576 for tex_query in tex_queries {
577 let instr = OpTxq {
578 dsts: [Dst::Reg(r0), Dst::Reg(r2)],
579
580 tex: TexRef::Bindless,
581
582 src: SrcRef::Reg(r1).into(),
583
584 query: tex_query,
585 nodep: true,
586 channel_mask: ChannelMask::for_comps(3),
587 };
588 c.push(
589 instr,
590 format!("txq.b.nodep r2, r0, r1, tex_header_{tex_query}, 0x7;"),
591 );
592 }
593
594 c.check(sm);
595 }
596 }
597
598 #[test]
599 pub fn test_lea() {
600 let r0 = RegRef::new(RegFile::GPR, 0, 1);
601 let r1 = RegRef::new(RegFile::GPR, 1, 1);
602 let r2 = RegRef::new(RegFile::GPR, 2, 1);
603 let r3 = RegRef::new(RegFile::GPR, 3, 1);
604 let p0 = RegRef::new(RegFile::Pred, 0, 1);
605
606 let src_mods = [
607 (SrcMod::None, SrcMod::None),
608 (SrcMod::INeg, SrcMod::None),
609 (SrcMod::None, SrcMod::INeg),
610 ];
611
612 for &sm in sm_list() {
613 let mut c = DisasmCheck::new();
614
615 for (intermediate_mod, b_mod) in src_mods {
616 for shift in 0..32 {
617 let intermediate_mod_str = match intermediate_mod {
618 SrcMod::None => "",
619 SrcMod::INeg => "-",
620 _ => unreachable!(),
621 };
622
623 let mut instr = OpLea {
624 dst: Dst::Reg(r0),
625 overflow: Dst::Reg(p0),
626
627 a: SrcRef::Reg(r1).into(),
628 b: SrcRef::Reg(r2).into(),
629
630 a_high: 0.into(),
631
632 shift,
633 dst_high: false,
634 intermediate_mod,
635 };
636 instr.b.src_mod = b_mod;
637 let disasm = format!(
638 "lea r0, p0, {0}r1, {1}, 0x{2:x};",
639 intermediate_mod_str, instr.b, shift
640 );
641 c.push(instr, disasm);
642
643 let mut instr = OpLea {
644 dst: Dst::Reg(r0),
645 overflow: Dst::Reg(p0),
646
647 a: SrcRef::Reg(r1).into(),
648 b: SrcRef::Reg(r2).into(),
649
650 a_high: SrcRef::Reg(r3).into(),
651
652 shift,
653 dst_high: true,
654 intermediate_mod,
655 };
656 instr.b.src_mod = b_mod;
657 let disasm = format!(
658 "lea.hi r0, p0, {0}r1, {1}, r3, 0x{2:x};",
659 intermediate_mod_str, instr.b, shift
660 );
661 c.push(instr, disasm);
662 }
663 }
664
665 c.check(sm);
666 }
667 }
668
669 #[test]
670 pub fn test_hfma2() {
671 let r0 = RegRef::new(RegFile::GPR, 0, 1);
672 let r1 = RegRef::new(RegFile::GPR, 1, 1);
673 let r2 = RegRef::new(RegFile::GPR, 2, 1);
674 let r3 = RegRef::new(RegFile::GPR, 3, 1);
675
676 let src_mods = [SrcMod::None, SrcMod::FAbs, SrcMod::FNeg, SrcMod::FNegAbs];
677
678 for &sm in sm_list() {
679 let mut c = DisasmCheck::new();
680
681 for a_mod in src_mods {
682 for b_mod in src_mods {
683 for c_mod in src_mods {
684 let mut instr = OpHFma2 {
685 dst: Dst::Reg(r0),
686
687 srcs: [
688 SrcRef::Reg(r1).into(),
689 SrcRef::Reg(r2).into(),
690 SrcRef::Reg(r3).into(),
691 ],
692
693 saturate: false,
694 ftz: false,
695 dnz: false,
696 f32: false,
697 };
698 instr.srcs[0].src_mod = a_mod;
699 instr.srcs[1].src_mod = b_mod;
700 instr.srcs[2].src_mod = c_mod;
701 let disasm = format!(
702 "hfma2 r0, {}, {}, {};",
703 instr.srcs[0], instr.srcs[1], instr.srcs[2],
704 );
705 c.push(instr, disasm);
706 }
707 }
708 }
709
710 c.check(sm);
711 }
712 }
713
714 #[test]
715 pub fn test_redux() {
716 let ur0 = RegRef::new(RegFile::UGPR, 0, 1);
717 let r1 = RegRef::new(RegFile::GPR, 1, 1);
718
719 for &sm in sm_list() {
720 if sm < 80 {
721 continue;
722 }
723
724 let mut c = DisasmCheck::new();
725 for (op, op_str) in [
726 (ReduxOp::And, ""),
727 (ReduxOp::Or, ".or"),
728 (ReduxOp::Xor, ".xor"),
729 (ReduxOp::Sum, ".sum"),
730 (ReduxOp::Min(IntCmpType::U32), ".min"),
731 (ReduxOp::Max(IntCmpType::U32), ".max"),
732 (ReduxOp::Min(IntCmpType::I32), ".min.s32"),
733 (ReduxOp::Max(IntCmpType::I32), ".max.s32"),
734 ] {
735 let instr = OpRedux {
736 dst: Dst::Reg(ur0),
737 src: SrcRef::Reg(r1).into(),
738 op,
739 };
740 let disasm = format!("redux{op_str} ur0, r1;");
741 c.push(instr, disasm);
742 }
743 c.check(sm);
744 }
745 }
746
747 #[test]
748 pub fn test_match() {
749 let r3 = RegRef::new(RegFile::GPR, 3, 1);
750 let p1 = RegRef::new(RegFile::Pred, 1, 1);
751
752 for &sm in sm_list() {
753 let mut c = DisasmCheck::new();
754
755 for (op, pred, pred_str) in [
756 (MatchOp::All, Dst::Reg(p1), "p1, "),
757 (MatchOp::Any, Dst::None, ""),
758 ] {
759 for (src_comps, u64_str) in [(1, ""), (2, ".u64")] {
760 let src = RegRef::new(RegFile::GPR, 4, src_comps);
761 let instr = OpMatch {
762 pred: pred.clone(),
763 mask: Dst::Reg(r3),
764
765 src: SrcRef::Reg(src).into(),
766 op,
767 u64: src_comps == 2,
768 };
769 let disasm = format!("match{op}{u64_str} {pred_str}r3, r4;");
770 c.push(instr, disasm);
771 }
772 }
773
774 c.check(sm);
775 }
776 }
777
778 #[test]
779 pub fn test_sgxt() {
780 let r0 = RegRef::new(RegFile::GPR, 0, 1);
781 let r1 = RegRef::new(RegFile::GPR, 1, 1);
782 let r2 = RegRef::new(RegFile::GPR, 2, 1);
783
784 for &sm in sm_list() {
785 let mut c = DisasmCheck::new();
786 for signed in [false, true] {
787 let instr = OpSgxt {
788 dst: Dst::Reg(r0),
789 a: SrcRef::Reg(r1).into(),
790 bits: SrcRef::Reg(r2).into(),
791 signed,
792 };
793
794 let disasm = if signed {
795 "sgxt r0, r1, r2;"
796 } else {
797 "sgxt.u32 r0, r1, r2;"
798 };
799 c.push(instr, disasm);
800 }
801 c.check(sm);
802 }
803 }
804
805 #[test]
806 pub fn test_plop3() {
807 let p0 = RegRef::new(RegFile::Pred, 0, 1);
808 let p1 = RegRef::new(RegFile::Pred, 1, 1);
809 let p2 = RegRef::new(RegFile::Pred, 2, 1);
810 let p3 = RegRef::new(RegFile::Pred, 3, 1);
811 let p4 = RegRef::new(RegFile::Pred, 4, 1);
812
813 let src_mods = [SrcMod::None, SrcMod::BNot];
814
815 for &sm in sm_list() {
816 let mut c = DisasmCheck::new();
817 for a_mod in src_mods {
818 for b_mod in src_mods {
819 for c_mod in src_mods {
820 for lut_bit in 0..16 {
821 let lut = 1 << lut_bit;
822 let lut0 = (lut >> 0) as u8;
823 let lut1 = (lut >> 8) as u8;
824
825 let mut instr = OpPLop3 {
826 dsts: [p0.into(), p1.into()],
827 ops: [
828 LogicOp3 { lut: lut0 },
829 LogicOp3 { lut: lut1 },
830 ],
831 srcs: [p2.into(), p3.into(), p4.into()],
832 };
833 instr.srcs[0].src_mod = a_mod;
834 instr.srcs[1].src_mod = b_mod;
835 instr.srcs[2].src_mod = c_mod;
836
837 let disasm = format!(
838 "plop3.lut p0, p1, {}, {}, {}, {:#x}, {:#x};",
839 instr.srcs[0],
840 instr.srcs[1],
841 instr.srcs[2],
842 lut0,
843 lut1,
844 );
845 c.push(instr, disasm);
846 }
847 }
848 }
849 }
850 c.check(sm);
851 }
852 }