Skip to content

Commit d10f929

Browse files
committed
fix conversation
1 parent 783de73 commit d10f929

File tree

8 files changed

+70
-38
lines changed

8 files changed

+70
-38
lines changed

libcxx/docs/ReleaseNotes/22.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Improvements and New Features
8383
iterators, resulting in a performance improvement for ``std::deque<short>`` and
8484
``std::join_view<vector<vector<short>>>`` iterators.
8585

86-
- The performance of ``align`` has been improved about 3x by making it an inline function.
86+
- The performance of ``align`` has been improved about 2x by making it an inline function.
8787

8888
Deprecations and Removals
8989
-------------------------

libcxx/include/__configuration/abi.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,19 @@
9797
// so disable it.
9898
# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
9999
# endif
100-
// The PE/COFF format reports a linking error when encountering multiple symbol definitions where at least one is a
101-
// strong symbol. So we can't inlining a function without ABI breakchange.
102-
# if defined(_LIBCPP_OBJECT_FORMAT_COFF)
103-
# define _LIBCPP_DISABLE_INLINE_OPTIMIZE_BECAUSE_MULTIPLY_SYMBOLS_ERROR
104-
# endif
105100
// Feature macros for disabling pre ABI v1 features. All of these options
106101
// are deprecated.
107102
# if defined(__FreeBSD__)
108103
# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
109104
# endif
110105
#endif
111106

107+
// The PE/COFF format reports a linking error when encountering multiple symbol definitions where at least one is a
108+
// strong symbol. So we can't inlining a non-inline function without ABI break change.
109+
#if defined(_LIBCPP_OBJECT_FORMAT_COFF)
110+
# define _LIBCPP_DISABLE_INLINE_OPTIMIZE_BECAUSE_MULTIPLY_SYMBOLS_ERROR
111+
#endif
112+
112113
// TODO(LLVM 22): Remove this check
113114
#if defined(_LIBCPP_ABI_NO_ITERATOR_BASES) && !defined(_LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER)
114115
# ifndef _LIBCPP_ONLY_NO_ITERATOR_BASES

libcxx/include/__memory/align.h

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

2020
_LIBCPP_BEGIN_NAMESPACE_STD
2121

