From 1e736d4e7250138d117dd93f578991a6b8d37698 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 23 Jan 2023 11:58:21 +0800 Subject: [PATCH] feat: short code speed up ffi --- CMakeLists.txt | 3 +++ src/CMakeLists.txt | 26 +++++++++++++------------- src/klotski/CMakeLists.txt | 25 ++++++++++++++++--------- src/klotski/ffi/klotski.h | 4 ++++ src/klotski/ffi/klotski_ffi.cc | 11 +++++++++++ src/klotski/klotski_ffi.cc | 0 6 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 src/klotski/ffi/klotski.h create mode 100644 src/klotski/ffi/klotski_ffi.cc delete mode 100644 src/klotski/klotski_ffi.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 34ce9de..19b8d51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,4 +9,7 @@ endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") +# TODO: only in libklotski.so +add_compile_options(-fPIC) + add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b85d86b..8067075 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,18 +1,18 @@ cmake_minimum_required(VERSION 3.0) -include_directories(klotski) -include_directories(klotski/utils) -include_directories(klotski/all_cases) - -include_directories(klotski/raw_code) -include_directories(klotski/short_code) -include_directories(klotski/common_code) - -include_directories(klotski/core) -include_directories(klotski/analyse) -include_directories(klotski/fast_cal) +#include_directories(klotski) +#include_directories(klotski/utils) +#include_directories(klotski/all_cases) +# +#include_directories(klotski/raw_code) +#include_directories(klotski/short_code) +#include_directories(klotski/common_code) +# +#include_directories(klotski/core) +#include_directories(klotski/analyse) +#include_directories(klotski/fast_cal) add_subdirectory(klotski) -add_executable(klotski_bin main.cc) -target_link_libraries(klotski_bin klotski) +#add_executable(klotski_bin main.cc) +#target_link_libraries(klotski_bin klotski) diff --git a/src/klotski/CMakeLists.txt b/src/klotski/CMakeLists.txt index 85a9032..37406bc 100644 --- a/src/klotski/CMakeLists.txt +++ b/src/klotski/CMakeLists.txt @@ -2,6 +2,19 @@ cmake_minimum_required(VERSION 3.0) ################################################ +include_directories(utils) +include_directories(all_cases) + +include_directories(raw_code) +include_directories(short_code) +include_directories(common_code) + +include_directories(core) +include_directories(analyse) +include_directories(fast_cal) + +################################################ + add_subdirectory(utils) add_subdirectory(all_cases) @@ -13,14 +26,12 @@ add_subdirectory(core) add_subdirectory(analyse) add_subdirectory(fast_cal) -#add_subdirectory(graph) -#add_subdirectory(benchmark) - ################################################ -#add_library(klotski klotski_ffi.cc) #add_library(klotski STATIC klotski_ffi.cc) -add_library(klotski SHARED klotski_ffi.cc) +add_library(klotski SHARED ffi/klotski_ffi.cc) + +################################################ target_link_libraries(klotski utils) target_link_libraries(klotski all_cases) @@ -34,7 +45,3 @@ target_link_libraries(klotski analyse) target_link_libraries(klotski fast_cal) ################################################ - -#target_link_libraries(klotski graph) -#target_link_libraries(klotski benchmark) -#target_link_libraries(klotski pthread) diff --git a/src/klotski/ffi/klotski.h b/src/klotski/ffi/klotski.h new file mode 100644 index 0000000..22dc2f6 --- /dev/null +++ b/src/klotski/ffi/klotski.h @@ -0,0 +1,4 @@ +#pragma once + +void short_code_speed_up_fast(); +void short_code_speed_up_normal(); diff --git a/src/klotski/ffi/klotski_ffi.cc b/src/klotski/ffi/klotski_ffi.cc new file mode 100644 index 0000000..4b4c2f0 --- /dev/null +++ b/src/klotski/ffi/klotski_ffi.cc @@ -0,0 +1,11 @@ +#include "klotski.h" + +#include "short_code.h" + +void short_code_speed_up_fast() { + ShortCode::speed_up(ShortCode::FAST); +} + +void short_code_speed_up_normal() { + ShortCode::speed_up(ShortCode::NORMAL); +} diff --git a/src/klotski/klotski_ffi.cc b/src/klotski/klotski_ffi.cc deleted file mode 100644 index e69de29..0000000