OLD | NEW |
1 /* Copyright (c) 2001-2011 Timothy B. Terriberry | 1 /* Copyright (c) 2001-2011 Timothy B. Terriberry |
2 Copyright (c) 2008-2009 Xiph.Org Foundation */ | 2 Copyright (c) 2008-2009 Xiph.Org Foundation */ |
3 /* | 3 /* |
4 Redistribution and use in source and binary forms, with or without | 4 Redistribution and use in source and binary forms, with or without |
5 modification, are permitted provided that the following conditions | 5 modification, are permitted provided that the following conditions |
6 are met: | 6 are met: |
7 | 7 |
8 - Redistributions of source code must retain the above copyright | 8 - Redistributions of source code must retain the above copyright |
9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #include "opus_types.h" | 28 #include "opus_types.h" |
29 #include "opus_defines.h" | 29 #include "opus_defines.h" |
30 | 30 |
31 #if !defined(_entcode_H) | 31 #if !defined(_entcode_H) |
32 # define _entcode_H (1) | 32 # define _entcode_H (1) |
33 # include <limits.h> | 33 # include <limits.h> |
34 # include <stddef.h> | 34 # include <stddef.h> |
35 # include "ecintrin.h" | 35 # include "ecintrin.h" |
36 | 36 |
| 37 extern const opus_uint32 SMALL_DIV_TABLE[129]; |
| 38 |
| 39 #ifdef OPUS_ARM_ASM |
| 40 #define USE_SMALL_DIV_TABLE |
| 41 #endif |
| 42 |
37 /*OPT: ec_window must be at least 32 bits, but if you have fast arithmetic on a | 43 /*OPT: ec_window must be at least 32 bits, but if you have fast arithmetic on a |
38 larger type, you can speed up the decoder by using it here.*/ | 44 larger type, you can speed up the decoder by using it here.*/ |
39 typedef opus_uint32 ec_window; | 45 typedef opus_uint32 ec_window; |
40 typedef struct ec_ctx ec_ctx; | 46 typedef struct ec_ctx ec_ctx; |
41 typedef struct ec_ctx ec_enc; | 47 typedef struct ec_ctx ec_enc; |
42 typedef struct ec_ctx ec_dec; | 48 typedef struct ec_ctx ec_dec; |
43 | 49 |
44 # define EC_WINDOW_SIZE ((int)sizeof(ec_window)*CHAR_BIT) | 50 # define EC_WINDOW_SIZE ((int)sizeof(ec_window)*CHAR_BIT) |
45 | 51 |
46 /*The number of bits to use for the range-coded part of unsigned integers.*/ | 52 /*The number of bits to use for the range-coded part of unsigned integers.*/ |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 113 } |
108 | 114 |
109 /*Returns the number of bits "used" by the encoded or decoded symbols so far. | 115 /*Returns the number of bits "used" by the encoded or decoded symbols so far. |
110 This same number can be computed in either the encoder or the decoder, and is | 116 This same number can be computed in either the encoder or the decoder, and is |
111 suitable for making coding decisions. | 117 suitable for making coding decisions. |
112 Return: The number of bits scaled by 2**BITRES. | 118 Return: The number of bits scaled by 2**BITRES. |
113 This will always be slightly larger than the exact value (e.g., all | 119 This will always be slightly larger than the exact value (e.g., all |
114 rounding error is in the positive direction).*/ | 120 rounding error is in the positive direction).*/ |
115 opus_uint32 ec_tell_frac(ec_ctx *_this); | 121 opus_uint32 ec_tell_frac(ec_ctx *_this); |
116 | 122 |
| 123 /* Tested exhaustively for all n and for 1<=d<=256 */ |
| 124 static OPUS_INLINE opus_uint32 celt_udiv(opus_uint32 n, opus_uint32 d) { |
| 125 celt_assert(d>0); |
| 126 #ifdef USE_SMALL_DIV_TABLE |
| 127 if (d>256) |
| 128 return n/d; |
| 129 else { |
| 130 opus_uint32 t, q; |
| 131 t = EC_ILOG(d&-d); |
| 132 q = (opus_uint64)SMALL_DIV_TABLE[d>>t]*(n>>(t-1))>>32; |
| 133 return q+(n-q*d >= d); |
| 134 } |
| 135 #else |
| 136 return n/d; |
117 #endif | 137 #endif |
| 138 } |
| 139 |
| 140 static OPUS_INLINE opus_int32 celt_sudiv(opus_int32 n, opus_int32 d) { |
| 141 celt_assert(d>0); |
| 142 #ifdef USE_SMALL_DIV_TABLE |
| 143 if (n<0) |
| 144 return -(opus_int32)celt_udiv(-n, d); |
| 145 else |
| 146 return celt_udiv(n, d); |
| 147 #else |
| 148 return n/d; |
| 149 #endif |
| 150 } |
| 151 |
| 152 #endif |
OLD | NEW |