Skip to content
Permalink
Browse files

porting to ARMv7

  • Loading branch information...
zzqcn committed Nov 20, 2019
1 parent 4cebdaa commit 249178abd421f2be6a5b28aecc53930976a92ce8
@@ -182,24 +182,26 @@ else()
# cpuid info and then chooses the best microarch it can (and replaces
# the flag), so use that for tune.

# arg1 might exist if using ccache
string (STRIP "${CMAKE_C_COMPILER_ARG1}" CC_ARG1)
set (EXEC_ARGS ${CC_ARG1} -c -Q --help=target -march=native -mtune=native)
execute_process(COMMAND ${CMAKE_C_COMPILER} ${EXEC_ARGS}
OUTPUT_VARIABLE _GCC_OUTPUT)
string(FIND "${_GCC_OUTPUT}" "Known" POS)
string(SUBSTRING "${_GCC_OUTPUT}" 0 ${POS} _GCC_OUTPUT)
string(REGEX REPLACE ".*march=[ \t]*([^ \n]*)[ \n].*" "\\1"
GNUCC_ARCH "${_GCC_OUTPUT}")

# test the parsed flag
set (EXEC_ARGS ${CC_ARG1} -E - -mtune=${GNUCC_ARCH})
execute_process(COMMAND ${CMAKE_C_COMPILER} ${EXEC_ARGS}
OUTPUT_QUIET ERROR_QUIET
INPUT_FILE /dev/null
RESULT_VARIABLE GNUCC_TUNE_TEST)
if (NOT GNUCC_TUNE_TEST EQUAL 0)
message(SEND_ERROR "Something went wrong determining gcc tune: -mtune=${GNUCC_ARCH} not valid")
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^x86")
# arg1 might exist if using ccache
string (STRIP "${CMAKE_C_COMPILER_ARG1}" CC_ARG1)
set (EXEC_ARGS ${CC_ARG1} -c -Q --help=target -march=native -mtune=native)
execute_process(COMMAND ${CMAKE_C_COMPILER} ${EXEC_ARGS}
OUTPUT_VARIABLE _GCC_OUTPUT)
string(FIND "${_GCC_OUTPUT}" "Known" POS)
string(SUBSTRING "${_GCC_OUTPUT}" 0 ${POS} _GCC_OUTPUT)
string(REGEX REPLACE ".*march=[ \t]*([^ \n]*)[ \n].*" "\\1"
GNUCC_ARCH "${_GCC_OUTPUT}")

# test the parsed flag
set (EXEC_ARGS ${CC_ARG1} -E - -mtune=${GNUCC_ARCH})
execute_process(COMMAND ${CMAKE_C_COMPILER} ${EXEC_ARGS}
OUTPUT_QUIET ERROR_QUIET
INPUT_FILE /dev/null
RESULT_VARIABLE GNUCC_TUNE_TEST)
if (NOT GNUCC_TUNE_TEST EQUAL 0)
message(SEND_ERROR "Something went wrong determining gcc tune: -mtune=${GNUCC_ARCH} not valid")
endif()
endif()
set(TUNE_FLAG ${GNUCC_ARCH})
else ()
@@ -280,11 +282,13 @@ else()
endif ()
endif()

CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES(intrin.h HAVE_C_INTRIN_H)
CHECK_INCLUDE_FILE_CXX(intrin.h HAVE_CXX_INTRIN_H)
CHECK_INCLUDE_FILES(x86intrin.h HAVE_C_X86INTRIN_H)
CHECK_INCLUDE_FILE_CXX(x86intrin.h HAVE_CXX_X86INTRIN_H)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^x86")
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES(intrin.h HAVE_C_INTRIN_H)
CHECK_INCLUDE_FILE_CXX(intrin.h HAVE_CXX_INTRIN_H)
CHECK_INCLUDE_FILES(x86intrin.h HAVE_C_X86INTRIN_H)
CHECK_INCLUDE_FILE_CXX(x86intrin.h HAVE_CXX_X86INTRIN_H)
endif()

