Mercurial > hg > beaglert
comparison projects/heavy/circularBuffer/Utils.h @ 163:20b52283c7b4 heavy-updated
- added circular buffer pd/heavy example (works but process needs to be killed manually if launched via ssh?)
author | chnrx <chris.heinrichs@gmail.com> |
---|---|
date | Thu, 12 Nov 2015 15:55:30 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
162:c3e8226a5651 | 163:20b52283c7b4 |
---|---|
1 /** | |
2 * Copyright (c) 2014, 2015, Enzien Audio Ltd. | |
3 * | |
4 * Permission to use, copy, modify, and/or distribute this software for any | |
5 * purpose with or without fee is hereby granted, provided that the above | |
6 * copyright notice and this permission notice appear in all copies. | |
7 * | |
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | |
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | |
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | |
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | |
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | |
14 * PERFORMANCE OF THIS SOFTWARE. | |
15 */ | |
16 | |
17 #ifndef _HEAVY_UTILS_H_ | |
18 #define _HEAVY_UTILS_H_ | |
19 | |
20 // Type definitions | |
21 #if _WIN32 || _WIN64 || WINAPI_FAMILY | |
22 #define HV_WIN 1 | |
23 #include <stddef.h> | |
24 #if defined (_MSC_VER) | |
25 #define HV_MSVC 1 | |
26 #endif | |
27 #define hv_size_t unsigned long | |
28 #define hv_uint32_t unsigned int | |
29 #define hv_uint16_t unsigned short | |
30 #define hv_int32_t int | |
31 #elif __APPLE__ && __MACH__ | |
32 #define HV_APPLE 1 | |
33 #include <stddef.h> | |
34 #define hv_size_t size_t | |
35 #define hv_uint32_t unsigned int | |
36 #define hv_uint16_t unsigned short | |
37 #define hv_int32_t int | |
38 #elif __unix__ || __unix | |
39 #define HV_UNIX 1 | |
40 #include <stddef.h> | |
41 #include <stdint.h> | |
42 #define hv_size_t size_t | |
43 #define hv_uint32_t uint32_t | |
44 #define hv_uint16_t uint16_t | |
45 #define hv_int32_t int32_t | |
46 #else | |
47 #error Unsupported platform | |
48 #endif | |
49 | |
50 // Memory management | |
51 extern void *hv_alloca(hv_size_t numbytes); | |
52 extern void *hv_malloc(hv_size_t numbytes); // allocates memory on 16 byte boundaries and clears it to zero | |
53 extern void hv_free(void *ptr); // frees aligned memory | |
54 extern void *hv_realloc(void *ptr, hv_size_t numBytes); | |
55 extern void *hv_memcpy(void *dest, const void *src, hv_size_t numbytes); | |
56 extern void *hv_memset(void *ptr, hv_size_t numbytes); // sets everything to 0 | |
57 | |
58 // String handling | |
59 extern hv_size_t hv_strlen(const char *str); | |
60 extern char *hv_strncat(char *dest, const char *str, hv_size_t n); | |
61 extern char *hv_strncpy(char *dest, const char *str, hv_size_t n); | |
62 extern int hv_strcmp(const char *str1, const char *str2); | |
63 extern int hv_strncmp(const char *str1, const char *str2, hv_size_t n); | |
64 extern int hv_snprintf(char *dest, hv_size_t n, const char *format, ...); | |
65 | |
66 // Math | |
67 extern int hv_max_i(int x, int y); | |
68 extern hv_size_t hv_max_ui(hv_size_t x, hv_size_t y); | |
69 extern int hv_min_i(int x, int y); | |
70 extern hv_size_t hv_min_ui(hv_size_t x, hv_size_t y); | |
71 extern float hv_max_f(float x, float y); | |
72 extern float hv_min_f(float x, float y); | |
73 extern double hv_max_d(double x, double y); | |
74 extern double hv_min_d(double x, double y); | |
75 extern float hv_sin_f(float x); | |
76 extern float hv_sinh_f(float x); | |
77 extern float hv_cos_f(float x); | |
78 extern float hv_cosh_f(float x); | |
79 extern float hv_tan_f(float x); | |
80 extern float hv_tanh_f(float x); | |
81 extern float hv_asin_f(float x); | |
82 extern float hv_asinh_f(float x); | |
83 extern float hv_acos_f(float x); | |
84 extern float hv_acosh_f(float x); | |
85 extern float hv_atan_f(float x); | |
86 extern float hv_atanh_f(float x); | |
87 extern float hv_atan2_f(float x, float y); | |
88 extern float hv_exp_f(float x); | |
89 extern float hv_abs_f(float x); | |
90 extern float hv_sqrt_f(float x); | |
91 extern float hv_log_f(float x); | |
92 extern float hv_log2_f(float x); | |
93 extern float hv_log10_f(float x); | |
94 extern float hv_ceil_f(float x); | |
95 extern float hv_floor_f(float x); | |
96 extern float hv_round_f(float x); | |
97 extern float hv_pow_f(float x, float y); | |
98 extern float hv_fma_f(float x, float y, float z); | |
99 | |
100 // Utilities | |
101 extern void hv_assert(int e); | |
102 extern void hv_clear_buffer(float *b, int n); | |
103 extern hv_uint32_t hv_min_max_log2(hv_uint32_t x); | |
104 | |
105 // SIMD | |
106 #ifndef HV_SIMD_NONE | |
107 #define HV_SIMD_NEON __ARM_NEON__ | |
108 #define HV_SIMD_SSE (__SSE__ && __SSE2__ && __SSE3__ && __SSSE3__ && __SSE4_1__) | |
109 #define HV_SIMD_AVX (__AVX__ && HV_SIMD_SSE) // it is required that if AVX exists then SSE will also be available | |
110 #define HV_SIMD_FMA __FMA__ | |
111 #endif | |
112 | |
113 #ifdef HV_WIN | |
114 #include "Utils_windows.h" | |
115 #elif HV_APPLE | |
116 #include "Utils_mac.h" | |
117 #elif HV_UNIX | |
118 #include "Utils_unix.h" | |
119 #else | |
120 #error Unsupported platform | |
121 #endif | |
122 | |
123 #if HV_SIMD_NEON // NEON | |
124 #define HV_N_SIMD 4 | |
125 #define hv_bufferf_t float32x4_t | |
126 #define hv_bufferi_t int32x4_t | |
127 #define hv_bInf_t float32x4_t | |
128 #define hv_bOutf_t float32x4_t* | |
129 #define hv_bIni_t int32x4_t | |
130 #define hv_bOuti_t int32x4_t* | |
131 #define VIf(_x) (_x) | |
132 #define VOf(_x) (&_x) | |
133 #define VIi(_x) (_x) | |
134 #define VOi(_x) (&_x) | |
135 #elif HV_SIMD_AVX // AVX | |
136 #define HV_N_SIMD 8 | |
137 #define hv_bufferf_t __m256 | |
138 #define hv_bufferi_t __m256i | |
139 #define hv_bInf_t __m256 | |
140 #define hv_bOutf_t __m256* | |
141 #define hv_bIni_t __m256i | |
142 #define hv_bOuti_t __m256i* | |
143 #define VIf(_x) (_x) | |
144 #define VOf(_x) (&_x) | |
145 #define VIi(_x) (_x) | |
146 #define VOi(_x) (&_x) | |
147 #elif HV_SIMD_SSE // SSE | |
148 #define HV_N_SIMD 4 | |
149 #define hv_bufferf_t __m128 | |
150 #define hv_bufferi_t __m128i | |
151 #define hv_bInf_t __m128 | |
152 #define hv_bOutf_t __m128* | |
153 #define hv_bIni_t __m128i | |
154 #define hv_bOuti_t __m128i* | |
155 #define VIf(_x) (_x) | |
156 #define VOf(_x) (&_x) | |
157 #define VIi(_x) (_x) | |
158 #define VOi(_x) (&_x) | |
159 #else // DEFAULT | |
160 #define HV_N_SIMD 1 | |
161 #undef HV_SIMD_NONE | |
162 #define HV_SIMD_NONE 1 | |
163 #define hv_bufferf_t float | |
164 #define hv_bufferi_t int | |
165 #define hv_bInf_t float | |
166 #define hv_bOutf_t float* | |
167 #define hv_bIni_t int | |
168 #define hv_bOuti_t int* | |
169 #define VIf(_x) (_x) | |
170 #define VOf(_x) (&_x) | |
171 #define VIi(_x) (_x) | |
172 #define VOi(_x) (&_x) | |
173 #endif | |
174 | |
175 #define HV_N_SIMD_MASK (HV_N_SIMD-1) | |
176 | |
177 #endif // _HEAVY_UTILS_H_ |