/* * Copyright (c) 2014 Rob Clark * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef UTIL_H_ #define UTIL_H_ #include #include #include #include #include #include #include #include #define MAX_REGS 256 void ir3_emu_run(void *instrs, uint32_t instrs_count, float *consts, uint32_t consts_size, float *regs, uint32_t regs_size, uint32_t half_regs_count); #define ALIGN(v,a) (((v) + (a) - 1) & ~((a) - 1)) #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) #define enable_debug 0 #define INFO_MSG(fmt, ...) \ do { printf("[I] "fmt " (%s:%d)\n", \ ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0) #define DEBUG_MSG(fmt, ...) \ do if (enable_debug) { printf("[D] "fmt " (%s:%d)\n", \ ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0) #define WARN_MSG(fmt, ...) \ do { printf("[W] "fmt " (%s:%d)\n", \ ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0) #define ERROR_MSG(fmt, ...) \ do { printf("[E] " fmt " (%s:%d)\n", \ ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0) /** * Return float bits. */ static inline uint32_t fui(float f) { union { float f; uint32_t ui; } fi; fi.f = f; return fi.ui; } static inline float uif(uint32_t ui) { union { float f; uint32_t ui; } fi; fi.ui = ui; return fi.f; } #endif /* UTIL_H_ */