Jean-Marc Valin | 72e8003 | 2008-03-12 10:16:26 +1100 | [diff] [blame] | 1 | /* Copyright (C) 2003 Jean-Marc Valin */ |
| 2 | /** |
| 3 | @file fixed_c5x.h |
| 4 | @brief Fixed-point operations for the TI C5x DSP family |
| 5 | */ |
| 6 | /* |
| 7 | Redistribution and use in source and binary forms, with or without |
| 8 | modification, are permitted provided that the following conditions |
| 9 | are met: |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 10 | |
Jean-Marc Valin | 72e8003 | 2008-03-12 10:16:26 +1100 | [diff] [blame] | 11 | - Redistributions of source code must retain the above copyright |
| 12 | notice, this list of conditions and the following disclaimer. |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 13 | |
Jean-Marc Valin | 72e8003 | 2008-03-12 10:16:26 +1100 | [diff] [blame] | 14 | - Redistributions in binary form must reproduce the above copyright |
| 15 | notice, this list of conditions and the following disclaimer in the |
| 16 | documentation and/or other materials provided with the distribution. |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 17 | |
Jean-Marc Valin | 72e8003 | 2008-03-12 10:16:26 +1100 | [diff] [blame] | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
| 22 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 23 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 24 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 25 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 26 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 27 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef FIXED_C5X_H |
| 32 | #define FIXED_C5X_H |
| 33 | |
Jean-Marc Valin | a75e25d | 2008-03-24 08:32:49 +1100 | [diff] [blame] | 34 | #include "dsplib.h" |
| 35 | |
Jean-Marc Valin | 821945d | 2008-04-10 13:24:48 +1000 | [diff] [blame] | 36 | #undef IMUL32 |
| 37 | static inline long IMUL32(long i, long j) |
| 38 | { |
| 39 | long ac0, ac1; |
| 40 | ac0 = _lmpy(i>>16,j); |
| 41 | ac1 = ac0 + _lmpy(i,j>>16); |
| 42 | return _lmpyu(i,j) + (ac1<<16); |
| 43 | } |
| 44 | |
Jean-Marc Valin | 72e8003 | 2008-03-12 10:16:26 +1100 | [diff] [blame] | 45 | #undef MAX16 |
| 46 | #define MAX16(a,b) _max(a,b) |
| 47 | |
| 48 | #undef MIN16 |
| 49 | #define MIN16(a,b) _min(a,b) |
| 50 | |
| 51 | #undef MAX32 |
| 52 | #define MAX32(a,b) _lmax(a,b) |
| 53 | |
| 54 | #undef MIN32 |
| 55 | #define MIN32(a,b) _lmin(a,b) |
| 56 | |
| 57 | #undef VSHR32 |
| 58 | #define VSHR32(a, shift) _lshl(a,-(shift)) |
Jean-Marc Valin | 72e8003 | 2008-03-12 10:16:26 +1100 | [diff] [blame] | 59 | |
Jean-Marc Valin | bfcbd18 | 2008-03-15 08:12:49 +1100 | [diff] [blame] | 60 | #undef MULT16_16_Q15 |
| 61 | #define MULT16_16_Q15(a,b) (_smpy(a,b)) |
| 62 | |
Gregory Maxwell | 71d39ad | 2011-07-30 00:00:29 -0400 | [diff] [blame] | 63 | #undef MULT16_16SU |
Jean-Marc Valin | b311554 | 2008-03-16 23:33:02 +1100 | [diff] [blame] | 64 | #define MULT16_16SU(a,b) _lmpysu(a,b) |
| 65 | |
| 66 | #undef MULT_16_16 |
| 67 | #define MULT_16_16(a,b) _lmpy(a,b) |
Jean-Marc Valin | bfcbd18 | 2008-03-15 08:12:49 +1100 | [diff] [blame] | 68 | |
Jean-Marc Valin | 948dabc | 2008-03-21 10:53:09 +1100 | [diff] [blame] | 69 | /* FIXME: This is technically incorrect and is bound to cause problems. Is there any cleaner solution? */ |
| 70 | #undef MULT16_32_Q15 |
| 71 | #define MULT16_32_Q15(a,b) ADD32(SHL(MULT16_16((a),SHR((b),16)),1), SHR(MULT16_16SU((a),(b)),15)) |
| 72 | |
Jean-Marc Valin | 83006ee | 2008-03-21 10:40:43 +1100 | [diff] [blame] | 73 | #define celt_ilog2(x) (30 - _lnorm(x)) |
| 74 | #define OVERRIDE_CELT_ILOG2 |
| 75 | |
Jean-Marc Valin | 59f42b5 | 2008-03-21 12:49:36 +1100 | [diff] [blame] | 76 | #define celt_maxabs16(x, len) MAX16(maxval((DATA *)x, len),-minval((DATA *)x, len)) |
Jean-Marc Valin | 9901cb9 | 2008-03-21 11:13:51 +1100 | [diff] [blame] | 77 | #define OVERRIDE_CELT_MAXABS16 |
| 78 | |
Jean-Marc Valin | bfcbd18 | 2008-03-15 08:12:49 +1100 | [diff] [blame] | 79 | #endif /* FIXED_C5X_H */ |