22-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE inline void*
23-
__align_impl(size_t __align, size_t __sz, void*& __ptr, size_t& __space) {
22+
#if defined(_LIBCPP_DISABLE_INLINE_OPTIMIZE_BECAUSE_MULTIPLY_SYMBOLS_ERROR) && !defined(_LIBCPP_ABI_DO_NOT_EXPORT_ALIGN)
23+
24+
_LIBCPP_EXPORTED_FROM_ABI void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
25+
26+
#else
27+
28+
_LIBCPP_HIDE_FROM_ABI inline void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space) {
2429
void* __r = nullptr;
2530
if (__sz <= __space) {
2631
char* __p1 = static_cast<char*>(__ptr);
@@ -35,20 +40,7 @@ __align_impl(size_t __align, size_t __sz, void*& __ptr, size_t& __space) {
3540
return __r;
3641
}
3742

38-
#ifndef _LIBCPP_EXPORT_ALIGN_SYMBOL
39-
# ifdef _LIBCPP_DISABLE_INLINE_OPTIMIZE_BECAUSE_MULTIPLY_SYMBOLS_ERROR
40-
41-
_LIBCPP_EXPORTED_FROM_ABI void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
42-
43-
# else
44-
45-
inline _LIBCPP_HIDE_FROM_ABI void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space) {
46-
return __align_impl(__align, __sz, __ptr, __space);
47-
}
48-
49-
# endif // _LIBCPP_DISABLE_INLINE_OPTIMIZE_BECAUSE_MULTIPLY_SYMBOLS_ERROR
50-
51-
#endif // _LIBCPP_EXPORT_ALIGN_SYMBOL
43+
#endif
5244

5345
_LIBCPP_END_NAMESPACE_STD
5446

libcxx/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ set(LIBCXX_SOURCES
3131
include/to_chars_floating_point.h
3232
include/from_chars_floating_point.h
3333
memory.cpp
34+
memory_align.cpp
3435
memory_resource.cpp
3536
new_handler.cpp
3637
new_helpers.cpp

libcxx/src/memory.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#ifdef _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
1111
# define _LIBCPP_SHARED_PTR_DEFINE_LEGACY_INLINE_FUNCTIONS
1212
#endif
13-
#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_ALIGN
14-
# define _LIBCPP_EXPORT_ALIGN_SYMBOL
15-
#endif
1613

1714
#include <__functional/hash.h>
1815
#include <memory>
@@ -135,12 +132,4 @@ __sp_mut& __get_sp_mut(const void* p) {
135132

136133
#endif // _LIBCPP_HAS_THREADS
137134

138-
#if defined(_LIBCPP_EXPORT_ALIGN_SYMBOL)
139-
140-
_LIBCPP_EXPORTED_FROM_ABI void* align(size_t alignment, size_t size, void*& ptr, size_t& space) {
141-
return __align_impl(alignment, size, ptr, space);
142-
}
143-
144-
#endif // _LIBCPP_EXPORT_ALIGN_SYMBOL
145-
146135
_LIBCPP_END_NAMESPACE_STD

libcxx/src/memory_align.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
#include <__config>
10+
#include <__cstddef/size_t.h>
11+
#include <cstdint>
12+
13+
// Don't include <memory> to avoid mulitple declartion of align()
14+
15+
#if !defined(_LIBCPP_ABI_DO_NOT_EXPORT_ALIGN)
16+
17+
_LIBCPP_BEGIN_NAMESPACE_STD
18+
19+
_LIBCPP_EXPORTED_FROM_ABI void* align(size_t alignment, size_t size, void*& ptr, size_t& space) {
20+
void* r = nullptr;
21+
if (size <= space) {
22+
char* p1 = static_cast<char*>(ptr);
23+
char* p2 = reinterpret_cast<char*>(reinterpret_cast<uintptr_t>(p1 + (alignment - 1)) & -alignment);
24+
size_t d = static_cast<size_t>(p2 - p1);
25+
if (d <= space - size) {
26+
r = p2;
27+
ptr = r;
28+
space -= d;
29+
}
30+
}
31+
return r;
32+
}
33+
34+
_LIBCPP_END_NAMESPACE_STD
35+
36+
#endif // _LIBCPP_ABI_DO_NOT_EXPORT_ALIGN

libcxx/test/benchmarks/memory/align.bench.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,29 @@
99
// UNSUPPORTED: c++03
1010

1111
#include <memory>
12+
#include <iostream>
1213

1314
#include "benchmark/benchmark.h"
14-
#include "test_macros.h"
15+
16+
struct Input {
17+
std::size_t align;
18+
std::size_t size;
19+
void* ptr;
20+
std::size_t buffer_size;
21+
};
1522

1623
static void BM_align(benchmark::State& state) {
1724
char buffer[1024];
18-
void* data = buffer + 123;
19-
std::size_t sz{sizeof(buffer) - 123};
20-
25+
Input input{};
26+
void* ptr = buffer + 123;
27+
std::size_t buffer_size = sizeof(buffer) - 123;
28+
input.align = state.range();
29+
input.size = state.range();
2130
for (auto _ : state) {
22-
benchmark::DoNotOptimize(std::align(state.range(), state.range(), data, sz));
31+
input.ptr = ptr;
32+
input.buffer_size = buffer_size;
33+
benchmark::DoNotOptimize(input);
34+
benchmark::DoNotOptimize(std::align(input.align, input.size, input.ptr, input.buffer_size));
2335
}
2436
}
2537
BENCHMARK(BM_align)->Range(1, 256);

llvm/utils/gn/secondary/libcxx/src/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ cxx_sources = [
152152
"iostream.cpp",
153153
"locale.cpp",
154154
"memory.cpp",
155+
"memory_align.cpp"
155156
"memory_resource.cpp",
156157
"mutex.cpp",
157158
"mutex_destructor.cpp",

0 commit comments

Comments
 (0)