Generate the dispatch header which contains the #definitions and headers for platform-specific instruction-sets for the enabled CPU baseline and dispatch-able features. Its highly recommended to take a look at the generated header also the generated source f
(self, header_path)
| 2354 | return objects |
| 2355 | |
| 2356 | def generate_dispatch_header(self, header_path): |
| 2357 | """ |
| 2358 | Generate the dispatch header which contains the #definitions and headers |
| 2359 | for platform-specific instruction-sets for the enabled CPU baseline and |
| 2360 | dispatch-able features. |
| 2361 | |
| 2362 | Its highly recommended to take a look at the generated header |
| 2363 | also the generated source files via `try_dispatch()` |
| 2364 | in order to get the full picture. |
| 2365 | """ |
| 2366 | self.dist_log("generate CPU dispatch header: (%s)" % header_path) |
| 2367 | |
| 2368 | baseline_names = self.cpu_baseline_names() |
| 2369 | dispatch_names = self.cpu_dispatch_names() |
| 2370 | baseline_len = len(baseline_names) |
| 2371 | dispatch_len = len(dispatch_names) |
| 2372 | |
| 2373 | header_dir = os.path.dirname(header_path) |
| 2374 | if not os.path.exists(header_dir): |
| 2375 | self.dist_log( |
| 2376 | f"dispatch header dir {header_dir} does not exist, creating it", |
| 2377 | stderr=True |
| 2378 | ) |
| 2379 | os.makedirs(header_dir) |
| 2380 | |
| 2381 | with open(header_path, 'w') as f: |
| 2382 | baseline_calls = ' \\\n'.join([ |
| 2383 | ( |
| 2384 | "\t%sWITH_CPU_EXPAND_(MACRO_TO_CALL(%s, __VA_ARGS__))" |
| 2385 | ) % (self.conf_c_prefix, f) |
| 2386 | for f in baseline_names |
| 2387 | ]) |
| 2388 | dispatch_calls = ' \\\n'.join([ |
| 2389 | ( |
| 2390 | "\t%sWITH_CPU_EXPAND_(MACRO_TO_CALL(%s, __VA_ARGS__))" |
| 2391 | ) % (self.conf_c_prefix, f) |
| 2392 | for f in dispatch_names |
| 2393 | ]) |
| 2394 | f.write(textwrap.dedent("""\ |
| 2395 | /* |
| 2396 | * AUTOGENERATED DON'T EDIT |
| 2397 | * Please make changes to the code generator (distutils/ccompiler_opt.py) |
| 2398 | */ |
| 2399 | #define {pfx}WITH_CPU_BASELINE "{baseline_str}" |
| 2400 | #define {pfx}WITH_CPU_DISPATCH "{dispatch_str}" |
| 2401 | #define {pfx}WITH_CPU_BASELINE_N {baseline_len} |
| 2402 | #define {pfx}WITH_CPU_DISPATCH_N {dispatch_len} |
| 2403 | #define {pfx}WITH_CPU_EXPAND_(X) X |
| 2404 | #define {pfx}WITH_CPU_BASELINE_CALL(MACRO_TO_CALL, ...) \\ |
| 2405 | {baseline_calls} |
| 2406 | #define {pfx}WITH_CPU_DISPATCH_CALL(MACRO_TO_CALL, ...) \\ |
| 2407 | {dispatch_calls} |
| 2408 | """).format( |
| 2409 | pfx=self.conf_c_prefix, baseline_str=" ".join(baseline_names), |
| 2410 | dispatch_str=" ".join(dispatch_names), baseline_len=baseline_len, |
| 2411 | dispatch_len=dispatch_len, baseline_calls=baseline_calls, |
| 2412 | dispatch_calls=dispatch_calls |
| 2413 | )) |
no test coverage detected