1/* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18/****************************************************************************************
19Portions of this file are derived from the following 3GPP standard:
20
21    3GPP TS 26.073
22    ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23    Available from http://www.3gpp.org
24
25(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26Permission to distribute, modify and use this file under the standard license
27terms listed above has been obtained from the copyright holder.
28****************************************************************************************/
29/*
30
31 Filename: /audio/gsm_amr/c/include/l_add.h
32
33------------------------------------------------------------------------------
34 REVISION HISTORY
35
36 Description: Created separate header file for L_add function.
37
38 Description: Changed function prototype declaration. A pointer to the overflow
39              flag is being passed in as a parameter instead of using global
40              data.
41
42 Description: Updated template. Changed paramter name from overflow to
43              pOverflow
44
45 Description: Moved _cplusplus #ifdef after Include section.
46
47 Description: Providing support for ARM and Linux-ARM assembly instructions.
48
49 Who:                       Date:
50 Description:
51
52------------------------------------------------------------------------------
53 INCLUDE DESCRIPTION
54
55 This file contains all the constant definitions and prototype definitions
56 needed by the L_add function.
57
58------------------------------------------------------------------------------
59*/
60
61/*----------------------------------------------------------------------------
62; CONTINUE ONLY IF NOT ALREADY DEFINED
63----------------------------------------------------------------------------*/
64#ifndef L_ADD_H
65#define L_ADD_H
66
67/*----------------------------------------------------------------------------
68; INCLUDES
69----------------------------------------------------------------------------*/
70#include    "basicop_malloc.h"
71
72/*--------------------------------------------------------------------------*/
73#ifdef __cplusplus
74extern "C"
75{
76#endif
77
78    /*----------------------------------------------------------------------------
79    ; MACROS
80    ; Define module specific macros here
81    ----------------------------------------------------------------------------*/
82
83    /*----------------------------------------------------------------------------
84    ; DEFINES
85    ; Include all pre-processor statements here.
86    ----------------------------------------------------------------------------*/
87
88    /*----------------------------------------------------------------------------
89    ; EXTERNAL VARIABLES REFERENCES
90    ; Declare variables used in this module but defined elsewhere
91    ----------------------------------------------------------------------------*/
92
93    /*----------------------------------------------------------------------------
94    ; SIMPLE TYPEDEF'S
95    ----------------------------------------------------------------------------*/
96
97    /*----------------------------------------------------------------------------
98    ; ENUMERATED TYPEDEF'S
99    ----------------------------------------------------------------------------*/
100
101    /*----------------------------------------------------------------------------
102    ; STRUCTURES TYPEDEF'S
103    ----------------------------------------------------------------------------*/
104
105    /*----------------------------------------------------------------------------
106    ; GLOBAL FUNCTION DEFINITIONS
107    ; Function Prototype declaration
108    ----------------------------------------------------------------------------*/
109#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/
110
111    __inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow)
112    {
113        Word32 result;
114
115        OSCL_UNUSED_ARG(pOverflow);
116        __asm
117        {
118            QADD result, L_var1, L_var2
119        }
120        return(result);
121    }
122
123#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/
124
125    __inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow)
126    {
127        register Word32 ra = L_var1;
128        register Word32 rb = L_var2;
129        Word32 result;
130
131        OSCL_UNUSED_ARG(pOverflow);
132
133        asm volatile("qadd %0, %1, %2"
134             : "=r"(result)
135                             : "r"(ra), "r"(rb)
136                            );
137        return (result);
138
139    }
140
141#else /* C EQUIVALENT */
142
143
144    static inline Word32 L_add(register Word32 L_var1, register Word32 L_var2, Flag *pOverflow)
145    {
146        Word32 L_sum;
147
148        L_sum = L_var1 + L_var2;
149
150        if ((L_var1 ^ L_var2) >= 0)
151        {
152            if ((L_sum ^ L_var1) < 0)
153            {
154                L_sum = (L_var1 < 0) ? MIN_32 : MAX_32;
155                *pOverflow = 1;
156            }
157        }
158
159        return (L_sum);
160    }
161
162#endif
163
164    /*----------------------------------------------------------------------------
165    ; END
166    ----------------------------------------------------------------------------*/
167#ifdef __cplusplus
168}
169#endif
170
171#endif /* _L_ADD_H_ */
172