| andrewm@379 | 1 /* | 
| andrewm@379 | 2  *  Copyright 2013-15 ARM Limited and Contributors. | 
| andrewm@379 | 3  *  All rights reserved. | 
| andrewm@379 | 4  * | 
| andrewm@379 | 5  *  Redistribution and use in source and binary forms, with or without | 
| andrewm@379 | 6  *  modification, are permitted provided that the following conditions are met: | 
| andrewm@379 | 7  *    * Redistributions of source code must retain the above copyright | 
| andrewm@379 | 8  *      notice, this list of conditions and the following disclaimer. | 
| andrewm@379 | 9  *    * Redistributions in binary form must reproduce the above copyright | 
| andrewm@379 | 10  *      notice, this list of conditions and the following disclaimer in the | 
| andrewm@379 | 11  *      documentation and/or other materials provided with the distribution. | 
| andrewm@379 | 12  *    * Neither the name of ARM Limited nor the | 
| andrewm@379 | 13  *      names of its contributors may be used to endorse or promote products | 
| andrewm@379 | 14  *      derived from this software without specific prior written permission. | 
| andrewm@379 | 15  * | 
| andrewm@379 | 16  *  THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND | 
| andrewm@379 | 17  *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 
| andrewm@379 | 18  *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
| andrewm@379 | 19  *  DISCLAIMED. IN NO EVENT SHALL ARM LIMITED AND CONTRIBUTORS BE LIABLE FOR ANY | 
| andrewm@379 | 20  *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 
| andrewm@379 | 21  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 
| andrewm@379 | 22  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 
| andrewm@379 | 23  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| andrewm@379 | 24  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 
| andrewm@379 | 25  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| andrewm@379 | 26  */ | 
| andrewm@379 | 27 | 
| andrewm@379 | 28 /* | 
| andrewm@379 | 29  * NE10 Library : inc/NE10_macros.h | 
| andrewm@379 | 30  */ | 
| andrewm@379 | 31 | 
| andrewm@379 | 32 /** NE10 defines a number of macros for use in its function signatures. | 
| andrewm@379 | 33  *  The macros are defined within this header file. | 
| andrewm@379 | 34  */ | 
| andrewm@379 | 35 | 
| andrewm@379 | 36 #ifndef NE10_MACROS_H | 
| andrewm@379 | 37 #define NE10_MACROS_H | 
| andrewm@379 | 38 | 
| andrewm@379 | 39 #ifdef __cplusplus | 
| andrewm@379 | 40 extern "C" { | 
| andrewm@379 | 41 #endif | 
| andrewm@379 | 42 | 
| andrewm@379 | 43 ///////////////////////////////////////////////////////// | 
| andrewm@379 | 44 // constant values that are used across the library | 
| andrewm@379 | 45 ///////////////////////////////////////////////////////// | 
| andrewm@379 | 46 | 
| andrewm@379 | 47 #define NE10_PI (ne10_float32_t)(3.1415926535897932384626433832795) | 
| andrewm@379 | 48 | 
| andrewm@379 | 49 ///////////////////////////////////////////////////////// | 
| andrewm@379 | 50 // some external macro definitions to be exposed to the users | 
| andrewm@379 | 51 ///////////////////////////////////////////////////////// | 
| andrewm@379 | 52 | 
| andrewm@379 | 53 #define NE10_MALLOC malloc | 
| andrewm@379 | 54 #define NE10_FREE(p) \ | 
| andrewm@379 | 55     do { \ | 
| andrewm@379 | 56         free(p); \ | 
| andrewm@379 | 57         p = NULL; \ | 
| andrewm@379 | 58     }while(0) | 
| andrewm@379 | 59 | 
| andrewm@379 | 60 #define NE10_MIN(a,b) ((a)>(b)?(b):(a)) | 
| andrewm@379 | 61 #define NE10_MAX(a,b) ((a)<(b)?(b):(a)) | 
| andrewm@379 | 62 | 
| andrewm@379 | 63 #define NE10_BYTE_ALIGNMENT(address, alignment) \ | 
| andrewm@379 | 64     do { \ | 
| andrewm@379 | 65         (address) = (((address) + ((alignment) - 1)) & ~ ((alignment) - 1)); \ | 
| andrewm@379 | 66     }while (0) | 
| andrewm@379 | 67 | 
| andrewm@379 | 68 ///////////////////////////////////////////////////////// | 
| andrewm@379 | 69 // macro definitions for float to fixed point | 
| andrewm@379 | 70 ///////////////////////////////////////////////////////// | 
| andrewm@379 | 71 #define NE10_F2I16_MAX         32767 | 
| andrewm@379 | 72 #define NE10_F2I16_SHIFT       15 | 
| andrewm@379 | 73 #define NE10_F2I16_SAMPPROD    ne10_int32_t | 
| andrewm@379 | 74 #define NE10_F2I16_OP(x)       (ne10_int16_t)((x)*NE10_F2I16_MAX + 0.5f) | 
| andrewm@379 | 75 #define NE10_F2I16_SROUND(x)   (ne10_int16_t)((((x)<<1)+(1<<NE10_F2I16_SHIFT))>>16) | 
| andrewm@379 | 76 #define NE10_F2I16_SMUL(a,b)   ((NE10_F2I16_SAMPPROD)(a)*(b)) | 
| andrewm@379 | 77 #define NE10_F2I16_FIXDIV(c,div) \ | 
| andrewm@379 | 78     do {    ((c).r) = ( ( ((c).r)/div) );  \ | 
| andrewm@379 | 79         ((c).i) = ( ( ((c).i)/div) ); }while (0) | 
| andrewm@379 | 80 | 
| andrewm@379 | 81 #define NE10_F2I32_MAX         2147483647 | 
| andrewm@379 | 82 #define NE10_F2I32_SHIFT       31 | 
| andrewm@379 | 83 #define NE10_F2I32_SAMPPROD    ne10_int64_t | 
| andrewm@379 | 84 #define NE10_F2I32_OP(x)       (ne10_int32_t)((x)*NE10_F2I32_MAX + 0.5f) | 
| andrewm@379 | 85 #define NE10_F2I32_SROUND(x)   (ne10_int32_t) ((x)>>NE10_F2I32_SHIFT) | 
| andrewm@379 | 86 #define NE10_F2I32_SMUL(a,b)    ((NE10_F2I32_SAMPPROD)(a)*(b)) | 
| andrewm@379 | 87 #define NE10_F2I32_FIXDIV(c,div) \ | 
| andrewm@379 | 88     do {    ((c).r) = ( ( ((c).r)/div) );  \ | 
| andrewm@379 | 89         ((c).i) = ( ( ((c).i)/div) ); }while (0) | 
| andrewm@379 | 90 | 
| andrewm@379 | 91 #ifdef __cplusplus | 
| andrewm@379 | 92 } | 
| andrewm@379 | 93 #endif | 
| andrewm@379 | 94 | 
| andrewm@379 | 95 #endif |