Skip to content

Commit

Permalink
Revert "CRC32 Power Optimization Changes"
Browse files Browse the repository at this point in the history
Summary:
This reverts commit 2289d38.
Closes facebook#2652

Differential Revision: D5506163

Pulled By: siying

fbshipit-source-id: 105e31dd9d99090453a6b9f32c165206cd3affa3
  • Loading branch information
siying authored and facebook-github-bot committed Jul 27, 2017
1 parent 9980de2 commit c281b44
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 1,949 deletions.
77 changes: 12 additions & 65 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,6 @@ OPT += -momit-leaf-frame-pointer
endif
endif

ifeq (,$(shell $(CXX) -fsyntax-only -maltivec -xc /dev/null 2>&1))
CXXFLAGS += -DHAS_ALTIVEC
CFLAGS += -DHAS_ALTIVEC
HAS_ALTIVEC=1
endif

ifeq (,$(shell $(CXX) -fsyntax-only -mcpu=power8 -xc /dev/null 2>&1))
CXXFLAGS += -DHAVE_POWER8
CFLAGS += -DHAVE_POWER8
HAVE_POWER8=1
endif

# if we're compiling for release, compile without debug code (-DNDEBUG) and
# don't treat warnings as errors
ifeq ($(DEBUG_LEVEL),0)
Expand Down Expand Up @@ -317,9 +305,9 @@ util/build_version.cc: FORCE
else mv -f $@-t $@; fi
endif

LIBOBJECTS = $(LIB_SOURCES:.cc=.cc.o) $(LIB_SOURCES_C:.c=.c.o) $(LIB_SOURCES_ASM:.S=.S.o)
LIBOBJECTS += $(TOOL_LIB_SOURCES:.cc=.cc.o)
MOCKOBJECTS = $(MOCK_LIB_SOURCES:.cc=.cc.o)
LIBOBJECTS = $(LIB_SOURCES:.cc=.o)
LIBOBJECTS += $(TOOL_LIB_SOURCES:.cc=.o)
MOCKOBJECTS = $(MOCK_LIB_SOURCES:.cc=.o)

GTEST = $(GTEST_DIR)/gtest/gtest-all.o
TESTUTIL = ./util/testutil.o
Expand Down Expand Up @@ -567,27 +555,14 @@ $(SHARED2): $(SHARED4)
$(SHARED3): $(SHARED4)
ln -fs $(SHARED4) $(SHARED3)
endif
SHARED_CC_OBJECTS = $(LIB_SOURCES:.cc=.cc.o)
SHARED_C_OBJECTS = $(LIB_SOURCES_C:.c=.c.o)
SHARED_ASM_OBJECTS = $(LIB_SOURCES_ASM:.S=.S.o)

SHARED_CC_LIBOBJECTS = $(patsubst %.cc.o,shared-objects/%.cc.o,$(SHARED_CC_OBJECTS))
SHARED_C_LIBOBJECTS = $(patsubst %.c.o,shared-objects/%.c.o,$(SHARED_C_OBJECTS))
SHARED_ASM_LIBOBJECTS = $(patsubst %.S.o,shared-objects/%.S.o,$(SHARED_ASM_OBJECTS))

shared_libobjects = $(SHARED_CC_LIBOBJECTS) $(SHARED_C_LIBOBJECTS) $(SHARED_ASM_LIBOBJECTS)
shared_libobjects = $(patsubst %,shared-objects/%,$(LIBOBJECTS))
CLEAN_FILES += shared-objects

$(SHARED_CC_LIBOBJECTS): shared-objects/%.cc.o: %.cc
$(AM_V_CC)mkdir -p $(@D) && $(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) -c $< -o $@

$(SHARED_C_LIBOBJECTS): shared-objects/%.c.o: %.c
$(shared_libobjects): shared-objects/%.o: %.cc
$(AM_V_CC)mkdir -p $(@D) && $(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) -c $< -o $@

$(SHARED_ASM_LIBOBJECTS): shared-objects/%.S.o: %.S
$(AM_V_CC)mkdir -p $(@D) && $(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) -c $< -o $@

$(SHARED4): $(shared_libobjects)
$(SHARED4): $(shared_libobjects)
$(CXX) $(PLATFORM_SHARED_LDFLAGS)$(SHARED3) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(shared_libobjects) $(LDFLAGS) -o $@

endif # PLATFORM_SHARED_EXT
Expand Down Expand Up @@ -1667,26 +1642,12 @@ rocksdbjavastaticpublishcentral:
mvn gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging -DpomFile=java/rocksjni.pom -Dfile=java/target/rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH).jar

# A version of each $(LIBOBJECTS) compiled with -fPIC
JAVA_CC_OBJECTS = $(SHARED_CC_OBJECTS)
JAVA_C_OBJECTS = $(SHARED_C_OBJECTS)
JAVA_ASM_OBJECTS = $(SHARED_ASM_OBJECTS)

