xref: /openbmc/qemu/target/hexagon/imported/alu.idef (revision 7cf9345c)
1*7cf9345cSTaylor Simpson/*
2*7cf9345cSTaylor Simpson *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
3*7cf9345cSTaylor Simpson *
4*7cf9345cSTaylor Simpson *  This program is free software; you can redistribute it and/or modify
5*7cf9345cSTaylor Simpson *  it under the terms of the GNU General Public License as published by
6*7cf9345cSTaylor Simpson *  the Free Software Foundation; either version 2 of the License, or
7*7cf9345cSTaylor Simpson *  (at your option) any later version.
8*7cf9345cSTaylor Simpson *
9*7cf9345cSTaylor Simpson *  This program is distributed in the hope that it will be useful,
10*7cf9345cSTaylor Simpson *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11*7cf9345cSTaylor Simpson *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*7cf9345cSTaylor Simpson *  GNU General Public License for more details.
13*7cf9345cSTaylor Simpson *
14*7cf9345cSTaylor Simpson *  You should have received a copy of the GNU General Public License
15*7cf9345cSTaylor Simpson *  along with this program; if not, see <http://www.gnu.org/licenses/>.
16*7cf9345cSTaylor Simpson */
17*7cf9345cSTaylor Simpson
18*7cf9345cSTaylor Simpson/*
19*7cf9345cSTaylor Simpson * ALU Instructions
20*7cf9345cSTaylor Simpson */
21*7cf9345cSTaylor Simpson
22*7cf9345cSTaylor Simpson
23*7cf9345cSTaylor Simpson/**********************************************/
24*7cf9345cSTaylor Simpson/* Add/Sub instructions                       */
25*7cf9345cSTaylor Simpson/**********************************************/
26*7cf9345cSTaylor Simpson
27*7cf9345cSTaylor SimpsonQ6INSN(A2_add,"Rd32=add(Rs32,Rt32)",ATTRIBS(),
28*7cf9345cSTaylor Simpson"Add 32-bit registers",
29*7cf9345cSTaylor Simpson{ RdV=RsV+RtV;})
30*7cf9345cSTaylor Simpson
31*7cf9345cSTaylor SimpsonQ6INSN(A2_sub,"Rd32=sub(Rt32,Rs32)",ATTRIBS(),
32*7cf9345cSTaylor Simpson"Subtract 32-bit registers",
33*7cf9345cSTaylor Simpson{ RdV=RtV-RsV;})
34*7cf9345cSTaylor Simpson
35*7cf9345cSTaylor Simpson#define COND_ALU(TAG,OPER,DESCR,SEMANTICS)\
36*7cf9345cSTaylor SimpsonQ6INSN(TAG##t,"if (Pu4) "OPER,ATTRIBS(A_ARCHV2),DESCR,{if(fLSBOLD(PuV)){SEMANTICS;} else {CANCEL;}})\
37*7cf9345cSTaylor SimpsonQ6INSN(TAG##f,"if (!Pu4) "OPER,ATTRIBS(A_ARCHV2),DESCR,{if(fLSBOLDNOT(PuV)){SEMANTICS;} else {CANCEL;}})\
38*7cf9345cSTaylor SimpsonQ6INSN(TAG##tnew,"if (Pu4.new) " OPER,ATTRIBS(A_ARCHV2),DESCR,{if(fLSBNEW(PuN)){SEMANTICS;} else {CANCEL;}})\
39*7cf9345cSTaylor SimpsonQ6INSN(TAG##fnew,"if (!Pu4.new) "OPER,ATTRIBS(A_ARCHV2),DESCR,{if(fLSBNEWNOT(PuN)){SEMANTICS;} else {CANCEL;}})
40*7cf9345cSTaylor Simpson
41*7cf9345cSTaylor SimpsonCOND_ALU(A2_padd,"Rd32=add(Rs32,Rt32)","Conditionally Add 32-bit registers",RdV=RsV+RtV)
42*7cf9345cSTaylor SimpsonCOND_ALU(A2_psub,"Rd32=sub(Rt32,Rs32)","Conditionally Subtract 32-bit registers",RdV=RtV-RsV)
43*7cf9345cSTaylor SimpsonCOND_ALU(A2_paddi,"Rd32=add(Rs32,#s8)","Conditionally Add Register and immediate",fIMMEXT(siV); RdV=RsV+siV)
44*7cf9345cSTaylor SimpsonCOND_ALU(A2_pxor,"Rd32=xor(Rs32,Rt32)","Conditionally XOR registers",RdV=RsV^RtV)
45*7cf9345cSTaylor SimpsonCOND_ALU(A2_pand,"Rd32=and(Rs32,Rt32)","Conditionally AND registers",RdV=RsV&RtV)
46*7cf9345cSTaylor SimpsonCOND_ALU(A2_por,"Rd32=or(Rs32,Rt32)","Conditionally OR registers",RdV=RsV|RtV)
47*7cf9345cSTaylor Simpson
48*7cf9345cSTaylor SimpsonCOND_ALU(A4_psxtb,"Rd32=sxtb(Rs32)","Conditionally sign-extend byte", RdV=fSXTN(8,32,RsV))
49*7cf9345cSTaylor SimpsonCOND_ALU(A4_pzxtb,"Rd32=zxtb(Rs32)","Conditionally zero-extend byte", RdV=fZXTN(8,32,RsV))
50*7cf9345cSTaylor SimpsonCOND_ALU(A4_psxth,"Rd32=sxth(Rs32)","Conditionally sign-extend halfword", RdV=fSXTN(16,32,RsV))
51*7cf9345cSTaylor SimpsonCOND_ALU(A4_pzxth,"Rd32=zxth(Rs32)","Conditionally zero-extend halfword", RdV=fZXTN(16,32,RsV))
52*7cf9345cSTaylor SimpsonCOND_ALU(A4_paslh,"Rd32=aslh(Rs32)","Conditionally zero-extend halfword", RdV=RsV<<16)
53*7cf9345cSTaylor SimpsonCOND_ALU(A4_pasrh,"Rd32=asrh(Rs32)","Conditionally zero-extend halfword", RdV=RsV>>16)
54*7cf9345cSTaylor Simpson
55*7cf9345cSTaylor Simpson
56*7cf9345cSTaylor SimpsonQ6INSN(A2_addsat,"Rd32=add(Rs32,Rt32):sat",ATTRIBS(),
57*7cf9345cSTaylor Simpson"Add 32-bit registers with saturation",
58*7cf9345cSTaylor Simpson{ RdV=fSAT(fSE32_64(RsV)+fSE32_64(RtV)); })
59*7cf9345cSTaylor Simpson
60*7cf9345cSTaylor SimpsonQ6INSN(A2_subsat,"Rd32=sub(Rt32,Rs32):sat",ATTRIBS(),
61*7cf9345cSTaylor Simpson"Subtract 32-bit registers with saturation",
62*7cf9345cSTaylor Simpson{ RdV=fSAT(fSE32_64(RtV) - fSE32_64(RsV)); })
63*7cf9345cSTaylor Simpson
64*7cf9345cSTaylor Simpson
65*7cf9345cSTaylor SimpsonQ6INSN(A2_addi,"Rd32=add(Rs32,#s16)",ATTRIBS(),
66*7cf9345cSTaylor Simpson"Add a signed immediate to a register",
67*7cf9345cSTaylor Simpson{ fIMMEXT(siV); RdV=RsV+siV;})
68*7cf9345cSTaylor Simpson
69*7cf9345cSTaylor Simpson
70*7cf9345cSTaylor SimpsonQ6INSN(C4_addipc,"Rd32=add(pc,#u6)",ATTRIBS(),
71*7cf9345cSTaylor Simpson"Add immediate to PC",
72*7cf9345cSTaylor Simpson{ RdV=fREAD_PC()+fIMMEXT(uiV);})
73*7cf9345cSTaylor Simpson
74*7cf9345cSTaylor Simpson
75*7cf9345cSTaylor Simpson
76*7cf9345cSTaylor Simpson/**********************************************/
77*7cf9345cSTaylor Simpson/* Single-precision HL forms                  */
78*7cf9345cSTaylor Simpson/* These insns and the SP mpy are the ones    */
79*7cf9345cSTaylor Simpson/* that can do .HL stuff                      */
80*7cf9345cSTaylor Simpson/**********************************************/
81*7cf9345cSTaylor Simpson#define STD_HL_INSN(TAG,OPER,AOPER,ATR,SEM)\
82*7cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_ll, OPER"(Rt.L32,Rs.L32)"AOPER,    ATR,"",{SEM(fGETHALF(0,RtV),fGETHALF(0,RsV));})\
83*7cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_lh, OPER"(Rt.L32,Rs.H32)"AOPER,    ATR,"",{SEM(fGETHALF(0,RtV),fGETHALF(1,RsV));})\
84*7cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_hl, OPER"(Rt.H32,Rs.L32)"AOPER,    ATR,"",{SEM(fGETHALF(1,RtV),fGETHALF(0,RsV));})\
85*7cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_hh, OPER"(Rt.H32,Rs.H32)"AOPER,    ATR,"",{SEM(fGETHALF(1,RtV),fGETHALF(1,RsV));})
86*7cf9345cSTaylor Simpson
87*7cf9345cSTaylor Simpson#define SUBSTD_HL_INSN(TAG,OPER,AOPER,ATR,SEM)\
88*7cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_ll, OPER"(Rt.L32,Rs.L32)"AOPER,    ATR,"",{SEM(fGETHALF(0,RtV),fGETHALF(0,RsV));})\
89*7cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_hl, OPER"(Rt.L32,Rs.H32)"AOPER,    ATR,"",{SEM(fGETHALF(0,RtV),fGETHALF(1,RsV));})
90*7cf9345cSTaylor Simpson
91*7cf9345cSTaylor Simpson
92*7cf9345cSTaylor Simpson#undef HLSEM
93*7cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=fSXTN(16,32,(A+B))
94*7cf9345cSTaylor SimpsonSUBSTD_HL_INSN(addh_l16,"Rd32=add","",ATTRIBS(),HLSEM)
95*7cf9345cSTaylor Simpson
96*7cf9345cSTaylor Simpson#undef HLSEM
97*7cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=fSATH(A+B)
98*7cf9345cSTaylor SimpsonSUBSTD_HL_INSN(addh_l16_sat,"Rd32=add",":sat",ATTRIBS(),HLSEM)
99*7cf9345cSTaylor Simpson
100*7cf9345cSTaylor Simpson#undef HLSEM
101*7cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=fSXTN(16,32,(A-B))
102*7cf9345cSTaylor SimpsonSUBSTD_HL_INSN(subh_l16,"Rd32=sub","",ATTRIBS(),HLSEM)
103*7cf9345cSTaylor Simpson
104*7cf9345cSTaylor Simpson#undef HLSEM
105*7cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=fSATH(A-B)
106*7cf9345cSTaylor SimpsonSUBSTD_HL_INSN(subh_l16_sat,"Rd32=sub",":sat",ATTRIBS(),HLSEM)
107*7cf9345cSTaylor Simpson
108*7cf9345cSTaylor Simpson#undef HLSEM
109*7cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=(A+B)<<16
110*7cf9345cSTaylor SimpsonSTD_HL_INSN(addh_h16,"Rd32=add",":<<16",ATTRIBS(),HLSEM)
111*7cf9345cSTaylor Simpson
112*7cf9345cSTaylor Simpson#undef HLSEM
113*7cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=(fSATH(A+B))<<16
114*7cf9345cSTaylor SimpsonSTD_HL_INSN(addh_h16_sat,"Rd32=add",":sat:<<16",ATTRIBS(),HLSEM)
115*7cf9345cSTaylor Simpson
116*7cf9345cSTaylor Simpson#undef HLSEM
117*7cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=(A-B)<<16
118*7cf9345cSTaylor SimpsonSTD_HL_INSN(subh_h16,"Rd32=sub",":<<16",ATTRIBS(),HLSEM)
119*7cf9345cSTaylor Simpson
120*7cf9345cSTaylor Simpson#undef HLSEM
121*7cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=(fSATH(A-B))<<16
122*7cf9345cSTaylor SimpsonSTD_HL_INSN(subh_h16_sat,"Rd32=sub",":sat:<<16",ATTRIBS(),HLSEM)
123*7cf9345cSTaylor Simpson
124*7cf9345cSTaylor Simpson
125*7cf9345cSTaylor Simpson
126*7cf9345cSTaylor Simpson
127*7cf9345cSTaylor SimpsonQ6INSN(A2_aslh,"Rd32=aslh(Rs32)",ATTRIBS(),
128*7cf9345cSTaylor Simpson"Arithmetic Shift Left by Halfword",{ RdV=RsV<<16; })
129*7cf9345cSTaylor Simpson
130*7cf9345cSTaylor SimpsonQ6INSN(A2_asrh,"Rd32=asrh(Rs32)",ATTRIBS(),
131*7cf9345cSTaylor Simpson"Arithmetic Shift Right by Halfword",{ RdV=RsV>>16; })
132*7cf9345cSTaylor Simpson
133*7cf9345cSTaylor Simpson
134*7cf9345cSTaylor Simpson/* 64-bit versions */
135*7cf9345cSTaylor Simpson
136*7cf9345cSTaylor SimpsonQ6INSN(A2_addp,"Rdd32=add(Rss32,Rtt32)",ATTRIBS(),
137*7cf9345cSTaylor Simpson"Add",
138*7cf9345cSTaylor Simpson{ RddV=RssV+RttV;})
139*7cf9345cSTaylor Simpson
140*7cf9345cSTaylor SimpsonQ6INSN(A2_addpsat,"Rdd32=add(Rss32,Rtt32):sat",ATTRIBS(A_ARCHV3),
141*7cf9345cSTaylor Simpson"Add",
142*7cf9345cSTaylor Simpson{ fADDSAT64(RddV,RssV,RttV);})
143*7cf9345cSTaylor Simpson
144*7cf9345cSTaylor SimpsonQ6INSN(A2_addspl,"Rdd32=add(Rss32,Rtt32):raw:lo",ATTRIBS(A_ARCHV3),
145*7cf9345cSTaylor Simpson"Add",
146*7cf9345cSTaylor Simpson{ RddV=RttV+fSXTN(32,64,fGETWORD(0,RssV));})
147*7cf9345cSTaylor Simpson
148*7cf9345cSTaylor SimpsonQ6INSN(A2_addsph,"Rdd32=add(Rss32,Rtt32):raw:hi",ATTRIBS(A_ARCHV3),
149*7cf9345cSTaylor Simpson"Add",
150*7cf9345cSTaylor Simpson{ RddV=RttV+fSXTN(32,64,fGETWORD(1,RssV));})
151*7cf9345cSTaylor Simpson
152*7cf9345cSTaylor SimpsonQ6INSN(A2_subp,"Rdd32=sub(Rtt32,Rss32)",ATTRIBS(),
153*7cf9345cSTaylor Simpson"Sub",
154*7cf9345cSTaylor Simpson{ RddV=RttV-RssV;})
155*7cf9345cSTaylor Simpson
156*7cf9345cSTaylor Simpson/* NEG and ABS */
157*7cf9345cSTaylor Simpson
158*7cf9345cSTaylor SimpsonQ6INSN(A2_negsat,"Rd32=neg(Rs32):sat",ATTRIBS(),
159*7cf9345cSTaylor Simpson"Arithmetic negate register", { RdV = fSAT(-fCAST8s(RsV)); })
160*7cf9345cSTaylor Simpson
161*7cf9345cSTaylor SimpsonQ6INSN(A2_abs,"Rd32=abs(Rs32)",ATTRIBS(),
162*7cf9345cSTaylor Simpson"Absolute Value register", { RdV = fABS(RsV); })
163*7cf9345cSTaylor Simpson
164*7cf9345cSTaylor SimpsonQ6INSN(A2_abssat,"Rd32=abs(Rs32):sat",ATTRIBS(),
165*7cf9345cSTaylor Simpson"Arithmetic negate register", { RdV = fSAT(fABS(fCAST4_8s(RsV))); })
166*7cf9345cSTaylor Simpson
167*7cf9345cSTaylor SimpsonQ6INSN(A2_vconj,"Rdd32=vconj(Rss32):sat",ATTRIBS(A_ARCHV2),
168*7cf9345cSTaylor Simpson"Vector Complex conjugate of Rss",
169*7cf9345cSTaylor Simpson{  fSETHALF(1,RddV,fSATN(16,-fGETHALF(1,RssV)));
170*7cf9345cSTaylor Simpson   fSETHALF(0,RddV,fGETHALF(0,RssV));
171*7cf9345cSTaylor Simpson   fSETHALF(3,RddV,fSATN(16,-fGETHALF(3,RssV)));
172*7cf9345cSTaylor Simpson   fSETHALF(2,RddV,fGETHALF(2,RssV));
173*7cf9345cSTaylor Simpson})
174*7cf9345cSTaylor Simpson
175*7cf9345cSTaylor Simpson
176*7cf9345cSTaylor Simpson/* 64-bit versions */
177*7cf9345cSTaylor Simpson
178*7cf9345cSTaylor SimpsonQ6INSN(A2_negp,"Rdd32=neg(Rss32)",ATTRIBS(),
179*7cf9345cSTaylor Simpson"Arithmetic negate register", { RddV = -RssV; })
180*7cf9345cSTaylor Simpson
181*7cf9345cSTaylor SimpsonQ6INSN(A2_absp,"Rdd32=abs(Rss32)",ATTRIBS(),
182*7cf9345cSTaylor Simpson"Absolute Value register", { RddV = fABS(RssV); })
183*7cf9345cSTaylor Simpson
184*7cf9345cSTaylor Simpson
185*7cf9345cSTaylor Simpson/* MIN and MAX  R */
186*7cf9345cSTaylor Simpson
187*7cf9345cSTaylor SimpsonQ6INSN(A2_max,"Rd32=max(Rs32,Rt32)",ATTRIBS(),
188*7cf9345cSTaylor Simpson"Maximum of two registers",
189*7cf9345cSTaylor Simpson{ RdV = fMAX(RsV,RtV); })
190*7cf9345cSTaylor Simpson
191*7cf9345cSTaylor SimpsonQ6INSN(A2_maxu,"Rd32=maxu(Rs32,Rt32)",ATTRIBS(),
192*7cf9345cSTaylor Simpson"Maximum of two registers (unsigned)",
193*7cf9345cSTaylor Simpson{ RdV = fMAX(fCAST4u(RsV),fCAST4u(RtV)); })
194*7cf9345cSTaylor Simpson
195*7cf9345cSTaylor SimpsonQ6INSN(A2_min,"Rd32=min(Rt32,Rs32)",ATTRIBS(),
196*7cf9345cSTaylor Simpson"Minimum of two registers",
197*7cf9345cSTaylor Simpson{ RdV = fMIN(RtV,RsV); })
198*7cf9345cSTaylor Simpson
199*7cf9345cSTaylor SimpsonQ6INSN(A2_minu,"Rd32=minu(Rt32,Rs32)",ATTRIBS(),
200*7cf9345cSTaylor Simpson"Minimum of two registers (unsigned)",
201*7cf9345cSTaylor Simpson{ RdV = fMIN(fCAST4u(RtV),fCAST4u(RsV)); })
202*7cf9345cSTaylor Simpson
203*7cf9345cSTaylor Simpson/* MIN and MAX Pairs */
204*7cf9345cSTaylor Simpson#if 1
205*7cf9345cSTaylor SimpsonQ6INSN(A2_maxp,"Rdd32=max(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
206*7cf9345cSTaylor Simpson"Maximum of two register pairs",
207*7cf9345cSTaylor Simpson{ RddV = fMAX(RssV,RttV); })
208*7cf9345cSTaylor Simpson
209*7cf9345cSTaylor SimpsonQ6INSN(A2_maxup,"Rdd32=maxu(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
210*7cf9345cSTaylor Simpson"Maximum of two register pairs (unsigned)",
211*7cf9345cSTaylor Simpson{ RddV = fMAX(fCAST8u(RssV),fCAST8u(RttV)); })
212*7cf9345cSTaylor Simpson
213*7cf9345cSTaylor SimpsonQ6INSN(A2_minp,"Rdd32=min(Rtt32,Rss32)",ATTRIBS(A_ARCHV3),
214*7cf9345cSTaylor Simpson"Minimum of two register pairs",
215*7cf9345cSTaylor Simpson{ RddV = fMIN(RttV,RssV); })
216*7cf9345cSTaylor Simpson
217*7cf9345cSTaylor SimpsonQ6INSN(A2_minup,"Rdd32=minu(Rtt32,Rss32)",ATTRIBS(A_ARCHV3),
218*7cf9345cSTaylor Simpson"Minimum of two register pairs (unsigned)",
219*7cf9345cSTaylor Simpson{ RddV = fMIN(fCAST8u(RttV),fCAST8u(RssV)); })
220*7cf9345cSTaylor Simpson#endif
221*7cf9345cSTaylor Simpson
222*7cf9345cSTaylor Simpson/**********************************************/
223*7cf9345cSTaylor Simpson/* Register and Immediate Transfers           */
224*7cf9345cSTaylor Simpson/**********************************************/
225*7cf9345cSTaylor Simpson
226*7cf9345cSTaylor SimpsonQ6INSN(A2_nop,"nop",ATTRIBS(A_IT_NOP),
227*7cf9345cSTaylor Simpson"Nop (32-bit encoding)",
228*7cf9345cSTaylor Simpson fHIDE( { }  ))
229*7cf9345cSTaylor Simpson
230*7cf9345cSTaylor Simpson
231*7cf9345cSTaylor SimpsonQ6INSN(A4_ext,"immext(#u26:6)",ATTRIBS(A_IT_EXTENDER),
232*7cf9345cSTaylor Simpson"This instruction carries the 26 most-significant immediate bits for the next instruction",
233*7cf9345cSTaylor Simpson{ fHIDE(); })
234*7cf9345cSTaylor Simpson
235*7cf9345cSTaylor Simpson
236*7cf9345cSTaylor SimpsonQ6INSN(A2_tfr,"Rd32=Rs32",ATTRIBS(),
237*7cf9345cSTaylor Simpson"tfr register",{ RdV=RsV;})
238*7cf9345cSTaylor Simpson
239*7cf9345cSTaylor SimpsonQ6INSN(A2_tfrsi,"Rd32=#s16",ATTRIBS(),
240*7cf9345cSTaylor Simpson"transfer signed immediate to register",{ fIMMEXT(siV); RdV=siV;})
241*7cf9345cSTaylor Simpson
242*7cf9345cSTaylor SimpsonQ6INSN(A2_sxtb,"Rd32=sxtb(Rs32)",ATTRIBS(),
243*7cf9345cSTaylor Simpson"Sign extend byte", {RdV = fSXTN(8,32,RsV);})
244*7cf9345cSTaylor Simpson
245*7cf9345cSTaylor SimpsonQ6INSN(A2_zxth,"Rd32=zxth(Rs32)",ATTRIBS(),
246*7cf9345cSTaylor Simpson"Zero extend half", {RdV = fZXTN(16,32,RsV);})
247*7cf9345cSTaylor Simpson
248*7cf9345cSTaylor SimpsonQ6INSN(A2_sxth,"Rd32=sxth(Rs32)",ATTRIBS(),
249*7cf9345cSTaylor Simpson"Sign extend half", {RdV = fSXTN(16,32,RsV);})
250*7cf9345cSTaylor Simpson
251*7cf9345cSTaylor SimpsonQ6INSN(A2_combinew,"Rdd32=combine(Rs32,Rt32)",ATTRIBS(),
252*7cf9345cSTaylor Simpson"Combine two words into a register pair",
253*7cf9345cSTaylor Simpson{ fSETWORD(0,RddV,RtV);
254*7cf9345cSTaylor Simpson  fSETWORD(1,RddV,RsV);
255*7cf9345cSTaylor Simpson})
256*7cf9345cSTaylor Simpson
257*7cf9345cSTaylor SimpsonQ6INSN(A4_combineri,"Rdd32=combine(Rs32,#s8)",ATTRIBS(),
258*7cf9345cSTaylor Simpson"Combine a word and an immediate into a register pair",
259*7cf9345cSTaylor Simpson{ fIMMEXT(siV); fSETWORD(0,RddV,siV);
260*7cf9345cSTaylor Simpson  fSETWORD(1,RddV,RsV);
261*7cf9345cSTaylor Simpson})
262*7cf9345cSTaylor Simpson
263*7cf9345cSTaylor SimpsonQ6INSN(A4_combineir,"Rdd32=combine(#s8,Rs32)",ATTRIBS(),
264*7cf9345cSTaylor Simpson"Combine a word and an immediate into a register pair",
265*7cf9345cSTaylor Simpson{ fIMMEXT(siV); fSETWORD(0,RddV,RsV);
266*7cf9345cSTaylor Simpson  fSETWORD(1,RddV,siV);
267*7cf9345cSTaylor Simpson})
268*7cf9345cSTaylor Simpson
269*7cf9345cSTaylor Simpson
270*7cf9345cSTaylor Simpson
271*7cf9345cSTaylor SimpsonQ6INSN(A2_combineii,"Rdd32=combine(#s8,#S8)",ATTRIBS(A_ARCHV2),
272*7cf9345cSTaylor Simpson"Set two small immediates",
273*7cf9345cSTaylor Simpson{ fIMMEXT(siV); fSETWORD(0,RddV,SiV); fSETWORD(1,RddV,siV); })
274*7cf9345cSTaylor Simpson
275*7cf9345cSTaylor SimpsonQ6INSN(A4_combineii,"Rdd32=combine(#s8,#U6)",ATTRIBS(),"Set two small immediates",
276*7cf9345cSTaylor Simpson{ fIMMEXT(UiV); fSETWORD(0,RddV,UiV); fSETWORD(1,RddV,siV); })
277*7cf9345cSTaylor Simpson
278*7cf9345cSTaylor Simpson
279*7cf9345cSTaylor SimpsonQ6INSN(A2_combine_hh,"Rd32=combine(Rt.H32,Rs.H32)",ATTRIBS(),
280*7cf9345cSTaylor Simpson"Combine two halfs into a register", {RdV = (fGETUHALF(1,RtV)<<16) | fGETUHALF(1,RsV);})
281*7cf9345cSTaylor Simpson
282*7cf9345cSTaylor SimpsonQ6INSN(A2_combine_hl,"Rd32=combine(Rt.H32,Rs.L32)",ATTRIBS(),
283*7cf9345cSTaylor Simpson"Combine two halfs into a register", {RdV = (fGETUHALF(1,RtV)<<16) | fGETUHALF(0,RsV);})
284*7cf9345cSTaylor Simpson
285*7cf9345cSTaylor SimpsonQ6INSN(A2_combine_lh,"Rd32=combine(Rt.L32,Rs.H32)",ATTRIBS(),
286*7cf9345cSTaylor Simpson"Combine two halfs into a register", {RdV = (fGETUHALF(0,RtV)<<16) | fGETUHALF(1,RsV);})
287*7cf9345cSTaylor Simpson
288*7cf9345cSTaylor SimpsonQ6INSN(A2_combine_ll,"Rd32=combine(Rt.L32,Rs.L32)",ATTRIBS(),
289*7cf9345cSTaylor Simpson"Combine two halfs into a register", {RdV = (fGETUHALF(0,RtV)<<16) | fGETUHALF(0,RsV);})
290*7cf9345cSTaylor Simpson
291*7cf9345cSTaylor SimpsonQ6INSN(A2_tfril,"Rx.L32=#u16",ATTRIBS(),
292*7cf9345cSTaylor Simpson"Set low 16-bits, leave upper 16 unchanged",{ fSETHALF(0,RxV,uiV);})
293*7cf9345cSTaylor Simpson
294*7cf9345cSTaylor SimpsonQ6INSN(A2_tfrih,"Rx.H32=#u16",ATTRIBS(),
295*7cf9345cSTaylor Simpson"Set high 16-bits, leave low 16 unchanged",{ fSETHALF(1,RxV,uiV);})
296*7cf9345cSTaylor Simpson
297*7cf9345cSTaylor SimpsonQ6INSN(A2_tfrcrr,"Rd32=Cs32",ATTRIBS(),
298*7cf9345cSTaylor Simpson"transfer control register to general register",{ RdV=CsV;})
299*7cf9345cSTaylor Simpson
300*7cf9345cSTaylor SimpsonQ6INSN(A2_tfrrcr,"Cd32=Rs32",ATTRIBS(),
301*7cf9345cSTaylor Simpson"transfer general register to control register",{ CdV=RsV;})
302*7cf9345cSTaylor Simpson
303*7cf9345cSTaylor SimpsonQ6INSN(A4_tfrcpp,"Rdd32=Css32",ATTRIBS(),
304*7cf9345cSTaylor Simpson"transfer control register to general register",{ RddV=CssV;})
305*7cf9345cSTaylor Simpson
306*7cf9345cSTaylor SimpsonQ6INSN(A4_tfrpcp,"Cdd32=Rss32",ATTRIBS(),
307*7cf9345cSTaylor Simpson"transfer general register to control register",{ CddV=RssV;})
308*7cf9345cSTaylor Simpson
309*7cf9345cSTaylor Simpson
310*7cf9345cSTaylor Simpson/**********************************************/
311*7cf9345cSTaylor Simpson/* Logicals                                   */
312*7cf9345cSTaylor Simpson/**********************************************/
313*7cf9345cSTaylor Simpson
314*7cf9345cSTaylor SimpsonQ6INSN(A2_and,"Rd32=and(Rs32,Rt32)",ATTRIBS(),
315*7cf9345cSTaylor Simpson"logical AND",{ RdV=RsV&RtV;})
316*7cf9345cSTaylor Simpson
317*7cf9345cSTaylor SimpsonQ6INSN(A2_or,"Rd32=or(Rs32,Rt32)",ATTRIBS(),
318*7cf9345cSTaylor Simpson"logical OR",{ RdV=RsV|RtV;})
319*7cf9345cSTaylor Simpson
320*7cf9345cSTaylor SimpsonQ6INSN(A2_xor,"Rd32=xor(Rs32,Rt32)",ATTRIBS(),
321*7cf9345cSTaylor Simpson"logical XOR",{ RdV=RsV^RtV;})
322*7cf9345cSTaylor Simpson
323*7cf9345cSTaylor SimpsonQ6INSN(M2_xor_xacc,"Rx32^=xor(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
324*7cf9345cSTaylor Simpson"logical XOR with XOR accumulation",{ RxV^=RsV^RtV;})
325*7cf9345cSTaylor Simpson
326*7cf9345cSTaylor SimpsonQ6INSN(M4_xor_xacc,"Rxx32^=xor(Rss32,Rtt32)",,
327*7cf9345cSTaylor Simpson"logical XOR with XOR accumulation",{ RxxV^=RssV^RttV;})
328*7cf9345cSTaylor Simpson
329*7cf9345cSTaylor Simpson
330*7cf9345cSTaylor Simpson
331*7cf9345cSTaylor SimpsonQ6INSN(A4_andn,"Rd32=and(Rt32,~Rs32)",,
332*7cf9345cSTaylor Simpson"And-Not", { RdV = (RtV & ~RsV); })
333*7cf9345cSTaylor Simpson
334*7cf9345cSTaylor SimpsonQ6INSN(A4_orn,"Rd32=or(Rt32,~Rs32)",,
335*7cf9345cSTaylor Simpson"Or-Not", { RdV = (RtV | ~RsV); })
336*7cf9345cSTaylor Simpson
337*7cf9345cSTaylor Simpson
338*7cf9345cSTaylor SimpsonQ6INSN(A4_andnp,"Rdd32=and(Rtt32,~Rss32)",,
339*7cf9345cSTaylor Simpson"And-Not", { RddV = (RttV & ~RssV); })
340*7cf9345cSTaylor Simpson
341*7cf9345cSTaylor SimpsonQ6INSN(A4_ornp,"Rdd32=or(Rtt32,~Rss32)",,
342*7cf9345cSTaylor Simpson"Or-Not", { RddV = (RttV | ~RssV); })
343*7cf9345cSTaylor Simpson
344*7cf9345cSTaylor Simpson
345*7cf9345cSTaylor Simpson
346*7cf9345cSTaylor Simpson
347*7cf9345cSTaylor Simpson/********************/
348*7cf9345cSTaylor Simpson/* Compound add-add */
349*7cf9345cSTaylor Simpson/********************/
350*7cf9345cSTaylor Simpson
351*7cf9345cSTaylor SimpsonQ6INSN(S4_addaddi,"Rd32=add(Rs32,add(Ru32,#s6))",ATTRIBS(),
352*7cf9345cSTaylor Simpson        "3-input add",
353*7cf9345cSTaylor Simpson        { RdV = RsV + RuV + fIMMEXT(siV); })
354*7cf9345cSTaylor Simpson
355*7cf9345cSTaylor Simpson
356*7cf9345cSTaylor SimpsonQ6INSN(S4_subaddi,"Rd32=add(Rs32,sub(#s6,Ru32))",ATTRIBS(),
357*7cf9345cSTaylor Simpson        "3-input sub",
358*7cf9345cSTaylor Simpson        { RdV = RsV - RuV + fIMMEXT(siV); })
359*7cf9345cSTaylor Simpson
360*7cf9345cSTaylor Simpson
361*7cf9345cSTaylor Simpson
362*7cf9345cSTaylor Simpson/****************************/
363*7cf9345cSTaylor Simpson/* Compound logical-logical */
364*7cf9345cSTaylor Simpson/****************************/
365*7cf9345cSTaylor Simpson
366*7cf9345cSTaylor SimpsonQ6INSN(M4_and_and,"Rx32&=and(Rs32,Rt32)",ATTRIBS(),
367*7cf9345cSTaylor Simpson"Compound And-And", { RxV &= (RsV & RtV); })
368*7cf9345cSTaylor Simpson
369*7cf9345cSTaylor SimpsonQ6INSN(M4_and_andn,"Rx32&=and(Rs32,~Rt32)",ATTRIBS(),
370*7cf9345cSTaylor Simpson"Compound And-Andn", { RxV &= (RsV & ~RtV); })
371*7cf9345cSTaylor Simpson
372*7cf9345cSTaylor SimpsonQ6INSN(M4_and_or,"Rx32&=or(Rs32,Rt32)",ATTRIBS(),
373*7cf9345cSTaylor Simpson"Compound And-Or", { RxV &= (RsV | RtV); })
374*7cf9345cSTaylor Simpson
375*7cf9345cSTaylor SimpsonQ6INSN(M4_and_xor,"Rx32&=xor(Rs32,Rt32)",ATTRIBS(),
376*7cf9345cSTaylor Simpson"Compound And-xor", { RxV &= (RsV ^ RtV); })
377*7cf9345cSTaylor Simpson
378*7cf9345cSTaylor Simpson
379*7cf9345cSTaylor Simpson
380*7cf9345cSTaylor SimpsonQ6INSN(M4_or_and,"Rx32|=and(Rs32,Rt32)",ATTRIBS(),
381*7cf9345cSTaylor Simpson"Compound Or-And", { RxV |= (RsV & RtV); })
382*7cf9345cSTaylor Simpson
383*7cf9345cSTaylor SimpsonQ6INSN(M4_or_andn,"Rx32|=and(Rs32,~Rt32)",ATTRIBS(),
384*7cf9345cSTaylor Simpson"Compound Or-AndN", { RxV |= (RsV & ~RtV); })
385*7cf9345cSTaylor Simpson
386*7cf9345cSTaylor SimpsonQ6INSN(M4_or_or,"Rx32|=or(Rs32,Rt32)",ATTRIBS(),
387*7cf9345cSTaylor Simpson"Compound Or-Or", { RxV |= (RsV | RtV); })
388*7cf9345cSTaylor Simpson
389*7cf9345cSTaylor SimpsonQ6INSN(M4_or_xor,"Rx32|=xor(Rs32,Rt32)",ATTRIBS(),
390*7cf9345cSTaylor Simpson"Compound Or-xor", { RxV |= (RsV ^ RtV); })
391*7cf9345cSTaylor Simpson
392*7cf9345cSTaylor Simpson
393*7cf9345cSTaylor SimpsonQ6INSN(S4_or_andix,"Rx32=or(Ru32,and(Rx32,#s10))",ATTRIBS(),
394*7cf9345cSTaylor Simpson"Compound Or-And", { RxV = RuV | (RxV & fIMMEXT(siV)); })
395*7cf9345cSTaylor Simpson
396*7cf9345cSTaylor SimpsonQ6INSN(S4_or_andi,"Rx32|=and(Rs32,#s10)",ATTRIBS(),
397*7cf9345cSTaylor Simpson"Compound Or-And", { RxV = RxV | (RsV & fIMMEXT(siV)); })
398*7cf9345cSTaylor Simpson
399*7cf9345cSTaylor SimpsonQ6INSN(S4_or_ori,"Rx32|=or(Rs32,#s10)",ATTRIBS(),
400*7cf9345cSTaylor Simpson"Compound Or-And", { RxV = RxV | (RsV | fIMMEXT(siV)); })
401*7cf9345cSTaylor Simpson
402*7cf9345cSTaylor Simpson
403*7cf9345cSTaylor Simpson
404*7cf9345cSTaylor Simpson
405*7cf9345cSTaylor SimpsonQ6INSN(M4_xor_and,"Rx32^=and(Rs32,Rt32)",ATTRIBS(),
406*7cf9345cSTaylor Simpson"Compound Xor-And", { RxV ^= (RsV & RtV); })
407*7cf9345cSTaylor Simpson
408*7cf9345cSTaylor SimpsonQ6INSN(M4_xor_or,"Rx32^=or(Rs32,Rt32)",ATTRIBS(),
409*7cf9345cSTaylor Simpson"Compound Xor-Or", { RxV ^= (RsV | RtV); })
410*7cf9345cSTaylor Simpson
411*7cf9345cSTaylor SimpsonQ6INSN(M4_xor_andn,"Rx32^=and(Rs32,~Rt32)",ATTRIBS(),
412*7cf9345cSTaylor Simpson"Compound Xor-And", { RxV ^= (RsV & ~RtV); })
413*7cf9345cSTaylor Simpson
414*7cf9345cSTaylor Simpson
415*7cf9345cSTaylor Simpson
416*7cf9345cSTaylor Simpson
417*7cf9345cSTaylor Simpson
418*7cf9345cSTaylor Simpson
419*7cf9345cSTaylor SimpsonQ6INSN(A2_subri,"Rd32=sub(#s10,Rs32)",ATTRIBS(A_ARCHV2),
420*7cf9345cSTaylor Simpson"Subtract register from immediate",{ fIMMEXT(siV); RdV=siV-RsV;})
421*7cf9345cSTaylor Simpson
422*7cf9345cSTaylor SimpsonQ6INSN(A2_andir,"Rd32=and(Rs32,#s10)",ATTRIBS(A_ARCHV2),
423*7cf9345cSTaylor Simpson"logical AND with immediate",{ fIMMEXT(siV); RdV=RsV&siV;})
424*7cf9345cSTaylor Simpson
425*7cf9345cSTaylor SimpsonQ6INSN(A2_orir,"Rd32=or(Rs32,#s10)",ATTRIBS(A_ARCHV2),
426*7cf9345cSTaylor Simpson"logical OR with immediate",{ fIMMEXT(siV); RdV=RsV|siV;})
427*7cf9345cSTaylor Simpson
428*7cf9345cSTaylor Simpson
429*7cf9345cSTaylor Simpson
430*7cf9345cSTaylor Simpson
431*7cf9345cSTaylor SimpsonQ6INSN(A2_andp,"Rdd32=and(Rss32,Rtt32)",ATTRIBS(),
432*7cf9345cSTaylor Simpson"logical AND pair",{ RddV=RssV&RttV;})
433*7cf9345cSTaylor Simpson
434*7cf9345cSTaylor SimpsonQ6INSN(A2_orp,"Rdd32=or(Rss32,Rtt32)",ATTRIBS(),
435*7cf9345cSTaylor Simpson"logical OR pair",{ RddV=RssV|RttV;})
436*7cf9345cSTaylor Simpson
437*7cf9345cSTaylor SimpsonQ6INSN(A2_xorp,"Rdd32=xor(Rss32,Rtt32)",ATTRIBS(),
438*7cf9345cSTaylor Simpson"logical eXclusive OR pair",{ RddV=RssV^RttV;})
439*7cf9345cSTaylor Simpson
440*7cf9345cSTaylor SimpsonQ6INSN(A2_notp,"Rdd32=not(Rss32)",ATTRIBS(),
441*7cf9345cSTaylor Simpson"logical NOT pair",{ RddV=~RssV;})
442*7cf9345cSTaylor Simpson
443*7cf9345cSTaylor SimpsonQ6INSN(A2_sxtw,"Rdd32=sxtw(Rs32)",ATTRIBS(),
444*7cf9345cSTaylor Simpson"Sign extend 32-bit word to 64-bit pair",
445*7cf9345cSTaylor Simpson{ RddV = fCAST4_8s(RsV); })
446*7cf9345cSTaylor Simpson
447*7cf9345cSTaylor SimpsonQ6INSN(A2_sat,"Rd32=sat(Rss32)",ATTRIBS(),
448*7cf9345cSTaylor Simpson"Saturate to 32-bit Signed",
449*7cf9345cSTaylor Simpson{ RdV = fSAT(RssV); })
450*7cf9345cSTaylor Simpson
451*7cf9345cSTaylor SimpsonQ6INSN(A2_roundsat,"Rd32=round(Rss32):sat",ATTRIBS(),
452*7cf9345cSTaylor Simpson"Round & Saturate to 32-bit Signed",
453*7cf9345cSTaylor Simpson{ fHIDE(size8s_t tmp;) fADDSAT64(tmp,RssV,0x080000000ULL); RdV = fGETWORD(1,tmp); })
454*7cf9345cSTaylor Simpson
455*7cf9345cSTaylor SimpsonQ6INSN(A2_sath,"Rd32=sath(Rs32)",ATTRIBS(),
456*7cf9345cSTaylor Simpson"Saturate to 16-bit Signed",
457*7cf9345cSTaylor Simpson{ RdV = fSATH(RsV); })
458*7cf9345cSTaylor Simpson
459*7cf9345cSTaylor SimpsonQ6INSN(A2_satuh,"Rd32=satuh(Rs32)",ATTRIBS(),
460*7cf9345cSTaylor Simpson"Saturate to 16-bit Unsigned",
461*7cf9345cSTaylor Simpson{ RdV = fSATUH(RsV); })
462*7cf9345cSTaylor Simpson
463*7cf9345cSTaylor SimpsonQ6INSN(A2_satub,"Rd32=satub(Rs32)",ATTRIBS(),
464*7cf9345cSTaylor Simpson"Saturate to 8-bit Unsigned",
465*7cf9345cSTaylor Simpson{ RdV = fSATUB(RsV); })
466*7cf9345cSTaylor Simpson
467*7cf9345cSTaylor SimpsonQ6INSN(A2_satb,"Rd32=satb(Rs32)",ATTRIBS(A_ARCHV2),
468*7cf9345cSTaylor Simpson"Saturate to 8-bit Signed",
469*7cf9345cSTaylor Simpson{ RdV = fSATB(RsV); })
470*7cf9345cSTaylor Simpson
471*7cf9345cSTaylor Simpson/**********************************************/
472*7cf9345cSTaylor Simpson/* Vector Add                                 */
473*7cf9345cSTaylor Simpson/**********************************************/
474*7cf9345cSTaylor Simpson
475*7cf9345cSTaylor SimpsonQ6INSN(A2_vaddub,"Rdd32=vaddub(Rss32,Rtt32)",ATTRIBS(),
476*7cf9345cSTaylor Simpson"Add vector of bytes",
477*7cf9345cSTaylor Simpson{
478*7cf9345cSTaylor Simpson        fHIDE(int i;)
479*7cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
480*7cf9345cSTaylor Simpson            fSETBYTE(i,RddV,(fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV)));
481*7cf9345cSTaylor Simpson        }
482*7cf9345cSTaylor Simpson})
483*7cf9345cSTaylor Simpson
484*7cf9345cSTaylor SimpsonQ6INSN(A2_vaddubs,"Rdd32=vaddub(Rss32,Rtt32):sat",ATTRIBS(),
485*7cf9345cSTaylor Simpson"Add vector of bytes",
486*7cf9345cSTaylor Simpson{
487*7cf9345cSTaylor Simpson        fHIDE(int i;)
488*7cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
489*7cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fSATUN(8,fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV)));
490*7cf9345cSTaylor Simpson        }
491*7cf9345cSTaylor Simpson})
492*7cf9345cSTaylor Simpson
493*7cf9345cSTaylor SimpsonQ6INSN(A2_vaddh,"Rdd32=vaddh(Rss32,Rtt32)",ATTRIBS(),
494*7cf9345cSTaylor Simpson"Add vector of half integers",
495*7cf9345cSTaylor Simpson{
496*7cf9345cSTaylor Simpson        fHIDE(int i;)
497*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
498*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fGETHALF(i,RssV)+fGETHALF(i,RttV));
499*7cf9345cSTaylor Simpson        }
500*7cf9345cSTaylor Simpson})
501*7cf9345cSTaylor Simpson
502*7cf9345cSTaylor SimpsonQ6INSN(A2_vaddhs,"Rdd32=vaddh(Rss32,Rtt32):sat",ATTRIBS(),
503*7cf9345cSTaylor Simpson"Add vector of half integers with saturation",
504*7cf9345cSTaylor Simpson{
505*7cf9345cSTaylor Simpson        fHIDE(int i;)
506*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
507*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATN(16,fGETHALF(i,RssV)+fGETHALF(i,RttV)));
508*7cf9345cSTaylor Simpson        }
509*7cf9345cSTaylor Simpson})
510*7cf9345cSTaylor Simpson
511*7cf9345cSTaylor SimpsonQ6INSN(A2_vadduhs,"Rdd32=vadduh(Rss32,Rtt32):sat",ATTRIBS(),
512*7cf9345cSTaylor Simpson"Add vector of unsigned half integers with saturation",
513*7cf9345cSTaylor Simpson{
514*7cf9345cSTaylor Simpson        fHIDE(int i;)
515*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
516*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATUN(16,fGETUHALF(i,RssV)+fGETUHALF(i,RttV)));
517*7cf9345cSTaylor Simpson        }
518*7cf9345cSTaylor Simpson})
519*7cf9345cSTaylor Simpson
520*7cf9345cSTaylor SimpsonQ6INSN(A5_vaddhubs,"Rd32=vaddhub(Rss32,Rtt32):sat",ATTRIBS(),
521*7cf9345cSTaylor Simpson"Add vector of half integers with saturation and pack to unsigned bytes",
522*7cf9345cSTaylor Simpson{
523*7cf9345cSTaylor Simpson        fHIDE(int i;)
524*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
525*7cf9345cSTaylor Simpson            fSETBYTE(i,RdV,fSATUB(fGETHALF(i,RssV)+fGETHALF(i,RttV)));
526*7cf9345cSTaylor Simpson        }
527*7cf9345cSTaylor Simpson})
528*7cf9345cSTaylor Simpson
529*7cf9345cSTaylor SimpsonQ6INSN(A2_vaddw,"Rdd32=vaddw(Rss32,Rtt32)",ATTRIBS(),
530*7cf9345cSTaylor Simpson"Add vector of words",
531*7cf9345cSTaylor Simpson{
532*7cf9345cSTaylor Simpson        fHIDE(int i;)
533*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
534*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,fGETWORD(i,RssV)+fGETWORD(i,RttV));
535*7cf9345cSTaylor Simpson        }
536*7cf9345cSTaylor Simpson})
537*7cf9345cSTaylor Simpson
538*7cf9345cSTaylor SimpsonQ6INSN(A2_vaddws,"Rdd32=vaddw(Rss32,Rtt32):sat",ATTRIBS(),
539*7cf9345cSTaylor Simpson"Add vector of words with saturation",
540*7cf9345cSTaylor Simpson{
541*7cf9345cSTaylor Simpson        fHIDE(int i;)
542*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
543*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSATN(32,fGETWORD(i,RssV)+fGETWORD(i,RttV)));
544*7cf9345cSTaylor Simpson        }
545*7cf9345cSTaylor Simpson})
546*7cf9345cSTaylor Simpson
547*7cf9345cSTaylor Simpson
548*7cf9345cSTaylor Simpson
549*7cf9345cSTaylor SimpsonQ6INSN(S4_vxaddsubw,"Rdd32=vxaddsubw(Rss32,Rtt32):sat",ATTRIBS(),
550*7cf9345cSTaylor Simpson"Cross vector add-sub words with saturation",
551*7cf9345cSTaylor Simpson{
552*7cf9345cSTaylor Simpson        fSETWORD(0,RddV,fSAT(fGETWORD(0,RssV)+fGETWORD(1,RttV)));
553*7cf9345cSTaylor Simpson        fSETWORD(1,RddV,fSAT(fGETWORD(1,RssV)-fGETWORD(0,RttV)));
554*7cf9345cSTaylor Simpson})
555*7cf9345cSTaylor SimpsonQ6INSN(S4_vxsubaddw,"Rdd32=vxsubaddw(Rss32,Rtt32):sat",ATTRIBS(),
556*7cf9345cSTaylor Simpson"Cross vector sub-add words with saturation",
557*7cf9345cSTaylor Simpson{
558*7cf9345cSTaylor Simpson        fSETWORD(0,RddV,fSAT(fGETWORD(0,RssV)-fGETWORD(1,RttV)));
559*7cf9345cSTaylor Simpson        fSETWORD(1,RddV,fSAT(fGETWORD(1,RssV)+fGETWORD(0,RttV)));
560*7cf9345cSTaylor Simpson})
561*7cf9345cSTaylor Simpson
562*7cf9345cSTaylor Simpson
563*7cf9345cSTaylor Simpson
564*7cf9345cSTaylor SimpsonQ6INSN(S4_vxaddsubh,"Rdd32=vxaddsubh(Rss32,Rtt32):sat",ATTRIBS(),
565*7cf9345cSTaylor Simpson"Cross vector add-sub halfwords with saturation",
566*7cf9345cSTaylor Simpson{
567*7cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH(fGETHALF(0,RssV)+fGETHALF(1,RttV)));
568*7cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH(fGETHALF(1,RssV)-fGETHALF(0,RttV)));
569*7cf9345cSTaylor Simpson
570*7cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH(fGETHALF(2,RssV)+fGETHALF(3,RttV)));
571*7cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH(fGETHALF(3,RssV)-fGETHALF(2,RttV)));
572*7cf9345cSTaylor Simpson
573*7cf9345cSTaylor Simpson})
574*7cf9345cSTaylor SimpsonQ6INSN(S4_vxsubaddh,"Rdd32=vxsubaddh(Rss32,Rtt32):sat",ATTRIBS(),
575*7cf9345cSTaylor Simpson"Cross vector sub-add halfwords with saturation",
576*7cf9345cSTaylor Simpson{
577*7cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH(fGETHALF(0,RssV)-fGETHALF(1,RttV)));
578*7cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH(fGETHALF(1,RssV)+fGETHALF(0,RttV)));
579*7cf9345cSTaylor Simpson
580*7cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH(fGETHALF(2,RssV)-fGETHALF(3,RttV)));
581*7cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH(fGETHALF(3,RssV)+fGETHALF(2,RttV)));
582*7cf9345cSTaylor Simpson})
583*7cf9345cSTaylor Simpson
584*7cf9345cSTaylor Simpson
585*7cf9345cSTaylor Simpson
586*7cf9345cSTaylor Simpson
587*7cf9345cSTaylor SimpsonQ6INSN(S4_vxaddsubhr,"Rdd32=vxaddsubh(Rss32,Rtt32):rnd:>>1:sat",ATTRIBS(),
588*7cf9345cSTaylor Simpson"Cross vector add-sub halfwords with shift, round, and saturation",
589*7cf9345cSTaylor Simpson{
590*7cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH((fGETHALF(0,RssV)+fGETHALF(1,RttV)+1)>>1));
591*7cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH((fGETHALF(1,RssV)-fGETHALF(0,RttV)+1)>>1));
592*7cf9345cSTaylor Simpson
593*7cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH((fGETHALF(2,RssV)+fGETHALF(3,RttV)+1)>>1));
594*7cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH((fGETHALF(3,RssV)-fGETHALF(2,RttV)+1)>>1));
595*7cf9345cSTaylor Simpson
596*7cf9345cSTaylor Simpson})
597*7cf9345cSTaylor SimpsonQ6INSN(S4_vxsubaddhr,"Rdd32=vxsubaddh(Rss32,Rtt32):rnd:>>1:sat",ATTRIBS(),
598*7cf9345cSTaylor Simpson"Cross vector sub-add halfwords with shift, round, and saturation",
599*7cf9345cSTaylor Simpson{
600*7cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH((fGETHALF(0,RssV)-fGETHALF(1,RttV)+1)>>1));
601*7cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH((fGETHALF(1,RssV)+fGETHALF(0,RttV)+1)>>1));
602*7cf9345cSTaylor Simpson
603*7cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH((fGETHALF(2,RssV)-fGETHALF(3,RttV)+1)>>1));
604*7cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH((fGETHALF(3,RssV)+fGETHALF(2,RttV)+1)>>1));
605*7cf9345cSTaylor Simpson})
606*7cf9345cSTaylor Simpson
607*7cf9345cSTaylor Simpson
608*7cf9345cSTaylor Simpson
609*7cf9345cSTaylor Simpson
610*7cf9345cSTaylor Simpson
611*7cf9345cSTaylor Simpson/**********************************************/
612*7cf9345cSTaylor Simpson/* 1/2 Vector operations                      */
613*7cf9345cSTaylor Simpson/**********************************************/
614*7cf9345cSTaylor Simpson
615*7cf9345cSTaylor Simpson
616*7cf9345cSTaylor SimpsonQ6INSN(A2_svavgh,"Rd32=vavgh(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
617*7cf9345cSTaylor Simpson"Avg vector of half integers",
618*7cf9345cSTaylor Simpson{
619*7cf9345cSTaylor Simpson        fHIDE(int i;)
620*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
621*7cf9345cSTaylor Simpson            fSETHALF(i,RdV,((fGETHALF(i,RsV)+fGETHALF(i,RtV))>>1));
622*7cf9345cSTaylor Simpson        }
623*7cf9345cSTaylor Simpson})
624*7cf9345cSTaylor Simpson
625*7cf9345cSTaylor SimpsonQ6INSN(A2_svavghs,"Rd32=vavgh(Rs32,Rt32):rnd",ATTRIBS(A_ARCHV2),
626*7cf9345cSTaylor Simpson"Avg vector of half integers with rounding",
627*7cf9345cSTaylor Simpson{
628*7cf9345cSTaylor Simpson        fHIDE(int i;)
629*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
630*7cf9345cSTaylor Simpson            fSETHALF(i,RdV,((fGETHALF(i,RsV)+fGETHALF(i,RtV)+1)>>1));
631*7cf9345cSTaylor Simpson        }
632*7cf9345cSTaylor Simpson})
633*7cf9345cSTaylor Simpson
634*7cf9345cSTaylor Simpson
635*7cf9345cSTaylor Simpson
636*7cf9345cSTaylor SimpsonQ6INSN(A2_svnavgh,"Rd32=vnavgh(Rt32,Rs32)",ATTRIBS(A_ARCHV2),
637*7cf9345cSTaylor Simpson"Avg vector of half integers",
638*7cf9345cSTaylor Simpson{
639*7cf9345cSTaylor Simpson        fHIDE(int i;)
640*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
641*7cf9345cSTaylor Simpson            fSETHALF(i,RdV,((fGETHALF(i,RtV)-fGETHALF(i,RsV))>>1));
642*7cf9345cSTaylor Simpson        }
643*7cf9345cSTaylor Simpson})
644*7cf9345cSTaylor Simpson
645*7cf9345cSTaylor Simpson
646*7cf9345cSTaylor SimpsonQ6INSN(A2_svaddh,"Rd32=vaddh(Rs32,Rt32)",ATTRIBS(),
647*7cf9345cSTaylor Simpson"Add vector of half integers",
648*7cf9345cSTaylor Simpson{
649*7cf9345cSTaylor Simpson        fHIDE(int i;)
650*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
651*7cf9345cSTaylor Simpson            fSETHALF(i,RdV,fGETHALF(i,RsV)+fGETHALF(i,RtV));
652*7cf9345cSTaylor Simpson        }
653*7cf9345cSTaylor Simpson})
654*7cf9345cSTaylor Simpson
655*7cf9345cSTaylor SimpsonQ6INSN(A2_svaddhs,"Rd32=vaddh(Rs32,Rt32):sat",ATTRIBS(),
656*7cf9345cSTaylor Simpson"Add vector of half integers with saturation",
657*7cf9345cSTaylor Simpson{
658*7cf9345cSTaylor Simpson        fHIDE(int i;)
659*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
660*7cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATN(16,fGETHALF(i,RsV)+fGETHALF(i,RtV)));
661*7cf9345cSTaylor Simpson        }
662*7cf9345cSTaylor Simpson})
663*7cf9345cSTaylor Simpson
664*7cf9345cSTaylor SimpsonQ6INSN(A2_svadduhs,"Rd32=vadduh(Rs32,Rt32):sat",ATTRIBS(),
665*7cf9345cSTaylor Simpson"Add vector of unsigned half integers with saturation",
666*7cf9345cSTaylor Simpson{
667*7cf9345cSTaylor Simpson        fHIDE(int i;)
668*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
669*7cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATUN(16,fGETUHALF(i,RsV)+fGETUHALF(i,RtV)));
670*7cf9345cSTaylor Simpson        }
671*7cf9345cSTaylor Simpson})
672*7cf9345cSTaylor Simpson
673*7cf9345cSTaylor Simpson
674*7cf9345cSTaylor SimpsonQ6INSN(A2_svsubh,"Rd32=vsubh(Rt32,Rs32)",ATTRIBS(),
675*7cf9345cSTaylor Simpson"Sub vector of half integers",
676*7cf9345cSTaylor Simpson{
677*7cf9345cSTaylor Simpson        fHIDE(int i;)
678*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
679*7cf9345cSTaylor Simpson            fSETHALF(i,RdV,fGETHALF(i,RtV)-fGETHALF(i,RsV));
680*7cf9345cSTaylor Simpson        }
681*7cf9345cSTaylor Simpson})
682*7cf9345cSTaylor Simpson
683*7cf9345cSTaylor SimpsonQ6INSN(A2_svsubhs,"Rd32=vsubh(Rt32,Rs32):sat",ATTRIBS(),
684*7cf9345cSTaylor Simpson"Sub vector of half integers with saturation",
685*7cf9345cSTaylor Simpson{
686*7cf9345cSTaylor Simpson        fHIDE(int i;)
687*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
688*7cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATN(16,fGETHALF(i,RtV)-fGETHALF(i,RsV)));
689*7cf9345cSTaylor Simpson        }
690*7cf9345cSTaylor Simpson})
691*7cf9345cSTaylor Simpson
692*7cf9345cSTaylor SimpsonQ6INSN(A2_svsubuhs,"Rd32=vsubuh(Rt32,Rs32):sat",ATTRIBS(),
693*7cf9345cSTaylor Simpson"Sub vector of unsigned half integers with saturation",
694*7cf9345cSTaylor Simpson{
695*7cf9345cSTaylor Simpson        fHIDE(int i;)
696*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
697*7cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATUN(16,fGETUHALF(i,RtV)-fGETUHALF(i,RsV)));
698*7cf9345cSTaylor Simpson        }
699*7cf9345cSTaylor Simpson})
700*7cf9345cSTaylor Simpson
701*7cf9345cSTaylor Simpson
702*7cf9345cSTaylor Simpson
703*7cf9345cSTaylor Simpson
704*7cf9345cSTaylor Simpson/**********************************************/
705*7cf9345cSTaylor Simpson/* Vector Reduce Add                          */
706*7cf9345cSTaylor Simpson/**********************************************/
707*7cf9345cSTaylor Simpson
708*7cf9345cSTaylor SimpsonQ6INSN(A2_vraddub,"Rdd32=vraddub(Rss32,Rtt32)",ATTRIBS(),
709*7cf9345cSTaylor Simpson"Sum: two vectors of unsigned bytes",
710*7cf9345cSTaylor Simpson{
711*7cf9345cSTaylor Simpson        fHIDE(int i;)
712*7cf9345cSTaylor Simpson        RddV = 0;
713*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
714*7cf9345cSTaylor Simpson            fSETWORD(0,RddV,(fGETWORD(0,RddV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
715*7cf9345cSTaylor Simpson        }
716*7cf9345cSTaylor Simpson        for (i=4;i<8;i++) {
717*7cf9345cSTaylor Simpson            fSETWORD(1,RddV,(fGETWORD(1,RddV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
718*7cf9345cSTaylor Simpson        }
719*7cf9345cSTaylor Simpson})
720*7cf9345cSTaylor Simpson
721*7cf9345cSTaylor SimpsonQ6INSN(A2_vraddub_acc,"Rxx32+=vraddub(Rss32,Rtt32)",ATTRIBS(),
722*7cf9345cSTaylor Simpson"Sum: two vectors of unsigned bytes",
723*7cf9345cSTaylor Simpson{
724*7cf9345cSTaylor Simpson        fHIDE(int i;)
725*7cf9345cSTaylor Simpson        for (i = 0; i < 4; i++) {
726*7cf9345cSTaylor Simpson            fSETWORD(0,RxxV,(fGETWORD(0,RxxV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
727*7cf9345cSTaylor Simpson        }
728*7cf9345cSTaylor Simpson        for (i = 4; i < 8; i++) {
729*7cf9345cSTaylor Simpson            fSETWORD(1,RxxV,(fGETWORD(1,RxxV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
730*7cf9345cSTaylor Simpson        }
731*7cf9345cSTaylor Simpson})
732*7cf9345cSTaylor Simpson
733*7cf9345cSTaylor Simpson
734*7cf9345cSTaylor Simpson
735*7cf9345cSTaylor SimpsonQ6INSN(M2_vraddh,"Rd32=vraddh(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
736*7cf9345cSTaylor Simpson"Sum: two vectors of halves",
737*7cf9345cSTaylor Simpson{
738*7cf9345cSTaylor Simpson        fHIDE(int i;)
739*7cf9345cSTaylor Simpson        RdV = 0;
740*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
741*7cf9345cSTaylor Simpson            RdV += (fGETHALF(i,RssV)+fGETHALF(i,RttV));
742*7cf9345cSTaylor Simpson        }
743*7cf9345cSTaylor Simpson})
744*7cf9345cSTaylor Simpson
745*7cf9345cSTaylor SimpsonQ6INSN(M2_vradduh,"Rd32=vradduh(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
746*7cf9345cSTaylor Simpson"Sum: two vectors of unsigned halves",
747*7cf9345cSTaylor Simpson{
748*7cf9345cSTaylor Simpson        fHIDE(int i;)
749*7cf9345cSTaylor Simpson        RdV = 0;
750*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
751*7cf9345cSTaylor Simpson            RdV += (fGETUHALF(i,RssV)+fGETUHALF(i,RttV));
752*7cf9345cSTaylor Simpson        }
753*7cf9345cSTaylor Simpson})
754*7cf9345cSTaylor Simpson
755*7cf9345cSTaylor Simpson/**********************************************/
756*7cf9345cSTaylor Simpson/* Vector Sub                                 */
757*7cf9345cSTaylor Simpson/**********************************************/
758*7cf9345cSTaylor Simpson
759*7cf9345cSTaylor SimpsonQ6INSN(A2_vsubub,"Rdd32=vsubub(Rtt32,Rss32)",ATTRIBS(),
760*7cf9345cSTaylor Simpson"Sub vector of bytes",
761*7cf9345cSTaylor Simpson{
762*7cf9345cSTaylor Simpson        fHIDE(int i;)
763*7cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
764*7cf9345cSTaylor Simpson            fSETBYTE(i,RddV,(fGETUBYTE(i,RttV)-fGETUBYTE(i,RssV)));
765*7cf9345cSTaylor Simpson        }
766*7cf9345cSTaylor Simpson})
767*7cf9345cSTaylor Simpson
768*7cf9345cSTaylor SimpsonQ6INSN(A2_vsububs,"Rdd32=vsubub(Rtt32,Rss32):sat",ATTRIBS(),
769*7cf9345cSTaylor Simpson"Sub vector of bytes",
770*7cf9345cSTaylor Simpson{
771*7cf9345cSTaylor Simpson        fHIDE(int i;)
772*7cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
773*7cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fSATUN(8,fGETUBYTE(i,RttV)-fGETUBYTE(i,RssV)));
774*7cf9345cSTaylor Simpson        }
775*7cf9345cSTaylor Simpson})
776*7cf9345cSTaylor Simpson
777*7cf9345cSTaylor SimpsonQ6INSN(A2_vsubh,"Rdd32=vsubh(Rtt32,Rss32)",ATTRIBS(),
778*7cf9345cSTaylor Simpson"Sub vector of half integers",
779*7cf9345cSTaylor Simpson{
780*7cf9345cSTaylor Simpson        fHIDE(int i;)
781*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
782*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fGETHALF(i,RttV)-fGETHALF(i,RssV));
783*7cf9345cSTaylor Simpson        }
784*7cf9345cSTaylor Simpson})
785*7cf9345cSTaylor Simpson
786*7cf9345cSTaylor SimpsonQ6INSN(A2_vsubhs,"Rdd32=vsubh(Rtt32,Rss32):sat",ATTRIBS(),
787*7cf9345cSTaylor Simpson"Sub vector of half integers with saturation",
788*7cf9345cSTaylor Simpson{
789*7cf9345cSTaylor Simpson        fHIDE(int i;)
790*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
791*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATN(16,fGETHALF(i,RttV)-fGETHALF(i,RssV)));
792*7cf9345cSTaylor Simpson        }
793*7cf9345cSTaylor Simpson})
794*7cf9345cSTaylor Simpson
795*7cf9345cSTaylor SimpsonQ6INSN(A2_vsubuhs,"Rdd32=vsubuh(Rtt32,Rss32):sat",ATTRIBS(),
796*7cf9345cSTaylor Simpson"Sub vector of unsigned half integers with saturation",
797*7cf9345cSTaylor Simpson{
798*7cf9345cSTaylor Simpson        fHIDE(int i;)
799*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
800*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATUN(16,fGETUHALF(i,RttV)-fGETUHALF(i,RssV)));
801*7cf9345cSTaylor Simpson        }
802*7cf9345cSTaylor Simpson})
803*7cf9345cSTaylor Simpson
804*7cf9345cSTaylor SimpsonQ6INSN(A2_vsubw,"Rdd32=vsubw(Rtt32,Rss32)",ATTRIBS(),
805*7cf9345cSTaylor Simpson"Sub vector of words",
806*7cf9345cSTaylor Simpson{
807*7cf9345cSTaylor Simpson        fHIDE(int i;)
808*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
809*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,fGETWORD(i,RttV)-fGETWORD(i,RssV));
810*7cf9345cSTaylor Simpson        }
811*7cf9345cSTaylor Simpson})
812*7cf9345cSTaylor Simpson
813*7cf9345cSTaylor SimpsonQ6INSN(A2_vsubws,"Rdd32=vsubw(Rtt32,Rss32):sat",ATTRIBS(),
814*7cf9345cSTaylor Simpson"Sub vector of words with saturation",
815*7cf9345cSTaylor Simpson{
816*7cf9345cSTaylor Simpson        fHIDE(int i;)
817*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
818*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSATN(32,fGETWORD(i,RttV)-fGETWORD(i,RssV)));
819*7cf9345cSTaylor Simpson        }
820*7cf9345cSTaylor Simpson})
821*7cf9345cSTaylor Simpson
822*7cf9345cSTaylor Simpson
823*7cf9345cSTaylor Simpson
824*7cf9345cSTaylor Simpson
825*7cf9345cSTaylor Simpson/**********************************************/
826*7cf9345cSTaylor Simpson/* Vector Abs                                 */
827*7cf9345cSTaylor Simpson/**********************************************/
828*7cf9345cSTaylor Simpson
829*7cf9345cSTaylor SimpsonQ6INSN(A2_vabsh,"Rdd32=vabsh(Rss32)",ATTRIBS(),
830*7cf9345cSTaylor Simpson"Negate vector of half integers",
831*7cf9345cSTaylor Simpson{
832*7cf9345cSTaylor Simpson        fHIDE(int i;)
833*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
834*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fABS(fGETHALF(i,RssV)));
835*7cf9345cSTaylor Simpson        }
836*7cf9345cSTaylor Simpson})
837*7cf9345cSTaylor Simpson
838*7cf9345cSTaylor SimpsonQ6INSN(A2_vabshsat,"Rdd32=vabsh(Rss32):sat",ATTRIBS(),
839*7cf9345cSTaylor Simpson"Negate vector of half integers",
840*7cf9345cSTaylor Simpson{
841*7cf9345cSTaylor Simpson        fHIDE(int i;)
842*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
843*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATH(fABS(fGETHALF(i,RssV))));
844*7cf9345cSTaylor Simpson        }
845*7cf9345cSTaylor Simpson})
846*7cf9345cSTaylor Simpson
847*7cf9345cSTaylor SimpsonQ6INSN(A2_vabsw,"Rdd32=vabsw(Rss32)",ATTRIBS(),
848*7cf9345cSTaylor Simpson"Absolute Value vector of words",
849*7cf9345cSTaylor Simpson{
850*7cf9345cSTaylor Simpson        fHIDE(int i;)
851*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
852*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,fABS(fGETWORD(i,RssV)));
853*7cf9345cSTaylor Simpson        }
854*7cf9345cSTaylor Simpson})
855*7cf9345cSTaylor Simpson
856*7cf9345cSTaylor SimpsonQ6INSN(A2_vabswsat,"Rdd32=vabsw(Rss32):sat",ATTRIBS(),
857*7cf9345cSTaylor Simpson"Absolute Value vector of words",
858*7cf9345cSTaylor Simpson{
859*7cf9345cSTaylor Simpson        fHIDE(int i;)
860*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
861*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSAT(fABS(fGETWORD(i,RssV))));
862*7cf9345cSTaylor Simpson        }
863*7cf9345cSTaylor Simpson})
864*7cf9345cSTaylor Simpson
865*7cf9345cSTaylor Simpson/**********************************************/
866*7cf9345cSTaylor Simpson/* Vector SAD                                 */
867*7cf9345cSTaylor Simpson/**********************************************/
868*7cf9345cSTaylor Simpson
869*7cf9345cSTaylor Simpson
870*7cf9345cSTaylor SimpsonQ6INSN(M2_vabsdiffw,"Rdd32=vabsdiffw(Rtt32,Rss32)",ATTRIBS(A_ARCHV2),
871*7cf9345cSTaylor Simpson"Absolute Differences: vector of words",
872*7cf9345cSTaylor Simpson{
873*7cf9345cSTaylor Simpson        fHIDE(int i;)
874*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
875*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,fABS(fGETWORD(i,RttV) - fGETWORD(i,RssV)));
876*7cf9345cSTaylor Simpson        }
877*7cf9345cSTaylor Simpson})
878*7cf9345cSTaylor Simpson
879*7cf9345cSTaylor SimpsonQ6INSN(M2_vabsdiffh,"Rdd32=vabsdiffh(Rtt32,Rss32)",ATTRIBS(A_ARCHV2),
880*7cf9345cSTaylor Simpson"Absolute Differences: vector of halfwords",
881*7cf9345cSTaylor Simpson{
882*7cf9345cSTaylor Simpson        fHIDE(int i;)
883*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
884*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fABS(fGETHALF(i,RttV) - fGETHALF(i,RssV)));
885*7cf9345cSTaylor Simpson        }
886*7cf9345cSTaylor Simpson})
887*7cf9345cSTaylor Simpson
888*7cf9345cSTaylor SimpsonQ6INSN(M6_vabsdiffb,"Rdd32=vabsdiffb(Rtt32,Rss32)",ATTRIBS(),
889*7cf9345cSTaylor Simpson"Absolute Differences: vector of halfwords",
890*7cf9345cSTaylor Simpson{
891*7cf9345cSTaylor Simpson        fHIDE(int i;)
892*7cf9345cSTaylor Simpson        for (i=0;i<8;i++) {
893*7cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fABS(fGETBYTE(i,RttV) - fGETBYTE(i,RssV)));
894*7cf9345cSTaylor Simpson        }
895*7cf9345cSTaylor Simpson})
896*7cf9345cSTaylor Simpson
897*7cf9345cSTaylor SimpsonQ6INSN(M6_vabsdiffub,"Rdd32=vabsdiffub(Rtt32,Rss32)",ATTRIBS(),
898*7cf9345cSTaylor Simpson"Absolute Differences: vector of halfwords",
899*7cf9345cSTaylor Simpson{
900*7cf9345cSTaylor Simpson        fHIDE(int i;)
901*7cf9345cSTaylor Simpson        for (i=0;i<8;i++) {
902*7cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fABS(fGETUBYTE(i,RttV) - fGETUBYTE(i,RssV)));
903*7cf9345cSTaylor Simpson        }
904*7cf9345cSTaylor Simpson})
905*7cf9345cSTaylor Simpson
906*7cf9345cSTaylor Simpson
907*7cf9345cSTaylor Simpson
908*7cf9345cSTaylor SimpsonQ6INSN(A2_vrsadub,"Rdd32=vrsadub(Rss32,Rtt32)",ATTRIBS(),
909*7cf9345cSTaylor Simpson"Sum of Absolute Differences: vector of unsigned bytes",
910*7cf9345cSTaylor Simpson{
911*7cf9345cSTaylor Simpson        fHIDE(int i;)
912*7cf9345cSTaylor Simpson        RddV = 0;
913*7cf9345cSTaylor Simpson        for (i = 0; i < 4; i++) {
914*7cf9345cSTaylor Simpson            fSETWORD(0,RddV,(fGETWORD(0,RddV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
915*7cf9345cSTaylor Simpson        }
916*7cf9345cSTaylor Simpson        for (i = 4; i < 8; i++) {
917*7cf9345cSTaylor Simpson            fSETWORD(1,RddV,(fGETWORD(1,RddV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
918*7cf9345cSTaylor Simpson        }
919*7cf9345cSTaylor Simpson})
920*7cf9345cSTaylor Simpson
921*7cf9345cSTaylor SimpsonQ6INSN(A2_vrsadub_acc,"Rxx32+=vrsadub(Rss32,Rtt32)",ATTRIBS(),
922*7cf9345cSTaylor Simpson"Sum of Absolute Differences: vector of unsigned bytes",
923*7cf9345cSTaylor Simpson{
924*7cf9345cSTaylor Simpson        fHIDE(int i;)
925*7cf9345cSTaylor Simpson        for (i = 0; i < 4; i++) {
926*7cf9345cSTaylor Simpson            fSETWORD(0,RxxV,(fGETWORD(0,RxxV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
927*7cf9345cSTaylor Simpson        }
928*7cf9345cSTaylor Simpson        for (i = 4; i < 8; i++) {
929*7cf9345cSTaylor Simpson            fSETWORD(1,RxxV,(fGETWORD(1,RxxV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
930*7cf9345cSTaylor Simpson        }
931*7cf9345cSTaylor Simpson})
932*7cf9345cSTaylor Simpson
933*7cf9345cSTaylor Simpson
934*7cf9345cSTaylor Simpson/**********************************************/
935*7cf9345cSTaylor Simpson/* Vector Average                             */
936*7cf9345cSTaylor Simpson/**********************************************/
937*7cf9345cSTaylor Simpson
938*7cf9345cSTaylor SimpsonQ6INSN(A2_vavgub,"Rdd32=vavgub(Rss32,Rtt32)",ATTRIBS(),
939*7cf9345cSTaylor Simpson"Average vector of unsigned bytes",
940*7cf9345cSTaylor Simpson{
941*7cf9345cSTaylor Simpson        fHIDE(int i;)
942*7cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
943*7cf9345cSTaylor Simpson            fSETBYTE(i,RddV,((fGETUBYTE(i,RssV) + fGETUBYTE(i,RttV))>>1));
944*7cf9345cSTaylor Simpson        }
945*7cf9345cSTaylor Simpson})
946*7cf9345cSTaylor Simpson
947*7cf9345cSTaylor SimpsonQ6INSN(A2_vavguh,"Rdd32=vavguh(Rss32,Rtt32)",ATTRIBS(),
948*7cf9345cSTaylor Simpson"Average vector of unsigned halfwords",
949*7cf9345cSTaylor Simpson{
950*7cf9345cSTaylor Simpson        fHIDE(int i;)
951*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
952*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETUHALF(i,RssV)+fGETUHALF(i,RttV))>>1);
953*7cf9345cSTaylor Simpson        }
954*7cf9345cSTaylor Simpson})
955*7cf9345cSTaylor Simpson
956*7cf9345cSTaylor SimpsonQ6INSN(A2_vavgh,"Rdd32=vavgh(Rss32,Rtt32)",ATTRIBS(),
957*7cf9345cSTaylor Simpson"Average vector of halfwords",
958*7cf9345cSTaylor Simpson{
959*7cf9345cSTaylor Simpson        fHIDE(int i;)
960*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
961*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETHALF(i,RssV)+fGETHALF(i,RttV))>>1);
962*7cf9345cSTaylor Simpson        }
963*7cf9345cSTaylor Simpson})
964*7cf9345cSTaylor Simpson
965*7cf9345cSTaylor SimpsonQ6INSN(A2_vnavgh,"Rdd32=vnavgh(Rtt32,Rss32)",ATTRIBS(),
966*7cf9345cSTaylor Simpson"Negative Average vector of halfwords",
967*7cf9345cSTaylor Simpson{
968*7cf9345cSTaylor Simpson        fHIDE(int i;)
969*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
970*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETHALF(i,RttV)-fGETHALF(i,RssV))>>1);
971*7cf9345cSTaylor Simpson        }
972*7cf9345cSTaylor Simpson})
973*7cf9345cSTaylor Simpson
974*7cf9345cSTaylor SimpsonQ6INSN(A2_vavgw,"Rdd32=vavgw(Rss32,Rtt32)",ATTRIBS(),
975*7cf9345cSTaylor Simpson"Average vector of words",
976*7cf9345cSTaylor Simpson{
977*7cf9345cSTaylor Simpson        fHIDE(int i;)
978*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
979*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fSXTN(32,33,fGETWORD(i,RssV))+fSXTN(32,33,fGETWORD(i,RttV)))>>1);
980*7cf9345cSTaylor Simpson        }
981*7cf9345cSTaylor Simpson})
982*7cf9345cSTaylor Simpson
983*7cf9345cSTaylor SimpsonQ6INSN(A2_vnavgw,"Rdd32=vnavgw(Rtt32,Rss32)",ATTRIBS(A_ARCHV2),
984*7cf9345cSTaylor Simpson"Average vector of words",
985*7cf9345cSTaylor Simpson{
986*7cf9345cSTaylor Simpson        fHIDE(int i;)
987*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
988*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fSXTN(32,33,fGETWORD(i,RttV))-fSXTN(32,33,fGETWORD(i,RssV)))>>1);
989*7cf9345cSTaylor Simpson        }
990*7cf9345cSTaylor Simpson})
991*7cf9345cSTaylor Simpson
992*7cf9345cSTaylor SimpsonQ6INSN(A2_vavgwr,"Rdd32=vavgw(Rss32,Rtt32):rnd",ATTRIBS(),
993*7cf9345cSTaylor Simpson"Average vector of words",
994*7cf9345cSTaylor Simpson{
995*7cf9345cSTaylor Simpson        fHIDE(int i;)
996*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
997*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fSXTN(32,33,fGETWORD(i,RssV))+fSXTN(32,33,fGETWORD(i,RttV))+1)>>1);
998*7cf9345cSTaylor Simpson        }
999*7cf9345cSTaylor Simpson})
1000*7cf9345cSTaylor Simpson
1001*7cf9345cSTaylor SimpsonQ6INSN(A2_vnavgwr,"Rdd32=vnavgw(Rtt32,Rss32):rnd:sat",ATTRIBS(A_ARCHV2),
1002*7cf9345cSTaylor Simpson"Average vector of words",
1003*7cf9345cSTaylor Simpson{
1004*7cf9345cSTaylor Simpson        fHIDE(int i;)
1005*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
1006*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSAT((fSXTN(32,33,fGETWORD(i,RttV))-fSXTN(32,33,fGETWORD(i,RssV))+1)>>1));
1007*7cf9345cSTaylor Simpson        }
1008*7cf9345cSTaylor Simpson})
1009*7cf9345cSTaylor Simpson
1010*7cf9345cSTaylor SimpsonQ6INSN(A2_vavgwcr,"Rdd32=vavgw(Rss32,Rtt32):crnd",ATTRIBS(A_ARCHV2),
1011*7cf9345cSTaylor Simpson"Average vector of words with convergent rounding",
1012*7cf9345cSTaylor Simpson{
1013*7cf9345cSTaylor Simpson        fHIDE(int i;)
1014*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
1015*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fCRND(fSXTN(32,33,fGETWORD(i,RssV))+fSXTN(32,33,fGETWORD(i,RttV)))>>1));
1016*7cf9345cSTaylor Simpson        }
1017*7cf9345cSTaylor Simpson})
1018*7cf9345cSTaylor Simpson
1019*7cf9345cSTaylor SimpsonQ6INSN(A2_vnavgwcr,"Rdd32=vnavgw(Rtt32,Rss32):crnd:sat",ATTRIBS(A_ARCHV2),
1020*7cf9345cSTaylor Simpson"Average negative vector of words with convergent rounding",
1021*7cf9345cSTaylor Simpson{
1022*7cf9345cSTaylor Simpson        fHIDE(int i;)
1023*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
1024*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSAT(fCRND(fSXTN(32,33,fGETWORD(i,RttV))-fSXTN(32,33,fGETWORD(i,RssV)))>>1));
1025*7cf9345cSTaylor Simpson        }
1026*7cf9345cSTaylor Simpson})
1027*7cf9345cSTaylor Simpson
1028*7cf9345cSTaylor SimpsonQ6INSN(A2_vavghcr,"Rdd32=vavgh(Rss32,Rtt32):crnd",ATTRIBS(A_ARCHV2),
1029*7cf9345cSTaylor Simpson"Average vector of halfwords with conv rounding",
1030*7cf9345cSTaylor Simpson{
1031*7cf9345cSTaylor Simpson        fHIDE(int i;)
1032*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
1033*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fCRND(fGETHALF(i,RssV)+fGETHALF(i,RttV))>>1);
1034*7cf9345cSTaylor Simpson        }
1035*7cf9345cSTaylor Simpson})
1036*7cf9345cSTaylor Simpson
1037*7cf9345cSTaylor SimpsonQ6INSN(A2_vnavghcr,"Rdd32=vnavgh(Rtt32,Rss32):crnd:sat",ATTRIBS(A_ARCHV2),
1038*7cf9345cSTaylor Simpson"Average negative vector of halfwords with conv rounding",
1039*7cf9345cSTaylor Simpson{
1040*7cf9345cSTaylor Simpson        fHIDE(int i;)
1041*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
1042*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATH(fCRND(fGETHALF(i,RttV)-fGETHALF(i,RssV))>>1));
1043*7cf9345cSTaylor Simpson        }
1044*7cf9345cSTaylor Simpson})
1045*7cf9345cSTaylor Simpson
1046*7cf9345cSTaylor Simpson
1047*7cf9345cSTaylor SimpsonQ6INSN(A2_vavguw,"Rdd32=vavguw(Rss32,Rtt32)",ATTRIBS(),
1048*7cf9345cSTaylor Simpson"Average vector of unsigned words",
1049*7cf9345cSTaylor Simpson{
1050*7cf9345cSTaylor Simpson        fHIDE(int i;)
1051*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
1052*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fZXTN(32,33,fGETUWORD(i,RssV))+fZXTN(32,33,fGETUWORD(i,RttV)))>>1);
1053*7cf9345cSTaylor Simpson        }
1054*7cf9345cSTaylor Simpson})
1055*7cf9345cSTaylor Simpson
1056*7cf9345cSTaylor SimpsonQ6INSN(A2_vavguwr,"Rdd32=vavguw(Rss32,Rtt32):rnd",ATTRIBS(),
1057*7cf9345cSTaylor Simpson"Average vector of unsigned words",
1058*7cf9345cSTaylor Simpson{
1059*7cf9345cSTaylor Simpson        fHIDE(int i;)
1060*7cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
1061*7cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fZXTN(32,33,fGETUWORD(i,RssV))+fZXTN(32,33,fGETUWORD(i,RttV))+1)>>1);
1062*7cf9345cSTaylor Simpson        }
1063*7cf9345cSTaylor Simpson})
1064*7cf9345cSTaylor Simpson
1065*7cf9345cSTaylor SimpsonQ6INSN(A2_vavgubr,"Rdd32=vavgub(Rss32,Rtt32):rnd",ATTRIBS(),
1066*7cf9345cSTaylor Simpson"Average vector of unsigned bytes",
1067*7cf9345cSTaylor Simpson{
1068*7cf9345cSTaylor Simpson        fHIDE(int i;)
1069*7cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
1070*7cf9345cSTaylor Simpson            fSETBYTE(i,RddV,((fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV)+1)>>1));
1071*7cf9345cSTaylor Simpson        }
1072*7cf9345cSTaylor Simpson})
1073*7cf9345cSTaylor Simpson
1074*7cf9345cSTaylor SimpsonQ6INSN(A2_vavguhr,"Rdd32=vavguh(Rss32,Rtt32):rnd",ATTRIBS(),
1075*7cf9345cSTaylor Simpson"Average vector of unsigned halfwords with rounding",
1076*7cf9345cSTaylor Simpson{
1077*7cf9345cSTaylor Simpson        fHIDE(int i;)
1078*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
1079*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETUHALF(i,RssV)+fGETUHALF(i,RttV)+1)>>1);
1080*7cf9345cSTaylor Simpson        }
1081*7cf9345cSTaylor Simpson})
1082*7cf9345cSTaylor Simpson
1083*7cf9345cSTaylor SimpsonQ6INSN(A2_vavghr,"Rdd32=vavgh(Rss32,Rtt32):rnd",ATTRIBS(),
1084*7cf9345cSTaylor Simpson"Average vector of halfwords with rounding",
1085*7cf9345cSTaylor Simpson{
1086*7cf9345cSTaylor Simpson        fHIDE(int i;)
1087*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
1088*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETHALF(i,RssV)+fGETHALF(i,RttV)+1)>>1);
1089*7cf9345cSTaylor Simpson        }
1090*7cf9345cSTaylor Simpson})
1091*7cf9345cSTaylor Simpson
1092*7cf9345cSTaylor SimpsonQ6INSN(A2_vnavghr,"Rdd32=vnavgh(Rtt32,Rss32):rnd:sat",ATTRIBS(A_ARCHV2),
1093*7cf9345cSTaylor Simpson"Negative Average vector of halfwords with rounding",
1094*7cf9345cSTaylor Simpson{
1095*7cf9345cSTaylor Simpson        fHIDE(int i;)
1096*7cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
1097*7cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATH((fGETHALF(i,RttV)-fGETHALF(i,RssV)+1)>>1));
1098*7cf9345cSTaylor Simpson        }
1099*7cf9345cSTaylor Simpson})
1100*7cf9345cSTaylor Simpson
1101*7cf9345cSTaylor Simpson
1102*7cf9345cSTaylor Simpson/* Rounding Instruction */
1103*7cf9345cSTaylor Simpson
1104*7cf9345cSTaylor SimpsonQ6INSN(A4_round_ri,"Rd32=round(Rs32,#u5)",ATTRIBS(),"Round", {RdV = fRNDN(RsV,uiV)>>uiV; })
1105*7cf9345cSTaylor SimpsonQ6INSN(A4_round_rr,"Rd32=round(Rs32,Rt32)",ATTRIBS(),"Round", {RdV = fRNDN(RsV,fZXTN(5,32,RtV))>>fZXTN(5,32,RtV); })
1106*7cf9345cSTaylor SimpsonQ6INSN(A4_round_ri_sat,"Rd32=round(Rs32,#u5):sat",ATTRIBS(),"Round", {RdV = (fSAT(fRNDN(RsV,uiV)))>>uiV; })
1107*7cf9345cSTaylor SimpsonQ6INSN(A4_round_rr_sat,"Rd32=round(Rs32,Rt32):sat",ATTRIBS(),"Round", {RdV = (fSAT(fRNDN(RsV,fZXTN(5,32,RtV))))>>fZXTN(5,32,RtV); })
1108*7cf9345cSTaylor Simpson
1109*7cf9345cSTaylor Simpson
1110*7cf9345cSTaylor SimpsonQ6INSN(A4_cround_ri,"Rd32=cround(Rs32,#u5)",ATTRIBS(),"Convergent Round", {RdV = fCRNDN(RsV,uiV); })
1111*7cf9345cSTaylor SimpsonQ6INSN(A4_cround_rr,"Rd32=cround(Rs32,Rt32)",ATTRIBS(),"Convergent Round", {RdV = fCRNDN(RsV,fZXTN(5,32,RtV)); })
1112*7cf9345cSTaylor Simpson
1113*7cf9345cSTaylor Simpson
1114*7cf9345cSTaylor Simpson#define CROUND(DST,SRC,SHIFT) \
1115*7cf9345cSTaylor Simpson        fHIDE(size16s_t rndbit_128;)\
1116*7cf9345cSTaylor Simpson        fHIDE(size16s_t tmp128;)\
1117*7cf9345cSTaylor Simpson        fHIDE(size16s_t src_128;)\
1118*7cf9345cSTaylor Simpson        if (SHIFT == 0) { \
1119*7cf9345cSTaylor Simpson            DST = SRC;\
1120*7cf9345cSTaylor Simpson        } else if ((SRC & (size8s_t)((1LL << (SHIFT - 1)) - 1LL)) == 0) { \
1121*7cf9345cSTaylor Simpson            src_128 = fCAST8S_16S(SRC);\
1122*7cf9345cSTaylor Simpson            rndbit_128 = fCAST8S_16S(1LL);\
1123*7cf9345cSTaylor Simpson            rndbit_128 = fSHIFTL128(rndbit_128, SHIFT);\
1124*7cf9345cSTaylor Simpson            rndbit_128 = fAND128(rndbit_128, src_128);\
1125*7cf9345cSTaylor Simpson            rndbit_128 = fSHIFTR128(rndbit_128, 1);\
1126*7cf9345cSTaylor Simpson            tmp128 = fADD128(src_128, rndbit_128);\
1127*7cf9345cSTaylor Simpson            tmp128 = fSHIFTR128(tmp128, SHIFT);\
1128*7cf9345cSTaylor Simpson            DST =  fCAST16S_8S(tmp128);\
1129*7cf9345cSTaylor Simpson        } else {\
1130*7cf9345cSTaylor Simpson            size16s_t rndbit_128 =  fCAST8S_16S((1LL << (SHIFT - 1))); \
1131*7cf9345cSTaylor Simpson            size16s_t src_128 =  fCAST8S_16S(SRC); \
1132*7cf9345cSTaylor Simpson            size16s_t tmp128 = fADD128(src_128, rndbit_128);\
1133*7cf9345cSTaylor Simpson            tmp128 = fSHIFTR128(tmp128, SHIFT);\
1134*7cf9345cSTaylor Simpson            DST =  fCAST16S_8S(tmp128);\
1135*7cf9345cSTaylor Simpson        }
1136*7cf9345cSTaylor Simpson
1137*7cf9345cSTaylor SimpsonQ6INSN(A7_croundd_ri,"Rdd32=cround(Rss32,#u6)",ATTRIBS(),"Convergent Round",
1138*7cf9345cSTaylor Simpson{
1139*7cf9345cSTaylor SimpsonCROUND(RddV,RssV,uiV);
1140*7cf9345cSTaylor Simpson})
1141*7cf9345cSTaylor Simpson
1142*7cf9345cSTaylor SimpsonQ6INSN(A7_croundd_rr,"Rdd32=cround(Rss32,Rt32)",ATTRIBS(),"Convergent Round",
1143*7cf9345cSTaylor Simpson{
1144*7cf9345cSTaylor SimpsonCROUND(RddV,RssV,fZXTN(6,32,RtV));
1145*7cf9345cSTaylor Simpson})
1146*7cf9345cSTaylor Simpson
1147*7cf9345cSTaylor Simpson
1148*7cf9345cSTaylor Simpson
1149*7cf9345cSTaylor Simpson
1150*7cf9345cSTaylor Simpson
1151*7cf9345cSTaylor Simpson
1152*7cf9345cSTaylor Simpson
1153*7cf9345cSTaylor Simpson
1154*7cf9345cSTaylor Simpson
1155*7cf9345cSTaylor SimpsonQ6INSN(A7_clip,"Rd32=clip(Rs32,#u5)",ATTRIBS(),"Clip to  #s5", {   fCLIP(RdV,RsV,uiV);})
1156*7cf9345cSTaylor SimpsonQ6INSN(A7_vclip,"Rdd32=vclip(Rss32,#u5)",ATTRIBS(),"Clip to  #s5",
1157*7cf9345cSTaylor Simpson{
1158*7cf9345cSTaylor SimpsonfHIDE(size4s_t tmp;)
1159*7cf9345cSTaylor SimpsonfCLIP(tmp, fGETWORD(0, RssV), uiV);
1160*7cf9345cSTaylor SimpsonfSETWORD(0, RddV, tmp);
1161*7cf9345cSTaylor SimpsonfCLIP(tmp,fGETWORD(1, RssV), uiV);
1162*7cf9345cSTaylor SimpsonfSETWORD(1, RddV, tmp);
1163*7cf9345cSTaylor Simpson}
1164*7cf9345cSTaylor Simpson)
1165*7cf9345cSTaylor Simpson
1166*7cf9345cSTaylor Simpson
1167*7cf9345cSTaylor Simpson
1168*7cf9345cSTaylor Simpson/**********************************************/
1169*7cf9345cSTaylor Simpson/* V4: Cross Vector Min/Max                   */
1170*7cf9345cSTaylor Simpson/**********************************************/
1171*7cf9345cSTaylor Simpson
1172*7cf9345cSTaylor Simpson
1173*7cf9345cSTaylor Simpson#define VRMINORMAX(TAG,STR,OP,SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT) \
1174*7cf9345cSTaylor SimpsonQ6INSN(A4_vr##TAG##SHORTTYPE,"Rxx32=vr"#TAG#SHORTTYPE"(Rss32,Ru32)",ATTRIBS(), \
1175*7cf9345cSTaylor Simpson"Choose " STR " elements of a vector", \
1176*7cf9345cSTaylor Simpson{ \
1177*7cf9345cSTaylor Simpson        fHIDE(int i; size8s_t TAG; size4s_t addr;) \
1178*7cf9345cSTaylor Simpson        TAG = fGET##GETTYPE(0,RxxV); \
1179*7cf9345cSTaylor Simpson        addr = fGETWORD(1,RxxV); \
1180*7cf9345cSTaylor Simpson        for (i = 0; i < NEL; i++) { \
1181*7cf9345cSTaylor Simpson            if (TAG OP fGET##GETTYPE(i,RssV)) { \
1182*7cf9345cSTaylor Simpson                TAG = fGET##GETTYPE(i,RssV); \
1183*7cf9345cSTaylor Simpson                addr = RuV | i<<SHIFT; \
1184*7cf9345cSTaylor Simpson            } \
1185*7cf9345cSTaylor Simpson        } \
1186*7cf9345cSTaylor Simpson        fSETWORD(0,RxxV,TAG); \
1187*7cf9345cSTaylor Simpson        fSETWORD(1,RxxV,addr); \
1188*7cf9345cSTaylor Simpson})
1189*7cf9345cSTaylor Simpson
1190*7cf9345cSTaylor Simpson#define RMINMAX(SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT) \
1191*7cf9345cSTaylor SimpsonVRMINORMAX(min,"minimum",>,SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT) \
1192*7cf9345cSTaylor SimpsonVRMINORMAX(max,"maximum",<,SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT)
1193*7cf9345cSTaylor Simpson
1194*7cf9345cSTaylor Simpson
1195*7cf9345cSTaylor SimpsonRMINMAX(h,HALF,HALF,4,1)
1196*7cf9345cSTaylor SimpsonRMINMAX(uh,HALF,UHALF,4,1)
1197*7cf9345cSTaylor SimpsonRMINMAX(w,WORD,WORD,2,2)
1198*7cf9345cSTaylor SimpsonRMINMAX(uw,WORD,UWORD,2,2)
1199*7cf9345cSTaylor Simpson
1200*7cf9345cSTaylor Simpson#undef RMINMAX
1201*7cf9345cSTaylor Simpson#undef VRMINORMAX
1202*7cf9345cSTaylor Simpson
1203*7cf9345cSTaylor Simpson/**********************************************/
1204*7cf9345cSTaylor Simpson/* Vector Min/Max                             */
1205*7cf9345cSTaylor Simpson/**********************************************/
1206*7cf9345cSTaylor Simpson
1207*7cf9345cSTaylor Simpson#define VMINORMAX(TAG,STR,FUNC,SHORTTYPE,SETTYPE,GETTYPE,NEL) \
1208*7cf9345cSTaylor SimpsonQ6INSN(A2_v##TAG##SHORTTYPE,"Rdd32=v"#TAG#SHORTTYPE"(Rtt32,Rss32)",ATTRIBS(), \
1209*7cf9345cSTaylor Simpson"Choose " STR " elements of two vectors", \
1210*7cf9345cSTaylor Simpson{ \
1211*7cf9345cSTaylor Simpson        fHIDE(int i;) \
1212*7cf9345cSTaylor Simpson        for (i = 0; i < NEL; i++) { \
1213*7cf9345cSTaylor Simpson            fSET##SETTYPE(i,RddV,FUNC(fGET##GETTYPE(i,RttV),fGET##GETTYPE(i,RssV))); \
1214*7cf9345cSTaylor Simpson        } \
1215*7cf9345cSTaylor Simpson})
1216*7cf9345cSTaylor Simpson
1217*7cf9345cSTaylor Simpson#define VMINORMAX3(TAG,STR,FUNC,SHORTTYPE,SETTYPE,GETTYPE,NEL) \
1218*7cf9345cSTaylor SimpsonQ6INSN(A6_v##TAG##SHORTTYPE##3,"Rxx32=v"#TAG#SHORTTYPE"3(Rtt32,Rss32)",ATTRIBS(), \
1219*7cf9345cSTaylor Simpson"Choose " STR " elements of two vectors", \
1220*7cf9345cSTaylor Simpson{ \
1221*7cf9345cSTaylor Simpson        fHIDE(int i;) \
1222*7cf9345cSTaylor Simpson        for (i = 0; i < NEL; i++) { \
1223*7cf9345cSTaylor Simpson            fSET##SETTYPE(i,RxxV,FUNC(fGET##GETTYPE(i,RxxV),FUNC(fGET##GETTYPE(i,RttV),fGET##GETTYPE(i,RssV)))); \
1224*7cf9345cSTaylor Simpson        } \
1225*7cf9345cSTaylor Simpson})
1226*7cf9345cSTaylor Simpson
1227*7cf9345cSTaylor Simpson#define MINMAX(SHORTTYPE,SETTYPE,GETTYPE,NEL) \
1228*7cf9345cSTaylor SimpsonVMINORMAX(min,"minimum",fMIN,SHORTTYPE,SETTYPE,GETTYPE,NEL) \
1229*7cf9345cSTaylor SimpsonVMINORMAX(max,"maximum",fMAX,SHORTTYPE,SETTYPE,GETTYPE,NEL)
1230*7cf9345cSTaylor Simpson
1231*7cf9345cSTaylor SimpsonMINMAX(b,BYTE,BYTE,8)
1232*7cf9345cSTaylor SimpsonMINMAX(ub,BYTE,UBYTE,8)
1233*7cf9345cSTaylor SimpsonMINMAX(h,HALF,HALF,4)
1234*7cf9345cSTaylor SimpsonMINMAX(uh,HALF,UHALF,4)
1235*7cf9345cSTaylor SimpsonMINMAX(w,WORD,WORD,2)
1236*7cf9345cSTaylor SimpsonMINMAX(uw,WORD,UWORD,2)
1237*7cf9345cSTaylor Simpson
1238*7cf9345cSTaylor Simpson#undef MINMAX
1239*7cf9345cSTaylor Simpson#undef VMINORMAX
1240*7cf9345cSTaylor Simpson#undef VMINORMAX3
1241*7cf9345cSTaylor Simpson
1242*7cf9345cSTaylor Simpson
1243*7cf9345cSTaylor Simpson/**********************************************/
1244*7cf9345cSTaylor Simpson/* Vector Min/Max                             */
1245*7cf9345cSTaylor Simpson/**********************************************/
1246*7cf9345cSTaylor Simpson
1247*7cf9345cSTaylor Simpson
1248*7cf9345cSTaylor SimpsonQ6INSN(A4_modwrapu,"Rd32=modwrap(Rs32,Rt32)",ATTRIBS(),
1249*7cf9345cSTaylor Simpson"Wrap to an unsigned modulo buffer",
1250*7cf9345cSTaylor Simpson{
1251*7cf9345cSTaylor Simpson        if (RsV < 0) {
1252*7cf9345cSTaylor Simpson            RdV = RsV + fCAST4u(RtV);
1253*7cf9345cSTaylor Simpson        } else if (fCAST4u(RsV) >= fCAST4u(RtV)) {
1254*7cf9345cSTaylor Simpson            RdV = RsV - fCAST4u(RtV);
1255*7cf9345cSTaylor Simpson        } else {
1256*7cf9345cSTaylor Simpson            RdV = RsV;
1257*7cf9345cSTaylor Simpson        }
1258*7cf9345cSTaylor Simpson})
1259