Generate C preprocessor definitions and include headers of a CPU feature. Parameters ---------- 'feature_name': str CPU feature name in uppercase. 'tabs': int if > 0, align the generated strings to the right depend on number of tabs.
(self, feature_name, tabs=0)
| 1660 | |
| 1661 | |
| 1662 | def feature_c_preprocessor(self, feature_name, tabs=0): |
| 1663 | """ |
| 1664 | Generate C preprocessor definitions and include headers of a CPU feature. |
| 1665 | |
| 1666 | Parameters |
| 1667 | ---------- |
| 1668 | 'feature_name': str |
| 1669 | CPU feature name in uppercase. |
| 1670 | 'tabs': int |
| 1671 | if > 0, align the generated strings to the right depend on number of tabs. |
| 1672 | |
| 1673 | Returns |
| 1674 | ------- |
| 1675 | str, generated C preprocessor |
| 1676 | |
| 1677 | Examples |
| 1678 | -------- |
| 1679 | >>> self.feature_c_preprocessor("SSE3") |
| 1680 | /** SSE3 **/ |
| 1681 | #define NPY_HAVE_SSE3 1 |
| 1682 | #include <pmmintrin.h> |
| 1683 | """ |
| 1684 | assert(feature_name.isupper()) |
| 1685 | feature = self.feature_supported.get(feature_name) |
| 1686 | assert(feature is not None) |
| 1687 | |
| 1688 | prepr = [ |
| 1689 | "/** %s **/" % feature_name, |
| 1690 | "#define %sHAVE_%s 1" % (self.conf_c_prefix, feature_name) |
| 1691 | ] |
| 1692 | prepr += [ |
| 1693 | "#include <%s>" % h for h in feature.get("headers", []) |
| 1694 | ] |
| 1695 | |
| 1696 | extra_defs = feature.get("group", []) |
| 1697 | extra_defs += self.feature_extra_checks(feature_name) |
| 1698 | for edef in extra_defs: |
| 1699 | # Guard extra definitions in case of duplicate with |
| 1700 | # another feature |
| 1701 | prepr += [ |
| 1702 | "#ifndef %sHAVE_%s" % (self.conf_c_prefix, edef), |
| 1703 | "\t#define %sHAVE_%s 1" % (self.conf_c_prefix, edef), |
| 1704 | "#endif", |
| 1705 | ] |
| 1706 | |
| 1707 | if tabs > 0: |
| 1708 | prepr = [('\t'*tabs) + l for l in prepr] |
| 1709 | return '\n'.join(prepr) |
| 1710 | |
| 1711 | class _Parse: |
| 1712 | """A helper class that parsing main arguments of `CCompilerOpt`, |
no test coverage detected