Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return
else:
log.info("building '%s' extension", ext.name)
capabilities = CCompilerCapabilities(self.compiler)
pybase64_write_config(capabilities)
objects = list()
for simd_opt in (CCompilerCapabilities.SIMD_SSSE3,
CCompilerCapabilities.SIMD_SSE41,
CCompilerCapabilities.SIMD_SSE42,
CCompilerCapabilities.SIMD_AVX,
CCompilerCapabilities.SIMD_AVX2,
CCompilerCapabilities.SIMD_NEON32,
CCompilerCapabilities.SIMD_NEON64):
if len(simd_sources[simd_opt]) == 0:
continue
if capabilities.has(simd_opt):
objects = objects + self.compiler.compile(
simd_sources[simd_opt],
output_dir=self.build_temp,
include_dirs=ext.include_dirs,
debug=self.debug,
extra_postargs=capabilities.flags(simd_opt),
depends=ext.depends)
else:
sources = sources + simd_sources[simd_opt]
objects = objects + self.compiler.compile(
sources,
output_dir=self.build_temp,
if not (self.force or newer_group(depends, ext_path, 'newer')):
log.debug("skipping '%s' extension (up-to-date)", ext.name)
return
else:
log.info("building '%s' extension", ext.name)
capabilities = CCompilerCapabilities(self.compiler)
pybase64_write_config(capabilities)
objects = list()
for simd_opt in (CCompilerCapabilities.SIMD_SSSE3,
CCompilerCapabilities.SIMD_SSE41,
CCompilerCapabilities.SIMD_SSE42,
CCompilerCapabilities.SIMD_AVX,
CCompilerCapabilities.SIMD_AVX2,
CCompilerCapabilities.SIMD_NEON32,
CCompilerCapabilities.SIMD_NEON64):
if len(simd_sources[simd_opt]) == 0:
continue
if capabilities.has(simd_opt):
objects = objects + self.compiler.compile(
simd_sources[simd_opt],
output_dir=self.build_temp,
include_dirs=ext.include_dirs,
debug=self.debug,
extra_postargs=capabilities.flags(simd_opt),
depends=ext.depends)
else:
sources = sources + simd_sources[simd_opt]
for add_sources in simd_sources_values:
depends = depends + add_sources
if not (self.force or newer_group(depends, ext_path, 'newer')):
log.debug("skipping '%s' extension (up-to-date)", ext.name)
return
else:
log.info("building '%s' extension", ext.name)
capabilities = CCompilerCapabilities(self.compiler)
pybase64_write_config(capabilities)
objects = list()
for simd_opt in (CCompilerCapabilities.SIMD_SSSE3,
CCompilerCapabilities.SIMD_SSE41,
CCompilerCapabilities.SIMD_SSE42,
CCompilerCapabilities.SIMD_AVX,
CCompilerCapabilities.SIMD_AVX2,
CCompilerCapabilities.SIMD_NEON32,
CCompilerCapabilities.SIMD_NEON64):
if len(simd_sources[simd_opt]) == 0:
continue
if capabilities.has(simd_opt):
objects = objects + self.compiler.compile(
simd_sources[simd_opt],
output_dir=self.build_temp,
include_dirs=ext.include_dirs,
debug=self.debug,
extra_postargs=capabilities.flags(simd_opt),
depends=ext.depends)
else:
if not (self.force or newer_group(depends, ext_path, 'newer')):
log.debug("skipping '%s' extension (up-to-date)", ext.name)
return
else:
log.info("building '%s' extension", ext.name)
capabilities = CCompilerCapabilities(self.compiler)
pybase64_write_config(capabilities)
objects = list()
for simd_opt in (CCompilerCapabilities.SIMD_SSSE3,
CCompilerCapabilities.SIMD_SSE41,
CCompilerCapabilities.SIMD_SSE42,
CCompilerCapabilities.SIMD_AVX,
CCompilerCapabilities.SIMD_AVX2,
CCompilerCapabilities.SIMD_NEON32,
CCompilerCapabilities.SIMD_NEON64):
if len(simd_sources[simd_opt]) == 0:
continue
if capabilities.has(simd_opt):
objects = objects + self.compiler.compile(
simd_sources[simd_opt],
output_dir=self.build_temp,
include_dirs=ext.include_dirs,
debug=self.debug,
extra_postargs=capabilities.flags(simd_opt),
depends=ext.depends)
else:
sources = sources + simd_sources[simd_opt]
objects = objects + self.compiler.compile(
self.__has_simd_support(
compiler,
['', '-mavx2', '/arch:AVX2'],
['-D__AVX2__'],
'immintrin.h',
'__m256i y = _mm256_loadu_si256((const __m256i*)argv[0]);'
'y = _mm256_i32gather_epi32((int const*)argv[1], y, 2);'
'return _mm_cvtsi128_si32(_mm256_castsi256_si128(y));'
)
log.info(
"AVX2: %s" %
str(self.__capabilities[
CCompilerCapabilities.SIMD_AVX2
]['support'])
)
self.__capabilities[CCompilerCapabilities.SIMD_NEON32] = \
self.__has_simd_support(
compiler,
[''],
[],
'arm_neon.h',
'uint8x16_t t = vdupq_n_u8(1);'
'return vgetq_lane_s32(vreinterpretq_s32_u8(t));'
)
log.info(
"NEON32: %s" %
str(self.__capabilities[
CCompilerCapabilities.SIMD_NEON32
]['support'])
)
depends = sources + ext.depends
try:
simd_sources_values = simd_sources.itervalues()
except AttributeError:
simd_sources_values = simd_sources.values()
for add_sources in simd_sources_values:
depends = depends + add_sources
if not (self.force or newer_group(depends, ext_path, 'newer')):
log.debug("skipping '%s' extension (up-to-date)", ext.name)
return
else:
log.info("building '%s' extension", ext.name)
capabilities = CCompilerCapabilities(self.compiler)
pybase64_write_config(capabilities)
objects = list()
for simd_opt in (CCompilerCapabilities.SIMD_SSSE3,
CCompilerCapabilities.SIMD_SSE41,
CCompilerCapabilities.SIMD_SSE42,
CCompilerCapabilities.SIMD_AVX,
CCompilerCapabilities.SIMD_AVX2,
CCompilerCapabilities.SIMD_NEON32,
CCompilerCapabilities.SIMD_NEON64):
if len(simd_sources[simd_opt]) == 0:
continue
if capabilities.has(simd_opt):
objects = objects + self.compiler.compile(
simd_sources[simd_opt],
def pybase64_write_config(capabilities):
log.info("creating 'base64/lib/config.h'")
with open(path.join(here, 'base64/lib/config.h'), mode='wt') as f:
f.write('\n#define HAVE_SSSE3 %i' %
capabilities.has(CCompilerCapabilities.SIMD_SSSE3))
f.write('\n#define HAVE_SSE41 %i' %
capabilities.has(CCompilerCapabilities.SIMD_SSE41))
f.write('\n#define HAVE_SSE42 %i' %
capabilities.has(CCompilerCapabilities.SIMD_SSE42))
f.write('\n#define HAVE_AVX %i' %
capabilities.has(CCompilerCapabilities.SIMD_AVX))
f.write('\n#define HAVE_AVX2 %i' %
capabilities.has(CCompilerCapabilities.SIMD_AVX2))
f.write('\n#define HAVE_NEON32 %i' % False)
f.write('\n#define HAVE_NEON64 %i' % False)
f.write('\n#define HAVE_FAST_UNALIGNED_ACCESS %i' % True)
f.write('\n')
]['support'])
)
self.__capabilities[CCompilerCapabilities.SIMD_SSE41] = \
self.__has_simd_support(
compiler,
['', '-msse4.1'],
['-D__SSE4_1__'],
'smmintrin.h',
'__m128i t = _mm_loadu_si128((const __m128i*)argv[0]);'
't = _mm_mpsadbw_epu8(t, t, 1);'
'return _mm_cvtsi128_si32(t);'
)
log.info(
"SSE41: %s" %
str(self.__capabilities[
CCompilerCapabilities.SIMD_SSE41
]['support'])
)
self.__capabilities[CCompilerCapabilities.SIMD_SSE42] = \
self.__has_simd_support(
compiler,
['', '-msse4.2'],
['-D__SSE4_2__'],
'nmmintrin.h',
'__m128i t = _mm_loadu_si128((const __m128i*)argv[0]);'
'return _mm_cmpistra(t, t, 0);'
)
log.info(
"SSE42: %s" %
str(self.__capabilities[
CCompilerCapabilities.SIMD_SSE42
]['support'])
def build_extension(self, ext):
sources = ext.sources
if sources is None or not isinstance(sources, (list, tuple)):
raise DistutilsSetupError(
"in 'ext_modules' option (extension '%s'), "
"'sources' must be present and must be "
"a list of source filenames" % ext.name)
sources = list(sources)
simd_sources = dict()
simd_sources[CCompilerCapabilities.SIMD_SSSE3] = ext.sources_ssse3
simd_sources[CCompilerCapabilities.SIMD_SSE41] = ext.sources_sse41
simd_sources[CCompilerCapabilities.SIMD_SSE42] = ext.sources_sse42
simd_sources[CCompilerCapabilities.SIMD_AVX] = ext.sources_avx
simd_sources[CCompilerCapabilities.SIMD_AVX2] = ext.sources_avx2
simd_sources[CCompilerCapabilities.SIMD_NEON32] = \
ext.sources_neon32
simd_sources[CCompilerCapabilities.SIMD_NEON64] = \
ext.sources_neon64
ext_path = self.get_ext_fullpath(ext.name)
depends = sources + ext.depends
try:
simd_sources_values = simd_sources.itervalues()
except AttributeError:
simd_sources_values = simd_sources.values()
for add_sources in simd_sources_values:
depends = depends + add_sources
def pybase64_write_config(capabilities):
log.info("creating 'base64/lib/config.h'")
with open(path.join(here, 'base64/lib/config.h'), mode='wt') as f:
f.write('\n#define HAVE_SSSE3 %i' %
capabilities.has(CCompilerCapabilities.SIMD_SSSE3))
f.write('\n#define HAVE_SSE41 %i' %
capabilities.has(CCompilerCapabilities.SIMD_SSE41))
f.write('\n#define HAVE_SSE42 %i' %
capabilities.has(CCompilerCapabilities.SIMD_SSE42))
f.write('\n#define HAVE_AVX %i' %
capabilities.has(CCompilerCapabilities.SIMD_AVX))
f.write('\n#define HAVE_AVX2 %i' %
capabilities.has(CCompilerCapabilities.SIMD_AVX2))
f.write('\n#define HAVE_NEON32 %i' % False)
f.write('\n#define HAVE_NEON64 %i' % False)
f.write('\n#define HAVE_FAST_UNALIGNED_ACCESS %i' % True)
f.write('\n')