blob: aceb88682d0ad759f5649a02095d086479a5e08f
1 | /* ***** BEGIN LICENSE BLOCK ***** |
2 | * Source last modified: $Id: assembly.h,v 1.13 2005/04/27 19:20:50 hubbe Exp $ |
3 | * |
4 | * REALNETWORKS CONFIDENTIAL--NOT FOR DISTRIBUTION IN SOURCE CODE FORM |
5 | * Portions Copyright (c) 1995-2002 RealNetworks, Inc. |
6 | * All Rights Reserved. |
7 | * |
8 | * The contents of this file, and the files included with this file, |
9 | * are subject to the current version of the Real Format Source Code |
10 | * Porting and Optimization License, available at |
11 | * https://helixcommunity.org/2005/license/realformatsource (unless |
12 | * RealNetworks otherwise expressly agrees in writing that you are |
13 | * subject to a different license). You may also obtain the license |
14 | * terms directly from RealNetworks. You may not use this file except |
15 | * in compliance with the Real Format Source Code Porting and |
16 | * Optimization License. There are no redistribution rights for the |
17 | * source code of this file. Please see the Real Format Source Code |
18 | * Porting and Optimization License for the rights, obligations and |
19 | * limitations governing use of the contents of the file. |
20 | * |
21 | * RealNetworks is the developer of the Original Code and owns the |
22 | * copyrights in the portions it created. |
23 | * |
24 | * This file, and the files included with this file, is distributed and |
25 | * made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, |
26 | * EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL |
27 | * SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT |
29 | * OR NON-INFRINGEMENT. |
30 | * |
31 | * Technology Compatibility Kit Test Suite(s) Location: |
32 | * https://rarvcode-tck.helixcommunity.org |
33 | * |
34 | * Contributor(s): |
35 | * |
36 | * ***** END LICENSE BLOCK ***** */ |
37 | |
38 | /************************************************************************************** |
39 | * Fixed-point RealAudio 8 decoder |
40 | * Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com) |
41 | * October 2003 |
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 | **************************************************************************************/ |
52 | |
53 | #ifndef _ASSEMBLY_H |
54 | #define _ASSEMBLY_H |
55 | |
56 | #include "coder.h" |
57 | |
58 | /* toolchain: ARM gcc |
59 | * target architecture: ARM v.4 and above (requires 'M' type processor for 32x32->64 multiplier) |
60 | */ |
61 | |
62 | #if defined(__aarch64__) |
63 | static __inline__ int MULSHIFT32(int x, int y) |
64 | { |
65 | long c; |
66 | c = (long)x * y; |
67 | return (int)c; |
68 | } |
69 | #else |
70 | static __inline__ int MULSHIFT32(int x, int y) |
71 | { |
72 | int zlow; |
73 | __asm__ volatile("smull %0,%1,%2,%3" : "=&r"(zlow), "=r"(y) : "r"(x), "1"(y)); |
74 | return y; |
75 | } |
76 | #endif |
77 | static __inline short CLIPTOSHORT(int x) |
78 | { |
79 | int sign; |
80 | |
81 | /* clip to [-32768, 32767] */ |
82 | sign = x >> 31; |
83 | if (sign != (x >> 15)) { |
84 | x = sign ^((1 << 15) - 1); |
85 | } |
86 | |
87 | return (short)x; |
88 | } |
89 | |
90 | static __inline int FASTABS(int x) |
91 | { |
92 | int sign; |
93 | |
94 | sign = x >> (sizeof(int) * 8 - 1); |
95 | x ^= sign; |
96 | x -= sign; |
97 | |
98 | return x; |
99 | } |
100 | |
101 | static __inline int CLZ(int x) |
102 | { |
103 | int numZeros; |
104 | |
105 | if (!x) { |
106 | return (sizeof(int) * 8); |
107 | } |
108 | |
109 | numZeros = 0; |
110 | while (!(x & 0x80000000)) { |
111 | numZeros++; |
112 | x <<= 1; |
113 | } |
114 | |
115 | return numZeros; |
116 | } |
117 | |
118 | |
119 | #endif /* _ASSEMBLY_H */ |
120 |