chris@160
|
1 /**
|
chris@160
|
2 * Copyright (c) 2014, 2015, Enzien Audio Ltd.
|
chris@160
|
3 *
|
chris@160
|
4 * Permission to use, copy, modify, and/or distribute this software for any
|
chris@160
|
5 * purpose with or without fee is hereby granted, provided that the above
|
chris@160
|
6 * copyright notice and this permission notice appear in all copies.
|
chris@160
|
7 *
|
chris@160
|
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
chris@160
|
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
chris@160
|
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
chris@160
|
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
chris@160
|
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
chris@160
|
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
chris@160
|
14 * PERFORMANCE OF THIS SOFTWARE.
|
chris@160
|
15 */
|
chris@160
|
16
|
chris@160
|
17 #ifndef _HEAVY_UTILS_MAC_H_
|
chris@160
|
18 #define _HEAVY_UTILS_MAC_H_
|
chris@160
|
19
|
chris@160
|
20 #include "Utils.h"
|
chris@160
|
21
|
chris@160
|
22 #if HV_APPLE
|
chris@160
|
23 #include <alloca.h>
|
chris@160
|
24 #if HV_SIMD_AVX || HV_SIMD_SSE
|
chris@160
|
25 #include <immintrin.h>
|
chris@160
|
26 #include <mm_malloc.h>
|
chris@160
|
27 #elif HV_SIMD_NEON
|
chris@160
|
28 #include <arm_neon.h>
|
chris@160
|
29 #endif
|
chris@160
|
30 #include <assert.h>
|
chris@160
|
31 #include <math.h>
|
chris@160
|
32 #include <stdarg.h>
|
chris@160
|
33 #include <stdbool.h>
|
chris@160
|
34 #include <stdint.h>
|
chris@160
|
35 #include <stdio.h>
|
chris@160
|
36 #include <stdlib.h>
|
chris@160
|
37 #include <string.h>
|
chris@160
|
38
|
chris@160
|
39 #define HV_EXPORT
|
chris@160
|
40 #define HV_FORCE_INLINE inline __attribute__((always_inline))
|
chris@160
|
41
|
chris@160
|
42 // Memory management
|
chris@160
|
43 #define hv_alloca(_n) alloca(_n)
|
chris@160
|
44 #if HV_SIMD_AVX || HV_SIMD_SSE
|
chris@160
|
45 #define hv_malloc(_n) _mm_malloc(_n, 32) // 32 to ensure AVX compatability (16 otherwise)
|
chris@160
|
46 #define hv_free(x) _mm_free(x)
|
chris@160
|
47 #else
|
chris@160
|
48 #define hv_malloc(_n) malloc(_n)
|
chris@160
|
49 #define hv_free(x) free(x)
|
chris@160
|
50 #endif
|
chris@160
|
51 #define hv_realloc(a, b) realloc(a, b)
|
chris@160
|
52 #define hv_memcpy(a, b, c) memcpy(a, b, c)
|
chris@160
|
53 #define hv_memset(a, b) memset(a, 0, b)
|
chris@160
|
54
|
chris@160
|
55 // Strings
|
chris@160
|
56 #define hv_strlen(a) strlen(a)
|
chris@160
|
57 #define hv_strncat(a, b, c) strncat(a, b, c)
|
chris@160
|
58 #define hv_strncpy(a, b, c) strncpy(a, b, c)
|
chris@160
|
59 #define hv_strcmp(a, b) strcmp(a, b)
|
chris@160
|
60 #define hv_strncmp(a, b, c) strncmp(a, b, c)
|
chris@160
|
61 #define hv_snprintf(a, b, c, ...) snprintf(a, b, c, __VA_ARGS__)
|
chris@160
|
62
|
chris@160
|
63 // Math
|
chris@160
|
64 #define hv_max_f(a, b) fmaxf(a, b)
|
chris@160
|
65 #define hv_min_f(a, b) fminf(a, b)
|
chris@160
|
66 #define hv_max_d(a, b) fmax(a, b)
|
chris@160
|
67 #define hv_min_d(a, b) fmin(a, b)
|
chris@160
|
68 #define hv_sin_f(a) sinf(a)
|
chris@160
|
69 #define hv_sinh_f(a) sinhf(a)
|
chris@160
|
70 #define hv_cos_f(a) cosf(a)
|
chris@160
|
71 #define hv_cosh_f(a) coshf(a)
|
chris@160
|
72 #define hv_tan_f(a) tanf(a)
|
chris@160
|
73 #define hv_tanh_f(a) tanhf(a)
|
chris@160
|
74 #define hv_asin_f(a) asinf(a)
|
chris@160
|
75 #define hv_asinh_f(a) asinhf(a)
|
chris@160
|
76 #define hv_acos_f(a) acosf(a)
|
chris@160
|
77 #define hv_acosh_f(a) acoshf(a)
|
chris@160
|
78 #define hv_atan_f(a) atanf(a)
|
chris@160
|
79 #define hv_atanh_f(a) atanhf(a)
|
chris@160
|
80 #define hv_atan2_f(a, b) atan2f(a, b)
|
chris@160
|
81 #define hv_exp_f(a) expf(a)
|
chris@160
|
82 #define hv_abs_f(a) fabsf(a)
|
chris@160
|
83 #define hv_sqrt_f(a) sqrtf(a)
|
chris@160
|
84 #define hv_log_f(a) logf(a)
|
chris@160
|
85 #define hv_log2_f(a) log2f(a)
|
chris@160
|
86 #define hv_log10_f(a) log10f(a)
|
chris@160
|
87 #define hv_ceil_f(a) ceilf(a)
|
chris@160
|
88 #define hv_floor_f(a) floorf(a)
|
chris@160
|
89 #define hv_round_f(a) roundf(a)
|
chris@160
|
90 #define hv_pow_f(a, b) powf(a, b)
|
chris@160
|
91 #define hv_fma_f(a, b, c) ((a*b)+c) // TODO(joe): use 'fmaf(a, b, c)' once emscripten supports it
|
chris@160
|
92
|
chris@160
|
93 // Utilities
|
chris@160
|
94 #define hv_assert(e) assert(e)
|
chris@160
|
95 #define hv_clear_buffer(b, n) memset(b, 0, (n)*sizeof(float))
|
chris@160
|
96
|
chris@160
|
97 #endif // HV_APPLE
|
chris@160
|
98 #endif // _HEAVY_UTILS_MAC_H_
|