123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827 |
- /**********************************************************************
- Each of the companies; Lucent, Motorola, Nokia, and Qualcomm (hereinafter
- referred to individually as "Source" or collectively as "Sources") do
- hereby state:
- To the extent to which the Source(s) may legally and freely do so, the
- Source(s), upon submission of a Contribution, grant(s) a free,
- irrevocable, non-exclusive, license to the Third Generation Partnership
- Project 2 (3GPP2) and its Organizational Partners: ARIB, CCSA, TIA, TTA,
- and TTC, under the Source's copyright or copyright license rights in the
- Contribution, to, in whole or in part, copy, make derivative works,
- perform, display and distribute the Contribution and derivative works
- thereof consistent with 3GPP2's and each Organizational Partner's
- policies and procedures, with the right to (i) sublicense the foregoing
- rights consistent with 3GPP2's and each Organizational Partner's policies
- and procedures and (ii) copyright and sell, if applicable) in 3GPP2's name
- or each Organizational Partner's name any 3GPP2 or transposed Publication
- even though this Publication may contain the Contribution or a derivative
- work thereof. The Contribution shall disclose any known limitations on
- the Source's rights to license as herein provided.
- When a Contribution is submitted by the Source(s) to assist the
- formulating groups of 3GPP2 or any of its Organizational Partners, it
- is proposed to the Committee as a basis for discussion and is not to
- be construed as a binding proposal on the Source(s). The Source(s)
- specifically reserve(s) the right to amend or modify the material
- contained in the Contribution. Nothing contained in the Contribution
- shall, except as herein expressly provided, be construed as conferring
- by implication, estoppel or otherwise, any license or right under (i)
- any existing or later issuing patent, whether or not the use of
- information in the document necessarily employs an invention of any
- existing or later issued patent, (ii) any copyright, (iii) any
- trademark, or (iv) any other intellectual property right.
- With respect to the Software necessary for the practice of any or
- all Normative portions of the Enhanced Variable Rate Codec (EVRC) as
- it exists on the date of submittal of this form, should the EVRC be
- approved as a Specification or Report by 3GPP2, or as a transposed
- Standard by any of the 3GPP2's Organizational Partners, the Source(s)
- state(s) that a worldwide license to reproduce, use and distribute the
- Software, the license rights to which are held by the Source(s), will
- be made available to applicants under terms and conditions that are
- reasonable and non-discriminatory, which may include monetary compensation,
- and only to the extent necessary for the practice of any or all of the
- Normative portions of the EVRC or the field of use of practice of the
- EVRC Specification, Report, or Standard. The statement contained above
- is irrevocable and shall be binding upon the Source(s). In the event
- the rights of the Source(s) in and to copyright or copyright license
- rights subject to such commitment are assigned or transferred, the
- Source(s) shall notify the assignee or transferee of the existence of
- such commitments.
- *******************************************************************/
-
- /*============================================================================*/
- /*===================================================================*/
- /* */
- /* Conexant Systems, Inc., Qualcomm Inc., Nokia Inc,. Nortel */
- /* Networks, Lucent Technologies, and Motorola Inc. grants a free, */
- /* irrevocable license to 3GPP2 and its Organizational Partners to */
- /* incorporate text or other copyrightable material contained in the */
- /* contribution and any modifications thereof in the creation of */
- /* 3GPP2 publications; to copyright and sell in Organizational */
- /* Partner's name any Organizational Partner's standards publication */
- /* even though it may include portions of the contribution; and at */
- /* the Organizational Partner's sole discretion to permit others to */
- /* reproduce in whole or in part such contributions or the resulting */
- /* Organizational Partner's standards publication. The contributor */
- /* must also be willing to grant licenses under such contributor */
- /* copyrights to third parties on reasonable, non-discriminatory */
- /* terms and conditions, as appropriate. */
- /* */
- /*-------------------------------------------------------------------*/
- /* */
- /* Copyright 2001 Conexant Systems, Inc. This document is provided */
- /* as a discussion instrument only and is not binding on Conexant */
- /* Systems, Inc. The contributor reserves the right to add to, amend */
- /* or otherwise modify the contents thereof. */
- /* */
- /* Conexant Systems, Inc. grants a free, irrevocable license to 3GPP2*/
- /* and its Organization Partners to incorporate, for any legitimate */
- /* 3GPP2 purpose, any copyrightable material contained in this */
- /* contribution and any revisions thereof, in publications of 3GPP2. */
- /* The contributor may hold one or more patents or applications for */
- /* letters patent that cover the information contained in this */
- /* contribution. Noting contained in this copyright statement shall */
- /* be construed as conferring by implication or estoppel, or */
- /* otherwise a license or any other right under any existing or */
- /* later issuing patent, whether or not the use of information */
- /* herein necessarily employs an invention of any such patent or */
- /* later issuing patent. */
- /* */
- /*-------------------------------------------------------------------*/
- /* */
- /* Copyright QUALCOMM Incorporated. All rights reserved. */
- /* The information contained in this contribution is provided for */
- /* the sole purpose of promoting discussion within the 3GPP2 and its */
- /* Organization Partners and is not binding on the contributor. */
- /* The contributor reserves the right to add to, amend, or withdraw */
- /* the statements contained herein. */
- /* QUALCOMM Incorporated grants a free, irrevocable license to 3GPP2 */
- /* and its Organization Partners to incorporate text or other */
- /* copyrightable material contained in the contribution and any */
- /* modifications thereof in the creation of 3GPP2 publications; */
- /* to copyright and sell in Organizational Partner's name any */
- /* Organizational Partner's standards publication even though it may */
- /* include portions of the contribution; and at the Organization */
- /* Partner's sole discretion to permit others to reproduce in whole */
- /* or in part such contributions or the resulting Organizational */
- /* Partner's standards publication. The contributor may hold one or */
- /* more patents or copyrights that cover information contained in */
- /* this contribution. A license will be made available to applicants */
- /* under reasonable terms and conditions that are demonstrably free */
- /* of any unfair discrimination. */
- /* Nothing contained herein shall be construed as conferring by */
- /* implication, estoppel, or otherwise any license or right under */
- /* any patent, whether or not the use of information herein */
- /* necessarily employs an invention of any existing or later issued */
- /* patent, or copyright. The contributor reserves the right to use */
- /* all material submitted in this contribution for his own purposes, */
- /* including republication and distribution to others. */
- /* */
- /*-------------------------------------------------------------------*/
- /* */
- /* The proposals in this submission have been formulated by Nokia, */
- /* Inc. (Nokia), to assist the 3GPP2 Standards Committee. This */
- /* document is offered to the committee as a basis for discussion */
- /* and is not binding on Nokia. The requirements are subject to */
- /* change in form and in numerical values after more study. Nokia */
- /* specifically reserves the right to add to, or amend, the */
- /* quantitative statements made herein. Nothing contained herein */
- /* shall be construed as conferring by implication, estoppel, or */
- /* otherwise any license or right under any patent, whether or not */
- /* the use of information herein necessarily employs an invention of */
- /* any existing or later issued patent. */
- /* Copyright 2001 Nokia, Inc. All Rights Reserved. Nokia hereby */
- /* gives permission for copying this submission for the legitimate */
- /* purposes of the 3GPP2 Standards Committee, provided Nokia, Inc. */
- /* is credited on all copies. Distribution or reproduction of this */
- /* document, by any means, electronic, mechanical, or otherwise, in */
- /* its entirety, or any portion thereof, for monetary gain or any */
- /* non-3GPP2 purposes is expressly prohibited. */
- /* */
- /*-------------------------------------------------------------------*/
- /* */
- /* Nortel Networks grants a free, irrevocable license to 3GPP2 and */
- /* its Organizational Partners to incorporate text or other */
- /* copyrightable material contained in the contribution and any */
- /* modifications thereof in the creation of 3GPP2 publications; to */
- /* copyright and sell in Organizational Partner's name any */
- /* Organizational Partner's standards publication even though it may */
- /* include portions of the contribution; and at the Organizational */
- /* Partner's sole discretion to permit others to reproduce in whole */
- /* or in part such contributions or the resulting Organizational */
- /* Partner's standards publication. The contributor must also be */
- /* willing to grant licenses under such contributor copyrights to */
- /* third parties on reasonable, non-discriminatory terms and */
- /* conditions, as appropriate. */
- /* */
- /*-------------------------------------------------------------------*/
- /* */
- /* Notice: */
- /* This contribution has been prepared by the contributor to assist */
- /* 3GPP2 Technical Specifications Group C. This document is offered */
- /* to 3GPP2 Technical Specifications Group C as a basis for */
- /* discussion and should not be construed as a binding proposal on */
- /* Lucent Technologies Inc. or any other company. Specifically, */
- /* Lucent Technologies Inc. reserves the right to modify, amend, or */
- /* withdraw the statements contained herein. */
- /* */
- /* Permission is granted to 3GPP2 Technical Specifications Group C */
- /* participants to copy any portion of this document for legitimate */
- /* purposes of 3GPP2 Technical Specifications Group C. Copying for */
- /* monetary gain or other non-3GPP2 Technical Specifications Group C */
- /* purposes is prohibited. */
- /* */
- /*-------------------------------------------------------------------*/
- /* */
- /* Grant of license Motorola Inc. grants a free, irrevocable license */
- /* to 3GPP2 and its organizational partners to incorporate Motorola- */
- /* supplied text or other copyrightable material contained in the */
- /* contribution and any modifications thereof in the creation of */
- /* 3GPP2 publications, to copyright and sell in organizational */
- /* partners name any organizational partners standards publications */
- /* even though it may include portions of the contribution; and at */
- /* the organizational partners sole discretion to permit others */
- /* to reproduce in whole or in part such contributions or the */
- /* resulting organizational partners standards publication. Motorola */
- /* is also willing to grant licenses under such Motorola copyrights */
- /* to third parties on reasonable, non-discriminatory terms and */
- /* conditions, as appropriate. */
- /* */
- /* Notice: */
- /* This document has been prepared by Motorola Inc. to assist the */
- /* 3GPP2 standards committee. This document is offered to the */
- /* committee as a basis for discussion and should not be considered */
- /* as a binding proposal on Motorola Inc. or any other company. */
- /* Specifically, Motorola Inc. reserves the right to modify, amend, */
- /* or withdraw the statement contained herein. Permission is granted */
- /* to 3GPP2 and its organizational partners to copy any portion of */
- /* this document for the legitimate purposes of the 3GPP2. Copying */
- /* this document for monetary gain or other non-3GPP2 purpose is */
- /* prohibited. Motorola Inc. may hold one or more patents of */
- /* copyrights that cover information contained in this contribution, */
- /* and agrees that a license under those rights will be made */
- /* available on reasonable and non-discriminatory terms and */
- /* conditions, subject to receiving a reciprocal license in return. */
- /* Nothing contained herein shall be construed as conferring by */
- /* implication, estoppel, or otherwise any license or right under */
- /* any patent, whether or not the use of information herein */
- /* necessarily employs an invention of any existing or later issued */
- /* patent, or copyright. */
- /* */
- /* Notice */
- /* Permission is granted to 3GPP2 participants to copy any portion of*/
- /* this contribution for the legitimate purpose of the 3GPP2. */
- /* Copying this contribution for monetary gain or other non-3GPP2 */
- /* purpose is prohibited. */
- /* */
- /*===================================================================*/
- /* FILE: basic_op40.c */
- /*-------------------------------------------------------------------*/
- /* PURPOSE : Modified TIA basic operations for 40-bit accumulators */
- /*===================================================================*/
- /*___________________________________________________________________________
- |
- | Basic arithmetic operators using 16-bit/40-bit arithmatic
- |
- | These operators come originally from ETSI TCH-HS library
- | (used in GSM EFR 13kbit/s).
- | They were modified to support 16-bit/40-bit arithmetic operations.
- | Standard 32-bit basic operators are replaced by 40-bit operators to be
- | compatible with
- | most of the new 40-bit DSP in the industry. The use of 40 bits
- | accumulator allow the DSP to avoid overflow/saturation in the calculation
- | of energy, correlation, filtering or any other procedure that need more than
- | 32 bits in the summation of product. These 40-bit operators should be
- | used when the target platform is DSP with 40-bit accumulator.
- |
- | Word40 is represented using a floating point format (double)
- | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- | Because some platforms do not allow integer of 40 bits, a floating point
- | format is used, with at less 40 bits in the mantissa, to represent long
- | integer of 40 bits. MAX_40 and MIN_40 are defined in this file.
- |____________________________________________________________________________
- */
- /***********************************************************************/
- /*_________________________________________________________________________
- | |
- | Include Files |
- |_________________________________________________________________________|
- */
- #include <math.h>
- #include "typedef_fx.h"
- #include "basic_op40.h"
- #ifdef WMOPS_FX
- #include "typedef_fx.h"
- #include "main_fx.h"
- #include "const_fx.h"
- #include "ext_var_fx.h"
- #include "lib_wmp_fx.h"
- #endif
- //*************************************************************************
- // local functions for 40 bit accumulator
- /*___________________________________________________________________________
- | |
- | Function Name : L_shift_left40 |
- | |
- | Purpose : |
- | |
- | Perform an integer arithmetic shift on the double format value. |
- | If nbits > 0, arithmetically shift the value left nbits positions. |
- | Zero fill the nbits LSB of the value. |
- | If nbits < 0, arithmetically shift the value right by -nbits positions |
- | with sign extension. |
- | No overflow control and saturation. |
- |___________________________________________________________________________|
- */
- static Word40 L_shift_left40(Word40 value, Word16 nbits)
- {
- if (nbits > 40) nbits = 40; /* to avoid needless loop after overflow */
- if (nbits < -40) nbits = -40;
- if (nbits < 0)
- {
- for(; nbits<0; nbits++)
- {
- value = value * 0.5; /* remove fraction bits */
- }
- value = floor(value);
- }
- else
- {
- value = floor(value); /* remove fraction bits */
- for(; nbits>0; nbits--)
- {
- value = value * 2;
- }
- }
- return(value);
- }
- /*___________________________________________________________________________
- | |
- | Function Name : L_saturate40 |
- | |
- | Purpose : |
- | |
- | Limit the value to the range of a 40 bit word. |
- | |
- | Return Value : |
- | |
- | var_out 40 bit short signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= var_out <= MAX_40. |
- |___________________________________________________________________________|
- */
- static Word40 L_saturate40(Word40 value)
- {
- Word40 L_var_out;
- L_var_out = value;
-
- if (L_var_out > MAX_40)
- {
- L_var_out = MAX_40;
- giOverflow = 1;
- }
- else if (L_var_out < MIN_40)
- {
- L_var_out = MIN_40;
- giOverflow = 1;
- }
- return(L_var_out);
- }
- //***************************************************************************
- //***************************************************************************
- //***************************************************************************
- //***************************************************************************
- // public functions for 40 bit accumulator
- //
- // J. Klein, Conexant Systems 12/01/00
- /*___________________________________________________________________________
- | |
- | Function Name : L_add40 |
- | |
- | Purpose : |
- | |
- | Add L_var1 by L_var2. Return a 40 bit result without saturation: |
- | L_add40 (L_var1, L_var2). |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var1 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var1 <= MAX_40. |
- | |
- | |
- | L_var2 32 bit long signed integer (Word32) whose value falls in |
- | the : MIN_32 <= L_var2 <= MAX_32. |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var_out <= MAX_40. |
- |___________________________________________________________________________|
- */
- Word40 L_add40(Word40 L_var1, Word32 L_var2)
- {
- Word40 L_var_out;
- L_var_out = L_var1 + (Word40)L_var2;
- L_var_out = L_saturate40(L_var_out);
- #ifdef WMOPS_FX
- counter_fx.L_add40++;
- #endif
- return(L_var_out);
- }
- /*___________________________________________________________________________
- | |
- | Function Name : L_sub40 |
- | |
- | Purpose : |
- | |
- | Substract L_var1 by L_var2. Return a 40 bit result without saturation: |
- | L_sub40 (L_var1, L_var2). |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var1 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var1 <= MAX_40. |
- | |
- | |
- | L_var2 32 bit long signed integer (Word32) whose value falls in |
- | the : MIN_32 <= L_var2 <= MAX_32. |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var_out <= MAX_40. |
- |___________________________________________________________________________|
- */
- Word40 L_sub40(Word40 L_var1, Word32 L_var2)
- {
- Word40 L_var_out;
- L_var_out = L_var1 - (Word40)L_var2;
- L_var_out = L_saturate40(L_var_out);
- #ifdef WMOPS_FX
- counter_fx.L_sub40++;
- #endif
- return(L_var_out);
- }
- /*___________________________________________________________________________
- | |
- | Function Name : L_mac40 |
- | |
- | Purpose : |
- | |
- | Multiply var1 by var2 and shift the result left by 1. Add the 40 bit |
- | result to L_var3 with saturation, return a 40 bit result: |
- | L_mac(L_var3,var1,var2) = L_add(L_var3,(L_mult(var1,var2)). |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var3 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var3 <= MAX_40. |
- | |
- | var1 16 bit short signed integer (Word16) whose value falls in |
- | the : MIN_16 <= var1 <= MAX_16. |
- | |
- | var2 16 bit short signed integer (Word16) whose value falls in |
- | the : MIN_16 <= var1 <= MAX_16. |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var_out <= MAX_40. |
- |___________________________________________________________________________|
- */
- Word40 L_mac40(Word40 L_var3, Word16 var1, Word16 var2)
- {
- Word40 L_var_out;
- L_var_out = L_var3 + ((Word40)var1 * (Word40)var2 * 2.0);
- L_var_out = L_saturate40(L_var_out);
- #ifdef WMOPS_FX
- counter_fx.L_mac40++;
- #endif
- return(L_var_out);
- }
- /*___________________________________________________________________________
- | |
- | Function Name : L_msu40 |
- | |
- | Purpose : |
- | |
- | Multiply var1 by var2 and shift the result left by 1. Subtract the 40 |
- | bit result to L_var3 with saturation, return a 40 bit result: |
- | L_msu(L_var3,var1,var2) = L_sub(L_var3,(L_mult(var1,var2)). |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var3 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var3 <= MAX_40. |
- | |
- | var1 16 bit short signed integer (Word16) whose value falls in |
- | the range : MIN_16 <= var1 <= MAX_16. |
- | |
- | var2 16 bit short signed integer (Word16) whose value falls in |
- | therange : MIN_16 <= var1 <= MAX_16. |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var_out <= MAX_40. |
- |___________________________________________________________________________|
- */
- Word40 L_msu40(Word40 L_var3, Word16 var1, Word16 var2)
- {
- Word40 L_var_out;
- L_var_out = L_var3 - ((Word40)var1 * (Word40)var2 * 2.0);
- L_var_out = L_saturate40(L_var_out);
- #ifdef WMOPS_FX
- counter_fx.L_msu40++;
- #endif
- return(L_var_out);
- }
- /*___________________________________________________________________________
- | |
- | Function Name : L_shr40 |
- | |
- | Purpose : |
- | |
- | Arithmetically shift the 40 bit input L_var1 right var2 positions with |
- | sign extension. If var2 is negative, arithmetically shift L_var1 left |
- | by -var2 and zero fill the var2 LSB of the result. Saturate the result |
- | in case of underflows or overflows. |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | L_var1 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var3 <= MAX_40. |
- | |
- | var2 16 bit short signed integer (Word16) whose value falls in |
- | therange : MIN_16 <= var1 <= MAX_16. |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var_out <= MAX_40. |
- |___________________________________________________________________________|
- */
- Word40 L_shr40(Word40 L_var1, Word16 var2)
- {
- Word40 L_var_out;
- Word40 L_shl40(Word40 L_var1, Word16 var2);
- if (var2 < 0)
- {
- L_var_out = L_shl40(L_var1,(Word16)(-var2));
- #ifdef WMOPS_FX
- counter_fx.L_shl40--;
- #endif
- }
- else
- {
- L_var_out = L_shift_left40(L_var1, (Word16)(-var2));
- }
- #ifdef WMOPS_FX
- counter_fx.L_shr40++;
- #endif
- return(L_var_out);
- }
- /*___________________________________________________________________________
- | |
- | Function Name : L_shl40 |
- | |
- | Purpose : |
- | |
- | Arithmetically shift the 40 bit input L_var1 left var2 positions. Zero |
- | fill the var2 LSB of the result. If var2 is negative, L_var1 right by |
- | -var2 arithmetically shift with sign extension. Saturate the result in |
- | case of underflows or overflows. |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | L_var1 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var3 <= MAX_40. |
- | |
- | var2 16 bit short signed integer (Word16) whose value falls in |
- | therange : MIN_16 <= var1 <= MAX_16. |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= L_var_out <= MAX_40. |
- |___________________________________________________________________________|
- */
- Word40 L_shl40(Word40 L_var1, Word16 var2)
- {
- Word40 L_var_out;
- if (var2 <= 0)
- {
- L_var_out = L_shr40(L_var1,(Word16)(-var2));
- #ifdef WMOPS_FX
- counter_fx.L_shr40--;
- #endif
- }
- else
- {
- L_var_out = L_shift_left40(L_var1, var2);
- L_var_out = L_saturate40(L_var_out);
- }
- #ifdef WMOPS_FX
- counter_fx.L_shl40++;
- #endif
- return(L_var_out);
- }
- /*___________________________________________________________________________
- | |
- | Function Name : L_sat32_40 |
- | |
- | Purpose : |
- | |
- | 40 bit L_var1 is limited to the range MAX_32..MIN_32. L_var1 is set |
- | to MAX_32 on overflow or MIN_32 on underflow. |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var1 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= var1 <= MAX_40. |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_32 <= var_out <= MAX_32. |
- |___________________________________________________________________________|
- */
- Word40 L_sat32_40(Word40 L_var1)
- {
- Word40 L_var_out;
- if (L_var1 > MAX_32)
- {
- L_var_out = MAX_32;
- giOverflow = 1;
- }
- else if (L_var1 < MIN_32)
- {
- L_var_out = MIN_32;
- giOverflow = 1;
- }
- else L_var_out = L_var1;
- #ifdef WMOPS_FX
- counter_fx.L_sat32_40++;
- #endif
- return (L_var_out);
- }
- /*___________________________________________________________________________
- | |
- | Function Name : norm32_l_40 |
- | |
- | Purpose : |
- | |
- | Produces the number of left shift needed to normalize in 32 bits format |
- | the 40 bit variable l_var1 for positive values on the interval with |
- | minimum of (MAX_32+1)/2 and maximum of MAX_32, and for negative values |
- | on the interval with minimum of MIN_32 and maximum of (MIN_32/2)+1; |
- | in order to normalize the result, the following operation must be done: |
- | |
- | norm_L_var1 = L_shl40(L_var1,norm32_l(L_var1)). |
- | |
- | Complexity weight : 3 |
- | |
- | Inputs : |
- | |
- | L_var1 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= var1 <= MAX_40. |
- | |
- | Return Value : |
- | |
- | var_out 16 bit short signed integer (Word16) whose value falls in |
- | therange : -8 <= var_out <= 31. |
- |___________________________________________________________________________|
- */
- Word16 norm32_l40(Word40 L_var1)
- {
- Word16 var_out;
- L_var1 = floor(L_var1);
- var_out = 0;
- if (L_var1 != 0)
- {
- while ((L_var1 > MIN_32) && (L_var1 < MAX_32))
- {
- L_var1 = L_shift_left40(L_var1, 1);
- var_out++;
- }
- while ((L_var1 < MIN_32) || (L_var1 > MAX_32))
- {
- L_var1 = L_shift_left40(L_var1, -1);
- var_out--;
- }
- }
- #ifdef WMOPS_FX
- counter_fx.norm32_l40++;
- #endif
- return(var_out);
- }
- /*___________________________________________________________________________
- | |
- | Function Name : extract_l40 |
- | |
- | Purpose : |
- | |
- | Get the lower 16 bits of a 40-bit variable into a 16-bit variable |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var1 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= var1 <= MAX_40. |
- | |
- | Return Value : |
- | |
- | var_out 16 bit short signed integer (Word16) which may take any value |
- |___________________________________________________________________________|
- */
- Word16 extract_l40(Word40 L_var1)
- {
- Word16 out;
-
- out = (Word16)(L_var1 - floor(L_var1/65536.)*65536.);
- #ifdef WMOPS_FX
- counter_fx.extract_l40++;
- #endif
- return (out);
- }
- /*___________________________________________________________________________
- | |
- | Function Name : L_deposit_l40 |
- | |
- | Purpose : |
- | |
- | Replace lower 16 bits of a 40-bit variable by those of 16-bit input |
- | variable var_in |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var1 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= var1 <= MAX_40. |
- | var_in 16 bit short signed integer (Word16) which may take any value |
- | |
- | Return Value : |
- | |
- | 40 bit long signed integer (Word40) whose value falls in the |
- | range : MIN_40 <= var1 <= MAX_40. |
- |___________________________________________________________________________|
- */
- Word40 L_deposit_l40(Word40 L_var1, Word16 var_in)
- {
- Word40 out;
- Word32 tmp32;
-
- tmp32 = 0x0000ffff & (Word32)var_in; /* no sign extend */
- out = L_add40(floor(L_var1/65536.)*65536., tmp32);
- #ifdef WMOPS_FX
- counter_fx.L_add40--;
- counter_fx.L_deposit_l40++;
- #endif
- return (out);
- }
|