Commit d637ab91 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[c++11] Replace V8_ALIGNAS and V8_ALIGNED by alignas

C++ introduces the {alignas} keyword, which can be used with types or
integral constant expressions. Use this instead of the V8_ALIGNAS (for
types) or V8_ALIGNED (for integral constants) macros.

R=ulan@chromium.org

Bug: v8:8562
Change-Id: I54999b56a5715237f88c63d8543ef728a5b2eff5
Reviewed-on: https://chromium-review.googlesource.com/c/1379935Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58290}
parent b5a2839b
......@@ -161,14 +161,12 @@
//
// C++11 feature detection
//
// V8_HAS_CXX11_ALIGNAS - alignas specifier supported
// V8_HAS_CXX11_ALIGNOF - alignof(type) operator supported
//
// Compiler-specific feature detection
//
// V8_HAS___ALIGNOF - __alignof(type) operator supported
// V8_HAS___ALIGNOF__ - __alignof__(type) operator supported
// V8_HAS_ATTRIBUTE_ALIGNED - __attribute__((aligned(n))) supported
// V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline))
// supported
// V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported
......@@ -188,7 +186,6 @@
// V8_HAS_BUILTIN_SADD_OVERFLOW - __builtin_sadd_overflow() supported
// V8_HAS_BUILTIN_SSUB_OVERFLOW - __builtin_ssub_overflow() supported
// V8_HAS_BUILTIN_UADD_OVERFLOW - __builtin_uadd_overflow() supported
// V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported
// V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported
// V8_HAS_DECLSPEC_NOINLINE - __declspec(noinline) supported
// V8_HAS_DECLSPEC_SELECTANY - __declspec(selectany) supported
......@@ -211,7 +208,6 @@
# define V8_HAS___ALIGNOF 1
# define V8_HAS___ALIGNOF__ V8_HAS___ALIGNOF
# define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned))
# define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
# define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated))
# define V8_HAS_ATTRIBUTE_DEPRECATED_MESSAGE \
......@@ -234,8 +230,6 @@
# define V8_HAS_BUILTIN_SSUB_OVERFLOW (__has_builtin(__builtin_ssub_overflow))
# define V8_HAS_BUILTIN_UADD_OVERFLOW (__has_builtin(__builtin_uadd_overflow))
# define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas))
# if __cplusplus >= 201402L
# define V8_CAN_HAVE_DCHECK_IN_CONSTEXPR 1
# endif
......@@ -256,7 +250,6 @@
# define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(4, 3, 0))
# define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0))
// always_inline is available in gcc 4.0 but not very reliable until 4.4.
// Works around "sorry, unimplemented: inlining failed" build errors with
// older compilers.
......@@ -276,7 +269,6 @@
# define V8_HAS_BUILTIN_POPCOUNT (V8_GNUC_PREREQ(3, 4, 0))
# if __cplusplus >= 201103L
# define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0))
# define V8_HAS_CXX11_ALIGNOF (V8_GNUC_PREREQ(4, 8, 0))
# endif
#endif
......@@ -285,7 +277,6 @@
# define V8_CC_MSVC 1
# define V8_HAS___ALIGNOF 1
# define V8_HAS_DECLSPEC_ALIGN 1
# define V8_HAS_DECLSPEC_DEPRECATED 1
# define V8_HAS_DECLSPEC_NOINLINE 1
# define V8_HAS_DECLSPEC_SELECTANY 1
......@@ -363,39 +354,6 @@
#endif
// This macro allows to specify memory alignment for structs, classes, etc.
// Use like:
// class V8_ALIGNED(16) MyClass { ... };
// V8_ALIGNED(32) int array[42];
#if V8_HAS_CXX11_ALIGNAS
# define V8_ALIGNED(n) alignas(n)
#elif V8_HAS_ATTRIBUTE_ALIGNED
# define V8_ALIGNED(n) __attribute__((aligned(n)))
#elif V8_HAS_DECLSPEC_ALIGN
# define V8_ALIGNED(n) __declspec(align(n))
#else
# define V8_ALIGNED(n) /* NOT SUPPORTED */
#endif
// This macro is similar to V8_ALIGNED(), but takes a type instead of size
// in bytes. If the compiler does not supports using the alignment of the
// |type|, it will align according to the |alignment| instead. For example,
// Visual Studio C++ cannot combine __declspec(align) and __alignof. The
// |alignment| must be a literal that is used as a kind of worst-case fallback
// alignment.
// Use like:
// struct V8_ALIGNAS(AnotherClass, 16) NewClass { ... };
// V8_ALIGNAS(double, 8) int array[100];
#if V8_HAS_CXX11_ALIGNAS
# define V8_ALIGNAS(type, alignment) alignas(type)
#elif V8_HAS___ALIGNOF__ && V8_HAS_ATTRIBUTE_ALIGNED
# define V8_ALIGNAS(type, alignment) __attribute__((aligned(__alignof__(type))))
#else
# define V8_ALIGNAS(type, alignment) V8_ALIGNED(alignment)
#endif
// This macro returns alignment in bytes (an integer power of two) required for
// any instance of the given type, which is either complete type, an array type,
// or a reference type.
......
......@@ -68,6 +68,8 @@
#ifndef V8_BASE_LAZY_INSTANCE_H_
#define V8_BASE_LAZY_INSTANCE_H_
#include <type_traits>
#include "src/base/macros.h"
#include "src/base/once.h"
......@@ -92,12 +94,8 @@ struct LeakyInstanceTrait {
template <typename T>
struct StaticallyAllocatedInstanceTrait {
// 16-byte alignment fallback to be on the safe side here.
struct V8_ALIGNAS(T, 16) StorageType {
char x[sizeof(T)];
};
STATIC_ASSERT(V8_ALIGNOF(StorageType) >= V8_ALIGNOF(T));
using StorageType =
typename std::aligned_storage<sizeof(T), alignof(T)>::type;
static T* MutableInstance(StorageType* storage) {
return reinterpret_cast<T*>(storage);
......@@ -112,7 +110,7 @@ struct StaticallyAllocatedInstanceTrait {
template <typename T>
struct DynamicallyAllocatedInstanceTrait {
typedef T* StorageType;
using StorageType = T*;
static T* MutableInstance(StorageType* storage) {
return *storage;
......@@ -165,7 +163,7 @@ template <typename T, typename AllocationTrait, typename CreateTrait,
typename InitOnceTrait, typename DestroyTrait /* not used yet. */>
struct LazyInstanceImpl {
public:
typedef typename AllocationTrait::StorageType StorageType;
using StorageType = typename AllocationTrait::StorageType;
private:
static void InitInstance(void* storage) {
......
......@@ -64,27 +64,27 @@ constexpr uint64_t double_the_hole_nan_constant = kHoleNanInt64;
constexpr double double_uint32_bias_constant =
static_cast<double>(kMaxUInt32) + 1;
constexpr struct V8_ALIGNED(16) {
constexpr struct alignas(16) {
uint32_t a;
uint32_t b;
uint32_t c;
uint32_t d;
} float_absolute_constant = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
constexpr struct V8_ALIGNED(16) {
constexpr struct alignas(16) {
uint32_t a;
uint32_t b;
uint32_t c;
uint32_t d;
} float_negate_constant = {0x80000000, 0x80000000, 0x80000000, 0x80000000};
constexpr struct V8_ALIGNED(16) {
constexpr struct alignas(16) {
uint64_t a;
uint64_t b;
} double_absolute_constant = {uint64_t{0x7FFFFFFFFFFFFFFF},
uint64_t{0x7FFFFFFFFFFFFFFF}};
constexpr struct V8_ALIGNED(16) {
constexpr struct alignas(16) {
uint64_t a;
uint64_t b;
} double_negate_constant = {uint64_t{0x8000000000000000},
......
......@@ -46,7 +46,7 @@ class SamplingCircularQueue {
// completely processed by the consumer.
};
struct V8_ALIGNED(PROCESSOR_CACHE_LINE_SIZE) Entry {
struct alignas(PROCESSOR_CACHE_LINE_SIZE) Entry {
Entry() : marker(kEmpty) {}
T record;
base::Atomic32 marker;
......@@ -55,8 +55,8 @@ class SamplingCircularQueue {
Entry* Next(Entry* entry);
Entry buffer_[Length];
V8_ALIGNED(PROCESSOR_CACHE_LINE_SIZE) Entry* enqueue_pos_;
V8_ALIGNED(PROCESSOR_CACHE_LINE_SIZE) Entry* dequeue_pos_;
alignas(PROCESSOR_CACHE_LINE_SIZE) Entry* enqueue_pos_;
alignas(PROCESSOR_CACHE_LINE_SIZE) Entry* dequeue_pos_;
DISALLOW_COPY_AND_ASSIGN(SamplingCircularQueue);
};
......
......@@ -1061,7 +1061,7 @@ void MixedParamTest(int start) {
Handle<Code> wrapper = Handle<Code>::null();
int32_t expected_ret;
char bytes[kDoubleSize];
V8_ALIGNED(8) char output[kDoubleSize];
alignas(8) char output[kDoubleSize];
int expected_size = 0;
CSignatureOf<int32_t> csig;
{
......
......@@ -223,7 +223,7 @@ class TestingModuleBuilder {
uint32_t global_offset = 0;
byte* mem_start_ = nullptr;
uint32_t mem_size_ = 0;
V8_ALIGNED(16) byte globals_data_[kMaxGlobalsSize];
alignas(16) byte globals_data_[kMaxGlobalsSize];
WasmInterpreter* interpreter_ = nullptr;
ExecutionTier execution_tier_;
Handle<WasmInstanceObject> instance_object_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment