Skip to content

Commit

Permalink
compile streamvbyte as C, not C++ (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
cldellow authored Jan 6, 2024
1 parent 65829e4 commit 7405050
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ endif()
if(MSVC)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
add_library(SQLite::SQLite3 ALIAS unofficial::sqlite3::sqlite3)
add_definitions(-D_USE_MATH_DEFINES -DWIN32_LEAN_AND_MEAN -DNOGDI)
add_definitions(-D_USE_MATH_DEFINES -DWIN32_LEAN_AND_MEAN -DNOGDI -D__restrict__=__restrict)
set(THREAD_LIB "")
else()
find_package(SQLite3 REQUIRED)
Expand All @@ -72,9 +72,9 @@ file(GLOB tilemaker_src_files
src/attribute_store.cpp
src/coordinates.cpp
src/coordinates_geom.cpp
src/external/streamvbyte_decode.cc
src/external/streamvbyte_encode.cc
src/external/streamvbyte_zigzag.cc
src/external/streamvbyte_decode.c
src/external/streamvbyte_encode.c
src/external/streamvbyte_zigzag.c
src/geojson_processor.cpp
src/geom.cpp
src/helpers.cpp
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ prefix = /usr/local
MANPREFIX := /usr/share/man
TM_VERSION ?= $(shell git describe --tags --abbrev=0)
CXXFLAGS ?= -O3 -Wall -Wno-unknown-pragmas -Wno-sign-compare -std=c++14 -pthread -fPIE -DTM_VERSION=$(TM_VERSION) $(CONFIG)
CFLAGS ?= -O3 -Wall -Wno-unknown-pragmas -Wno-sign-compare -std=c99 -fPIE -DTM_VERSION=$(TM_VERSION) $(CONFIG)
LIB := -L$(PLATFORM_PATH)/lib -lz $(LUA_LIBS) -lboost_program_options -lsqlite3 -lboost_filesystem -lboost_system -lboost_iostreams -lshp -pthread
INC := -I$(PLATFORM_PATH)/include -isystem ./include -I./src $(LUA_CFLAGS)

Expand Down Expand Up @@ -194,8 +195,8 @@ server: \
%.o: %.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INC)

%.o: %.cc
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INC)
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $< $(INC)

install:
install -m 0755 -d $(DESTDIR)$(prefix)/bin/
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "streamvbyte_x64_encode.c"
#endif

static uint8_t svb_encode_data(uint32_t val, uint8_t * *dataPtrPtr) {
static uint8_t svb_encode_data(uint32_t val, uint8_t *__restrict__ *dataPtrPtr) {
uint8_t *dataPtr = *dataPtrPtr;
uint8_t code;

Expand All @@ -37,8 +37,8 @@ static uint8_t svb_encode_data(uint32_t val, uint8_t * *dataPtrPtr) {
}

static uint8_t *svb_encode_scalar(const uint32_t *in,
uint8_t * keyPtr,
uint8_t * dataPtr,
uint8_t *__restrict__ keyPtr,
uint8_t *__restrict__ dataPtr,
uint32_t count) {
if (count == 0)
return dataPtr; // exit immediately if no data
Expand Down
6 changes: 3 additions & 3 deletions src/external/streamvbyte_x64_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifdef STREAMVBYTE_X64
STREAMVBYTE_TARGET_SSE41
static inline __m128i svb_decode_sse41(uint32_t key,
const uint8_t * *dataPtrPtr) {
const uint8_t *__restrict__ *dataPtrPtr) {
uint8_t len;
__m128i Data = _mm_loadu_si128((const __m128i *)*dataPtrPtr);
uint8_t *pshuf = (uint8_t *) &shuffleTable[key];
Expand Down Expand Up @@ -37,8 +37,8 @@ STREAMVBYTE_UNTARGET_REGION

STREAMVBYTE_TARGET_SSE41
static inline const uint8_t *svb_decode_sse41_simple(uint32_t *out,
const uint8_t * keyPtr,
const uint8_t * dataPtr,
const uint8_t *__restrict__ keyPtr,
const uint8_t *__restrict__ dataPtr,
uint64_t count) {

uint64_t keybytes = count / 4; // number of key bytes
Expand Down
7 changes: 2 additions & 5 deletions src/external/streamvbyte_x64_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@ STREAMVBYTE_UNTARGET_REGION
STREAMVBYTE_TARGET_SSE41
static size_t streamvbyte_encode_SSE41 (const uint32_t* in, uint32_t count, uint8_t* out) {
uint32_t keyLen = (count >> 2) + (((count & 3) + 3) >> 2); // 2-bits per each rounded up to byte boundary
// cldellow: NB `restrict` is only available in C99, not c++14.
// uint8_t *restrict keyPtr = &out[0];
// uint8_t *restrict dataPtr = &out[keyLen]; // variable length data after keys
uint8_t * keyPtr = &out[0];
uint8_t * dataPtr = &out[keyLen]; // variable length data after keys
uint8_t *restrict keyPtr = &out[0];
uint8_t *restrict dataPtr = &out[keyLen]; // variable length data after keys

for (const uint32_t* end = &in[(count & ~7U)]; in != end; in += 8)
{
Expand Down
File renamed without changes.

0 comments on commit 7405050

Please sign in to comment.