CHECK_FUNCTION_EXISTS(posix_memalign HAVE_POSIX_MEMALIGN)
CHECK_FUNCTION_EXISTS(_aligned_malloc HAVE__ALIGNED_MALLOC)
@@ -1,6 +1,7 @@
# detect architecture features
#
# must be called after determining where compiler intrinsics are defined
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^x86")

if (HAVE_C_X86INTRIN_H)
set (INTRIN_INC_H "x86intrin.h")
@@ -58,6 +59,13 @@ int main(){
(void)_mm512_abs_epi8(z);
}" HAVE_AVX512)

elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
set(HAVE_SSSE3 TRUE)
else()
message(FATAL_ERROR "don't support processor " ${CMAKE_SYSTEM_PROCESSOR})
endif()


if (FAT_RUNTIME)
if (NOT HAVE_SSSE3)
message(FATAL_ERROR "SSSE3 support required to build fat runtime")
@@ -15,6 +15,10 @@
/* "Define if building for EM64T" */
#cmakedefine ARCH_X86_64

#cmakedefine ARCH_ARM32

#cmakedefine ARCH_ARM64

/* internal build, switch on dump support. */
#cmakedefine DUMP_SUPPORT

@@ -1,9 +1,21 @@
# determine the target arch

if (CMAKE_SYSTEM_PROCESSOR MATCHES "^x86")

# really only interested in the preprocessor here
CHECK_C_SOURCE_COMPILES("#if !(defined(__x86_64__) || defined(_M_X64))\n#error not 64bit\n#endif\nint main(void) { return 0; }" ARCH_64_BIT)

CHECK_C_SOURCE_COMPILES("#if !(defined(__i386__) || defined(_M_IX86))\n#error not 64bit\n#endif\nint main(void) { return 0; }" ARCH_32_BIT)

set(ARCH_X86_64 ${ARCH_64_BIT})
set(ARCH_IA32 ${ARCH_32_BIT})


elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
# TODO: XXX
set(ARCH_32_BIT TRUE)
set(ARCH_ARM32 TRUE)
else()
message(FATAL_ERROR "don't support processor " ${CMAKE_SYSTEM_PROCESSOR})
endif()

@@ -0,0 +1,46 @@
# ARMv7
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

#set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")

set(TOOL_CHAIN_DIR /opt/shct/crosstools-arm-gcc-5.3-linux-4.1-glibc-2.22-binutils-2.25)
set(TOOL_CHAIN_INCLUDE
${TOOL_CHAIN_DIR}/usr/arm-buildroot-linux-gnueabi/sysroot/include
${TOOL_CHAIN_DIR}/usr/include
)
set(TOOL_CHAIN_LIB
${TOOL_CHAIN_DIR}/usr/lib
)

set(CMAKE_SYSROOT ${TOOL_CHAIN_DIR}/usr/arm-buildroot-linux-gnueabi/sysroot)

set(CMAKE_C_COMPILER ${TOOL_CHAIN_DIR}/usr/bin/arm-buildroot-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${TOOL_CHAIN_DIR}/usr/bin/arm-buildroot-linux-gnueabi-g++)

set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)

#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -mfpu=neon")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -mfpu=neon")

#set(CMAKE_FIND_ROOT_PATH ${TOOL_CHAIN_DIR}/usr/arm-buildroot-linux-gnueabi)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(SIMDE_INCLUDE /home/zzq/pkg/simde/simde CACHE PATH "SIMDe include directory")

include_directories(
${TOOL_CHAIN_DIR}/usr/arm-buildroot-linux-gnueabi/sysroot/include
${TOOL_CHAIN_DIR}/usr/include
${SIMDE_INCLUDE}
)

#set(CMAKE_INCLUDE_PATH
# ${TOOL_CHAIN_INCLUDE}
#)

#set(CMAKE_LIBRARY_PATH ${TOOL_CHAIN_LIB})
@@ -83,4 +83,8 @@
#define NO_ASM
#endif

