Skip to content

Commit 945ddda

Browse files
committed
modify simd switches
1 parent c33e4c2 commit 945ddda

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,21 @@ An implementaion of adaptive range coder for C++
5757
|xargs.1|0.628815|13|15|
5858

5959
# Building
60-
For Visual Studio 15 2017,
60+
First, make sure you clone this repository.
61+
Then, deflate cantrbry.tar.bz2.
62+
If you work on Windows, you're going to need to deflate zlib.tar.bz2 and lz4.tar.bz2.
63+
6164
```
6265
git clone https://github.com/taqu/cpprcoder.git
6366
cd cpprcoder/test
64-
mkdir build_simd
65-
pushd build_simd
66-
cmake -G"Visual Studio 15 2017 Win64" -DUSE_SIMD=1 ..
67+
tar jxvf cantrbry.tar.bz2
68+
```
69+
70+
Next,
71+
```
72+
mkdir build
73+
pushd build
74+
cmake -DUSE_SIMD=1 ..
6775
```
6876

6977
# License

cpprcoder.h

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ namespace cpprcoder
109109

110110
#ifndef CPPRCODER_MAXRANGE_DECODE
111111
#define CPPRCODER_MAXRANGE_DECODE (0x00FFFFFFU)
112-
#endif
113-
114-
#if defined(__AVX__)
115-
#define CPPRCODER_USE_AVX (1)
116-
#elif defined(__SSE2__)
117-
#define CPPRCODER_USE_SSE2 (1)
118112
#endif
119113

120114
enum Status
@@ -277,7 +271,7 @@ namespace cpprcoder
277271
void countChunks();
278272

279273
u32 total_;
280-
#if defined(CPPRCODER_USE_SSE2) || defined(CPPRCODER_USE_AVX)
274+
#if defined(CPPRCODER_USE_SIMD)
281275
u32* prefix_;
282276
u32* frequencies_;
283277
u32 prefix_buffer_[CHUNKS + 4];
@@ -404,12 +398,7 @@ namespace cpprcoder
404398

405399
#ifdef CPPRCODER_IMPLEMENTATION
406400

407-
#ifdef CPPRCODER_USE_SSE2
408-
#include <immintrin.h>
409-
#include <emmintrin.h>
410-
#endif
411-
412-
#ifdef CPPRCODER_USE_AVX
401+
#ifdef CPPRCODER_USE_SIMD
413402
#include <immintrin.h>
414403
#endif
415404

@@ -656,7 +645,7 @@ namespace cpprcoder
656645
FrequencyTable::FrequencyTable()
657646
:total_(SIZE)
658647
{
659-
#if defined(CPPRCODER_USE_SSE2) || defined(CPPRCODER_USE_AVX)
648+
#if defined(CPPRCODER_USE_SIMD)
660649
prefix_ = reinterpret_cast<u32*>((reinterpret_cast<uintptr_t>(prefix_buffer_) + ALIGN_MASK) & ~ALIGN_MASK);
661650
frequencies_ = reinterpret_cast<u32*>((reinterpret_cast<uintptr_t>(frequencies_buffer_) + ALIGN_MASK) & ~ALIGN_MASK);
662651

@@ -695,7 +684,7 @@ namespace cpprcoder
695684

696685
void FrequencyTable::update(u8 b)
697686
{
698-
#if defined(CPPRCODER_USE_SSE2) || defined(CPPRCODER_USE_AVX)
687+
#if defined(CPPRCODER_USE_SIMD)
699688
++frequencies_[b];
700689
if(CPPRCODER_MINRANGE<=(++total_)){
701690
__m128i one = _mm_set1_epi32(1);
@@ -766,7 +755,7 @@ namespace cpprcoder
766755

767756
void FrequencyTable::find(u32& count, u8& code, u32 target) const
768757
{
769-
#if 0 //#if defined(CPPRCODER_USE_SSE2) || defined(CPPRCODER_USE_AVX)
758+
#if 0 //#if defined(CPPRCODER_USE_SIMD)
770759
__m128i target128 = _mm_set1_epi32(target);
771760
__m128i one = _mm_set1_epi32(1);
772761

@@ -855,7 +844,7 @@ namespace cpprcoder
855844

856845
void BinaryIndexedTree::initialize(u32 value)
857846
{
858-
#if defined(CPPRCODER_USE_SSE2) || defined(CPPRCODER_USE_AVX)
847+
#if defined(CPPRCODER_USE_SIMD)
859848
__m128i one = _mm_set1_epi32(0);
860849
__m128i* p = reinterpret_cast<__m128i*>(frequencies_);
861850
__m128i* end = p + (SIZE/4);

test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ add_executable(${ProjectName} ${FILES})
2525
set(CXX_FLAGS_SIMD "")
2626
if(MSVC)
2727
if(USE_SIMD)
28-
set(CXX_FLAGS_SIMD "/arch:AVX")
28+
set(CXX_FLAGS_SIMD "/arch:AVX /DCPPRCODER_USE_SIMD")
2929
endif()
3030

3131
set(DEFAULT_CXX_FLAGS "/DWIN32 /D_WINDOWS /D_MBCS /W4 /WX- /nologo /fp:precise /Zc:wchar_t /TP /Gd ${CXX_FLAGS_SIMD}")
@@ -41,7 +41,7 @@ if(MSVC)
4141

4242
elseif(UNIX)
4343
if(USE_SIMD)
44-
set(CXX_FLAGS_SIMD "-march=native")
44+
set(CXX_FLAGS_SIMD "-march=native -DCPPRCODER_USE_SIMD")
4545
endif()
4646
set(DEFAULT_CXX_FLAGS "-Wall -O2 -std=c++11 ${CXX_FLAGS_SIMD}")
4747
set(CMAKE_CXX_FLAGS "${DEFAULT_CXX_FLAGS}")

0 commit comments

Comments
 (0)