📄 math_ext32.c
字号:
/* 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. */
/* */
/*-------------------------------------------------------------------*/
/*_________________________________________________________________________
| |
| Include |
|_________________________________________________________________________|
*/
#include "typedef_fx.h"
#include "basic_op.h"
#ifdef WMOPS_FX
#include "main_fx.h"
#include "const_fx.h"
#include "ext_var_fx.h"
#endif
/*_________________________________________________________________________
| |
| Define |
|_________________________________________________________________________|
*/
#define SW_MIN (short)0x8000 /* smallest Ram */
#define SW_MAX (short)0x7fff /* largest Ram */
/*_________________________________________________________________________
| |
| Functions |
|_________________________________________________________________________|
*/
/****************************************************************************
*
* FUNCTION NAME: L_mpy_ll
*
* PURPOSE: Multiply a 32 bit number (L_var1) and a 32 bit number
* (L_var2), and return a 32 bit result.
*
* INPUTS:
*
* L_var1 A Word32 input variable
*
* L_var2 A Word32 input variable
*
* OUTPUTS: none
*
* IMPLEMENTATION:
*
* Performs a 31x31 bit multiply, Complexity=24 Ops.
*
* Let x1x0, or y1y0, be the two constituent halves
* of a 32 bit number. This function performs the
* following:
*
* low = ((x0 >> 1)*(y0 >> 1)) >> 16 (low * low)
* mid1 = [(x1 * (y0 >> 1)) >> 1 ] (high * low)
* mid2 = [(y1 * (x0 >> 1)) >> 1] (high * low)
* mid = (mid1 + low + mid2) >> 14 (sum so far)
* output = (y1*x1) + mid (high * high)
*
*
* RETURN VALUE: A Word32 value
*
* KEYWORDS: mult,mpy,multiplication
*
***************************************************************************/
Word32 L_mpy_ll(Word32 L_var1, Word32 L_var2)
{
Word16 swLow1,
swLow2,
swHigh1,
swHigh2;
Word32 L_varOut,
L_low,
L_mid1,
L_mid2,
L_mid;
#ifdef WMOPS_FX
counter_fx.L_mpy_ll++;
counter_fx.shr -= 2;
counter_fx.extract_l -= 2;
counter_fx.extract_h -= 2;
counter_fx.L_mult -= 3;
counter_fx.L_shr -= 4;
counter_fx.L_add -= 2;
counter_fx.L_mac--;
#endif
swLow1 = shr(extract_l(L_var1), 1);
swLow1 = SW_MAX & swLow1;
swLow2 = shr(extract_l(L_var2), 1);
swLow2 = SW_MAX & swLow2;
swHigh1 = extract_h(L_var1);
swHigh2 = extract_h(L_var2);
L_low = L_mult(swLow1, swLow2);
L_low = L_shr(L_low, 16);
L_mid1 = L_mult(swHigh1, swLow2);
L_mid1 = L_shr(L_mid1, 1);
L_mid = L_add(L_mid1, L_low);
L_mid2 = L_mult(swHigh2, swLow1);
L_mid2 = L_shr(L_mid2, 1);
L_mid = L_add(L_mid, L_mid2);
L_mid = L_shr(L_mid, 14);
L_varOut = L_mac(L_mid, swHigh1, swHigh2);
return (L_varOut);
}
/*----------------------------------------------------------------------------*/
/****************************************************************************
*
* FUNCTION NAME: L_mpy_ls
*
* PURPOSE: Multiply a 32 bit number (L_var2) and a 16 bit
* number (var1) returning a 32 bit result. L_var2
* is truncated to 31 bits prior to executing the
* multiply.
*
* INPUTS:
*
* L_var2 A Word32 input variable
*
* var1 A Word16 input variable
*
* OUTPUTS: none
*
* RETURN VALUE: A Word32 value
*
* KEYWORDS: mult,mpy,multiplication
*
***************************************************************************/
Word32 L_mpy_ls(Word32 L_var2, Word16 var1)
{
Word32 L_varOut;
Word16 swtemp;
#ifdef WMOPS_FX
counter_fx.L_mpy_ls++;
counter_fx.shr--;
counter_fx.extract_l--;
counter_fx.L_mult--;
counter_fx.L_shr--;
counter_fx.L_mac--;
#endif
swtemp = shr(extract_l(L_var2), 1);
swtemp = (short) 32767 & (short) swtemp;
L_varOut = L_mult(var1, swtemp);
L_varOut = L_shr(L_varOut, 15);
L_varOut = L_mac(L_varOut, var1, extract_h(L_var2));
return (L_varOut);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -