Skip to content

Commit

Permalink
Fix build on M-class ARM processors
Browse files Browse the repository at this point in the history
  • Loading branch information
xguerin committed Nov 15, 2023
1 parent d20dfcf commit 3d25740
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,26 @@ endif (TULIPS_TESTS)
# Compiler flags
#

set(CMAKE_C_FLAGS "-Wall -Wextra -Werror -Wfatal-errors -mssse3")
set(CMAKE_C_FLAGS "-Wall -Wextra -Werror -Wfatal-errors")
set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O3")

set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -Wfatal-errors -mssse3")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -Wfatal-errors")
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g3 -O3")

if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mssse3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3")
endif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")

if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-address-of-packed-member")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-address-of-packed-member")
endif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")

#
# Option definitions
#
Expand Down
17 changes: 16 additions & 1 deletion include/tulips/system/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@

namespace tulips::system::utils {

#ifdef __aarch64__

inline uint32_t
log2(const uint32_t x)
{
uint32_t y, z;
asm("rbit %w1, %w0" : "=r"(y) : "r"(x));
asm("clz %w1, %w0" : "=r"(z) : "r"(y));
return x;
}

#else

inline uint32_t
log2(const uint32_t x)
{
uint32_t y;
asm("\tbsr %1, %0\n" : "=r"(y) : "r"(x));
asm("bsr %1, %0" : "=r"(y) : "r"(x));
return y;
}

#endif

void join(std::vector<std::string> const& r, const char d, std::string& s);
void split(std::string_view s, const char d, std::vector<std::string>& r);

Expand Down
1 change: 1 addition & 0 deletions src/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include_directories(${OpenSSL_INCLUDE_DIRS})
include_directories(${TCLAP_INCLUDE_DIRS})

set(CMAKE_POSITION_INDEPENDENT_CODE 1)
Expand Down

0 comments on commit 3d25740

Please sign in to comment.