S390x support (#1103)

* s390x support

* - Fix for FrodoKEM-SHAKE for big endian support
- Fix unused variable in Keccak code on big endian
This commit is contained in:
Basil Hess 2021-10-12 20:39:56 +02:00 committed by GitHub
parent 59c19872eb
commit 016404076d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 4 deletions

View File

@ -22,8 +22,15 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
endif()
if(OQS_OPT_TARGET STREQUAL "generic")
# Assume sensible default like -march=x86-64, -march=armv8-a, etc.
set(OQS_OPT_FLAG "")
if(ARCH_S390X)
# At least z9-109 is needed for 'stckf' in benchmarking code.
# gcc's default is z900 (older than z9-109), clang's default and minimum is z10.
# setting to z10 as sensible default.
set(OQS_OPT_FLAG "-march=z10")
else()
# Assume sensible default like -march=x86-64, -march=armv8-a, etc.
set(OQS_OPT_FLAG "")
endif()
elseif(OQS_OPT_TARGET STREQUAL "auto")
if(ARCH_X86_64)
set(OQS_OPT_FLAG "-march=native")
@ -31,6 +38,8 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
set(OQS_OPT_FLAG "-mcpu=native")
elseif(ARCH_ARM64v8 AND CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(OQS_OPT_FLAG "-mcpu=native")
elseif(ARCH_S390X)
set(OQS_OPT_FLAG "-march=native")
else()
message(WARNING "Setting OQS_OPT_TARGET=AUTO may not produce optimized code on this system.")
endif()
@ -39,6 +48,8 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
set(OQS_OPT_FLAG "-march=${OQS_OPT_TARGET}")
elseif(ARCH_ARM64v8 OR ARCH_ARM32v7)
set(OQS_OPT_FLAG "-mcpu=${OQS_OPT_TARGET}")
elseif(ARCH_S390X)
set(OQS_OPT_FLAG "-march=${OQS_OPT_TARGET}")
endif()
endif()

View File

@ -11,3 +11,11 @@ jobs:
script:
- mkdir build && cd build && cmake -GNinja .. && cmake -LA .. && ninja
- cd build & ninja run_tests
- arch: s390x
os: linux
dist: focal
compiler: gcc
if: NOT branch =~ /^ghactionsonly-/
script:
- mkdir build && cd build && cmake -DOQS_ENABLE_KEM_BIKE=OFF -GNinja .. && cmake -LA .. && ninja
- cd build & ninja run_tests

View File

@ -59,6 +59,12 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
if(${OQS_DIST_BUILD})
set(OQS_DIST_PPC64LE_BUILD ON)
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
set(ARCH "s390x")
set(ARCH_S390X ON)
if(${OQS_DIST_BUILD})
set(OQS_DIST_S390X_BUILD ON)
endif()
elseif(OQS_PERMIT_UNSUPPORTED_ARCHITECTURE)
message(WARNING "Unknown or unsupported processor: " ${CMAKE_SYSTEM_PROCESSOR})
message(WARNING "Compilation on an unsupported processor should only be used for testing, as it may result an insecure configuration, for example due to variable-time instructions leaking secret information.")

View File

@ -135,6 +135,11 @@ static void set_available_cpu_extensions(void) {
/* mark that this function has been called */
cpu_ext_data[OQS_CPU_EXT_INIT] = 1;
}
#elif defined(OQS_DIST_S390X_BUILD)
static void set_available_cpu_extensions(void) {
/* mark that this function has been called */
cpu_ext_data[OQS_CPU_EXT_INIT] = 1;
}
#elif defined(OQS_DIST_BUILD)
static void set_available_cpu_extensions(void) {
}

View File

@ -435,10 +435,11 @@ void KeccakP1600_ExtractAndAddBytesInLane(const void *state, unsigned int lanePo
void KeccakP1600_ExtractAndAddLanes(const void *state, const unsigned char *input, unsigned char *output, unsigned int laneCount) {
unsigned int i;
uint64_t lane;
#if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN)
unsigned char temp[8];
unsigned int j;
#else
uint64_t lane;
#endif
for (i = 0; i < laneCount; i++) {

View File

@ -39,7 +39,7 @@ int frodo_mul_add_sa_plus_e_shake_portable(uint16_t *out, const uint16_t *s, con
for (j = 0; j < 4; j++) {
uint16_t sp = s[i*PARAMS_N + kk + j];
for (int k = 0; k < PARAMS_N; k++) { // Matrix-vector multiplication
sum[k] += (uint16_t) ((uint32_t) sp * (uint32_t) a_cols[(t+j)*PARAMS_N + k]);
sum[k] += (uint16_t) ((uint32_t) sp * (uint32_t) UINT16_TO_LE(a_cols[(t+j)*PARAMS_N + k]));
}
}
for (int k = 0; k < PARAMS_N; k++){

View File

@ -128,6 +128,8 @@ if(OQS_ENABLE_KEM_sike_p434 OR
endif()
elseif(ARCH_PPC64LE)
target_compile_definitions(sike PRIVATE _GENERIC_ _PPC64LE_)
elseif(ARCH_S390X)
target_compile_definitions(sike PRIVATE _GENERIC_ _S390X_)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")

View File

@ -135,6 +135,11 @@ static uint64_t _bench_rdtsc(void) {
__asm__ volatile("mrc p15, 0, %0, c9, c13, 0\t\n"
: "=r"(value));
return value;
#elif defined(__s390x__)
#define USING_TIME_RATHER_THAN_CYCLES
uint64_t tod;
__asm__ volatile("stckf %0\n" : "=Q" (tod) : : "cc");
return (tod * 1000 / 4096);
#else
#define USING_TIME_RATHER_THAN_CYCLES
struct timespec time;