asmjitutils.h (7225B)
1 // This file is part of AsmJit project <https://asmjit.com> 2 // 3 // See <asmjit/core.h> or LICENSE.md for license and copyright information 4 // SPDX-License-Identifier: Zlib 5 6 #ifndef ASMJITUTILS_H_INCLUDED 7 #define ASMJITUTILS_H_INCLUDED 8 9 #include <asmjit/core.h> 10 11 namespace { 12 13 [[maybe_unused]] 14 static const char* asmjit_build_type() noexcept { 15 #if defined(ASMJIT_BUILD_DEBUG) 16 static const char build_type[] = "Debug"; 17 #else 18 static const char build_type[] = "Release"; 19 #endif 20 return build_type; 21 } 22 23 [[maybe_unused]] 24 static const char* asmjit_arch_as_string(asmjit::Arch arch) noexcept { 25 switch (arch) { 26 case asmjit::Arch::kX86 : return "X86"; 27 case asmjit::Arch::kX64 : return "X64"; 28 29 case asmjit::Arch::kRISCV32 : return "RISCV32"; 30 case asmjit::Arch::kRISCV64 : return "RISCV64"; 31 32 case asmjit::Arch::kARM : return "ARM"; 33 case asmjit::Arch::kAArch64 : return "AArch64"; 34 case asmjit::Arch::kThumb : return "Thumb"; 35 36 case asmjit::Arch::kMIPS32_LE : return "MIPS_LE"; 37 case asmjit::Arch::kMIPS64_LE : return "MIPS64_LE"; 38 39 case asmjit::Arch::kARM_BE : return "ARM_BE"; 40 case asmjit::Arch::kThumb_BE : return "Thumb_BE"; 41 case asmjit::Arch::kAArch64_BE: return "AArch64_BE"; 42 43 case asmjit::Arch::kMIPS32_BE : return "MIPS_BE"; 44 case asmjit::Arch::kMIPS64_BE : return "MIPS64_BE"; 45 46 default: 47 return "<Unknown>"; 48 } 49 } 50 51 [[maybe_unused]] 52 static void print_indented(const char* str, size_t indent) noexcept { 53 const char* start = str; 54 while (*str) { 55 if (*str == '\n') { 56 size_t size = (size_t)(str - start); 57 printf("%*s%.*s\n", size ? int(indent) : 0, "", int(size), start); 58 start = str + 1; 59 } 60 str++; 61 } 62 63 size_t size = (size_t)(str - start); 64 if (size) 65 printf("%*s%.*s\n", int(indent), "", int(size), start); 66 } 67 68 [[maybe_unused]] 69 static void print_cpu_info() noexcept { 70 const asmjit::CpuInfo& cpu = asmjit::CpuInfo::host(); 71 72 // CPU Information 73 // --------------- 74 75 printf("CPU Info:\n"); 76 printf(" Vendor : %s\n", cpu.vendor()); 77 printf(" Brand : %s\n", cpu.brand()); 78 printf(" Model ID : 0x%08X (%u)\n", cpu.model_id(), cpu.model_id()); 79 printf(" Brand ID : 0x%08X (%u)\n", cpu.brand_id(), cpu.brand_id()); 80 printf(" Family ID : 0x%08X (%u)\n", cpu.family_id(), cpu.family_id()); 81 printf(" Stepping : %u\n", cpu.stepping()); 82 printf(" Processor Type : %u\n", cpu.processor_type()); 83 printf(" Max logical Processors : %u\n", cpu.max_logical_processors()); 84 printf(" Cache-Line Size : %u\n", cpu.cache_line_size()); 85 printf(" HW-Thread Count : %u\n", cpu.hw_thread_count()); 86 printf("\n"); 87 88 // CPU Features 89 // ------------ 90 91 using asmjit::CpuHints; 92 93 #ifndef ASMJIT_NO_LOGGING 94 printf("CPU Features:\n"); 95 asmjit::CpuFeatures::Iterator it(cpu.features().iterator()); 96 while (it.has_next()) { 97 uint32_t feature_id = uint32_t(it.next()); 98 asmjit::StringTmp<64> feature_string; 99 asmjit::Formatter::format_feature(feature_string, cpu.arch(), feature_id); 100 printf(" %s\n", feature_string.data()); 101 }; 102 printf("\n"); 103 #endif // !ASMJIT_NO_LOGGING 104 105 // CPU Hints 106 // --------- 107 108 printf("CPU Hints:\n"); 109 auto print_hint = [&](CpuHints hint, const char* name) { 110 if ((cpu.hints() & hint) != CpuHints::kNone) { 111 printf(" %s\n", name); 112 } 113 }; 114 115 print_hint(CpuHints::kVecMaskedOps8 , "VecMaskedOps8" ); 116 print_hint(CpuHints::kVecMaskedOps16 , "VecMaskedOps16" ); 117 print_hint(CpuHints::kVecMaskedOps32 , "VecMaskedOps32" ); 118 print_hint(CpuHints::kVecMaskedOps64 , "VecMaskedOps64" ); 119 print_hint(CpuHints::kVecFastIntMul32, "VecFastIntMul32"); 120 print_hint(CpuHints::kVecFastIntMul64, "VecFastIntMul64"); 121 print_hint(CpuHints::kVecFastGather , "VecFastGather" ); 122 print_hint(CpuHints::kVecMaskedStore , "VecMaskedStore" ); 123 124 printf("\n"); 125 } 126 127 [[maybe_unused]] 128 static void print_build_options() { 129 auto stringify_build_definition = [](bool b) { return b ? "defined" : "(not defined)"; }; 130 131 #if defined(ASMJIT_NO_X86) 132 constexpr bool no_x86 = true; 133 #else 134 constexpr bool no_x86 = false; 135 #endif 136 137 #if defined(ASMJIT_NO_AARCH64) 138 constexpr bool no_aarch64 = true; 139 #else 140 constexpr bool no_aarch64 = false; 141 #endif 142 143 #if defined(ASMJIT_NO_FOREIGN) 144 constexpr bool no_foreign = true; 145 #else 146 constexpr bool no_foreign = false; 147 #endif 148 149 #if defined(ASMJIT_NO_DEPRECATED) 150 constexpr bool no_deprecated = true; 151 #else 152 constexpr bool no_deprecated = false; 153 #endif 154 155 #if defined(ASMJIT_NO_ABI_NAMESPACE) 156 constexpr bool no_abi_namespace = true; 157 #else 158 constexpr bool no_abi_namespace = false; 159 #endif 160 161 #if defined(ASMJIT_NO_SHM_OPEN) 162 constexpr bool no_shm_open = true; 163 #else 164 constexpr bool no_shm_open = false; 165 #endif 166 167 #if defined(ASMJIT_NO_JIT) 168 constexpr bool no_jit = true; 169 #else 170 constexpr bool no_jit = false; 171 #endif 172 173 #if defined(ASMJIT_NO_TEXT) 174 constexpr bool no_text = true; 175 #else 176 constexpr bool no_text = false; 177 #endif 178 179 #if defined(ASMJIT_NO_LOGGING) 180 constexpr bool no_logging = true; 181 #else 182 constexpr bool no_logging = false; 183 #endif 184 185 #if defined(ASMJIT_NO_VALIDATION) 186 constexpr bool no_validation = true; 187 #else 188 constexpr bool no_validation = false; 189 #endif 190 191 #if defined(ASMJIT_NO_INTROSPECTION) 192 constexpr bool no_introspection = true; 193 #else 194 constexpr bool no_introspection = false; 195 #endif 196 197 #if defined(ASMJIT_NO_BUILDER) 198 constexpr bool no_builder = true; 199 #else 200 constexpr bool no_builder = false; 201 #endif 202 203 #if defined(ASMJIT_NO_COMPILER) 204 constexpr bool no_compiler = true; 205 #else 206 constexpr bool no_compiler = false; 207 #endif 208 209 #if defined(ASMJIT_NO_UJIT) 210 constexpr bool no_ujit = true; 211 #else 212 constexpr bool no_ujit = false; 213 #endif 214 215 printf("Build Options:\n"); 216 printf(" BUILD_TYPE : %s\n", asmjit_build_type()); 217 printf(" ASMJIT_NO_DEPRECATED : %s\n", stringify_build_definition(no_deprecated)); 218 printf(" ASMJIT_NO_ABI_NAMESPACE: %s\n", stringify_build_definition(no_abi_namespace)); 219 printf("\n"); 220 221 printf("Build Backends:\n"); 222 printf(" ASMJIT_NO_X86 : %s\n", stringify_build_definition(no_x86)); 223 printf(" ASMJIT_NO_AARCH64 : %s\n", stringify_build_definition(no_aarch64)); 224 printf(" ASMJIT_NO_FOREIGN : %s\n", stringify_build_definition(no_foreign)); 225 printf("\n"); 226 227 printf("Build Features:\n"); 228 printf(" ASMJIT_NO_SHM_OPEN : %s\n", stringify_build_definition(no_shm_open)); 229 printf(" ASMJIT_NO_JIT : %s\n", stringify_build_definition(no_jit)); 230 printf(" ASMJIT_NO_TEXT : %s\n", stringify_build_definition(no_text)); 231 printf(" ASMJIT_NO_LOGGING : %s\n", stringify_build_definition(no_logging)); 232 printf(" ASMJIT_NO_VALIDATION : %s\n", stringify_build_definition(no_validation)); 233 printf(" ASMJIT_NO_INTROSPECTION: %s\n", stringify_build_definition(no_introspection)); 234 printf(" ASMJIT_NO_BUILDER : %s\n", stringify_build_definition(no_builder)); 235 printf(" ASMJIT_NO_COMPILER : %s\n", stringify_build_definition(no_compiler)); 236 printf(" ASMJIT_NO_UJIT : %s\n", stringify_build_definition(no_ujit)); 237 printf("\n"); 238 } 239 240 } // {anonymous} 241 242 #endif // ASMJITUTILS_H_INCLUDED