JAVA_CC_LIBOBJECTS = $(patsubst %.cc.o,jl/%.cc.o,$(JAVA_CC_OBJECTS))
JAVA_C_LIBOBJECTS = $(patsubst %.c.o,jl/%.c.o,$(JAVA_C_OBJECTS))
JAVA_ASM_LIBOBJECTS = $(patsubst %.S.o,jl/%.S.o,$(JAVA_ASM_OBJECTS))
java_libobjects = $(JAVA_CC_LIBOBJECTS) $(JAVA_C_LIBOBJECTS) $(JAVA_ASM_LIBOBJECTS)
java_libobjects = $(patsubst %,jl/%,$(LIBOBJECTS))
CLEAN_FILES += jl

$(JAVA_CC_LIBOBJECTS): jl/%.cc.o: %.cc
$(AM_V_CC)mkdir -p $(@D) && $(CXX) $(CXXFLAGS) -fPIC -c $< -o $@ $(COVERAGEFLAGS)

$(JAVA_C_LIBOBJECTS): jl/%.c.o: %.c
$(AM_V_CC)mkdir -p $(@D) && $(CXX) $(CXXFLAGS) -fPIC -c $< -o $@ $(COVERAGEFLAGS)

$(JAVA_ASM_LIBOBJECTS): jl/%.S.o: %.S
$(java_libobjects): jl/%.o: %.cc
$(AM_V_CC)mkdir -p $(@D) && $(CXX) $(CXXFLAGS) -fPIC -c $< -o $@ $(COVERAGEFLAGS)