#if defined(__arm__)
#define NO_ASM
#endif

#endif // UTIL_ARCH_H_
@@ -33,6 +33,8 @@
#include "hs_internal.h"
#include "util/arch.h"

#if defined(ARCH_IA32) || defined(ARCH_X86_64)

#if !defined(_WIN32) && !defined(CPUID_H_)
#include <cpuid.h>
#endif
@@ -157,3 +159,15 @@ u32 cpuid_tune(void) {

return HS_TUNE_FAMILY_GENERIC;
}

#elif defined(ARCH_ARM32)

u64a cpuid_flags(void) {
return 0;
}

u32 cpuid_tune(void) {
return HS_TUNE_FAMILY_GENERIC;
}

#endif
@@ -31,11 +31,13 @@

#include "ue2common.h"

#if defined(ARCH_IA32) || defined(ARCH_X86_64)
#if !defined(_WIN32) && !defined(CPUID_H_)
#include <cpuid.h>
/* system header doesn't have a header guard */
#define CPUID_H_
#endif
#endif

#ifdef __cplusplus
extern "C"
@@ -32,17 +32,21 @@
#include "ue2common.h"
#include "cpuid_flags.h"

#if defined(ARCH_IA32) || defined(ARCH_X86_64)

#if !defined(_WIN32) && !defined(CPUID_H_)
#include <cpuid.h>
/* system header doesn't have a header guard */
#define CPUID_H_
#endif
#endif

#ifdef __cplusplus
extern "C"
{
#endif

#if defined(ARCH_IA32) || defined(ARCH_X86_64)
static inline
void cpuid(unsigned int op, unsigned int leaf, unsigned int *eax,
unsigned int *ebx, unsigned int *ecx, unsigned int *edx) {
@@ -207,6 +211,36 @@ int check_popcnt(void) {
return !!(ecx & CPUID_POPCNT);
}

#elif defined(ARCH_ARM32)

static inline
int check_ssse3(void) {
return 1;
}

static inline
int check_sse42(void) {
return 0;
}

static inline
int check_popcnt(void) {
return 0;
}

static inline
int check_avx2(void) {
return 0;
}

static inline
int check_avx512(void) {
return 0;
}


#endif

#ifdef __cplusplus
} /* extern "C" */
#endif
@@ -35,6 +35,8 @@

#include "config.h"

#if defined(ARCH_IA32) || defined(ARCH_X86_64)

#ifdef __cplusplus
# if defined(HAVE_CXX_X86INTRIN_H)
# define USE_X86INTRIN_H
@@ -63,4 +65,11 @@
#error no intrinsics file
#endif


#elif defined(ARCH_ARM32)

#include "sse_helper.h"

#endif

#endif // INTRINSICS_H
@@ -34,6 +34,8 @@
#include "util/intrinsics.h"
#include "ue2common.h"

#if defined(ARCH_IA32) || defined(ARCH_X86_64)

#if defined(HAVE_SSE2)
typedef __m128i m128;
#else
@@ -53,5 +55,14 @@ typedef __m512i m512;
typedef struct ALIGN_ATTR(64) {m256 lo; m256 hi;} m512;
#endif

#elif defined(ARCH_ARM32)

typedef simde__m128i m128;
typedef struct ALIGN_AVX_DIRECTIVE {m128 lo; m128 hi;} m256;
typedef struct {m128 lo; m128 mid; m128 hi;} m384;
typedef struct ALIGN_ATTR(64) {m256 lo; m256 hi;} m512;

#endif

#endif /* SIMD_TYPES_H */

@@ -33,9 +33,11 @@
#ifndef SIMD_UTILS
#define SIMD_UTILS

#if defined(ARCH_IA32) || defined(ARCH_X86_64)
#if !defined(_WIN32) && !defined(__SSSE3__)
#error SSSE3 instructions must be enabled
#endif
#endif

#include "config.h"
#include "ue2common.h"

0 comments on commit 249178a

Please sign in to comment.
You can’t perform that action at this time.