• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004-2010 NXP Software
3  * Copyright (C) 2010 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include "LVM_Types.h"
19 #include "LVM_Macros.h"
20 #include "ScalarArithmetic.h"
21 
22 /*-------------------------------------------------------------------------*/
23 /* FUNCTION:                                                               */
24 /*   LVM_Polynomial                                                        */
25 /*                                                                         */
26 /* DESCRIPTION:                                                            */
27 /*   This function performs polynomial expansion                           */
28 /*  Y = (A0 + A1*X + A2*X2 + A3*X3 + �.. + AN*xN) << AN+1                  */
29 /*                                                                         */
30 /*  LVM_INT32 LVM_Polynomial(LVM_UINT16    N,                              */
31 /*                           LVM_INT32    *pCoefficients,                  */
32 /*                           LVM_INT32    X)                               */
33 /*                                                                         */
34 /* PARAMETERS:                                                             */
35 /*                                                                         */
36 /*  N                is the polynomial order                               */
37 /*  pCoefficients    is the ptr to polynomial coefficients A0,A1.. in Q.31 */
38 /*  X                is the input variable                                 */
39 /*                                                                         */
40 /* RETURNS:                                                                */
41 /*   The result of the polynomial expansion in Q1.31 format                */
42 /*-------------------------------------------------------------------------*/
43 
LVM_Polynomial(LVM_UINT16 N,LVM_INT32 * pCoefficients,LVM_INT32 X)44 LVM_INT32 LVM_Polynomial(LVM_UINT16    N,
45                          LVM_INT32    *pCoefficients,
46                          LVM_INT32    X)
47 {
48     LVM_INT32 i;
49     LVM_INT32 Y,A,XTemp,Temp,sign;
50 
51     Y=*pCoefficients; /* Y=A0*/
52     pCoefficients++;
53 
54     if((LVM_UINT32)X==0x80000000)
55     {
56         Temp=-1;
57         sign=Temp;
58         for(i=1;i<=N;i++)
59         {
60             Y+=((*pCoefficients)*sign);
61             pCoefficients++;
62             sign*=Temp;
63         }
64 
65 
66     }
67     else
68     {
69         XTemp=X;
70         for(i=N-1;i>=0;i--)
71         {
72             A=*pCoefficients;
73             pCoefficients++;
74 
75             MUL32x32INTO32(A,XTemp,Temp,31)
76             Y+=Temp;
77 
78             MUL32x32INTO32(XTemp,X,Temp,31)
79             XTemp=Temp;
80         }
81     }
82     A=*pCoefficients;
83     pCoefficients++;
84 
85     if(A<0)
86     {
87         A=Abs_32(A);
88         Y=Y>>A;
89     }
90     else
91     {
92         Y = Y<<A;
93     }
94     return Y;
95 }
96 
97