From b9a4068eefd1768f701dffe3d3bcdad02387f58c Mon Sep 17 00:00:00 2001 From: Zhang Xianyi Date: Fri, 1 May 2015 20:24:07 +0000 Subject: [PATCH] Add ARM and AARCH64 config. --- cmake/arch_detect.c | 11 +++ cmake/auto_detect_cpu.cmake | 15 +++- cmake/cpuid_arm.c | 136 ++++++++++++++++++++++++++++++ kernel/aarch64/Kernel_generic.txt | 19 +++++ kernel/arm/Kernel_armv7a.txt | 1 + kernel/arm/Kernel_cortexa15.txt | 1 + kernel/arm/Kernel_cortexa9.txt | 1 + kernel/arm/Kernel_generic.txt | 19 +++++ 8 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 cmake/cpuid_arm.c create mode 100644 kernel/aarch64/Kernel_generic.txt create mode 100644 kernel/arm/Kernel_armv7a.txt create mode 100644 kernel/arm/Kernel_cortexa15.txt create mode 100644 kernel/arm/Kernel_cortexa9.txt create mode 100644 kernel/arm/Kernel_generic.txt diff --git a/cmake/arch_detect.c b/cmake/arch_detect.c index 28e7ff6..48c044e 100644 --- a/cmake/arch_detect.c +++ b/cmake/arch_detect.c @@ -31,6 +31,17 @@ int main() printf("x86_64"); return 0; #endif + +#if defined(__arm__) || defined(_M_ARM) || (__TARGET_ARCH_ARM) + printf("arm"); + return 0; +#endif + +#if defined(__aarch64__) + printf("aarch64"); + return 0; +#endif + //default printf("generic"); return 0; diff --git a/cmake/auto_detect_cpu.cmake b/cmake/auto_detect_cpu.cmake index 3f52711..e379761 100644 --- a/cmake/auto_detect_cpu.cmake +++ b/cmake/auto_detect_cpu.cmake @@ -31,6 +31,17 @@ try_run(cpu_detect_result cpu_detect_compile_result #endif() endif() + +#For ARM 32-bit +if(OpenVML_ARCH STREQUAL "arm") +try_run(cpu_detect_result cpu_detect_compile_result + ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/cpuid_arm.c + COMPILE_DEFINITIONS ${OpenVML_CPU_DETECT_FLAGS} + RUN_OUTPUT_VARIABLE cpu_detect_output + COMPILE_OUTPUT_VARIABLE cpu_detect_compile_output + ) +endif() + if(cpu_detect_compile_result) if(cpu_detect_result EQUAL 0) set (OpenVML_CPU_CORENAME ${cpu_detect_output}) @@ -38,8 +49,8 @@ else() message("${cpu_detect_output}") endif() else() -message("detect compile error") -message("${cpu_detect_compile_output}") +#message("detect compile error") +#message("${cpu_detect_compile_output}") endif() diff --git a/cmake/cpuid_arm.c b/cmake/cpuid_arm.c new file mode 100644 index 0000000..4695efa --- /dev/null +++ b/cmake/cpuid_arm.c @@ -0,0 +1,136 @@ +/* * Copyright (c) 2014, 2015 Zhang Xianyi + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#define CPUNAME_GENERIC 0 +#define CPUNAME_ARMV7 1 +#define CPUNAME_CORTEXA9 2 +#define CPUNAME_CORTEXA15 3 + +static char *cpuname[] = { + "generic", + "armv7a", + "cortexa9", + "cortexa15", +}; + +int get_feature(char *search) +{ + FILE *infile; + char buffer[2048], *p,*t; + p = (char *) NULL; + + infile = fopen("/proc/cpuinfo", "r"); + if (infile == NULL) { + return 0; + } + + while (fgets(buffer, sizeof(buffer), infile)) { + if (!strncmp("Features", buffer, 8)) { + p = strchr(buffer, ':') + 2; + break; + } + } + fclose(infile); + + if( p == NULL ) return 0; + + t = strtok(p," "); + if (t != NULL) { + if (!strcmp(t, search)) { return 1; } + } + while( t = strtok(NULL," ")){ + if (!strcmp(t, search)) { return 1; } + } + + return 0; +} + +int cpu_detect(void) +{ + FILE *infile; + char buffer[512], *p; + p = (char *) NULL ; + + infile = fopen("/proc/cpuinfo", "r"); + if (infile == NULL) { + return CPUNAME_GENERIC; + } + while (fgets(buffer, sizeof(buffer), infile)) { + if (!strncmp("CPU part", buffer, 8)) { + p = strchr(buffer, ':') + 2; + break; + } + } + fclose(infile); + + if(p != NULL) { + if (strstr(p, "0xc09")) { + if(get_feature("neon")) + return CPUNAME_CORTEXA9; + else + return CPUNAME_ARMV7; + } + if (strstr(p, "0xc0f")) { + if(get_feature("neon")) + return CPUNAME_CORTEXA15; + else + return CPUNAME_ARMV7; + } + } + + p = (char *) NULL ; + infile = fopen("/proc/cpuinfo", "r"); + if (infile == NULL) { + return CPUNAME_GENERIC; + } + + while (fgets(buffer, sizeof(buffer), infile)) { + if ((!strncmp("model name", buffer, 10)) || (!strncmp("Processor", buffer, 9))) { + p = strchr(buffer, ':') + 2; + break; + } + } + fclose(infile); + + if(p != NULL) { + if (strstr(p, "ARMv7")) { + return CPUNAME_ARMV7; + } + } + + return CPUNAME_GENERIC; +} + +int main() +{ + int cpuname_id; + + cpuname_id=cpu_detect(); + printf("%s", cpuname[cpuname_id]); + return 0; +} diff --git a/kernel/aarch64/Kernel_generic.txt b/kernel/aarch64/Kernel_generic.txt new file mode 100644 index 0000000..12b75a3 --- /dev/null +++ b/kernel/aarch64/Kernel_generic.txt @@ -0,0 +1,19 @@ +set(add_S_KERNEL_SOURCE generic/add_kernel.c) +set(add_D_KERNEL_SOURCE generic/add_kernel.c) +set(add_C_KERNEL_SOURCE generic/add_kernel.c) +set(add_Z_KERNEL_SOURCE generic/add_kernel.c) + +set(sub_S_KERNEL_SOURCE generic/sub_kernel.c) +set(sub_D_KERNEL_SOURCE generic/sub_kernel.c) +set(sub_C_KERNEL_SOURCE generic/sub_kernel.c) +set(sub_Z_KERNEL_SOURCE generic/sub_kernel.c) + +set(pow_S_KERNEL_SOURCE generic/pow_kernel.c) +set(pow_D_KERNEL_SOURCE generic/pow_kernel.c) + +set(exp_S_KERNEL_SOURCE generic/exp_kernel.c) +set(exp_D_KERNEL_SOURCE generic/exp_kernel.c) + +set(tanh_S_KERNEL_SOURCE generic/tanh_kernel.c) +set(tanh_D_KERNEL_SOURCE generic/tanh_kernel.c) + diff --git a/kernel/arm/Kernel_armv7a.txt b/kernel/arm/Kernel_armv7a.txt new file mode 100644 index 0000000..25b74ee --- /dev/null +++ b/kernel/arm/Kernel_armv7a.txt @@ -0,0 +1 @@ +include(${OpenVML_ARCH}/Kernel_generic.txt) diff --git a/kernel/arm/Kernel_cortexa15.txt b/kernel/arm/Kernel_cortexa15.txt new file mode 100644 index 0000000..25b74ee --- /dev/null +++ b/kernel/arm/Kernel_cortexa15.txt @@ -0,0 +1 @@ +include(${OpenVML_ARCH}/Kernel_generic.txt) diff --git a/kernel/arm/Kernel_cortexa9.txt b/kernel/arm/Kernel_cortexa9.txt new file mode 100644 index 0000000..25b74ee --- /dev/null +++ b/kernel/arm/Kernel_cortexa9.txt @@ -0,0 +1 @@ +include(${OpenVML_ARCH}/Kernel_generic.txt) diff --git a/kernel/arm/Kernel_generic.txt b/kernel/arm/Kernel_generic.txt new file mode 100644 index 0000000..12b75a3 --- /dev/null +++ b/kernel/arm/Kernel_generic.txt @@ -0,0 +1,19 @@ +set(add_S_KERNEL_SOURCE generic/add_kernel.c) +set(add_D_KERNEL_SOURCE generic/add_kernel.c) +set(add_C_KERNEL_SOURCE generic/add_kernel.c) +set(add_Z_KERNEL_SOURCE generic/add_kernel.c) + +set(sub_S_KERNEL_SOURCE generic/sub_kernel.c) +set(sub_D_KERNEL_SOURCE generic/sub_kernel.c) +set(sub_C_KERNEL_SOURCE generic/sub_kernel.c) +set(sub_Z_KERNEL_SOURCE generic/sub_kernel.c) + +set(pow_S_KERNEL_SOURCE generic/pow_kernel.c) +set(pow_D_KERNEL_SOURCE generic/pow_kernel.c) + +set(exp_S_KERNEL_SOURCE generic/exp_kernel.c) +set(exp_D_KERNEL_SOURCE generic/exp_kernel.c) + +set(tanh_S_KERNEL_SOURCE generic/tanh_kernel.c) +set(tanh_D_KERNEL_SOURCE generic/tanh_kernel.c) +