summaryrefslogtreecommitdiff
path: root/audio_codec/libraac/assembly.h (plain)
blob: aeee62b5116bbc4f7194523f8bee82e84263397d
1/* ***** BEGIN LICENSE BLOCK *****
2 * Source last modified: $Id: assembly.h,v 1.7 2005/11/10 00:04:40 margotm Exp $
3 *
4 * Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved.
5 *
6 * The contents of this file, and the files included with this file,
7 * are subject to the current version of the RealNetworks Public
8 * Source License (the "RPSL") available at
9 * http://www.helixcommunity.org/content/rpsl unless you have licensed
10 * the file under the current version of the RealNetworks Community
11 * Source License (the "RCSL") available at
12 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
13 * will apply. You may also obtain the license terms directly from
14 * RealNetworks. You may not use this file except in compliance with
15 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
16 * to this file, the RCSL. Please see the applicable RPSL or RCSL for
17 * the rights, obligations and limitations governing use of the
18 * contents of the file.
19 *
20 * This file is part of the Helix DNA Technology. RealNetworks is the
21 * developer of the Original Code and owns the copyrights in the
22 * portions it created.
23 *
24 * This file, and the files included with this file, is distributed
25 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
26 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
27 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
28 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
29 * ENJOYMENT OR NON-INFRINGEMENT.
30 *
31 * Technology Compatibility Kit Test Suite(s) Location:
32 * http://www.helixcommunity.org/content/tck
33 *
34 * Contributor(s):
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/**************************************************************************************
39 * Fixed-point HE-AAC decoder
40 * Jon Recker (jrecker@real.com)
41 * February 2005
42 *
43 * assembly.h - inline assembly language functions and prototypes
44 *
45 * MULSHIFT32(x, y) signed multiply of two 32-bit integers (x and y),
46 * returns top 32-bits of 64-bit result
47 * CLIPTOSHORT(x) convert 32-bit integer to 16-bit short,
48 * clipping to [-32768, 32767]
49 * FASTABS(x) branchless absolute value of signed integer x
50 * CLZ(x) count leading zeros on signed integer x
51 * MADD64(sum64, x, y) 64-bit multiply accumulate: sum64 += (x*y)
52 **************************************************************************************/
53
54#ifndef _ASSEMBLY_H
55#define _ASSEMBLY_H
56
57/* toolchain: ARM gcc
58 * target architecture: ARM v.4 and above (requires 'M' type processor for 32x32->64 multiplier)
59 */
60
61#if defined(__aarch64__)
62static __inline__ int MULSHIFT32(int x, int y)
63{
64 long c;
65 c = (long)x * y;
66 return (int)c;
67}
68#else
69static __inline__ int MULSHIFT32(int x, int y)
70{
71 int zlow;
72 __asm__ volatile("smull %0,%1,%2,%3" : "=&r"(zlow), "=r"(y) : "r"(x), "1"(y) : "cc");
73 return y;
74}
75#endif
76static __inline__ short CLIPTOSHORT(int x)
77{
78 int sign;
79
80 /* clip to [-32768, 32767] */
81 sign = x >> 31;
82 if (sign != (x >> 15)) {
83 x = sign ^((1 << 15) - 1);
84 }
85
86 return (short)x;
87}
88
89static __inline__ int FASTABS(int x)
90{
91 int sign;
92
93 sign = x >> (sizeof(int) * 8 - 1);
94 x ^= sign;
95 x -= sign;
96
97 return x;
98}
99
100static __inline__ int CLZ(int x)
101{
102 int numZeros;
103
104 if (!x) {
105 return (sizeof(int) * 8);
106 }
107
108 numZeros = 0;
109 while (!(x & 0x80000000)) {
110 numZeros++;
111 x <<= 1;
112 }
113
114 return numZeros;
115}
116
117typedef long long Word64;
118
119typedef union _U64 {
120 Word64 w64;
121 struct {
122 /* ARM ADS = little endian */
123 unsigned int lo32;
124 signed int hi32;
125 } r;
126} U64;
127
128#if defined(__aarch64__)
129static __inline__ Word64 MADD64(Word64 sum64, int x, int y)
130{
131 sum64 += (long)x * y;
132
133 return sum64;
134}
135#else
136static __inline__ Word64 MADD64(Word64 sum64, int x, int y)
137{
138 U64 u;
139 u.w64 = sum64;
140
141 __asm__ volatile("smlal %0,%1,%2,%3" : "+&r"(u.r.lo32), "+&r"(u.r.hi32) : "r"(x), "r"(y) : "cc");
142
143 return u.w64;
144}
145#endif
146
147#endif /* _ASSEMBLY_H */
148