Skip to content

Commit

Permalink
Add support for non-x86_64 architectures (e.g. Linux ARM64)
Browse files Browse the repository at this point in the history
Fixes voutcn#320
Based on: voutcn#329

Preserves the x86_64 specifics when building on x86_64 machine

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
  • Loading branch information
martin-g committed Mar 27, 2024
1 parent 5f329c6 commit 296ad6b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ add_executable(megahit_core_popcnt ${OTHER_SOURCE} ${ASMBL_SOURCE} ${IDBA_SOURCE
${CX1_SOURCE} ${TOOLKIT_SOURCE})
add_executable(megahit_core_no_hw_accel ${OTHER_SOURCE} ${ASMBL_SOURCE} ${IDBA_SOURCE} ${SDBG_SOURCE} ${LCASM_SOURCE}
${SEQ_SOURCE} ${CX1_SOURCE} ${TOOLKIT_SOURCE})
set_target_properties(megahit_core PROPERTIES COMPILE_FLAGS "-mbmi2 -DUSE_BMI2 -mpopcnt")
set_target_properties(megahit_core_popcnt PROPERTIES COMPILE_FLAGS "-mpopcnt")

if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(amd64)|(AMD64)")
set_target_properties(megahit_core PROPERTIES COMPILE_FLAGS "-mbmi2 -DUSE_BMI2 -mpopcnt")
set_target_properties(megahit_core_popcnt PROPERTIES COMPILE_FLAGS "-mpopcnt")
endif ()


if (STATIC_BUILD)
# TODO dirty
Expand Down
2 changes: 2 additions & 0 deletions src/kmlib/kmrns.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#if defined(__x86_64__)
#include <x86intrin.h>
#endif
#include <vector>

namespace kmlib {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/cpu_dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef MEGAHIT_CPU_DISPATCH_H
#define MEGAHIT_CPU_DISPATCH_H

#if defined(__x86_64__)
inline bool HasPopcnt() {
unsigned eax, ebx, ecx, edx;
#ifdef _MSC_VER
Expand Down Expand Up @@ -32,5 +33,10 @@ inline bool HasBmi2() {
#endif
return ebx >> 8U & 1U;
}
#else
inline bool HasPopcnt() { return false; }
inline bool HasBmi2() { return false; }
#endif


#endif // MEGAHIT_CPU_DISPATCH_H

0 comments on commit 296ad6b

Please sign in to comment.