This is an automated email from the ASF dual-hosted git repository.
zhaoc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new 2a8e77d Support arm atomicops (#2626) (#2627)
2a8e77d is described below
commit 2a8e77d9cb7bf0be0532f9b60081baa8dbc88f4f
Author: yangzhg <[email protected]>
AuthorDate: Tue Dec 31 22:39:22 2019 +0800
Support arm atomicops (#2626) (#2627)
---
be/CMakeLists.txt | 11 +-
be/src/gutil/CMakeLists.txt | 58 +++++----
be/src/gutil/atomicops-internals-gcc.h | 222 +++++++++++++++++++++++++++++++++
be/src/gutil/atomicops.h | 12 ++
4 files changed, 276 insertions(+), 27 deletions(-)
diff --git a/be/CMakeLists.txt b/be/CMakeLists.txt
index 53cd74a..5a82572 100644
--- a/be/CMakeLists.txt
+++ b/be/CMakeLists.txt
@@ -39,6 +39,13 @@ endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
message(STATUS "Build type is ${CMAKE_BUILD_TYPE}")
+# set CMAKE_BUILD_TARGET_ARCH
+execute_process(COMMAND bash "-c" "lscpu | grep 'Architecture' | awk '{print
$2}'"
+ OUTPUT_VARIABLE
+ CMAKE_BUILD_TARGET_ARCH
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+message(STATUS "Build target arch is ${CMAKE_BUILD_TARGET_ARCH}")
+
# Set dirs
set(BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(ENV{DORIS_HOME} "${BASE_DIR}/../")
@@ -322,7 +329,9 @@ set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -std=gnu++11
-D__STDC_FORMAT_MACROS")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-deprecated -Wno-vla")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS}
-DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -DBOOST_SYSTEM_NO_DEPRECATED")
-set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -msse4.2")
+if ("${CMAKE_BUILD_TARGET_ARCH}" STREQUAL "x86" OR
"${CMAKE_BUILD_TARGET_ARCH}" STREQUAL "x86_64")
+ set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -msse4.2")
+endif()
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -DLLVM_ON_UNIX")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-attributes -DS2_USE_GFLAGS
-DS2_USE_GLOG")
diff --git a/be/src/gutil/CMakeLists.txt b/be/src/gutil/CMakeLists.txt
index 1523da9..2c0d283 100644
--- a/be/src/gutil/CMakeLists.txt
+++ b/be/src/gutil/CMakeLists.txt
@@ -23,32 +23,37 @@ set(LIBRARY_OUTPUT_PATH "${BUILD_DIR}/src/gutil")
# where to put generated binaries
set(EXECUTABLE_OUTPUT_PATH "${BUILD_DIR}/src/gutil")
-add_library(Gutil STATIC
- atomicops-internals-x86.cc
- bits.cc
- dynamic_annotations.c
- hash/city.cc
- hash/hash.cc
- hash/jenkins.cc
- int128.cc
- once.cc
- spinlock_internal.cc
- stringprintf.cc
- strings/ascii_ctype.cc
- strings/charset.cc
- strings/escaping.cc
- strings/join.cc
- strings/memutil.cc
- strings/numbers.cc
- strings/split.cc
- strings/strip.cc
- strings/strcat.cc
- strings/stringpiece.cc
- strings/substitute.cc
- strings/util.cc
- strtoint.cc
- utf/rune.c
- cpu.cc)
+SET(SOURCE_FILES
+ bits.cc
+ dynamic_annotations.c
+ hash/city.cc
+ hash/hash.cc
+ hash/jenkins.cc
+ int128.cc
+ once.cc
+ spinlock_internal.cc
+ stringprintf.cc
+ strings/ascii_ctype.cc
+ strings/charset.cc
+ strings/escaping.cc
+ strings/join.cc
+ strings/memutil.cc
+ strings/numbers.cc
+ strings/split.cc
+ strings/strip.cc
+ strings/strcat.cc
+ strings/stringpiece.cc
+ strings/substitute.cc
+ strings/util.cc
+ strtoint.cc
+ utf/rune.c
+ cpu.cc)
+
+if ("${CMAKE_BUILD_TARGET_ARCH}" STREQUAL "x86" OR
"${CMAKE_BUILD_TARGET_ARCH}" STREQUAL "x86_64")
+ set(SOURCE_FILES ${SOURCE_FILES} atomicops-internals-x86.cc)
+endif()
+
+add_library(Gutil STATIC ${SOURCE_FILES})
set_target_properties(Gutil PROPERTIES COMPILE_FLAGS "-funsigned-char
-Wno-deprecated -Wno-char-subscripts")
# target_link_libraries(Gutil glog protobuf rt)
@@ -70,3 +75,4 @@ set_target_properties(Gutil PROPERTIES COMPILE_FLAGS
"-funsigned-char -Wno-depre
# COMPILE_FLAGS "-funsigned-char -Wno-deprecated -Wno-char-subscripts")
#add_kudu_test(strings/string_util-test)
+
diff --git a/be/src/gutil/atomicops-internals-gcc.h
b/be/src/gutil/atomicops-internals-gcc.h
new file mode 100644
index 0000000..26e32e0
--- /dev/null
+++ b/be/src/gutil/atomicops-internals-gcc.h
@@ -0,0 +1,222 @@
+// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
+// Copyright (c) 2014, Linaro
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// ---
+//
+// Author: Riku Voipio, [email protected]
+//
+// atomic primitives implemented with gcc atomic intrinsics:
+// http://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
+//
+
+#ifndef BASE_ATOMICOPS_INTERNALS_GCC_GENERIC_H_
+#define BASE_ATOMICOPS_INTERNALS_GCC_GENERIC_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "gutil/basictypes.h"
+
+typedef int32_t Atomic32;
+
+namespace base {
+namespace subtle {
+
+typedef int64_t Atomic64;
+
+inline void MemoryBarrier() {
+ __sync_synchronize();
+}
+
+inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
+ Atomic32 old_value,
+ Atomic32 new_value) {
+ Atomic32 prev_value = old_value;
+ __atomic_compare_exchange_n(ptr, &prev_value, new_value,
+ 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
+ return prev_value;
+}
+
+inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
+ Atomic32 new_value) {
+ return __atomic_exchange_n(const_cast<Atomic32*>(ptr), new_value,
__ATOMIC_RELAXED);
+}
+
+inline Atomic32 Acquire_AtomicExchange(volatile Atomic32* ptr,
+ Atomic32 new_value) {
+ return __atomic_exchange_n(const_cast<Atomic32*>(ptr), new_value,
__ATOMIC_ACQUIRE);
+}
+
+inline Atomic32 Release_AtomicExchange(volatile Atomic32* ptr,
+ Atomic32 new_value) {
+ return __atomic_exchange_n(const_cast<Atomic32*>(ptr), new_value,
__ATOMIC_RELEASE);
+}
+
+inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
+ Atomic32 increment) {
+ return __atomic_add_fetch(ptr, increment, __ATOMIC_RELAXED);
+}
+
+inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
+ Atomic32 increment) {
+ return __atomic_add_fetch(ptr, increment, __ATOMIC_SEQ_CST);
+}
+
+inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
+ Atomic32 old_value,
+ Atomic32 new_value) {
+ Atomic32 prev_value = old_value;
+ __atomic_compare_exchange_n(ptr, &prev_value, new_value,
+ 0, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED);
+ return prev_value;
+}
+
+inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
+ Atomic32 old_value,
+ Atomic32 new_value) {
+ Atomic32 prev_value = old_value;
+ __atomic_compare_exchange_n(ptr, &prev_value, new_value,
+ 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED);
+ return prev_value;
+}
+
+inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
+ *ptr = value;
+}
+
+inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
+ *ptr = value;
+ MemoryBarrier();
+}
+
+inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
+ MemoryBarrier();
+ *ptr = value;
+}
+
+inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
+ return *ptr;
+}
+
+inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
+ Atomic32 value = *ptr;
+ MemoryBarrier();
+ return value;
+}
+
+inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
+ MemoryBarrier();
+ return *ptr;
+}
+
+// 64-bit versions
+
+inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
+ Atomic64 old_value,
+ Atomic64 new_value) {
+ Atomic64 prev_value = old_value;
+ __atomic_compare_exchange_n(ptr, &prev_value, new_value,
+ 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
+ return prev_value;
+}
+
+inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
+ Atomic64 new_value) {
+ return __atomic_exchange_n(const_cast<Atomic64*>(ptr), new_value,
__ATOMIC_RELAXED);
+}
+
+inline Atomic64 Acquire_AtomicExchange(volatile Atomic64* ptr,
+ Atomic64 new_value) {
+ return __atomic_exchange_n(const_cast<Atomic64*>(ptr), new_value,
__ATOMIC_ACQUIRE);
+}
+
+inline Atomic64 Release_AtomicExchange(volatile Atomic64* ptr,
+ Atomic64 new_value) {
+ return __atomic_exchange_n(const_cast<Atomic64*>(ptr), new_value,
__ATOMIC_RELEASE);
+}
+
+inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
+ Atomic64 increment) {
+ return __atomic_add_fetch(ptr, increment, __ATOMIC_RELAXED);
+}
+
+inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
+ Atomic64 increment) {
+ return __sync_add_and_fetch(ptr, increment);
+}
+inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
+ Atomic64 old_value,
+ Atomic64 new_value) {
+ Atomic64 prev_value = old_value;
+ __atomic_compare_exchange_n(ptr, &prev_value, new_value,
+ 0, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED);
+ return prev_value;
+}
+
+inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
+ Atomic64 old_value,
+ Atomic64 new_value) {
+ Atomic64 prev_value = old_value;
+ __atomic_compare_exchange_n(ptr, &prev_value, new_value,
+ 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED);
+ return prev_value;
+}
+
+inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
+ *ptr = value;
+}
+
+inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
+ *ptr = value;
+ MemoryBarrier();
+}
+
+inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
+ MemoryBarrier();
+ *ptr = value;
+}
+
+inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
+ return *ptr;
+}
+
+inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
+ Atomic64 value = *ptr;
+ MemoryBarrier();
+ return value;
+}
+
+inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
+ MemoryBarrier();
+ return *ptr;
+}
+
+} // namespace base::subtle
+} // namespace base
+
+#endif // BASE_ATOMICOPS_INTERNALS_GCC_GENERIC_H_
diff --git a/be/src/gutil/atomicops.h b/be/src/gutil/atomicops.h
index ac0a0f7..ab8abd4 100644
--- a/be/src/gutil/atomicops.h
+++ b/be/src/gutil/atomicops.h
@@ -67,11 +67,23 @@
// #endif
// ------------------------------------------------------------------------
+#define GCC_VERSION (__GNUC__ * 10000 \
+ + __GNUC_MINOR__ * 100 \
+ + __GNUC_PATCHLEVEL__)
+
+#define CLANG_VERSION (__clang_major__ * 10000 \
+ + __clang_minor__ * 100 \
+ + __clang_patchlevel__)
+
// ThreadSanitizer provides own implementation of atomicops.
#if defined(THREAD_SANITIZER)
#include "gutil/atomicops-internals-tsan.h"
#elif defined(__GNUC__) && (defined(__i386) || defined(__x86_64__))
#include "gutil/atomicops-internals-x86.h"
+#elif defined(__GNUC__) && GCC_VERSION >= 40700
+#include "gutil/atomicops-internals-gcc.h"
+#elif defined(__clang__) && CLANG_VERSION >= 30400
+#include "gutil/atomicops-internals-gcc.h"
#else
#error You need to implement atomic operations for this architecture
#endif
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]