l_sub.h revision 4f1efc098cb5791c3e9f483f2af84aef70d2d0a0
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_sub.h
32
33------------------------------------------------------------------------------
34 REVISION HISTORY
35
36 Description: Created separate header file for L_sub function.
37
38 Description: Updated function prototype declaration to reflect new interface.
39              A pointer to overflow flag is passed into the function. Updated
40              template.
41
42 Description: Moved _cplusplus #ifdef after Include section.
43
44 Description: Providing support for ARM and Linux-ARM assembly instructions.
45
46 Who:                       Date:
47 Description:
48
49------------------------------------------------------------------------------
50 INCLUDE DESCRIPTION
51
52 This file contains all the constant definitions and prototype definitions
53 needed by the L_sub function.
54
55------------------------------------------------------------------------------
56*/
57
58/*----------------------------------------------------------------------------
59; CONTINUE ONLY IF NOT ALREADY DEFINED
60----------------------------------------------------------------------------*/
61#ifndef L_SUB_H
62#define L_SUB_H
63
64
65/*----------------------------------------------------------------------------
66; INCLUDES
67----------------------------------------------------------------------------*/
68#include    "basicop_malloc.h"
69
70/*--------------------------------------------------------------------------*/
71#ifdef __cplusplus
72extern "C"
73{
74#endif
75
76    /*----------------------------------------------------------------------------
77    ; MACROS
78    ; Define module specific macros here
79    ----------------------------------------------------------------------------*/
80
81    /*----------------------------------------------------------------------------
82    ; DEFINES
83    ; Include all pre-processor statements here.
84    ----------------------------------------------------------------------------*/
85
86    /*----------------------------------------------------------------------------
87    ; EXTERNAL VARIABLES REFERENCES
88    ; Declare variables used in this module but defined elsewhere
89    ----------------------------------------------------------------------------*/
90
91    /*----------------------------------------------------------------------------
92    ; SIMPLE TYPEDEF'S
93    ----------------------------------------------------------------------------*/
94
95    /*----------------------------------------------------------------------------
96    ; ENUMERATED TYPEDEF'S
97    ----------------------------------------------------------------------------*/
98
99    /*----------------------------------------------------------------------------
100    ; STRUCTURES TYPEDEF'S
101    ----------------------------------------------------------------------------*/
102
103    /*----------------------------------------------------------------------------
104    ; GLOBAL FUNCTION DEFINITIONS
105    ; Function Prototype declaration
106    ----------------------------------------------------------------------------*/
107#if defined(PV_ARM_V5) /* Instructions for ARM Assembly on ADS*/
108
109    __inline Word32 L_sub(Word32 L_var1, Word32 L_var2, Flag *pOverflow)
110    {
111        Word32 result;
112
113        OSCL_UNUSED_ARG(pOverflow);
114
115        __asm
116        {
117            QSUB result, L_var1, L_var2
118        }
119
120        return(result);
121
122    }
123
124#elif defined(PV_ARM_GCC_V5) /* Instructions for ARM-linux cross-compiler*/
125
126    __inline Word32 L_sub(Word32 L_var1, Word32 L_var2, Flag *pOverflow)
127    {
128        register Word32 ra = L_var1;
129        register Word32 rb = L_var2;
130        Word32 result;
131
132        OSCL_UNUSED_ARG(pOverflow);
133
134        asm volatile("qsub %0, %1, %2"
135             : "=r"(result)
136                             : "r"(ra), "r"(rb)
137                            );
138
139        return (result);
140    }
141
142#else /* C EQUIVALENT */
143
144    static inline Word32 L_sub(register Word32 L_var1, register Word32 L_var2,
145                               register Flag *pOverflow)
146    {
147        Word32 L_diff;
148
149        L_diff = L_var1 - L_var2;
150
151        if ((L_var1 ^ L_var2) < 0)
152        {
153            if ((L_diff ^ L_var1) & MIN_32)
154            {
155                L_diff = (L_var1 < 0L) ? MIN_32 : MAX_32;
156                *pOverflow = 1;
157            }
158        }
159
160        return (L_diff);
161    }
162
163#endif
164    /*----------------------------------------------------------------------------
165    ; END
166    ----------------------------------------------------------------------------*/
167#ifdef __cplusplus
168}
169#endif
170
171#endif /* _L_SUB_H_ */
172
173
174