1/*
2 *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 *
4 *  This program is free software; you can redistribute it and/or modify
5 *  it under the terms of the GNU General Public License as published by
6 *  the Free Software Foundation; either version 2 of the License, or
7 *  (at your option) any later version.
8 *
9 *  This program is distributed in the hope that it will be useful,
10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *  GNU General Public License for more details.
13 *
14 *  You should have received a copy of the GNU General Public License
15 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Compare Instructions
20 */
21
22
23
24/*********************************************/
25/* Scalar compare instructions               */
26/*********************************************/
27
28Q6INSN(C2_cmpeq,"Pd4=cmp.eq(Rs32,Rt32)",ATTRIBS(),
29"Compare for Equal",
30{PdV=f8BITSOF(RsV==RtV);})
31
32Q6INSN(C2_cmpgt,"Pd4=cmp.gt(Rs32,Rt32)",ATTRIBS(),
33"Compare for signed Greater Than",
34{PdV=f8BITSOF(RsV>RtV);})
35
36Q6INSN(C2_cmpgtu,"Pd4=cmp.gtu(Rs32,Rt32)",ATTRIBS(),
37"Compare for Greater Than Unsigned",
38{PdV=f8BITSOF(fCAST4u(RsV)>fCAST4u(RtV));})
39
40Q6INSN(C2_cmpeqp,"Pd4=cmp.eq(Rss32,Rtt32)",ATTRIBS(),
41"Compare for Equal",
42{PdV=f8BITSOF(RssV==RttV);})
43
44Q6INSN(C2_cmpgtp,"Pd4=cmp.gt(Rss32,Rtt32)",ATTRIBS(),
45"Compare for signed Greater Than",
46{PdV=f8BITSOF(RssV>RttV);})
47
48Q6INSN(C2_cmpgtup,"Pd4=cmp.gtu(Rss32,Rtt32)",ATTRIBS(),
49"Compare for Greater Than Unsigned",
50{PdV=f8BITSOF(fCAST8u(RssV)>fCAST8u(RttV));})
51
52
53
54
55/*********************************************/
56/* Compare and put result in GPR             */
57/*  typically for function I/O               */
58/*********************************************/
59
60Q6INSN(A4_rcmpeqi,"Rd32=cmp.eq(Rs32,#s8)",ATTRIBS(),
61"Compare for Equal",
62{fIMMEXT(siV); RdV=(RsV==siV); })
63
64Q6INSN(A4_rcmpneqi,"Rd32=!cmp.eq(Rs32,#s8)",ATTRIBS(),
65"Compare for Equal",
66{fIMMEXT(siV); RdV=(RsV!=siV); })
67
68
69Q6INSN(A4_rcmpeq,"Rd32=cmp.eq(Rs32,Rt32)",ATTRIBS(),
70"Compare for Equal",
71{RdV=(RsV==RtV); })
72
73Q6INSN(A4_rcmpneq,"Rd32=!cmp.eq(Rs32,Rt32)",ATTRIBS(),
74"Compare for Equal",
75{RdV=(RsV!=RtV); })
76
77
78
79/*********************************************/
80/* Scalar compare instructions               */
81/*********************************************/
82
83
84Q6INSN(C2_bitsset,"Pd4=bitsset(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
85"Compare for selected bits set",
86{PdV=f8BITSOF((RsV&RtV)==RtV);})
87
88Q6INSN(C2_bitsclr,"Pd4=bitsclr(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
89"Compare for selected bits clear",
90{PdV=f8BITSOF((RsV&RtV)==0);})
91
92
93Q6INSN(C4_nbitsset,"Pd4=!bitsset(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
94"Compare for selected bits set",
95{PdV=f8BITSOF((RsV&RtV)!=RtV);})
96
97Q6INSN(C4_nbitsclr,"Pd4=!bitsclr(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
98"Compare for selected bits clear",
99{PdV=f8BITSOF((RsV&RtV)!=0);})
100
101
102
103/*********************************************/
104/* Scalar compare instructions W/ immediate  */
105/*********************************************/
106
107Q6INSN(C2_cmpeqi,"Pd4=cmp.eq(Rs32,#s10)",ATTRIBS(),
108"Compare for Equal",
109{fIMMEXT(siV); PdV=f8BITSOF(RsV==siV);})
110
111Q6INSN(C2_cmpgti,"Pd4=cmp.gt(Rs32,#s10)",ATTRIBS(),
112"Compare for signed Greater Than",
113{fIMMEXT(siV); PdV=f8BITSOF(RsV>siV);})
114
115Q6INSN(C2_cmpgtui,"Pd4=cmp.gtu(Rs32,#u9)",ATTRIBS(),
116"Compare for Greater Than Unsigned",
117{fIMMEXT(uiV); PdV=f8BITSOF(fCAST4u(RsV)>fCAST4u(uiV));})
118
119Q6INSN(C2_bitsclri,"Pd4=bitsclr(Rs32,#u6)",ATTRIBS(A_ARCHV2),
120"Compare for selected bits clear",
121{PdV=f8BITSOF((RsV&uiV)==0);})
122
123Q6INSN(C4_nbitsclri,"Pd4=!bitsclr(Rs32,#u6)",ATTRIBS(A_ARCHV2),
124"Compare for selected bits clear",
125{PdV=f8BITSOF((RsV&uiV)!=0);})
126
127
128
129
130Q6INSN(C4_cmpneqi,"Pd4=!cmp.eq(Rs32,#s10)",ATTRIBS(), "Compare for Not Equal", {fIMMEXT(siV); PdV=f8BITSOF(RsV!=siV);})
131Q6INSN(C4_cmpltei,"Pd4=!cmp.gt(Rs32,#s10)",ATTRIBS(), "Compare for Less Than or Equal", {fIMMEXT(siV); PdV=f8BITSOF(RsV<=siV);})
132Q6INSN(C4_cmplteui,"Pd4=!cmp.gtu(Rs32,#u9)",ATTRIBS(), "Compare for Less Than or Equal Unsigned", {fIMMEXT(uiV); PdV=f8BITSOF(fCAST4u(RsV)<=fCAST4u(uiV));})
133
134Q6INSN(C4_cmpneq,"Pd4=!cmp.eq(Rs32,Rt32)",ATTRIBS(), "And-Compare for Equal", {PdV=f8BITSOF(RsV!=RtV);})
135Q6INSN(C4_cmplte,"Pd4=!cmp.gt(Rs32,Rt32)",ATTRIBS(), "And-Compare for signed Greater Than", {PdV=f8BITSOF(RsV<=RtV);})
136Q6INSN(C4_cmplteu,"Pd4=!cmp.gtu(Rs32,Rt32)",ATTRIBS(), "And-Compare for Greater Than Unsigned", {PdV=f8BITSOF(fCAST4u(RsV)<=fCAST4u(RtV));})
137
138
139
140
141
142/* Predicate Logical Operations */
143
144Q6INSN(C2_and,"Pd4=and(Pt4,Ps4)",ATTRIBS(A_CRSLOT23),
145"Predicate AND",
146{PdV=PsV & PtV;})
147
148Q6INSN(C2_or,"Pd4=or(Pt4,Ps4)",ATTRIBS(A_CRSLOT23),
149"Predicate OR",
150{PdV=PsV | PtV;})
151
152Q6INSN(C2_xor,"Pd4=xor(Ps4,Pt4)",ATTRIBS(A_CRSLOT23),
153"Predicate XOR",
154{PdV=PsV ^ PtV;})
155
156Q6INSN(C2_andn,"Pd4=and(Pt4,!Ps4)",ATTRIBS(A_CRSLOT23),
157"Predicate AND NOT",
158{PdV=PtV & (~PsV);})
159
160Q6INSN(C2_not,"Pd4=not(Ps4)",ATTRIBS(A_CRSLOT23),
161"Logical NOT Predicate",
162{PdV=~PsV;})
163
164Q6INSN(C2_orn,"Pd4=or(Pt4,!Ps4)",ATTRIBS(A_ARCHV2,A_CRSLOT23),
165"Predicate OR NOT",
166{PdV=PtV | (~PsV);})
167
168
169
170
171
172Q6INSN(C4_and_and,"Pd4=and(Ps4,and(Pt4,Pu4))",ATTRIBS(A_CRSLOT23),
173"Compound And-And", { PdV = PsV & PtV & PuV; })
174
175Q6INSN(C4_and_or,"Pd4=and(Ps4,or(Pt4,Pu4))",ATTRIBS(A_CRSLOT23),
176"Compound And-Or", { PdV = PsV &  (PtV | PuV); })
177
178Q6INSN(C4_or_and,"Pd4=or(Ps4,and(Pt4,Pu4))",ATTRIBS(A_CRSLOT23),
179"Compound Or-And", { PdV = PsV | (PtV & PuV); })
180
181Q6INSN(C4_or_or,"Pd4=or(Ps4,or(Pt4,Pu4))",ATTRIBS(A_CRSLOT23),
182"Compound Or-Or", { PdV = PsV | PtV | PuV; })
183
184
185
186Q6INSN(C4_and_andn,"Pd4=and(Ps4,and(Pt4,!Pu4))",ATTRIBS(A_CRSLOT23),
187"Compound And-And", { PdV = PsV & PtV & (~PuV); })
188
189Q6INSN(C4_and_orn,"Pd4=and(Ps4,or(Pt4,!Pu4))",ATTRIBS(A_CRSLOT23),
190"Compound And-Or", { PdV = PsV &  (PtV | (~PuV)); })
191
192Q6INSN(C4_or_andn,"Pd4=or(Ps4,and(Pt4,!Pu4))",ATTRIBS(A_CRSLOT23),
193"Compound Or-And", { PdV = PsV | (PtV & (~PuV)); })
194
195Q6INSN(C4_or_orn,"Pd4=or(Ps4,or(Pt4,!Pu4))",ATTRIBS(A_CRSLOT23),
196"Compound Or-Or", { PdV = PsV | PtV | (~PuV); })
197
198
199Q6INSN(C2_any8,"Pd4=any8(Ps4)",ATTRIBS(A_CRSLOT23),
200"Logical ANY of low 8 predicate bits",
201{ PdV = (PsV ? 0xff : 0x00); })
202
203Q6INSN(C2_all8,"Pd4=all8(Ps4)",ATTRIBS(A_CRSLOT23),
204"Logical ALL of low 8 predicate bits",
205{ PdV = (PsV == 0xff ? 0xff : 0x00); })
206
207Q6INSN(C2_vitpack,"Rd32=vitpack(Ps4,Pt4)",ATTRIBS(),
208"Pack the odd and even bits of two predicate registers",
209{ RdV = (PsV&0x55) | (PtV&0xAA); })
210
211/* Mux instructions */
212
213Q6INSN(C2_mux,"Rd32=mux(Pu4,Rs32,Rt32)",ATTRIBS(),
214"Scalar MUX",
215{ RdV = (fLSBOLD(PuV) ? RsV : RtV); })
216
217
218Q6INSN(C2_cmovenewit,"if (Pu4.new) Rd32=#s12",ATTRIBS(A_ARCHV2),
219"Scalar conditional move",
220{ fIMMEXT(siV); if (fLSBNEW(PuN)) RdV=siV; else CANCEL;})
221
222Q6INSN(C2_cmovenewif,"if (!Pu4.new) Rd32=#s12",ATTRIBS(A_ARCHV2),
223"Scalar conditional move",
224{ fIMMEXT(siV); if (fLSBNEWNOT(PuN)) RdV=siV; else CANCEL;})
225
226Q6INSN(C2_cmoveit,"if (Pu4) Rd32=#s12",ATTRIBS(A_ARCHV2),
227"Scalar conditional move",
228{ fIMMEXT(siV); if (fLSBOLD(PuV)) RdV=siV; else CANCEL;})
229
230Q6INSN(C2_cmoveif,"if (!Pu4) Rd32=#s12",ATTRIBS(A_ARCHV2),
231"Scalar conditional move",
232{ fIMMEXT(siV); if (fLSBOLDNOT(PuV)) RdV=siV; else CANCEL;})
233
234
235
236Q6INSN(C2_ccombinewnewt,"if (Pu4.new) Rdd32=combine(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
237"Conditionally combine two words into a register pair",
238{ if (fLSBNEW(PuN)) {
239    fSETWORD(0,RddV,RtV);
240    fSETWORD(1,RddV,RsV);
241  } else {CANCEL;}
242})
243
244Q6INSN(C2_ccombinewnewf,"if (!Pu4.new) Rdd32=combine(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
245"Conditionally combine two words into a register pair",
246{ if (fLSBNEWNOT(PuN)) {
247    fSETWORD(0,RddV,RtV);
248    fSETWORD(1,RddV,RsV);
249  } else {CANCEL;}
250})
251
252Q6INSN(C2_ccombinewt,"if (Pu4) Rdd32=combine(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
253"Conditionally combine two words into a register pair",
254{ if (fLSBOLD(PuV)) {
255    fSETWORD(0,RddV,RtV);
256    fSETWORD(1,RddV,RsV);
257  } else {CANCEL;}
258})
259
260Q6INSN(C2_ccombinewf,"if (!Pu4) Rdd32=combine(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
261"Conditionally combine two words into a register pair",
262{ if (fLSBOLDNOT(PuV)) {
263    fSETWORD(0,RddV,RtV);
264    fSETWORD(1,RddV,RsV);
265  } else {CANCEL;}
266})
267
268
269
270Q6INSN(C2_muxii,"Rd32=mux(Pu4,#s8,#S8)",ATTRIBS(A_ARCHV2),
271"Scalar MUX immediates",
272{ fIMMEXT(siV); RdV = (fLSBOLD(PuV) ? siV : SiV); })
273
274
275
276Q6INSN(C2_muxir,"Rd32=mux(Pu4,Rs32,#s8)",ATTRIBS(A_ARCHV2),
277"Scalar MUX register immediate",
278{ fIMMEXT(siV); RdV = (fLSBOLD(PuV) ? RsV : siV); })
279
280
281Q6INSN(C2_muxri,"Rd32=mux(Pu4,#s8,Rs32)",ATTRIBS(A_ARCHV2),
282"Scalar MUX register immediate",
283{ fIMMEXT(siV); RdV = (fLSBOLD(PuV) ? siV : RsV); })
284
285
286
287Q6INSN(C2_vmux,"Rdd32=vmux(Pu4,Rss32,Rtt32)",ATTRIBS(),
288"Vector MUX",
289{
290    fHIDE(int i;)
291    for (i = 0; i < 8; i++) {
292        fSETBYTE(i,RddV,(fGETBIT(i,PuV)?(fGETBYTE(i,RssV)):(fGETBYTE(i,RttV))));
293    }
294})
295
296Q6INSN(C2_mask,"Rdd32=mask(Pt4)",ATTRIBS(),
297"Vector Mask Generation",
298{
299    fHIDE(int i;)
300    for (i = 0; i < 8; i++) {
301        fSETBYTE(i,RddV,(fGETBIT(i,PtV)?(0xff):(0x00)));
302    }
303})
304
305/* VCMP */
306
307Q6INSN(A2_vcmpbeq,"Pd4=vcmpb.eq(Rss32,Rtt32)",ATTRIBS(),
308"Compare elements of two vectors ",
309{
310    fHIDE(int i;)
311    for (i = 0; i < 8; i++) {
312        fSETBIT(i,PdV,(fGETBYTE(i,RssV) == fGETBYTE(i,RttV)));
313    }
314})
315
316Q6INSN(A4_vcmpbeqi,"Pd4=vcmpb.eq(Rss32,#u8)",ATTRIBS(),
317"Compare elements of two vectors ",
318{
319    fHIDE(int i;)
320    for (i = 0; i < 8; i++) {
321        fSETBIT(i,PdV,(fGETUBYTE(i,RssV) == uiV));
322    }
323})
324
325Q6INSN(A4_vcmpbeq_any,"Pd4=any8(vcmpb.eq(Rss32,Rtt32))",ATTRIBS(),
326"Compare elements of two vectors ",
327{
328    fHIDE(int i;)
329    PdV = 0;
330    for (i = 0; i < 8; i++) {
331        if (fGETBYTE(i,RssV) == fGETBYTE(i,RttV)) PdV = 0xff;
332    }
333})
334
335Q6INSN(A6_vcmpbeq_notany,"Pd4=!any8(vcmpb.eq(Rss32,Rtt32))",ATTRIBS(),
336"Compare elements of two vectors ",
337{
338    fHIDE(int i;)
339    PdV = 0;
340    for (i = 0; i < 8; i++) {
341        if (fGETBYTE(i,RssV) == fGETBYTE(i,RttV)) PdV = 0xff;
342    }
343    PdV = ~PdV;
344})
345
346Q6INSN(A2_vcmpbgtu,"Pd4=vcmpb.gtu(Rss32,Rtt32)",ATTRIBS(),
347"Compare elements of two vectors ",
348{
349    fHIDE(int i;)
350    for (i = 0; i < 8; i++) {
351        fSETBIT(i,PdV,(fGETUBYTE(i,RssV) > fGETUBYTE(i,RttV)));
352    }
353})
354
355Q6INSN(A4_vcmpbgtui,"Pd4=vcmpb.gtu(Rss32,#u7)",ATTRIBS(),
356"Compare elements of two vectors ",
357{
358    fHIDE(int i;)
359    for (i = 0; i < 8; i++) {
360        fSETBIT(i,PdV,(fGETUBYTE(i,RssV) > uiV));
361    }
362})
363
364Q6INSN(A4_vcmpbgt,"Pd4=vcmpb.gt(Rss32,Rtt32)",ATTRIBS(),
365"Compare elements of two vectors ",
366{
367    fHIDE(int i;)
368    for (i = 0; i < 8; i++) {
369        fSETBIT(i,PdV,(fGETBYTE(i,RssV) > fGETBYTE(i,RttV)));
370    }
371})
372
373Q6INSN(A4_vcmpbgti,"Pd4=vcmpb.gt(Rss32,#s8)",ATTRIBS(),
374"Compare elements of two vectors ",
375{
376    fHIDE(int i;)
377    for (i = 0; i < 8; i++) {
378        fSETBIT(i,PdV,(fGETBYTE(i,RssV) > siV));
379    }
380})
381
382
383
384Q6INSN(A4_cmpbeq,"Pd4=cmpb.eq(Rs32,Rt32)",ATTRIBS(),
385"Compare bytes ",
386{
387    PdV=f8BITSOF(fGETBYTE(0,RsV) == fGETBYTE(0,RtV));
388})
389
390Q6INSN(A4_cmpbeqi,"Pd4=cmpb.eq(Rs32,#u8)",ATTRIBS(),
391"Compare bytes ",
392{
393    PdV=f8BITSOF(fGETUBYTE(0,RsV) == uiV);
394})
395
396Q6INSN(A4_cmpbgtu,"Pd4=cmpb.gtu(Rs32,Rt32)",ATTRIBS(),
397"Compare bytes ",
398{
399    PdV=f8BITSOF(fGETUBYTE(0,RsV) > fGETUBYTE(0,RtV));
400})
401
402Q6INSN(A4_cmpbgtui,"Pd4=cmpb.gtu(Rs32,#u7)",ATTRIBS(),
403"Compare bytes ",
404{
405    fIMMEXT(uiV);
406    PdV=f8BITSOF(fGETUBYTE(0,RsV) > fCAST4u(uiV));
407})
408
409Q6INSN(A4_cmpbgt,"Pd4=cmpb.gt(Rs32,Rt32)",ATTRIBS(),
410"Compare bytes ",
411{
412    PdV=f8BITSOF(fGETBYTE(0,RsV) > fGETBYTE(0,RtV));
413})
414
415Q6INSN(A4_cmpbgti,"Pd4=cmpb.gt(Rs32,#s8)",ATTRIBS(),
416"Compare bytes ",
417{
418    PdV=f8BITSOF(fGETBYTE(0,RsV) > siV);
419})
420
421Q6INSN(A2_vcmpheq,"Pd4=vcmph.eq(Rss32,Rtt32)",ATTRIBS(),
422"Compare elements of two vectors ",
423{
424    fHIDE(int i;)
425    for (i = 0; i < 4; i++) {
426        fSETBIT(i*2,PdV,  (fGETHALF(i,RssV) == fGETHALF(i,RttV)));
427        fSETBIT(i*2+1,PdV,(fGETHALF(i,RssV) == fGETHALF(i,RttV)));
428    }
429})
430
431Q6INSN(A2_vcmphgt,"Pd4=vcmph.gt(Rss32,Rtt32)",ATTRIBS(),
432"Compare elements of two vectors ",
433{
434    fHIDE(int i;)
435    for (i = 0; i < 4; i++) {
436        fSETBIT(i*2,  PdV,  (fGETHALF(i,RssV) > fGETHALF(i,RttV)));
437        fSETBIT(i*2+1,PdV,  (fGETHALF(i,RssV) > fGETHALF(i,RttV)));
438    }
439})
440
441Q6INSN(A2_vcmphgtu,"Pd4=vcmph.gtu(Rss32,Rtt32)",ATTRIBS(),
442"Compare elements of two vectors ",
443{
444    fHIDE(int i;)
445    for (i = 0; i < 4; i++) {
446        fSETBIT(i*2,  PdV,  (fGETUHALF(i,RssV) > fGETUHALF(i,RttV)));
447        fSETBIT(i*2+1,PdV,  (fGETUHALF(i,RssV) > fGETUHALF(i,RttV)));
448    }
449})
450
451Q6INSN(A4_vcmpheqi,"Pd4=vcmph.eq(Rss32,#s8)",ATTRIBS(),
452"Compare elements of two vectors ",
453{
454    fHIDE(int i;)
455    for (i = 0; i < 4; i++) {
456        fSETBIT(i*2,PdV,  (fGETHALF(i,RssV) == siV));
457        fSETBIT(i*2+1,PdV,(fGETHALF(i,RssV) == siV));
458    }
459})
460
461Q6INSN(A4_vcmphgti,"Pd4=vcmph.gt(Rss32,#s8)",ATTRIBS(),
462"Compare elements of two vectors ",
463{
464    fHIDE(int i;)
465    for (i = 0; i < 4; i++) {
466        fSETBIT(i*2,  PdV,  (fGETHALF(i,RssV) > siV));
467        fSETBIT(i*2+1,PdV,  (fGETHALF(i,RssV) > siV));
468    }
469})
470
471
472Q6INSN(A4_vcmphgtui,"Pd4=vcmph.gtu(Rss32,#u7)",ATTRIBS(),
473"Compare elements of two vectors ",
474{
475    fHIDE(int i;)
476    for (i = 0; i < 4; i++) {
477        fSETBIT(i*2,  PdV,  (fGETUHALF(i,RssV) > uiV));
478        fSETBIT(i*2+1,PdV,  (fGETUHALF(i,RssV) > uiV));
479    }
480})
481
482Q6INSN(A4_cmpheq,"Pd4=cmph.eq(Rs32,Rt32)",ATTRIBS(),
483"Compare halfwords ",
484{
485    PdV=f8BITSOF(fGETHALF(0,RsV) == fGETHALF(0,RtV));
486})
487
488Q6INSN(A4_cmphgt,"Pd4=cmph.gt(Rs32,Rt32)",ATTRIBS(),
489"Compare halfwords ",
490{
491    PdV=f8BITSOF(fGETHALF(0,RsV) > fGETHALF(0,RtV));
492})
493
494Q6INSN(A4_cmphgtu,"Pd4=cmph.gtu(Rs32,Rt32)",ATTRIBS(),
495"Compare halfwords ",
496{
497    PdV=f8BITSOF(fGETUHALF(0,RsV) > fGETUHALF(0,RtV));
498})
499
500Q6INSN(A4_cmpheqi,"Pd4=cmph.eq(Rs32,#s8)",ATTRIBS(),
501"Compare halfwords ",
502{
503    fIMMEXT(siV);
504    PdV=f8BITSOF(fGETHALF(0,RsV) == siV);
505})
506
507Q6INSN(A4_cmphgti,"Pd4=cmph.gt(Rs32,#s8)",ATTRIBS(),
508"Compare halfwords ",
509{
510    fIMMEXT(siV);
511    PdV=f8BITSOF(fGETHALF(0,RsV) > siV);
512})
513
514Q6INSN(A4_cmphgtui,"Pd4=cmph.gtu(Rs32,#u7)",ATTRIBS(),
515"Compare halfwords ",
516{
517    fIMMEXT(uiV);
518    PdV=f8BITSOF(fGETUHALF(0,RsV) > fCAST4u(uiV));
519})
520
521Q6INSN(A2_vcmpweq,"Pd4=vcmpw.eq(Rss32,Rtt32)",ATTRIBS(),
522"Compare elements of two vectors ",
523{
524    fSETBITS(3,0,PdV,(fGETWORD(0,RssV)==fGETWORD(0,RttV)));
525    fSETBITS(7,4,PdV,(fGETWORD(1,RssV)==fGETWORD(1,RttV)));
526})
527
528Q6INSN(A2_vcmpwgt,"Pd4=vcmpw.gt(Rss32,Rtt32)",ATTRIBS(),
529"Compare elements of two vectors ",
530{
531    fSETBITS(3,0,PdV,(fGETWORD(0,RssV)>fGETWORD(0,RttV)));
532    fSETBITS(7,4,PdV,(fGETWORD(1,RssV)>fGETWORD(1,RttV)));
533})
534
535Q6INSN(A2_vcmpwgtu,"Pd4=vcmpw.gtu(Rss32,Rtt32)",ATTRIBS(),
536"Compare elements of two vectors ",
537{
538    fSETBITS(3,0,PdV,(fGETUWORD(0,RssV)>fGETUWORD(0,RttV)));
539    fSETBITS(7,4,PdV,(fGETUWORD(1,RssV)>fGETUWORD(1,RttV)));
540})
541
542Q6INSN(A4_vcmpweqi,"Pd4=vcmpw.eq(Rss32,#s8)",ATTRIBS(),
543"Compare elements of two vectors ",
544{
545    fSETBITS(3,0,PdV,(fGETWORD(0,RssV)==siV));
546    fSETBITS(7,4,PdV,(fGETWORD(1,RssV)==siV));
547})
548
549Q6INSN(A4_vcmpwgti,"Pd4=vcmpw.gt(Rss32,#s8)",ATTRIBS(),
550"Compare elements of two vectors ",
551{
552    fSETBITS(3,0,PdV,(fGETWORD(0,RssV)>siV));
553    fSETBITS(7,4,PdV,(fGETWORD(1,RssV)>siV));
554})
555
556Q6INSN(A4_vcmpwgtui,"Pd4=vcmpw.gtu(Rss32,#u7)",ATTRIBS(),
557"Compare elements of two vectors ",
558{
559    fSETBITS(3,0,PdV,(fGETUWORD(0,RssV)>fCAST4u(uiV)));
560    fSETBITS(7,4,PdV,(fGETUWORD(1,RssV)>fCAST4u(uiV)));
561})
562
563Q6INSN(A4_boundscheck_hi,"Pd4=boundscheck(Rss32,Rtt32):raw:hi",ATTRIBS(),
564"Detect if a register is within bounds",
565{
566    fHIDE(size4u_t src;)
567    src = fGETUWORD(1,RssV);
568    PdV = f8BITSOF((fCAST4u(src) >= fGETUWORD(0,RttV)) && (fCAST4u(src) < fGETUWORD(1,RttV)));
569})
570
571Q6INSN(A4_boundscheck_lo,"Pd4=boundscheck(Rss32,Rtt32):raw:lo",ATTRIBS(),
572"Detect if a register is within bounds",
573{
574    fHIDE(size4u_t src;)
575    src = fGETUWORD(0,RssV);
576    PdV = f8BITSOF((fCAST4u(src) >= fGETUWORD(0,RttV)) && (fCAST4u(src) < fGETUWORD(1,RttV)));
577})
578
579Q6INSN(A4_tlbmatch,"Pd4=tlbmatch(Rss32,Rt32)",ATTRIBS(),
580"Detect if a VA/ASID matches a TLB entry",
581{
582    fHIDE(size4u_t TLBHI; size4u_t TLBLO; size4u_t MASK; size4u_t SIZE;)
583    MASK = 0x07ffffff;
584    TLBLO = fGETUWORD(0,RssV);
585    TLBHI = fGETUWORD(1,RssV);
586    SIZE = fMIN(6,fCL1_4(~fBREV_4(TLBLO)));
587    MASK &= (0xffffffff << 2*SIZE);
588    PdV = f8BITSOF(fGETBIT(31,TLBHI) && ((TLBHI & MASK) == (RtV & MASK)));
589})
590
591Q6INSN(C2_tfrpr,"Rd32=Ps4",ATTRIBS(),
592"Transfer predicate to general register", { RdV = fZXTN(8,32,PsV); })
593
594Q6INSN(C2_tfrrp,"Pd4=Rs32",ATTRIBS(),
595"Transfer general register to Predicate", { PdV = fGETUBYTE(0,RsV); })
596
597Q6INSN(C4_fastcorner9,"Pd4=fastcorner9(Ps4,Pt4)",ATTRIBS(A_CRSLOT23),
598"Determine whether the predicate sources define a corner",
599{
600    fHIDE(size4u_t tmp = 0; size4u_t i;)
601    fSETHALF(0,tmp,(PsV<<8)|PtV);
602    fSETHALF(1,tmp,(PsV<<8)|PtV);
603    for (i = 1; i < 9; i++) {
604        tmp &= tmp >> 1;
605    }
606    PdV = f8BITSOF(tmp != 0);
607})
608
609Q6INSN(C4_fastcorner9_not,"Pd4=!fastcorner9(Ps4,Pt4)",ATTRIBS(A_CRSLOT23),
610"Determine whether the predicate sources define a corner",
611{
612    fHIDE(size4u_t tmp = 0; size4u_t i;)
613    fSETHALF(0,tmp,(PsV<<8)|PtV);
614    fSETHALF(1,tmp,(PsV<<8)|PtV);
615    for (i = 1; i < 9; i++) {
616        tmp &= tmp >> 1;
617    }
618    PdV = f8BITSOF(tmp == 0);
619})
620