fuel_asm/
op.rs

1//! Definitions and implementations for each unique instruction type, one for each
2//! unique `Opcode` variant.
3
4use super::{
5    wideint::{
6        CompareArgs,
7        DivArgs,
8        MathArgs,
9        MulArgs,
10    },
11    CheckRegId,
12    GMArgs,
13    GTFArgs,
14    Imm12,
15    Imm18,
16    Instruction,
17    RegId,
18};
19
20// Here we re-export the generated instruction types and constructors, but extend them
21// with `gm_args` and `gtf_args` short-hand constructors below to take their `GMArgs` and
22// `GTFArgs` values respectively.
23#[doc(inline)]
24pub use super::_op::*;
25
26#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
27impl GM {
28    /// Construct a `GM` instruction from its arguments.
29    pub fn from_args(ra: RegId, args: GMArgs) -> Self {
30        Self::new(ra, Imm18::new(args as _))
31    }
32}
33
34#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
35impl GTF {
36    /// Construct a `GTF` instruction from its arguments.
37    pub fn from_args(ra: RegId, rb: RegId, args: GTFArgs) -> Self {
38        Self::new(ra, rb, Imm12::new(args as _))
39    }
40}
41
42/// Construct a `GM` instruction from its arguments.
43pub fn gm_args<A: CheckRegId>(ra: A, args: GMArgs) -> Instruction {
44    Instruction::GM(GM::from_args(ra.check(), args))
45}
46
47#[cfg(feature = "typescript")]
48const _: () = {
49    use super::*;
50
51    #[wasm_bindgen::prelude::wasm_bindgen]
52    /// Construct a `GM` instruction from its arguments.
53    pub fn gm_args(ra: u8, args: GMArgs) -> typescript::Instruction {
54        Instruction::GM(GM::from_args(ra.check(), args)).into()
55    }
56};
57
58/// Construct a `GM` instruction from its arguments.
59pub fn gtf_args<A: CheckRegId, B: CheckRegId>(
60    ra: A,
61    rb: B,
62    args: GTFArgs,
63) -> Instruction {
64    Instruction::GTF(GTF::from_args(ra.check(), rb.check(), args))
65}
66
67#[cfg(feature = "typescript")]
68const _: () = {
69    use super::*;
70
71    #[wasm_bindgen::prelude::wasm_bindgen]
72    /// Construct a `GM` instruction from its arguments.
73    pub fn gtf_args(ra: u8, rb: u8, args: GTFArgs) -> typescript::Instruction {
74        Instruction::GTF(GTF::from_args(ra.check(), rb.check(), args)).into()
75    }
76};
77
78#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
79impl WDCM {
80    /// Construct a `WDCM` instruction from its arguments.
81    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: CompareArgs) -> Self {
82        Self::new(ra, rb, rc, args.to_imm())
83    }
84}
85
86#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
87impl WQCM {
88    /// Construct a `WQCM` instruction from its arguments.
89    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: CompareArgs) -> Self {
90        Self::new(ra, rb, rc, args.to_imm())
91    }
92}
93
94#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
95impl WDOP {
96    /// Construct a `WDOP` instruction from its arguments.
97    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: MathArgs) -> Self {
98        Self::new(ra, rb, rc, args.to_imm())
99    }
100}
101
102#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
103impl WQOP {
104    /// Construct a `WQOP` instruction from its arguments.
105    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: MathArgs) -> Self {
106        Self::new(ra, rb, rc, args.to_imm())
107    }
108}
109
110#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
111impl WDML {
112    /// Construct a `WDML` instruction from its arguments.
113    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: MulArgs) -> Self {
114        Self::new(ra, rb, rc, args.to_imm())
115    }
116}
117
118#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
119impl WQML {
120    /// Construct a `WQML` instruction from its arguments.
121    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: MulArgs) -> Self {
122        Self::new(ra, rb, rc, args.to_imm())
123    }
124}
125
126#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
127impl WDDV {
128    /// Construct a `WDDV` instruction from its arguments.
129    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: DivArgs) -> Self {
130        Self::new(ra, rb, rc, args.to_imm())
131    }
132}
133
134#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
135impl WQDV {
136    /// Construct a `WQDV` instruction from its arguments.
137    pub fn from_args(ra: RegId, rb: RegId, rc: RegId, args: DivArgs) -> Self {
138        Self::new(ra, rb, rc, args.to_imm())
139    }
140}
141
142/// Construct a `WDCM` instruction from its arguments.
143pub fn wdcm_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
144    ra: A,
145    rb: B,
146    rc: C,
147    args: CompareArgs,
148) -> Instruction {
149    Instruction::WDCM(WDCM::from_args(ra.check(), rb.check(), rc.check(), args))
150}
151
152#[cfg(feature = "typescript")]
153const _: () = {
154    use super::*;
155
156    #[wasm_bindgen::prelude::wasm_bindgen]
157    /// Construct a `WDCM` instruction from its arguments.
158    pub fn wdcm_args(
159        ra: u8,
160        rb: u8,
161        rc: u8,
162        args: CompareArgs,
163    ) -> typescript::Instruction {
164        crate::op::wdcm_args(ra, rb, rc, args).into()
165    }
166};
167
168/// Construct a `WQCM` instruction from its arguments.
169pub fn wqcm_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
170    ra: A,
171    rb: B,
172    rc: C,
173    args: CompareArgs,
174) -> Instruction {
175    Instruction::WQCM(WQCM::from_args(ra.check(), rb.check(), rc.check(), args))
176}
177
178#[cfg(feature = "typescript")]
179const _: () = {
180    use super::*;
181
182    #[wasm_bindgen::prelude::wasm_bindgen]
183    /// Construct a `WQCM` instruction from its arguments.
184    pub fn wqcm_args(
185        ra: u8,
186        rb: u8,
187        rc: u8,
188        args: CompareArgs,
189    ) -> typescript::Instruction {
190        crate::op::wqcm_args(ra, rb, rc, args).into()
191    }
192};
193
194/// Construct a `WDOP` instruction from its arguments.
195pub fn wdop_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
196    ra: A,
197    rb: B,
198    rc: C,
199    args: MathArgs,
200) -> Instruction {
201    Instruction::WDOP(WDOP::from_args(ra.check(), rb.check(), rc.check(), args))
202}
203
204#[cfg(feature = "typescript")]
205const _: () = {
206    use super::*;
207
208    #[wasm_bindgen::prelude::wasm_bindgen]
209    /// Construct a `WDOP` instruction from its arguments.
210    pub fn wdop_args(ra: u8, rb: u8, rc: u8, args: MathArgs) -> typescript::Instruction {
211        crate::op::wdop_args(ra, rb, rc, args).into()
212    }
213};
214
215/// Construct a `WQOP` instruction from its arguments.
216pub fn wqop_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
217    ra: A,
218    rb: B,
219    rc: C,
220    args: MathArgs,
221) -> Instruction {
222    Instruction::WQOP(WQOP::from_args(ra.check(), rb.check(), rc.check(), args))
223}
224
225#[cfg(feature = "typescript")]
226const _: () = {
227    use super::*;
228
229    #[wasm_bindgen::prelude::wasm_bindgen]
230    /// Construct a `WQOP` instruction from its arguments.
231    pub fn wqop_args(ra: u8, rb: u8, rc: u8, args: MathArgs) -> typescript::Instruction {
232        crate::op::wqop_args(ra, rb, rc, args).into()
233    }
234};
235
236/// Construct a `WDML` instruction from its arguments.
237pub fn wdml_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
238    ra: A,
239    rb: B,
240    rc: C,
241    args: MulArgs,
242) -> Instruction {
243    Instruction::WDML(WDML::from_args(ra.check(), rb.check(), rc.check(), args))
244}
245
246#[cfg(feature = "typescript")]
247const _: () = {
248    use super::*;
249
250    #[wasm_bindgen::prelude::wasm_bindgen]
251    /// Construct a `WDML` instruction from its arguments.
252    pub fn wdml_args(ra: u8, rb: u8, rc: u8, args: MulArgs) -> typescript::Instruction {
253        crate::op::wdml_args(ra, rb, rc, args).into()
254    }
255};
256
257/// Construct a `WQML` instruction from its arguments.
258pub fn wqml_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
259    ra: A,
260    rb: B,
261    rc: C,
262    args: MulArgs,
263) -> Instruction {
264    Instruction::WQML(WQML::from_args(ra.check(), rb.check(), rc.check(), args))
265}
266
267#[cfg(feature = "typescript")]
268const _: () = {
269    use super::*;
270
271    #[wasm_bindgen::prelude::wasm_bindgen]
272    /// Construct a `WQML` instruction from its arguments.
273    pub fn wqml_args(ra: u8, rb: u8, rc: u8, args: MulArgs) -> typescript::Instruction {
274        crate::op::wqml_args(ra, rb, rc, args).into()
275    }
276};
277
278/// Construct a `WDDV` instruction from its arguments.
279pub fn wddv_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
280    ra: A,
281    rb: B,
282    rc: C,
283    args: DivArgs,
284) -> Instruction {
285    Instruction::WDDV(WDDV::from_args(ra.check(), rb.check(), rc.check(), args))
286}
287
288#[cfg(feature = "typescript")]
289const _: () = {
290    use super::*;
291
292    #[wasm_bindgen::prelude::wasm_bindgen]
293    /// Construct a `WDDV` instruction from its arguments.
294    pub fn wddv_args(ra: u8, rb: u8, rc: u8, args: DivArgs) -> typescript::Instruction {
295        crate::op::wddv_args(ra, rb, rc, args).into()
296    }
297};
298
299/// Construct a `WQDV` instruction from its arguments.
300pub fn wqdv_args<A: CheckRegId, B: CheckRegId, C: CheckRegId>(
301    ra: A,
302    rb: B,
303    rc: C,
304    args: DivArgs,
305) -> Instruction {
306    Instruction::WQDV(WQDV::from_args(ra.check(), rb.check(), rc.check(), args))
307}
308
309#[cfg(feature = "typescript")]
310const _: () = {
311    use super::*;
312
313    #[wasm_bindgen::prelude::wasm_bindgen]
314    /// Construct a `WQDV` instruction from its arguments.
315    pub fn wqdv_args(ra: u8, rb: u8, rc: u8, args: DivArgs) -> typescript::Instruction {
316        crate::op::wqdv_args(ra, rb, rc, args).into()
317    }
318};