xref: /openbmc/qemu/target/hexagon/imported/alu.idef (revision 6c67d98c)
17cf9345cSTaylor Simpson/*
27cf9345cSTaylor Simpson *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
37cf9345cSTaylor Simpson *
47cf9345cSTaylor Simpson *  This program is free software; you can redistribute it and/or modify
57cf9345cSTaylor Simpson *  it under the terms of the GNU General Public License as published by
67cf9345cSTaylor Simpson *  the Free Software Foundation; either version 2 of the License, or
77cf9345cSTaylor Simpson *  (at your option) any later version.
87cf9345cSTaylor Simpson *
97cf9345cSTaylor Simpson *  This program is distributed in the hope that it will be useful,
107cf9345cSTaylor Simpson *  but WITHOUT ANY WARRANTY; without even the implied warranty of
117cf9345cSTaylor Simpson *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
127cf9345cSTaylor Simpson *  GNU General Public License for more details.
137cf9345cSTaylor Simpson *
147cf9345cSTaylor Simpson *  You should have received a copy of the GNU General Public License
157cf9345cSTaylor Simpson *  along with this program; if not, see <http://www.gnu.org/licenses/>.
167cf9345cSTaylor Simpson */
177cf9345cSTaylor Simpson
187cf9345cSTaylor Simpson/*
197cf9345cSTaylor Simpson * ALU Instructions
207cf9345cSTaylor Simpson */
217cf9345cSTaylor Simpson
227cf9345cSTaylor Simpson
237cf9345cSTaylor Simpson/**********************************************/
247cf9345cSTaylor Simpson/* Add/Sub instructions                       */
257cf9345cSTaylor Simpson/**********************************************/
267cf9345cSTaylor Simpson
277cf9345cSTaylor SimpsonQ6INSN(A2_add,"Rd32=add(Rs32,Rt32)",ATTRIBS(),
287cf9345cSTaylor Simpson"Add 32-bit registers",
297cf9345cSTaylor Simpson{ RdV=RsV+RtV;})
307cf9345cSTaylor Simpson
317cf9345cSTaylor SimpsonQ6INSN(A2_sub,"Rd32=sub(Rt32,Rs32)",ATTRIBS(),
327cf9345cSTaylor Simpson"Subtract 32-bit registers",
337cf9345cSTaylor Simpson{ RdV=RtV-RsV;})
347cf9345cSTaylor Simpson
357cf9345cSTaylor Simpson#define COND_ALU(TAG,OPER,DESCR,SEMANTICS)\
367cf9345cSTaylor SimpsonQ6INSN(TAG##t,"if (Pu4) "OPER,ATTRIBS(A_ARCHV2),DESCR,{if(fLSBOLD(PuV)){SEMANTICS;} else {CANCEL;}})\
377cf9345cSTaylor SimpsonQ6INSN(TAG##f,"if (!Pu4) "OPER,ATTRIBS(A_ARCHV2),DESCR,{if(fLSBOLDNOT(PuV)){SEMANTICS;} else {CANCEL;}})\
387cf9345cSTaylor SimpsonQ6INSN(TAG##tnew,"if (Pu4.new) " OPER,ATTRIBS(A_ARCHV2),DESCR,{if(fLSBNEW(PuN)){SEMANTICS;} else {CANCEL;}})\
397cf9345cSTaylor SimpsonQ6INSN(TAG##fnew,"if (!Pu4.new) "OPER,ATTRIBS(A_ARCHV2),DESCR,{if(fLSBNEWNOT(PuN)){SEMANTICS;} else {CANCEL;}})
407cf9345cSTaylor Simpson
417cf9345cSTaylor SimpsonCOND_ALU(A2_padd,"Rd32=add(Rs32,Rt32)","Conditionally Add 32-bit registers",RdV=RsV+RtV)
427cf9345cSTaylor SimpsonCOND_ALU(A2_psub,"Rd32=sub(Rt32,Rs32)","Conditionally Subtract 32-bit registers",RdV=RtV-RsV)
437cf9345cSTaylor SimpsonCOND_ALU(A2_paddi,"Rd32=add(Rs32,#s8)","Conditionally Add Register and immediate",fIMMEXT(siV); RdV=RsV+siV)
447cf9345cSTaylor SimpsonCOND_ALU(A2_pxor,"Rd32=xor(Rs32,Rt32)","Conditionally XOR registers",RdV=RsV^RtV)
457cf9345cSTaylor SimpsonCOND_ALU(A2_pand,"Rd32=and(Rs32,Rt32)","Conditionally AND registers",RdV=RsV&RtV)
467cf9345cSTaylor SimpsonCOND_ALU(A2_por,"Rd32=or(Rs32,Rt32)","Conditionally OR registers",RdV=RsV|RtV)
477cf9345cSTaylor Simpson
487cf9345cSTaylor SimpsonCOND_ALU(A4_psxtb,"Rd32=sxtb(Rs32)","Conditionally sign-extend byte", RdV=fSXTN(8,32,RsV))
497cf9345cSTaylor SimpsonCOND_ALU(A4_pzxtb,"Rd32=zxtb(Rs32)","Conditionally zero-extend byte", RdV=fZXTN(8,32,RsV))
507cf9345cSTaylor SimpsonCOND_ALU(A4_psxth,"Rd32=sxth(Rs32)","Conditionally sign-extend halfword", RdV=fSXTN(16,32,RsV))
517cf9345cSTaylor SimpsonCOND_ALU(A4_pzxth,"Rd32=zxth(Rs32)","Conditionally zero-extend halfword", RdV=fZXTN(16,32,RsV))
527cf9345cSTaylor SimpsonCOND_ALU(A4_paslh,"Rd32=aslh(Rs32)","Conditionally zero-extend halfword", RdV=RsV<<16)
537cf9345cSTaylor SimpsonCOND_ALU(A4_pasrh,"Rd32=asrh(Rs32)","Conditionally zero-extend halfword", RdV=RsV>>16)
547cf9345cSTaylor Simpson
557cf9345cSTaylor Simpson
567cf9345cSTaylor SimpsonQ6INSN(A2_addsat,"Rd32=add(Rs32,Rt32):sat",ATTRIBS(),
577cf9345cSTaylor Simpson"Add 32-bit registers with saturation",
587cf9345cSTaylor Simpson{ RdV=fSAT(fSE32_64(RsV)+fSE32_64(RtV)); })
597cf9345cSTaylor Simpson
607cf9345cSTaylor SimpsonQ6INSN(A2_subsat,"Rd32=sub(Rt32,Rs32):sat",ATTRIBS(),
617cf9345cSTaylor Simpson"Subtract 32-bit registers with saturation",
627cf9345cSTaylor Simpson{ RdV=fSAT(fSE32_64(RtV) - fSE32_64(RsV)); })
637cf9345cSTaylor Simpson
647cf9345cSTaylor Simpson
657cf9345cSTaylor SimpsonQ6INSN(A2_addi,"Rd32=add(Rs32,#s16)",ATTRIBS(),
667cf9345cSTaylor Simpson"Add a signed immediate to a register",
677cf9345cSTaylor Simpson{ fIMMEXT(siV); RdV=RsV+siV;})
687cf9345cSTaylor Simpson
697cf9345cSTaylor Simpson
707cf9345cSTaylor SimpsonQ6INSN(C4_addipc,"Rd32=add(pc,#u6)",ATTRIBS(),
717cf9345cSTaylor Simpson"Add immediate to PC",
727cf9345cSTaylor Simpson{ RdV=fREAD_PC()+fIMMEXT(uiV);})
737cf9345cSTaylor Simpson
747cf9345cSTaylor Simpson
757cf9345cSTaylor Simpson
767cf9345cSTaylor Simpson/**********************************************/
777cf9345cSTaylor Simpson/* Single-precision HL forms                  */
787cf9345cSTaylor Simpson/* These insns and the SP mpy are the ones    */
797cf9345cSTaylor Simpson/* that can do .HL stuff                      */
807cf9345cSTaylor Simpson/**********************************************/
817cf9345cSTaylor Simpson#define STD_HL_INSN(TAG,OPER,AOPER,ATR,SEM)\
827cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_ll, OPER"(Rt.L32,Rs.L32)"AOPER,    ATR,"",{SEM(fGETHALF(0,RtV),fGETHALF(0,RsV));})\
837cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_lh, OPER"(Rt.L32,Rs.H32)"AOPER,    ATR,"",{SEM(fGETHALF(0,RtV),fGETHALF(1,RsV));})\
847cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_hl, OPER"(Rt.H32,Rs.L32)"AOPER,    ATR,"",{SEM(fGETHALF(1,RtV),fGETHALF(0,RsV));})\
857cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_hh, OPER"(Rt.H32,Rs.H32)"AOPER,    ATR,"",{SEM(fGETHALF(1,RtV),fGETHALF(1,RsV));})
867cf9345cSTaylor Simpson
877cf9345cSTaylor Simpson#define SUBSTD_HL_INSN(TAG,OPER,AOPER,ATR,SEM)\
887cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_ll, OPER"(Rt.L32,Rs.L32)"AOPER,    ATR,"",{SEM(fGETHALF(0,RtV),fGETHALF(0,RsV));})\
897cf9345cSTaylor SimpsonQ6INSN(A2_##TAG##_hl, OPER"(Rt.L32,Rs.H32)"AOPER,    ATR,"",{SEM(fGETHALF(0,RtV),fGETHALF(1,RsV));})
907cf9345cSTaylor Simpson
917cf9345cSTaylor Simpson
927cf9345cSTaylor Simpson#undef HLSEM
937cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=fSXTN(16,32,(A+B))
947cf9345cSTaylor SimpsonSUBSTD_HL_INSN(addh_l16,"Rd32=add","",ATTRIBS(),HLSEM)
957cf9345cSTaylor Simpson
967cf9345cSTaylor Simpson#undef HLSEM
977cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=fSATH(A+B)
987cf9345cSTaylor SimpsonSUBSTD_HL_INSN(addh_l16_sat,"Rd32=add",":sat",ATTRIBS(),HLSEM)
997cf9345cSTaylor Simpson
1007cf9345cSTaylor Simpson#undef HLSEM
1017cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=fSXTN(16,32,(A-B))
1027cf9345cSTaylor SimpsonSUBSTD_HL_INSN(subh_l16,"Rd32=sub","",ATTRIBS(),HLSEM)
1037cf9345cSTaylor Simpson
1047cf9345cSTaylor Simpson#undef HLSEM
1057cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=fSATH(A-B)
1067cf9345cSTaylor SimpsonSUBSTD_HL_INSN(subh_l16_sat,"Rd32=sub",":sat",ATTRIBS(),HLSEM)
1077cf9345cSTaylor Simpson
1087cf9345cSTaylor Simpson#undef HLSEM
1097cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=(A+B)<<16
1107cf9345cSTaylor SimpsonSTD_HL_INSN(addh_h16,"Rd32=add",":<<16",ATTRIBS(),HLSEM)
1117cf9345cSTaylor Simpson
1127cf9345cSTaylor Simpson#undef HLSEM
1137cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=(fSATH(A+B))<<16
1147cf9345cSTaylor SimpsonSTD_HL_INSN(addh_h16_sat,"Rd32=add",":sat:<<16",ATTRIBS(),HLSEM)
1157cf9345cSTaylor Simpson
1167cf9345cSTaylor Simpson#undef HLSEM
1177cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=(A-B)<<16
1187cf9345cSTaylor SimpsonSTD_HL_INSN(subh_h16,"Rd32=sub",":<<16",ATTRIBS(),HLSEM)
1197cf9345cSTaylor Simpson
1207cf9345cSTaylor Simpson#undef HLSEM
1217cf9345cSTaylor Simpson#define HLSEM(A,B) RdV=(fSATH(A-B))<<16
1227cf9345cSTaylor SimpsonSTD_HL_INSN(subh_h16_sat,"Rd32=sub",":sat:<<16",ATTRIBS(),HLSEM)
1237cf9345cSTaylor Simpson
1247cf9345cSTaylor Simpson
1257cf9345cSTaylor Simpson
1267cf9345cSTaylor Simpson
1277cf9345cSTaylor SimpsonQ6INSN(A2_aslh,"Rd32=aslh(Rs32)",ATTRIBS(),
1287cf9345cSTaylor Simpson"Arithmetic Shift Left by Halfword",{ RdV=RsV<<16; })
1297cf9345cSTaylor Simpson
1307cf9345cSTaylor SimpsonQ6INSN(A2_asrh,"Rd32=asrh(Rs32)",ATTRIBS(),
1317cf9345cSTaylor Simpson"Arithmetic Shift Right by Halfword",{ RdV=RsV>>16; })
1327cf9345cSTaylor Simpson
1337cf9345cSTaylor Simpson
1347cf9345cSTaylor Simpson/* 64-bit versions */
1357cf9345cSTaylor Simpson
1367cf9345cSTaylor SimpsonQ6INSN(A2_addp,"Rdd32=add(Rss32,Rtt32)",ATTRIBS(),
1377cf9345cSTaylor Simpson"Add",
1387cf9345cSTaylor Simpson{ RddV=RssV+RttV;})
1397cf9345cSTaylor Simpson
1407cf9345cSTaylor SimpsonQ6INSN(A2_addpsat,"Rdd32=add(Rss32,Rtt32):sat",ATTRIBS(A_ARCHV3),
1417cf9345cSTaylor Simpson"Add",
1427cf9345cSTaylor Simpson{ fADDSAT64(RddV,RssV,RttV);})
1437cf9345cSTaylor Simpson
1447cf9345cSTaylor SimpsonQ6INSN(A2_addspl,"Rdd32=add(Rss32,Rtt32):raw:lo",ATTRIBS(A_ARCHV3),
1457cf9345cSTaylor Simpson"Add",
1467cf9345cSTaylor Simpson{ RddV=RttV+fSXTN(32,64,fGETWORD(0,RssV));})
1477cf9345cSTaylor Simpson
1487cf9345cSTaylor SimpsonQ6INSN(A2_addsph,"Rdd32=add(Rss32,Rtt32):raw:hi",ATTRIBS(A_ARCHV3),
1497cf9345cSTaylor Simpson"Add",
1507cf9345cSTaylor Simpson{ RddV=RttV+fSXTN(32,64,fGETWORD(1,RssV));})
1517cf9345cSTaylor Simpson
1527cf9345cSTaylor SimpsonQ6INSN(A2_subp,"Rdd32=sub(Rtt32,Rss32)",ATTRIBS(),
1537cf9345cSTaylor Simpson"Sub",
1547cf9345cSTaylor Simpson{ RddV=RttV-RssV;})
1557cf9345cSTaylor Simpson
15657d352acSTaylor Simpson/* 64-bit with carry */
15757d352acSTaylor Simpson
15857d352acSTaylor SimpsonQ6INSN(A4_addp_c,"Rdd32=add(Rss32,Rtt32,Px4):carry",ATTRIBS(),"Add with Carry",
15957d352acSTaylor Simpson{
16057d352acSTaylor Simpson  RddV = RssV + RttV + fLSBOLD(PxV);
16157d352acSTaylor Simpson  PxV = f8BITSOF(fCARRY_FROM_ADD(RssV,RttV,fLSBOLD(PxV)));
16257d352acSTaylor Simpson})
16357d352acSTaylor Simpson
16457d352acSTaylor SimpsonQ6INSN(A4_subp_c,"Rdd32=sub(Rss32,Rtt32,Px4):carry",ATTRIBS(),"Sub with Carry",
16557d352acSTaylor Simpson{
16657d352acSTaylor Simpson  RddV = RssV + ~RttV + fLSBOLD(PxV);
16757d352acSTaylor Simpson  PxV = f8BITSOF(fCARRY_FROM_ADD(RssV,~RttV,fLSBOLD(PxV)));
16857d352acSTaylor Simpson})
16957d352acSTaylor Simpson
17057d352acSTaylor Simpson
1717cf9345cSTaylor Simpson/* NEG and ABS */
1727cf9345cSTaylor Simpson
1737cf9345cSTaylor SimpsonQ6INSN(A2_negsat,"Rd32=neg(Rs32):sat",ATTRIBS(),
1747cf9345cSTaylor Simpson"Arithmetic negate register", { RdV = fSAT(-fCAST8s(RsV)); })
1757cf9345cSTaylor Simpson
1767cf9345cSTaylor SimpsonQ6INSN(A2_abs,"Rd32=abs(Rs32)",ATTRIBS(),
1777cf9345cSTaylor Simpson"Absolute Value register", { RdV = fABS(RsV); })
1787cf9345cSTaylor Simpson
1797cf9345cSTaylor SimpsonQ6INSN(A2_abssat,"Rd32=abs(Rs32):sat",ATTRIBS(),
1807cf9345cSTaylor Simpson"Arithmetic negate register", { RdV = fSAT(fABS(fCAST4_8s(RsV))); })
1817cf9345cSTaylor Simpson
1827cf9345cSTaylor SimpsonQ6INSN(A2_vconj,"Rdd32=vconj(Rss32):sat",ATTRIBS(A_ARCHV2),
1837cf9345cSTaylor Simpson"Vector Complex conjugate of Rss",
1847cf9345cSTaylor Simpson{  fSETHALF(1,RddV,fSATN(16,-fGETHALF(1,RssV)));
1857cf9345cSTaylor Simpson   fSETHALF(0,RddV,fGETHALF(0,RssV));
1867cf9345cSTaylor Simpson   fSETHALF(3,RddV,fSATN(16,-fGETHALF(3,RssV)));
1877cf9345cSTaylor Simpson   fSETHALF(2,RddV,fGETHALF(2,RssV));
1887cf9345cSTaylor Simpson})
1897cf9345cSTaylor Simpson
1907cf9345cSTaylor Simpson
1917cf9345cSTaylor Simpson/* 64-bit versions */
1927cf9345cSTaylor Simpson
1937cf9345cSTaylor SimpsonQ6INSN(A2_negp,"Rdd32=neg(Rss32)",ATTRIBS(),
1947cf9345cSTaylor Simpson"Arithmetic negate register", { RddV = -RssV; })
1957cf9345cSTaylor Simpson
1967cf9345cSTaylor SimpsonQ6INSN(A2_absp,"Rdd32=abs(Rss32)",ATTRIBS(),
1977cf9345cSTaylor Simpson"Absolute Value register", { RddV = fABS(RssV); })
1987cf9345cSTaylor Simpson
1997cf9345cSTaylor Simpson
2007cf9345cSTaylor Simpson/* MIN and MAX  R */
2017cf9345cSTaylor Simpson
2027cf9345cSTaylor SimpsonQ6INSN(A2_max,"Rd32=max(Rs32,Rt32)",ATTRIBS(),
2037cf9345cSTaylor Simpson"Maximum of two registers",
2047cf9345cSTaylor Simpson{ RdV = fMAX(RsV,RtV); })
2057cf9345cSTaylor Simpson
2067cf9345cSTaylor SimpsonQ6INSN(A2_maxu,"Rd32=maxu(Rs32,Rt32)",ATTRIBS(),
2077cf9345cSTaylor Simpson"Maximum of two registers (unsigned)",
2087cf9345cSTaylor Simpson{ RdV = fMAX(fCAST4u(RsV),fCAST4u(RtV)); })
2097cf9345cSTaylor Simpson
2107cf9345cSTaylor SimpsonQ6INSN(A2_min,"Rd32=min(Rt32,Rs32)",ATTRIBS(),
2117cf9345cSTaylor Simpson"Minimum of two registers",
2127cf9345cSTaylor Simpson{ RdV = fMIN(RtV,RsV); })
2137cf9345cSTaylor Simpson
2147cf9345cSTaylor SimpsonQ6INSN(A2_minu,"Rd32=minu(Rt32,Rs32)",ATTRIBS(),
2157cf9345cSTaylor Simpson"Minimum of two registers (unsigned)",
2167cf9345cSTaylor Simpson{ RdV = fMIN(fCAST4u(RtV),fCAST4u(RsV)); })
2177cf9345cSTaylor Simpson
2187cf9345cSTaylor Simpson/* MIN and MAX Pairs */
2197cf9345cSTaylor Simpson#if 1
2207cf9345cSTaylor SimpsonQ6INSN(A2_maxp,"Rdd32=max(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
2217cf9345cSTaylor Simpson"Maximum of two register pairs",
2227cf9345cSTaylor Simpson{ RddV = fMAX(RssV,RttV); })
2237cf9345cSTaylor Simpson
2247cf9345cSTaylor SimpsonQ6INSN(A2_maxup,"Rdd32=maxu(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
2257cf9345cSTaylor Simpson"Maximum of two register pairs (unsigned)",
2267cf9345cSTaylor Simpson{ RddV = fMAX(fCAST8u(RssV),fCAST8u(RttV)); })
2277cf9345cSTaylor Simpson
2287cf9345cSTaylor SimpsonQ6INSN(A2_minp,"Rdd32=min(Rtt32,Rss32)",ATTRIBS(A_ARCHV3),
2297cf9345cSTaylor Simpson"Minimum of two register pairs",
2307cf9345cSTaylor Simpson{ RddV = fMIN(RttV,RssV); })
2317cf9345cSTaylor Simpson
2327cf9345cSTaylor SimpsonQ6INSN(A2_minup,"Rdd32=minu(Rtt32,Rss32)",ATTRIBS(A_ARCHV3),
2337cf9345cSTaylor Simpson"Minimum of two register pairs (unsigned)",
2347cf9345cSTaylor Simpson{ RddV = fMIN(fCAST8u(RttV),fCAST8u(RssV)); })
2357cf9345cSTaylor Simpson#endif
2367cf9345cSTaylor Simpson
2377cf9345cSTaylor Simpson/**********************************************/
2387cf9345cSTaylor Simpson/* Register and Immediate Transfers           */
2397cf9345cSTaylor Simpson/**********************************************/
2407cf9345cSTaylor Simpson
2417cf9345cSTaylor SimpsonQ6INSN(A2_nop,"nop",ATTRIBS(A_IT_NOP),
2427cf9345cSTaylor Simpson"Nop (32-bit encoding)",
2437cf9345cSTaylor Simpson fHIDE( { }  ))
2447cf9345cSTaylor Simpson
2457cf9345cSTaylor Simpson
2467cf9345cSTaylor SimpsonQ6INSN(A4_ext,"immext(#u26:6)",ATTRIBS(A_IT_EXTENDER),
2477cf9345cSTaylor Simpson"This instruction carries the 26 most-significant immediate bits for the next instruction",
2487cf9345cSTaylor Simpson{ fHIDE(); })
2497cf9345cSTaylor Simpson
2507cf9345cSTaylor Simpson
2517cf9345cSTaylor SimpsonQ6INSN(A2_tfr,"Rd32=Rs32",ATTRIBS(),
2527cf9345cSTaylor Simpson"tfr register",{ RdV=RsV;})
2537cf9345cSTaylor Simpson
2547cf9345cSTaylor SimpsonQ6INSN(A2_tfrsi,"Rd32=#s16",ATTRIBS(),
2557cf9345cSTaylor Simpson"transfer signed immediate to register",{ fIMMEXT(siV); RdV=siV;})
2567cf9345cSTaylor Simpson
2577cf9345cSTaylor SimpsonQ6INSN(A2_sxtb,"Rd32=sxtb(Rs32)",ATTRIBS(),
2587cf9345cSTaylor Simpson"Sign extend byte", {RdV = fSXTN(8,32,RsV);})
2597cf9345cSTaylor Simpson
2607cf9345cSTaylor SimpsonQ6INSN(A2_zxth,"Rd32=zxth(Rs32)",ATTRIBS(),
2617cf9345cSTaylor Simpson"Zero extend half", {RdV = fZXTN(16,32,RsV);})
2627cf9345cSTaylor Simpson
2637cf9345cSTaylor SimpsonQ6INSN(A2_sxth,"Rd32=sxth(Rs32)",ATTRIBS(),
2647cf9345cSTaylor Simpson"Sign extend half", {RdV = fSXTN(16,32,RsV);})
2657cf9345cSTaylor Simpson
2667cf9345cSTaylor SimpsonQ6INSN(A2_combinew,"Rdd32=combine(Rs32,Rt32)",ATTRIBS(),
2677cf9345cSTaylor Simpson"Combine two words into a register pair",
2687cf9345cSTaylor Simpson{ fSETWORD(0,RddV,RtV);
2697cf9345cSTaylor Simpson  fSETWORD(1,RddV,RsV);
2707cf9345cSTaylor Simpson})
2717cf9345cSTaylor Simpson
2727cf9345cSTaylor SimpsonQ6INSN(A4_combineri,"Rdd32=combine(Rs32,#s8)",ATTRIBS(),
2737cf9345cSTaylor Simpson"Combine a word and an immediate into a register pair",
2747cf9345cSTaylor Simpson{ fIMMEXT(siV); fSETWORD(0,RddV,siV);
2757cf9345cSTaylor Simpson  fSETWORD(1,RddV,RsV);
2767cf9345cSTaylor Simpson})
2777cf9345cSTaylor Simpson
2787cf9345cSTaylor SimpsonQ6INSN(A4_combineir,"Rdd32=combine(#s8,Rs32)",ATTRIBS(),
2797cf9345cSTaylor Simpson"Combine a word and an immediate into a register pair",
2807cf9345cSTaylor Simpson{ fIMMEXT(siV); fSETWORD(0,RddV,RsV);
2817cf9345cSTaylor Simpson  fSETWORD(1,RddV,siV);
2827cf9345cSTaylor Simpson})
2837cf9345cSTaylor Simpson
2847cf9345cSTaylor Simpson
2857cf9345cSTaylor Simpson
2867cf9345cSTaylor SimpsonQ6INSN(A2_combineii,"Rdd32=combine(#s8,#S8)",ATTRIBS(A_ARCHV2),
2877cf9345cSTaylor Simpson"Set two small immediates",
2887cf9345cSTaylor Simpson{ fIMMEXT(siV); fSETWORD(0,RddV,SiV); fSETWORD(1,RddV,siV); })
2897cf9345cSTaylor Simpson
2907cf9345cSTaylor SimpsonQ6INSN(A4_combineii,"Rdd32=combine(#s8,#U6)",ATTRIBS(),"Set two small immediates",
2917cf9345cSTaylor Simpson{ fIMMEXT(UiV); fSETWORD(0,RddV,UiV); fSETWORD(1,RddV,siV); })
2927cf9345cSTaylor Simpson
2937cf9345cSTaylor Simpson
2947cf9345cSTaylor SimpsonQ6INSN(A2_combine_hh,"Rd32=combine(Rt.H32,Rs.H32)",ATTRIBS(),
295*6c67d98cSMichael Tokarev"Combine two halves into a register", {RdV = (fGETUHALF(1,RtV)<<16) | fGETUHALF(1,RsV);})
2967cf9345cSTaylor Simpson
2977cf9345cSTaylor SimpsonQ6INSN(A2_combine_hl,"Rd32=combine(Rt.H32,Rs.L32)",ATTRIBS(),
298*6c67d98cSMichael Tokarev"Combine two halves into a register", {RdV = (fGETUHALF(1,RtV)<<16) | fGETUHALF(0,RsV);})
2997cf9345cSTaylor Simpson
3007cf9345cSTaylor SimpsonQ6INSN(A2_combine_lh,"Rd32=combine(Rt.L32,Rs.H32)",ATTRIBS(),
301*6c67d98cSMichael Tokarev"Combine two halves into a register", {RdV = (fGETUHALF(0,RtV)<<16) | fGETUHALF(1,RsV);})
3027cf9345cSTaylor Simpson
3037cf9345cSTaylor SimpsonQ6INSN(A2_combine_ll,"Rd32=combine(Rt.L32,Rs.L32)",ATTRIBS(),
304*6c67d98cSMichael Tokarev"Combine two halves into a register", {RdV = (fGETUHALF(0,RtV)<<16) | fGETUHALF(0,RsV);})
3057cf9345cSTaylor Simpson
3067cf9345cSTaylor SimpsonQ6INSN(A2_tfril,"Rx.L32=#u16",ATTRIBS(),
3077cf9345cSTaylor Simpson"Set low 16-bits, leave upper 16 unchanged",{ fSETHALF(0,RxV,uiV);})
3087cf9345cSTaylor Simpson
3097cf9345cSTaylor SimpsonQ6INSN(A2_tfrih,"Rx.H32=#u16",ATTRIBS(),
3107cf9345cSTaylor Simpson"Set high 16-bits, leave low 16 unchanged",{ fSETHALF(1,RxV,uiV);})
3117cf9345cSTaylor Simpson
3127cf9345cSTaylor SimpsonQ6INSN(A2_tfrcrr,"Rd32=Cs32",ATTRIBS(),
3137cf9345cSTaylor Simpson"transfer control register to general register",{ RdV=CsV;})
3147cf9345cSTaylor Simpson
3157cf9345cSTaylor SimpsonQ6INSN(A2_tfrrcr,"Cd32=Rs32",ATTRIBS(),
3167cf9345cSTaylor Simpson"transfer general register to control register",{ CdV=RsV;})
3177cf9345cSTaylor Simpson
3187cf9345cSTaylor SimpsonQ6INSN(A4_tfrcpp,"Rdd32=Css32",ATTRIBS(),
3197cf9345cSTaylor Simpson"transfer control register to general register",{ RddV=CssV;})
3207cf9345cSTaylor Simpson
3217cf9345cSTaylor SimpsonQ6INSN(A4_tfrpcp,"Cdd32=Rss32",ATTRIBS(),
3227cf9345cSTaylor Simpson"transfer general register to control register",{ CddV=RssV;})
3237cf9345cSTaylor Simpson
3247cf9345cSTaylor Simpson
3257cf9345cSTaylor Simpson/**********************************************/
3267cf9345cSTaylor Simpson/* Logicals                                   */
3277cf9345cSTaylor Simpson/**********************************************/
3287cf9345cSTaylor Simpson
3297cf9345cSTaylor SimpsonQ6INSN(A2_and,"Rd32=and(Rs32,Rt32)",ATTRIBS(),
3307cf9345cSTaylor Simpson"logical AND",{ RdV=RsV&RtV;})
3317cf9345cSTaylor Simpson
3327cf9345cSTaylor SimpsonQ6INSN(A2_or,"Rd32=or(Rs32,Rt32)",ATTRIBS(),
3337cf9345cSTaylor Simpson"logical OR",{ RdV=RsV|RtV;})
3347cf9345cSTaylor Simpson
3357cf9345cSTaylor SimpsonQ6INSN(A2_xor,"Rd32=xor(Rs32,Rt32)",ATTRIBS(),
3367cf9345cSTaylor Simpson"logical XOR",{ RdV=RsV^RtV;})
3377cf9345cSTaylor Simpson
3387cf9345cSTaylor SimpsonQ6INSN(M2_xor_xacc,"Rx32^=xor(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
3397cf9345cSTaylor Simpson"logical XOR with XOR accumulation",{ RxV^=RsV^RtV;})
3407cf9345cSTaylor Simpson
3417cf9345cSTaylor SimpsonQ6INSN(M4_xor_xacc,"Rxx32^=xor(Rss32,Rtt32)",,
3427cf9345cSTaylor Simpson"logical XOR with XOR accumulation",{ RxxV^=RssV^RttV;})
3437cf9345cSTaylor Simpson
3447cf9345cSTaylor Simpson
3457cf9345cSTaylor Simpson
3467cf9345cSTaylor SimpsonQ6INSN(A4_andn,"Rd32=and(Rt32,~Rs32)",,
3477cf9345cSTaylor Simpson"And-Not", { RdV = (RtV & ~RsV); })
3487cf9345cSTaylor Simpson
3497cf9345cSTaylor SimpsonQ6INSN(A4_orn,"Rd32=or(Rt32,~Rs32)",,
3507cf9345cSTaylor Simpson"Or-Not", { RdV = (RtV | ~RsV); })
3517cf9345cSTaylor Simpson
3527cf9345cSTaylor Simpson
3537cf9345cSTaylor SimpsonQ6INSN(A4_andnp,"Rdd32=and(Rtt32,~Rss32)",,
3547cf9345cSTaylor Simpson"And-Not", { RddV = (RttV & ~RssV); })
3557cf9345cSTaylor Simpson
3567cf9345cSTaylor SimpsonQ6INSN(A4_ornp,"Rdd32=or(Rtt32,~Rss32)",,
3577cf9345cSTaylor Simpson"Or-Not", { RddV = (RttV | ~RssV); })
3587cf9345cSTaylor Simpson
3597cf9345cSTaylor Simpson
3607cf9345cSTaylor Simpson
3617cf9345cSTaylor Simpson
3627cf9345cSTaylor Simpson/********************/
3637cf9345cSTaylor Simpson/* Compound add-add */
3647cf9345cSTaylor Simpson/********************/
3657cf9345cSTaylor Simpson
3667cf9345cSTaylor SimpsonQ6INSN(S4_addaddi,"Rd32=add(Rs32,add(Ru32,#s6))",ATTRIBS(),
3677cf9345cSTaylor Simpson        "3-input add",
3687cf9345cSTaylor Simpson        { RdV = RsV + RuV + fIMMEXT(siV); })
3697cf9345cSTaylor Simpson
3707cf9345cSTaylor Simpson
3717cf9345cSTaylor SimpsonQ6INSN(S4_subaddi,"Rd32=add(Rs32,sub(#s6,Ru32))",ATTRIBS(),
3727cf9345cSTaylor Simpson        "3-input sub",
3737cf9345cSTaylor Simpson        { RdV = RsV - RuV + fIMMEXT(siV); })
3747cf9345cSTaylor Simpson
3757cf9345cSTaylor Simpson
3767cf9345cSTaylor Simpson
3777cf9345cSTaylor Simpson/****************************/
3787cf9345cSTaylor Simpson/* Compound logical-logical */
3797cf9345cSTaylor Simpson/****************************/
3807cf9345cSTaylor Simpson
3817cf9345cSTaylor SimpsonQ6INSN(M4_and_and,"Rx32&=and(Rs32,Rt32)",ATTRIBS(),
3827cf9345cSTaylor Simpson"Compound And-And", { RxV &= (RsV & RtV); })
3837cf9345cSTaylor Simpson
3847cf9345cSTaylor SimpsonQ6INSN(M4_and_andn,"Rx32&=and(Rs32,~Rt32)",ATTRIBS(),
3857cf9345cSTaylor Simpson"Compound And-Andn", { RxV &= (RsV & ~RtV); })
3867cf9345cSTaylor Simpson
3877cf9345cSTaylor SimpsonQ6INSN(M4_and_or,"Rx32&=or(Rs32,Rt32)",ATTRIBS(),
3887cf9345cSTaylor Simpson"Compound And-Or", { RxV &= (RsV | RtV); })
3897cf9345cSTaylor Simpson
3907cf9345cSTaylor SimpsonQ6INSN(M4_and_xor,"Rx32&=xor(Rs32,Rt32)",ATTRIBS(),
3917cf9345cSTaylor Simpson"Compound And-xor", { RxV &= (RsV ^ RtV); })
3927cf9345cSTaylor Simpson
3937cf9345cSTaylor Simpson
3947cf9345cSTaylor Simpson
3957cf9345cSTaylor SimpsonQ6INSN(M4_or_and,"Rx32|=and(Rs32,Rt32)",ATTRIBS(),
3967cf9345cSTaylor Simpson"Compound Or-And", { RxV |= (RsV & RtV); })
3977cf9345cSTaylor Simpson
3987cf9345cSTaylor SimpsonQ6INSN(M4_or_andn,"Rx32|=and(Rs32,~Rt32)",ATTRIBS(),
3997cf9345cSTaylor Simpson"Compound Or-AndN", { RxV |= (RsV & ~RtV); })
4007cf9345cSTaylor Simpson
4017cf9345cSTaylor SimpsonQ6INSN(M4_or_or,"Rx32|=or(Rs32,Rt32)",ATTRIBS(),
4027cf9345cSTaylor Simpson"Compound Or-Or", { RxV |= (RsV | RtV); })
4037cf9345cSTaylor Simpson
4047cf9345cSTaylor SimpsonQ6INSN(M4_or_xor,"Rx32|=xor(Rs32,Rt32)",ATTRIBS(),
4057cf9345cSTaylor Simpson"Compound Or-xor", { RxV |= (RsV ^ RtV); })
4067cf9345cSTaylor Simpson
4077cf9345cSTaylor Simpson
4087cf9345cSTaylor SimpsonQ6INSN(S4_or_andix,"Rx32=or(Ru32,and(Rx32,#s10))",ATTRIBS(),
4097cf9345cSTaylor Simpson"Compound Or-And", { RxV = RuV | (RxV & fIMMEXT(siV)); })
4107cf9345cSTaylor Simpson
4117cf9345cSTaylor SimpsonQ6INSN(S4_or_andi,"Rx32|=and(Rs32,#s10)",ATTRIBS(),
4127cf9345cSTaylor Simpson"Compound Or-And", { RxV = RxV | (RsV & fIMMEXT(siV)); })
4137cf9345cSTaylor Simpson
4147cf9345cSTaylor SimpsonQ6INSN(S4_or_ori,"Rx32|=or(Rs32,#s10)",ATTRIBS(),
4157cf9345cSTaylor Simpson"Compound Or-And", { RxV = RxV | (RsV | fIMMEXT(siV)); })
4167cf9345cSTaylor Simpson
4177cf9345cSTaylor Simpson
4187cf9345cSTaylor Simpson
4197cf9345cSTaylor Simpson
4207cf9345cSTaylor SimpsonQ6INSN(M4_xor_and,"Rx32^=and(Rs32,Rt32)",ATTRIBS(),
4217cf9345cSTaylor Simpson"Compound Xor-And", { RxV ^= (RsV & RtV); })
4227cf9345cSTaylor Simpson
4237cf9345cSTaylor SimpsonQ6INSN(M4_xor_or,"Rx32^=or(Rs32,Rt32)",ATTRIBS(),
4247cf9345cSTaylor Simpson"Compound Xor-Or", { RxV ^= (RsV | RtV); })
4257cf9345cSTaylor Simpson
4267cf9345cSTaylor SimpsonQ6INSN(M4_xor_andn,"Rx32^=and(Rs32,~Rt32)",ATTRIBS(),
4277cf9345cSTaylor Simpson"Compound Xor-And", { RxV ^= (RsV & ~RtV); })
4287cf9345cSTaylor Simpson
4297cf9345cSTaylor Simpson
4307cf9345cSTaylor Simpson
4317cf9345cSTaylor Simpson
4327cf9345cSTaylor Simpson
4337cf9345cSTaylor Simpson
4347cf9345cSTaylor SimpsonQ6INSN(A2_subri,"Rd32=sub(#s10,Rs32)",ATTRIBS(A_ARCHV2),
4357cf9345cSTaylor Simpson"Subtract register from immediate",{ fIMMEXT(siV); RdV=siV-RsV;})
4367cf9345cSTaylor Simpson
4377cf9345cSTaylor SimpsonQ6INSN(A2_andir,"Rd32=and(Rs32,#s10)",ATTRIBS(A_ARCHV2),
4387cf9345cSTaylor Simpson"logical AND with immediate",{ fIMMEXT(siV); RdV=RsV&siV;})
4397cf9345cSTaylor Simpson
4407cf9345cSTaylor SimpsonQ6INSN(A2_orir,"Rd32=or(Rs32,#s10)",ATTRIBS(A_ARCHV2),
4417cf9345cSTaylor Simpson"logical OR with immediate",{ fIMMEXT(siV); RdV=RsV|siV;})
4427cf9345cSTaylor Simpson
4437cf9345cSTaylor Simpson
4447cf9345cSTaylor Simpson
4457cf9345cSTaylor Simpson
4467cf9345cSTaylor SimpsonQ6INSN(A2_andp,"Rdd32=and(Rss32,Rtt32)",ATTRIBS(),
4477cf9345cSTaylor Simpson"logical AND pair",{ RddV=RssV&RttV;})
4487cf9345cSTaylor Simpson
4497cf9345cSTaylor SimpsonQ6INSN(A2_orp,"Rdd32=or(Rss32,Rtt32)",ATTRIBS(),
4507cf9345cSTaylor Simpson"logical OR pair",{ RddV=RssV|RttV;})
4517cf9345cSTaylor Simpson
4527cf9345cSTaylor SimpsonQ6INSN(A2_xorp,"Rdd32=xor(Rss32,Rtt32)",ATTRIBS(),
4537cf9345cSTaylor Simpson"logical eXclusive OR pair",{ RddV=RssV^RttV;})
4547cf9345cSTaylor Simpson
4557cf9345cSTaylor SimpsonQ6INSN(A2_notp,"Rdd32=not(Rss32)",ATTRIBS(),
4567cf9345cSTaylor Simpson"logical NOT pair",{ RddV=~RssV;})
4577cf9345cSTaylor Simpson
4587cf9345cSTaylor SimpsonQ6INSN(A2_sxtw,"Rdd32=sxtw(Rs32)",ATTRIBS(),
4597cf9345cSTaylor Simpson"Sign extend 32-bit word to 64-bit pair",
4607cf9345cSTaylor Simpson{ RddV = fCAST4_8s(RsV); })
4617cf9345cSTaylor Simpson
4627cf9345cSTaylor SimpsonQ6INSN(A2_sat,"Rd32=sat(Rss32)",ATTRIBS(),
4637cf9345cSTaylor Simpson"Saturate to 32-bit Signed",
4647cf9345cSTaylor Simpson{ RdV = fSAT(RssV); })
4657cf9345cSTaylor Simpson
4667cf9345cSTaylor SimpsonQ6INSN(A2_roundsat,"Rd32=round(Rss32):sat",ATTRIBS(),
4677cf9345cSTaylor Simpson"Round & Saturate to 32-bit Signed",
4687cf9345cSTaylor Simpson{ fHIDE(size8s_t tmp;) fADDSAT64(tmp,RssV,0x080000000ULL); RdV = fGETWORD(1,tmp); })
4697cf9345cSTaylor Simpson
4707cf9345cSTaylor SimpsonQ6INSN(A2_sath,"Rd32=sath(Rs32)",ATTRIBS(),
4717cf9345cSTaylor Simpson"Saturate to 16-bit Signed",
4727cf9345cSTaylor Simpson{ RdV = fSATH(RsV); })
4737cf9345cSTaylor Simpson
4747cf9345cSTaylor SimpsonQ6INSN(A2_satuh,"Rd32=satuh(Rs32)",ATTRIBS(),
4757cf9345cSTaylor Simpson"Saturate to 16-bit Unsigned",
4767cf9345cSTaylor Simpson{ RdV = fSATUH(RsV); })
4777cf9345cSTaylor Simpson
4787cf9345cSTaylor SimpsonQ6INSN(A2_satub,"Rd32=satub(Rs32)",ATTRIBS(),
4797cf9345cSTaylor Simpson"Saturate to 8-bit Unsigned",
4807cf9345cSTaylor Simpson{ RdV = fSATUB(RsV); })
4817cf9345cSTaylor Simpson
4827cf9345cSTaylor SimpsonQ6INSN(A2_satb,"Rd32=satb(Rs32)",ATTRIBS(A_ARCHV2),
4837cf9345cSTaylor Simpson"Saturate to 8-bit Signed",
4847cf9345cSTaylor Simpson{ RdV = fSATB(RsV); })
4857cf9345cSTaylor Simpson
4867cf9345cSTaylor Simpson/**********************************************/
4877cf9345cSTaylor Simpson/* Vector Add                                 */
4887cf9345cSTaylor Simpson/**********************************************/
4897cf9345cSTaylor Simpson
4907cf9345cSTaylor SimpsonQ6INSN(A2_vaddub,"Rdd32=vaddub(Rss32,Rtt32)",ATTRIBS(),
4917cf9345cSTaylor Simpson"Add vector of bytes",
4927cf9345cSTaylor Simpson{
4937cf9345cSTaylor Simpson        fHIDE(int i;)
4947cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
4957cf9345cSTaylor Simpson            fSETBYTE(i,RddV,(fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV)));
4967cf9345cSTaylor Simpson        }
4977cf9345cSTaylor Simpson})
4987cf9345cSTaylor Simpson
4997cf9345cSTaylor SimpsonQ6INSN(A2_vaddubs,"Rdd32=vaddub(Rss32,Rtt32):sat",ATTRIBS(),
5007cf9345cSTaylor Simpson"Add vector of bytes",
5017cf9345cSTaylor Simpson{
5027cf9345cSTaylor Simpson        fHIDE(int i;)
5037cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
5047cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fSATUN(8,fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV)));
5057cf9345cSTaylor Simpson        }
5067cf9345cSTaylor Simpson})
5077cf9345cSTaylor Simpson
5087cf9345cSTaylor SimpsonQ6INSN(A2_vaddh,"Rdd32=vaddh(Rss32,Rtt32)",ATTRIBS(),
5097cf9345cSTaylor Simpson"Add vector of half integers",
5107cf9345cSTaylor Simpson{
5117cf9345cSTaylor Simpson        fHIDE(int i;)
5127cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
5137cf9345cSTaylor Simpson            fSETHALF(i,RddV,fGETHALF(i,RssV)+fGETHALF(i,RttV));
5147cf9345cSTaylor Simpson        }
5157cf9345cSTaylor Simpson})
5167cf9345cSTaylor Simpson
5177cf9345cSTaylor SimpsonQ6INSN(A2_vaddhs,"Rdd32=vaddh(Rss32,Rtt32):sat",ATTRIBS(),
5187cf9345cSTaylor Simpson"Add vector of half integers with saturation",
5197cf9345cSTaylor Simpson{
5207cf9345cSTaylor Simpson        fHIDE(int i;)
5217cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
5227cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATN(16,fGETHALF(i,RssV)+fGETHALF(i,RttV)));
5237cf9345cSTaylor Simpson        }
5247cf9345cSTaylor Simpson})
5257cf9345cSTaylor Simpson
5267cf9345cSTaylor SimpsonQ6INSN(A2_vadduhs,"Rdd32=vadduh(Rss32,Rtt32):sat",ATTRIBS(),
5277cf9345cSTaylor Simpson"Add vector of unsigned half integers with saturation",
5287cf9345cSTaylor Simpson{
5297cf9345cSTaylor Simpson        fHIDE(int i;)
5307cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
5317cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATUN(16,fGETUHALF(i,RssV)+fGETUHALF(i,RttV)));
5327cf9345cSTaylor Simpson        }
5337cf9345cSTaylor Simpson})
5347cf9345cSTaylor Simpson
5357cf9345cSTaylor SimpsonQ6INSN(A5_vaddhubs,"Rd32=vaddhub(Rss32,Rtt32):sat",ATTRIBS(),
5367cf9345cSTaylor Simpson"Add vector of half integers with saturation and pack to unsigned bytes",
5377cf9345cSTaylor Simpson{
5387cf9345cSTaylor Simpson        fHIDE(int i;)
5397cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
5407cf9345cSTaylor Simpson            fSETBYTE(i,RdV,fSATUB(fGETHALF(i,RssV)+fGETHALF(i,RttV)));
5417cf9345cSTaylor Simpson        }
5427cf9345cSTaylor Simpson})
5437cf9345cSTaylor Simpson
5447cf9345cSTaylor SimpsonQ6INSN(A2_vaddw,"Rdd32=vaddw(Rss32,Rtt32)",ATTRIBS(),
5457cf9345cSTaylor Simpson"Add vector of words",
5467cf9345cSTaylor Simpson{
5477cf9345cSTaylor Simpson        fHIDE(int i;)
5487cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
5497cf9345cSTaylor Simpson            fSETWORD(i,RddV,fGETWORD(i,RssV)+fGETWORD(i,RttV));
5507cf9345cSTaylor Simpson        }
5517cf9345cSTaylor Simpson})
5527cf9345cSTaylor Simpson
5537cf9345cSTaylor SimpsonQ6INSN(A2_vaddws,"Rdd32=vaddw(Rss32,Rtt32):sat",ATTRIBS(),
5547cf9345cSTaylor Simpson"Add vector of words with saturation",
5557cf9345cSTaylor Simpson{
5567cf9345cSTaylor Simpson        fHIDE(int i;)
5577cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
5587cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSATN(32,fGETWORD(i,RssV)+fGETWORD(i,RttV)));
5597cf9345cSTaylor Simpson        }
5607cf9345cSTaylor Simpson})
5617cf9345cSTaylor Simpson
5627cf9345cSTaylor Simpson
5637cf9345cSTaylor Simpson
5647cf9345cSTaylor SimpsonQ6INSN(S4_vxaddsubw,"Rdd32=vxaddsubw(Rss32,Rtt32):sat",ATTRIBS(),
5657cf9345cSTaylor Simpson"Cross vector add-sub words with saturation",
5667cf9345cSTaylor Simpson{
5677cf9345cSTaylor Simpson        fSETWORD(0,RddV,fSAT(fGETWORD(0,RssV)+fGETWORD(1,RttV)));
5687cf9345cSTaylor Simpson        fSETWORD(1,RddV,fSAT(fGETWORD(1,RssV)-fGETWORD(0,RttV)));
5697cf9345cSTaylor Simpson})
5707cf9345cSTaylor SimpsonQ6INSN(S4_vxsubaddw,"Rdd32=vxsubaddw(Rss32,Rtt32):sat",ATTRIBS(),
5717cf9345cSTaylor Simpson"Cross vector sub-add words with saturation",
5727cf9345cSTaylor Simpson{
5737cf9345cSTaylor Simpson        fSETWORD(0,RddV,fSAT(fGETWORD(0,RssV)-fGETWORD(1,RttV)));
5747cf9345cSTaylor Simpson        fSETWORD(1,RddV,fSAT(fGETWORD(1,RssV)+fGETWORD(0,RttV)));
5757cf9345cSTaylor Simpson})
5767cf9345cSTaylor Simpson
5777cf9345cSTaylor Simpson
5787cf9345cSTaylor Simpson
5797cf9345cSTaylor SimpsonQ6INSN(S4_vxaddsubh,"Rdd32=vxaddsubh(Rss32,Rtt32):sat",ATTRIBS(),
5807cf9345cSTaylor Simpson"Cross vector add-sub halfwords with saturation",
5817cf9345cSTaylor Simpson{
5827cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH(fGETHALF(0,RssV)+fGETHALF(1,RttV)));
5837cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH(fGETHALF(1,RssV)-fGETHALF(0,RttV)));
5847cf9345cSTaylor Simpson
5857cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH(fGETHALF(2,RssV)+fGETHALF(3,RttV)));
5867cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH(fGETHALF(3,RssV)-fGETHALF(2,RttV)));
5877cf9345cSTaylor Simpson
5887cf9345cSTaylor Simpson})
5897cf9345cSTaylor SimpsonQ6INSN(S4_vxsubaddh,"Rdd32=vxsubaddh(Rss32,Rtt32):sat",ATTRIBS(),
5907cf9345cSTaylor Simpson"Cross vector sub-add halfwords with saturation",
5917cf9345cSTaylor Simpson{
5927cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH(fGETHALF(0,RssV)-fGETHALF(1,RttV)));
5937cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH(fGETHALF(1,RssV)+fGETHALF(0,RttV)));
5947cf9345cSTaylor Simpson
5957cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH(fGETHALF(2,RssV)-fGETHALF(3,RttV)));
5967cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH(fGETHALF(3,RssV)+fGETHALF(2,RttV)));
5977cf9345cSTaylor Simpson})
5987cf9345cSTaylor Simpson
5997cf9345cSTaylor Simpson
6007cf9345cSTaylor Simpson
6017cf9345cSTaylor Simpson
6027cf9345cSTaylor SimpsonQ6INSN(S4_vxaddsubhr,"Rdd32=vxaddsubh(Rss32,Rtt32):rnd:>>1:sat",ATTRIBS(),
6037cf9345cSTaylor Simpson"Cross vector add-sub halfwords with shift, round, and saturation",
6047cf9345cSTaylor Simpson{
6057cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH((fGETHALF(0,RssV)+fGETHALF(1,RttV)+1)>>1));
6067cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH((fGETHALF(1,RssV)-fGETHALF(0,RttV)+1)>>1));
6077cf9345cSTaylor Simpson
6087cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH((fGETHALF(2,RssV)+fGETHALF(3,RttV)+1)>>1));
6097cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH((fGETHALF(3,RssV)-fGETHALF(2,RttV)+1)>>1));
6107cf9345cSTaylor Simpson
6117cf9345cSTaylor Simpson})
6127cf9345cSTaylor SimpsonQ6INSN(S4_vxsubaddhr,"Rdd32=vxsubaddh(Rss32,Rtt32):rnd:>>1:sat",ATTRIBS(),
6137cf9345cSTaylor Simpson"Cross vector sub-add halfwords with shift, round, and saturation",
6147cf9345cSTaylor Simpson{
6157cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH((fGETHALF(0,RssV)-fGETHALF(1,RttV)+1)>>1));
6167cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH((fGETHALF(1,RssV)+fGETHALF(0,RttV)+1)>>1));
6177cf9345cSTaylor Simpson
6187cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH((fGETHALF(2,RssV)-fGETHALF(3,RttV)+1)>>1));
6197cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH((fGETHALF(3,RssV)+fGETHALF(2,RttV)+1)>>1));
6207cf9345cSTaylor Simpson})
6217cf9345cSTaylor Simpson
6227cf9345cSTaylor Simpson
6237cf9345cSTaylor Simpson
6247cf9345cSTaylor Simpson
6257cf9345cSTaylor Simpson
6267cf9345cSTaylor Simpson/**********************************************/
6277cf9345cSTaylor Simpson/* 1/2 Vector operations                      */
6287cf9345cSTaylor Simpson/**********************************************/
6297cf9345cSTaylor Simpson
6307cf9345cSTaylor Simpson
6317cf9345cSTaylor SimpsonQ6INSN(A2_svavgh,"Rd32=vavgh(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
6327cf9345cSTaylor Simpson"Avg vector of half integers",
6337cf9345cSTaylor Simpson{
6347cf9345cSTaylor Simpson        fHIDE(int i;)
6357cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6367cf9345cSTaylor Simpson            fSETHALF(i,RdV,((fGETHALF(i,RsV)+fGETHALF(i,RtV))>>1));
6377cf9345cSTaylor Simpson        }
6387cf9345cSTaylor Simpson})
6397cf9345cSTaylor Simpson
6407cf9345cSTaylor SimpsonQ6INSN(A2_svavghs,"Rd32=vavgh(Rs32,Rt32):rnd",ATTRIBS(A_ARCHV2),
6417cf9345cSTaylor Simpson"Avg vector of half integers with rounding",
6427cf9345cSTaylor Simpson{
6437cf9345cSTaylor Simpson        fHIDE(int i;)
6447cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6457cf9345cSTaylor Simpson            fSETHALF(i,RdV,((fGETHALF(i,RsV)+fGETHALF(i,RtV)+1)>>1));
6467cf9345cSTaylor Simpson        }
6477cf9345cSTaylor Simpson})
6487cf9345cSTaylor Simpson
6497cf9345cSTaylor Simpson
6507cf9345cSTaylor Simpson
6517cf9345cSTaylor SimpsonQ6INSN(A2_svnavgh,"Rd32=vnavgh(Rt32,Rs32)",ATTRIBS(A_ARCHV2),
6527cf9345cSTaylor Simpson"Avg vector of half integers",
6537cf9345cSTaylor Simpson{
6547cf9345cSTaylor Simpson        fHIDE(int i;)
6557cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6567cf9345cSTaylor Simpson            fSETHALF(i,RdV,((fGETHALF(i,RtV)-fGETHALF(i,RsV))>>1));
6577cf9345cSTaylor Simpson        }
6587cf9345cSTaylor Simpson})
6597cf9345cSTaylor Simpson
6607cf9345cSTaylor Simpson
6617cf9345cSTaylor SimpsonQ6INSN(A2_svaddh,"Rd32=vaddh(Rs32,Rt32)",ATTRIBS(),
6627cf9345cSTaylor Simpson"Add vector of half integers",
6637cf9345cSTaylor Simpson{
6647cf9345cSTaylor Simpson        fHIDE(int i;)
6657cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6667cf9345cSTaylor Simpson            fSETHALF(i,RdV,fGETHALF(i,RsV)+fGETHALF(i,RtV));
6677cf9345cSTaylor Simpson        }
6687cf9345cSTaylor Simpson})
6697cf9345cSTaylor Simpson
6707cf9345cSTaylor SimpsonQ6INSN(A2_svaddhs,"Rd32=vaddh(Rs32,Rt32):sat",ATTRIBS(),
6717cf9345cSTaylor Simpson"Add vector of half integers with saturation",
6727cf9345cSTaylor Simpson{
6737cf9345cSTaylor Simpson        fHIDE(int i;)
6747cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6757cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATN(16,fGETHALF(i,RsV)+fGETHALF(i,RtV)));
6767cf9345cSTaylor Simpson        }
6777cf9345cSTaylor Simpson})
6787cf9345cSTaylor Simpson
6797cf9345cSTaylor SimpsonQ6INSN(A2_svadduhs,"Rd32=vadduh(Rs32,Rt32):sat",ATTRIBS(),
6807cf9345cSTaylor Simpson"Add vector of unsigned half integers with saturation",
6817cf9345cSTaylor Simpson{
6827cf9345cSTaylor Simpson        fHIDE(int i;)
6837cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6847cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATUN(16,fGETUHALF(i,RsV)+fGETUHALF(i,RtV)));
6857cf9345cSTaylor Simpson        }
6867cf9345cSTaylor Simpson})
6877cf9345cSTaylor Simpson
6887cf9345cSTaylor Simpson
6897cf9345cSTaylor SimpsonQ6INSN(A2_svsubh,"Rd32=vsubh(Rt32,Rs32)",ATTRIBS(),
6907cf9345cSTaylor Simpson"Sub vector of half integers",
6917cf9345cSTaylor Simpson{
6927cf9345cSTaylor Simpson        fHIDE(int i;)
6937cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6947cf9345cSTaylor Simpson            fSETHALF(i,RdV,fGETHALF(i,RtV)-fGETHALF(i,RsV));
6957cf9345cSTaylor Simpson        }
6967cf9345cSTaylor Simpson})
6977cf9345cSTaylor Simpson
6987cf9345cSTaylor SimpsonQ6INSN(A2_svsubhs,"Rd32=vsubh(Rt32,Rs32):sat",ATTRIBS(),
6997cf9345cSTaylor Simpson"Sub vector of half integers with saturation",
7007cf9345cSTaylor Simpson{
7017cf9345cSTaylor Simpson        fHIDE(int i;)
7027cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
7037cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATN(16,fGETHALF(i,RtV)-fGETHALF(i,RsV)));
7047cf9345cSTaylor Simpson        }
7057cf9345cSTaylor Simpson})
7067cf9345cSTaylor Simpson
7077cf9345cSTaylor SimpsonQ6INSN(A2_svsubuhs,"Rd32=vsubuh(Rt32,Rs32):sat",ATTRIBS(),
7087cf9345cSTaylor Simpson"Sub vector of unsigned half integers with saturation",
7097cf9345cSTaylor Simpson{
7107cf9345cSTaylor Simpson        fHIDE(int i;)
7117cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
7127cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATUN(16,fGETUHALF(i,RtV)-fGETUHALF(i,RsV)));
7137cf9345cSTaylor Simpson        }
7147cf9345cSTaylor Simpson})
7157cf9345cSTaylor Simpson
7167cf9345cSTaylor Simpson
7177cf9345cSTaylor Simpson
7187cf9345cSTaylor Simpson
7197cf9345cSTaylor Simpson/**********************************************/
7207cf9345cSTaylor Simpson/* Vector Reduce Add                          */
7217cf9345cSTaylor Simpson/**********************************************/
7227cf9345cSTaylor Simpson
7237cf9345cSTaylor SimpsonQ6INSN(A2_vraddub,"Rdd32=vraddub(Rss32,Rtt32)",ATTRIBS(),
7247cf9345cSTaylor Simpson"Sum: two vectors of unsigned bytes",
7257cf9345cSTaylor Simpson{
7267cf9345cSTaylor Simpson        fHIDE(int i;)
7277cf9345cSTaylor Simpson        RddV = 0;
7287cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
7297cf9345cSTaylor Simpson            fSETWORD(0,RddV,(fGETWORD(0,RddV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
7307cf9345cSTaylor Simpson        }
7317cf9345cSTaylor Simpson        for (i=4;i<8;i++) {
7327cf9345cSTaylor Simpson            fSETWORD(1,RddV,(fGETWORD(1,RddV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
7337cf9345cSTaylor Simpson        }
7347cf9345cSTaylor Simpson})
7357cf9345cSTaylor Simpson
7367cf9345cSTaylor SimpsonQ6INSN(A2_vraddub_acc,"Rxx32+=vraddub(Rss32,Rtt32)",ATTRIBS(),
7377cf9345cSTaylor Simpson"Sum: two vectors of unsigned bytes",
7387cf9345cSTaylor Simpson{
7397cf9345cSTaylor Simpson        fHIDE(int i;)
7407cf9345cSTaylor Simpson        for (i = 0; i < 4; i++) {
7417cf9345cSTaylor Simpson            fSETWORD(0,RxxV,(fGETWORD(0,RxxV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
7427cf9345cSTaylor Simpson        }
7437cf9345cSTaylor Simpson        for (i = 4; i < 8; i++) {
7447cf9345cSTaylor Simpson            fSETWORD(1,RxxV,(fGETWORD(1,RxxV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
7457cf9345cSTaylor Simpson        }
7467cf9345cSTaylor Simpson})
7477cf9345cSTaylor Simpson
7487cf9345cSTaylor Simpson
7497cf9345cSTaylor Simpson
7507cf9345cSTaylor SimpsonQ6INSN(M2_vraddh,"Rd32=vraddh(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
7517cf9345cSTaylor Simpson"Sum: two vectors of halves",
7527cf9345cSTaylor Simpson{
7537cf9345cSTaylor Simpson        fHIDE(int i;)
7547cf9345cSTaylor Simpson        RdV = 0;
7557cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
7567cf9345cSTaylor Simpson            RdV += (fGETHALF(i,RssV)+fGETHALF(i,RttV));
7577cf9345cSTaylor Simpson        }
7587cf9345cSTaylor Simpson})
7597cf9345cSTaylor Simpson
7607cf9345cSTaylor SimpsonQ6INSN(M2_vradduh,"Rd32=vradduh(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
7617cf9345cSTaylor Simpson"Sum: two vectors of unsigned halves",
7627cf9345cSTaylor Simpson{
7637cf9345cSTaylor Simpson        fHIDE(int i;)
7647cf9345cSTaylor Simpson        RdV = 0;
7657cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
7667cf9345cSTaylor Simpson            RdV += (fGETUHALF(i,RssV)+fGETUHALF(i,RttV));
7677cf9345cSTaylor Simpson        }
7687cf9345cSTaylor Simpson})
7697cf9345cSTaylor Simpson
7707cf9345cSTaylor Simpson/**********************************************/
7717cf9345cSTaylor Simpson/* Vector Sub                                 */
7727cf9345cSTaylor Simpson/**********************************************/
7737cf9345cSTaylor Simpson
7747cf9345cSTaylor SimpsonQ6INSN(A2_vsubub,"Rdd32=vsubub(Rtt32,Rss32)",ATTRIBS(),
7757cf9345cSTaylor Simpson"Sub vector of bytes",
7767cf9345cSTaylor Simpson{
7777cf9345cSTaylor Simpson        fHIDE(int i;)
7787cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
7797cf9345cSTaylor Simpson            fSETBYTE(i,RddV,(fGETUBYTE(i,RttV)-fGETUBYTE(i,RssV)));
7807cf9345cSTaylor Simpson        }
7817cf9345cSTaylor Simpson})
7827cf9345cSTaylor Simpson
7837cf9345cSTaylor SimpsonQ6INSN(A2_vsububs,"Rdd32=vsubub(Rtt32,Rss32):sat",ATTRIBS(),
7847cf9345cSTaylor Simpson"Sub vector of bytes",
7857cf9345cSTaylor Simpson{
7867cf9345cSTaylor Simpson        fHIDE(int i;)
7877cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
7887cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fSATUN(8,fGETUBYTE(i,RttV)-fGETUBYTE(i,RssV)));
7897cf9345cSTaylor Simpson        }
7907cf9345cSTaylor Simpson})
7917cf9345cSTaylor Simpson
7927cf9345cSTaylor SimpsonQ6INSN(A2_vsubh,"Rdd32=vsubh(Rtt32,Rss32)",ATTRIBS(),
7937cf9345cSTaylor Simpson"Sub vector of half integers",
7947cf9345cSTaylor Simpson{
7957cf9345cSTaylor Simpson        fHIDE(int i;)
7967cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
7977cf9345cSTaylor Simpson            fSETHALF(i,RddV,fGETHALF(i,RttV)-fGETHALF(i,RssV));
7987cf9345cSTaylor Simpson        }
7997cf9345cSTaylor Simpson})
8007cf9345cSTaylor Simpson
8017cf9345cSTaylor SimpsonQ6INSN(A2_vsubhs,"Rdd32=vsubh(Rtt32,Rss32):sat",ATTRIBS(),
8027cf9345cSTaylor Simpson"Sub vector of half integers with saturation",
8037cf9345cSTaylor Simpson{
8047cf9345cSTaylor Simpson        fHIDE(int i;)
8057cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
8067cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATN(16,fGETHALF(i,RttV)-fGETHALF(i,RssV)));
8077cf9345cSTaylor Simpson        }
8087cf9345cSTaylor Simpson})
8097cf9345cSTaylor Simpson
8107cf9345cSTaylor SimpsonQ6INSN(A2_vsubuhs,"Rdd32=vsubuh(Rtt32,Rss32):sat",ATTRIBS(),
8117cf9345cSTaylor Simpson"Sub vector of unsigned half integers with saturation",
8127cf9345cSTaylor Simpson{
8137cf9345cSTaylor Simpson        fHIDE(int i;)
8147cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
8157cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATUN(16,fGETUHALF(i,RttV)-fGETUHALF(i,RssV)));
8167cf9345cSTaylor Simpson        }
8177cf9345cSTaylor Simpson})
8187cf9345cSTaylor Simpson
8197cf9345cSTaylor SimpsonQ6INSN(A2_vsubw,"Rdd32=vsubw(Rtt32,Rss32)",ATTRIBS(),
8207cf9345cSTaylor Simpson"Sub vector of words",
8217cf9345cSTaylor Simpson{
8227cf9345cSTaylor Simpson        fHIDE(int i;)
8237cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
8247cf9345cSTaylor Simpson            fSETWORD(i,RddV,fGETWORD(i,RttV)-fGETWORD(i,RssV));
8257cf9345cSTaylor Simpson        }
8267cf9345cSTaylor Simpson})
8277cf9345cSTaylor Simpson
8287cf9345cSTaylor SimpsonQ6INSN(A2_vsubws,"Rdd32=vsubw(Rtt32,Rss32):sat",ATTRIBS(),
8297cf9345cSTaylor Simpson"Sub vector of words with saturation",
8307cf9345cSTaylor Simpson{
8317cf9345cSTaylor Simpson        fHIDE(int i;)
8327cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
8337cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSATN(32,fGETWORD(i,RttV)-fGETWORD(i,RssV)));
8347cf9345cSTaylor Simpson        }
8357cf9345cSTaylor Simpson})
8367cf9345cSTaylor Simpson
8377cf9345cSTaylor Simpson
8387cf9345cSTaylor Simpson
8397cf9345cSTaylor Simpson
8407cf9345cSTaylor Simpson/**********************************************/
8417cf9345cSTaylor Simpson/* Vector Abs                                 */
8427cf9345cSTaylor Simpson/**********************************************/
8437cf9345cSTaylor Simpson
8447cf9345cSTaylor SimpsonQ6INSN(A2_vabsh,"Rdd32=vabsh(Rss32)",ATTRIBS(),
8457cf9345cSTaylor Simpson"Negate vector of half integers",
8467cf9345cSTaylor Simpson{
8477cf9345cSTaylor Simpson        fHIDE(int i;)
8487cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
8497cf9345cSTaylor Simpson            fSETHALF(i,RddV,fABS(fGETHALF(i,RssV)));
8507cf9345cSTaylor Simpson        }
8517cf9345cSTaylor Simpson})
8527cf9345cSTaylor Simpson
8537cf9345cSTaylor SimpsonQ6INSN(A2_vabshsat,"Rdd32=vabsh(Rss32):sat",ATTRIBS(),
8547cf9345cSTaylor Simpson"Negate vector of half integers",
8557cf9345cSTaylor Simpson{
8567cf9345cSTaylor Simpson        fHIDE(int i;)
8577cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
8587cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATH(fABS(fGETHALF(i,RssV))));
8597cf9345cSTaylor Simpson        }
8607cf9345cSTaylor Simpson})
8617cf9345cSTaylor Simpson
8627cf9345cSTaylor SimpsonQ6INSN(A2_vabsw,"Rdd32=vabsw(Rss32)",ATTRIBS(),
8637cf9345cSTaylor Simpson"Absolute Value vector of words",
8647cf9345cSTaylor Simpson{
8657cf9345cSTaylor Simpson        fHIDE(int i;)
8667cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
8677cf9345cSTaylor Simpson            fSETWORD(i,RddV,fABS(fGETWORD(i,RssV)));
8687cf9345cSTaylor Simpson        }
8697cf9345cSTaylor Simpson})
8707cf9345cSTaylor Simpson
8717cf9345cSTaylor SimpsonQ6INSN(A2_vabswsat,"Rdd32=vabsw(Rss32):sat",ATTRIBS(),
8727cf9345cSTaylor Simpson"Absolute Value vector of words",
8737cf9345cSTaylor Simpson{
8747cf9345cSTaylor Simpson        fHIDE(int i;)
8757cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
8767cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSAT(fABS(fGETWORD(i,RssV))));
8777cf9345cSTaylor Simpson        }
8787cf9345cSTaylor Simpson})
8797cf9345cSTaylor Simpson
8807cf9345cSTaylor Simpson/**********************************************/
8817cf9345cSTaylor Simpson/* Vector SAD                                 */
8827cf9345cSTaylor Simpson/**********************************************/
8837cf9345cSTaylor Simpson
8847cf9345cSTaylor Simpson
8857cf9345cSTaylor SimpsonQ6INSN(M2_vabsdiffw,"Rdd32=vabsdiffw(Rtt32,Rss32)",ATTRIBS(A_ARCHV2),
8867cf9345cSTaylor Simpson"Absolute Differences: vector of words",
8877cf9345cSTaylor Simpson{
8887cf9345cSTaylor Simpson        fHIDE(int i;)
8897cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
8907cf9345cSTaylor Simpson            fSETWORD(i,RddV,fABS(fGETWORD(i,RttV) - fGETWORD(i,RssV)));
8917cf9345cSTaylor Simpson        }
8927cf9345cSTaylor Simpson})
8937cf9345cSTaylor Simpson
8947cf9345cSTaylor SimpsonQ6INSN(M2_vabsdiffh,"Rdd32=vabsdiffh(Rtt32,Rss32)",ATTRIBS(A_ARCHV2),
8957cf9345cSTaylor Simpson"Absolute Differences: vector of halfwords",
8967cf9345cSTaylor Simpson{
8977cf9345cSTaylor Simpson        fHIDE(int i;)
8987cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
8997cf9345cSTaylor Simpson            fSETHALF(i,RddV,fABS(fGETHALF(i,RttV) - fGETHALF(i,RssV)));
9007cf9345cSTaylor Simpson        }
9017cf9345cSTaylor Simpson})
9027cf9345cSTaylor Simpson
9037cf9345cSTaylor SimpsonQ6INSN(M6_vabsdiffb,"Rdd32=vabsdiffb(Rtt32,Rss32)",ATTRIBS(),
9047cf9345cSTaylor Simpson"Absolute Differences: vector of halfwords",
9057cf9345cSTaylor Simpson{
9067cf9345cSTaylor Simpson        fHIDE(int i;)
9077cf9345cSTaylor Simpson        for (i=0;i<8;i++) {
9087cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fABS(fGETBYTE(i,RttV) - fGETBYTE(i,RssV)));
9097cf9345cSTaylor Simpson        }
9107cf9345cSTaylor Simpson})
9117cf9345cSTaylor Simpson
9127cf9345cSTaylor SimpsonQ6INSN(M6_vabsdiffub,"Rdd32=vabsdiffub(Rtt32,Rss32)",ATTRIBS(),
9137cf9345cSTaylor Simpson"Absolute Differences: vector of halfwords",
9147cf9345cSTaylor Simpson{
9157cf9345cSTaylor Simpson        fHIDE(int i;)
9167cf9345cSTaylor Simpson        for (i=0;i<8;i++) {
9177cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fABS(fGETUBYTE(i,RttV) - fGETUBYTE(i,RssV)));
9187cf9345cSTaylor Simpson        }
9197cf9345cSTaylor Simpson})
9207cf9345cSTaylor Simpson
9217cf9345cSTaylor Simpson
9227cf9345cSTaylor Simpson
9237cf9345cSTaylor SimpsonQ6INSN(A2_vrsadub,"Rdd32=vrsadub(Rss32,Rtt32)",ATTRIBS(),
9247cf9345cSTaylor Simpson"Sum of Absolute Differences: vector of unsigned bytes",
9257cf9345cSTaylor Simpson{
9267cf9345cSTaylor Simpson        fHIDE(int i;)
9277cf9345cSTaylor Simpson        RddV = 0;
9287cf9345cSTaylor Simpson        for (i = 0; i < 4; i++) {
9297cf9345cSTaylor Simpson            fSETWORD(0,RddV,(fGETWORD(0,RddV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
9307cf9345cSTaylor Simpson        }
9317cf9345cSTaylor Simpson        for (i = 4; i < 8; i++) {
9327cf9345cSTaylor Simpson            fSETWORD(1,RddV,(fGETWORD(1,RddV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
9337cf9345cSTaylor Simpson        }
9347cf9345cSTaylor Simpson})
9357cf9345cSTaylor Simpson
9367cf9345cSTaylor SimpsonQ6INSN(A2_vrsadub_acc,"Rxx32+=vrsadub(Rss32,Rtt32)",ATTRIBS(),
9377cf9345cSTaylor Simpson"Sum of Absolute Differences: vector of unsigned bytes",
9387cf9345cSTaylor Simpson{
9397cf9345cSTaylor Simpson        fHIDE(int i;)
9407cf9345cSTaylor Simpson        for (i = 0; i < 4; i++) {
9417cf9345cSTaylor Simpson            fSETWORD(0,RxxV,(fGETWORD(0,RxxV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
9427cf9345cSTaylor Simpson        }
9437cf9345cSTaylor Simpson        for (i = 4; i < 8; i++) {
9447cf9345cSTaylor Simpson            fSETWORD(1,RxxV,(fGETWORD(1,RxxV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
9457cf9345cSTaylor Simpson        }
9467cf9345cSTaylor Simpson})
9477cf9345cSTaylor Simpson
9487cf9345cSTaylor Simpson
9497cf9345cSTaylor Simpson/**********************************************/
9507cf9345cSTaylor Simpson/* Vector Average                             */
9517cf9345cSTaylor Simpson/**********************************************/
9527cf9345cSTaylor Simpson
9537cf9345cSTaylor SimpsonQ6INSN(A2_vavgub,"Rdd32=vavgub(Rss32,Rtt32)",ATTRIBS(),
9547cf9345cSTaylor Simpson"Average vector of unsigned bytes",
9557cf9345cSTaylor Simpson{
9567cf9345cSTaylor Simpson        fHIDE(int i;)
9577cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
9587cf9345cSTaylor Simpson            fSETBYTE(i,RddV,((fGETUBYTE(i,RssV) + fGETUBYTE(i,RttV))>>1));
9597cf9345cSTaylor Simpson        }
9607cf9345cSTaylor Simpson})
9617cf9345cSTaylor Simpson
9627cf9345cSTaylor SimpsonQ6INSN(A2_vavguh,"Rdd32=vavguh(Rss32,Rtt32)",ATTRIBS(),
9637cf9345cSTaylor Simpson"Average vector of unsigned halfwords",
9647cf9345cSTaylor Simpson{
9657cf9345cSTaylor Simpson        fHIDE(int i;)
9667cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
9677cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETUHALF(i,RssV)+fGETUHALF(i,RttV))>>1);
9687cf9345cSTaylor Simpson        }
9697cf9345cSTaylor Simpson})
9707cf9345cSTaylor Simpson
9717cf9345cSTaylor SimpsonQ6INSN(A2_vavgh,"Rdd32=vavgh(Rss32,Rtt32)",ATTRIBS(),
9727cf9345cSTaylor Simpson"Average vector of halfwords",
9737cf9345cSTaylor Simpson{
9747cf9345cSTaylor Simpson        fHIDE(int i;)
9757cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
9767cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETHALF(i,RssV)+fGETHALF(i,RttV))>>1);
9777cf9345cSTaylor Simpson        }
9787cf9345cSTaylor Simpson})
9797cf9345cSTaylor Simpson
9807cf9345cSTaylor SimpsonQ6INSN(A2_vnavgh,"Rdd32=vnavgh(Rtt32,Rss32)",ATTRIBS(),
9817cf9345cSTaylor Simpson"Negative Average vector of halfwords",
9827cf9345cSTaylor Simpson{
9837cf9345cSTaylor Simpson        fHIDE(int i;)
9847cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
9857cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETHALF(i,RttV)-fGETHALF(i,RssV))>>1);
9867cf9345cSTaylor Simpson        }
9877cf9345cSTaylor Simpson})
9887cf9345cSTaylor Simpson
9897cf9345cSTaylor SimpsonQ6INSN(A2_vavgw,"Rdd32=vavgw(Rss32,Rtt32)",ATTRIBS(),
9907cf9345cSTaylor Simpson"Average vector of words",
9917cf9345cSTaylor Simpson{
9927cf9345cSTaylor Simpson        fHIDE(int i;)
9937cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
9947cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fSXTN(32,33,fGETWORD(i,RssV))+fSXTN(32,33,fGETWORD(i,RttV)))>>1);
9957cf9345cSTaylor Simpson        }
9967cf9345cSTaylor Simpson})
9977cf9345cSTaylor Simpson
9987cf9345cSTaylor SimpsonQ6INSN(A2_vnavgw,"Rdd32=vnavgw(Rtt32,Rss32)",ATTRIBS(A_ARCHV2),
9997cf9345cSTaylor Simpson"Average vector of words",
10007cf9345cSTaylor Simpson{
10017cf9345cSTaylor Simpson        fHIDE(int i;)
10027cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10037cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fSXTN(32,33,fGETWORD(i,RttV))-fSXTN(32,33,fGETWORD(i,RssV)))>>1);
10047cf9345cSTaylor Simpson        }
10057cf9345cSTaylor Simpson})
10067cf9345cSTaylor Simpson
10077cf9345cSTaylor SimpsonQ6INSN(A2_vavgwr,"Rdd32=vavgw(Rss32,Rtt32):rnd",ATTRIBS(),
10087cf9345cSTaylor Simpson"Average vector of words",
10097cf9345cSTaylor Simpson{
10107cf9345cSTaylor Simpson        fHIDE(int i;)
10117cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10127cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fSXTN(32,33,fGETWORD(i,RssV))+fSXTN(32,33,fGETWORD(i,RttV))+1)>>1);
10137cf9345cSTaylor Simpson        }
10147cf9345cSTaylor Simpson})
10157cf9345cSTaylor Simpson
10167cf9345cSTaylor SimpsonQ6INSN(A2_vnavgwr,"Rdd32=vnavgw(Rtt32,Rss32):rnd:sat",ATTRIBS(A_ARCHV2),
10177cf9345cSTaylor Simpson"Average vector of words",
10187cf9345cSTaylor Simpson{
10197cf9345cSTaylor Simpson        fHIDE(int i;)
10207cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10217cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSAT((fSXTN(32,33,fGETWORD(i,RttV))-fSXTN(32,33,fGETWORD(i,RssV))+1)>>1));
10227cf9345cSTaylor Simpson        }
10237cf9345cSTaylor Simpson})
10247cf9345cSTaylor Simpson
10257cf9345cSTaylor SimpsonQ6INSN(A2_vavgwcr,"Rdd32=vavgw(Rss32,Rtt32):crnd",ATTRIBS(A_ARCHV2),
10267cf9345cSTaylor Simpson"Average vector of words with convergent rounding",
10277cf9345cSTaylor Simpson{
10287cf9345cSTaylor Simpson        fHIDE(int i;)
10297cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10307cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fCRND(fSXTN(32,33,fGETWORD(i,RssV))+fSXTN(32,33,fGETWORD(i,RttV)))>>1));
10317cf9345cSTaylor Simpson        }
10327cf9345cSTaylor Simpson})
10337cf9345cSTaylor Simpson
10347cf9345cSTaylor SimpsonQ6INSN(A2_vnavgwcr,"Rdd32=vnavgw(Rtt32,Rss32):crnd:sat",ATTRIBS(A_ARCHV2),
10357cf9345cSTaylor Simpson"Average negative vector of words with convergent rounding",
10367cf9345cSTaylor Simpson{
10377cf9345cSTaylor Simpson        fHIDE(int i;)
10387cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10397cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSAT(fCRND(fSXTN(32,33,fGETWORD(i,RttV))-fSXTN(32,33,fGETWORD(i,RssV)))>>1));
10407cf9345cSTaylor Simpson        }
10417cf9345cSTaylor Simpson})
10427cf9345cSTaylor Simpson
10437cf9345cSTaylor SimpsonQ6INSN(A2_vavghcr,"Rdd32=vavgh(Rss32,Rtt32):crnd",ATTRIBS(A_ARCHV2),
10447cf9345cSTaylor Simpson"Average vector of halfwords with conv rounding",
10457cf9345cSTaylor Simpson{
10467cf9345cSTaylor Simpson        fHIDE(int i;)
10477cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
10487cf9345cSTaylor Simpson            fSETHALF(i,RddV,fCRND(fGETHALF(i,RssV)+fGETHALF(i,RttV))>>1);
10497cf9345cSTaylor Simpson        }
10507cf9345cSTaylor Simpson})
10517cf9345cSTaylor Simpson
10527cf9345cSTaylor SimpsonQ6INSN(A2_vnavghcr,"Rdd32=vnavgh(Rtt32,Rss32):crnd:sat",ATTRIBS(A_ARCHV2),
10537cf9345cSTaylor Simpson"Average negative vector of halfwords with conv rounding",
10547cf9345cSTaylor Simpson{
10557cf9345cSTaylor Simpson        fHIDE(int i;)
10567cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
10577cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATH(fCRND(fGETHALF(i,RttV)-fGETHALF(i,RssV))>>1));
10587cf9345cSTaylor Simpson        }
10597cf9345cSTaylor Simpson})
10607cf9345cSTaylor Simpson
10617cf9345cSTaylor Simpson
10627cf9345cSTaylor SimpsonQ6INSN(A2_vavguw,"Rdd32=vavguw(Rss32,Rtt32)",ATTRIBS(),
10637cf9345cSTaylor Simpson"Average vector of unsigned words",
10647cf9345cSTaylor Simpson{
10657cf9345cSTaylor Simpson        fHIDE(int i;)
10667cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10677cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fZXTN(32,33,fGETUWORD(i,RssV))+fZXTN(32,33,fGETUWORD(i,RttV)))>>1);
10687cf9345cSTaylor Simpson        }
10697cf9345cSTaylor Simpson})
10707cf9345cSTaylor Simpson
10717cf9345cSTaylor SimpsonQ6INSN(A2_vavguwr,"Rdd32=vavguw(Rss32,Rtt32):rnd",ATTRIBS(),
10727cf9345cSTaylor Simpson"Average vector of unsigned words",
10737cf9345cSTaylor Simpson{
10747cf9345cSTaylor Simpson        fHIDE(int i;)
10757cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10767cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fZXTN(32,33,fGETUWORD(i,RssV))+fZXTN(32,33,fGETUWORD(i,RttV))+1)>>1);
10777cf9345cSTaylor Simpson        }
10787cf9345cSTaylor Simpson})
10797cf9345cSTaylor Simpson
10807cf9345cSTaylor SimpsonQ6INSN(A2_vavgubr,"Rdd32=vavgub(Rss32,Rtt32):rnd",ATTRIBS(),
10817cf9345cSTaylor Simpson"Average vector of unsigned bytes",
10827cf9345cSTaylor Simpson{
10837cf9345cSTaylor Simpson        fHIDE(int i;)
10847cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
10857cf9345cSTaylor Simpson            fSETBYTE(i,RddV,((fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV)+1)>>1));
10867cf9345cSTaylor Simpson        }
10877cf9345cSTaylor Simpson})
10887cf9345cSTaylor Simpson
10897cf9345cSTaylor SimpsonQ6INSN(A2_vavguhr,"Rdd32=vavguh(Rss32,Rtt32):rnd",ATTRIBS(),
10907cf9345cSTaylor Simpson"Average vector of unsigned halfwords with rounding",
10917cf9345cSTaylor Simpson{
10927cf9345cSTaylor Simpson        fHIDE(int i;)
10937cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
10947cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETUHALF(i,RssV)+fGETUHALF(i,RttV)+1)>>1);
10957cf9345cSTaylor Simpson        }
10967cf9345cSTaylor Simpson})
10977cf9345cSTaylor Simpson
10987cf9345cSTaylor SimpsonQ6INSN(A2_vavghr,"Rdd32=vavgh(Rss32,Rtt32):rnd",ATTRIBS(),
10997cf9345cSTaylor Simpson"Average vector of halfwords with rounding",
11007cf9345cSTaylor Simpson{
11017cf9345cSTaylor Simpson        fHIDE(int i;)
11027cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
11037cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETHALF(i,RssV)+fGETHALF(i,RttV)+1)>>1);
11047cf9345cSTaylor Simpson        }
11057cf9345cSTaylor Simpson})
11067cf9345cSTaylor Simpson
11077cf9345cSTaylor SimpsonQ6INSN(A2_vnavghr,"Rdd32=vnavgh(Rtt32,Rss32):rnd:sat",ATTRIBS(A_ARCHV2),
11087cf9345cSTaylor Simpson"Negative Average vector of halfwords with rounding",
11097cf9345cSTaylor Simpson{
11107cf9345cSTaylor Simpson        fHIDE(int i;)
11117cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
11127cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATH((fGETHALF(i,RttV)-fGETHALF(i,RssV)+1)>>1));
11137cf9345cSTaylor Simpson        }
11147cf9345cSTaylor Simpson})
11157cf9345cSTaylor Simpson
11167cf9345cSTaylor Simpson
11177cf9345cSTaylor Simpson/* Rounding Instruction */
11187cf9345cSTaylor Simpson
11197cf9345cSTaylor SimpsonQ6INSN(A4_round_ri,"Rd32=round(Rs32,#u5)",ATTRIBS(),"Round", {RdV = fRNDN(RsV,uiV)>>uiV; })
11207cf9345cSTaylor SimpsonQ6INSN(A4_round_rr,"Rd32=round(Rs32,Rt32)",ATTRIBS(),"Round", {RdV = fRNDN(RsV,fZXTN(5,32,RtV))>>fZXTN(5,32,RtV); })
11217cf9345cSTaylor SimpsonQ6INSN(A4_round_ri_sat,"Rd32=round(Rs32,#u5):sat",ATTRIBS(),"Round", {RdV = (fSAT(fRNDN(RsV,uiV)))>>uiV; })
11227cf9345cSTaylor SimpsonQ6INSN(A4_round_rr_sat,"Rd32=round(Rs32,Rt32):sat",ATTRIBS(),"Round", {RdV = (fSAT(fRNDN(RsV,fZXTN(5,32,RtV))))>>fZXTN(5,32,RtV); })
11237cf9345cSTaylor Simpson
11247cf9345cSTaylor Simpson
11257cf9345cSTaylor SimpsonQ6INSN(A4_cround_ri,"Rd32=cround(Rs32,#u5)",ATTRIBS(),"Convergent Round", {RdV = fCRNDN(RsV,uiV); })
11267cf9345cSTaylor SimpsonQ6INSN(A4_cround_rr,"Rd32=cround(Rs32,Rt32)",ATTRIBS(),"Convergent Round", {RdV = fCRNDN(RsV,fZXTN(5,32,RtV)); })
11277cf9345cSTaylor Simpson
11287cf9345cSTaylor Simpson
11297cf9345cSTaylor Simpson#define CROUND(DST,SRC,SHIFT) \
11307cf9345cSTaylor Simpson        fHIDE(size16s_t rndbit_128;)\
11317cf9345cSTaylor Simpson        fHIDE(size16s_t tmp128;)\
11327cf9345cSTaylor Simpson        fHIDE(size16s_t src_128;)\
11337cf9345cSTaylor Simpson        if (SHIFT == 0) { \
11347cf9345cSTaylor Simpson            DST = SRC;\
11357cf9345cSTaylor Simpson        } else if ((SRC & (size8s_t)((1LL << (SHIFT - 1)) - 1LL)) == 0) { \
11367cf9345cSTaylor Simpson            src_128 = fCAST8S_16S(SRC);\
11377cf9345cSTaylor Simpson            rndbit_128 = fCAST8S_16S(1LL);\
11387cf9345cSTaylor Simpson            rndbit_128 = fSHIFTL128(rndbit_128, SHIFT);\
11397cf9345cSTaylor Simpson            rndbit_128 = fAND128(rndbit_128, src_128);\
11407cf9345cSTaylor Simpson            rndbit_128 = fSHIFTR128(rndbit_128, 1);\
11417cf9345cSTaylor Simpson            tmp128 = fADD128(src_128, rndbit_128);\
11427cf9345cSTaylor Simpson            tmp128 = fSHIFTR128(tmp128, SHIFT);\
11437cf9345cSTaylor Simpson            DST =  fCAST16S_8S(tmp128);\
11447cf9345cSTaylor Simpson        } else {\
11457cf9345cSTaylor Simpson            size16s_t rndbit_128 =  fCAST8S_16S((1LL << (SHIFT - 1))); \
11467cf9345cSTaylor Simpson            size16s_t src_128 =  fCAST8S_16S(SRC); \
11477cf9345cSTaylor Simpson            size16s_t tmp128 = fADD128(src_128, rndbit_128);\
11487cf9345cSTaylor Simpson            tmp128 = fSHIFTR128(tmp128, SHIFT);\
11497cf9345cSTaylor Simpson            DST =  fCAST16S_8S(tmp128);\
11507cf9345cSTaylor Simpson        }
11517cf9345cSTaylor Simpson
11527cf9345cSTaylor SimpsonQ6INSN(A7_croundd_ri,"Rdd32=cround(Rss32,#u6)",ATTRIBS(),"Convergent Round",
11537cf9345cSTaylor Simpson{
11547cf9345cSTaylor SimpsonCROUND(RddV,RssV,uiV);
11557cf9345cSTaylor Simpson})
11567cf9345cSTaylor Simpson
11577cf9345cSTaylor SimpsonQ6INSN(A7_croundd_rr,"Rdd32=cround(Rss32,Rt32)",ATTRIBS(),"Convergent Round",
11587cf9345cSTaylor Simpson{
11597cf9345cSTaylor SimpsonCROUND(RddV,RssV,fZXTN(6,32,RtV));
11607cf9345cSTaylor Simpson})
11617cf9345cSTaylor Simpson
11627cf9345cSTaylor Simpson
11637cf9345cSTaylor Simpson
11647cf9345cSTaylor Simpson
11657cf9345cSTaylor Simpson
11667cf9345cSTaylor Simpson
11677cf9345cSTaylor Simpson
11687cf9345cSTaylor Simpson
11697cf9345cSTaylor Simpson
11707cf9345cSTaylor SimpsonQ6INSN(A7_clip,"Rd32=clip(Rs32,#u5)",ATTRIBS(),"Clip to  #s5", {   fCLIP(RdV,RsV,uiV);})
11717cf9345cSTaylor SimpsonQ6INSN(A7_vclip,"Rdd32=vclip(Rss32,#u5)",ATTRIBS(),"Clip to  #s5",
11727cf9345cSTaylor Simpson{
11737cf9345cSTaylor SimpsonfHIDE(size4s_t tmp;)
11747cf9345cSTaylor SimpsonfCLIP(tmp, fGETWORD(0, RssV), uiV);
11757cf9345cSTaylor SimpsonfSETWORD(0, RddV, tmp);
11767cf9345cSTaylor SimpsonfCLIP(tmp,fGETWORD(1, RssV), uiV);
11777cf9345cSTaylor SimpsonfSETWORD(1, RddV, tmp);
11787cf9345cSTaylor Simpson}
11797cf9345cSTaylor Simpson)
11807cf9345cSTaylor Simpson
11817cf9345cSTaylor Simpson
11827cf9345cSTaylor Simpson
11837cf9345cSTaylor Simpson/**********************************************/
11847cf9345cSTaylor Simpson/* V4: Cross Vector Min/Max                   */
11857cf9345cSTaylor Simpson/**********************************************/
11867cf9345cSTaylor Simpson
11877cf9345cSTaylor Simpson
11887cf9345cSTaylor Simpson#define VRMINORMAX(TAG,STR,OP,SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT) \
11897cf9345cSTaylor SimpsonQ6INSN(A4_vr##TAG##SHORTTYPE,"Rxx32=vr"#TAG#SHORTTYPE"(Rss32,Ru32)",ATTRIBS(), \
11907cf9345cSTaylor Simpson"Choose " STR " elements of a vector", \
11917cf9345cSTaylor Simpson{ \
11927cf9345cSTaylor Simpson        fHIDE(int i; size8s_t TAG; size4s_t addr;) \
11937cf9345cSTaylor Simpson        TAG = fGET##GETTYPE(0,RxxV); \
11947cf9345cSTaylor Simpson        addr = fGETWORD(1,RxxV); \
11957cf9345cSTaylor Simpson        for (i = 0; i < NEL; i++) { \
11967cf9345cSTaylor Simpson            if (TAG OP fGET##GETTYPE(i,RssV)) { \
11977cf9345cSTaylor Simpson                TAG = fGET##GETTYPE(i,RssV); \
11987cf9345cSTaylor Simpson                addr = RuV | i<<SHIFT; \
11997cf9345cSTaylor Simpson            } \
12007cf9345cSTaylor Simpson        } \
12017cf9345cSTaylor Simpson        fSETWORD(0,RxxV,TAG); \
12027cf9345cSTaylor Simpson        fSETWORD(1,RxxV,addr); \
12037cf9345cSTaylor Simpson})
12047cf9345cSTaylor Simpson
12057cf9345cSTaylor Simpson#define RMINMAX(SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT) \
12067cf9345cSTaylor SimpsonVRMINORMAX(min,"minimum",>,SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT) \
12077cf9345cSTaylor SimpsonVRMINORMAX(max,"maximum",<,SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT)
12087cf9345cSTaylor Simpson
12097cf9345cSTaylor Simpson
12107cf9345cSTaylor SimpsonRMINMAX(h,HALF,HALF,4,1)
12117cf9345cSTaylor SimpsonRMINMAX(uh,HALF,UHALF,4,1)
12127cf9345cSTaylor SimpsonRMINMAX(w,WORD,WORD,2,2)
12137cf9345cSTaylor SimpsonRMINMAX(uw,WORD,UWORD,2,2)
12147cf9345cSTaylor Simpson
12157cf9345cSTaylor Simpson#undef RMINMAX
12167cf9345cSTaylor Simpson#undef VRMINORMAX
12177cf9345cSTaylor Simpson
12187cf9345cSTaylor Simpson/**********************************************/
12197cf9345cSTaylor Simpson/* Vector Min/Max                             */
12207cf9345cSTaylor Simpson/**********************************************/
12217cf9345cSTaylor Simpson
12227cf9345cSTaylor Simpson#define VMINORMAX(TAG,STR,FUNC,SHORTTYPE,SETTYPE,GETTYPE,NEL) \
12237cf9345cSTaylor SimpsonQ6INSN(A2_v##TAG##SHORTTYPE,"Rdd32=v"#TAG#SHORTTYPE"(Rtt32,Rss32)",ATTRIBS(), \
12247cf9345cSTaylor Simpson"Choose " STR " elements of two vectors", \
12257cf9345cSTaylor Simpson{ \
12267cf9345cSTaylor Simpson        fHIDE(int i;) \
12277cf9345cSTaylor Simpson        for (i = 0; i < NEL; i++) { \
12287cf9345cSTaylor Simpson            fSET##SETTYPE(i,RddV,FUNC(fGET##GETTYPE(i,RttV),fGET##GETTYPE(i,RssV))); \
12297cf9345cSTaylor Simpson        } \
12307cf9345cSTaylor Simpson})
12317cf9345cSTaylor Simpson
12327cf9345cSTaylor Simpson#define VMINORMAX3(TAG,STR,FUNC,SHORTTYPE,SETTYPE,GETTYPE,NEL) \
12337cf9345cSTaylor SimpsonQ6INSN(A6_v##TAG##SHORTTYPE##3,"Rxx32=v"#TAG#SHORTTYPE"3(Rtt32,Rss32)",ATTRIBS(), \
12347cf9345cSTaylor Simpson"Choose " STR " elements of two vectors", \
12357cf9345cSTaylor Simpson{ \
12367cf9345cSTaylor Simpson        fHIDE(int i;) \
12377cf9345cSTaylor Simpson        for (i = 0; i < NEL; i++) { \
12387cf9345cSTaylor Simpson            fSET##SETTYPE(i,RxxV,FUNC(fGET##GETTYPE(i,RxxV),FUNC(fGET##GETTYPE(i,RttV),fGET##GETTYPE(i,RssV)))); \
12397cf9345cSTaylor Simpson        } \
12407cf9345cSTaylor Simpson})
12417cf9345cSTaylor Simpson
12427cf9345cSTaylor Simpson#define MINMAX(SHORTTYPE,SETTYPE,GETTYPE,NEL) \
12437cf9345cSTaylor SimpsonVMINORMAX(min,"minimum",fMIN,SHORTTYPE,SETTYPE,GETTYPE,NEL) \
12447cf9345cSTaylor SimpsonVMINORMAX(max,"maximum",fMAX,SHORTTYPE,SETTYPE,GETTYPE,NEL)
12457cf9345cSTaylor Simpson
12467cf9345cSTaylor SimpsonMINMAX(b,BYTE,BYTE,8)
12477cf9345cSTaylor SimpsonMINMAX(ub,BYTE,UBYTE,8)
12487cf9345cSTaylor SimpsonMINMAX(h,HALF,HALF,4)
12497cf9345cSTaylor SimpsonMINMAX(uh,HALF,UHALF,4)
12507cf9345cSTaylor SimpsonMINMAX(w,WORD,WORD,2)
12517cf9345cSTaylor SimpsonMINMAX(uw,WORD,UWORD,2)
12527cf9345cSTaylor Simpson
12537cf9345cSTaylor Simpson#undef MINMAX
12547cf9345cSTaylor Simpson#undef VMINORMAX
12557cf9345cSTaylor Simpson#undef VMINORMAX3
12567cf9345cSTaylor Simpson
12577cf9345cSTaylor Simpson
1258da74cd2dSTaylor SimpsonQ6INSN(A5_ACS,"Rxx32,Pe4=vacsh(Rss32,Rtt32)",ATTRIBS(),
1259da74cd2dSTaylor Simpson"Add Compare and Select elements of two vectors, record the maximums and the decisions ",
1260da74cd2dSTaylor Simpson{
1261da74cd2dSTaylor Simpson        fHIDE(int i;)
1262da74cd2dSTaylor Simpson        fHIDE(int xv;)
1263da74cd2dSTaylor Simpson        fHIDE(int sv;)
1264da74cd2dSTaylor Simpson        fHIDE(int tv;)
1265da74cd2dSTaylor Simpson        for (i = 0; i < 4; i++) {
1266da74cd2dSTaylor Simpson                xv = (int) fGETHALF(i,RxxV);
1267da74cd2dSTaylor Simpson                sv = (int) fGETHALF(i,RssV);
1268da74cd2dSTaylor Simpson                tv = (int) fGETHALF(i,RttV);
1269da74cd2dSTaylor Simpson                xv = xv + tv;           //assumes 17bit datapath
1270da74cd2dSTaylor Simpson                sv = sv - tv;           //assumes 17bit datapath
1271da74cd2dSTaylor Simpson                fSETBIT(i*2,  PeV,  (xv > sv));
1272da74cd2dSTaylor Simpson                fSETBIT(i*2+1,PeV,  (xv > sv));
1273da74cd2dSTaylor Simpson                fSETHALF(i,   RxxV, fSATH(fMAX(xv,sv)));
1274da74cd2dSTaylor Simpson        }
1275da74cd2dSTaylor Simpson})
1276da74cd2dSTaylor Simpson
12770a65d286STaylor SimpsonQ6INSN(A6_vminub_RdP,"Rdd32,Pe4=vminub(Rtt32,Rss32)",ATTRIBS(),
12780a65d286STaylor Simpson"Vector minimum of bytes, records minimum and decision vector",
12790a65d286STaylor Simpson{
12800a65d286STaylor Simpson        fHIDE(int i;)
12810a65d286STaylor Simpson        for (i = 0; i < 8; i++) {
12820a65d286STaylor Simpson            fSETBIT(i, PeV,     (fGETUBYTE(i,RttV) > fGETUBYTE(i,RssV)));
12830a65d286STaylor Simpson            fSETBYTE(i,RddV,fMIN(fGETUBYTE(i,RttV),fGETUBYTE(i,RssV)));
12840a65d286STaylor Simpson        }
12850a65d286STaylor Simpson})
12860a65d286STaylor Simpson
12877cf9345cSTaylor Simpson/**********************************************/
12887cf9345cSTaylor Simpson/* Vector Min/Max                             */
12897cf9345cSTaylor Simpson/**********************************************/
12907cf9345cSTaylor Simpson
12917cf9345cSTaylor Simpson
12927cf9345cSTaylor SimpsonQ6INSN(A4_modwrapu,"Rd32=modwrap(Rs32,Rt32)",ATTRIBS(),
12937cf9345cSTaylor Simpson"Wrap to an unsigned modulo buffer",
12947cf9345cSTaylor Simpson{
12957cf9345cSTaylor Simpson        if (RsV < 0) {
12967cf9345cSTaylor Simpson            RdV = RsV + fCAST4u(RtV);
12977cf9345cSTaylor Simpson        } else if (fCAST4u(RsV) >= fCAST4u(RtV)) {
12987cf9345cSTaylor Simpson            RdV = RsV - fCAST4u(RtV);
12997cf9345cSTaylor Simpson        } else {
13007cf9345cSTaylor Simpson            RdV = RsV;
13017cf9345cSTaylor Simpson        }
13027cf9345cSTaylor Simpson})
1303