| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758 |
- /*
- * Copyright (c) 2006-2010 Tensilica Inc. ALL RIGHTS RESERVED.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- #ifndef __C6X_COMPAT__H
- #define __C6X_COMPAT__H
- /* Unimplemented functions _gmpy, _gmpy4, _xormpy, _lssub, _cmpy, _cmpyr,
- _cmpyr1, _ddotpl2r, _ddotph2r */
- typedef long long C6X_COMPAT_LONG40;
- #define _memd8(a) (*((double*)(a)))
- #define _memd8_const(a) (*((const double*)(a)))
- #define _amemd8(a) (*((double*)(a)))
- #define _amemd8_const(a) (*((const double*)(a)))
- #define _mem8(a) (*((unsigned long long*)(a)))
- #define _mem8_const(a) (*((const unsigned long long*)(a)))
- #define _mem4(a) (*((unsigned*)(a)))
- #define _mem4_const(a) (*((const unsigned*)(a)))
- #define _amem4_const(a) (*((const unsigned*)(a)))
- /* NOTE: To emulate a C6X properly you should define global variables
- for your Xtensa with these names. Some of the emulation routines
- will set these values. */
- extern int _carry;
- extern int _overflow;
- // Utility routines
- #define TESTBIT(x,n) (((x) >> (n)) & 1)
- #define NSA_BITS 32
- static inline unsigned int norm_shift_amt_U_and_non_U(int is_signed, int inp) {
- int j=0, k=0;
- int x=inp;
- if (is_signed) {
- /* Invert signed val if negative */
- x= TESTBIT(x,(NSA_BITS-1))? ~x: x;
- x= (x&1)|(x<<1); /* Shift up to return count-1 */
- if (x ==0)
- return NSA_BITS-1;
- }
- if (x ==0)
- return NSA_BITS;
- /* Now count leading zeros */
- for (j=0, k=NSA_BITS-1; k>=0; j++, k--) {
- if (TESTBIT(x,k))
- return j;
- }
- return NSA_BITS;
- }
- static inline long long
- orig_L40_set( long long L40_var1) {
- long long L40_var_out;
-
- L40_var_out = L40_var1 & 0x000000ffffffffffLL;
- if( L40_var1 & 0x8000000000LL)
- L40_var_out = L40_var_out | 0xffffff0000000000LL;
- return( L40_var_out);
- }
- static inline signed long long
- util_saturate_n_no_state(signed long long t, int n)
- {
- signed long long maxv, minv;
- maxv = (1LL << (n-1)) - 1;
- minv = (-1LL << (n-1));
- if (t > maxv) {
- t = maxv;
- } else if (t < minv) {
- t = minv;
- }
- return t;
- }
- static inline signed long long
- util_saturate_n_sgn(signed long long t, int n)
- {
- signed long long result;
- signed long long maxv, minv;
- maxv = (1LL << (n-1)) - 1;
- minv = (-1LL << (n-1));
- if (t > 0) {
- result = maxv;
- _overflow = 1;
- } else if (t < 0) {
- result = minv;
- _overflow = 1;
- } else {
- result = 0;
- }
- return result;
- }
- /* well-behaved signed shift right (left on negative) with
- saturation */
- static inline signed long long
- util_shift_right_saturate_n(signed long long t, int shval, int n)
- {
- /* n should be <= 62 */
- long long result;
- signed long long mask;
- int actual_shift = shval;
- long long shft = actual_shift > 0 ? actual_shift : -actual_shift;
- if (t == 0 || actual_shift == 0)
- return t;
- if (actual_shift >= n) {
- return (t < 0) ? -1 : 0;
- }
- if (actual_shift <= -n) {
- return util_saturate_n_sgn(t, n);
- }
- if (actual_shift > 0) {
- return t >> actual_shift;
- }
- /* actual_shift < 0. Check for saturation after shift. */
- mask = (-1LL << (n-shft-1));
- if (t > 0 && ((mask & t) != 0)) {
- return util_saturate_n_sgn(t, n);
- }
- if (t < 0 && ((mask & t) != mask)) {
- return util_saturate_n_sgn(t, n);
- }
- result = t << shft;
- return result;
- }
- /* Implemented c6x standard C compatibility functions (alphabetical
- order) */
- static inline int _abs(int src1) {
- if ((unsigned) src1 == (unsigned) 0x80000000) {
- return 0x7fffffff;
- }
- return abs(src1);
- }
- static inline int _abs2(int src1) {
- short s1[2],r[2];
- int result;
- *((int*)s1) = src1;
- if ((unsigned short) s1[1] == (unsigned short) 0x8000) r[1] = 0x7fff;
- else r[1] = abs(s1[1]);
- if ((unsigned short) s1[0] == (unsigned short) 0x8000) r[0] = 0x7fff;
- else r[0] = abs(s1[0]);
- result = *(int*)r;
- return result;
- }
- static inline int _add2(int src1, int src2) {
- short s1[2], s2[2], r[2];
- int result;
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- r[0] = s1[0] + s2[0];
- r[1] = s1[1] + s2[1];
- result = *(int*)r;
- return result;
- }
- static inline int _add4(int src1, int src2) {
- char c1[4], c2[4], r[4];
- int result;
- *((int*)c1) = src1;
- *((int*)c2) = src2;
- r[0] = c1[0] + c2[0];
- r[1] = c1[1] + c2[1];
- r[2] = c1[2] + c2[2];
- r[3] = c1[3] + c2[3];
- result = *(int*)r;
- return result;
- }
- static inline long long _addsub(unsigned int src1, unsigned int src2)
- {
-
- int res_lo;
- int res_hi;
-
- res_hi = src1+src2;
- res_lo = src1-src2;
- return (((unsigned long long) res_hi) << 32) | ((unsigned int) res_lo) ;
- }
-
- static inline long long _addsub2(unsigned int src1, unsigned int src2)
- {
- short s1[2], s2[2], ra[2], rs[2];
- int res_lo;
- int res_hi;
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- ra[0] = s1[0] + s2[0];
- ra[1] = s1[1] + s2[1];
- rs[0] = s1[0] - s2[0];
- rs[1] = s1[1] - s2[1];
-
- res_hi = *(int*)ra;
- res_lo = *(int*)rs;
- return (((unsigned long long) res_hi) << 32) | ((unsigned int) res_lo) ;
- }
- static inline int _avg2(int src1, int src2) {
- int low = (((int)1 + (short) src1 + (short) src2) >> 1) & 0XFFFF;
- int high1 = src1 >> 16;
- int high2 = src2 >> 16;
- int high = ((high1 + high2 + 1) >> 1)<< 16;
- return high | low;
- }
- static inline unsigned int _avgu4(unsigned int src1, unsigned int src2) {
- unsigned int res0 = ((src1 & 0xFF) + (src2 & 0xFF) + 1) >> 1;
- unsigned int res1 = (((src1 & 0xFF00) >> 8) + ((src2 & 0xFF00) >> 8) + 1) >> 1;
- unsigned int res2 = (((src1 & 0xFF0000) >> 16) + ((src2 & 0xFF0000) >> 16) + 1) >> 1;
- unsigned int res3 = (((src1 & 0xFF000000) >> 24) + ((src2 & 0xFF000000) >> 24) + 1) >> 1;
- return (res3 << 24) | (res2 << 16) | (res1 << 8) | res0;
- }
- static inline int TEN_popc (unsigned char b)
- {
- int i, result = 0;
- for (i = 0; i < 8; i++){
- if (b & 0x1)
- result++;
- b >>= 1;
- }
- return result;
- }
- static inline unsigned int _bitc4(unsigned int src1)
- {
- unsigned int res0 = TEN_popc(src1 & 0xFF);
- unsigned int res1 = TEN_popc((src1 & 0xFF00) >> 8);
- unsigned int res2 = TEN_popc((src1 & 0xFF0000) >> 16);
- unsigned int res3 = TEN_popc((src1 & 0xFF000000) >> 24);
- return (res3 << 24) | (res2 << 16) | (res1 << 8) | res0;
- }
- static inline unsigned int _bitr(unsigned int src) {
- int i;
- unsigned r = 0;
- for (i = 0; i< 32; ++i) {
- r = r | (((src >> i) & 1)<<(31-i));
- }
- return r;
- }
- static inline unsigned int _clr(unsigned int src2, int csta, int cstb)
- {
- csta &= 0x1f;
- cstb &= 0x1f;
- if (csta > cstb)
- return src2;
- else {
- unsigned int mask = (((1 << (cstb - csta)) << 1) - 1) << csta;
- return src2 & (~mask);
- }
- }
- static inline unsigned int _clrr(unsigned int src2, int src1)
- {
- unsigned int csta = (src1 >> 5) & 0x1f;
- unsigned int cstb = src1 & 0x1f;
- if (csta > cstb)
- return src2;
- else {
- unsigned int mask = (((1 << (cstb - csta)) << 1) - 1) << csta;
- return src2 & (~mask);
- }
- }
- static inline int _cmpeq2(int src1, int src2) {
- short s1[2], s2[2];
- int r0, r1;
- int result;
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- r0 = s1[0] == s2[0] ? 1 : 0;
- r1 = s1[1] == s2[1] ? 1 : 0;
- result = (r1 << 1) | r0;
- return result;
- }
- static inline int _cmpeq4(int src1, int src2) {
- char s1[4], s2[4];
- int r0, r1, r2, r3;
- int result;
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- r0 = s1[0] == s2[0] ? 1 : 0;
- r1 = s1[1] == s2[1] ? 1 : 0;
- r2 = s1[2] == s2[2] ? 1 : 0;
- r3 = s1[3] == s2[3] ? 1 : 0;
- result = (r3 << 3) | (r2 << 2) | (r1 << 1) | r0;
- return result;
- }
- static inline int _cmpgt2(int src1, int src2) {
- short s1[2], s2[2];
- int r1, r0;
- int result;
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- r0 = s1[0] > s2[0] ? 1 : 0;
- r1 = s1[1] > s2[1] ? 1 : 0;
- result = (r1<<1) | r0;
- return result;
- }
- static inline unsigned int _cmpgtu4(unsigned int src1, unsigned int src2) {
- unsigned int s1_0 = (src1 & 0xFF);
- unsigned int s1_1 = (src1 & 0xFF00) >> 8;
- unsigned int s1_2 = (src1 & 0xFF0000) >> 16;
- unsigned int s1_3 = (src1 & 0xFF000000) >> 24;
- unsigned int s2_0 = (src2 & 0xFF);
- unsigned int s2_1 = (src2 & 0xFF00) >> 8;
- unsigned int s2_2 = (src2 & 0xFF0000) >> 16;
- unsigned int s2_3 = (src2 & 0xFF000000) >> 24;
- unsigned int result = 0;
- if (s1_0 > s2_0)
- result |= 0x1;
- if (s1_1 > s2_1)
- result |= 0x2;
- if (s1_2 > s2_2)
- result |= 0x4;
- if (s1_3 > s2_3)
- result |= 0x8;
- return result;
- }
- static inline long long _ddotp4(unsigned int src1, unsigned int src2) {
- unsigned int res0, res1;
- short s1_0 = (src1 & 0xffff);
- short s1_1 = (src1 & 0xfff0000) >> 16;
- unsigned short s2_0 = (src2 & 0xff);
- unsigned short s2_1 = (src2 & 0xff00) >> 8;
- unsigned short s2_2 = (src2 & 0xff0000) >> 16;
- unsigned short s2_3 = (src2 & 0xff000000) >> 24;
- res0 = ((int)s1_0) * s2_0 + ((int)s1_1) * s2_1;
- res1 = ((int)s1_0) * s2_2 + ((int)s1_1) * s2_3;
- return (res1 << 16) | res0;
- }
- static inline long long _ddotph2(long long src1_o_src1_e, unsigned int src2)
- {
- unsigned int src1_o = src1_o_src1_e >> 32;
- unsigned int src1_e = src1_o_src1_e & 0xFFFFFFFF;
- short ls1_o = src1_o & 0XFFFF;
- short hs1_o = src1_o >> 16;
- // short ls1_e = src1_e & 0XFFFF;
- short hs1_e = src1_e >> 16;
- short ls2 = src2 & 0XFFFF;
- short hs2 = src2 >> 16;
- unsigned long long res_hi = ls2 * ls1_o + hs2 * hs1_o;
- unsigned int res_lo = ls1_o * hs2 + hs1_e * ls2;
- return (res_hi << 32) | res_lo;
- }
- static inline long long _ddotpl2(long long src1_o_src1_e, unsigned int src2)
- {
- unsigned int src1_o = src1_o_src1_e >> 32;
- unsigned int src1_e = src1_o_src1_e & 0xFFFFFFFF;
- short ls1_o = src1_o & 0XFFFF;
- // short hs1_o = src1_o >> 16;
- short ls1_e = src1_e & 0XFFFF;
- short hs1_e = src1_e >> 16;
- short ls2 = src2 & 0XFFFF;
- short hs2 = src2 >> 16;
- unsigned long long res_hi = ls2 * hs1_e + hs2 * ls1_o;
- unsigned res_lo = hs1_e * hs2 + ls1_e * ls2;
- return (res_hi << 32) | res_lo;
- }
- static inline unsigned int _deal(unsigned int src)
- {
- int i;
- unsigned short lo = 0, hi = 0;
- for (i = 0; i < 32; i+= 2) {
- lo >>= 1;
- lo |= (src & 0x1) << 15;
- src >>= 1;
- hi >>= 1;
- hi |= (src & 0x1) << 15;
- src >>= 1;
- }
- return (hi << 16) | lo;
- }
- static inline long long _dmv(unsigned int src1, unsigned int src2)
- {
- return (((long long) src1) << 32) | src2;
- }
- static inline int _dotpn2(int src1, int src2) {
- short int s1_h = src1>>16;
- short int s1_l = src1;
- short int s2_h = src2>>16;
- short int s2_l = src2;
- return s1_h * s2_h - s1_l * s2_l;
- }
- static inline int _dotp2(int src1, int src2) {
- short int s1_h = src1>>16;
- short int s1_l = src1;
- short int s2_h = src2>>16;
- short int s2_l = src2;
- return s1_h * s2_h + s1_l * s2_l;
- }
- static inline int _dotpnrsu2(int src1, unsigned int src2)
- {
- short ls1 = src1 & 0XFFFF;
- unsigned short ls2 = src2 & 0XFFFF;
- short hs1 = src1 >> 16;
- unsigned short hs2 = src2 >> 16;
- int result = (((long long) (int)(hs1 * hs2)) - ((long long) (int)(ls1 * ls2)) + (1 << 15)) >> 16;
- return result;
- }
- static inline int _dotprsu2(int src1, unsigned int src2) {
- short ls1 = src1 & 0XFFFF;
- unsigned short ls2 = (src2 & 0XFFFF);
- short hs1 = src1 >> 16;
- unsigned short hs2 = (src2 >> 16);
- int result = (((long long) (int) (ls1 * ls2)) + ((long long) (int) (hs1 * hs2)) + (1LL << 15)) >> 16;
- return result;
- }
- static inline int _dotpsu4(int src1, unsigned int src2) {
- int result;
- signed char s1_0 = (src1 & 0xff);
- signed char s1_1 = (src1 & 0xff00) >> 8;
- signed char s1_2 = (src1 & 0xff0000) >> 16;
- signed char s1_3 = (src1 & 0xff000000) >> 24;
- unsigned int s2_0 = (src2 & 0xff);
- unsigned int s2_1 = (src2 & 0xff00) >> 8;
- unsigned int s2_2 = (src2 & 0xff0000) >> 16;
- unsigned int s2_3 = (src2 & 0xff000000) >> 24;
- result = s1_0 * s2_0 + s1_1 * s2_1 + s1_2 * s2_2 + s1_3 * s2_3;
- return result;
- }
- static inline unsigned int _dotpu4(unsigned int src1, unsigned int src2) {
- unsigned char v1_0 = src1 & 0xff;
- unsigned char v1_1 = (src1>>8) & 0xff;
- unsigned char v1_2 = (src1>>16) & 0xff;
- unsigned char v1_3 = (src1>>24) & 0xff;
- unsigned char v2_0 = src2 & 0xff;
- unsigned char v2_1 = (src2>>8) & 0xff;
- unsigned char v2_2 = (src2>>16) & 0xff;
- unsigned char v2_3 = (src2>>24) & 0xff;
- unsigned v = v1_0 * v2_0 + v1_1 * v2_1 + v1_2 * v2_2 + v1_3 * v2_3;
- return v;
- }
- static inline long long _dpack2(unsigned int src1, unsigned int src2){
- unsigned short s1[2], s2[2];
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- return ((unsigned long long) s1[1] << 48) | ((unsigned long long) s2[1] << 32) | ((unsigned long long) s1[0] << 16) | ((unsigned long long) s2[0]);
- }
- static inline long long _dpackx2(unsigned int src1, unsigned int src2){
- unsigned short s1[2], s2[2];
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- return ((unsigned long long) s2[0] << 48) | ((unsigned long long) s1[1] << 32) | ((unsigned long long) s1[0] << 16) | ((unsigned long long) s2[1]);
- }
- static inline int _ext(int src2, unsigned int csta, unsigned int cstb)
- {
- return (src2 << csta) >> cstb;
- }
- static inline int _extr(int src2, int src1)
- {
- unsigned int csta = (src1 >> 5) & 0x1f;
- unsigned int cstb = src1 & 0x1f;
- return (src2 << csta) >> cstb;
- }
- static inline unsigned int _extu(unsigned int src2, unsigned int csta, unsigned int cstb)
- {
- return (src2 << csta) >> cstb;
- }
- static inline unsigned int _extur(unsigned int src2, int src1)
- {
- unsigned int csta = (src1 >> 5) & 0x1f;
- unsigned int cstb = src1 & 0x1f;
- return (src2 << csta) >> cstb;
- }
- static inline unsigned long long _hi(double src) {
- unsigned long long v;
- *(double*)&v = src;
- return v>>32;
- }
- static inline unsigned int _hill (long long src)
- {
- return (unsigned int) (src >> 32);
- }
- static inline double _itod(unsigned hi, unsigned lo) {
- double v;
- unsigned long long ll = ((((unsigned long long)(hi))<<32) | (unsigned long long)((unsigned)lo));
- *((unsigned long long *)&v) = ll;
- return v;
- }
- static inline long long _itoll(unsigned int src2, unsigned int src1)
- {
- return (((long long) src2) << 32) | src1;
- }
- static inline C6X_COMPAT_LONG40 _labs(C6X_COMPAT_LONG40 src2)
- {
- long long maxv = (1LL << (40 -1)) - 1;
- long long minv = (-1LL << (40 - 1));
- C6X_COMPAT_LONG40 lres = orig_L40_set(src2);
- lres = lres < 0 ? -lres : lres;
- if (lres > maxv) lres = maxv;
- else if (lres < minv) lres = minv;
-
- return lres;
- }
- static inline C6X_COMPAT_LONG40 _ldotp2(int src1, int src2) {
- return (C6X_COMPAT_LONG40) _dotp2(src1, src2);
- }
- static inline unsigned int _lmbd(unsigned int src1, unsigned int src2)
- {
- return norm_shift_amt_U_and_non_U(0,(((int) (src1 << 31)) >> 31) ^ (~src2));
- }
- static inline unsigned int _lnorm(C6X_COMPAT_LONG40 src2) {
- if (src2 == 0)
- return 39;
- else {
- int hi = (int)(src2 >> 32);
- int lo = (int)src2;
-
- long long temp = (unsigned long long)(unsigned)lo | (unsigned long long)hi << 32;
- temp = orig_L40_set(temp);
- if (temp == 0) return 0;
- int cnt = 0;
- while (((temp >> 39) & 1) == ((temp >> 38) & 1)) {
- temp <<= 1;
- cnt++;
- }
- return cnt;
- }
- }
- static inline unsigned long long _lo(double src) {
- unsigned long long v;
- *(double*)&v = src;
- return v;
- }
- static inline unsigned int _loll (long long src)
- {
- return (unsigned int) src;
- }
- static inline C6X_COMPAT_LONG40 _lsadd(int src1, C6X_COMPAT_LONG40 src2)
- {
- long long maxv = (1LL << (40 -1)) - 1;
- long long minv = (-1LL << (40 - 1));
- int hi = (int)(src2 >> 32);
- int lo = (int)src2;
- long long src2_int = (unsigned long long)(unsigned)lo | (unsigned long long)hi << 32;
- long long src2_int2 = orig_L40_set(src2_int);
-
- long long res = src1 + src2_int2;
- if (res > maxv) {
- res = maxv;
- _overflow = 1;
- }
- else if (res < minv) {
- res = minv;
- _overflow = 1;
- }
- long long res2 = orig_L40_set(res);
- res2 = (signed char)(res2 >> 32);
-
- C6X_COMPAT_LONG40 lres = (((C6X_COMPAT_LONG40) res2) << 32) | ((unsigned int)res);
- return lres;
- }
- static inline int _max2 (int src1, int src2) {
- short s1[2], s2[2], r[2];
- int result;
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- r[0] = s1[0] > s2[0] ? s1[0] : s2[0];
- r[1] = s1[1] > s2[1] ? s1[1] : s2[1];
- result = *(int*)r;
- return result;
- }
- static inline unsigned int _maxu4(unsigned int src1, unsigned int src2) {
- unsigned int res0, res1, res2, res3;
- unsigned int s1_0 = res0 = (src1 & 0xFF);
- unsigned int s1_1 = res1 = (src1 & 0xFF00) >> 8;
- unsigned int s1_2 = res2 = (src1 & 0xFF0000) >> 16;
- unsigned int s1_3 = res3 = (src1 & 0xFF000000) >> 24;
- unsigned int s2_0 = (src2 & 0xFF);
- unsigned int s2_1 = (src2 & 0xFF00) >> 8;
- unsigned int s2_2 = (src2 & 0xFF0000) >> 16;
- unsigned int s2_3 = (src2 & 0xFF000000) >> 24;
- // unsigned int res = 0;
- if (s1_0 < s2_0)
- res0 = s2_0;
- if (s1_1 < s2_1)
- res1 = s2_1;
- if (s1_2 < s2_2)
- res2 = s2_2;
- if (s1_3 < s2_3)
- res3 = s2_3;
- return (res3 << 24) | (res2 << 16) | (res1 << 8) | res0;
- }
- static inline int _min2(int src1, int src2) {
- short s1[2], s2[2], r[2];
- int result;
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- r[0] = s1[0] < s2[0] ? s1[0] : s2[0];
- r[1] = s1[1] < s2[1] ? s1[1] : s2[1];
- result = *(int*)r;
- return result;
- }
- static inline unsigned int _minu4(unsigned int src1, unsigned int src2) {
- unsigned int res0, res1, res2, res3;
- unsigned int s1_0 = res0 = (src1 & 0xFF);
- unsigned int s1_1 = res1 = (src1 & 0xFF00) >> 8;
- unsigned int s1_2 = res2 = (src1 & 0xFF0000) >> 16;
- unsigned int s1_3 = res3 = (src1 & 0xFF000000) >> 24;
- unsigned int s2_0 = (src2 & 0xFF);
- unsigned int s2_1 = (src2 & 0xFF00) >> 8;
- unsigned int s2_2 = (src2 & 0xFF0000) >> 16;
- unsigned int s2_3 = (src2 & 0xFF000000) >> 24;
- // unsigned int res = 0;
- if (s1_0 > s2_0)
- res0 = s2_0;
- if (s1_1 > s2_1)
- res1 = s2_1;
- if (s1_2 > s2_2)
- res2 = s2_2;
- if (s1_3 > s2_3)
- res3 = s2_3;
- return (res3 << 24) | (res2 << 16) | (res1 << 8) | res0;
- }
- static inline int _mpy(int src1, int src2) {
- return (short) src1 * (short) src2;
- }
- static inline int _mpyh(int src1, int src2) {
- return (short) (src1 >> 16) * (short) (src2 >> 16);
- }
- static inline long long _mpyhill (int src1, int src2)
- {
- short s1 = src1 >> 16;
- return ((long long) src2) * s1;
- }
- static inline int _mpyhir(int src1, int src2)
- {
- short s1 = src1 >> 16;
- long long result = ((long long) src2) * s1 + (1 << 14);
- result >>= 15;
- return result;
- }
- static inline int _mpyhl(int src1, int src2) {
- return (short) (src1 >> 16) * (short) (src2);
- }
- static inline unsigned int _mpyhlu(unsigned int src1, unsigned int src2) {
- return (unsigned short) (src1 >> 16) * (unsigned short) (src2);
- }
- static inline int _mpyhslu(int src1, unsigned int src2) {
- return (short) (src1 >> 16) * (unsigned short) src2;
- }
- static inline int _mpyhsu(int src1, unsigned int src2) {
- return (short) (src1 >>16) * (unsigned short) (src2 >>16);
- }
- static inline unsigned int _mpyhu(unsigned int src1, unsigned int src2) {
- return (unsigned short) (src1 >>16) * (unsigned short) (src2 >> 16);
- }
- static inline int _mpyhuls(unsigned int src1, int src2) {
- return (unsigned short) (src1 >>16) * (signed short) (src2);
- }
- static inline int _mpyhus(unsigned int src1, int src2) {
- return (unsigned short) (src1 >> 16) * (short) (src2 >>16);
- }
- static inline long long _mpyidll (int src1, int src2)
- {
- return (long long) src1 * src2;
- }
- static inline int _mpylh(int src1, int src2) {
- return (signed short) (src1 & 0xffff) * (signed short) (src2 >> 16);
- }
- static inline unsigned int _mpylhu(unsigned int src1, unsigned int src2) {
- return (unsigned short) src1 * (unsigned short) (src2 >> 16);
- }
- static inline long long _mpylill (int src1, int src2)
- {
- return ((long long) src2) * ((short)src1);
- }
- static inline int _mpylir(int src1, int src2)
- {
- short s1 = src1;
- long long result = ((long long) src2) * s1 + (1 << 14);
- result >>= 15;
- return result;
- }
- static inline int _mpylshu(int src1, unsigned int src2) {
- return (short) src1 * (unsigned short) (src2 >> 16);
- }
- static inline int _mpyluhs(unsigned int src1, int src2) {
- return (unsigned short) src1 * (short) (src2 >> 16);
- }
- static inline int _mpysu(int src1, unsigned int src2) {
- return (short) src1 * (unsigned short) src2;
- }
- static inline long long _mpysu4ll (int src1, unsigned int src2) {
- unsigned short res0, res1, res2, res3;
- signed char s1_0 = (src1 & 0xff);
- signed char s1_1 = (src1 & 0xff00) >> 8;
- signed char s1_2 = (src1 & 0xff0000) >> 16;
- signed char s1_3 = (src1 & 0xff000000) >> 24;
- unsigned short s2_0 = (src2 & 0xff);
- unsigned short s2_1 = (src2 & 0xff00) >> 8;
- unsigned short s2_2 = (src2 & 0xff0000) >> 16;
- unsigned short s2_3 = (src2 & 0xff000000) >> 24;
- res0 = s1_0 * s2_0;
- res1 = s1_1 * s2_1;
- res2 = s1_2 * s2_2;
- res3 = s1_3 * s2_3;
- return (((unsigned long long) res3) << 48)
- | (((unsigned long long) res2) << 32)
- | (((unsigned long long) res1) << 16)
- | res0;
- }
- static inline unsigned int _mpyu(unsigned int src1, unsigned int src2) {
- unsigned v = (unsigned short)src1 * (unsigned short)src2;
- return v;
- }
- static inline int _mpyus(unsigned int src1, int src2) {
- return (unsigned short) src1 * (short) src2;
- }
- static inline long long _mpyu4ll (unsigned int src1, unsigned int src2) {
- unsigned short res0, res1, res2, res3;
- unsigned char s1_0 = (src1 & 0xff);
- unsigned char s1_1 = (src1 & 0xff00) >> 8;
- unsigned char s1_2 = (src1 & 0xff0000) >> 16;
- unsigned char s1_3 = (src1 & 0xff000000) >> 24;
- unsigned short s2_0 = (src2 & 0xff);
- unsigned short s2_1 = (src2 & 0xff00) >> 8;
- unsigned short s2_2 = (src2 & 0xff0000) >> 16;
- unsigned short s2_3 = (src2 & 0xff000000) >> 24;
- res0 = s1_0 * s2_0;
- res1 = s1_1 * s2_1;
- res2 = s1_2 * s2_2;
- res3 = s1_3 * s2_3;
- return (((unsigned long long) res3) << 48)
- | (((unsigned long long) res2) << 32)
- | (((unsigned long long) res1) << 16)
- | res0;
- }
- static inline long long _mpy2ir(unsigned int src1, unsigned int src2)
- {
- if ((src1 == 0x8000) && (src2 == 0x80000000)) {
- _overflow = 1;
- return 0;
- }
- else {
- short ls1 = src1 & 0xffff;
- short hs1 = src1 >> 16;
- unsigned long long hi = (((long long) hs1) * (int) src2 + (1 << 14)) >> 15;
- unsigned long long lo = ((((long long) ls1) * (int) src2 + (1 << 14)) >> 15) & 0xFFFFFFFF;
- return (hi << 32) | lo;
- }
- }
- static inline long long _mpy2ll (int src1, int src2) {
- short ls1 = src1 & 0xffff;
- short hs1 = src1 >> 16;
- short ls2 = src2 & 0xffff;
- short hs2 = src2 >> 16;
- unsigned long long hi = hs1 * hs2;
- unsigned long long lo = (ls1 * ls2) & 0xFFFFFFFF;
- return (hi << 32) | lo;
-
- }
- static inline int _mpy32(int src1, int src2)
- {
- return src1 * src2;
- }
- static inline long long _mpy32ll(int src1, int src2)
- {
- return ((long long) src1) * src2;
- }
- static inline long long _mpy32su(int src1, unsigned int src2)
- {
- return ((long long) src1) * ((int) src2);
- }
- static inline long long _mpy32u(unsigned int src1, unsigned int src2)
- {
- return ((long long) ((int) src1)) * ((long long) ((int) src2));
- }
- static inline long long _mpy32us(unsigned int src1, int src2)
- {
- return ((int) src1) * ((long long) src2);
- }
- static inline int _mvd (int src2)
- {
- return src2;
- }
- static inline unsigned int _norm(int src2)
- {
- return norm_shift_amt_U_and_non_U(1,src2);
- }
- static inline unsigned int _pack2 (unsigned int src1, unsigned int src2) {
- short s1[2], s2[2], r[2];
- int result;
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- r[0] = s2[0];
- r[1] = s1[0];
- result = *(int*)r;
- return result;
- }
- static inline int _packh2 (unsigned int src1, unsigned int src2) {
- unsigned v0 = src1 & 0xffff0000;
- unsigned v1 = src2 >> 16;
- unsigned v = v0|v1;
- return v;
-
- }
- static inline unsigned int _packh4 (unsigned int src1, unsigned int src2) {
- unsigned v3 = (src1 >> 24) & 0xff;
- unsigned v2 = (src1 >> 8) & 0xff;
- unsigned v1 = (src2 >> 24) & 0xff;
- unsigned v0 = (src2 >> 8) & 0xff;
- unsigned v = (v3<<24) | (v2<<16) | (v1 << 8) | v0;
- return v;
- }
- static inline unsigned int _packhl2 (unsigned int src1, unsigned int src2) {
- unsigned v0 = src1 & 0xffff0000;
- unsigned v1 = src2 & 0x0000ffff;
- unsigned v = v0|v1;
- return v;
- }
- static inline unsigned int _packlh2 (unsigned int src1, unsigned int src2) {
- unsigned v0 = src1 << 16;
- unsigned v1 = (src2 >> 16) & 0xffff;
- unsigned v = v0|v1;
- return v;
- }
- static inline unsigned int _packl4 (unsigned int src1, unsigned int src2) {
- unsigned v3 = (src1 >> 16) & 0xff;
- unsigned v2 = (src1) & 0xff;
- unsigned v1 = (src2 >> 16) & 0xff;
- unsigned v0 = (src2) & 0xff;
- unsigned v = (v3<<24) | (v2<<16) | (v1 << 8) | v0;
- return v;
- }
- static inline unsigned int _rpack2 (unsigned int src1, unsigned int src2) {
- int s1 = (int) src1;
- int s2 = (int) src2;
- s1 = util_shift_right_saturate_n (s1, -1, 32);
- s2 = util_shift_right_saturate_n (s2, -1, 32);
- return (unsigned int) (s1 & 0xffff0000) | (unsigned int) ((s2 & 0xffff0000) >>16);
- }
- static inline unsigned int _rotl (unsigned int src1, unsigned int src2)
- {
- src2 &= 0x1f;
- return (src1 << src2) | (src1 >> (32 - src2));
- }
- static inline int _sadd(int src1, int src2) {
- signed long long res;
- signed long long maxv, minv;
- maxv = (1LL << (32-1)) - 1;
- minv = (-1LL << (32-1));
- res = (long long) src1 + (long long) src2;
- if (res > maxv) {
- res = maxv;
- _overflow = 1;
- }
- else if (res < minv ) {
- res = minv;
- _overflow = 1;
- }
- return (int) res;
- }
- static inline long long _saddsub(unsigned int src1, unsigned int src2) {
- int radd;
- signed long long rsub;
- signed long long maxv, minv;
- maxv = (1LL << (32-1)) - 1;
- minv = (-1LL << (32-1));
- radd = (int) src1 + (int) src2;
- // saturate on subtract, not add
- rsub = (long long) ((int) src1) - (long long) ((int) src2);
- if (rsub > maxv) {
- rsub = maxv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- else if (rsub < minv ) {
- rsub = minv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- return (((unsigned long long) radd) << 32) | ( rsub & 0x00000000ffffffff ) ;
- }
- static inline long long _saddsub2(unsigned int src1, unsigned int src2) {
- signed int radd[2];
- signed int rsub[2];
- signed short s1[2], s2[2];
- signed int maxv, minv;
- maxv = (1L << (16-1)) - 1;
- minv = (-1L << (16-1));
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- radd[0] = (int) s1[0] + (int) s2[0];
- radd[1] = (int) s1[1] + (int) s2[1];
- rsub[0] = (int) s1[0] - (int) s2[0];
- rsub[1] = (int) s1[1] - (int) s2[1];
- if (radd[0] > maxv) {
- radd[0] = maxv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- else if (radd[0] < minv ) {
- radd[0] = minv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- if (radd[1] > maxv) {
- radd[1] = maxv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- else if (radd[1] < minv ) {
- radd[1] = minv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- if (rsub[0] > maxv) {
- rsub[0] = maxv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- else if (rsub[0] < minv ) {
- rsub[0] = minv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- if (rsub[1] > maxv) {
- rsub[1] = maxv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- else if (rsub[1] < minv ) {
- rsub[1] = minv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- return ((((unsigned long long) radd[1]) & 0x000000000000ffff) << 48) |
- ((((unsigned long long) radd[0]) & 0x000000000000ffff) << 32) |
- ((((unsigned long long) rsub[1]) & 0x000000000000ffff) << 16) |
- ((((unsigned long long) rsub[0]) & 0x000000000000ffff));
- }
- static inline int _sadd2(int src1, int src2) {
- signed short s1[2], s2[2];
- signed int r[2], maxv, minv;
- maxv = (1L << (16-1)) - 1;
- minv = (-1L << (16-1));
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- r[0] = (int) s1[0] + (int) s2[0];
- r[1] = (int) s1[1] + (int) s2[1];
- if (r[0] > maxv) {
- r[0] = maxv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- else if (r[0] < minv ) {
- r[0] = minv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- if (r[1] > maxv) {
- r[1] = maxv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- else if (r[1] < minv ) {
- r[1] = minv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- return ((r[1] & 0xffff) << 16 ) | (r[0] & 0xffff) ;
- }
- static inline int _saddus2(unsigned int src1, int src2) {
- int res0, res1;
- unsigned int s1_0 = (src1 & 0xffff);
- unsigned int s1_1 = (src1 & 0xffff0000) >> 16;
- short s2_0 = (src2 & 0xffff);
- short s2_1 = (src2 & 0xffff0000) >> 16;
- res0 = s1_0 + s2_0;
- res1 = s1_1 + s2_1;
- if (res0 >= 0x10000)
- res0 = 0xffff;
- else if (res0 < 0)
- res0 = 0;
-
- if (res1 >= 0x10000)
- res1 = 0xffff;
- else if (res1 < 0)
- res1 = 0;
-
- return (res1 << 16) | res0;
- }
- static inline unsigned int _saddu4(unsigned int src1, unsigned int src2) {
- unsigned int res0, res1, res2, res3;
- unsigned int s1_0 = (src1 & 0xff);
- unsigned int s1_1 = (src1 & 0xff00) >> 8;
- unsigned int s1_2 = (src1 & 0xff0000) >> 16;
- unsigned int s1_3 = (src1 & 0xff000000) >> 24;
- unsigned int s2_0 = (src2 & 0xff);
- unsigned int s2_1 = (src2 & 0xff00) >> 8;
- unsigned int s2_2 = (src2 & 0xff0000) >> 16;
- unsigned int s2_3 = (src2 & 0xff000000) >> 24;
- res0 = s1_0 + s2_0;
- res1 = s1_1 + s2_1;
- res2 = s1_2 + s2_2;
- res3 = s1_3 + s2_3;
- if (res0 >= 0x100)
- res0 = 0xff;
-
- if (res1 >= 0x100)
- res1 = 0xff;
-
- if (res2 >= 0x100)
- res2 = 0xff;
-
- if (res3 >= 0x100)
- res3 = 0xff;
- return (res3 << 24) | (res2 << 16) | (res1 << 8) | res0;
- }
- static inline int _sat(C6X_COMPAT_LONG40 src2)
- {
- long long maxv = (1LL << (32-1)) - 1;
- long long minv = (-1LL << (32-1));
- int hi = (int)(src2 >> 32);
- int lo = (int)src2;
- long long temp = (unsigned long long)(unsigned)lo | (unsigned long long)hi << 32;
- temp = orig_L40_set(temp);
-
- if (temp > maxv) {
- temp = maxv;
- _overflow = 1;
- }
- else if (temp < minv) {
- temp = minv;
- _overflow = 1;
- }
- return (int) temp;
- }
- static inline unsigned int _set(unsigned int src2, unsigned int csta, unsigned int cstb)
- {
- csta &= 0x1f;
- cstb &= 0x1f;
- if (csta > cstb)
- return src2;
- else {
- unsigned int mask = (((1 << (cstb - csta)) << 1) - 1) << csta;
- return src2 | mask;
- }
- }
- static inline unsigned int _setr(unsigned int src2, int src1)
- {
- unsigned int csta = (src1 >> 5) & 0x1f;
- unsigned int cstb = src1 & 0x1f;
- if (csta > cstb)
- return src2;
- else {
- unsigned int mask = (((1 << (cstb - csta)) << 1) - 1) << csta;
- return src2 | mask;
- }
- }
- static inline unsigned int _shfl (unsigned int src2)
- {
- unsigned short lo = src2;
- unsigned short hi = src2 >> 16;
- unsigned int result = 0;
- int i;
- for (i = 0; i < 32; i+= 2) {
- result >>= 1;
- result |= (lo & 0x1) << 31;
- lo >>= 1;
- result >>= 1;
- result |= (hi & 0x1) << 31;
- hi >>= 1;
- }
- return result;
- }
- static inline long long _shfl3 (unsigned int src1, unsigned int src2)
- {
- unsigned short lo = src2;
- unsigned short hi = src1 >> 16;
- unsigned short mid = src1;
- unsigned long long result = 0;
- int i;
- for (i = 0; i < 32; i+= 2) {
- result >>= 1;
- result |= ((unsigned long long) (lo & 0x1)) << 47;
- lo >>= 1;
- result >>= 1;
- result |= ((unsigned long long) (mid & 0x1)) << 47;
- mid >>= 1;
- result >>= 1;
- result |= ((unsigned long long) (hi & 0x1)) << 47;
- hi >>= 1;
- }
- return result;
- }
- static inline unsigned int _shlmb (unsigned int src1, unsigned int src2)
- {
- return (src2 << 8) | (src1 >> 24);
- }
- static inline unsigned int _shrmb (unsigned int src1, unsigned int src2)
- {
- return (src2 >> 8) | (src1 << 24);
- }
- static inline unsigned int _shru2 (unsigned int src1, unsigned int src2) {
- unsigned short hs1 = src1 >> 16;
- unsigned short ls1 = src1 & 0xFFFF;
- hs1 >>= src2;
- ls1 >>= src2;
- return (hs1 << 16) | ls1;
- }
- static inline int _shr2 (int src1, unsigned int src2) {
- short s1[2], result[2];
- *((int*)s1) = src1;
- src2 = src2 & 31;
- result[0] = (int)s1[0] >> src2;
- result[1] = (int)s1[1] >> src2;
- return *(int*)result;
- }
- static inline int _smpy (int src1, int src2) {
- unsigned long long result;
- result = (((short) src1 * (short) src2) << 1);
- if ((result & 0xffffffff) == 0x80000000){
- result = 0x7fffffff;
- _overflow = 1;
- }
- return (int) (result);
- }
- static inline int _smpyh (int src1, int src2) {
- unsigned long long result;
- result = ((short) (src1 >> 16) * (short) (src2 >> 16)) << 1;
- if ((result & 0xffffffff) == 0x80000000){
- result = 0x7fffffff;
- _overflow = 1;
- }
- return (int) (result);
- }
- static inline int _smpyhl (int src1, int src2) {
- unsigned long long result;
- result = ((short) (src1 >> 16) * (short) (src2)) << 1;
- if ((result & 0xffffffff) == 0x80000000){
- result = 0x7fffffff;
- _overflow = 1;
- }
- return (int) (result);
- }
- static inline int _smpylh (int src1, int src2) {
- unsigned long long result;
- result = ((short) (src1) * (short) (src2 >> 16)) << 1;
- if ((result & 0xffffffff) == 0x80000000){
- result = 0x7fffffff;
- _overflow = 1;
- }
- return (int) (result);
- }
- static inline long long _smpy2ll (int src1, int src2) {
- short ls1 = src1 & 0XFFFF;
- short hs1 = src1 >> 16;
- short ls2 = src2 & 0XFFFF;
- short hs2 = src2 >> 16;
- unsigned long long hi = (hs1 * hs2) << 1;
- unsigned long long lo = ((ls1 * ls2) << 1) & 0xFFFFFFFF;
- if ((hi & 0xffffffff) == 0x80000000){
- hi = 0x7fffffff;
- _overflow = 1;
- }
- if ((lo & 0xffffffff) == 0x80000000){
- lo = 0x7fffffff;
- _overflow = 1;
- }
- return (hi << 32) | lo;
- }
- static inline int _smpy32(int src1, int src2)
- {
- long long res = (long long) src1 * src2;
- res <<= 1;
- res >>= 32;
- return res;
- }
- static inline unsigned char TEN_satu8 (short src)
- {
- if (src > 0xff)
- return 0xff;
- else if (src < 0)
- return 0;
- else
- return src;
- }
- static inline int _spack2 (int src1, int src2) {
- short s1 = (short) util_saturate_n_no_state(src1,16);
- short s2 = (short) util_saturate_n_no_state(src2,16);
- return ( (unsigned int) s1 << 16) | (((int) s2) & 0xFFFF);
- }
- static inline unsigned int _spacku4 (int src1, int src2) {
- short lolo = src2;
- short lohi = src2 >> 16;
- short hilo = src1;
- short hihi = src1 >> 16;
- lolo = TEN_satu8(lolo);
- lohi = TEN_satu8(lohi);
- hilo = TEN_satu8(hilo);
- hihi = TEN_satu8(hihi);
- return (((unsigned int) hihi) << 24) | (((unsigned int) hilo) << 16) | (lohi << 8) | lolo;
- }
- static inline int _sshl (int src1, unsigned int src2) {
- short local2 = (short)(src2 & 0x7FFF);
- return (int) util_shift_right_saturate_n(src1, -local2, 32);
- }
- static inline int _sshvl (int src2, int src1) {
- short s1;
- if (src1 > 31)
- s1 = 31;
- else if (src1 < -31)
- s1 = -31;
- else
- s1 = src1;
- return (int) util_shift_right_saturate_n(src2, -s1, 32);
- }
- static inline int _sshvr (int src2, int src1) {
- short s1;
- if (src1 > 31)
- s1 = 31;
- else if (src1 < -31)
- s1 = -31;
- else
- s1 = src1;
- return (int) util_shift_right_saturate_n(src2, s1, 32);
- }
- static inline int _ssub(int src1, int src2) {
- signed long long res;
- signed long long maxv, minv;
- maxv = (1LL << (32-1)) - 1;
- minv = (-1LL << (32-1));
- res = (long long) src1 - (long long) src2;
- if (res > maxv) {
- res = maxv;
- _overflow = 1;
- }
- else if (res < minv ) {
- res = minv;
- _overflow = 1;
- }
- return (int) res;
- }
- static inline int _ssub2(int src1, int src2) {
- signed short s1[2], s2[2];
- signed int r[2], maxv, minv;
- maxv = (1L << (16-1)) - 1;
- minv = (-1L << (16-1));
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- r[0] = (int) s1[0] - (int) s2[0];
- r[1] = (int) s1[1] - (int) s2[1];
- if (r[0] > maxv) {
- r[0] = maxv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- else if (r[0] < minv ) {
- r[0] = minv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- if (r[1] > maxv) {
- r[1] = maxv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- else if (r[1] < minv ) {
- r[1] = minv;
- /* NOTE: TI c6x does NOT set the overflow register even if results saturate */
- /* _overflow = 1; */
- }
- return ((r[1] & 0xffff) << 16 ) | (r[0] & 0xffff) ;
- }
- static inline int _subabs4 (int src1, int src2) {
- int res0, res1, res2, res3;
- unsigned int s1_0 = (src1 & 0xff);
- unsigned int s1_1 = (src1 & 0xff00) >> 8;
- unsigned int s1_2 = (src1 & 0xff0000) >> 16;
- unsigned int s1_3 = (src1 & 0xff000000) >> 24;
- unsigned int s2_0 = (src2 & 0xff);
- unsigned int s2_1 = (src2 & 0xff00) >> 8;
- unsigned int s2_2 = (src2 & 0xff0000) >> 16;
- unsigned int s2_3 = (src2 & 0xff000000) >> 24;
- res0 = s1_0 - s2_0;
- res1 = s1_1 - s2_1;
- res2 = s1_2 - s2_2;
- res3 = s1_3 - s2_3;
- if (res0 < 0)
- res0 = -res0;
-
- if (res1 < 0)
- res1 = -res1;
-
- if (res2 < 0)
- res2 = -res2;
-
- if (res3 < 0)
- res3 = -res3;
- return (res3 << 24) | (res2 << 16) | (res1 << 8) | res0;
- }
- static inline unsigned int _subc (unsigned int src1, unsigned int src2)
- {
- if ( src1 >= src2)
- return ((src1 - src2) << 1) + 1;
- else
- return src1 << 1;
- }
- static inline int _sub2(int src1, int src2) {
- short s1[2], s2[2], r[2];
- int result;
- *((int*)s1) = src1;
- *((int*)s2) = src2;
- r[0] = s1[0] - s2[0];
- r[1] = s1[1] - s2[1];
- result = *(int*)r;
- return result;
- }
- static inline int _sub4(int src1, int src2) {
- char c1[4], c2[4], r[4];
- int result;
- *((int*)c1) = src1;
- *((int*)c2) = src2;
- r[0] = c1[0] - c2[0];
- r[1] = c1[1] - c2[1];
- r[2] = c1[2] - c2[2];
- r[3] = c1[3] - c2[3];
- result = *(int*)r;
- return result;
- }
- static inline int _swap4 (unsigned int src1) {
- unsigned char v0 = src1;
- unsigned char v1 = src1 >> 8;
- unsigned char v2 = src1 >> 16;
- unsigned char v3 = src1 >> 24;
- unsigned v = v0<<8 | v1 | v2<<24 | v3<<16;
- return v;
- }
- static inline unsigned int _unpkhu4 (unsigned int src1) {
- unsigned v0 = src1>>24;
- unsigned v1 = (src1>>16) & 0xff;
- return (v0<<16) | v1;
- }
- static inline unsigned int _unpklu4 (unsigned int src1) {
- unsigned v1 = (src1>>8) & 0xff;
- unsigned v0 = (src1) & 0xff;
- return (v1<<16) | v0;
- }
- static inline unsigned int _xpnd2 (unsigned int src1) {
- int v0 = (src1 & 0x1) ? 0x0000ffff : 0x00000000;
- int v1 = (src1 & 0x2) ? 0xffff0000 : 0x00000000;
- return v0|v1;
- }
- static inline unsigned int _xpnd4 (unsigned int src1) {
- int v0 = (src1 & 0x1) ? 0x000000ff : 0x00000000;
- int v1 = (src1 & 0x2) ? 0x0000ff00 : 0x00000000;
- int v2 = (src1 & 0x4) ? 0x00ff0000 : 0x00000000;
- int v3 = (src1 & 0x8) ? 0xff000000 : 0x00000000;
- int r = v0|v1|v2|v3;
- return r;
- }
- // end of Implemented in alphabetical order
- #endif /* __C6X_COMPAT__H */
|