rocksdbjava: $(java_libobjects)
$(AM_V_GEN)cd java;$(MAKE) javalib;
$(AM_V_at)rm -f ./java/target/$(ROCKSDBJNILIB)
Expand Down Expand Up @@ -1742,24 +1703,19 @@ IOSVERSION=$(shell defaults read $(PLATFORMSROOT)/iPhoneOS.platform/version CFBu
lipo ios-x86/$@ ios-arm/$@ -create -output $@

else
%.cc.o: %.cc
.cc.o:
$(AM_V_CC)$(CXX) $(CXXFLAGS) -c $< -o $@ $(COVERAGEFLAGS)

%.c.o: %.c
$(AM_V_CC)$(CC) $(CFLAGS) -c $< -o $@

%.S.o: %.S
.c.o:
$(AM_V_CC)$(CC) $(CFLAGS) -c $< -o $@

endif

# ---------------------------------------------------------------------------
# Source files dependencies detection
# ---------------------------------------------------------------------------

all_sources = $(LIB_SOURCES) $(MAIN_SOURCES) $(MOCK_LIB_SOURCES) $(TOOL_LIB_SOURCES) $(BENCH_LIB_SOURCES) $(TEST_LIB_SOURCES) $(EXP_LIB_SOURCES)
DEPFILES = $(all_sources:.cc=.d)
DEPFILES_C = $(LIB_SOURCES_C:.c=.d)
DEPFILES_ASM = $(LIB_SOURCES_ASM:.S=.d)

# Add proper dependency support so changing a .h file forces a .cc file to
# rebuild.
Expand All @@ -1770,16 +1726,7 @@ $(DEPFILES): %.d: %.cc
@$(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) \
-MM -MT'$@' -MT'$(<:.cc=.o)' "$<" -o '$@'

$(DEPFILES_C): %.d: %.c
@$(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) \
-MM -MT'$@' -MT'$(<:.c=.o)' "$<" -o '$@'

$(DEPFILES_ASM): %.d: %.S
@$(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) \
-MM -MT'$@' -MT'$(<:.S=.o)' "$<" -o '$@'


depend: $(DEPFILES) $(DEPFILES_C) $(DEPFILES_ASM)
depend: $(DEPFILES)

# if the make goal is either "clean" or "format", we shouldn't
# try to import the *.d files.
Expand Down
7 changes: 4 additions & 3 deletions db/db_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,12 @@ Options DBTestBase::GetOptions(
Options options = default_options;
BlockBasedTableOptions table_options;
bool set_block_based_table_factory = true;
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && \
!defined(OS_AIX)
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && \
!defined(OS_AIX)
rocksdb::SyncPoint::GetInstance()->ClearCallBack(
"NewRandomAccessFile:O_DIRECT");
rocksdb::SyncPoint::GetInstance()->ClearCallBack("NewWritableFile:O_DIRECT");
rocksdb::SyncPoint::GetInstance()->ClearCallBack(
"NewWritableFile:O_DIRECT");
#endif

bool can_allow_mmap = IsMemoryMappedAccessSupported();
Expand Down
10 changes: 0 additions & 10 deletions src.mk
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,6 @@ LIB_SOURCES = \
utilities/write_batch_with_index/write_batch_with_index.cc \
utilities/write_batch_with_index/write_batch_with_index_internal.cc \

ifeq (,$(shell $(CXX) -fsyntax-only -maltivec -xc /dev/null 2>&1))
LIB_SOURCES_ASM =\
util/crc32c_ppc_asm.S
LIB_SOURCES_C = \
util/crc32c_ppc.c
else
LIB_SOURCES_ASM =
LIB_SOURCES_C =
endif

TOOL_LIB_SOURCES = \
tools/ldb_cmd.cc \
tools/ldb_tool.cc \
Expand Down
16 changes: 8 additions & 8 deletions tools/db_stress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2370,15 +2370,15 @@ int main(int argc, char** argv) {
#if !defined(NDEBUG) && !defined(OS_MACOSX) && !defined(OS_WIN) && \
!defined(OS_SOLARIS) && !defined(OS_AIX)
rocksdb::SyncPoint::GetInstance()->SetCallBack(
"NewWritableFile:O_DIRECT", [&](void* arg) {
int* val = static_cast<int*>(arg);
*val &= ~O_DIRECT;
});
"NewWritableFile:O_DIRECT", [&](void* arg) {
int* val = static_cast<int*>(arg);
*val &= ~O_DIRECT;
});
rocksdb::SyncPoint::GetInstance()->SetCallBack(
"NewRandomAccessFile:O_DIRECT", [&](void* arg) {
int* val = static_cast<int*>(arg);
*val &= ~O_DIRECT;
});
"NewRandomAccessFile:O_DIRECT", [&](void* arg) {
int* val = static_cast<int*>(arg);
*val &= ~O_DIRECT;
});
rocksdb::SyncPoint::GetInstance()->EnableProcessing();
#endif

Expand Down
69 changes: 1 addition & 68 deletions util/crc32c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,9 @@
#endif
#include "util/coding.h"

#ifdef __powerpc64__
#include "util/crc32c_ppc.h"
#include "util/crc32c_ppc_constants.h"

#if __linux__
#include <sys/auxv.h>

#ifndef PPC_FEATURE2_VEC_CRYPTO
#define PPC_FEATURE2_VEC_CRYPTO 0x02000000
#endif

#ifndef AT_HWCAP2
#define AT_HWCAP2 26
#endif

#endif /* __linux__ */

#endif

namespace rocksdb {
namespace crc32c {

#ifdef __powerpc64__
static int arch_ppc_crc32 = 0;
#endif

static const uint32_t table0_[256] = {
0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4,
0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb,
Expand Down Expand Up @@ -394,7 +371,6 @@ uint32_t ExtendImpl(uint32_t crc, const char* buf, size_t size) {
}

// Detect if SS42 or not.
#ifndef HAVE_POWER8
static bool isSSE42() {
#ifndef HAVE_SSE42
return false;
Expand All @@ -411,58 +387,15 @@ static bool isSSE42() {
return false;
#endif
}
#endif

typedef uint32_t (*Function)(uint32_t, const char*, size_t);

#if defined(HAVE_POWER8) && defined(HAS_ALTIVEC)
uint32_t ExtendPPCImpl(uint32_t crc, const char *buf, size_t size) {
return crc32c_ppc(crc, (const unsigned char *)buf, size);
}

#if __linux__
static int arch_ppc_probe(void) {
arch_ppc_crc32 = 0;

#if defined(__powerpc64__)
if (getauxval(AT_HWCAP2) & PPC_FEATURE2_VEC_CRYPTO) arch_ppc_crc32 = 1;
#endif /* __powerpc64__ */

return arch_ppc_crc32;
}
#endif // __linux__

static bool isAltiVec() {
if (arch_ppc_probe()) {
return true;
} else {
return false;
}
}
#endif

static inline Function Choose_Extend() {
#ifndef HAVE_POWER8
return isSSE42() ? ExtendImpl<Fast_CRC32> : ExtendImpl<Slow_CRC32>;
#else
return isAltiVec() ? ExtendPPCImpl : ExtendImpl<Slow_CRC32>;
#endif
}

bool IsFastCrc32Supported() {
bool has_fast_crc = false;
#ifdef HAVE_POWER8
#ifdef HAS_ALTIVEC
if (arch_ppc_probe()) {
has_fast_crc = true;
}
#else
has_fast_crc = false;
#endif
#else
has_fast_crc = isSSE42();
#endif
return has_fast_crc;
return isSSE42();
}

Function ChosenExtend = Choose_Extend();
Expand Down
95 changes: 0 additions & 95 deletions util/crc32c_ppc.c

This file was deleted.

Loading

0 comments on commit c281b44

Please sign in to comment.