Changeset 2616


Ignore:
Timestamp:
Apr 18, 2009 2:29:28 PM (15 years ago)
Author:
bennylp
Message:

More ticket #774: optimization for siren7/siren14 codecs

Location:
pjproject/trunk
Files:
1 added
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-codec/g7221.c

    r2603 r2616  
    223223} 
    224224 
     225#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0 
     226PJ_INLINE(void) swap_bytes(pj_uint16_t *buf, unsigned count) 
     227{ 
     228    pj_uint16_t *end = buf + count; 
     229    while (buf != end) { 
     230        *buf = (pj_uint16_t)((*buf << 8) | (*buf >> 8)); 
     231        ++buf; 
     232    } 
     233} 
     234#else 
     235#define swap_bytes(buf, count) 
     236#endif 
     237 
    225238/* 
    226239 * Initialize and register G722.1 codec factory to pjmedia endpoint. 
     
    775788            output->buf); 
    776789 
    777 #if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0 
    778     { 
    779         pj_uint16_t *p, *p_end; 
    780  
    781         p = (pj_uint16_t*)output->buf; 
    782         p_end = p + codec_data->frame_size/2; 
    783         while (p < p_end) { 
    784             *p = pj_htons(*p); 
    785             ++p; 
    786         } 
    787     } 
    788 #endif 
     790    /* Encoder output are in native host byte order, while ITU says 
     791     * it must be in network byte order (MSB first). 
     792     */ 
     793    swap_bytes((pj_uint16_t*)output->buf, codec_data->frame_size/2); 
    789794 
    790795    output->type = PJMEDIA_FRAME_TYPE_AUDIO; 
     
    819824                         PJMEDIA_CODEC_EFRMINLEN); 
    820825 
    821         /* Decoder requires input of 16-bits array, so we need to take care 
    822          * about endianness. 
     826        /* Decoder requires input of 16-bits array in native host byte 
     827         * order, while the frame received from the network are in 
     828         * network byte order (MSB first). 
    823829         */ 
    824 #if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0 
    825         { 
    826             pj_uint16_t *p, *p_end; 
    827  
    828             p = (pj_uint16_t*)input->buf; 
    829             p_end = p + codec_data->frame_size/2; 
    830             while (p < p_end) { 
    831                 *p = pj_ntohs(*p); 
    832                 ++p; 
    833             } 
    834         } 
    835 #endif 
     830        swap_bytes((pj_uint16_t*)input->buf, codec_data->frame_size/2); 
    836831 
    837832        bitobj.code_word_ptr = (Word16*)input->buf; 
  • pjproject/trunk/third_party/build/g7221/libg7221codec.dsp

    r2607 r2616  
    4343F90=df.exe 
    4444# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c 
    45 # ADD CPP /nologo /MD /W3 /GX /O2 /I "../.." /I "../../g7221/common" /I "../../g7221/common/stl-files" /I "../../../pjlib/include" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c 
     45# ADD CPP /nologo /MD /W3 /GX /O2 /I "../.." /I "../../g7221/common" /I "../../g7221/common/stl-files" /I "../../../pjlib/include" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /c 
     46# SUBTRACT CPP /Z<none> 
    4647# ADD BASE RSC /l 0x409 /d "NDEBUG" 
    4748# ADD RSC /l 0x409 /d "NDEBUG" 
     
    6768F90=df.exe 
    6869# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c 
    69 # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../.." /I "../../g7221/common" /I "../../g7221/common/stl-files" /I "../../../pjlib/include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c 
     70# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../.." /I "../../g7221/common" /I "../../g7221/common/stl-files" /I "../../../pjlib/include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /YX /FD /GZ /c 
    7071# ADD BASE RSC /l 0x409 /d "_DEBUG" 
    7172# ADD RSC /l 0x409 /d "_DEBUG" 
     
    102103# Begin Source File 
    103104 
    104 SOURCE="..\..\g7221\common\stl-files\count.c" 
     105SOURCE="..\..\g7221\common\stl-files\basop32_i.h" 
    105106# End Source File 
    106107# Begin Source File 
  • pjproject/trunk/third_party/g7221/common/common.c

    r2563 r2616  
    9595        number_of_available_bits = sub(number_of_available_bits,frame_size); 
    9696        number_of_available_bits = extract_l(L_mult0(number_of_available_bits,5)); 
    97         number_of_available_bits = shr(number_of_available_bits,3); 
     97        number_of_available_bits = shr_nocheck(number_of_available_bits,3); 
    9898        number_of_available_bits = add(number_of_available_bits,frame_size); 
    9999    } 
     
    208208    { 
    209209        min_plus_max = add(max,min); 
    210         two_x_number_of_available_bits = shl(number_of_available_bits,1); 
     210        two_x_number_of_available_bits = shl_nocheck(number_of_available_bits,1); 
    211211         
    212212        temp = sub(min_plus_max,two_x_number_of_available_bits); 
     
    223223                if (max_rate_categories[region] > 0)  
    224224                { 
    225                     itemp0 = shl(max_rate_categories[region],1); 
     225                    itemp0 = shl_nocheck(max_rate_categories[region],1); 
    226226                    itemp1 = sub(offset,rms_index[region]); 
    227227                    itemp0 = sub(itemp1,itemp0); 
     
    259259                if (temp < 0) 
    260260                { 
    261                     itemp0 = shl(min_rate_categories[region],1); 
     261                    itemp0 = shl_nocheck(min_rate_categories[region],1); 
    262262                    itemp1 = sub(offset,rms_index[region]); 
    263263                    itemp0 = sub(itemp1,itemp0); 
     
    357357        { 
    358358            j = sub(test_offset,rms_index[region]); 
    359             j = shr(j,1); 
     359            j = shr_nocheck(j,1); 
    360360             
    361361            /* Ensure j is between 0 and NUM_CAT-1 */ 
     
    392392            move16(); 
    393393        } 
    394         delta = shr(delta,1); 
     394        delta = shr_nocheck(delta,1); 
    395395        test(); /* for the while loop */ 
    396396    } while (delta > 0); 
     
    441441    { 
    442442        j = sub(offset,rms_index[region]); 
    443         j = shr(j,1); 
     443        j = shr_nocheck(j,1); 
    444444         
    445445        /* make sure j is between 0 and NUM_CAT-1 */ 
  • pjproject/trunk/third_party/g7221/common/stl-files/basop32.c

    r2601 r2616  
    8080/*___________________________________________________________________________ 
    8181 |                                                                           | 
    82  |   Local Functions                                                         | 
    83  |___________________________________________________________________________| 
    84 */ 
    85 Word16 saturate (Word32 L_var1); 
    86  
    87 /*___________________________________________________________________________ 
    88  |                                                                           | 
    8982 |   Constants and Globals                                                   | 
    9083 |___________________________________________________________________________| 
    9184*/ 
    92 Flag Overflow = 0; 
    93 Flag Carry = 0; 
     85#if INCLUDE_UNSAFE 
     86Flag g7221_Overflow = 0; 
     87Flag g7221_Carry = 0; 
     88#endif 
    9489 
    9590/*___________________________________________________________________________ 
     
    9893 |___________________________________________________________________________| 
    9994*/ 
    100  
    101 /*___________________________________________________________________________ 
    102  |                                                                           | 
    103  |   Function Name : saturate                                                | 
    104  |                                                                           | 
    105  |   Purpose :                                                               | 
    106  |                                                                           | 
    107  |    Limit the 32 bit input to the range of a 16 bit word.                  | 
    108  |                                                                           | 
    109  |   Inputs :                                                                | 
    110  |                                                                           | 
    111  |    L_var1                                                                 | 
    112  |             32 bit long signed integer (Word32) whose value falls in the  | 
    113  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 | 
     95/*___________________________________________________________________________ 
     96 |                                                                           | 
     97 |   Function Name : shr                                                     | 
     98 |                                                                           | 
     99 |   Purpose :                                                               | 
     100 |                                                                           | 
     101 |   Arithmetically shift the 16 bit input var1 right var2 positions with    | 
     102 |   sign extension. If var2 is negative, arithmetically shift var1 left by  | 
     103 |   -var2 with sign extension. Saturate the result in case of underflows or | 
     104 |   overflows.                                                              | 
     105 |                                                                           | 
     106 |   Complexity weight : 1                                                   | 
     107 |                                                                           | 
     108 |   Inputs :                                                                | 
     109 |                                                                           | 
     110 |    var1                                                                   | 
     111 |             16 bit short signed integer (Word16) whose value falls in the | 
     112 |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
     113 |                                                                           | 
     114 |    var2                                                                   | 
     115 |             16 bit short signed integer (Word16) whose value falls in the | 
     116 |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    114117 |                                                                           | 
    115118 |   Outputs :                                                               | 
     
    124127 |___________________________________________________________________________| 
    125128*/ 
    126 Word16 saturate (Word32 L_var1) 
    127 { 
    128     Word16 var_out; 
    129  
    130     if (L_var1 > 0X00007fffL) 
    131     { 
    132         Overflow = 1; 
    133         var_out = MAX_16; 
    134     } 
    135     else if (L_var1 < (Word32) 0xffff8000L) 
    136     { 
    137         Overflow = 1; 
    138         var_out = MIN_16; 
     129Word16 shr (Word16 var1, Word16 var2) 
     130{ 
     131    if (var2 < 0) 
     132    { 
     133        if (var2 < -16) 
     134            var2 = -16; 
     135        return shl_nocheck(var1, (Word16) -var2); 
    139136    } 
    140137    else 
    141138    { 
    142         var_out = extract_l (L_var1); 
    143 #if (WMOPS) 
    144         multiCounter[currCounter].extract_l--; 
    145 #endif 
    146     } 
    147  
    148     return (var_out); 
    149 } 
    150 /* ------------------------- End of saturate() ------------------------- */ 
    151  
    152  
    153 /*___________________________________________________________________________ 
    154  |                                                                           | 
    155  |   Function Name : add                                                     | 
    156  |                                                                           | 
    157  |   Purpose :                                                               | 
    158  |                                                                           | 
    159  |    Performs the addition (var1+var2) with overflow control and saturation;| 
    160  |    the 16 bit result is set at +32767 when overflow occurs or at -32768   | 
    161  |    when underflow occurs.                                                 | 
    162  |                                                                           | 
    163  |   Complexity weight : 1                                                   | 
    164  |                                                                           | 
    165  |   Inputs :                                                                | 
    166  |                                                                           | 
    167  |    var1                                                                   | 
    168  |             16 bit short signed integer (Word16) whose value falls in the | 
    169  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    170  |                                                                           | 
    171  |    var2                                                                   | 
    172  |             16 bit short signed integer (Word16) whose value falls in the | 
    173  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    174  |                                                                           | 
    175  |   Outputs :                                                               | 
    176  |                                                                           | 
    177  |    none                                                                   | 
    178  |                                                                           | 
    179  |   Return Value :                                                          | 
    180  |                                                                           | 
    181  |    var_out                                                                | 
    182  |             16 bit short signed integer (Word16) whose value falls in the | 
    183  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                | 
    184  |___________________________________________________________________________| 
    185 */ 
    186 Word16 add (Word16 var1, Word16 var2) 
    187 { 
    188     Word16 var_out; 
    189     Word32 L_sum; 
    190  
    191     L_sum = (Word32) var1 + var2; 
    192     var_out = saturate (L_sum); 
    193 #if (WMOPS) 
    194     multiCounter[currCounter].add++; 
    195 #endif 
    196     return (var_out); 
    197 } 
    198 /* ------------------------- End of add() ------------------------- */ 
    199  
    200  
    201 /*___________________________________________________________________________ 
    202  |                                                                           | 
    203  |   Function Name : sub                                                     | 
    204  |                                                                           | 
    205  |   Purpose :                                                               | 
    206  |                                                                           | 
    207  |    Performs the subtraction (var1+var2) with overflow control and satu-   | 
    208  |    ration; the 16 bit result is set at +32767 when overflow occurs or at  | 
    209  |    -32768 when underflow occurs.                                          | 
    210  |                                                                           | 
    211  |   Complexity weight : 1                                                   | 
    212  |                                                                           | 
    213  |   Inputs :                                                                | 
    214  |                                                                           | 
    215  |    var1                                                                   | 
    216  |             16 bit short signed integer (Word16) whose value falls in the | 
    217  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    218  |                                                                           | 
    219  |    var2                                                                   | 
    220  |             16 bit short signed integer (Word16) whose value falls in the | 
    221  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    222  |                                                                           | 
    223  |   Outputs :                                                               | 
    224  |                                                                           | 
    225  |    none                                                                   | 
    226  |                                                                           | 
    227  |   Return Value :                                                          | 
    228  |                                                                           | 
    229  |    var_out                                                                | 
    230  |             16 bit short signed integer (Word16) whose value falls in the | 
    231  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                | 
    232  |___________________________________________________________________________| 
    233 */ 
    234 Word16 sub (Word16 var1, Word16 var2) 
    235 { 
    236     Word16 var_out; 
    237     Word32 L_diff; 
    238  
    239     L_diff = (Word32) var1 - var2; 
    240     var_out = saturate (L_diff); 
    241 #if (WMOPS) 
    242     multiCounter[currCounter].sub++; 
    243 #endif 
    244     return (var_out); 
    245 } 
    246 /* ------------------------- End of sub() ------------------------- */ 
    247  
    248  
    249 /*___________________________________________________________________________ 
    250  |                                                                           | 
    251  |   Function Name : abs_s                                                   | 
    252  |                                                                           | 
    253  |   Purpose :                                                               | 
    254  |                                                                           | 
    255  |    Absolute value of var1; abs_s(-32768) = 32767.                         | 
    256  |                                                                           | 
    257  |   Complexity weight : 1                                                   | 
    258  |                                                                           | 
    259  |   Inputs :                                                                | 
    260  |                                                                           | 
    261  |    var1                                                                   | 
    262  |             16 bit short signed integer (Word16) whose value falls in the | 
    263  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    264  |                                                                           | 
    265  |   Outputs :                                                               | 
    266  |                                                                           | 
    267  |    none                                                                   | 
    268  |                                                                           | 
    269  |   Return Value :                                                          | 
    270  |                                                                           | 
    271  |    var_out                                                                | 
    272  |             16 bit short signed integer (Word16) whose value falls in the | 
    273  |             range : 0x0000 0000 <= var_out <= 0x0000 7fff.                | 
    274  |___________________________________________________________________________| 
    275 */ 
    276 Word16 abs_s (Word16 var1) 
    277 { 
    278     Word16 var_out; 
    279  
    280     if (var1 == (Word16) 0X8000) 
    281     { 
    282         var_out = MAX_16; 
    283     } 
    284     else 
    285     { 
    286         if (var1 < 0) 
    287         { 
    288             var_out = -var1; 
    289         } 
    290         else 
    291         { 
    292             var_out = var1; 
    293         } 
    294     } 
    295 #if (WMOPS) 
    296     multiCounter[currCounter].abs_s++; 
    297 #endif 
    298     return (var_out); 
    299 } 
    300 /* ------------------------- End of abs_s() ------------------------- */ 
     139        return shr_nocheck(var1, var2); 
     140    } 
     141} 
     142/* ------------------------- End of shr() ------------------------- */ 
    301143 
    302144 
     
    337179Word16 shl (Word16 var1, Word16 var2) 
    338180{ 
    339     Word16 var_out; 
    340     Word32 result; 
    341  
    342181    if (var2 < 0) 
    343182    { 
    344         if (var2 < -16) 
    345             var2 = -16; 
    346         var_out = shr (var1, (Word16) -var2); 
    347 #if (WMOPS) 
    348         multiCounter[currCounter].shr--; 
    349 #endif 
     183        return shr_nocheck(var1, (Word16) -var2); 
    350184    } 
    351185    else 
    352186    { 
    353         result = (Word32) var1 *((Word32) 1 << var2); 
    354  
    355         if ((var2 > 15 && var1 != 0) || (result != (Word32) ((Word16) result))) 
    356         { 
    357             Overflow = 1; 
    358             var_out = (var1 > 0) ? MAX_16 : MIN_16; 
    359         } 
    360         else 
    361         { 
    362             var_out = extract_l (result); 
    363 #if (WMOPS) 
    364             multiCounter[currCounter].extract_l--; 
    365 #endif 
    366         } 
    367     } 
    368 #if (WMOPS) 
    369     multiCounter[currCounter].shl++; 
    370 #endif 
    371     return (var_out); 
     187        return shl_nocheck(var1, var2); 
     188    } 
    372189} 
    373190/* ------------------------- End of shl() ------------------------- */ 
    374191 
    375  
    376 /*___________________________________________________________________________ 
    377  |                                                                           | 
    378  |   Function Name : shr                                                     | 
    379  |                                                                           | 
    380  |   Purpose :                                                               | 
    381  |                                                                           | 
    382  |   Arithmetically shift the 16 bit input var1 right var2 positions with    | 
    383  |   sign extension. If var2 is negative, arithmetically shift var1 left by  | 
    384  |   -var2 with sign extension. Saturate the result in case of underflows or | 
    385  |   overflows.                                                              | 
    386  |                                                                           | 
    387  |   Complexity weight : 1                                                   | 
    388  |                                                                           | 
    389  |   Inputs :                                                                | 
    390  |                                                                           | 
    391  |    var1                                                                   | 
    392  |             16 bit short signed integer (Word16) whose value falls in the | 
    393  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    394  |                                                                           | 
    395  |    var2                                                                   | 
    396  |             16 bit short signed integer (Word16) whose value falls in the | 
    397  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    398  |                                                                           | 
    399  |   Outputs :                                                               | 
    400  |                                                                           | 
    401  |    none                                                                   | 
    402  |                                                                           | 
    403  |   Return Value :                                                          | 
    404  |                                                                           | 
    405  |    var_out                                                                | 
    406  |             16 bit short signed integer (Word16) whose value falls in the | 
    407  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                | 
    408  |___________________________________________________________________________| 
    409 */ 
    410 Word16 shr (Word16 var1, Word16 var2) 
    411 { 
    412     Word16 var_out; 
    413  
    414     if (var2 < 0) 
    415     { 
    416         if (var2 < -16) 
    417             var2 = -16; 
    418         var_out = shl (var1, (Word16) -var2); 
    419 #if (WMOPS) 
    420         multiCounter[currCounter].shl--; 
    421 #endif 
    422     } 
    423     else 
    424     { 
    425         if (var2 >= 15) 
    426         { 
    427             var_out = (var1 < 0) ? -1 : 0; 
    428         } 
    429         else 
    430         { 
    431             if (var1 < 0) 
    432             { 
    433                 var_out = ~((~var1) >> var2); 
    434             } 
    435             else 
    436             { 
    437                 var_out = var1 >> var2; 
    438             } 
    439         } 
    440     } 
    441  
    442 #if (WMOPS) 
    443     multiCounter[currCounter].shr++; 
    444 #endif 
    445     return (var_out); 
    446 } 
    447 /* ------------------------- End of shr() ------------------------- */ 
    448192 
    449193 
     
    505249/*___________________________________________________________________________ 
    506250 |                                                                           | 
    507  |   Function Name : L_mult                                                  | 
    508  |                                                                           | 
    509  |   Purpose :                                                               | 
    510  |                                                                           | 
    511  |   L_mult is the 32 bit result of the multiplication of var1 times var2    | 
    512  |   with one shift left i.e.:                                               | 
    513  |        L_mult(var1,var2) = L_shl((var1 times var2),1) and                 | 
    514  |        L_mult(-32768,-32768) = 2147483647.                                | 
     251 |   Function Name : L_msu                                                   | 
     252 |                                                                           | 
     253 |   Purpose :                                                               | 
     254 |                                                                           | 
     255 |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   | 
     256 |   bit result to L_var3 with saturation, return a 32 bit result:           | 
     257 |        L_msu(L_var3,var1,var2) = L_sub(L_var3,L_mult(var1,var2)).         | 
    515258 |                                                                           | 
    516259 |   Complexity weight : 1                                                   | 
    517260 |                                                                           | 
    518261 |   Inputs :                                                                | 
     262 |                                                                           | 
     263 |    L_var3   32 bit long signed integer (Word32) whose value falls in the  | 
     264 |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 | 
    519265 |                                                                           | 
    520266 |    var1                                                                   | 
     
    537283 |___________________________________________________________________________| 
    538284*/ 
    539 Word32 L_mult (Word16 var1, Word16 var2) 
    540 { 
    541     Word32 L_var_out; 
    542  
    543     L_var_out = (Word32) var1 *(Word32) var2; 
    544  
    545     if (L_var_out != (Word32) 0x40000000L) 
    546     { 
    547         L_var_out *= 2; 
    548     } 
    549     else 
    550     { 
    551         Overflow = 1; 
    552         L_var_out = MAX_32; 
    553     } 
    554  
    555 #if (WMOPS) 
    556     multiCounter[currCounter].L_mult++; 
    557 #endif 
    558     return (L_var_out); 
    559 } 
    560 /* ------------------------- End of L_mult() ------------------------- */ 
    561  
    562  
    563 /*___________________________________________________________________________ 
    564  |                                                                           | 
    565  |   Function Name : negate                                                  | 
    566  |                                                                           | 
    567  |   Purpose :                                                               | 
    568  |                                                                           | 
    569  |   Negate var1 with saturation, saturate in the case where input is -32768:| 
    570  |                negate(var1) = sub(0,var1).                                | 
    571  |                                                                           | 
    572  |   Complexity weight : 1                                                   | 
    573  |                                                                           | 
    574  |   Inputs :                                                                | 
    575  |                                                                           | 
    576  |    var1                                                                   | 
    577  |             16 bit short signed integer (Word16) whose value falls in the | 
    578  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    579  |                                                                           | 
    580  |   Outputs :                                                               | 
    581  |                                                                           | 
    582  |    none                                                                   | 
    583  |                                                                           | 
    584  |   Return Value :                                                          | 
    585  |                                                                           | 
    586  |    var_out                                                                | 
    587  |             16 bit short signed integer (Word16) whose value falls in the | 
    588  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                | 
    589  |___________________________________________________________________________| 
    590 */ 
    591 Word16 negate (Word16 var1) 
    592 { 
    593     Word16 var_out; 
    594  
    595     var_out = (var1 == MIN_16) ? MAX_16 : -var1; 
    596 #if (WMOPS) 
    597     multiCounter[currCounter].negate++; 
    598 #endif 
    599     return (var_out); 
    600 } 
    601 /* ------------------------- End of negate() ------------------------- */ 
    602  
    603  
    604 /*___________________________________________________________________________ 
    605  |                                                                           | 
    606  |   Function Name : extract_h                                               | 
    607  |                                                                           | 
    608  |   Purpose :                                                               | 
    609  |                                                                           | 
    610  |   Return the 16 MSB of L_var1.                                            | 
    611  |                                                                           | 
    612  |   Complexity weight : 1                                                   | 
    613  |                                                                           | 
    614  |   Inputs :                                                                | 
    615  |                                                                           | 
    616  |    L_var1                                                                 | 
    617  |             32 bit long signed integer (Word32 ) whose value falls in the | 
    618  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 | 
    619  |                                                                           | 
    620  |   Outputs :                                                               | 
    621  |                                                                           | 
    622  |    none                                                                   | 
    623  |                                                                           | 
    624  |   Return Value :                                                          | 
    625  |                                                                           | 
    626  |    var_out                                                                | 
    627  |             16 bit short signed integer (Word16) whose value falls in the | 
    628  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                | 
    629  |___________________________________________________________________________| 
    630 */ 
    631 Word16 extract_h (Word32 L_var1) 
    632 { 
    633     Word16 var_out; 
    634  
    635     var_out = (Word16) (L_var1 >> 16); 
    636 #if (WMOPS) 
    637     multiCounter[currCounter].extract_h++; 
    638 #endif 
    639     return (var_out); 
    640 } 
    641 /* ------------------------- End of extract_h() ------------------------- */ 
    642  
    643  
    644 /*___________________________________________________________________________ 
    645  |                                                                           | 
    646  |   Function Name : extract_l                                               | 
    647  |                                                                           | 
    648  |   Purpose :                                                               | 
    649  |                                                                           | 
    650  |   Return the 16 LSB of L_var1.                                            | 
    651  |                                                                           | 
    652  |   Complexity weight : 1                                                   | 
    653  |                                                                           | 
    654  |   Inputs :                                                                | 
    655  |                                                                           | 
    656  |    L_var1                                                                 | 
    657  |             32 bit long signed integer (Word32 ) whose value falls in the | 
    658  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 | 
    659  |                                                                           | 
    660  |   Outputs :                                                               | 
    661  |                                                                           | 
    662  |    none                                                                   | 
    663  |                                                                           | 
    664  |   Return Value :                                                          | 
    665  |                                                                           | 
    666  |    var_out                                                                | 
    667  |             16 bit short signed integer (Word16) whose value falls in the | 
    668  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                | 
    669  |___________________________________________________________________________| 
    670 */ 
    671 Word16 extract_l (Word32 L_var1) 
    672 { 
    673     Word16 var_out; 
    674  
    675     var_out = (Word16) L_var1; 
    676 #if (WMOPS) 
    677     multiCounter[currCounter].extract_l++; 
    678 #endif 
    679     return (var_out); 
    680 } 
    681 /* ------------------------- End of extract_l() ------------------------- */ 
    682  
    683  
    684 /*___________________________________________________________________________ 
    685  |                                                                           | 
    686  |   Function Name : round                                                   | 
    687  |                                                                           | 
    688  |   Purpose :                                                               | 
    689  |                                                                           | 
    690  |   Round the lower 16 bits of the 32 bit input number into the MS 16 bits  | 
    691  |   with saturation. Shift the resulting bits right by 16 and return the 16 | 
    692  |   bit number:                                                             | 
    693  |               round(L_var1) = extract_h(L_add(L_var1,32768))              | 
    694  |                                                                           | 
    695  |   Complexity weight : 1                                                   | 
    696  |                                                                           | 
    697  |   Inputs :                                                                | 
    698  |                                                                           | 
    699  |    L_var1                                                                 | 
    700  |             32 bit long signed integer (Word32 ) whose value falls in the | 
    701  |             range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.                 | 
    702  |                                                                           | 
    703  |   Outputs :                                                               | 
    704  |                                                                           | 
    705  |    none                                                                   | 
    706  |                                                                           | 
    707  |   Return Value :                                                          | 
    708  |                                                                           | 
    709  |    var_out                                                                | 
    710  |             16 bit short signed integer (Word16) whose value falls in the | 
    711  |             range : 0xffff 8000 <= var_out <= 0x0000 7fff.                | 
    712  |___________________________________________________________________________| 
    713 */ 
    714 Word16 itu_round (Word32 L_var1) 
    715 { 
    716     Word16 var_out; 
    717     Word32 L_rounded; 
    718  
    719     L_rounded = L_add (L_var1, (Word32) 0x00008000L); 
    720 #if (WMOPS) 
    721     multiCounter[currCounter].L_add--; 
    722 #endif 
    723     var_out = extract_h (L_rounded); 
    724 #if (WMOPS) 
    725     multiCounter[currCounter].extract_h--; 
    726     multiCounter[currCounter].round++; 
    727 #endif 
    728     return (var_out); 
    729 } 
    730 /* ------------------------- End of round() ------------------------- */ 
    731  
    732  
    733 /*___________________________________________________________________________ 
    734  |                                                                           | 
    735  |   Function Name : L_mac                                                   | 
    736  |                                                                           | 
    737  |   Purpose :                                                               | 
    738  |                                                                           | 
    739  |   Multiply var1 by var2 and shift the result left by 1. Add the 32 bit    | 
    740  |   result to L_var3 with saturation, return a 32 bit result:               | 
    741  |        L_mac(L_var3,var1,var2) = L_add(L_var3,L_mult(var1,var2)).         | 
    742  |                                                                           | 
    743  |   Complexity weight : 1                                                   | 
    744  |                                                                           | 
    745  |   Inputs :                                                                | 
    746  |                                                                           | 
    747  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  | 
    748  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 | 
    749  |                                                                           | 
    750  |    var1                                                                   | 
    751  |             16 bit short signed integer (Word16) whose value falls in the | 
    752  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    753  |                                                                           | 
    754  |    var2                                                                   | 
    755  |             16 bit short signed integer (Word16) whose value falls in the | 
    756  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    757  |                                                                           | 
    758  |   Outputs :                                                               | 
    759  |                                                                           | 
    760  |    none                                                                   | 
    761  |                                                                           | 
    762  |   Return Value :                                                          | 
    763  |                                                                           | 
    764  |    L_var_out                                                              | 
    765  |             32 bit long signed integer (Word32) whose value falls in the  | 
    766  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              | 
    767  |___________________________________________________________________________| 
    768 */ 
    769 Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2) 
     285Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2) 
    770286{ 
    771287    Word32 L_var_out; 
     
    776292    multiCounter[currCounter].L_mult--; 
    777293#endif 
    778     L_var_out = L_add (L_var3, L_product); 
    779 #if (WMOPS) 
    780     multiCounter[currCounter].L_add--; 
    781     multiCounter[currCounter].L_mac++; 
    782 #endif 
    783     return (L_var_out); 
    784 } 
    785 /* ------------------------- End of L_mac() ------------------------- */ 
    786  
    787  
    788 /*___________________________________________________________________________ 
    789  |                                                                           | 
    790  |   Function Name : L_msu                                                   | 
    791  |                                                                           | 
    792  |   Purpose :                                                               | 
    793  |                                                                           | 
    794  |   Multiply var1 by var2 and shift the result left by 1. Subtract the 32   | 
    795  |   bit result to L_var3 with saturation, return a 32 bit result:           | 
    796  |        L_msu(L_var3,var1,var2) = L_sub(L_var3,L_mult(var1,var2)).         | 
    797  |                                                                           | 
    798  |   Complexity weight : 1                                                   | 
    799  |                                                                           | 
    800  |   Inputs :                                                                | 
    801  |                                                                           | 
    802  |    L_var3   32 bit long signed integer (Word32) whose value falls in the  | 
    803  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 | 
    804  |                                                                           | 
    805  |    var1                                                                   | 
    806  |             16 bit short signed integer (Word16) whose value falls in the | 
    807  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    808  |                                                                           | 
    809  |    var2                                                                   | 
    810  |             16 bit short signed integer (Word16) whose value falls in the | 
    811  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    812  |                                                                           | 
    813  |   Outputs :                                                               | 
    814  |                                                                           | 
    815  |    none                                                                   | 
    816  |                                                                           | 
    817  |   Return Value :                                                          | 
    818  |                                                                           | 
    819  |    L_var_out                                                              | 
    820  |             32 bit long signed integer (Word32) whose value falls in the  | 
    821  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              | 
    822  |___________________________________________________________________________| 
    823 */ 
    824 Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2) 
    825 { 
    826     Word32 L_var_out; 
    827     Word32 L_product; 
    828  
    829     L_product = L_mult (var1, var2); 
    830 #if (WMOPS) 
    831     multiCounter[currCounter].L_mult--; 
    832 #endif 
    833294    L_var_out = L_sub (L_var3, L_product); 
    834295#if (WMOPS) 
     
    840301/* ------------------------- End of L_msu() ------------------------- */ 
    841302 
    842  
     303#if INCLUDE_UNSAFE 
    843304/*___________________________________________________________________________ 
    844305 |                                                                           | 
     
    898359    return (L_var_out); 
    899360} 
     361#endif 
    900362/* ------------------------- End of L_macNs() ------------------------- */ 
    901363 
    902  
     364#if INCLUDE_UNSAFE 
    903365/*___________________________________________________________________________ 
    904366 |                                                                           | 
     
    958420    return (L_var_out); 
    959421} 
     422#endif 
     423 
    960424/* ------------------------- End of L_msuNs() ------------------------- */ 
    961425 
    962426 
    963 /*___________________________________________________________________________ 
    964  |                                                                           | 
    965  |   Function Name : L_add                                                   | 
    966  |                                                                           | 
    967  |   Purpose :                                                               | 
    968  |                                                                           | 
    969  |   32 bits addition of the two 32 bits variables (L_var1+L_var2) with      | 
    970  |   overflow control and saturation; the result is set at +2147483647 when  | 
    971  |   overflow occurs or at -2147483648 when underflow occurs.                | 
    972  |                                                                           | 
    973  |   Complexity weight : 2                                                   | 
    974  |                                                                           | 
    975  |   Inputs :                                                                | 
    976  |                                                                           | 
    977  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  | 
    978  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 | 
    979  |                                                                           | 
    980  |    L_var2   32 bit long signed integer (Word32) whose value falls in the  | 
    981  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 | 
    982  |                                                                           | 
    983  |   Outputs :                                                               | 
    984  |                                                                           | 
    985  |    none                                                                   | 
    986  |                                                                           | 
    987  |   Return Value :                                                          | 
    988  |                                                                           | 
    989  |    L_var_out                                                              | 
    990  |             32 bit long signed integer (Word32) whose value falls in the  | 
    991  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              | 
    992  |___________________________________________________________________________| 
    993 */ 
    994 Word32 L_add (Word32 L_var1, Word32 L_var2) 
    995 { 
    996     Word32 L_var_out; 
    997  
    998     L_var_out = L_var1 + L_var2; 
    999  
    1000     if (((L_var1 ^ L_var2) & MIN_32) == 0) 
    1001     { 
    1002         if ((L_var_out ^ L_var1) & MIN_32) 
    1003         { 
    1004             L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32; 
    1005             Overflow = 1; 
    1006         } 
    1007     } 
    1008 #if (WMOPS) 
    1009     multiCounter[currCounter].L_add++; 
    1010 #endif 
    1011     return (L_var_out); 
    1012 } 
    1013 /* ------------------------- End of L_add() ------------------------- */ 
    1014  
    1015  
    1016 /*___________________________________________________________________________ 
    1017  |                                                                           | 
    1018  |   Function Name : L_sub                                                   | 
    1019  |                                                                           | 
    1020  |   Purpose :                                                               | 
    1021  |                                                                           | 
    1022  |   32 bits subtraction of the two 32 bits variables (L_var1-L_var2) with   | 
    1023  |   overflow control and saturation; the result is set at +2147483647 when  | 
    1024  |   overflow occurs or at -2147483648 when underflow occurs.                | 
    1025  |                                                                           | 
    1026  |   Complexity weight : 2                                                   | 
    1027  |                                                                           | 
    1028  |   Inputs :                                                                | 
    1029  |                                                                           | 
    1030  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  | 
    1031  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 | 
    1032  |                                                                           | 
    1033  |    L_var2   32 bit long signed integer (Word32) whose value falls in the  | 
    1034  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 | 
    1035  |                                                                           | 
    1036  |   Outputs :                                                               | 
    1037  |                                                                           | 
    1038  |    none                                                                   | 
    1039  |                                                                           | 
    1040  |   Return Value :                                                          | 
    1041  |                                                                           | 
    1042  |    L_var_out                                                              | 
    1043  |             32 bit long signed integer (Word32) whose value falls in the  | 
    1044  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              | 
    1045  |___________________________________________________________________________| 
    1046 */ 
    1047 Word32 L_sub (Word32 L_var1, Word32 L_var2) 
    1048 { 
    1049     Word32 L_var_out; 
    1050  
    1051     L_var_out = L_var1 - L_var2; 
    1052  
    1053     if (((L_var1 ^ L_var2) & MIN_32) != 0) 
    1054     { 
    1055         if ((L_var_out ^ L_var1) & MIN_32) 
    1056         { 
    1057             L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32; 
    1058             Overflow = 1; 
    1059         } 
    1060     } 
    1061 #if (WMOPS) 
    1062     multiCounter[currCounter].L_sub++; 
    1063 #endif 
    1064     return (L_var_out); 
    1065 } 
    1066 /* ------------------------- End of L_sub() ------------------------- */ 
    1067  
    1068  
     427#if INCLUDE_UNSAFE 
    1069428/*___________________________________________________________________________ 
    1070429 |                                                                           | 
     
    1110469    Flag carry_int = 0; 
    1111470 
    1112     L_var_out = L_var1 + L_var2 + Carry; 
     471    L_var_out = L_var1 + L_var2 + GET_CARRY(); 
    1113472 
    1114473    L_test = L_var1 + L_var2; 
     
    1116475    if ((L_var1 > 0) && (L_var2 > 0) && (L_test < 0)) 
    1117476    { 
    1118         Overflow = 1; 
     477        SET_OVERFLOW(1); 
    1119478        carry_int = 0; 
    1120479    } 
     
    1125484            if (L_test >= 0) 
    1126485            { 
    1127                 Overflow = 1; 
     486                SET_OVERFLOW(1); 
    1128487                carry_int = 1; 
    1129488            } 
    1130489            else 
    1131490            { 
    1132                 Overflow = 0; 
     491                SET_OVERFLOW(0); 
    1133492                carry_int = 1; 
    1134493            } 
     
    1138497            if (((L_var1 ^ L_var2) < 0) && (L_test >= 0)) 
    1139498            { 
    1140                 Overflow = 0; 
     499                SET_OVERFLOW(0); 
    1141500                carry_int = 1; 
    1142501            } 
    1143502            else 
    1144503            { 
    1145                 Overflow = 0; 
     504                SET_OVERFLOW(0); 
    1146505                carry_int = 0; 
    1147506            } 
     
    1149508    } 
    1150509 
    1151     if (Carry) 
     510    if (GET_CARRY()) 
    1152511    { 
    1153512        if (L_test == MAX_32) 
    1154513        { 
    1155             Overflow = 1; 
    1156             Carry = carry_int; 
     514            SET_OVERFLOW(1); 
     515            SET_CARRY(carry_int); 
    1157516        } 
    1158517        else 
     
    1160519            if (L_test == (Word32) 0xFFFFFFFFL) 
    1161520            { 
    1162                 Carry = 1; 
     521                SET_CARRY(1); 
    1163522            } 
    1164523            else 
    1165524            { 
    1166                 Carry = carry_int; 
     525                SET_CARRY(carry_int); 
    1167526            } 
    1168527        } 
     
    1170529    else 
    1171530    { 
    1172         Carry = carry_int; 
     531        SET_CARRY(carry_int); 
    1173532    } 
    1174533 
     
    1178537    return (L_var_out); 
    1179538} 
     539#endif 
     540 
    1180541/* ------------------------- End of L_add_c() ------------------------- */ 
    1181542 
    1182  
     543#if INCLUDE_UNSAFE 
    1183544/*___________________________________________________________________________ 
    1184545 |                                                                           | 
     
    1224585    Flag carry_int = 0; 
    1225586 
    1226     if (Carry) 
    1227     { 
    1228         Carry = 0; 
     587    if (GET_CARRY()) 
     588    { 
     589        SET_CARRY(0); 
    1229590        if (L_var2 != MIN_32) 
    1230591        { 
     
    1239600            if (L_var1 > 0L) 
    1240601            { 
    1241                 Overflow = 1; 
    1242                 Carry = 0; 
     602                SET_OVERFLOW(1); 
     603                SET_CARRY(0); 
    1243604            } 
    1244605        } 
     
    1251612        if ((L_test < 0) && (L_var1 > 0) && (L_var2 < 0)) 
    1252613        { 
    1253             Overflow = 1; 
     614            SET_OVERFLOW(1); 
    1254615            carry_int = 0; 
    1255616        } 
    1256617        else if ((L_test > 0) && (L_var1 < 0) && (L_var2 > 0)) 
    1257618        { 
    1258             Overflow = 1; 
     619            SET_OVERFLOW(1); 
    1259620            carry_int = 1; 
    1260621        } 
    1261622        else if ((L_test > 0) && ((L_var1 ^ L_var2) > 0)) 
    1262623        { 
    1263             Overflow = 0; 
     624            SET_OVERFLOW(0); 
    1264625            carry_int = 1; 
    1265626        } 
    1266627        if (L_test == MIN_32) 
    1267628        { 
    1268             Overflow = 1; 
    1269             Carry = carry_int; 
     629            SET_OVERFLOW(1); 
     630            SET_CARRY(carry_int); 
    1270631        } 
    1271632        else 
    1272633        { 
    1273             Carry = carry_int; 
     634            SET_CARRY(carry_int); 
    1274635        } 
    1275636    } 
     
    1280641    return (L_var_out); 
    1281642} 
     643#endif 
    1282644/* ------------------------- End of L_sub_c() ------------------------- */ 
    1283645 
     
    1378740/* ------------------------- End of mult_r() ------------------------- */ 
    1379741 
    1380  
    1381 /*___________________________________________________________________________ 
    1382  |                                                                           | 
    1383  |   Function Name : L_shl                                                   | 
    1384  |                                                                           | 
    1385  |   Purpose :                                                               | 
    1386  |                                                                           | 
    1387  |   Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero  | 
    1388  |   fill the var2 LSB of the result. If var2 is negative, arithmetically    | 
    1389  |   shift L_var1 right by -var2 with sign extension. Saturate the result in | 
    1390  |   case of underflows or overflows.                                        | 
    1391  |                                                                           | 
    1392  |   Complexity weight : 2                                                   | 
    1393  |                                                                           | 
    1394  |   Inputs :                                                                | 
    1395  |                                                                           | 
    1396  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  | 
    1397  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 | 
    1398  |                                                                           | 
    1399  |    var2                                                                   | 
    1400  |             16 bit short signed integer (Word16) whose value falls in the | 
    1401  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    1402  |                                                                           | 
    1403  |   Outputs :                                                               | 
    1404  |                                                                           | 
    1405  |    none                                                                   | 
    1406  |                                                                           | 
    1407  |   Return Value :                                                          | 
    1408  |                                                                           | 
    1409  |    L_var_out                                                              | 
    1410  |             32 bit long signed integer (Word32) whose value falls in the  | 
    1411  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              | 
    1412  |___________________________________________________________________________| 
    1413 */ 
    1414 Word32 L_shl (Word32 L_var1, Word16 var2) 
    1415 { 
    1416     Word32 L_var_out; 
    1417  
    1418     if (var2 <= 0) 
    1419     { 
    1420         if (var2 < -32) 
    1421             var2 = -32; 
    1422         L_var_out = L_shr (L_var1, (Word16) -var2); 
    1423 #if (WMOPS) 
    1424         multiCounter[currCounter].L_shr--; 
    1425 #endif 
    1426     } 
    1427     else 
    1428     { 
    1429         for (; var2 > 0; var2--) 
    1430         { 
    1431             if (L_var1 > (Word32) 0X3fffffffL) 
    1432             { 
    1433                 Overflow = 1; 
    1434                 L_var_out = MAX_32; 
    1435                 break; 
    1436             } 
    1437             else 
    1438             { 
    1439                 if (L_var1 < (Word32) 0xc0000000L) 
    1440                 { 
    1441                     Overflow = 1; 
    1442                     L_var_out = MIN_32; 
    1443                     break; 
    1444                 } 
    1445             } 
    1446             L_var1 *= 2; 
    1447             L_var_out = L_var1; 
    1448         } 
    1449     } 
    1450 #if (WMOPS) 
    1451     multiCounter[currCounter].L_shl++; 
    1452 #endif 
    1453     return (L_var_out); 
    1454 } 
    1455 /* ------------------------- End of L_shl() ------------------------- */ 
    1456  
    1457  
    1458 /*___________________________________________________________________________ 
    1459  |                                                                           | 
    1460  |   Function Name : L_shr                                                   | 
    1461  |                                                                           | 
    1462  |   Purpose :                                                               | 
    1463  |                                                                           | 
    1464  |   Arithmetically shift the 32 bit input L_var1 right var2 positions with  | 
    1465  |   sign extension. If var2 is negative, arithmetically shift L_var1 left   | 
    1466  |   by -var2 and zero fill the -var2 LSB of the result. Saturate the result | 
    1467  |   in case of underflows or overflows.                                     | 
    1468  |                                                                           | 
    1469  |   Complexity weight : 2                                                   | 
    1470  |                                                                           | 
    1471  |   Inputs :                                                                | 
    1472  |                                                                           | 
    1473  |    L_var1   32 bit long signed integer (Word32) whose value falls in the  | 
    1474  |             range : 0x8000 0000 <= L_var3 <= 0x7fff ffff.                 | 
    1475  |                                                                           | 
    1476  |    var2                                                                   | 
    1477  |             16 bit short signed integer (Word16) whose value falls in the | 
    1478  |             range : 0xffff 8000 <= var1 <= 0x0000 7fff.                   | 
    1479  |                                                                           | 
    1480  |   Outputs :                                                               | 
    1481  |                                                                           | 
    1482  |    none                                                                   | 
    1483  |                                                                           | 
    1484  |   Return Value :                                                          | 
    1485  |                                                                           | 
    1486  |    L_var_out                                                              | 
    1487  |             32 bit long signed integer (Word32) whose value falls in the  | 
    1488  |             range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.              | 
    1489  |___________________________________________________________________________| 
    1490 */ 
    1491 Word32 L_shr (Word32 L_var1, Word16 var2) 
    1492 { 
    1493     Word32 L_var_out; 
    1494  
    1495     if (var2 < 0) 
    1496     { 
    1497         if (var2 < -32) 
    1498             var2 = -32; 
    1499         L_var_out = L_shl (L_var1, (Word16) -var2); 
    1500 #if (WMOPS) 
    1501         multiCounter[currCounter].L_shl--; 
    1502 #endif 
    1503     } 
    1504     else 
    1505     { 
    1506         if (var2 >= 31) 
    1507         { 
    1508             L_var_out = (L_var1 < 0L) ? -1 : 0; 
    1509         } 
    1510         else 
    1511         { 
    1512             if (L_var1 < 0) 
    1513             { 
    1514                 L_var_out = ~((~L_var1) >> var2); 
    1515             } 
    1516             else 
    1517             { 
    1518                 L_var_out = L_var1 >> var2; 
    1519             } 
    1520         } 
    1521     } 
    1522 #if (WMOPS) 
    1523     multiCounter[currCounter].L_shr++; 
    1524 #endif 
    1525     return (L_var_out); 
    1526 } 
    1527 /* ------------------------- End of L_shr() ------------------------- */ 
    1528742 
    1529743 
     
    19311145/*___________________________________________________________________________ 
    19321146 |                                                                           | 
    1933  |   Function Name : L_sat                                                   | 
    1934  |                                                                           | 
    1935  |   Purpose :                                                               | 
    1936  |                                                                           | 
    1937  |    32 bit L_var1 is set to 2147483647 if an overflow occured or to        | 
    1938  |    -2147483648 if an underflow occured on the most recent L_add_c,        | 
    1939  |    L_sub_c, L_macNs or L_msuNs operations. The carry and overflow values  | 
    1940  |    are binary values which can be tested and assigned values.             | 
    1941  |                                                                           | 
    1942  |   Complexity weight : 4                                                   | 
    1943  |                                                                           | 
    1944  |   Inputs :                                                                | 
    1945  |                                                                           | 
    1946  |    L_var1                                                                 | 
    1947  |             32 bit long signed integer (Word32) whose value falls in the  | 
    1948  |             range : 0x8000 0000 <= var1 <= 0x7fff ffff.                   | 
    1949  |                                                                           | 
    1950  |   Outputs :                                                               | 
    1951  |                                                                           | 
    1952  |    none                                                                   | 
    1953  |                                                                           | 
    1954  |   Return Value :                                                          | 
    1955  |                                                                           | 
    1956  |    L_var_out                                                              | 
    1957  |             32 bit long signed integer (Word32) whose value falls in the  | 
    1958  |             range : 0x8000 0000 <= var_out <= 0x7fff ffff.                | 
    1959  |___________________________________________________________________________| 
    1960 */ 
    1961 Word32 L_sat (Word32 L_var1) 
    1962 { 
    1963     Word32 L_var_out; 
    1964  
    1965     L_var_out = L_var1; 
    1966  
    1967     if (Overflow) 
    1968     { 
    1969  
    1970         if (Carry) 
    1971         { 
    1972             L_var_out = MIN_32; 
    1973         } 
    1974         else 
    1975         { 
    1976             L_var_out = MAX_32; 
    1977         } 
    1978  
    1979         Carry = 0; 
    1980         Overflow = 0; 
    1981     } 
    1982 #if (WMOPS) 
    1983     multiCounter[currCounter].L_sat++; 
    1984 #endif 
    1985     return (L_var_out); 
    1986 } 
    1987 /* ------------------------- End of L_sat() ------------------------- */ 
    1988  
    1989  
    1990 /*___________________________________________________________________________ 
    1991  |                                                                           | 
    19921147 |   Function Name : norm_s                                                  | 
    19931148 |                                                                           | 
     
    22761431   Temp = Lv & (Word32) 0x0000ffff ; 
    22771432   Temp = Temp * (Word32) v ; 
    2278    Temp = L_shr( Temp, (Word16) 15 ) ; 
     1433   Temp = L_shr_nocheck( Temp, (Word16) 15 ) ; 
    22791434   Temp = L_mac( Temp, v, extract_h(Lv) ) ; 
    22801435 
     
    23581513    } 
    23591514    else { 
    2360         L_num = L_shr(L_num, (Word16)1) ; 
    2361         L_den = L_shr(L_den, (Word16)1); 
     1515        L_num = L_shr_nocheck(L_num, (Word16)1) ; 
     1516        L_den = L_shr_nocheck(L_den, (Word16)1); 
    23621517#if (WMOPS) 
    23631518        multiCounter[currCounter].L_shr-=2; 
    23641519#endif 
    23651520        for(iteration=(Word16)0; iteration< (Word16)15;iteration++) { 
    2366             var_out = shl( var_out, (Word16)1); 
    2367             L_num   = L_shl( L_num, (Word16)1); 
     1521            var_out = shl_nocheck( var_out, (Word16)1); 
     1522            L_num   = L_shl_nocheck( L_num, (Word16)1); 
    23681523#if (WMOPS) 
    23691524            multiCounter[currCounter].shl--; 
     
    26291784            if (L_var1 > (UWord32) 0X7fffffffL) 
    26301785            { 
    2631                 Overflow = 1; 
     1786                SET_OVERFLOW(1); 
    26321787                L_var_out = UMAX_32; 
    26331788                break; 
     
    26371792                if (L_var1 < (UWord32) 0x00000001L) 
    26381793                { 
    2639                     Overflow = 1; 
     1794                    SET_OVERFLOW(1); 
    26401795                    L_var_out = MIN_32; 
    26411796                    break; 
  • pjproject/trunk/third_party/g7221/common/stl-files/basop32.h

    r2601 r2616  
    3434 
    3535#define MAX_16 (Word16)0x7fff 
    36 #define MIN_16 (Word16)0x8000 
     36#define MIN_16 ((Word16)0x8000) 
    3737 
    3838#define UMAX_32 (Word32)0xffffffffL 
     
    4545*/ 
    4646 
    47 Word16 add (Word16 var1, Word16 var2);    /* Short add,           1   */ 
    48 Word16 sub (Word16 var1, Word16 var2);    /* Short sub,           1   */ 
    49 Word16 abs_s (Word16 var1);               /* Short abs,           1   */ 
     47PJ_INLINE(Word16) add (Word16 var1, Word16 var2);    /* Short add,           1   */ 
     48PJ_INLINE(Word16) sub (Word16 var1, Word16 var2);    /* Short sub,           1   */ 
     49PJ_INLINE(Word16) abs_s (Word16 var1);               /* Short abs,           1   */ 
    5050Word16 shl (Word16 var1, Word16 var2);    /* Short shift left,    1   */ 
     51PJ_INLINE(Word16) shl_nocheck(Word16 var1, Word16 var2); 
    5152Word16 shr (Word16 var1, Word16 var2);    /* Short shift right,   1   */ 
     53PJ_INLINE(Word16) shr_nocheck(Word16 var1, Word16 var2); 
    5254Word16 mult (Word16 var1, Word16 var2);   /* Short mult,          1   */ 
    53 Word32 L_mult (Word16 var1, Word16 var2); /* Long mult,           1   */ 
    54 Word16 negate (Word16 var1);              /* Short negate,        1   */ 
    55 Word16 extract_h (Word32 L_var1);         /* Extract high,        1   */ 
    56 Word16 extract_l (Word32 L_var1);         /* Extract low,         1   */ 
    57 Word16 itu_round (Word32 L_var1);         /* Round,               1   */ 
    58 Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2);   /* Mac,  1  */ 
     55PJ_INLINE(Word32) L_mult (Word16 var1, Word16 var2); /* Long mult,           1   */ 
     56PJ_INLINE(Word16) negate (Word16 var1);              /* Short negate,        1   */ 
     57PJ_INLINE(Word16) extract_h (Word32 L_var1);         /* Extract high,        1   */ 
     58PJ_INLINE(Word16) extract_l (Word32 L_var1);         /* Extract low,         1   */ 
     59PJ_INLINE(Word16) itu_round (Word32 L_var1);         /* Round,               1   */ 
     60PJ_INLINE(Word32) L_mac (Word32 L_var3, Word16 var1, Word16 var2);   /* Mac,  1  */ 
    5961Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2);   /* Msu,  1  */ 
    6062Word32 L_macNs (Word32 L_var3, Word16 var1, Word16 var2); /* Mac without 
     
    6264Word32 L_msuNs (Word32 L_var3, Word16 var1, Word16 var2); /* Msu without 
    6365                                                             sat, 1   */ 
    64 Word32 L_add (Word32 L_var1, Word32 L_var2);    /* Long add,        2 */ 
    65 Word32 L_sub (Word32 L_var1, Word32 L_var2);    /* Long sub,        2 */ 
     66//PJ_INLINE(Word32) L_add (Word32 L_var1, Word32 L_var2);    /* Long add,        2 */ 
     67PJ_INLINE(Word32) L_sub (Word32 L_var1, Word32 L_var2);    /* Long sub,        2 */ 
    6668Word32 L_add_c (Word32 L_var1, Word32 L_var2);  /* Long add with c, 2 */ 
    6769Word32 L_sub_c (Word32 L_var1, Word32 L_var2);  /* Long sub with c, 2 */ 
    6870Word32 L_negate (Word32 L_var1);                /* Long negate,     2 */ 
    6971Word16 mult_r (Word16 var1, Word16 var2);       /* Mult with round, 2 */ 
    70 Word32 L_shl (Word32 L_var1, Word16 var2);      /* Long shift left, 2 */ 
    71 Word32 L_shr (Word32 L_var1, Word16 var2);      /* Long shift right, 2*/ 
     72PJ_INLINE(Word32) L_shl (Word32 L_var1, Word16 var2);      /* Long shift left, 2 */ 
     73PJ_INLINE(Word32) L_shr (Word32 L_var1, Word16 var2);      /* Long shift right, 2*/ 
    7274Word16 shr_r (Word16 var1, Word16 var2);        /* Shift right with 
    7375                                                   round, 2           */ 
     
    106108UWord32 LU_shl (UWord32 L_var1, Word16 var2); 
    107109UWord32 LU_shr (UWord32 L_var1, Word16 var2); 
     110 
     111#define INCLUDE_UNSAFE      0 
     112 
     113/* Local */ 
     114PJ_INLINE(Word16) saturate (Word32 L_var1); 
     115 
     116#if INCLUDE_UNSAFE 
     117    extern Flag g7221_Overflow; 
     118    extern Flag g7221_Carry; 
     119#   define SET_OVERFLOW(n)  g7221_Overflow = n 
     120#   define SET_CARRY(n)     g7221_Carry = n 
     121 
     122#else 
     123#   define SET_OVERFLOW(n) 
     124#   define SET_CARRY(n) 
     125#   define GET_OVERFLOW()   0 
     126#   define GET_CARRY()      0 
     127#endif 
     128 
     129#include "basop32_i.h" 
     130 
     131 
     132 
    108133#endif /* BASOP_H_DEFINED */ 
    109134 
  • pjproject/trunk/third_party/g7221/common/stl-files/count.h

    r2563 r2616  
    3636 =========================================================================== 
    3737*/ 
     38#if 0 
    3839#ifndef COUNT_H 
    3940#define COUNT_H "$Id $" 
     
    7273 */ 
    7374 
    74 Word32 fwc (void); 
     75PJ_INLINE(Word32) fwc (void) 
     76{ 
     77#if WMOPS 
     78    Word32 tot; 
     79 
     80    tot = DeltaWeightedOperation (); 
     81    if (tot > wc[currCounter][funcid[currCounter]]) 
     82        wc[currCounter][funcid[currCounter]] = tot; 
     83 
     84    funcid[currCounter]++; 
     85 
     86    return (tot); 
     87#else 
     88    return 0; /* Dummy */ 
     89#endif 
     90} 
     91 
    7592/* 
    7693 * worst worst case counter. 
     
    83100 * The WMOPS_output function add together all parts and presents the sum. 
    84101 */ 
    85  
    86 void move16 (void); 
    87 void move32 (void); 
    88 void logic16 (void); 
    89 void logic32 (void); 
    90 void test (void); 
     102PJ_INLINE(void) move16 (void) 
     103{ 
     104#if WMOPS 
     105    multiCounter[currCounter].DataMove16++; 
     106#endif 
     107} 
     108 
     109PJ_INLINE(void) move32 (void) 
     110{ 
     111#if WMOPS 
     112    multiCounter[currCounter].DataMove32++; 
     113#endif 
     114} 
     115 
     116PJ_INLINE(void )logic16 (void) 
     117{ 
     118#if WMOPS 
     119    multiCounter[currCounter].Logic16++; 
     120#endif 
     121} 
     122 
     123PJ_INLINE(void) logic32 (void) 
     124{ 
     125#if WMOPS 
     126    multiCounter[currCounter].Logic32++; 
     127#endif 
     128} 
     129 
     130PJ_INLINE(void) test (void) 
     131{ 
     132#if WMOPS 
     133    multiCounter[currCounter].Test++; 
     134#endif 
     135} 
     136 
     137 
    91138/* 
    92139 * The functions above increases the corresponding operation counter for 
     
    206253 
    207254#endif /* COUNT_H */ 
     255#else 
     256 
     257#define move16() 
     258#define move32() 
     259#define logic16() 
     260#define logic32() 
     261#define test() 
     262 
     263#endif 
  • pjproject/trunk/third_party/g7221/decode/coef2sam.c

    r2601 r2616  
    8989     
    9090 
    91     half_dct_size = shr(dct_length,1); 
     91    half_dct_size = shr_nocheck(dct_length,1); 
    9292     
    9393    /* Perform a Type IV (inverse) DCT on the coefficients */ 
     
    9999        for(index=0;index<dct_length;index++) 
    100100        { 
    101             new_samples[index] = shr(new_samples[index],mag_shift); 
     101            new_samples[index] = shr_nocheck(new_samples[index],mag_shift); 
    102102            move16(); 
    103103        } 
     
    111111            for(index=0;index<dct_length;index++) 
    112112            { 
    113                 new_samples[index] = shl(new_samples[index],mag_shift); 
     113                new_samples[index] = shl_nocheck(new_samples[index],mag_shift); 
    114114                move16(); 
    115115            } 
     
    148148        sum = L_mac(sum,*win_new++, *--new_ptr); 
    149149        sum = L_mac(sum,*--win_old, *old_ptr++); 
    150         *out_ptr++ = itu_round(L_shl(sum,2)); 
     150        *out_ptr++ = itu_round(L_shl_nocheck(sum,2)); 
    151151        move16(); 
    152152 
     
    161161        sum = L_mac(sum,*win_new++, *new_ptr++); 
    162162        sum = L_mac(sum,negate(*--win_old), *--old_ptr); 
    163         *out_ptr++ = itu_round(L_shl(sum,2)); 
     163        *out_ptr++ = itu_round(L_shl_nocheck(sum,2)); 
    164164        move16(); 
    165165    } 
  • pjproject/trunk/third_party/g7221/decode/dct4_s.c

    r2601 r2616  
    141141         
    142142        /*    set_span      = 1 << (DCT_LENGTH_LOG - set_count_log); */ 
    143         set_span = shr(dct_length,set_count_log); 
     143        set_span = shr_nocheck(dct_length,set_count_log); 
    144144            
    145         set_count     = shl(1,set_count_log); 
     145        set_count     = shl_nocheck(1,set_count_log); 
    146146        in_ptr        = in_buffer; 
    147147        move16(); 
     
    186186                         
    187187                    dummy = add(in_val_low,dither_ptr[i++]); 
    188                     acca = L_add(dummy,in_val_high); 
    189                     out_val_low = extract_l(L_shr(acca,1)); 
     188                    // blp: addition of two 16bits vars, there's no way 
     189                    //      they'll overflow a 32bit var 
     190                    //acca = L_add(dummy,in_val_high); 
     191                    acca = dummy + in_val_high; 
     192                    out_val_low = extract_l(L_shr_nocheck(acca,1)); 
    190193                     
    191194                    dummy = add(in_val_low,dither_ptr[i++]); 
    192                     acca = L_add(dummy,-in_val_high); 
    193                     out_val_high = extract_l(L_shr(acca,1)); 
     195                    // blp: addition of two 16bits vars, there's no way 
     196                    //      they'll overflow a 32bit var 
     197                    //acca = L_add(dummy,-in_val_high); 
     198                    acca = dummy - in_val_high; 
     199                    out_val_high = extract_l(L_shr_nocheck(acca,1)); 
    194200                     
    195201                    *out_ptr_low++  = out_val_low; 
     
    285291        for ( k=0; k<CORE_SIZE; k++ ) 
    286292        { 
     293#if PJ_HAS_INT64 
     294            /* blp: danger danger! not really compatible but faster */ 
     295            pj_int64_t sum64=0; 
     296            move32(); 
     297             
     298            for ( i=0; i<CORE_SIZE; i++ ) 
     299            { 
     300                sum64 += L_mult(pair_ptr[i], dct_core_s[i][k]); 
     301            } 
     302            sum = L_saturate(sum64); 
     303#else 
    287304            sum=0L; 
    288305            move32(); 
     
    292309                sum = L_mac(sum, pair_ptr[i],dct_core_s[i][k]); 
    293310            } 
     311#endif 
    294312            buffer_swap[k] = itu_round(sum); 
    295313        } 
     
    324342         
    325343        /*    set_span      = 1 << (DCT_LENGTH_LOG - set_count_log); */ 
    326         set_span = shr(dct_length,set_count_log); 
    327          
    328         set_count     = shl(1,set_count_log); 
     344        set_span = shr_nocheck(dct_length,set_count_log); 
     345         
     346        set_count     = shl_nocheck(1,set_count_log); 
    329347        next_in_base  = in_buffer; 
    330348        move16(); 
     
    355373            move16(); 
    356374             
    357             temp = shr(set_span,1); 
     375            temp = shr_nocheck(set_span,1); 
    358376            in_ptr_high    = in_ptr_low + temp; 
    359377            move16(); 
     
    402420                sum = L_mac(sum,cos_even,in_low_even); 
    403421                sum = L_mac(sum,negate(msin_even),in_high_even); 
    404                 out_low_even = itu_round(L_shl(sum,1)); 
     422                out_low_even = itu_round(L_shl_nocheck(sum,1)); 
    405423                 
    406424                sum = 0L; 
     
    408426                sum = L_mac(sum,msin_even,in_low_even); 
    409427                sum = L_mac(sum,cos_even,in_high_even); 
    410                 out_high_even = itu_round(L_shl(sum,1)); 
     428                out_high_even = itu_round(L_shl_nocheck(sum,1)); 
    411429                 
    412430                sum = 0L; 
     
    414432                sum = L_mac(sum,cos_odd,in_low_odd); 
    415433                sum = L_mac(sum,msin_odd,in_high_odd); 
    416                 out_low_odd = itu_round(L_shl(sum,1)); 
     434                out_low_odd = itu_round(L_shl_nocheck(sum,1)); 
    417435                 
    418436                sum = 0L; 
     
    420438                sum = L_mac(sum,msin_odd,in_low_odd); 
    421439                sum = L_mac(sum,negate(cos_odd),in_high_odd); 
    422                 out_high_odd = itu_round(L_shl(sum,1)); 
     440                out_high_odd = itu_round(L_shl_nocheck(sum,1)); 
    423441                 
    424442                *out_ptr_low++  = out_low_even; 
     
    459477        for(i=0;i<320;i++)  
    460478        { 
    461            sum = L_add(output[i],syn_bias_7khz[i]); 
     479           // blp: addition of two 16bits vars, there's no way 
     480           //      they'll overflow a 32bit var 
     481           //sum = L_add(output[i],syn_bias_7khz[i]); 
     482           sum = output[i] + syn_bias_7khz[i]; 
    462483           acca = L_sub(sum,32767); 
    463484           test(); 
     
    467488               move32(); 
    468489           } 
    469            acca = L_add(sum,32768L); 
     490           // blp: addition of two 16bits vars, there's no way 
     491           //      they'll overflow 32bit var 
     492           //acca = L_add(sum,32768L); 
     493           acca = sum + 32768; 
    470494           test(); 
    471495           if (acca < 0)  
  • pjproject/trunk/third_party/g7221/decode/decoder.c

    r2563 r2616  
    137137        { 
    138138                get_next_bit(bitobj); 
    139                 categorization_control = shl(categorization_control,1); 
     139                categorization_control = shl_nocheck(categorization_control,1); 
    140140                categorization_control = add(categorization_control,bitobj->next_bit); 
    141141        } 
     
    247247    { 
    248248        get_next_bit(bitobj); 
    249         index = shl(index,1); 
     249        index = shl_nocheck(index,1); 
    250250        index = add(index,bitobj->next_bit); 
    251251    } 
     
    333333    { 
    334334        i = sub(i,1); 
    335         temp = shr(temp,1); 
     335        temp = shr_nocheck(temp,1); 
    336336        max_index = sub(max_index,2); 
    337337        temp1 = sub(temp,8); 
     
    531531                    if (bitobj->next_bit == 0) 
    532532                        { 
    533                         temp = shl(index,1); 
     533                        temp = shl_nocheck(index,1); 
    534534                        index = (Word16)*(decoder_table_ptr + temp); 
    535535                        move16(); 
     
    537537                        else 
    538538                        { 
    539                         temp = shl(index,1); 
     539                        temp = shl_nocheck(index,1); 
    540540                        index = (Word16)*(decoder_table_ptr + temp + 1); 
    541541                        move16(); 
     
    568568                        { 
    569569                                    get_next_bit(bitobj); 
    570                                 signs_index = shl(signs_index,1); 
     570                                signs_index = shl_nocheck(signs_index,1); 
    571571                                    signs_index = add(signs_index,bitobj->next_bit); 
    572572                                    bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,1); 
    573573                            } 
    574574                            temp = sub(num_sign_bits,1); 
    575                         bit = shl(1,(temp)); 
     575                        bit = shl_nocheck(1,(temp)); 
    576576                        } 
    577577                         
     
    579579                    { 
    580580                            acca = L_mult0(standard_deviation,mlt_quant_centroid[category][k[j]]); 
    581                         acca = L_shr(acca,12); 
     581                        acca = L_shr_nocheck(acca,12); 
    582582                        decoder_mlt_value = extract_l(acca); 
    583583                             
     
    588588                            if ((signs_index & bit) == 0) 
    589589                                        decoder_mlt_value = negate(decoder_mlt_value); 
    590                                     bit = shr(bit,1); 
     590                                    bit = shr_nocheck(bit,1); 
    591591                            } 
    592592                        *decoder_mlt_ptr++ = decoder_mlt_value; 
     
    653653                        *decoder_mlt_ptr = temp1; 
    654654                    move16(); 
    655                         random_word = shr(random_word,1); 
     655                        random_word = shr_nocheck(random_word,1); 
    656656                    } 
    657657                    /* pointer arithmetic */ 
     
    678678                        *decoder_mlt_ptr = temp1; 
    679679                    move16(); 
    680                         random_word  = shr(random_word,1); 
     680                        random_word  = shr_nocheck(random_word,1); 
    681681                    } 
    682682                    /* pointer arithmetic */ 
     
    711711                *decoder_mlt_ptr++ = temp1; 
    712712                move16(); 
    713                 random_word = shr(random_word,1); 
     713                random_word = shr_nocheck(random_word,1); 
    714714            } 
    715715            random_word = get_rand(randobj); 
     
    731731                *decoder_mlt_ptr++ = temp1; 
    732732                move16(); 
    733                 random_word = shr(random_word,1); 
     733                random_word = shr_nocheck(random_word,1); 
    734734            } 
    735735        } 
     
    10601060    } 
    10611061    bitobj->code_bit_count = sub(bitobj->code_bit_count,1); 
    1062     temp = shr(bitobj->current_word,bitobj->code_bit_count); 
     1062    temp = shr_nocheck(bitobj->current_word,bitobj->code_bit_count); 
    10631063    logic16(); 
    10641064    bitobj->next_bit = (Word16 )(temp & 1); 
  • pjproject/trunk/third_party/g7221/encode/dct4_a.c

    r2601 r2616  
    136136 
    137137        /*    set_span      = 1 << (DCT_LENGTH_LOG - set_count_log); */ 
    138         set_span = shr(dct_length,set_count_log); 
    139  
    140         set_count     = shl(1,set_count_log); 
     138        set_span = shr_nocheck(dct_length,set_count_log); 
     139 
     140        set_count     = shl_nocheck(1,set_count_log); 
    141141 
    142142        in_ptr        = in_buffer; 
     
    169169                in_val_low      = *in_ptr++; 
    170170                in_val_high     = *in_ptr++; 
    171                 acca            = L_add(in_val_low,in_val_high); 
    172                 acca            = L_shr(acca,1); 
     171                // blp: addition of two 16bits vars, there's no way 
     172                //      they'll overflow a 32bit var 
     173                //acca            = L_add(in_val_low,in_val_high); 
     174                acca = (in_val_low + in_val_high); 
     175                acca            = L_shr_nocheck(acca,1); 
    173176                out_val_low     = extract_l(acca); 
    174177 
    175178                acca            = L_sub(in_val_low,in_val_high); 
    176                 acca            = L_shr(acca,1); 
     179                acca            = L_shr_nocheck(acca,1); 
    177180                out_val_high    = extract_l(acca); 
    178181 
     
    214217 
    215218    temp = sub(dct_length_log,1); 
    216     temp = shl(1,temp); 
     219    temp = shl_nocheck(1,temp); 
    217220 
    218221    for (pairs_left=temp; pairs_left > 0; pairs_left--) 
     
    220223        for ( k=0; k<CORE_SIZE; k++ ) 
    221224        { 
     225#if PJ_HAS_INT64 
     226            /* blp: danger danger! not really compatible but faster */ 
     227            pj_int64_t sum64=0; 
     228            move32(); 
     229             
     230            for ( i=0; i<CORE_SIZE; i++ ) 
     231            { 
     232                sum64 += L_mult(pair_ptr[i], dct_core_a[i][k]); 
     233            } 
     234            sum = L_saturate(sum64); 
     235#else 
    222236            sum=0L; 
    223237            move32(); 
     
    226240                sum = L_mac(sum, pair_ptr[i],dct_core_a[i][k]); 
    227241            } 
     242#endif 
    228243            buffer_swap[k] = itu_round(sum); 
    229244        } 
     
    251266        /*===========================================================*/ 
    252267        /*    set_span      = 1 << (DCT_LENGTH_LOG - set_count_log); */ 
    253         set_span = shr(dct_length,set_count_log); 
    254  
    255         set_count     = shl(1,set_count_log); 
     268        set_span = shr_nocheck(dct_length,set_count_log); 
     269 
     270        set_count     = shl_nocheck(1,set_count_log); 
    256271        next_in_base  = in_buffer; 
    257272        move16(); 
     
    278293            in_ptr_low     = next_in_base; 
    279294            move16(); 
    280             temp           = shr(set_span,1); 
     295            temp           = shr_nocheck(set_span,1); 
    281296 
    282297            /* address arithmetic */ 
  • pjproject/trunk/third_party/g7221/encode/encoder.c

    r2563 r2616  
    141141       to be exactly 3.010299957 or 20.0 times log base 10 
    142142       of square root of 2. */ 
    143     temp = shl(mag_shift,1); 
     143    temp = shl_nocheck(mag_shift,1); 
    144144    mag_shift_offset = add(temp,REGION_POWER_TABLE_NUM_NEGATIVES); 
    145145     
     
    259259        if (j >= 0) 
    260260        { 
    261             temp = extract_l(L_shr(current_word,j)); 
     261            temp = extract_l(L_shr_nocheck(current_word,j)); 
    262262            out_word = add(out_word,temp); 
    263263 
     
    291291    { 
    292292        accb = L_deposit_l(out_word_index); 
    293         accb = L_shl(accb,4); 
     293        accb = L_shl_nocheck(accb,4); 
    294294        accb = L_sub(accb,number_of_bits_per_frame); 
    295295        test(); 
    296296        if(accb < 0)         
    297297        { 
    298             temp = shl(region,2); 
     298            temp = shl_nocheck(region,2); 
    299299            in_word_ptr = &region_mlt_bits[temp]; 
    300300            region_bit_count = region_mlt_bit_counts[region]; 
     
    311311     
    312312            acca = L_deposit_l(out_word_index); 
    313             acca = L_shl(acca,4); 
     313            acca = L_shl_nocheck(acca,4); 
    314314            acca = L_sub(acca,number_of_bits_per_frame); 
    315315             
     
    382382                } 
    383383                acca = L_deposit_l(out_word_index); 
    384                 acca = L_shl(acca,4); 
     384                acca = L_shl_nocheck(acca,4); 
    385385                acca = L_sub(acca,number_of_bits_per_frame); 
    386386            } 
    387387            accb = L_deposit_l(out_word_index); 
    388             accb = L_shl(accb,4); 
     388            accb = L_shl_nocheck(accb,4); 
    389389            accb = L_sub(accb,number_of_bits_per_frame); 
    390390        } 
     
    415415         
    416416        acca = L_deposit_l(out_word_index); 
    417         acca = L_shl(acca,4); 
     417        acca = L_shl_nocheck(acca,4); 
    418418        acca = L_sub(acca,number_of_bits_per_frame); 
    419419    } 
     
    462462    { 
    463463        n = sub(absolute_region_power_index[region],39); 
    464         n = shr(n,1); 
     464        n = shr_nocheck(n,1); 
    465465         
    466466        test(); 
     
    473473            for (i=0; i<REGION_SIZE; i++) 
    474474            { 
    475                 acca = L_shl(*raw_mlt_ptr,16); 
     475                acca = L_shl_nocheck(*raw_mlt_ptr,16); 
    476476                acca = L_add(acca,32768L); 
    477                 acca = L_shr(acca,n); 
    478                 acca = L_shr(acca,16); 
     477                acca = L_shr_nocheck(acca,n); 
     478                acca = L_shr_nocheck(acca,16); 
    479479                *raw_mlt_ptr++ = extract_l(acca); 
    480480            } 
    481481 
    482             temp = shl(n,1); 
     482            temp = shl_nocheck(n,1); 
    483483            temp = sub(absolute_region_power_index[region],temp); 
    484484            absolute_region_power_index[region] = temp; 
     
    568568        { 
    569569            test(); 
    570             long_accumulator = L_shr(long_accumulator,1); 
     570            long_accumulator = L_shr_nocheck(long_accumulator,1); 
    571571             
    572572            acca = (long_accumulator & 0x7fff0000L); 
     
    588588            logic16(); 
    589589             
    590             long_accumulator = L_shl(long_accumulator,1); 
     590            long_accumulator = L_shl_nocheck(long_accumulator,1); 
    591591            acca = L_sub(long_accumulator,32767); 
    592592            power_shift--; 
    593593            temp = add(power_shift,15); 
    594594        } 
    595         long_accumulator = L_shr(long_accumulator,1); 
     595        long_accumulator = L_shr_nocheck(long_accumulator,1); 
    596596        /* 28963 corresponds to square root of 2 times REGION_SIZE(20). */ 
    597597        acca = L_sub(long_accumulator,28963); 
     
    602602         
    603603        acca = L_deposit_l(mag_shift); 
    604         acca = L_shl(acca,1); 
     604        acca = L_shl_nocheck(acca,1); 
    605605        acca = L_sub(power_shift,acca); 
    606606        acca = L_add(35,acca); 
     
    786786 
    787787    /* Start in the middle of the categorization control range. */ 
    788     temp = shr(num_categorization_control_possibilities,1); 
     788    temp = shr_nocheck(num_categorization_control_possibilities,1); 
    789789    temp = sub(temp,1); 
    790790    for (*p_categorization_control = 0; *p_categorization_control < temp; (*p_categorization_control)++) 
     
    809809            region_mlt_bit_counts[region] = 
    810810            vector_huffman(category, absolute_region_power_index[region],raw_mlt_ptr, 
    811                            &region_mlt_bits[shl(region,2)]); 
     811                           &region_mlt_bits[shl_nocheck(region,2)]); 
    812812        } 
    813813        else 
     
    850850            region_mlt_bit_counts[region] = 
    851851                vector_huffman(category, absolute_region_power_index[region],raw_mlt_ptr, 
    852                            &region_mlt_bits[shl(region,2)]); 
     852                           &region_mlt_bits[shl_nocheck(region,2)]); 
    853853        } 
    854854        else 
     
    896896            region_mlt_bit_counts[region] = 
    897897                vector_huffman(category, absolute_region_power_index[region],raw_mlt_ptr, 
    898                            &region_mlt_bits[shl(region,2)]); 
     898                           &region_mlt_bits[shl_nocheck(region,2)]); 
    899899        } 
    900900        else 
     
    10031003    /* compute inverse of step size * standard deviation */ 
    10041004    acca = L_mult(step_size_inverse_table[category],standard_deviation_inverse_table[power_index]); 
    1005     acca = L_shr(acca,1); 
     1005    acca = L_shr_nocheck(acca,1); 
    10061006    acca = L_add(acca,4096); 
    1007     acca = L_shr(acca,13); 
     1007    acca = L_shr_nocheck(acca,13); 
    10081008 
    10091009        /* 
     
    10121012      
    10131013        mytemp = acca & 0x3; 
    1014     acca = L_shr(acca,2); 
     1014    acca = L_shr_nocheck(acca,2); 
    10151015 
    10161016    inv_of_step_size_times_std_dev = extract_l(acca); 
     
    10331033             
    10341034            acca = L_mult(k,inv_of_step_size_times_std_dev); 
    1035             acca = L_shr(acca,1); 
     1035            acca = L_shr_nocheck(acca,1); 
    10361036                     
    10371037                        /* 
     
    10401040 
    10411041                        myacca = (Word16)L_mult(k,mytemp); 
    1042                         myacca = (Word16)L_shr(myacca,1); 
     1042                        myacca = (Word16)L_shr_nocheck(myacca,1); 
    10431043                        myacca = (Word16)L_add(myacca,int_dead_zone_low_bits[category]); 
    1044                         myacca = (Word16)L_shr(myacca,2); 
     1044                        myacca = (Word16)L_shr_nocheck(myacca,2); 
    10451045 
    10461046            acca = L_add(acca,int_dead_zone[category]); 
     
    10511051 
    10521052                        acca = L_add(acca,myacca); 
    1053                         acca = L_shr(acca,13); 
     1053                        acca = L_shr_nocheck(acca,13); 
    10541054 
    10551055            k = extract_l(acca); 
     
    10591059            { 
    10601060                number_of_non_zero = add(number_of_non_zero,1); 
    1061                 signs_index = shl(signs_index,1); 
     1061                signs_index = shl_nocheck(signs_index,1); 
    10621062                 
    10631063                test(); 
     
    10751075                } 
    10761076            } 
    1077             acca = L_shr(L_mult(index,(kmax_plus_one)),1); 
     1077            acca = L_shr_nocheck(L_mult(index,(kmax_plus_one)),1); 
    10781078            index = extract_l(acca); 
    10791079            index = add(index,k); 
     
    11051105        { 
    11061106            j = negate(j); 
    1107             acca = L_shr(code_bits,j); 
     1107            acca = L_shr_nocheck(code_bits,j); 
    11081108            current_word = L_add(current_word,acca); 
    11091109             
  • pjproject/trunk/third_party/g7221/encode/sam2coef.c

    r2601 r2616  
    8585    Word16      temp5; 
    8686    
    87     half_dct_size = shr(dct_length,1); 
     87    half_dct_size = shr_nocheck(dct_length,1); 
    8888    
    8989    /*++++++++++++++++++++++++++++++++++++++++++++*/ 
     
    209209        } 
    210210        accb = L_mult(temp,9587); 
    211         acca = L_shr(accb,20); 
     211        acca = L_shr_nocheck(accb,20); 
    212212        temp5 = extract_l(acca); 
    213213        temp = norm_s(temp5); 
     
    231231    } 
    232232     
    233     acca = L_shr(acca,7); 
     233    acca = L_shr_nocheck(acca,7); 
    234234     
    235235    test(); 
     
    244244        for(index=0;index<dct_length;index++) 
    245245        { 
    246             windowed_data[index] = shl(windowed_data[index],mag_shift); 
     246            windowed_data[index] = shl_nocheck(windowed_data[index],mag_shift); 
    247247        } 
    248248    } 
     
    255255            for(index=0;index<dct_length;index++) 
    256256            { 
    257                 windowed_data[index] = shr(windowed_data[index],n); 
     257                windowed_data[index] = shr_nocheck(windowed_data[index],n); 
    258258                move16(); 
    259259            } 
Note: See TracChangeset for help on using the changeset viewer.