comparison projects/heavy/hello-world/Utils_unix.h @ 160:5bcf04234f80 heavy-updated

- added -std=c99 to Makefile for user-supplied C files (required for heavy files) - changed heavy core render.cpp file to use latest API and removed all redundant functions (e.g. foleyDesigner/touchkey stuff) - use build_pd.sh to compile and run pd files (-h for usage instructions)
author chnrx <chris.heinrichs@gmail.com>
date Thu, 05 Nov 2015 18:58:26 +0000
parents
children
comparison
equal deleted inserted replaced
159:1e7db6610600 160:5bcf04234f80
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_UNIX_H_
18 #define _HEAVY_UTILS_UNIX_H_
19
20 #include "Utils.h"
21
22 #if HV_UNIX
23 #if HV_SIMD_AVX || HV_SIMD_SSE
24 #include <immintrin.h>
25 #include <mm_malloc.h>
26 #elif HV_SIMD_NEON
27 #include <arm_neon.h>
28 #endif
29 #include <alloca.h>
30 #include <assert.h>
31 #include <math.h>
32 #include <stdarg.h>
33 #include <stdbool.h>
34 #include <stdint.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 #define HV_EXPORT
40 #define HV_FORCE_INLINE inline __attribute__((always_inline))
41
42 // Memory management
43 #define hv_alloca(_n) alloca(_n)
44 #if HV_SIMD_AVX || HV_SIMD_SSE
45 #define hv_malloc(_n) _mm_malloc(_n, 32) // 32 to ensure AVX compatability (16 otherwise)
46 #define hv_free(x) _mm_free(x)
47 #else
48 #define hv_malloc(_n) malloc(_n)
49 #define hv_free(_n) free(_n)
50 #endif
51 #define hv_realloc(a, b) realloc(a, b)
52 #define hv_memcpy(a, b, c) memcpy(a, b, c)
53 #define hv_memset(a, b) memset(a, 0, b)
54
55 // Strings
56 #define hv_strlen(a) strlen(a)
57 #define hv_strncat(a, b, c) strncat(a, b, c)
58 #define hv_strncpy(a, b, c) strncpy(a, b, c)
59 #define hv_strcmp(a, b) strcmp(a, b)
60 #define hv_strncmp(a, b, c) strncmp(a, b, c)
61 #define hv_snprintf(a, b, c, ...) snprintf(a, b, c, __VA_ARGS__)
62
63 // Math
64 #define hv_max_f(a, b) fmaxf(a, b)
65 #define hv_min_f(a, b) fminf(a, b)
66 #define hv_max_d(a, b) fmax(a, b)
67 #define hv_min_d(a, b) fmin(a, b)
68 #define hv_sin_f(a) sinf(a)
69 #define hv_sinh_f(a) sinhf(a)
70 #define hv_cos_f(a) cosf(a)
71 #define hv_cosh_f(a) coshf(a)
72 #define hv_tan_f(a) tanf(a)
73 #define hv_tanh_f(a) tanhf(a)
74 #define hv_asin_f(a) asinf(a)
75 #define hv_asinh_f(a) asinhf(a)
76 #define hv_acos_f(a) acosf(a)
77 #define hv_acosh_f(a) acoshf(a)
78 #define hv_atan_f(a) atanf(a)
79 #define hv_atanh_f(a) atanhf(a)
80 #define hv_atan2_f(a, b) atan2f(a, b)
81 #define hv_exp_f(a) expf(a)
82 #define hv_abs_f(a) fabsf(a)
83 #define hv_sqrt_f(a) sqrtf(a)
84 #define hv_log_f(a) logf(a)
85 #define hv_log2_f(a) log2f(a)
86 #define hv_log10_f(a) log10f(a)
87 #define hv_ceil_f(a) ceilf(a)
88 #define hv_floor_f(a) floorf(a)
89 #define hv_round_f(a) roundf(a)
90 #define hv_pow_f(a, b) powf(a, b)
91 #define hv_fma_f(a, b, c) ((a*b)+c) // TODO(joe): use 'fmaf(a, b, c)' once emscripten supports it
92
93 // Utilities
94 #define hv_assert(e) assert(e)
95 #define hv_clear_buffer(b, n) memset(b, 0, n*sizeof(float))
96
97 #endif // HV_UNIX
98 #endif // _HEAVY_UTILS_UNIX_H_