Skip to content

Commit 0987145

Browse files
committed
also make align an inline function in v1 abi
1 parent 2be510f commit 0987145

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

libcxx/docs/ReleaseNotes/22.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ Improvements and New Features
8282
iterators, resulting in a performance improvement for ``std::deque<short>`` and
8383
``std::join_view<vector<vector<short>>>`` iterators.
8484

85+
- The performance of ``align`` has been improved about 3x by making it an inline function.
86+
8587
Deprecations and Removals
8688
-------------------------
8789

@@ -98,6 +100,8 @@ Potentially breaking changes
98100
``_LIBCPP_ABI_NO_ITERATOR_BASES``. If you are using this flag and care about ABI stability, you should set
99101
``_LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER`` as well.
100102

103+
- ``align`` has been removed from libc++ dynamic library in ABI v2. You could use the ABI flag ``_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS`` to reserve it.
104+
101105
Announcements About Future Releases
102106
-----------------------------------
103107

@@ -113,5 +117,7 @@ ABI Affecting Changes
113117
potentially inheriting from the types they wrap. At this point in time we are not aware of any ABI changes caused by
114118
this.
115119

120+
- ``align`` has been removed from libc++ dynamic library in ABI v2. You could use the ABI flag ``_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS`` to reserve it.
121+
116122
Build System Changes
117123
--------------------

libcxx/include/__memory/align.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919

2020
_LIBCPP_BEGIN_NAMESPACE_STD
2121

22-
// From >=v2 ABI, std::align is an inline function.
23-
#if _LIBCPP_ABI_VERSION >= 2
22+
#ifdef _LIBCPP_ALIGN_DEFINE_LEGACY_INLINE_FUNCTIONS
23+
24+
_LIBCPP_EXPORTED_FROM_ABI void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
25+
26+
#else
27+
2428
inline _LIBCPP_HIDE_FROM_ABI void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space) {
2529
void* __r = nullptr;
2630
if (__sz <= __space) {
@@ -35,9 +39,8 @@ inline _LIBCPP_HIDE_FROM_ABI void* align(size_t __align, size_t __sz, void*& __p
3539
}
3640
return __r;
3741
}
38-
#else
39-
_LIBCPP_EXPORTED_FROM_ABI void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
40-
#endif
42+
43+
#endif // _LIBCPP_ALIGN_DEFINE_LEGACY_INLINE_FUNCTIONS
4144

4245
_LIBCPP_END_NAMESPACE_STD
4346

libcxx/src/memory.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <__config>
1010
#ifdef _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
11+
# define _LIBCPP_ALIGN_DEFINE_LEGACY_INLINE_FUNCTIONS
1112
# define _LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS
1213
#endif
1314

@@ -132,8 +133,8 @@ __sp_mut& __get_sp_mut(const void* p) {
132133

133134
#endif // _LIBCPP_HAS_THREADS
134135

135-
// Remove std::align from >=v2 dylib ABI, make it an inline function.
136-
#if _LIBCPP_ABI_VERSION == 1
136+
#if defined(_LIBCPP_ALIGN_DEFINE_LEGACY_INLINE_FUNCTIONS)
137+
137138
void* align(size_t alignment, size_t size, void*& ptr, size_t& space) {
138139
void* r = nullptr;
139140
if (size <= space) {
@@ -148,6 +149,6 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space) {
148149
}
149150
return r;
150151
}
151-
#endif
152+
#endif // _LIBCPP_ALIGN_DEFINE_LEGACY_INLINE_FUNCTIONS
152153

153154
_LIBCPP_END_NAMESPACE_STD
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03
10+
11+
#include <memory>
12+
13+
#include "benchmark/benchmark.h"
14+
#include "test_macros.h"
15+
16+
static void BM_align(benchmark::State& state) {
17+
char buffer[1024];
18+
char* data = buffer + 123;
19+
std::size_t sz{1024 - 123};
20+
void* p;
21+
22+
for (auto _ : state) {
23+
benchmark::DoNotOptimize(std::align(state.range(), state.range(), p, sz))
24+
}
25+
}
26+
BENCHMARK(BM_align)->Range(1, 256);
27+
28+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)