xref: /qemu/target/hexagon/imported/alu.idef (revision da74cd2d)
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
1567cf9345cSTaylor Simpson/* NEG and ABS */
1577cf9345cSTaylor Simpson
1587cf9345cSTaylor SimpsonQ6INSN(A2_negsat,"Rd32=neg(Rs32):sat",ATTRIBS(),
1597cf9345cSTaylor Simpson"Arithmetic negate register", { RdV = fSAT(-fCAST8s(RsV)); })
1607cf9345cSTaylor Simpson
1617cf9345cSTaylor SimpsonQ6INSN(A2_abs,"Rd32=abs(Rs32)",ATTRIBS(),
1627cf9345cSTaylor Simpson"Absolute Value register", { RdV = fABS(RsV); })
1637cf9345cSTaylor Simpson
1647cf9345cSTaylor SimpsonQ6INSN(A2_abssat,"Rd32=abs(Rs32):sat",ATTRIBS(),
1657cf9345cSTaylor Simpson"Arithmetic negate register", { RdV = fSAT(fABS(fCAST4_8s(RsV))); })
1667cf9345cSTaylor Simpson
1677cf9345cSTaylor SimpsonQ6INSN(A2_vconj,"Rdd32=vconj(Rss32):sat",ATTRIBS(A_ARCHV2),
1687cf9345cSTaylor Simpson"Vector Complex conjugate of Rss",
1697cf9345cSTaylor Simpson{  fSETHALF(1,RddV,fSATN(16,-fGETHALF(1,RssV)));
1707cf9345cSTaylor Simpson   fSETHALF(0,RddV,fGETHALF(0,RssV));
1717cf9345cSTaylor Simpson   fSETHALF(3,RddV,fSATN(16,-fGETHALF(3,RssV)));
1727cf9345cSTaylor Simpson   fSETHALF(2,RddV,fGETHALF(2,RssV));
1737cf9345cSTaylor Simpson})
1747cf9345cSTaylor Simpson
1757cf9345cSTaylor Simpson
1767cf9345cSTaylor Simpson/* 64-bit versions */
1777cf9345cSTaylor Simpson
1787cf9345cSTaylor SimpsonQ6INSN(A2_negp,"Rdd32=neg(Rss32)",ATTRIBS(),
1797cf9345cSTaylor Simpson"Arithmetic negate register", { RddV = -RssV; })
1807cf9345cSTaylor Simpson
1817cf9345cSTaylor SimpsonQ6INSN(A2_absp,"Rdd32=abs(Rss32)",ATTRIBS(),
1827cf9345cSTaylor Simpson"Absolute Value register", { RddV = fABS(RssV); })
1837cf9345cSTaylor Simpson
1847cf9345cSTaylor Simpson
1857cf9345cSTaylor Simpson/* MIN and MAX  R */
1867cf9345cSTaylor Simpson
1877cf9345cSTaylor SimpsonQ6INSN(A2_max,"Rd32=max(Rs32,Rt32)",ATTRIBS(),
1887cf9345cSTaylor Simpson"Maximum of two registers",
1897cf9345cSTaylor Simpson{ RdV = fMAX(RsV,RtV); })
1907cf9345cSTaylor Simpson
1917cf9345cSTaylor SimpsonQ6INSN(A2_maxu,"Rd32=maxu(Rs32,Rt32)",ATTRIBS(),
1927cf9345cSTaylor Simpson"Maximum of two registers (unsigned)",
1937cf9345cSTaylor Simpson{ RdV = fMAX(fCAST4u(RsV),fCAST4u(RtV)); })
1947cf9345cSTaylor Simpson
1957cf9345cSTaylor SimpsonQ6INSN(A2_min,"Rd32=min(Rt32,Rs32)",ATTRIBS(),
1967cf9345cSTaylor Simpson"Minimum of two registers",
1977cf9345cSTaylor Simpson{ RdV = fMIN(RtV,RsV); })
1987cf9345cSTaylor Simpson
1997cf9345cSTaylor SimpsonQ6INSN(A2_minu,"Rd32=minu(Rt32,Rs32)",ATTRIBS(),
2007cf9345cSTaylor Simpson"Minimum of two registers (unsigned)",
2017cf9345cSTaylor Simpson{ RdV = fMIN(fCAST4u(RtV),fCAST4u(RsV)); })
2027cf9345cSTaylor Simpson
2037cf9345cSTaylor Simpson/* MIN and MAX Pairs */
2047cf9345cSTaylor Simpson#if 1
2057cf9345cSTaylor SimpsonQ6INSN(A2_maxp,"Rdd32=max(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
2067cf9345cSTaylor Simpson"Maximum of two register pairs",
2077cf9345cSTaylor Simpson{ RddV = fMAX(RssV,RttV); })
2087cf9345cSTaylor Simpson
2097cf9345cSTaylor SimpsonQ6INSN(A2_maxup,"Rdd32=maxu(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
2107cf9345cSTaylor Simpson"Maximum of two register pairs (unsigned)",
2117cf9345cSTaylor Simpson{ RddV = fMAX(fCAST8u(RssV),fCAST8u(RttV)); })
2127cf9345cSTaylor Simpson
2137cf9345cSTaylor SimpsonQ6INSN(A2_minp,"Rdd32=min(Rtt32,Rss32)",ATTRIBS(A_ARCHV3),
2147cf9345cSTaylor Simpson"Minimum of two register pairs",
2157cf9345cSTaylor Simpson{ RddV = fMIN(RttV,RssV); })
2167cf9345cSTaylor Simpson
2177cf9345cSTaylor SimpsonQ6INSN(A2_minup,"Rdd32=minu(Rtt32,Rss32)",ATTRIBS(A_ARCHV3),
2187cf9345cSTaylor Simpson"Minimum of two register pairs (unsigned)",
2197cf9345cSTaylor Simpson{ RddV = fMIN(fCAST8u(RttV),fCAST8u(RssV)); })
2207cf9345cSTaylor Simpson#endif
2217cf9345cSTaylor Simpson
2227cf9345cSTaylor Simpson/**********************************************/
2237cf9345cSTaylor Simpson/* Register and Immediate Transfers           */
2247cf9345cSTaylor Simpson/**********************************************/
2257cf9345cSTaylor Simpson
2267cf9345cSTaylor SimpsonQ6INSN(A2_nop,"nop",ATTRIBS(A_IT_NOP),
2277cf9345cSTaylor Simpson"Nop (32-bit encoding)",
2287cf9345cSTaylor Simpson fHIDE( { }  ))
2297cf9345cSTaylor Simpson
2307cf9345cSTaylor Simpson
2317cf9345cSTaylor SimpsonQ6INSN(A4_ext,"immext(#u26:6)",ATTRIBS(A_IT_EXTENDER),
2327cf9345cSTaylor Simpson"This instruction carries the 26 most-significant immediate bits for the next instruction",
2337cf9345cSTaylor Simpson{ fHIDE(); })
2347cf9345cSTaylor Simpson
2357cf9345cSTaylor Simpson
2367cf9345cSTaylor SimpsonQ6INSN(A2_tfr,"Rd32=Rs32",ATTRIBS(),
2377cf9345cSTaylor Simpson"tfr register",{ RdV=RsV;})
2387cf9345cSTaylor Simpson
2397cf9345cSTaylor SimpsonQ6INSN(A2_tfrsi,"Rd32=#s16",ATTRIBS(),
2407cf9345cSTaylor Simpson"transfer signed immediate to register",{ fIMMEXT(siV); RdV=siV;})
2417cf9345cSTaylor Simpson
2427cf9345cSTaylor SimpsonQ6INSN(A2_sxtb,"Rd32=sxtb(Rs32)",ATTRIBS(),
2437cf9345cSTaylor Simpson"Sign extend byte", {RdV = fSXTN(8,32,RsV);})
2447cf9345cSTaylor Simpson
2457cf9345cSTaylor SimpsonQ6INSN(A2_zxth,"Rd32=zxth(Rs32)",ATTRIBS(),
2467cf9345cSTaylor Simpson"Zero extend half", {RdV = fZXTN(16,32,RsV);})
2477cf9345cSTaylor Simpson
2487cf9345cSTaylor SimpsonQ6INSN(A2_sxth,"Rd32=sxth(Rs32)",ATTRIBS(),
2497cf9345cSTaylor Simpson"Sign extend half", {RdV = fSXTN(16,32,RsV);})
2507cf9345cSTaylor Simpson
2517cf9345cSTaylor SimpsonQ6INSN(A2_combinew,"Rdd32=combine(Rs32,Rt32)",ATTRIBS(),
2527cf9345cSTaylor Simpson"Combine two words into a register pair",
2537cf9345cSTaylor Simpson{ fSETWORD(0,RddV,RtV);
2547cf9345cSTaylor Simpson  fSETWORD(1,RddV,RsV);
2557cf9345cSTaylor Simpson})
2567cf9345cSTaylor Simpson
2577cf9345cSTaylor SimpsonQ6INSN(A4_combineri,"Rdd32=combine(Rs32,#s8)",ATTRIBS(),
2587cf9345cSTaylor Simpson"Combine a word and an immediate into a register pair",
2597cf9345cSTaylor Simpson{ fIMMEXT(siV); fSETWORD(0,RddV,siV);
2607cf9345cSTaylor Simpson  fSETWORD(1,RddV,RsV);
2617cf9345cSTaylor Simpson})
2627cf9345cSTaylor Simpson
2637cf9345cSTaylor SimpsonQ6INSN(A4_combineir,"Rdd32=combine(#s8,Rs32)",ATTRIBS(),
2647cf9345cSTaylor Simpson"Combine a word and an immediate into a register pair",
2657cf9345cSTaylor Simpson{ fIMMEXT(siV); fSETWORD(0,RddV,RsV);
2667cf9345cSTaylor Simpson  fSETWORD(1,RddV,siV);
2677cf9345cSTaylor Simpson})
2687cf9345cSTaylor Simpson
2697cf9345cSTaylor Simpson
2707cf9345cSTaylor Simpson
2717cf9345cSTaylor SimpsonQ6INSN(A2_combineii,"Rdd32=combine(#s8,#S8)",ATTRIBS(A_ARCHV2),
2727cf9345cSTaylor Simpson"Set two small immediates",
2737cf9345cSTaylor Simpson{ fIMMEXT(siV); fSETWORD(0,RddV,SiV); fSETWORD(1,RddV,siV); })
2747cf9345cSTaylor Simpson
2757cf9345cSTaylor SimpsonQ6INSN(A4_combineii,"Rdd32=combine(#s8,#U6)",ATTRIBS(),"Set two small immediates",
2767cf9345cSTaylor Simpson{ fIMMEXT(UiV); fSETWORD(0,RddV,UiV); fSETWORD(1,RddV,siV); })
2777cf9345cSTaylor Simpson
2787cf9345cSTaylor Simpson
2797cf9345cSTaylor SimpsonQ6INSN(A2_combine_hh,"Rd32=combine(Rt.H32,Rs.H32)",ATTRIBS(),
2807cf9345cSTaylor Simpson"Combine two halfs into a register", {RdV = (fGETUHALF(1,RtV)<<16) | fGETUHALF(1,RsV);})
2817cf9345cSTaylor Simpson
2827cf9345cSTaylor SimpsonQ6INSN(A2_combine_hl,"Rd32=combine(Rt.H32,Rs.L32)",ATTRIBS(),
2837cf9345cSTaylor Simpson"Combine two halfs into a register", {RdV = (fGETUHALF(1,RtV)<<16) | fGETUHALF(0,RsV);})
2847cf9345cSTaylor Simpson
2857cf9345cSTaylor SimpsonQ6INSN(A2_combine_lh,"Rd32=combine(Rt.L32,Rs.H32)",ATTRIBS(),
2867cf9345cSTaylor Simpson"Combine two halfs into a register", {RdV = (fGETUHALF(0,RtV)<<16) | fGETUHALF(1,RsV);})
2877cf9345cSTaylor Simpson
2887cf9345cSTaylor SimpsonQ6INSN(A2_combine_ll,"Rd32=combine(Rt.L32,Rs.L32)",ATTRIBS(),
2897cf9345cSTaylor Simpson"Combine two halfs into a register", {RdV = (fGETUHALF(0,RtV)<<16) | fGETUHALF(0,RsV);})
2907cf9345cSTaylor Simpson
2917cf9345cSTaylor SimpsonQ6INSN(A2_tfril,"Rx.L32=#u16",ATTRIBS(),
2927cf9345cSTaylor Simpson"Set low 16-bits, leave upper 16 unchanged",{ fSETHALF(0,RxV,uiV);})
2937cf9345cSTaylor Simpson
2947cf9345cSTaylor SimpsonQ6INSN(A2_tfrih,"Rx.H32=#u16",ATTRIBS(),
2957cf9345cSTaylor Simpson"Set high 16-bits, leave low 16 unchanged",{ fSETHALF(1,RxV,uiV);})
2967cf9345cSTaylor Simpson
2977cf9345cSTaylor SimpsonQ6INSN(A2_tfrcrr,"Rd32=Cs32",ATTRIBS(),
2987cf9345cSTaylor Simpson"transfer control register to general register",{ RdV=CsV;})
2997cf9345cSTaylor Simpson
3007cf9345cSTaylor SimpsonQ6INSN(A2_tfrrcr,"Cd32=Rs32",ATTRIBS(),
3017cf9345cSTaylor Simpson"transfer general register to control register",{ CdV=RsV;})
3027cf9345cSTaylor Simpson
3037cf9345cSTaylor SimpsonQ6INSN(A4_tfrcpp,"Rdd32=Css32",ATTRIBS(),
3047cf9345cSTaylor Simpson"transfer control register to general register",{ RddV=CssV;})
3057cf9345cSTaylor Simpson
3067cf9345cSTaylor SimpsonQ6INSN(A4_tfrpcp,"Cdd32=Rss32",ATTRIBS(),
3077cf9345cSTaylor Simpson"transfer general register to control register",{ CddV=RssV;})
3087cf9345cSTaylor Simpson
3097cf9345cSTaylor Simpson
3107cf9345cSTaylor Simpson/**********************************************/
3117cf9345cSTaylor Simpson/* Logicals                                   */
3127cf9345cSTaylor Simpson/**********************************************/
3137cf9345cSTaylor Simpson
3147cf9345cSTaylor SimpsonQ6INSN(A2_and,"Rd32=and(Rs32,Rt32)",ATTRIBS(),
3157cf9345cSTaylor Simpson"logical AND",{ RdV=RsV&RtV;})
3167cf9345cSTaylor Simpson
3177cf9345cSTaylor SimpsonQ6INSN(A2_or,"Rd32=or(Rs32,Rt32)",ATTRIBS(),
3187cf9345cSTaylor Simpson"logical OR",{ RdV=RsV|RtV;})
3197cf9345cSTaylor Simpson
3207cf9345cSTaylor SimpsonQ6INSN(A2_xor,"Rd32=xor(Rs32,Rt32)",ATTRIBS(),
3217cf9345cSTaylor Simpson"logical XOR",{ RdV=RsV^RtV;})
3227cf9345cSTaylor Simpson
3237cf9345cSTaylor SimpsonQ6INSN(M2_xor_xacc,"Rx32^=xor(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
3247cf9345cSTaylor Simpson"logical XOR with XOR accumulation",{ RxV^=RsV^RtV;})
3257cf9345cSTaylor Simpson
3267cf9345cSTaylor SimpsonQ6INSN(M4_xor_xacc,"Rxx32^=xor(Rss32,Rtt32)",,
3277cf9345cSTaylor Simpson"logical XOR with XOR accumulation",{ RxxV^=RssV^RttV;})
3287cf9345cSTaylor Simpson
3297cf9345cSTaylor Simpson
3307cf9345cSTaylor Simpson
3317cf9345cSTaylor SimpsonQ6INSN(A4_andn,"Rd32=and(Rt32,~Rs32)",,
3327cf9345cSTaylor Simpson"And-Not", { RdV = (RtV & ~RsV); })
3337cf9345cSTaylor Simpson
3347cf9345cSTaylor SimpsonQ6INSN(A4_orn,"Rd32=or(Rt32,~Rs32)",,
3357cf9345cSTaylor Simpson"Or-Not", { RdV = (RtV | ~RsV); })
3367cf9345cSTaylor Simpson
3377cf9345cSTaylor Simpson
3387cf9345cSTaylor SimpsonQ6INSN(A4_andnp,"Rdd32=and(Rtt32,~Rss32)",,
3397cf9345cSTaylor Simpson"And-Not", { RddV = (RttV & ~RssV); })
3407cf9345cSTaylor Simpson
3417cf9345cSTaylor SimpsonQ6INSN(A4_ornp,"Rdd32=or(Rtt32,~Rss32)",,
3427cf9345cSTaylor Simpson"Or-Not", { RddV = (RttV | ~RssV); })
3437cf9345cSTaylor Simpson
3447cf9345cSTaylor Simpson
3457cf9345cSTaylor Simpson
3467cf9345cSTaylor Simpson
3477cf9345cSTaylor Simpson/********************/
3487cf9345cSTaylor Simpson/* Compound add-add */
3497cf9345cSTaylor Simpson/********************/
3507cf9345cSTaylor Simpson
3517cf9345cSTaylor SimpsonQ6INSN(S4_addaddi,"Rd32=add(Rs32,add(Ru32,#s6))",ATTRIBS(),
3527cf9345cSTaylor Simpson        "3-input add",
3537cf9345cSTaylor Simpson        { RdV = RsV + RuV + fIMMEXT(siV); })
3547cf9345cSTaylor Simpson
3557cf9345cSTaylor Simpson
3567cf9345cSTaylor SimpsonQ6INSN(S4_subaddi,"Rd32=add(Rs32,sub(#s6,Ru32))",ATTRIBS(),
3577cf9345cSTaylor Simpson        "3-input sub",
3587cf9345cSTaylor Simpson        { RdV = RsV - RuV + fIMMEXT(siV); })
3597cf9345cSTaylor Simpson
3607cf9345cSTaylor Simpson
3617cf9345cSTaylor Simpson
3627cf9345cSTaylor Simpson/****************************/
3637cf9345cSTaylor Simpson/* Compound logical-logical */
3647cf9345cSTaylor Simpson/****************************/
3657cf9345cSTaylor Simpson
3667cf9345cSTaylor SimpsonQ6INSN(M4_and_and,"Rx32&=and(Rs32,Rt32)",ATTRIBS(),
3677cf9345cSTaylor Simpson"Compound And-And", { RxV &= (RsV & RtV); })
3687cf9345cSTaylor Simpson
3697cf9345cSTaylor SimpsonQ6INSN(M4_and_andn,"Rx32&=and(Rs32,~Rt32)",ATTRIBS(),
3707cf9345cSTaylor Simpson"Compound And-Andn", { RxV &= (RsV & ~RtV); })
3717cf9345cSTaylor Simpson
3727cf9345cSTaylor SimpsonQ6INSN(M4_and_or,"Rx32&=or(Rs32,Rt32)",ATTRIBS(),
3737cf9345cSTaylor Simpson"Compound And-Or", { RxV &= (RsV | RtV); })
3747cf9345cSTaylor Simpson
3757cf9345cSTaylor SimpsonQ6INSN(M4_and_xor,"Rx32&=xor(Rs32,Rt32)",ATTRIBS(),
3767cf9345cSTaylor Simpson"Compound And-xor", { RxV &= (RsV ^ RtV); })
3777cf9345cSTaylor Simpson
3787cf9345cSTaylor Simpson
3797cf9345cSTaylor Simpson
3807cf9345cSTaylor SimpsonQ6INSN(M4_or_and,"Rx32|=and(Rs32,Rt32)",ATTRIBS(),
3817cf9345cSTaylor Simpson"Compound Or-And", { RxV |= (RsV & RtV); })
3827cf9345cSTaylor Simpson
3837cf9345cSTaylor SimpsonQ6INSN(M4_or_andn,"Rx32|=and(Rs32,~Rt32)",ATTRIBS(),
3847cf9345cSTaylor Simpson"Compound Or-AndN", { RxV |= (RsV & ~RtV); })
3857cf9345cSTaylor Simpson
3867cf9345cSTaylor SimpsonQ6INSN(M4_or_or,"Rx32|=or(Rs32,Rt32)",ATTRIBS(),
3877cf9345cSTaylor Simpson"Compound Or-Or", { RxV |= (RsV | RtV); })
3887cf9345cSTaylor Simpson
3897cf9345cSTaylor SimpsonQ6INSN(M4_or_xor,"Rx32|=xor(Rs32,Rt32)",ATTRIBS(),
3907cf9345cSTaylor Simpson"Compound Or-xor", { RxV |= (RsV ^ RtV); })
3917cf9345cSTaylor Simpson
3927cf9345cSTaylor Simpson
3937cf9345cSTaylor SimpsonQ6INSN(S4_or_andix,"Rx32=or(Ru32,and(Rx32,#s10))",ATTRIBS(),
3947cf9345cSTaylor Simpson"Compound Or-And", { RxV = RuV | (RxV & fIMMEXT(siV)); })
3957cf9345cSTaylor Simpson
3967cf9345cSTaylor SimpsonQ6INSN(S4_or_andi,"Rx32|=and(Rs32,#s10)",ATTRIBS(),
3977cf9345cSTaylor Simpson"Compound Or-And", { RxV = RxV | (RsV & fIMMEXT(siV)); })
3987cf9345cSTaylor Simpson
3997cf9345cSTaylor SimpsonQ6INSN(S4_or_ori,"Rx32|=or(Rs32,#s10)",ATTRIBS(),
4007cf9345cSTaylor Simpson"Compound Or-And", { RxV = RxV | (RsV | fIMMEXT(siV)); })
4017cf9345cSTaylor Simpson
4027cf9345cSTaylor Simpson
4037cf9345cSTaylor Simpson
4047cf9345cSTaylor Simpson
4057cf9345cSTaylor SimpsonQ6INSN(M4_xor_and,"Rx32^=and(Rs32,Rt32)",ATTRIBS(),
4067cf9345cSTaylor Simpson"Compound Xor-And", { RxV ^= (RsV & RtV); })
4077cf9345cSTaylor Simpson
4087cf9345cSTaylor SimpsonQ6INSN(M4_xor_or,"Rx32^=or(Rs32,Rt32)",ATTRIBS(),
4097cf9345cSTaylor Simpson"Compound Xor-Or", { RxV ^= (RsV | RtV); })
4107cf9345cSTaylor Simpson
4117cf9345cSTaylor SimpsonQ6INSN(M4_xor_andn,"Rx32^=and(Rs32,~Rt32)",ATTRIBS(),
4127cf9345cSTaylor Simpson"Compound Xor-And", { RxV ^= (RsV & ~RtV); })
4137cf9345cSTaylor Simpson
4147cf9345cSTaylor Simpson
4157cf9345cSTaylor Simpson
4167cf9345cSTaylor Simpson
4177cf9345cSTaylor Simpson
4187cf9345cSTaylor Simpson
4197cf9345cSTaylor SimpsonQ6INSN(A2_subri,"Rd32=sub(#s10,Rs32)",ATTRIBS(A_ARCHV2),
4207cf9345cSTaylor Simpson"Subtract register from immediate",{ fIMMEXT(siV); RdV=siV-RsV;})
4217cf9345cSTaylor Simpson
4227cf9345cSTaylor SimpsonQ6INSN(A2_andir,"Rd32=and(Rs32,#s10)",ATTRIBS(A_ARCHV2),
4237cf9345cSTaylor Simpson"logical AND with immediate",{ fIMMEXT(siV); RdV=RsV&siV;})
4247cf9345cSTaylor Simpson
4257cf9345cSTaylor SimpsonQ6INSN(A2_orir,"Rd32=or(Rs32,#s10)",ATTRIBS(A_ARCHV2),
4267cf9345cSTaylor Simpson"logical OR with immediate",{ fIMMEXT(siV); RdV=RsV|siV;})
4277cf9345cSTaylor Simpson
4287cf9345cSTaylor Simpson
4297cf9345cSTaylor Simpson
4307cf9345cSTaylor Simpson
4317cf9345cSTaylor SimpsonQ6INSN(A2_andp,"Rdd32=and(Rss32,Rtt32)",ATTRIBS(),
4327cf9345cSTaylor Simpson"logical AND pair",{ RddV=RssV&RttV;})
4337cf9345cSTaylor Simpson
4347cf9345cSTaylor SimpsonQ6INSN(A2_orp,"Rdd32=or(Rss32,Rtt32)",ATTRIBS(),
4357cf9345cSTaylor Simpson"logical OR pair",{ RddV=RssV|RttV;})
4367cf9345cSTaylor Simpson
4377cf9345cSTaylor SimpsonQ6INSN(A2_xorp,"Rdd32=xor(Rss32,Rtt32)",ATTRIBS(),
4387cf9345cSTaylor Simpson"logical eXclusive OR pair",{ RddV=RssV^RttV;})
4397cf9345cSTaylor Simpson
4407cf9345cSTaylor SimpsonQ6INSN(A2_notp,"Rdd32=not(Rss32)",ATTRIBS(),
4417cf9345cSTaylor Simpson"logical NOT pair",{ RddV=~RssV;})
4427cf9345cSTaylor Simpson
4437cf9345cSTaylor SimpsonQ6INSN(A2_sxtw,"Rdd32=sxtw(Rs32)",ATTRIBS(),
4447cf9345cSTaylor Simpson"Sign extend 32-bit word to 64-bit pair",
4457cf9345cSTaylor Simpson{ RddV = fCAST4_8s(RsV); })
4467cf9345cSTaylor Simpson
4477cf9345cSTaylor SimpsonQ6INSN(A2_sat,"Rd32=sat(Rss32)",ATTRIBS(),
4487cf9345cSTaylor Simpson"Saturate to 32-bit Signed",
4497cf9345cSTaylor Simpson{ RdV = fSAT(RssV); })
4507cf9345cSTaylor Simpson
4517cf9345cSTaylor SimpsonQ6INSN(A2_roundsat,"Rd32=round(Rss32):sat",ATTRIBS(),
4527cf9345cSTaylor Simpson"Round & Saturate to 32-bit Signed",
4537cf9345cSTaylor Simpson{ fHIDE(size8s_t tmp;) fADDSAT64(tmp,RssV,0x080000000ULL); RdV = fGETWORD(1,tmp); })
4547cf9345cSTaylor Simpson
4557cf9345cSTaylor SimpsonQ6INSN(A2_sath,"Rd32=sath(Rs32)",ATTRIBS(),
4567cf9345cSTaylor Simpson"Saturate to 16-bit Signed",
4577cf9345cSTaylor Simpson{ RdV = fSATH(RsV); })
4587cf9345cSTaylor Simpson
4597cf9345cSTaylor SimpsonQ6INSN(A2_satuh,"Rd32=satuh(Rs32)",ATTRIBS(),
4607cf9345cSTaylor Simpson"Saturate to 16-bit Unsigned",
4617cf9345cSTaylor Simpson{ RdV = fSATUH(RsV); })
4627cf9345cSTaylor Simpson
4637cf9345cSTaylor SimpsonQ6INSN(A2_satub,"Rd32=satub(Rs32)",ATTRIBS(),
4647cf9345cSTaylor Simpson"Saturate to 8-bit Unsigned",
4657cf9345cSTaylor Simpson{ RdV = fSATUB(RsV); })
4667cf9345cSTaylor Simpson
4677cf9345cSTaylor SimpsonQ6INSN(A2_satb,"Rd32=satb(Rs32)",ATTRIBS(A_ARCHV2),
4687cf9345cSTaylor Simpson"Saturate to 8-bit Signed",
4697cf9345cSTaylor Simpson{ RdV = fSATB(RsV); })
4707cf9345cSTaylor Simpson
4717cf9345cSTaylor Simpson/**********************************************/
4727cf9345cSTaylor Simpson/* Vector Add                                 */
4737cf9345cSTaylor Simpson/**********************************************/
4747cf9345cSTaylor Simpson
4757cf9345cSTaylor SimpsonQ6INSN(A2_vaddub,"Rdd32=vaddub(Rss32,Rtt32)",ATTRIBS(),
4767cf9345cSTaylor Simpson"Add vector of bytes",
4777cf9345cSTaylor Simpson{
4787cf9345cSTaylor Simpson        fHIDE(int i;)
4797cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
4807cf9345cSTaylor Simpson            fSETBYTE(i,RddV,(fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV)));
4817cf9345cSTaylor Simpson        }
4827cf9345cSTaylor Simpson})
4837cf9345cSTaylor Simpson
4847cf9345cSTaylor SimpsonQ6INSN(A2_vaddubs,"Rdd32=vaddub(Rss32,Rtt32):sat",ATTRIBS(),
4857cf9345cSTaylor Simpson"Add vector of bytes",
4867cf9345cSTaylor Simpson{
4877cf9345cSTaylor Simpson        fHIDE(int i;)
4887cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
4897cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fSATUN(8,fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV)));
4907cf9345cSTaylor Simpson        }
4917cf9345cSTaylor Simpson})
4927cf9345cSTaylor Simpson
4937cf9345cSTaylor SimpsonQ6INSN(A2_vaddh,"Rdd32=vaddh(Rss32,Rtt32)",ATTRIBS(),
4947cf9345cSTaylor Simpson"Add vector of half integers",
4957cf9345cSTaylor Simpson{
4967cf9345cSTaylor Simpson        fHIDE(int i;)
4977cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
4987cf9345cSTaylor Simpson            fSETHALF(i,RddV,fGETHALF(i,RssV)+fGETHALF(i,RttV));
4997cf9345cSTaylor Simpson        }
5007cf9345cSTaylor Simpson})
5017cf9345cSTaylor Simpson
5027cf9345cSTaylor SimpsonQ6INSN(A2_vaddhs,"Rdd32=vaddh(Rss32,Rtt32):sat",ATTRIBS(),
5037cf9345cSTaylor Simpson"Add vector of half integers with saturation",
5047cf9345cSTaylor Simpson{
5057cf9345cSTaylor Simpson        fHIDE(int i;)
5067cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
5077cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATN(16,fGETHALF(i,RssV)+fGETHALF(i,RttV)));
5087cf9345cSTaylor Simpson        }
5097cf9345cSTaylor Simpson})
5107cf9345cSTaylor Simpson
5117cf9345cSTaylor SimpsonQ6INSN(A2_vadduhs,"Rdd32=vadduh(Rss32,Rtt32):sat",ATTRIBS(),
5127cf9345cSTaylor Simpson"Add vector of unsigned half integers with saturation",
5137cf9345cSTaylor Simpson{
5147cf9345cSTaylor Simpson        fHIDE(int i;)
5157cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
5167cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATUN(16,fGETUHALF(i,RssV)+fGETUHALF(i,RttV)));
5177cf9345cSTaylor Simpson        }
5187cf9345cSTaylor Simpson})
5197cf9345cSTaylor Simpson
5207cf9345cSTaylor SimpsonQ6INSN(A5_vaddhubs,"Rd32=vaddhub(Rss32,Rtt32):sat",ATTRIBS(),
5217cf9345cSTaylor Simpson"Add vector of half integers with saturation and pack to unsigned bytes",
5227cf9345cSTaylor Simpson{
5237cf9345cSTaylor Simpson        fHIDE(int i;)
5247cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
5257cf9345cSTaylor Simpson            fSETBYTE(i,RdV,fSATUB(fGETHALF(i,RssV)+fGETHALF(i,RttV)));
5267cf9345cSTaylor Simpson        }
5277cf9345cSTaylor Simpson})
5287cf9345cSTaylor Simpson
5297cf9345cSTaylor SimpsonQ6INSN(A2_vaddw,"Rdd32=vaddw(Rss32,Rtt32)",ATTRIBS(),
5307cf9345cSTaylor Simpson"Add vector of words",
5317cf9345cSTaylor Simpson{
5327cf9345cSTaylor Simpson        fHIDE(int i;)
5337cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
5347cf9345cSTaylor Simpson            fSETWORD(i,RddV,fGETWORD(i,RssV)+fGETWORD(i,RttV));
5357cf9345cSTaylor Simpson        }
5367cf9345cSTaylor Simpson})
5377cf9345cSTaylor Simpson
5387cf9345cSTaylor SimpsonQ6INSN(A2_vaddws,"Rdd32=vaddw(Rss32,Rtt32):sat",ATTRIBS(),
5397cf9345cSTaylor Simpson"Add vector of words with saturation",
5407cf9345cSTaylor Simpson{
5417cf9345cSTaylor Simpson        fHIDE(int i;)
5427cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
5437cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSATN(32,fGETWORD(i,RssV)+fGETWORD(i,RttV)));
5447cf9345cSTaylor Simpson        }
5457cf9345cSTaylor Simpson})
5467cf9345cSTaylor Simpson
5477cf9345cSTaylor Simpson
5487cf9345cSTaylor Simpson
5497cf9345cSTaylor SimpsonQ6INSN(S4_vxaddsubw,"Rdd32=vxaddsubw(Rss32,Rtt32):sat",ATTRIBS(),
5507cf9345cSTaylor Simpson"Cross vector add-sub words with saturation",
5517cf9345cSTaylor Simpson{
5527cf9345cSTaylor Simpson        fSETWORD(0,RddV,fSAT(fGETWORD(0,RssV)+fGETWORD(1,RttV)));
5537cf9345cSTaylor Simpson        fSETWORD(1,RddV,fSAT(fGETWORD(1,RssV)-fGETWORD(0,RttV)));
5547cf9345cSTaylor Simpson})
5557cf9345cSTaylor SimpsonQ6INSN(S4_vxsubaddw,"Rdd32=vxsubaddw(Rss32,Rtt32):sat",ATTRIBS(),
5567cf9345cSTaylor Simpson"Cross vector sub-add words with saturation",
5577cf9345cSTaylor Simpson{
5587cf9345cSTaylor Simpson        fSETWORD(0,RddV,fSAT(fGETWORD(0,RssV)-fGETWORD(1,RttV)));
5597cf9345cSTaylor Simpson        fSETWORD(1,RddV,fSAT(fGETWORD(1,RssV)+fGETWORD(0,RttV)));
5607cf9345cSTaylor Simpson})
5617cf9345cSTaylor Simpson
5627cf9345cSTaylor Simpson
5637cf9345cSTaylor Simpson
5647cf9345cSTaylor SimpsonQ6INSN(S4_vxaddsubh,"Rdd32=vxaddsubh(Rss32,Rtt32):sat",ATTRIBS(),
5657cf9345cSTaylor Simpson"Cross vector add-sub halfwords with saturation",
5667cf9345cSTaylor Simpson{
5677cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH(fGETHALF(0,RssV)+fGETHALF(1,RttV)));
5687cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH(fGETHALF(1,RssV)-fGETHALF(0,RttV)));
5697cf9345cSTaylor Simpson
5707cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH(fGETHALF(2,RssV)+fGETHALF(3,RttV)));
5717cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH(fGETHALF(3,RssV)-fGETHALF(2,RttV)));
5727cf9345cSTaylor Simpson
5737cf9345cSTaylor Simpson})
5747cf9345cSTaylor SimpsonQ6INSN(S4_vxsubaddh,"Rdd32=vxsubaddh(Rss32,Rtt32):sat",ATTRIBS(),
5757cf9345cSTaylor Simpson"Cross vector sub-add halfwords with saturation",
5767cf9345cSTaylor Simpson{
5777cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH(fGETHALF(0,RssV)-fGETHALF(1,RttV)));
5787cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH(fGETHALF(1,RssV)+fGETHALF(0,RttV)));
5797cf9345cSTaylor Simpson
5807cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH(fGETHALF(2,RssV)-fGETHALF(3,RttV)));
5817cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH(fGETHALF(3,RssV)+fGETHALF(2,RttV)));
5827cf9345cSTaylor Simpson})
5837cf9345cSTaylor Simpson
5847cf9345cSTaylor Simpson
5857cf9345cSTaylor Simpson
5867cf9345cSTaylor Simpson
5877cf9345cSTaylor SimpsonQ6INSN(S4_vxaddsubhr,"Rdd32=vxaddsubh(Rss32,Rtt32):rnd:>>1:sat",ATTRIBS(),
5887cf9345cSTaylor Simpson"Cross vector add-sub halfwords with shift, round, and saturation",
5897cf9345cSTaylor Simpson{
5907cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH((fGETHALF(0,RssV)+fGETHALF(1,RttV)+1)>>1));
5917cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH((fGETHALF(1,RssV)-fGETHALF(0,RttV)+1)>>1));
5927cf9345cSTaylor Simpson
5937cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH((fGETHALF(2,RssV)+fGETHALF(3,RttV)+1)>>1));
5947cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH((fGETHALF(3,RssV)-fGETHALF(2,RttV)+1)>>1));
5957cf9345cSTaylor Simpson
5967cf9345cSTaylor Simpson})
5977cf9345cSTaylor SimpsonQ6INSN(S4_vxsubaddhr,"Rdd32=vxsubaddh(Rss32,Rtt32):rnd:>>1:sat",ATTRIBS(),
5987cf9345cSTaylor Simpson"Cross vector sub-add halfwords with shift, round, and saturation",
5997cf9345cSTaylor Simpson{
6007cf9345cSTaylor Simpson        fSETHALF(0,RddV,fSATH((fGETHALF(0,RssV)-fGETHALF(1,RttV)+1)>>1));
6017cf9345cSTaylor Simpson        fSETHALF(1,RddV,fSATH((fGETHALF(1,RssV)+fGETHALF(0,RttV)+1)>>1));
6027cf9345cSTaylor Simpson
6037cf9345cSTaylor Simpson        fSETHALF(2,RddV,fSATH((fGETHALF(2,RssV)-fGETHALF(3,RttV)+1)>>1));
6047cf9345cSTaylor Simpson        fSETHALF(3,RddV,fSATH((fGETHALF(3,RssV)+fGETHALF(2,RttV)+1)>>1));
6057cf9345cSTaylor Simpson})
6067cf9345cSTaylor Simpson
6077cf9345cSTaylor Simpson
6087cf9345cSTaylor Simpson
6097cf9345cSTaylor Simpson
6107cf9345cSTaylor Simpson
6117cf9345cSTaylor Simpson/**********************************************/
6127cf9345cSTaylor Simpson/* 1/2 Vector operations                      */
6137cf9345cSTaylor Simpson/**********************************************/
6147cf9345cSTaylor Simpson
6157cf9345cSTaylor Simpson
6167cf9345cSTaylor SimpsonQ6INSN(A2_svavgh,"Rd32=vavgh(Rs32,Rt32)",ATTRIBS(A_ARCHV2),
6177cf9345cSTaylor Simpson"Avg vector of half integers",
6187cf9345cSTaylor Simpson{
6197cf9345cSTaylor Simpson        fHIDE(int i;)
6207cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6217cf9345cSTaylor Simpson            fSETHALF(i,RdV,((fGETHALF(i,RsV)+fGETHALF(i,RtV))>>1));
6227cf9345cSTaylor Simpson        }
6237cf9345cSTaylor Simpson})
6247cf9345cSTaylor Simpson
6257cf9345cSTaylor SimpsonQ6INSN(A2_svavghs,"Rd32=vavgh(Rs32,Rt32):rnd",ATTRIBS(A_ARCHV2),
6267cf9345cSTaylor Simpson"Avg vector of half integers with rounding",
6277cf9345cSTaylor Simpson{
6287cf9345cSTaylor Simpson        fHIDE(int i;)
6297cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6307cf9345cSTaylor Simpson            fSETHALF(i,RdV,((fGETHALF(i,RsV)+fGETHALF(i,RtV)+1)>>1));
6317cf9345cSTaylor Simpson        }
6327cf9345cSTaylor Simpson})
6337cf9345cSTaylor Simpson
6347cf9345cSTaylor Simpson
6357cf9345cSTaylor Simpson
6367cf9345cSTaylor SimpsonQ6INSN(A2_svnavgh,"Rd32=vnavgh(Rt32,Rs32)",ATTRIBS(A_ARCHV2),
6377cf9345cSTaylor Simpson"Avg vector of half integers",
6387cf9345cSTaylor Simpson{
6397cf9345cSTaylor Simpson        fHIDE(int i;)
6407cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6417cf9345cSTaylor Simpson            fSETHALF(i,RdV,((fGETHALF(i,RtV)-fGETHALF(i,RsV))>>1));
6427cf9345cSTaylor Simpson        }
6437cf9345cSTaylor Simpson})
6447cf9345cSTaylor Simpson
6457cf9345cSTaylor Simpson
6467cf9345cSTaylor SimpsonQ6INSN(A2_svaddh,"Rd32=vaddh(Rs32,Rt32)",ATTRIBS(),
6477cf9345cSTaylor Simpson"Add vector of half integers",
6487cf9345cSTaylor Simpson{
6497cf9345cSTaylor Simpson        fHIDE(int i;)
6507cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6517cf9345cSTaylor Simpson            fSETHALF(i,RdV,fGETHALF(i,RsV)+fGETHALF(i,RtV));
6527cf9345cSTaylor Simpson        }
6537cf9345cSTaylor Simpson})
6547cf9345cSTaylor Simpson
6557cf9345cSTaylor SimpsonQ6INSN(A2_svaddhs,"Rd32=vaddh(Rs32,Rt32):sat",ATTRIBS(),
6567cf9345cSTaylor Simpson"Add vector of half integers with saturation",
6577cf9345cSTaylor Simpson{
6587cf9345cSTaylor Simpson        fHIDE(int i;)
6597cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6607cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATN(16,fGETHALF(i,RsV)+fGETHALF(i,RtV)));
6617cf9345cSTaylor Simpson        }
6627cf9345cSTaylor Simpson})
6637cf9345cSTaylor Simpson
6647cf9345cSTaylor SimpsonQ6INSN(A2_svadduhs,"Rd32=vadduh(Rs32,Rt32):sat",ATTRIBS(),
6657cf9345cSTaylor Simpson"Add vector of unsigned half integers with saturation",
6667cf9345cSTaylor Simpson{
6677cf9345cSTaylor Simpson        fHIDE(int i;)
6687cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6697cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATUN(16,fGETUHALF(i,RsV)+fGETUHALF(i,RtV)));
6707cf9345cSTaylor Simpson        }
6717cf9345cSTaylor Simpson})
6727cf9345cSTaylor Simpson
6737cf9345cSTaylor Simpson
6747cf9345cSTaylor SimpsonQ6INSN(A2_svsubh,"Rd32=vsubh(Rt32,Rs32)",ATTRIBS(),
6757cf9345cSTaylor Simpson"Sub vector of half integers",
6767cf9345cSTaylor Simpson{
6777cf9345cSTaylor Simpson        fHIDE(int i;)
6787cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6797cf9345cSTaylor Simpson            fSETHALF(i,RdV,fGETHALF(i,RtV)-fGETHALF(i,RsV));
6807cf9345cSTaylor Simpson        }
6817cf9345cSTaylor Simpson})
6827cf9345cSTaylor Simpson
6837cf9345cSTaylor SimpsonQ6INSN(A2_svsubhs,"Rd32=vsubh(Rt32,Rs32):sat",ATTRIBS(),
6847cf9345cSTaylor Simpson"Sub vector of half integers with saturation",
6857cf9345cSTaylor Simpson{
6867cf9345cSTaylor Simpson        fHIDE(int i;)
6877cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6887cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATN(16,fGETHALF(i,RtV)-fGETHALF(i,RsV)));
6897cf9345cSTaylor Simpson        }
6907cf9345cSTaylor Simpson})
6917cf9345cSTaylor Simpson
6927cf9345cSTaylor SimpsonQ6INSN(A2_svsubuhs,"Rd32=vsubuh(Rt32,Rs32):sat",ATTRIBS(),
6937cf9345cSTaylor Simpson"Sub vector of unsigned half integers with saturation",
6947cf9345cSTaylor Simpson{
6957cf9345cSTaylor Simpson        fHIDE(int i;)
6967cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
6977cf9345cSTaylor Simpson            fSETHALF(i,RdV,fSATUN(16,fGETUHALF(i,RtV)-fGETUHALF(i,RsV)));
6987cf9345cSTaylor Simpson        }
6997cf9345cSTaylor Simpson})
7007cf9345cSTaylor Simpson
7017cf9345cSTaylor Simpson
7027cf9345cSTaylor Simpson
7037cf9345cSTaylor Simpson
7047cf9345cSTaylor Simpson/**********************************************/
7057cf9345cSTaylor Simpson/* Vector Reduce Add                          */
7067cf9345cSTaylor Simpson/**********************************************/
7077cf9345cSTaylor Simpson
7087cf9345cSTaylor SimpsonQ6INSN(A2_vraddub,"Rdd32=vraddub(Rss32,Rtt32)",ATTRIBS(),
7097cf9345cSTaylor Simpson"Sum: two vectors of unsigned bytes",
7107cf9345cSTaylor Simpson{
7117cf9345cSTaylor Simpson        fHIDE(int i;)
7127cf9345cSTaylor Simpson        RddV = 0;
7137cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
7147cf9345cSTaylor Simpson            fSETWORD(0,RddV,(fGETWORD(0,RddV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
7157cf9345cSTaylor Simpson        }
7167cf9345cSTaylor Simpson        for (i=4;i<8;i++) {
7177cf9345cSTaylor Simpson            fSETWORD(1,RddV,(fGETWORD(1,RddV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
7187cf9345cSTaylor Simpson        }
7197cf9345cSTaylor Simpson})
7207cf9345cSTaylor Simpson
7217cf9345cSTaylor SimpsonQ6INSN(A2_vraddub_acc,"Rxx32+=vraddub(Rss32,Rtt32)",ATTRIBS(),
7227cf9345cSTaylor Simpson"Sum: two vectors of unsigned bytes",
7237cf9345cSTaylor Simpson{
7247cf9345cSTaylor Simpson        fHIDE(int i;)
7257cf9345cSTaylor Simpson        for (i = 0; i < 4; i++) {
7267cf9345cSTaylor Simpson            fSETWORD(0,RxxV,(fGETWORD(0,RxxV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
7277cf9345cSTaylor Simpson        }
7287cf9345cSTaylor Simpson        for (i = 4; i < 8; i++) {
7297cf9345cSTaylor Simpson            fSETWORD(1,RxxV,(fGETWORD(1,RxxV) + (fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV))));
7307cf9345cSTaylor Simpson        }
7317cf9345cSTaylor Simpson})
7327cf9345cSTaylor Simpson
7337cf9345cSTaylor Simpson
7347cf9345cSTaylor Simpson
7357cf9345cSTaylor SimpsonQ6INSN(M2_vraddh,"Rd32=vraddh(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
7367cf9345cSTaylor Simpson"Sum: two vectors of halves",
7377cf9345cSTaylor Simpson{
7387cf9345cSTaylor Simpson        fHIDE(int i;)
7397cf9345cSTaylor Simpson        RdV = 0;
7407cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
7417cf9345cSTaylor Simpson            RdV += (fGETHALF(i,RssV)+fGETHALF(i,RttV));
7427cf9345cSTaylor Simpson        }
7437cf9345cSTaylor Simpson})
7447cf9345cSTaylor Simpson
7457cf9345cSTaylor SimpsonQ6INSN(M2_vradduh,"Rd32=vradduh(Rss32,Rtt32)",ATTRIBS(A_ARCHV3),
7467cf9345cSTaylor Simpson"Sum: two vectors of unsigned halves",
7477cf9345cSTaylor Simpson{
7487cf9345cSTaylor Simpson        fHIDE(int i;)
7497cf9345cSTaylor Simpson        RdV = 0;
7507cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
7517cf9345cSTaylor Simpson            RdV += (fGETUHALF(i,RssV)+fGETUHALF(i,RttV));
7527cf9345cSTaylor Simpson        }
7537cf9345cSTaylor Simpson})
7547cf9345cSTaylor Simpson
7557cf9345cSTaylor Simpson/**********************************************/
7567cf9345cSTaylor Simpson/* Vector Sub                                 */
7577cf9345cSTaylor Simpson/**********************************************/
7587cf9345cSTaylor Simpson
7597cf9345cSTaylor SimpsonQ6INSN(A2_vsubub,"Rdd32=vsubub(Rtt32,Rss32)",ATTRIBS(),
7607cf9345cSTaylor Simpson"Sub vector of bytes",
7617cf9345cSTaylor Simpson{
7627cf9345cSTaylor Simpson        fHIDE(int i;)
7637cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
7647cf9345cSTaylor Simpson            fSETBYTE(i,RddV,(fGETUBYTE(i,RttV)-fGETUBYTE(i,RssV)));
7657cf9345cSTaylor Simpson        }
7667cf9345cSTaylor Simpson})
7677cf9345cSTaylor Simpson
7687cf9345cSTaylor SimpsonQ6INSN(A2_vsububs,"Rdd32=vsubub(Rtt32,Rss32):sat",ATTRIBS(),
7697cf9345cSTaylor Simpson"Sub vector of bytes",
7707cf9345cSTaylor Simpson{
7717cf9345cSTaylor Simpson        fHIDE(int i;)
7727cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
7737cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fSATUN(8,fGETUBYTE(i,RttV)-fGETUBYTE(i,RssV)));
7747cf9345cSTaylor Simpson        }
7757cf9345cSTaylor Simpson})
7767cf9345cSTaylor Simpson
7777cf9345cSTaylor SimpsonQ6INSN(A2_vsubh,"Rdd32=vsubh(Rtt32,Rss32)",ATTRIBS(),
7787cf9345cSTaylor Simpson"Sub vector of half integers",
7797cf9345cSTaylor Simpson{
7807cf9345cSTaylor Simpson        fHIDE(int i;)
7817cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
7827cf9345cSTaylor Simpson            fSETHALF(i,RddV,fGETHALF(i,RttV)-fGETHALF(i,RssV));
7837cf9345cSTaylor Simpson        }
7847cf9345cSTaylor Simpson})
7857cf9345cSTaylor Simpson
7867cf9345cSTaylor SimpsonQ6INSN(A2_vsubhs,"Rdd32=vsubh(Rtt32,Rss32):sat",ATTRIBS(),
7877cf9345cSTaylor Simpson"Sub vector of half integers with saturation",
7887cf9345cSTaylor Simpson{
7897cf9345cSTaylor Simpson        fHIDE(int i;)
7907cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
7917cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATN(16,fGETHALF(i,RttV)-fGETHALF(i,RssV)));
7927cf9345cSTaylor Simpson        }
7937cf9345cSTaylor Simpson})
7947cf9345cSTaylor Simpson
7957cf9345cSTaylor SimpsonQ6INSN(A2_vsubuhs,"Rdd32=vsubuh(Rtt32,Rss32):sat",ATTRIBS(),
7967cf9345cSTaylor Simpson"Sub vector of unsigned half integers with saturation",
7977cf9345cSTaylor Simpson{
7987cf9345cSTaylor Simpson        fHIDE(int i;)
7997cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
8007cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATUN(16,fGETUHALF(i,RttV)-fGETUHALF(i,RssV)));
8017cf9345cSTaylor Simpson        }
8027cf9345cSTaylor Simpson})
8037cf9345cSTaylor Simpson
8047cf9345cSTaylor SimpsonQ6INSN(A2_vsubw,"Rdd32=vsubw(Rtt32,Rss32)",ATTRIBS(),
8057cf9345cSTaylor Simpson"Sub vector of words",
8067cf9345cSTaylor Simpson{
8077cf9345cSTaylor Simpson        fHIDE(int i;)
8087cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
8097cf9345cSTaylor Simpson            fSETWORD(i,RddV,fGETWORD(i,RttV)-fGETWORD(i,RssV));
8107cf9345cSTaylor Simpson        }
8117cf9345cSTaylor Simpson})
8127cf9345cSTaylor Simpson
8137cf9345cSTaylor SimpsonQ6INSN(A2_vsubws,"Rdd32=vsubw(Rtt32,Rss32):sat",ATTRIBS(),
8147cf9345cSTaylor Simpson"Sub vector of words with saturation",
8157cf9345cSTaylor Simpson{
8167cf9345cSTaylor Simpson        fHIDE(int i;)
8177cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
8187cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSATN(32,fGETWORD(i,RttV)-fGETWORD(i,RssV)));
8197cf9345cSTaylor Simpson        }
8207cf9345cSTaylor Simpson})
8217cf9345cSTaylor Simpson
8227cf9345cSTaylor Simpson
8237cf9345cSTaylor Simpson
8247cf9345cSTaylor Simpson
8257cf9345cSTaylor Simpson/**********************************************/
8267cf9345cSTaylor Simpson/* Vector Abs                                 */
8277cf9345cSTaylor Simpson/**********************************************/
8287cf9345cSTaylor Simpson
8297cf9345cSTaylor SimpsonQ6INSN(A2_vabsh,"Rdd32=vabsh(Rss32)",ATTRIBS(),
8307cf9345cSTaylor Simpson"Negate vector of half integers",
8317cf9345cSTaylor Simpson{
8327cf9345cSTaylor Simpson        fHIDE(int i;)
8337cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
8347cf9345cSTaylor Simpson            fSETHALF(i,RddV,fABS(fGETHALF(i,RssV)));
8357cf9345cSTaylor Simpson        }
8367cf9345cSTaylor Simpson})
8377cf9345cSTaylor Simpson
8387cf9345cSTaylor SimpsonQ6INSN(A2_vabshsat,"Rdd32=vabsh(Rss32):sat",ATTRIBS(),
8397cf9345cSTaylor Simpson"Negate vector of half integers",
8407cf9345cSTaylor Simpson{
8417cf9345cSTaylor Simpson        fHIDE(int i;)
8427cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
8437cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATH(fABS(fGETHALF(i,RssV))));
8447cf9345cSTaylor Simpson        }
8457cf9345cSTaylor Simpson})
8467cf9345cSTaylor Simpson
8477cf9345cSTaylor SimpsonQ6INSN(A2_vabsw,"Rdd32=vabsw(Rss32)",ATTRIBS(),
8487cf9345cSTaylor Simpson"Absolute Value vector of words",
8497cf9345cSTaylor Simpson{
8507cf9345cSTaylor Simpson        fHIDE(int i;)
8517cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
8527cf9345cSTaylor Simpson            fSETWORD(i,RddV,fABS(fGETWORD(i,RssV)));
8537cf9345cSTaylor Simpson        }
8547cf9345cSTaylor Simpson})
8557cf9345cSTaylor Simpson
8567cf9345cSTaylor SimpsonQ6INSN(A2_vabswsat,"Rdd32=vabsw(Rss32):sat",ATTRIBS(),
8577cf9345cSTaylor Simpson"Absolute Value vector of words",
8587cf9345cSTaylor Simpson{
8597cf9345cSTaylor Simpson        fHIDE(int i;)
8607cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
8617cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSAT(fABS(fGETWORD(i,RssV))));
8627cf9345cSTaylor Simpson        }
8637cf9345cSTaylor Simpson})
8647cf9345cSTaylor Simpson
8657cf9345cSTaylor Simpson/**********************************************/
8667cf9345cSTaylor Simpson/* Vector SAD                                 */
8677cf9345cSTaylor Simpson/**********************************************/
8687cf9345cSTaylor Simpson
8697cf9345cSTaylor Simpson
8707cf9345cSTaylor SimpsonQ6INSN(M2_vabsdiffw,"Rdd32=vabsdiffw(Rtt32,Rss32)",ATTRIBS(A_ARCHV2),
8717cf9345cSTaylor Simpson"Absolute Differences: vector of words",
8727cf9345cSTaylor Simpson{
8737cf9345cSTaylor Simpson        fHIDE(int i;)
8747cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
8757cf9345cSTaylor Simpson            fSETWORD(i,RddV,fABS(fGETWORD(i,RttV) - fGETWORD(i,RssV)));
8767cf9345cSTaylor Simpson        }
8777cf9345cSTaylor Simpson})
8787cf9345cSTaylor Simpson
8797cf9345cSTaylor SimpsonQ6INSN(M2_vabsdiffh,"Rdd32=vabsdiffh(Rtt32,Rss32)",ATTRIBS(A_ARCHV2),
8807cf9345cSTaylor Simpson"Absolute Differences: vector of halfwords",
8817cf9345cSTaylor Simpson{
8827cf9345cSTaylor Simpson        fHIDE(int i;)
8837cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
8847cf9345cSTaylor Simpson            fSETHALF(i,RddV,fABS(fGETHALF(i,RttV) - fGETHALF(i,RssV)));
8857cf9345cSTaylor Simpson        }
8867cf9345cSTaylor Simpson})
8877cf9345cSTaylor Simpson
8887cf9345cSTaylor SimpsonQ6INSN(M6_vabsdiffb,"Rdd32=vabsdiffb(Rtt32,Rss32)",ATTRIBS(),
8897cf9345cSTaylor Simpson"Absolute Differences: vector of halfwords",
8907cf9345cSTaylor Simpson{
8917cf9345cSTaylor Simpson        fHIDE(int i;)
8927cf9345cSTaylor Simpson        for (i=0;i<8;i++) {
8937cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fABS(fGETBYTE(i,RttV) - fGETBYTE(i,RssV)));
8947cf9345cSTaylor Simpson        }
8957cf9345cSTaylor Simpson})
8967cf9345cSTaylor Simpson
8977cf9345cSTaylor SimpsonQ6INSN(M6_vabsdiffub,"Rdd32=vabsdiffub(Rtt32,Rss32)",ATTRIBS(),
8987cf9345cSTaylor Simpson"Absolute Differences: vector of halfwords",
8997cf9345cSTaylor Simpson{
9007cf9345cSTaylor Simpson        fHIDE(int i;)
9017cf9345cSTaylor Simpson        for (i=0;i<8;i++) {
9027cf9345cSTaylor Simpson            fSETBYTE(i,RddV,fABS(fGETUBYTE(i,RttV) - fGETUBYTE(i,RssV)));
9037cf9345cSTaylor Simpson        }
9047cf9345cSTaylor Simpson})
9057cf9345cSTaylor Simpson
9067cf9345cSTaylor Simpson
9077cf9345cSTaylor Simpson
9087cf9345cSTaylor SimpsonQ6INSN(A2_vrsadub,"Rdd32=vrsadub(Rss32,Rtt32)",ATTRIBS(),
9097cf9345cSTaylor Simpson"Sum of Absolute Differences: vector of unsigned bytes",
9107cf9345cSTaylor Simpson{
9117cf9345cSTaylor Simpson        fHIDE(int i;)
9127cf9345cSTaylor Simpson        RddV = 0;
9137cf9345cSTaylor Simpson        for (i = 0; i < 4; i++) {
9147cf9345cSTaylor Simpson            fSETWORD(0,RddV,(fGETWORD(0,RddV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
9157cf9345cSTaylor Simpson        }
9167cf9345cSTaylor Simpson        for (i = 4; i < 8; i++) {
9177cf9345cSTaylor Simpson            fSETWORD(1,RddV,(fGETWORD(1,RddV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
9187cf9345cSTaylor Simpson        }
9197cf9345cSTaylor Simpson})
9207cf9345cSTaylor Simpson
9217cf9345cSTaylor SimpsonQ6INSN(A2_vrsadub_acc,"Rxx32+=vrsadub(Rss32,Rtt32)",ATTRIBS(),
9227cf9345cSTaylor Simpson"Sum of Absolute Differences: vector of unsigned bytes",
9237cf9345cSTaylor Simpson{
9247cf9345cSTaylor Simpson        fHIDE(int i;)
9257cf9345cSTaylor Simpson        for (i = 0; i < 4; i++) {
9267cf9345cSTaylor Simpson            fSETWORD(0,RxxV,(fGETWORD(0,RxxV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
9277cf9345cSTaylor Simpson        }
9287cf9345cSTaylor Simpson        for (i = 4; i < 8; i++) {
9297cf9345cSTaylor Simpson            fSETWORD(1,RxxV,(fGETWORD(1,RxxV) + fABS((fGETUBYTE(i,RssV) - fGETUBYTE(i,RttV)))));
9307cf9345cSTaylor Simpson        }
9317cf9345cSTaylor Simpson})
9327cf9345cSTaylor Simpson
9337cf9345cSTaylor Simpson
9347cf9345cSTaylor Simpson/**********************************************/
9357cf9345cSTaylor Simpson/* Vector Average                             */
9367cf9345cSTaylor Simpson/**********************************************/
9377cf9345cSTaylor Simpson
9387cf9345cSTaylor SimpsonQ6INSN(A2_vavgub,"Rdd32=vavgub(Rss32,Rtt32)",ATTRIBS(),
9397cf9345cSTaylor Simpson"Average vector of unsigned bytes",
9407cf9345cSTaylor Simpson{
9417cf9345cSTaylor Simpson        fHIDE(int i;)
9427cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
9437cf9345cSTaylor Simpson            fSETBYTE(i,RddV,((fGETUBYTE(i,RssV) + fGETUBYTE(i,RttV))>>1));
9447cf9345cSTaylor Simpson        }
9457cf9345cSTaylor Simpson})
9467cf9345cSTaylor Simpson
9477cf9345cSTaylor SimpsonQ6INSN(A2_vavguh,"Rdd32=vavguh(Rss32,Rtt32)",ATTRIBS(),
9487cf9345cSTaylor Simpson"Average vector of unsigned halfwords",
9497cf9345cSTaylor Simpson{
9507cf9345cSTaylor Simpson        fHIDE(int i;)
9517cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
9527cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETUHALF(i,RssV)+fGETUHALF(i,RttV))>>1);
9537cf9345cSTaylor Simpson        }
9547cf9345cSTaylor Simpson})
9557cf9345cSTaylor Simpson
9567cf9345cSTaylor SimpsonQ6INSN(A2_vavgh,"Rdd32=vavgh(Rss32,Rtt32)",ATTRIBS(),
9577cf9345cSTaylor Simpson"Average vector of halfwords",
9587cf9345cSTaylor Simpson{
9597cf9345cSTaylor Simpson        fHIDE(int i;)
9607cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
9617cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETHALF(i,RssV)+fGETHALF(i,RttV))>>1);
9627cf9345cSTaylor Simpson        }
9637cf9345cSTaylor Simpson})
9647cf9345cSTaylor Simpson
9657cf9345cSTaylor SimpsonQ6INSN(A2_vnavgh,"Rdd32=vnavgh(Rtt32,Rss32)",ATTRIBS(),
9667cf9345cSTaylor Simpson"Negative Average vector of halfwords",
9677cf9345cSTaylor Simpson{
9687cf9345cSTaylor Simpson        fHIDE(int i;)
9697cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
9707cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETHALF(i,RttV)-fGETHALF(i,RssV))>>1);
9717cf9345cSTaylor Simpson        }
9727cf9345cSTaylor Simpson})
9737cf9345cSTaylor Simpson
9747cf9345cSTaylor SimpsonQ6INSN(A2_vavgw,"Rdd32=vavgw(Rss32,Rtt32)",ATTRIBS(),
9757cf9345cSTaylor Simpson"Average vector of words",
9767cf9345cSTaylor Simpson{
9777cf9345cSTaylor Simpson        fHIDE(int i;)
9787cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
9797cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fSXTN(32,33,fGETWORD(i,RssV))+fSXTN(32,33,fGETWORD(i,RttV)))>>1);
9807cf9345cSTaylor Simpson        }
9817cf9345cSTaylor Simpson})
9827cf9345cSTaylor Simpson
9837cf9345cSTaylor SimpsonQ6INSN(A2_vnavgw,"Rdd32=vnavgw(Rtt32,Rss32)",ATTRIBS(A_ARCHV2),
9847cf9345cSTaylor Simpson"Average vector of words",
9857cf9345cSTaylor Simpson{
9867cf9345cSTaylor Simpson        fHIDE(int i;)
9877cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
9887cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fSXTN(32,33,fGETWORD(i,RttV))-fSXTN(32,33,fGETWORD(i,RssV)))>>1);
9897cf9345cSTaylor Simpson        }
9907cf9345cSTaylor Simpson})
9917cf9345cSTaylor Simpson
9927cf9345cSTaylor SimpsonQ6INSN(A2_vavgwr,"Rdd32=vavgw(Rss32,Rtt32):rnd",ATTRIBS(),
9937cf9345cSTaylor Simpson"Average vector of words",
9947cf9345cSTaylor Simpson{
9957cf9345cSTaylor Simpson        fHIDE(int i;)
9967cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
9977cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fSXTN(32,33,fGETWORD(i,RssV))+fSXTN(32,33,fGETWORD(i,RttV))+1)>>1);
9987cf9345cSTaylor Simpson        }
9997cf9345cSTaylor Simpson})
10007cf9345cSTaylor Simpson
10017cf9345cSTaylor SimpsonQ6INSN(A2_vnavgwr,"Rdd32=vnavgw(Rtt32,Rss32):rnd:sat",ATTRIBS(A_ARCHV2),
10027cf9345cSTaylor Simpson"Average vector of words",
10037cf9345cSTaylor Simpson{
10047cf9345cSTaylor Simpson        fHIDE(int i;)
10057cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10067cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSAT((fSXTN(32,33,fGETWORD(i,RttV))-fSXTN(32,33,fGETWORD(i,RssV))+1)>>1));
10077cf9345cSTaylor Simpson        }
10087cf9345cSTaylor Simpson})
10097cf9345cSTaylor Simpson
10107cf9345cSTaylor SimpsonQ6INSN(A2_vavgwcr,"Rdd32=vavgw(Rss32,Rtt32):crnd",ATTRIBS(A_ARCHV2),
10117cf9345cSTaylor Simpson"Average vector of words with convergent rounding",
10127cf9345cSTaylor Simpson{
10137cf9345cSTaylor Simpson        fHIDE(int i;)
10147cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10157cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fCRND(fSXTN(32,33,fGETWORD(i,RssV))+fSXTN(32,33,fGETWORD(i,RttV)))>>1));
10167cf9345cSTaylor Simpson        }
10177cf9345cSTaylor Simpson})
10187cf9345cSTaylor Simpson
10197cf9345cSTaylor SimpsonQ6INSN(A2_vnavgwcr,"Rdd32=vnavgw(Rtt32,Rss32):crnd:sat",ATTRIBS(A_ARCHV2),
10207cf9345cSTaylor Simpson"Average negative vector of words with convergent rounding",
10217cf9345cSTaylor Simpson{
10227cf9345cSTaylor Simpson        fHIDE(int i;)
10237cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10247cf9345cSTaylor Simpson            fSETWORD(i,RddV,fSAT(fCRND(fSXTN(32,33,fGETWORD(i,RttV))-fSXTN(32,33,fGETWORD(i,RssV)))>>1));
10257cf9345cSTaylor Simpson        }
10267cf9345cSTaylor Simpson})
10277cf9345cSTaylor Simpson
10287cf9345cSTaylor SimpsonQ6INSN(A2_vavghcr,"Rdd32=vavgh(Rss32,Rtt32):crnd",ATTRIBS(A_ARCHV2),
10297cf9345cSTaylor Simpson"Average vector of halfwords with conv rounding",
10307cf9345cSTaylor Simpson{
10317cf9345cSTaylor Simpson        fHIDE(int i;)
10327cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
10337cf9345cSTaylor Simpson            fSETHALF(i,RddV,fCRND(fGETHALF(i,RssV)+fGETHALF(i,RttV))>>1);
10347cf9345cSTaylor Simpson        }
10357cf9345cSTaylor Simpson})
10367cf9345cSTaylor Simpson
10377cf9345cSTaylor SimpsonQ6INSN(A2_vnavghcr,"Rdd32=vnavgh(Rtt32,Rss32):crnd:sat",ATTRIBS(A_ARCHV2),
10387cf9345cSTaylor Simpson"Average negative vector of halfwords with conv rounding",
10397cf9345cSTaylor Simpson{
10407cf9345cSTaylor Simpson        fHIDE(int i;)
10417cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
10427cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATH(fCRND(fGETHALF(i,RttV)-fGETHALF(i,RssV))>>1));
10437cf9345cSTaylor Simpson        }
10447cf9345cSTaylor Simpson})
10457cf9345cSTaylor Simpson
10467cf9345cSTaylor Simpson
10477cf9345cSTaylor SimpsonQ6INSN(A2_vavguw,"Rdd32=vavguw(Rss32,Rtt32)",ATTRIBS(),
10487cf9345cSTaylor Simpson"Average vector of unsigned words",
10497cf9345cSTaylor Simpson{
10507cf9345cSTaylor Simpson        fHIDE(int i;)
10517cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10527cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fZXTN(32,33,fGETUWORD(i,RssV))+fZXTN(32,33,fGETUWORD(i,RttV)))>>1);
10537cf9345cSTaylor Simpson        }
10547cf9345cSTaylor Simpson})
10557cf9345cSTaylor Simpson
10567cf9345cSTaylor SimpsonQ6INSN(A2_vavguwr,"Rdd32=vavguw(Rss32,Rtt32):rnd",ATTRIBS(),
10577cf9345cSTaylor Simpson"Average vector of unsigned words",
10587cf9345cSTaylor Simpson{
10597cf9345cSTaylor Simpson        fHIDE(int i;)
10607cf9345cSTaylor Simpson        for (i=0;i<2;i++) {
10617cf9345cSTaylor Simpson            fSETWORD(i,RddV,(fZXTN(32,33,fGETUWORD(i,RssV))+fZXTN(32,33,fGETUWORD(i,RttV))+1)>>1);
10627cf9345cSTaylor Simpson        }
10637cf9345cSTaylor Simpson})
10647cf9345cSTaylor Simpson
10657cf9345cSTaylor SimpsonQ6INSN(A2_vavgubr,"Rdd32=vavgub(Rss32,Rtt32):rnd",ATTRIBS(),
10667cf9345cSTaylor Simpson"Average vector of unsigned bytes",
10677cf9345cSTaylor Simpson{
10687cf9345cSTaylor Simpson        fHIDE(int i;)
10697cf9345cSTaylor Simpson        for (i = 0; i < 8; i++) {
10707cf9345cSTaylor Simpson            fSETBYTE(i,RddV,((fGETUBYTE(i,RssV)+fGETUBYTE(i,RttV)+1)>>1));
10717cf9345cSTaylor Simpson        }
10727cf9345cSTaylor Simpson})
10737cf9345cSTaylor Simpson
10747cf9345cSTaylor SimpsonQ6INSN(A2_vavguhr,"Rdd32=vavguh(Rss32,Rtt32):rnd",ATTRIBS(),
10757cf9345cSTaylor Simpson"Average vector of unsigned halfwords with rounding",
10767cf9345cSTaylor Simpson{
10777cf9345cSTaylor Simpson        fHIDE(int i;)
10787cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
10797cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETUHALF(i,RssV)+fGETUHALF(i,RttV)+1)>>1);
10807cf9345cSTaylor Simpson        }
10817cf9345cSTaylor Simpson})
10827cf9345cSTaylor Simpson
10837cf9345cSTaylor SimpsonQ6INSN(A2_vavghr,"Rdd32=vavgh(Rss32,Rtt32):rnd",ATTRIBS(),
10847cf9345cSTaylor Simpson"Average vector of halfwords with rounding",
10857cf9345cSTaylor Simpson{
10867cf9345cSTaylor Simpson        fHIDE(int i;)
10877cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
10887cf9345cSTaylor Simpson            fSETHALF(i,RddV,(fGETHALF(i,RssV)+fGETHALF(i,RttV)+1)>>1);
10897cf9345cSTaylor Simpson        }
10907cf9345cSTaylor Simpson})
10917cf9345cSTaylor Simpson
10927cf9345cSTaylor SimpsonQ6INSN(A2_vnavghr,"Rdd32=vnavgh(Rtt32,Rss32):rnd:sat",ATTRIBS(A_ARCHV2),
10937cf9345cSTaylor Simpson"Negative Average vector of halfwords with rounding",
10947cf9345cSTaylor Simpson{
10957cf9345cSTaylor Simpson        fHIDE(int i;)
10967cf9345cSTaylor Simpson        for (i=0;i<4;i++) {
10977cf9345cSTaylor Simpson            fSETHALF(i,RddV,fSATH((fGETHALF(i,RttV)-fGETHALF(i,RssV)+1)>>1));
10987cf9345cSTaylor Simpson        }
10997cf9345cSTaylor Simpson})
11007cf9345cSTaylor Simpson
11017cf9345cSTaylor Simpson
11027cf9345cSTaylor Simpson/* Rounding Instruction */
11037cf9345cSTaylor Simpson
11047cf9345cSTaylor SimpsonQ6INSN(A4_round_ri,"Rd32=round(Rs32,#u5)",ATTRIBS(),"Round", {RdV = fRNDN(RsV,uiV)>>uiV; })
11057cf9345cSTaylor SimpsonQ6INSN(A4_round_rr,"Rd32=round(Rs32,Rt32)",ATTRIBS(),"Round", {RdV = fRNDN(RsV,fZXTN(5,32,RtV))>>fZXTN(5,32,RtV); })
11067cf9345cSTaylor SimpsonQ6INSN(A4_round_ri_sat,"Rd32=round(Rs32,#u5):sat",ATTRIBS(),"Round", {RdV = (fSAT(fRNDN(RsV,uiV)))>>uiV; })
11077cf9345cSTaylor SimpsonQ6INSN(A4_round_rr_sat,"Rd32=round(Rs32,Rt32):sat",ATTRIBS(),"Round", {RdV = (fSAT(fRNDN(RsV,fZXTN(5,32,RtV))))>>fZXTN(5,32,RtV); })
11087cf9345cSTaylor Simpson
11097cf9345cSTaylor Simpson
11107cf9345cSTaylor SimpsonQ6INSN(A4_cround_ri,"Rd32=cround(Rs32,#u5)",ATTRIBS(),"Convergent Round", {RdV = fCRNDN(RsV,uiV); })
11117cf9345cSTaylor SimpsonQ6INSN(A4_cround_rr,"Rd32=cround(Rs32,Rt32)",ATTRIBS(),"Convergent Round", {RdV = fCRNDN(RsV,fZXTN(5,32,RtV)); })
11127cf9345cSTaylor Simpson
11137cf9345cSTaylor Simpson
11147cf9345cSTaylor Simpson#define CROUND(DST,SRC,SHIFT) \
11157cf9345cSTaylor Simpson        fHIDE(size16s_t rndbit_128;)\
11167cf9345cSTaylor Simpson        fHIDE(size16s_t tmp128;)\
11177cf9345cSTaylor Simpson        fHIDE(size16s_t src_128;)\
11187cf9345cSTaylor Simpson        if (SHIFT == 0) { \
11197cf9345cSTaylor Simpson            DST = SRC;\
11207cf9345cSTaylor Simpson        } else if ((SRC & (size8s_t)((1LL << (SHIFT - 1)) - 1LL)) == 0) { \
11217cf9345cSTaylor Simpson            src_128 = fCAST8S_16S(SRC);\
11227cf9345cSTaylor Simpson            rndbit_128 = fCAST8S_16S(1LL);\
11237cf9345cSTaylor Simpson            rndbit_128 = fSHIFTL128(rndbit_128, SHIFT);\
11247cf9345cSTaylor Simpson            rndbit_128 = fAND128(rndbit_128, src_128);\
11257cf9345cSTaylor Simpson            rndbit_128 = fSHIFTR128(rndbit_128, 1);\
11267cf9345cSTaylor Simpson            tmp128 = fADD128(src_128, rndbit_128);\
11277cf9345cSTaylor Simpson            tmp128 = fSHIFTR128(tmp128, SHIFT);\
11287cf9345cSTaylor Simpson            DST =  fCAST16S_8S(tmp128);\
11297cf9345cSTaylor Simpson        } else {\
11307cf9345cSTaylor Simpson            size16s_t rndbit_128 =  fCAST8S_16S((1LL << (SHIFT - 1))); \
11317cf9345cSTaylor Simpson            size16s_t src_128 =  fCAST8S_16S(SRC); \
11327cf9345cSTaylor Simpson            size16s_t tmp128 = fADD128(src_128, rndbit_128);\
11337cf9345cSTaylor Simpson            tmp128 = fSHIFTR128(tmp128, SHIFT);\
11347cf9345cSTaylor Simpson            DST =  fCAST16S_8S(tmp128);\
11357cf9345cSTaylor Simpson        }
11367cf9345cSTaylor Simpson
11377cf9345cSTaylor SimpsonQ6INSN(A7_croundd_ri,"Rdd32=cround(Rss32,#u6)",ATTRIBS(),"Convergent Round",
11387cf9345cSTaylor Simpson{
11397cf9345cSTaylor SimpsonCROUND(RddV,RssV,uiV);
11407cf9345cSTaylor Simpson})
11417cf9345cSTaylor Simpson
11427cf9345cSTaylor SimpsonQ6INSN(A7_croundd_rr,"Rdd32=cround(Rss32,Rt32)",ATTRIBS(),"Convergent Round",
11437cf9345cSTaylor Simpson{
11447cf9345cSTaylor SimpsonCROUND(RddV,RssV,fZXTN(6,32,RtV));
11457cf9345cSTaylor Simpson})
11467cf9345cSTaylor Simpson
11477cf9345cSTaylor Simpson
11487cf9345cSTaylor Simpson
11497cf9345cSTaylor Simpson
11507cf9345cSTaylor Simpson
11517cf9345cSTaylor Simpson
11527cf9345cSTaylor Simpson
11537cf9345cSTaylor Simpson
11547cf9345cSTaylor Simpson
11557cf9345cSTaylor SimpsonQ6INSN(A7_clip,"Rd32=clip(Rs32,#u5)",ATTRIBS(),"Clip to  #s5", {   fCLIP(RdV,RsV,uiV);})
11567cf9345cSTaylor SimpsonQ6INSN(A7_vclip,"Rdd32=vclip(Rss32,#u5)",ATTRIBS(),"Clip to  #s5",
11577cf9345cSTaylor Simpson{
11587cf9345cSTaylor SimpsonfHIDE(size4s_t tmp;)
11597cf9345cSTaylor SimpsonfCLIP(tmp, fGETWORD(0, RssV), uiV);
11607cf9345cSTaylor SimpsonfSETWORD(0, RddV, tmp);
11617cf9345cSTaylor SimpsonfCLIP(tmp,fGETWORD(1, RssV), uiV);
11627cf9345cSTaylor SimpsonfSETWORD(1, RddV, tmp);
11637cf9345cSTaylor Simpson}
11647cf9345cSTaylor Simpson)
11657cf9345cSTaylor Simpson
11667cf9345cSTaylor Simpson
11677cf9345cSTaylor Simpson
11687cf9345cSTaylor Simpson/**********************************************/
11697cf9345cSTaylor Simpson/* V4: Cross Vector Min/Max                   */
11707cf9345cSTaylor Simpson/**********************************************/
11717cf9345cSTaylor Simpson
11727cf9345cSTaylor Simpson
11737cf9345cSTaylor Simpson#define VRMINORMAX(TAG,STR,OP,SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT) \
11747cf9345cSTaylor SimpsonQ6INSN(A4_vr##TAG##SHORTTYPE,"Rxx32=vr"#TAG#SHORTTYPE"(Rss32,Ru32)",ATTRIBS(), \
11757cf9345cSTaylor Simpson"Choose " STR " elements of a vector", \
11767cf9345cSTaylor Simpson{ \
11777cf9345cSTaylor Simpson        fHIDE(int i; size8s_t TAG; size4s_t addr;) \
11787cf9345cSTaylor Simpson        TAG = fGET##GETTYPE(0,RxxV); \
11797cf9345cSTaylor Simpson        addr = fGETWORD(1,RxxV); \
11807cf9345cSTaylor Simpson        for (i = 0; i < NEL; i++) { \
11817cf9345cSTaylor Simpson            if (TAG OP fGET##GETTYPE(i,RssV)) { \
11827cf9345cSTaylor Simpson                TAG = fGET##GETTYPE(i,RssV); \
11837cf9345cSTaylor Simpson                addr = RuV | i<<SHIFT; \
11847cf9345cSTaylor Simpson            } \
11857cf9345cSTaylor Simpson        } \
11867cf9345cSTaylor Simpson        fSETWORD(0,RxxV,TAG); \
11877cf9345cSTaylor Simpson        fSETWORD(1,RxxV,addr); \
11887cf9345cSTaylor Simpson})
11897cf9345cSTaylor Simpson
11907cf9345cSTaylor Simpson#define RMINMAX(SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT) \
11917cf9345cSTaylor SimpsonVRMINORMAX(min,"minimum",>,SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT) \
11927cf9345cSTaylor SimpsonVRMINORMAX(max,"maximum",<,SHORTTYPE,SETTYPE,GETTYPE,NEL,SHIFT)
11937cf9345cSTaylor Simpson
11947cf9345cSTaylor Simpson
11957cf9345cSTaylor SimpsonRMINMAX(h,HALF,HALF,4,1)
11967cf9345cSTaylor SimpsonRMINMAX(uh,HALF,UHALF,4,1)
11977cf9345cSTaylor SimpsonRMINMAX(w,WORD,WORD,2,2)
11987cf9345cSTaylor SimpsonRMINMAX(uw,WORD,UWORD,2,2)
11997cf9345cSTaylor Simpson
12007cf9345cSTaylor Simpson#undef RMINMAX
12017cf9345cSTaylor Simpson#undef VRMINORMAX
12027cf9345cSTaylor Simpson
12037cf9345cSTaylor Simpson/**********************************************/
12047cf9345cSTaylor Simpson/* Vector Min/Max                             */
12057cf9345cSTaylor Simpson/**********************************************/
12067cf9345cSTaylor Simpson
12077cf9345cSTaylor Simpson#define VMINORMAX(TAG,STR,FUNC,SHORTTYPE,SETTYPE,GETTYPE,NEL) \
12087cf9345cSTaylor SimpsonQ6INSN(A2_v##TAG##SHORTTYPE,"Rdd32=v"#TAG#SHORTTYPE"(Rtt32,Rss32)",ATTRIBS(), \
12097cf9345cSTaylor Simpson"Choose " STR " elements of two vectors", \
12107cf9345cSTaylor Simpson{ \
12117cf9345cSTaylor Simpson        fHIDE(int i;) \
12127cf9345cSTaylor Simpson        for (i = 0; i < NEL; i++) { \
12137cf9345cSTaylor Simpson            fSET##SETTYPE(i,RddV,FUNC(fGET##GETTYPE(i,RttV),fGET##GETTYPE(i,RssV))); \
12147cf9345cSTaylor Simpson        } \
12157cf9345cSTaylor Simpson})
12167cf9345cSTaylor Simpson
12177cf9345cSTaylor Simpson#define VMINORMAX3(TAG,STR,FUNC,SHORTTYPE,SETTYPE,GETTYPE,NEL) \
12187cf9345cSTaylor SimpsonQ6INSN(A6_v##TAG##SHORTTYPE##3,"Rxx32=v"#TAG#SHORTTYPE"3(Rtt32,Rss32)",ATTRIBS(), \
12197cf9345cSTaylor Simpson"Choose " STR " elements of two vectors", \
12207cf9345cSTaylor Simpson{ \
12217cf9345cSTaylor Simpson        fHIDE(int i;) \
12227cf9345cSTaylor Simpson        for (i = 0; i < NEL; i++) { \
12237cf9345cSTaylor Simpson            fSET##SETTYPE(i,RxxV,FUNC(fGET##GETTYPE(i,RxxV),FUNC(fGET##GETTYPE(i,RttV),fGET##GETTYPE(i,RssV)))); \
12247cf9345cSTaylor Simpson        } \
12257cf9345cSTaylor Simpson})
12267cf9345cSTaylor Simpson
12277cf9345cSTaylor Simpson#define MINMAX(SHORTTYPE,SETTYPE,GETTYPE,NEL) \
12287cf9345cSTaylor SimpsonVMINORMAX(min,"minimum",fMIN,SHORTTYPE,SETTYPE,GETTYPE,NEL) \
12297cf9345cSTaylor SimpsonVMINORMAX(max,"maximum",fMAX,SHORTTYPE,SETTYPE,GETTYPE,NEL)
12307cf9345cSTaylor Simpson
12317cf9345cSTaylor SimpsonMINMAX(b,BYTE,BYTE,8)
12327cf9345cSTaylor SimpsonMINMAX(ub,BYTE,UBYTE,8)
12337cf9345cSTaylor SimpsonMINMAX(h,HALF,HALF,4)
12347cf9345cSTaylor SimpsonMINMAX(uh,HALF,UHALF,4)
12357cf9345cSTaylor SimpsonMINMAX(w,WORD,WORD,2)
12367cf9345cSTaylor SimpsonMINMAX(uw,WORD,UWORD,2)
12377cf9345cSTaylor Simpson
12387cf9345cSTaylor Simpson#undef MINMAX
12397cf9345cSTaylor Simpson#undef VMINORMAX
12407cf9345cSTaylor Simpson#undef VMINORMAX3
12417cf9345cSTaylor Simpson
12427cf9345cSTaylor Simpson
1243*da74cd2dSTaylor SimpsonQ6INSN(A5_ACS,"Rxx32,Pe4=vacsh(Rss32,Rtt32)",ATTRIBS(),
1244*da74cd2dSTaylor Simpson"Add Compare and Select elements of two vectors, record the maximums and the decisions ",
1245*da74cd2dSTaylor Simpson{
1246*da74cd2dSTaylor Simpson        fHIDE(int i;)
1247*da74cd2dSTaylor Simpson        fHIDE(int xv;)
1248*da74cd2dSTaylor Simpson        fHIDE(int sv;)
1249*da74cd2dSTaylor Simpson        fHIDE(int tv;)
1250*da74cd2dSTaylor Simpson        for (i = 0; i < 4; i++) {
1251*da74cd2dSTaylor Simpson                xv = (int) fGETHALF(i,RxxV);
1252*da74cd2dSTaylor Simpson                sv = (int) fGETHALF(i,RssV);
1253*da74cd2dSTaylor Simpson                tv = (int) fGETHALF(i,RttV);
1254*da74cd2dSTaylor Simpson                xv = xv + tv;           //assumes 17bit datapath
1255*da74cd2dSTaylor Simpson                sv = sv - tv;           //assumes 17bit datapath
1256*da74cd2dSTaylor Simpson                fSETBIT(i*2,  PeV,  (xv > sv));
1257*da74cd2dSTaylor Simpson                fSETBIT(i*2+1,PeV,  (xv > sv));
1258*da74cd2dSTaylor Simpson                fSETHALF(i,   RxxV, fSATH(fMAX(xv,sv)));
1259*da74cd2dSTaylor Simpson        }
1260*da74cd2dSTaylor Simpson})
1261*da74cd2dSTaylor Simpson
12627cf9345cSTaylor Simpson/**********************************************/
12637cf9345cSTaylor Simpson/* Vector Min/Max                             */
12647cf9345cSTaylor Simpson/**********************************************/
12657cf9345cSTaylor Simpson
12667cf9345cSTaylor Simpson
12677cf9345cSTaylor SimpsonQ6INSN(A4_modwrapu,"Rd32=modwrap(Rs32,Rt32)",ATTRIBS(),
12687cf9345cSTaylor Simpson"Wrap to an unsigned modulo buffer",
12697cf9345cSTaylor Simpson{
12707cf9345cSTaylor Simpson        if (RsV < 0) {
12717cf9345cSTaylor Simpson            RdV = RsV + fCAST4u(RtV);
12727cf9345cSTaylor Simpson        } else if (fCAST4u(RsV) >= fCAST4u(RtV)) {
12737cf9345cSTaylor Simpson            RdV = RsV - fCAST4u(RtV);
12747cf9345cSTaylor Simpson        } else {
12757cf9345cSTaylor Simpson            RdV = RsV;
12767cf9345cSTaylor Simpson        }
12777cf9345cSTaylor Simpson})
1278