Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
project('libb2', 'c', version: '0.98.1',
meson_version: '>=0.47.0',
default_options: ['optimization=3'])

openmp = dependency('openmp', required: get_option('openmp'))

conf = configuration_data()
cc = meson.get_compiler('c')

testcode = '''
int main() {
__builtin_cpu_init();
return !__builtin_cpu_supports ("@0@");
}
'''

fat = get_option('fat')
native = get_option('native') and not fat

if fat or native
foreach iset: ['avx', 'avx2', 'sse2', 'ssse3', 'sse4.1', 'xop']
arg = '-m'+iset
has_arg = cc.has_argument(arg)
if fat and not has_arg
error('fat binary but compiler does not support "@0@"'.format(arg))
elif native and has_arg and cc.run(testcode.format(iset)).returncode() == 0
add_project_arguments(arg, language: 'c')
# this is technically unnecessary as blake2-config.h additionally defines it
# based on gcc builtin __<iset>__ once -m<iset> is added
conf.set('HAVE_' + iset.underscorify().to_upper(), true)
endif
endforeach
endif

if host_machine.endian() == 'little'
conf.set('NATIVE_LITTLE_ENDIAN', true)
endif

use_sse = conf.get('HAVE_SSSE3', false)

subdir('src')
3 changes: 3 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
option('fat', type: 'boolean', value: false, description: 'build a fat binary on systems which support it')
option('native', type: 'boolean', value: true, description: 'build a native binary with all optimizations supported')
option('openmp', type: 'feature', value: 'auto', description: 'build with OpenMP support')
92 changes: 92 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
configure_file(output: 'config.h', configuration: conf)

sources = files(
'blake2sp.c',
'blake2bp.c',
)

if false # the code uses defines, not separate files
simd_mod = import('unstable-simd')
libb2_simd = simd_mod.check('blake2b',
sse2: 'blake2b-sse2.c',
ssse3: 'blake2b-ssse3.c',
sse41: 'blake2b-sse41.c',
avx: 'blake2b-avx.c',
# xop is not available in meson
)
endif
Comment on lines +8 to +17
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://mesonbuild.com/Simd-module.html

This would have actually been fairly convenient, since meson's compiler definitions include MSVC and include SIMD mappings.

A future optimization would be to improve the meson SIMD module to also allow retrieving a list of compiler-supported isets alongside their CFLAGS, then reuse that for a completely custom implementation of library building. In order to reuse it for the native codepath, it would additionally require all-new code to teach a compiler how to test for CPU (not compiler) support. I have WIP code for this, but it would end up requiring bleeding edge versions of meson...


internal_libs = []

if get_option('fat')
sources += files(
'blake2-dispatch.c',
)
internal_libs += [
static_library('blake2_ref',
'blake2b-ref.c', 'blake2s-ref.c',
dependencies: openmp,
c_args: ['-DSUFFIX=_ref']
),
static_library('blake2_sse2',
'blake2b.c', 'blake2s.c',
dependencies: openmp,
c_args: ['-DSUFFIX=_sse2', '-msse2']
),
static_library('blake2_ssse3',
'blake2b.c', 'blake2s.c',
dependencies: openmp,
c_args: ['-DSUFFIX=_ssse3', '-msse2', '-mssse3']
),
static_library('blake2_sse4.1',
'blake2b.c', 'blake2s.c',
dependencies: openmp,
c_args: ['-DSUFFIX=_sse41', '-msse2', '-mssse3', '-msse4.1']
),
static_library('blake2_avx',
'blake2b.c', 'blake2s.c',
dependencies: openmp,
c_args: ['-DSUFFIX=_avx', '-msse2', '-mssse3', '-msse4.1', '-mavx']
),
static_library('blake2_xop',
'blake2b.c', 'blake2s.c',
dependencies: openmp,
c_args: ['-DSUFFIX=_xop', '-msse2', '-mssse3', '-msse4.1', '-mavx', '-mxop']
),
]
elif use_sse
sources += files(
'blake2s.c',
'blake2b.c',
)
else
sources += files(
'blake2s-ref.c',
'blake2b-ref.c',
)
endif

install_headers('blake2.h')
libb2 = library('b2', sources,
c_args: '-DSUFFIX=',
link_with: internal_libs,
dependencies: openmp,
version: '1.0.4',
install: true,
)

libb2_dep = declare_dependency(
link_with: libb2,
include_directories: include_directories('.')
)
import('pkgconfig').generate(libb2,
name: 'libb2',
description: 'C library providing BLAKE2b, BLAKE2s, BLAKE2bp, BLAKE2sp',
url: 'https://github.com/BLAKE2/libb2',
)

foreach t: ['2s', '2b', '2sp', '2bp']
name = 'blake'+t+'-test'
testprog = executable(name, name+'.c', link_with: libb2)
test(name, testprog)
endforeach