Module: Mesa
Branch: main
Commit: 8e00ee6fe875bae1cc4cc22437ebc264eeaa860b
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=8e00ee6fe875bae1cc4cc22437ebc264eeaa860b

Author: Faith Ekstrand <[email protected]>
Date:   Thu Nov  9 13:57:56 2023 -0600

nak: Drop OpAtomCas in favor of OpAtom with atom_op == CmpExch

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26181>

---

 src/nouveau/compiler/nak_encode_sm75.rs | 67 +++++++++------------------------
 src/nouveau/compiler/nak_from_nir.rs    |  8 +++-
 src/nouveau/compiler/nak_ir.rs          | 52 ++-----------------------
 3 files changed, 27 insertions(+), 100 deletions(-)

diff --git a/src/nouveau/compiler/nak_encode_sm75.rs 
b/src/nouveau/compiler/nak_encode_sm75.rs
index 323e800fded..f8aebda7c0d 100644
--- a/src/nouveau/compiler/nak_encode_sm75.rs
+++ b/src/nouveau/compiler/nak_encode_sm75.rs
@@ -1390,38 +1390,24 @@ impl SM75Instr {
     }
 
     fn encode_atomg(&mut self, op: &OpAtom) {
-        self.set_opcode(0x38a);
+        if op.atom_op == AtomOp::CmpExch {
+            self.set_opcode(0x38b);
 
-        self.set_dst(op.dst);
-        self.set_pred_dst(81..84, Dst::None);
-
-        self.set_reg_src(24..32, op.addr);
-        self.set_reg_src(32..40, op.data);
-        self.set_field(40..64, op.addr_offset);
-
-        self.set_field(
-            72..73,
-            match op.addr_type {
-                MemAddrType::A32 => 0_u8,
-                MemAddrType::A64 => 1_u8,
-            },
-        );
+            self.set_reg_src(32..40, op.cmpr);
+            self.set_reg_src(64..72, op.data);
+        } else {
+            self.set_opcode(0x38a);
 
-        self.set_atom_type(73..76, op.atom_type);
-        self.set_mem_order(&op.mem_order);
-        self.set_atom_op(87..91, op.atom_op);
-    }
+            self.set_reg_src(32..40, op.data);
 
-    fn encode_atomg_cas(&mut self, op: &OpAtomCas) {
-        self.set_opcode(0x38b);
+            self.set_atom_op(87..91, op.atom_op);
+        }
 
         self.set_dst(op.dst);
         self.set_pred_dst(81..84, Dst::None);
 
         self.set_reg_src(24..32, op.addr);
-        self.set_reg_src(32..40, op.cmpr);
         self.set_field(40..64, op.addr_offset);
-        self.set_reg_src(64..72, op.data);
 
         self.set_field(
             72..73,
@@ -1436,30 +1422,22 @@ impl SM75Instr {
     }
 
     fn encode_atoms(&mut self, op: &OpAtom) {
-        self.set_opcode(0x38c);
+        if op.atom_op == AtomOp::CmpExch {
+            self.set_opcode(0x38d);
 
-        self.set_dst(op.dst);
-
-        self.set_reg_src(24..32, op.addr);
-        self.set_reg_src(32..40, op.data);
-        self.set_field(40..64, op.addr_offset);
-
-        assert!(op.addr_type == MemAddrType::A32);
-        assert!(op.mem_order == MemOrder::Strong(MemScope::CTA));
+            self.set_reg_src(32..40, op.cmpr);
+            self.set_reg_src(64..72, op.data);
+        } else {
+            self.set_opcode(0x38c);
 
-        self.set_atom_type(73..76, op.atom_type);
-        self.set_atom_op(87..91, op.atom_op);
-    }
+            self.set_reg_src(32..40, op.data);
 
-    fn encode_atoms_cas(&mut self, op: &OpAtomCas) {
-        self.set_opcode(0x38d);
+            self.set_atom_op(87..91, op.atom_op);
+        }
 
         self.set_dst(op.dst);
-
         self.set_reg_src(24..32, op.addr);
-        self.set_reg_src(32..40, op.cmpr);
         self.set_field(40..64, op.addr_offset);
-        self.set_reg_src(64..72, op.data);
 
         assert!(op.addr_type == MemAddrType::A32);
         assert!(op.mem_order == MemOrder::Strong(MemScope::CTA));
@@ -1475,14 +1453,6 @@ impl SM75Instr {
         }
     }
 
-    fn encode_atom_cas(&mut self, op: &OpAtomCas) {
-        match op.mem_space {
-            MemSpace::Global => self.encode_atomg_cas(op),
-            MemSpace::Local => panic!("Atomics do not support local"),
-            MemSpace::Shared => self.encode_atoms_cas(op),
-        }
-    }
-
     fn encode_al2p(&mut self, op: &OpAL2P) {
         self.set_opcode(0x920);
 
@@ -1867,7 +1837,6 @@ impl SM75Instr {
             Op::Ldc(op) => si.encode_ldc(&op),
             Op::St(op) => si.encode_st(&op),
             Op::Atom(op) => si.encode_atom(&op),
-            Op::AtomCas(op) => si.encode_atom_cas(&op),
             Op::AL2P(op) => si.encode_al2p(&op),
             Op::ALd(op) => si.encode_ald(&op),
             Op::ASt(op) => si.encode_ast(&op),
diff --git a/src/nouveau/compiler/nak_from_nir.rs 
b/src/nouveau/compiler/nak_from_nir.rs
index 9b7d2cad1e3..164b10e92d8 100644
--- a/src/nouveau/compiler/nak_from_nir.rs
+++ b/src/nouveau/compiler/nak_from_nir.rs
@@ -1521,6 +1521,7 @@ impl<'a> ShaderFromNir<'a> {
                 b.push_op(OpAtom {
                     dst: dst.into(),
                     addr: addr,
+                    cmpr: 0.into(),
                     data: data,
                     atom_op: atom_op,
                     atom_type: atom_type,
@@ -1542,11 +1543,12 @@ impl<'a> ShaderFromNir<'a> {
                 assert!(intrin.def.num_components() == 1);
                 let dst = b.alloc_ssa(RegFile::GPR, bit_size.div_ceil(32));
 
-                b.push_op(OpAtomCas {
+                b.push_op(OpAtom {
                     dst: dst.into(),
                     addr: addr,
                     cmpr: cmpr,
                     data: data,
+                    atom_op: AtomOp::CmpExch,
                     atom_type: atom_type,
                     addr_type: MemAddrType::A64,
                     addr_offset: offset,
@@ -1933,6 +1935,7 @@ impl<'a> ShaderFromNir<'a> {
                 b.push_op(OpAtom {
                     dst: dst.into(),
                     addr: addr,
+                    cmpr: 0.into(),
                     data: data,
                     atom_op: atom_op,
                     atom_type: atom_type,
@@ -1954,11 +1957,12 @@ impl<'a> ShaderFromNir<'a> {
                 assert!(intrin.def.num_components() == 1);
                 let dst = b.alloc_ssa(RegFile::GPR, bit_size.div_ceil(32));
 
-                b.push_op(OpAtomCas {
+                b.push_op(OpAtom {
                     dst: dst.into(),
                     addr: addr,
                     cmpr: cmpr,
                     data: data,
+                    atom_op: AtomOp::CmpExch,
                     atom_type: atom_type,
                     addr_type: MemAddrType::A32,
                     addr_offset: offset,
diff --git a/src/nouveau/compiler/nak_ir.rs b/src/nouveau/compiler/nak_ir.rs
index 234b45f2a30..cf3b2f86a17 100644
--- a/src/nouveau/compiler/nak_ir.rs
+++ b/src/nouveau/compiler/nak_ir.rs
@@ -3219,6 +3219,9 @@ pub struct OpAtom {
     #[src_type(GPR)]
     pub addr: Src,
 
+    #[src_type(SSA)]
+    pub cmpr: Src,
+
     #[src_type(SSA)]
     pub data: Src,
 
@@ -3253,50 +3256,6 @@ impl fmt::Display for OpAtom {
     }
 }
 
-#[repr(C)]
-#[derive(SrcsAsSlice, DstsAsSlice)]
-pub struct OpAtomCas {
-    pub dst: Dst,
-
-    #[src_type(GPR)]
-    pub addr: Src,
-
-    #[src_type(SSA)]
-    pub cmpr: Src,
-
-    #[src_type(SSA)]
-    pub data: Src,
-
-    pub atom_type: AtomType,
-
-    pub addr_type: MemAddrType,
-    pub addr_offset: i32,
-
-    pub mem_space: MemSpace,
-    pub mem_order: MemOrder,
-}
-
-impl fmt::Display for OpAtomCas {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(
-            f,
-            "ATOM.CAS.{}.{} {}",
-            self.atom_type, self.mem_order, self.dst
-        )?;
-        write!(f, " [")?;
-        if !self.addr.is_zero() {
-            write!(f, "{}", self.addr)?;
-        }
-        if self.addr_offset > 0 {
-            if !self.addr.is_zero() {
-                write!(f, "+")?;
-            }
-            write!(f, "+{:#x}", self.addr_offset)?;
-        }
-        write!(f, "] {} {}", self.cmpr, self.data)
-    }
-}
-
 #[repr(C)]
 #[derive(SrcsAsSlice, DstsAsSlice)]
 pub struct OpAL2P {
@@ -4210,7 +4169,6 @@ pub enum Op {
     Ldc(OpLdc),
     St(OpSt),
     Atom(OpAtom),
-    AtomCas(OpAtomCas),
     AL2P(OpAL2P),
     ALd(OpALd),
     ASt(OpASt),
@@ -4546,7 +4504,6 @@ impl Instr {
     pub fn uses_global_mem(&self) -> bool {
         match &self.op {
             Op::Atom(op) => op.mem_space != MemSpace::Local,
-            Op::AtomCas(op) => op.mem_space != MemSpace::Local,
             Op::Ld(op) => op.access.space != MemSpace::Local,
             Op::St(op) => op.access.space != MemSpace::Local,
             Op::SuAtom(_) | Op::SuLd(_) | Op::SuSt(_) => true,
@@ -4557,7 +4514,6 @@ impl Instr {
     pub fn writes_global_mem(&self) -> bool {
         match &self.op {
             Op::Atom(op) => op.mem_space == MemSpace::Global,
-            Op::AtomCas(op) => op.mem_space == MemSpace::Global,
             Op::St(op) => op.access.space == MemSpace::Global,
             Op::SuAtom(_) | Op::SuSt(_) => true,
             _ => false,
@@ -4571,7 +4527,6 @@ impl Instr {
             | Op::SuAtom(_)
             | Op::St(_)
             | Op::Atom(_)
-            | Op::AtomCas(_)
             | Op::CCtl(_)
             | Op::MemBar(_)
             | Op::Kill(_)
@@ -4647,7 +4602,6 @@ impl Instr {
             | Op::Ldc(_)
             | Op::St(_)
             | Op::Atom(_)
-            | Op::AtomCas(_)
             | Op::AL2P(_)
             | Op::ALd(_)
             | Op::ASt(_)

Reply via email to