Skip to content

Commit

Permalink
Fix avx on windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
egorpugin committed Feb 23, 2017
1 parent 4cd5e91 commit e376ffc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ if (STATIC)
endif()

if (WIN32)
add_definitions(-D__SSE4_1__)
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)

Expand Down Expand Up @@ -214,6 +213,17 @@ set(tesseract_src ${tesseract_src}
api/pdfrenderer.cpp
)

if (WIN32)
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/arch/dotproductsse.cpp
PROPERTIES COMPILE_DEFINITIONS __SSE4_1__)
if (MSVC)
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/arch/dotproductavx.cpp

This comment has been minimized.

Copy link
@stweil

stweil Feb 23, 2017

Member

Should PROPERTIES COMPILE_DEFINITIONS __AVX__) be added here? Or is that macro also set by MSVC?

This comment has been minimized.

Copy link
@egorpugin

egorpugin Feb 23, 2017

Author Contributor

MSVC will set it.

This comment has been minimized.

Copy link
@stweil

stweil Feb 23, 2017

Member

And are the MSVC builds 32 bit or are they 64 bit?

This comment has been minimized.

Copy link
@egorpugin

egorpugin Feb 23, 2017

Author Contributor

Works both on 32/64.

PROPERTIES COMPILE_FLAGS "/arch:AVX")
endif()
endif()

add_library (libtesseract ${LIBRARY_TYPE} ${tesseract_src} ${tesseract_hdr})
if (NOT STATIC)
target_compile_definitions (libtesseract
Expand Down
11 changes: 10 additions & 1 deletion arch/dotproductavx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,17 @@ double DotProductAVX(const double* u, const double* v, int n) {
// _mm256_extract_f64 doesn't exist, but resist the temptation to use an sse
// instruction, as that introduces a 70 cycle delay. All this casting is to
// fool the instrinsics into thinking we are extracting the bottom int64.
auto cast_sum = _mm256_castpd_si256(sum);
*(reinterpret_cast<inT64*>(&result)) =
_mm256_extract_epi64(_mm256_castpd_si256(sum), 0);
#ifndef _WIN32
_mm256_extract_epi64(cast_sum, 0)
#else
// this is a very simple workaround that probably could be activated
// for all other platforms that do not have _mm256_extract_epi64
// _mm256_extract_epi64(X, Y) == ((uint64_t*)&X)[Y]
((uint64_t*)&cast_sum)[0]
#endif

This comment has been minimized.

Copy link
@stweil

stweil Feb 23, 2017

Member

So any 32 bit platform with Intel AVX could be supported now?

This comment has been minimized.

Copy link
@egorpugin

egorpugin Feb 23, 2017

Author Contributor

We need just to check it somewhere. I don't have avx processor.

This comment has been minimized.

Copy link
@egorpugin

egorpugin Feb 23, 2017

Author Contributor

Yes, other platforms too, but I did not remove defined(__i386__) check in the beginning of file because we need to test it first.

;
while (offset < n) {
result += u[offset] * v[offset];
++offset;
Expand Down
16 changes: 11 additions & 5 deletions cppan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,19 @@ projects:
- _Bool

pre_sources: |
# dummy config file
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/config_auto.h)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/config_auto.h)
endif()
file_write_once(${BDIR}/config_auto.h "")
post_sources: |
if (NOT WIN32)
if (WIN32)
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/arch/dotproductsse.cpp
PROPERTIES COMPILE_DEFINITIONS __SSE4_1__)
if (MSVC)
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/arch/dotproductavx.cpp

This comment has been minimized.

Copy link
@stweil

stweil Feb 23, 2017

Member

See comment above regarding __AVX__ macro.

PROPERTIES COMPILE_FLAGS "/arch:AVX")
endif()
else()
remove_src_dir(vs2010/port/*)
endif()
Expand Down

0 comments on commit e376ffc

Please sign in to comment.