chris@160: /** chris@160: * Copyright (c) 2014, 2015, Enzien Audio Ltd. chris@160: * chris@160: * Permission to use, copy, modify, and/or distribute this software for any chris@160: * purpose with or without fee is hereby granted, provided that the above chris@160: * copyright notice and this permission notice appear in all copies. chris@160: * chris@160: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH chris@160: * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY chris@160: * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, chris@160: * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM chris@160: * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR chris@160: * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR chris@160: * PERFORMANCE OF THIS SOFTWARE. chris@160: */ chris@160: chris@160: #ifndef _HEAVY_UTILS_UNIX_H_ chris@160: #define _HEAVY_UTILS_UNIX_H_ chris@160: chris@160: #include "Utils.h" chris@160: chris@160: #if HV_UNIX chris@160: #if HV_SIMD_AVX || HV_SIMD_SSE chris@160: #include chris@160: #include chris@160: #elif HV_SIMD_NEON chris@160: #include chris@160: #endif chris@160: #include chris@160: #include chris@160: #include chris@160: #include chris@160: #include chris@160: #include chris@160: #include chris@160: #include chris@160: #include chris@160: chris@160: #define HV_EXPORT chris@160: #define HV_FORCE_INLINE inline __attribute__((always_inline)) chris@160: chris@160: // Memory management chris@160: #define hv_alloca(_n) alloca(_n) chris@160: #if HV_SIMD_AVX || HV_SIMD_SSE chris@160: #define hv_malloc(_n) _mm_malloc(_n, 32) // 32 to ensure AVX compatability (16 otherwise) chris@160: #define hv_free(x) _mm_free(x) chris@160: #else chris@160: #define hv_malloc(_n) malloc(_n) chris@160: #define hv_free(_n) free(_n) chris@160: #endif chris@160: #define hv_realloc(a, b) realloc(a, b) chris@160: #define hv_memcpy(a, b, c) memcpy(a, b, c) chris@160: #define hv_memset(a, b) memset(a, 0, b) chris@160: chris@160: // Strings chris@160: #define hv_strlen(a) strlen(a) chris@160: #define hv_strncat(a, b, c) strncat(a, b, c) chris@160: #define hv_strncpy(a, b, c) strncpy(a, b, c) chris@160: #define hv_strcmp(a, b) strcmp(a, b) chris@160: #define hv_strncmp(a, b, c) strncmp(a, b, c) chris@160: #define hv_snprintf(a, b, c, ...) snprintf(a, b, c, __VA_ARGS__) chris@160: chris@160: // Math chris@160: #define hv_max_f(a, b) fmaxf(a, b) chris@160: #define hv_min_f(a, b) fminf(a, b) chris@160: #define hv_max_d(a, b) fmax(a, b) chris@160: #define hv_min_d(a, b) fmin(a, b) chris@160: #define hv_sin_f(a) sinf(a) chris@160: #define hv_sinh_f(a) sinhf(a) chris@160: #define hv_cos_f(a) cosf(a) chris@160: #define hv_cosh_f(a) coshf(a) chris@160: #define hv_tan_f(a) tanf(a) chris@160: #define hv_tanh_f(a) tanhf(a) chris@160: #define hv_asin_f(a) asinf(a) chris@160: #define hv_asinh_f(a) asinhf(a) chris@160: #define hv_acos_f(a) acosf(a) chris@160: #define hv_acosh_f(a) acoshf(a) chris@160: #define hv_atan_f(a) atanf(a) chris@160: #define hv_atanh_f(a) atanhf(a) chris@160: #define hv_atan2_f(a, b) atan2f(a, b) chris@160: #define hv_exp_f(a) expf(a) chris@160: #define hv_abs_f(a) fabsf(a) chris@160: #define hv_sqrt_f(a) sqrtf(a) chris@160: #define hv_log_f(a) logf(a) chris@160: #define hv_log2_f(a) log2f(a) chris@160: #define hv_log10_f(a) log10f(a) chris@160: #define hv_ceil_f(a) ceilf(a) chris@160: #define hv_floor_f(a) floorf(a) chris@160: #define hv_round_f(a) roundf(a) chris@160: #define hv_pow_f(a, b) powf(a, b) chris@160: #define hv_fma_f(a, b, c) ((a*b)+c) // TODO(joe): use 'fmaf(a, b, c)' once emscripten supports it chris@160: chris@160: // Utilities chris@160: #define hv_assert(e) assert(e) chris@160: #define hv_clear_buffer(b, n) memset(b, 0, n*sizeof(float)) chris@160: chris@160: #endif // HV_UNIX chris@160: #endif // _HEAVY_UTILS_UNIX_H_