Improved CPU extension handling and updated README. (#622)

This commit is contained in:
xvzcf 2020-02-20 11:17:25 -05:00 committed by GitHub
parent f857b57df8
commit 56eece81d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 77 deletions

View File

@ -1,68 +0,0 @@
if(ARCH STREQUAL "x86" OR
ARCH STREQUAL "x86_64")
try_run(RUN_RESULT COMPILE_RESULT
"${CMAKE_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/.CMake/list-cpu-extensions.c"
RUN_OUTPUT_VARIABLE RUN_OUTPUT)
foreach(CPU_EXTENSION ${RUN_OUTPUT})
set(USE_${CPU_EXTENSION}_INSTRUCTIONS TRUE)
endforeach()
if(USE_AES_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes")
endif()
if(USE_AVX_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
endif()
if(USE_AVX2_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
endif()
if(USE_AVX512BW_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512bw")
endif()
if(USE_AVX512DQ_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512dq")
endif()
if(USE_AVX512F_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512f")
endif()
if(USE_AVX512BW_INSTRUCTIONS AND
USE_AVX512DQ_INSTRUCTIONS AND
USE_AVX512F_INSTRUCTIONS)
set(USE_AVX512_INSTRUCTIONS ON)
endif()
if(USE_BMI_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mbmi")
endif()
if(USE_BMI2_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mbmi2")
endif()
if(USE_FMA_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma")
endif()
if(USE_FMA4_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma4")
endif()
if(USE_MMX_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmmx")
endif()
if(USE_POPCNT_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mpopcnt")
endif()
if(USE_SSE_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse")
endif()
if(USE_SSE2_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
endif()
if(USE_SSE3_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3")
endif()
if(USE_SSE4A_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4a")
endif()
if(USE_SSE4_1_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1")
endif()
if(USE_SSE4_2_INSTRUCTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2")
endif()
endif()

View File

@ -0,0 +1,15 @@
# TODO: Use cpu_features instead of list-cpu-extensions.c
if(ARCH STREQUAL "x86" OR
ARCH STREQUAL "x86_64")
try_run(RUN_RESULT COMPILE_RESULT
"${CMAKE_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/.CMake/list-cpu-extensions.c"
RUN_OUTPUT_VARIABLE RUN_OUTPUT)
foreach(CPU_EXTENSION ${RUN_OUTPUT})
set(USE_${CPU_EXTENSION}_INSTRUCTIONS TRUE)
endforeach()
if(USE_AVX512BW_INSTRUCTIONS AND
USE_AVX512DQ_INSTRUCTIONS AND
USE_AVX512F_INSTRUCTIONS)
set(USE_AVX512_INSTRUCTIONS ON)
endif()
endif()

View File

@ -120,7 +120,7 @@ jobs:
xcode: "11.3.0"
environment:
#TODO: Make tests pass with Release build
CONFIGURE_ARGS: -DUSE_OPENSSL=OFF -DCMAKE_BUILD_TYPE=Debug
CONFIGURE_ARGS: -DUSE_OPENSSL=OFF
SKIP_TESTS: style
steps:
- checkout

1
.gitignore vendored
View File

@ -12,4 +12,5 @@ build/
__pycache__
.pytest_cache
.cache
.CMake/a.out

View File

@ -39,8 +39,8 @@ if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb3")
else()
include(.CMake/add-cpu-extension-flags.cmake)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fomit-frame-pointer")
include(.CMake/cpu-extensions.cmake)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fomit-frame-pointer -march=native")
endif()
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
@ -51,7 +51,7 @@ if(BUILD_SHARED_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
endif()
include(.CMake/config-oqs-alg-support.cmake)
include(.CMake/alg-support.cmake)
include(.CMake/sanitizers.cmake)

View File

@ -12,7 +12,7 @@ liboqs is an open source C library for quantum-safe cryptographic algorithms.
- [Quickstart](#quickstart)
* [Linux / macOS](#linuxmacOS)
* [Windows](#windows)
* [Others](#others)
* [Cross compilation](#cross-compilation)
- [Documentation](#documentation)
- [Contributing](#contributing)
- [License](#license)
@ -92,11 +92,15 @@ We realize some parties may want to deploy quantum-safe cryptography prior to th
cmake -GNinja ..
ninja
Various options can be passed to `cmake` to disable algorithms, use different implementations, specify whether to use OpenSSL, etc.. All supported options are listed in the `.CMake/alg-support.cmake` file, and can be viewed by running `cmake -LAH ..` in the `build` directory`. All subsequent instructions assume we are in this directory.
Various options can be passed to `cmake` to customize the build. Some of them include:
If the build fails on macOS, you might have to run `cmake -GNinja -DCMAKE_BUILD_TYPE="Debug .."` before calling `ninja`.
- `-DUSE_OPENSSL=<val>`: `<val>` can be `ON` or `OFF`; when `ON`, liboqs uses OpenSSL's AES, SHA-2, and SHA-3 implementations.
- `-DBUILD_SHARED_LIBS=<val>`: `<val>` can be `ON` or `OFF`; when `ON`, CMake generates instructions for building a shared library, otherwise it generates instructions for building a static library.
- `OPENSSL_ROOT_DIR=<dir>`: `<dir>` specifies the directory in which CMake will look for OpenSSL.
3. The main build result is `lib/liboqs.a`, a static library. There are also a variety of programs built under the `tests` directory:
All supported options are listed in the `.CMake/alg-support.cmake` file, and can be viewed by running `cmake -LAH ..` in the `build` directory. All subsequent instructions assume we are in `build`.
3. The main build result is `lib/liboqs.a`, a static library. The public headers are located in the `include` directory. There are also a variety of programs built under the `tests` directory:
- `test_kem`: Simple test harness for key encapsulation mechanisms
- `test_sig`: Simple test harness for key signature schemes
@ -118,13 +122,15 @@ If the build fails on macOS, you might have to run `cmake -GNinja -DCMAKE_BUILD_
Then open `build/docs/doxygen/html/index.html` in your web browser.
4. Finally, `ninja install` can be run to install the built library and `include` files to a location of choice, which can be specified by passing the `-DCMAKE_INSTALL_PREFIX=<dir>` option to `cmake` at configure time.
### Windows
Binaries can be generated using Visual Studio 2019 with the [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) extension installed.
### Cross compilation
You can cross compile liboqs for various platform by supplying CMake with an appropriate [toolchain](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html) file.
You can cross compile liboqs for various platform by supplying CMake with an appropriate [toolchain](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html) file.
For example, to cross compile for a Raspberry Pi from Ubuntu Bionic: