Changeset 2616 for pjproject/trunk
- Timestamp:
- Apr 18, 2009 2:29:28 PM (16 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 1 added
- 1 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-codec/g7221.c
r2603 r2616 223 223 } 224 224 225 #if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0 226 PJ_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 225 238 /* 226 239 * Initialize and register G722.1 codec factory to pjmedia endpoint. … … 775 788 output->buf); 776 789 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); 789 794 790 795 output->type = PJMEDIA_FRAME_TYPE_AUDIO; … … 819 824 PJMEDIA_CODEC_EFRMINLEN); 820 825 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). 823 829 */ 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); 836 831 837 832 bitobj.code_word_ptr = (Word16*)input->buf; -
pjproject/trunk/third_party/build/g7221/libg7221codec.dsp
r2607 r2616 43 43 F90=df.exe 44 44 # 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> 46 47 # ADD BASE RSC /l 0x409 /d "NDEBUG" 47 48 # ADD RSC /l 0x409 /d "NDEBUG" … … 67 68 F90=df.exe 68 69 # 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 /c70 # 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 70 71 # ADD BASE RSC /l 0x409 /d "_DEBUG" 71 72 # ADD RSC /l 0x409 /d "_DEBUG" … … 102 103 # Begin Source File 103 104 104 SOURCE="..\..\g7221\common\stl-files\ count.c"105 SOURCE="..\..\g7221\common\stl-files\basop32_i.h" 105 106 # End Source File 106 107 # Begin Source File -
pjproject/trunk/third_party/g7221/common/common.c
r2563 r2616 95 95 number_of_available_bits = sub(number_of_available_bits,frame_size); 96 96 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); 98 98 number_of_available_bits = add(number_of_available_bits,frame_size); 99 99 } … … 208 208 { 209 209 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); 211 211 212 212 temp = sub(min_plus_max,two_x_number_of_available_bits); … … 223 223 if (max_rate_categories[region] > 0) 224 224 { 225 itemp0 = shl (max_rate_categories[region],1);225 itemp0 = shl_nocheck(max_rate_categories[region],1); 226 226 itemp1 = sub(offset,rms_index[region]); 227 227 itemp0 = sub(itemp1,itemp0); … … 259 259 if (temp < 0) 260 260 { 261 itemp0 = shl (min_rate_categories[region],1);261 itemp0 = shl_nocheck(min_rate_categories[region],1); 262 262 itemp1 = sub(offset,rms_index[region]); 263 263 itemp0 = sub(itemp1,itemp0); … … 357 357 { 358 358 j = sub(test_offset,rms_index[region]); 359 j = shr (j,1);359 j = shr_nocheck(j,1); 360 360 361 361 /* Ensure j is between 0 and NUM_CAT-1 */ … … 392 392 move16(); 393 393 } 394 delta = shr (delta,1);394 delta = shr_nocheck(delta,1); 395 395 test(); /* for the while loop */ 396 396 } while (delta > 0); … … 441 441 { 442 442 j = sub(offset,rms_index[region]); 443 j = shr (j,1);443 j = shr_nocheck(j,1); 444 444 445 445 /* make sure j is between 0 and NUM_CAT-1 */ -
pjproject/trunk/third_party/g7221/common/stl-files/basop32.c
r2601 r2616 80 80 /*___________________________________________________________________________ 81 81 | | 82 | Local Functions |83 |___________________________________________________________________________|84 */85 Word16 saturate (Word32 L_var1);86 87 /*___________________________________________________________________________88 | |89 82 | Constants and Globals | 90 83 |___________________________________________________________________________| 91 84 */ 92 Flag Overflow = 0; 93 Flag Carry = 0; 85 #if INCLUDE_UNSAFE 86 Flag g7221_Overflow = 0; 87 Flag g7221_Carry = 0; 88 #endif 94 89 95 90 /*___________________________________________________________________________ … … 98 93 |___________________________________________________________________________| 99 94 */ 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. | 114 117 | | 115 118 | Outputs : | … … 124 127 |___________________________________________________________________________| 125 128 */ 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; 129 Word16 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); 139 136 } 140 137 else 141 138 { 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() ------------------------- */ 301 143 302 144 … … 337 179 Word16 shl (Word16 var1, Word16 var2) 338 180 { 339 Word16 var_out;340 Word32 result;341 342 181 if (var2 < 0) 343 182 { 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); 350 184 } 351 185 else 352 186 { 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 } 372 189 } 373 190 /* ------------------------- End of shl() ------------------------- */ 374 191 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 #endif422 }423 else424 {425 if (var2 >= 15)426 {427 var_out = (var1 < 0) ? -1 : 0;428 }429 else430 {431 if (var1 < 0)432 {433 var_out = ~((~var1) >> var2);434 }435 else436 {437 var_out = var1 >> var2;438 }439 }440 }441 442 #if (WMOPS)443 multiCounter[currCounter].shr++;444 #endif445 return (var_out);446 }447 /* ------------------------- End of shr() ------------------------- */448 192 449 193 … … 505 249 /*___________________________________________________________________________ 506 250 | | 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)). | 515 258 | | 516 259 | Complexity weight : 1 | 517 260 | | 518 261 | Inputs : | 262 | | 263 | L_var3 32 bit long signed integer (Word32) whose value falls in the | 264 | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. | 519 265 | | 520 266 | var1 | … … 537 283 |___________________________________________________________________________| 538 284 */ 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) 285 Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2) 770 286 { 771 287 Word32 L_var_out; … … 776 292 multiCounter[currCounter].L_mult--; 777 293 #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 #endif783 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 #endif833 294 L_var_out = L_sub (L_var3, L_product); 834 295 #if (WMOPS) … … 840 301 /* ------------------------- End of L_msu() ------------------------- */ 841 302 842 303 #if INCLUDE_UNSAFE 843 304 /*___________________________________________________________________________ 844 305 | | … … 898 359 return (L_var_out); 899 360 } 361 #endif 900 362 /* ------------------------- End of L_macNs() ------------------------- */ 901 363 902 364 #if INCLUDE_UNSAFE 903 365 /*___________________________________________________________________________ 904 366 | | … … 958 420 return (L_var_out); 959 421 } 422 #endif 423 960 424 /* ------------------------- End of L_msuNs() ------------------------- */ 961 425 962 426 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 1069 428 /*___________________________________________________________________________ 1070 429 | | … … 1110 469 Flag carry_int = 0; 1111 470 1112 L_var_out = L_var1 + L_var2 + Carry;471 L_var_out = L_var1 + L_var2 + GET_CARRY(); 1113 472 1114 473 L_test = L_var1 + L_var2; … … 1116 475 if ((L_var1 > 0) && (L_var2 > 0) && (L_test < 0)) 1117 476 { 1118 Overflow = 1;477 SET_OVERFLOW(1); 1119 478 carry_int = 0; 1120 479 } … … 1125 484 if (L_test >= 0) 1126 485 { 1127 Overflow = 1;486 SET_OVERFLOW(1); 1128 487 carry_int = 1; 1129 488 } 1130 489 else 1131 490 { 1132 Overflow = 0;491 SET_OVERFLOW(0); 1133 492 carry_int = 1; 1134 493 } … … 1138 497 if (((L_var1 ^ L_var2) < 0) && (L_test >= 0)) 1139 498 { 1140 Overflow = 0;499 SET_OVERFLOW(0); 1141 500 carry_int = 1; 1142 501 } 1143 502 else 1144 503 { 1145 Overflow = 0;504 SET_OVERFLOW(0); 1146 505 carry_int = 0; 1147 506 } … … 1149 508 } 1150 509 1151 if ( Carry)510 if (GET_CARRY()) 1152 511 { 1153 512 if (L_test == MAX_32) 1154 513 { 1155 Overflow = 1;1156 Carry = carry_int;514 SET_OVERFLOW(1); 515 SET_CARRY(carry_int); 1157 516 } 1158 517 else … … 1160 519 if (L_test == (Word32) 0xFFFFFFFFL) 1161 520 { 1162 Carry = 1;521 SET_CARRY(1); 1163 522 } 1164 523 else 1165 524 { 1166 Carry = carry_int;525 SET_CARRY(carry_int); 1167 526 } 1168 527 } … … 1170 529 else 1171 530 { 1172 Carry = carry_int;531 SET_CARRY(carry_int); 1173 532 } 1174 533 … … 1178 537 return (L_var_out); 1179 538 } 539 #endif 540 1180 541 /* ------------------------- End of L_add_c() ------------------------- */ 1181 542 1182 543 #if INCLUDE_UNSAFE 1183 544 /*___________________________________________________________________________ 1184 545 | | … … 1224 585 Flag carry_int = 0; 1225 586 1226 if ( Carry)1227 { 1228 Carry = 0;587 if (GET_CARRY()) 588 { 589 SET_CARRY(0); 1229 590 if (L_var2 != MIN_32) 1230 591 { … … 1239 600 if (L_var1 > 0L) 1240 601 { 1241 Overflow = 1;1242 Carry = 0;602 SET_OVERFLOW(1); 603 SET_CARRY(0); 1243 604 } 1244 605 } … … 1251 612 if ((L_test < 0) && (L_var1 > 0) && (L_var2 < 0)) 1252 613 { 1253 Overflow = 1;614 SET_OVERFLOW(1); 1254 615 carry_int = 0; 1255 616 } 1256 617 else if ((L_test > 0) && (L_var1 < 0) && (L_var2 > 0)) 1257 618 { 1258 Overflow = 1;619 SET_OVERFLOW(1); 1259 620 carry_int = 1; 1260 621 } 1261 622 else if ((L_test > 0) && ((L_var1 ^ L_var2) > 0)) 1262 623 { 1263 Overflow = 0;624 SET_OVERFLOW(0); 1264 625 carry_int = 1; 1265 626 } 1266 627 if (L_test == MIN_32) 1267 628 { 1268 Overflow = 1;1269 Carry = carry_int;629 SET_OVERFLOW(1); 630 SET_CARRY(carry_int); 1270 631 } 1271 632 else 1272 633 { 1273 Carry = carry_int;634 SET_CARRY(carry_int); 1274 635 } 1275 636 } … … 1280 641 return (L_var_out); 1281 642 } 643 #endif 1282 644 /* ------------------------- End of L_sub_c() ------------------------- */ 1283 645 … … 1378 740 /* ------------------------- End of mult_r() ------------------------- */ 1379 741 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 #endif1426 }1427 else1428 {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 else1438 {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 #endif1453 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 #endif1503 }1504 else1505 {1506 if (var2 >= 31)1507 {1508 L_var_out = (L_var1 < 0L) ? -1 : 0;1509 }1510 else1511 {1512 if (L_var1 < 0)1513 {1514 L_var_out = ~((~L_var1) >> var2);1515 }1516 else1517 {1518 L_var_out = L_var1 >> var2;1519 }1520 }1521 }1522 #if (WMOPS)1523 multiCounter[currCounter].L_shr++;1524 #endif1525 return (L_var_out);1526 }1527 /* ------------------------- End of L_shr() ------------------------- */1528 742 1529 743 … … 1931 1145 /*___________________________________________________________________________ 1932 1146 | | 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 else1975 {1976 L_var_out = MAX_32;1977 }1978 1979 Carry = 0;1980 Overflow = 0;1981 }1982 #if (WMOPS)1983 multiCounter[currCounter].L_sat++;1984 #endif1985 return (L_var_out);1986 }1987 /* ------------------------- End of L_sat() ------------------------- */1988 1989 1990 /*___________________________________________________________________________1991 | |1992 1147 | Function Name : norm_s | 1993 1148 | | … … 2276 1431 Temp = Lv & (Word32) 0x0000ffff ; 2277 1432 Temp = Temp * (Word32) v ; 2278 Temp = L_shr ( Temp, (Word16) 15 ) ;1433 Temp = L_shr_nocheck( Temp, (Word16) 15 ) ; 2279 1434 Temp = L_mac( Temp, v, extract_h(Lv) ) ; 2280 1435 … … 2358 1513 } 2359 1514 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); 2362 1517 #if (WMOPS) 2363 1518 multiCounter[currCounter].L_shr-=2; 2364 1519 #endif 2365 1520 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); 2368 1523 #if (WMOPS) 2369 1524 multiCounter[currCounter].shl--; … … 2629 1784 if (L_var1 > (UWord32) 0X7fffffffL) 2630 1785 { 2631 Overflow = 1;1786 SET_OVERFLOW(1); 2632 1787 L_var_out = UMAX_32; 2633 1788 break; … … 2637 1792 if (L_var1 < (UWord32) 0x00000001L) 2638 1793 { 2639 Overflow = 1;1794 SET_OVERFLOW(1); 2640 1795 L_var_out = MIN_32; 2641 1796 break; -
pjproject/trunk/third_party/g7221/common/stl-files/basop32.h
r2601 r2616 34 34 35 35 #define MAX_16 (Word16)0x7fff 36 #define MIN_16 ( Word16)0x800036 #define MIN_16 ((Word16)0x8000) 37 37 38 38 #define UMAX_32 (Word32)0xffffffffL … … 45 45 */ 46 46 47 Word16add (Word16 var1, Word16 var2); /* Short add, 1 */48 Word16sub (Word16 var1, Word16 var2); /* Short sub, 1 */49 Word16abs_s (Word16 var1); /* Short abs, 1 */47 PJ_INLINE(Word16) add (Word16 var1, Word16 var2); /* Short add, 1 */ 48 PJ_INLINE(Word16) sub (Word16 var1, Word16 var2); /* Short sub, 1 */ 49 PJ_INLINE(Word16) abs_s (Word16 var1); /* Short abs, 1 */ 50 50 Word16 shl (Word16 var1, Word16 var2); /* Short shift left, 1 */ 51 PJ_INLINE(Word16) shl_nocheck(Word16 var1, Word16 var2); 51 52 Word16 shr (Word16 var1, Word16 var2); /* Short shift right, 1 */ 53 PJ_INLINE(Word16) shr_nocheck(Word16 var1, Word16 var2); 52 54 Word16 mult (Word16 var1, Word16 var2); /* Short mult, 1 */ 53 Word32L_mult (Word16 var1, Word16 var2); /* Long mult, 1 */54 Word16negate (Word16 var1); /* Short negate, 1 */55 Word16extract_h (Word32 L_var1); /* Extract high, 1 */56 Word16extract_l (Word32 L_var1); /* Extract low, 1 */57 Word16itu_round (Word32 L_var1); /* Round, 1 */58 Word32L_mac (Word32 L_var3, Word16 var1, Word16 var2); /* Mac, 1 */55 PJ_INLINE(Word32) L_mult (Word16 var1, Word16 var2); /* Long mult, 1 */ 56 PJ_INLINE(Word16) negate (Word16 var1); /* Short negate, 1 */ 57 PJ_INLINE(Word16) extract_h (Word32 L_var1); /* Extract high, 1 */ 58 PJ_INLINE(Word16) extract_l (Word32 L_var1); /* Extract low, 1 */ 59 PJ_INLINE(Word16) itu_round (Word32 L_var1); /* Round, 1 */ 60 PJ_INLINE(Word32) L_mac (Word32 L_var3, Word16 var1, Word16 var2); /* Mac, 1 */ 59 61 Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2); /* Msu, 1 */ 60 62 Word32 L_macNs (Word32 L_var3, Word16 var1, Word16 var2); /* Mac without … … 62 64 Word32 L_msuNs (Word32 L_var3, Word16 var1, Word16 var2); /* Msu without 63 65 sat, 1 */ 64 Word32L_add (Word32 L_var1, Word32 L_var2); /* Long add, 2 */65 Word32L_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 */ 67 PJ_INLINE(Word32) L_sub (Word32 L_var1, Word32 L_var2); /* Long sub, 2 */ 66 68 Word32 L_add_c (Word32 L_var1, Word32 L_var2); /* Long add with c, 2 */ 67 69 Word32 L_sub_c (Word32 L_var1, Word32 L_var2); /* Long sub with c, 2 */ 68 70 Word32 L_negate (Word32 L_var1); /* Long negate, 2 */ 69 71 Word16 mult_r (Word16 var1, Word16 var2); /* Mult with round, 2 */ 70 Word32L_shl (Word32 L_var1, Word16 var2); /* Long shift left, 2 */71 Word32L_shr (Word32 L_var1, Word16 var2); /* Long shift right, 2*/72 PJ_INLINE(Word32) L_shl (Word32 L_var1, Word16 var2); /* Long shift left, 2 */ 73 PJ_INLINE(Word32) L_shr (Word32 L_var1, Word16 var2); /* Long shift right, 2*/ 72 74 Word16 shr_r (Word16 var1, Word16 var2); /* Shift right with 73 75 round, 2 */ … … 106 108 UWord32 LU_shl (UWord32 L_var1, Word16 var2); 107 109 UWord32 LU_shr (UWord32 L_var1, Word16 var2); 110 111 #define INCLUDE_UNSAFE 0 112 113 /* Local */ 114 PJ_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 108 133 #endif /* BASOP_H_DEFINED */ 109 134 -
pjproject/trunk/third_party/g7221/common/stl-files/count.h
r2563 r2616 36 36 =========================================================================== 37 37 */ 38 #if 0 38 39 #ifndef COUNT_H 39 40 #define COUNT_H "$Id $" … … 72 73 */ 73 74 74 Word32 fwc (void); 75 PJ_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 75 92 /* 76 93 * worst worst case counter. … … 83 100 * The WMOPS_output function add together all parts and presents the sum. 84 101 */ 85 86 void move16 (void); 87 void move32 (void); 88 void logic16 (void); 89 void logic32 (void); 90 void test (void); 102 PJ_INLINE(void) move16 (void) 103 { 104 #if WMOPS 105 multiCounter[currCounter].DataMove16++; 106 #endif 107 } 108 109 PJ_INLINE(void) move32 (void) 110 { 111 #if WMOPS 112 multiCounter[currCounter].DataMove32++; 113 #endif 114 } 115 116 PJ_INLINE(void )logic16 (void) 117 { 118 #if WMOPS 119 multiCounter[currCounter].Logic16++; 120 #endif 121 } 122 123 PJ_INLINE(void) logic32 (void) 124 { 125 #if WMOPS 126 multiCounter[currCounter].Logic32++; 127 #endif 128 } 129 130 PJ_INLINE(void) test (void) 131 { 132 #if WMOPS 133 multiCounter[currCounter].Test++; 134 #endif 135 } 136 137 91 138 /* 92 139 * The functions above increases the corresponding operation counter for … … 206 253 207 254 #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 89 89 90 90 91 half_dct_size = shr (dct_length,1);91 half_dct_size = shr_nocheck(dct_length,1); 92 92 93 93 /* Perform a Type IV (inverse) DCT on the coefficients */ … … 99 99 for(index=0;index<dct_length;index++) 100 100 { 101 new_samples[index] = shr (new_samples[index],mag_shift);101 new_samples[index] = shr_nocheck(new_samples[index],mag_shift); 102 102 move16(); 103 103 } … … 111 111 for(index=0;index<dct_length;index++) 112 112 { 113 new_samples[index] = shl (new_samples[index],mag_shift);113 new_samples[index] = shl_nocheck(new_samples[index],mag_shift); 114 114 move16(); 115 115 } … … 148 148 sum = L_mac(sum,*win_new++, *--new_ptr); 149 149 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)); 151 151 move16(); 152 152 … … 161 161 sum = L_mac(sum,*win_new++, *new_ptr++); 162 162 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)); 164 164 move16(); 165 165 } -
pjproject/trunk/third_party/g7221/decode/dct4_s.c
r2601 r2616 141 141 142 142 /* 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); 144 144 145 set_count = shl (1,set_count_log);145 set_count = shl_nocheck(1,set_count_log); 146 146 in_ptr = in_buffer; 147 147 move16(); … … 186 186 187 187 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)); 190 193 191 194 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)); 194 200 195 201 *out_ptr_low++ = out_val_low; … … 285 291 for ( k=0; k<CORE_SIZE; k++ ) 286 292 { 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 287 304 sum=0L; 288 305 move32(); … … 292 309 sum = L_mac(sum, pair_ptr[i],dct_core_s[i][k]); 293 310 } 311 #endif 294 312 buffer_swap[k] = itu_round(sum); 295 313 } … … 324 342 325 343 /* 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); 329 347 next_in_base = in_buffer; 330 348 move16(); … … 355 373 move16(); 356 374 357 temp = shr (set_span,1);375 temp = shr_nocheck(set_span,1); 358 376 in_ptr_high = in_ptr_low + temp; 359 377 move16(); … … 402 420 sum = L_mac(sum,cos_even,in_low_even); 403 421 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)); 405 423 406 424 sum = 0L; … … 408 426 sum = L_mac(sum,msin_even,in_low_even); 409 427 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)); 411 429 412 430 sum = 0L; … … 414 432 sum = L_mac(sum,cos_odd,in_low_odd); 415 433 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)); 417 435 418 436 sum = 0L; … … 420 438 sum = L_mac(sum,msin_odd,in_low_odd); 421 439 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)); 423 441 424 442 *out_ptr_low++ = out_low_even; … … 459 477 for(i=0;i<320;i++) 460 478 { 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]; 462 483 acca = L_sub(sum,32767); 463 484 test(); … … 467 488 move32(); 468 489 } 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; 470 494 test(); 471 495 if (acca < 0) -
pjproject/trunk/third_party/g7221/decode/decoder.c
r2563 r2616 137 137 { 138 138 get_next_bit(bitobj); 139 categorization_control = shl (categorization_control,1);139 categorization_control = shl_nocheck(categorization_control,1); 140 140 categorization_control = add(categorization_control,bitobj->next_bit); 141 141 } … … 247 247 { 248 248 get_next_bit(bitobj); 249 index = shl (index,1);249 index = shl_nocheck(index,1); 250 250 index = add(index,bitobj->next_bit); 251 251 } … … 333 333 { 334 334 i = sub(i,1); 335 temp = shr (temp,1);335 temp = shr_nocheck(temp,1); 336 336 max_index = sub(max_index,2); 337 337 temp1 = sub(temp,8); … … 531 531 if (bitobj->next_bit == 0) 532 532 { 533 temp = shl (index,1);533 temp = shl_nocheck(index,1); 534 534 index = (Word16)*(decoder_table_ptr + temp); 535 535 move16(); … … 537 537 else 538 538 { 539 temp = shl (index,1);539 temp = shl_nocheck(index,1); 540 540 index = (Word16)*(decoder_table_ptr + temp + 1); 541 541 move16(); … … 568 568 { 569 569 get_next_bit(bitobj); 570 signs_index = shl (signs_index,1);570 signs_index = shl_nocheck(signs_index,1); 571 571 signs_index = add(signs_index,bitobj->next_bit); 572 572 bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,1); 573 573 } 574 574 temp = sub(num_sign_bits,1); 575 bit = shl (1,(temp));575 bit = shl_nocheck(1,(temp)); 576 576 } 577 577 … … 579 579 { 580 580 acca = L_mult0(standard_deviation,mlt_quant_centroid[category][k[j]]); 581 acca = L_shr (acca,12);581 acca = L_shr_nocheck(acca,12); 582 582 decoder_mlt_value = extract_l(acca); 583 583 … … 588 588 if ((signs_index & bit) == 0) 589 589 decoder_mlt_value = negate(decoder_mlt_value); 590 bit = shr (bit,1);590 bit = shr_nocheck(bit,1); 591 591 } 592 592 *decoder_mlt_ptr++ = decoder_mlt_value; … … 653 653 *decoder_mlt_ptr = temp1; 654 654 move16(); 655 random_word = shr (random_word,1);655 random_word = shr_nocheck(random_word,1); 656 656 } 657 657 /* pointer arithmetic */ … … 678 678 *decoder_mlt_ptr = temp1; 679 679 move16(); 680 random_word = shr (random_word,1);680 random_word = shr_nocheck(random_word,1); 681 681 } 682 682 /* pointer arithmetic */ … … 711 711 *decoder_mlt_ptr++ = temp1; 712 712 move16(); 713 random_word = shr (random_word,1);713 random_word = shr_nocheck(random_word,1); 714 714 } 715 715 random_word = get_rand(randobj); … … 731 731 *decoder_mlt_ptr++ = temp1; 732 732 move16(); 733 random_word = shr (random_word,1);733 random_word = shr_nocheck(random_word,1); 734 734 } 735 735 } … … 1060 1060 } 1061 1061 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); 1063 1063 logic16(); 1064 1064 bitobj->next_bit = (Word16 )(temp & 1); -
pjproject/trunk/third_party/g7221/encode/dct4_a.c
r2601 r2616 136 136 137 137 /* 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); 141 141 142 142 in_ptr = in_buffer; … … 169 169 in_val_low = *in_ptr++; 170 170 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); 173 176 out_val_low = extract_l(acca); 174 177 175 178 acca = L_sub(in_val_low,in_val_high); 176 acca = L_shr (acca,1);179 acca = L_shr_nocheck(acca,1); 177 180 out_val_high = extract_l(acca); 178 181 … … 214 217 215 218 temp = sub(dct_length_log,1); 216 temp = shl (1,temp);219 temp = shl_nocheck(1,temp); 217 220 218 221 for (pairs_left=temp; pairs_left > 0; pairs_left--) … … 220 223 for ( k=0; k<CORE_SIZE; k++ ) 221 224 { 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 222 236 sum=0L; 223 237 move32(); … … 226 240 sum = L_mac(sum, pair_ptr[i],dct_core_a[i][k]); 227 241 } 242 #endif 228 243 buffer_swap[k] = itu_round(sum); 229 244 } … … 251 266 /*===========================================================*/ 252 267 /* 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); 256 271 next_in_base = in_buffer; 257 272 move16(); … … 278 293 in_ptr_low = next_in_base; 279 294 move16(); 280 temp = shr (set_span,1);295 temp = shr_nocheck(set_span,1); 281 296 282 297 /* address arithmetic */ -
pjproject/trunk/third_party/g7221/encode/encoder.c
r2563 r2616 141 141 to be exactly 3.010299957 or 20.0 times log base 10 142 142 of square root of 2. */ 143 temp = shl (mag_shift,1);143 temp = shl_nocheck(mag_shift,1); 144 144 mag_shift_offset = add(temp,REGION_POWER_TABLE_NUM_NEGATIVES); 145 145 … … 259 259 if (j >= 0) 260 260 { 261 temp = extract_l(L_shr (current_word,j));261 temp = extract_l(L_shr_nocheck(current_word,j)); 262 262 out_word = add(out_word,temp); 263 263 … … 291 291 { 292 292 accb = L_deposit_l(out_word_index); 293 accb = L_shl (accb,4);293 accb = L_shl_nocheck(accb,4); 294 294 accb = L_sub(accb,number_of_bits_per_frame); 295 295 test(); 296 296 if(accb < 0) 297 297 { 298 temp = shl (region,2);298 temp = shl_nocheck(region,2); 299 299 in_word_ptr = ®ion_mlt_bits[temp]; 300 300 region_bit_count = region_mlt_bit_counts[region]; … … 311 311 312 312 acca = L_deposit_l(out_word_index); 313 acca = L_shl (acca,4);313 acca = L_shl_nocheck(acca,4); 314 314 acca = L_sub(acca,number_of_bits_per_frame); 315 315 … … 382 382 } 383 383 acca = L_deposit_l(out_word_index); 384 acca = L_shl (acca,4);384 acca = L_shl_nocheck(acca,4); 385 385 acca = L_sub(acca,number_of_bits_per_frame); 386 386 } 387 387 accb = L_deposit_l(out_word_index); 388 accb = L_shl (accb,4);388 accb = L_shl_nocheck(accb,4); 389 389 accb = L_sub(accb,number_of_bits_per_frame); 390 390 } … … 415 415 416 416 acca = L_deposit_l(out_word_index); 417 acca = L_shl (acca,4);417 acca = L_shl_nocheck(acca,4); 418 418 acca = L_sub(acca,number_of_bits_per_frame); 419 419 } … … 462 462 { 463 463 n = sub(absolute_region_power_index[region],39); 464 n = shr (n,1);464 n = shr_nocheck(n,1); 465 465 466 466 test(); … … 473 473 for (i=0; i<REGION_SIZE; i++) 474 474 { 475 acca = L_shl (*raw_mlt_ptr,16);475 acca = L_shl_nocheck(*raw_mlt_ptr,16); 476 476 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); 479 479 *raw_mlt_ptr++ = extract_l(acca); 480 480 } 481 481 482 temp = shl (n,1);482 temp = shl_nocheck(n,1); 483 483 temp = sub(absolute_region_power_index[region],temp); 484 484 absolute_region_power_index[region] = temp; … … 568 568 { 569 569 test(); 570 long_accumulator = L_shr (long_accumulator,1);570 long_accumulator = L_shr_nocheck(long_accumulator,1); 571 571 572 572 acca = (long_accumulator & 0x7fff0000L); … … 588 588 logic16(); 589 589 590 long_accumulator = L_shl (long_accumulator,1);590 long_accumulator = L_shl_nocheck(long_accumulator,1); 591 591 acca = L_sub(long_accumulator,32767); 592 592 power_shift--; 593 593 temp = add(power_shift,15); 594 594 } 595 long_accumulator = L_shr (long_accumulator,1);595 long_accumulator = L_shr_nocheck(long_accumulator,1); 596 596 /* 28963 corresponds to square root of 2 times REGION_SIZE(20). */ 597 597 acca = L_sub(long_accumulator,28963); … … 602 602 603 603 acca = L_deposit_l(mag_shift); 604 acca = L_shl (acca,1);604 acca = L_shl_nocheck(acca,1); 605 605 acca = L_sub(power_shift,acca); 606 606 acca = L_add(35,acca); … … 786 786 787 787 /* 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); 789 789 temp = sub(temp,1); 790 790 for (*p_categorization_control = 0; *p_categorization_control < temp; (*p_categorization_control)++) … … 809 809 region_mlt_bit_counts[region] = 810 810 vector_huffman(category, absolute_region_power_index[region],raw_mlt_ptr, 811 ®ion_mlt_bits[shl (region,2)]);811 ®ion_mlt_bits[shl_nocheck(region,2)]); 812 812 } 813 813 else … … 850 850 region_mlt_bit_counts[region] = 851 851 vector_huffman(category, absolute_region_power_index[region],raw_mlt_ptr, 852 ®ion_mlt_bits[shl (region,2)]);852 ®ion_mlt_bits[shl_nocheck(region,2)]); 853 853 } 854 854 else … … 896 896 region_mlt_bit_counts[region] = 897 897 vector_huffman(category, absolute_region_power_index[region],raw_mlt_ptr, 898 ®ion_mlt_bits[shl (region,2)]);898 ®ion_mlt_bits[shl_nocheck(region,2)]); 899 899 } 900 900 else … … 1003 1003 /* compute inverse of step size * standard deviation */ 1004 1004 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); 1006 1006 acca = L_add(acca,4096); 1007 acca = L_shr (acca,13);1007 acca = L_shr_nocheck(acca,13); 1008 1008 1009 1009 /* … … 1012 1012 1013 1013 mytemp = acca & 0x3; 1014 acca = L_shr (acca,2);1014 acca = L_shr_nocheck(acca,2); 1015 1015 1016 1016 inv_of_step_size_times_std_dev = extract_l(acca); … … 1033 1033 1034 1034 acca = L_mult(k,inv_of_step_size_times_std_dev); 1035 acca = L_shr (acca,1);1035 acca = L_shr_nocheck(acca,1); 1036 1036 1037 1037 /* … … 1040 1040 1041 1041 myacca = (Word16)L_mult(k,mytemp); 1042 myacca = (Word16)L_shr (myacca,1);1042 myacca = (Word16)L_shr_nocheck(myacca,1); 1043 1043 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); 1045 1045 1046 1046 acca = L_add(acca,int_dead_zone[category]); … … 1051 1051 1052 1052 acca = L_add(acca,myacca); 1053 acca = L_shr (acca,13);1053 acca = L_shr_nocheck(acca,13); 1054 1054 1055 1055 k = extract_l(acca); … … 1059 1059 { 1060 1060 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); 1062 1062 1063 1063 test(); … … 1075 1075 } 1076 1076 } 1077 acca = L_shr (L_mult(index,(kmax_plus_one)),1);1077 acca = L_shr_nocheck(L_mult(index,(kmax_plus_one)),1); 1078 1078 index = extract_l(acca); 1079 1079 index = add(index,k); … … 1105 1105 { 1106 1106 j = negate(j); 1107 acca = L_shr (code_bits,j);1107 acca = L_shr_nocheck(code_bits,j); 1108 1108 current_word = L_add(current_word,acca); 1109 1109 -
pjproject/trunk/third_party/g7221/encode/sam2coef.c
r2601 r2616 85 85 Word16 temp5; 86 86 87 half_dct_size = shr (dct_length,1);87 half_dct_size = shr_nocheck(dct_length,1); 88 88 89 89 /*++++++++++++++++++++++++++++++++++++++++++++*/ … … 209 209 } 210 210 accb = L_mult(temp,9587); 211 acca = L_shr (accb,20);211 acca = L_shr_nocheck(accb,20); 212 212 temp5 = extract_l(acca); 213 213 temp = norm_s(temp5); … … 231 231 } 232 232 233 acca = L_shr (acca,7);233 acca = L_shr_nocheck(acca,7); 234 234 235 235 test(); … … 244 244 for(index=0;index<dct_length;index++) 245 245 { 246 windowed_data[index] = shl (windowed_data[index],mag_shift);246 windowed_data[index] = shl_nocheck(windowed_data[index],mag_shift); 247 247 } 248 248 } … … 255 255 for(index=0;index<dct_length;index++) 256 256 { 257 windowed_data[index] = shr (windowed_data[index],n);257 windowed_data[index] = shr_nocheck(windowed_data[index],n); 258 258 move16(); 259 259 }
Note: See TracChangeset
for help on using the changeset viewer.