[libcxx-commits] [libcxx] 56a33ba - [libc++] Implement P0154R1 (Hardware inference size)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 22 16:31:30 PDT 2022


Author: Nikolas Klauser
Date: 2022-06-23T01:31:09+02:00
New Revision: 56a33ba3dd2bfd411e77946871814e98d92ec2fa

URL: https://github.com/llvm/llvm-project/commit/56a33ba3dd2bfd411e77946871814e98d92ec2fa
DIFF: https://github.com/llvm/llvm-project/commit/56a33ba3dd2bfd411e77946871814e98d92ec2fa.diff

LOG: [libc++] Implement P0154R1 (Hardware inference size)

`__GCC_CONSTRUCTIVE_SIZE` and `__GCC_DESTRUCTIVE_SIZE` are available since GCC 12. I'm assuming clang will also implement these for compatability with libstdc++.

Reviewed By: ldionne, #libc

Spies: h-vetinari, libcxx-commits, arichardson

Differential Revision: https://reviews.llvm.org/D122276

Added: 
    libcxx/test/std/language.support/support.dynamic/hardware_inference_size.compile.pass.cpp

Modified: 
    libcxx/docs/FeatureTestMacroTable.rst
    libcxx/docs/ReleaseNotes.rst
    libcxx/docs/Status/Cxx17.rst
    libcxx/docs/Status/Cxx17Papers.csv
    libcxx/include/new
    libcxx/include/version
    libcxx/test/std/language.support/support.limits/support.limits.general/new.version.compile.pass.cpp
    libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
    libcxx/utils/generate_feature_test_macro_components.py

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst
index 020ef2aae744..f615b405edf8 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -100,7 +100,7 @@ Status
     ------------------------------------------------- -----------------
     ``__cpp_lib_gcd_lcm``                             ``201606L``
     ------------------------------------------------- -----------------
-    ``__cpp_lib_hardware_interference_size``          *unimplemented*
+    ``__cpp_lib_hardware_interference_size``          ``201703L``
     ------------------------------------------------- -----------------
     ``__cpp_lib_has_unique_object_representations``   ``201606L``
     ------------------------------------------------- -----------------

diff  --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst
index c5d1907d4caf..c7f9cb3c270f 100644
--- a/libcxx/docs/ReleaseNotes.rst
+++ b/libcxx/docs/ReleaseNotes.rst
@@ -45,6 +45,7 @@ Implemented Papers
 - P2216R3 (std::format improvements)
 - P0174R2 (Deprecating Vestigial Library Parts in C++17)
 - N4190 (Removing auto_ptr, random_shuffle(), And Old <functional> Stuff)
+- P0154R1 (Hardware inference size)
 
 - Marked the following papers as "Complete" (note that some of those might have
   been implemented in a previous release but not marked as such):

diff  --git a/libcxx/docs/Status/Cxx17.rst b/libcxx/docs/Status/Cxx17.rst
index 26bf0ad6be68..96c010cf47e5 100644
--- a/libcxx/docs/Status/Cxx17.rst
+++ b/libcxx/docs/Status/Cxx17.rst
@@ -42,7 +42,7 @@ Paper Status
 
    .. [#note-P0067] P0067: ``std::(to|from)_chars`` for integrals has been available since version 7.0. ``std::to_chars`` for ``float`` and ``double`` since version 14.0 ``std::to_chars`` for ``long double`` uses the implementation for ``double``.
    .. [#note-P0607] P0607: The parts of P0607 that are not done are the ``<regex>`` bits.
-
+   .. [#note-P0154] P0154: This is currently not implemented for clang because clang does not implement the required macros.
 
 .. _issues-status-cxx17:
 

diff  --git a/libcxx/docs/Status/Cxx17Papers.csv b/libcxx/docs/Status/Cxx17Papers.csv
index 2a996cea4126..84904ac7a82c 100644
--- a/libcxx/docs/Status/Cxx17Papers.csv
+++ b/libcxx/docs/Status/Cxx17Papers.csv
@@ -35,7 +35,7 @@
 "`P0185R1 <https://wg21.link/P0185R1>`__","LWG","Adding [nothrow-]swappable traits","Jacksonville","|Complete|","3.9"
 "`P0253R1 <https://wg21.link/P0253R1>`__","LWG","Fixing a design mistake in the searchers interface","Jacksonville","|Complete|","3.9"
 "`P0025R0 <https://wg21.link/P0025R0>`__","LWG","An algorithm to ""clamp"" a value between a pair of boundary values","Jacksonville","|Complete|","3.9"
-"`P0154R1 <https://wg21.link/P0154R1>`__","LWG","constexpr std::hardware_{constructive,destructive}_interference_size","Jacksonville","",""
+"`P0154R1 <https://wg21.link/P0154R1>`__","LWG","constexpr std::hardware_{constructive,destructive}_interference_size","Jacksonville","|Partial| [#note-P0154]_","15.0"
 "`P0030R1 <https://wg21.link/P0030R1>`__","LWG","Proposal to Introduce a 3-Argument Overload to std::hypot","Jacksonville","|Complete|","3.9"
 "`P0031R0 <https://wg21.link/P0031R0>`__","LWG","A Proposal to Add Constexpr Modifiers to reverse_iterator, move_iterator, array and Range Access","Jacksonville","|Complete|","4.0"
 "`P0272R1 <https://wg21.link/P0272R1>`__","LWG","Give ``std::string``\  a non-const ``.data()``\  member function","Jacksonville","|Complete|","3.9"

diff  --git a/libcxx/include/new b/libcxx/include/new
index e91a42253d5b..ed95caed1c41 100644
--- a/libcxx/include/new
+++ b/libcxx/include/new
@@ -360,6 +360,17 @@ constexpr _Tp* launder(_Tp* __p) noexcept
 }
 #endif
 
+#if _LIBCPP_STD_VER > 14
+
+#if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
+
+inline constexpr size_t hardware_destructive_interference_size = __GCC_DESTRUCTIVE_SIZE;
+inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
+
+#endif // defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
+
+#endif // _LIBCPP_STD_VER > 14
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP_NEW

diff  --git a/libcxx/include/version b/libcxx/include/version
index dcebba4d6d50..2034e4b1f3d9 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -247,7 +247,9 @@ __cpp_lib_void_t                                        201411L <type_traits>
 #   define __cpp_lib_filesystem                         201703L
 # endif
 # define __cpp_lib_gcd_lcm                              201606L
-// # define __cpp_lib_hardware_interference_size           201703L
+# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
+#   define __cpp_lib_hardware_interference_size         201703L
+# endif
 # define __cpp_lib_has_unique_object_representations    201606L
 # define __cpp_lib_hypot                                201603L
 # define __cpp_lib_incomplete_container_elements        201505L

diff  --git a/libcxx/test/std/language.support/support.dynamic/hardware_inference_size.compile.pass.cpp b/libcxx/test/std/language.support/support.dynamic/hardware_inference_size.compile.pass.cpp
new file mode 100644
index 000000000000..ae277d53e46f
--- /dev/null
+++ b/libcxx/test/std/language.support/support.dynamic/hardware_inference_size.compile.pass.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+// XFAIL: (clang || apple-clang) && stdlib=libc++
+
+#include <new>
+
+#include "test_macros.h"
+
+ASSERT_SAME_TYPE(decltype(std::hardware_destructive_interference_size), const std::size_t);
+ASSERT_SAME_TYPE(decltype(std::hardware_constructive_interference_size), const std::size_t);

diff  --git a/libcxx/test/std/language.support/support.limits/support.limits.general/new.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/new.version.compile.pass.cpp
index ca8fead1b975..da1d9d48597b 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/new.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/new.version.compile.pass.cpp
@@ -58,16 +58,16 @@
 #   error "__cpp_lib_destroying_delete should not be defined before c++20"
 # endif
 
-# if !defined(_LIBCPP_VERSION)
+# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
 #   ifndef __cpp_lib_hardware_interference_size
 #     error "__cpp_lib_hardware_interference_size should be defined in c++17"
 #   endif
 #   if __cpp_lib_hardware_interference_size != 201703L
 #     error "__cpp_lib_hardware_interference_size should have the value 201703L in c++17"
 #   endif
-# else // _LIBCPP_VERSION
+# else
 #   ifdef __cpp_lib_hardware_interference_size
-#     error "__cpp_lib_hardware_interference_size should not be defined because it is unimplemented in libc++!"
+#     error "__cpp_lib_hardware_interference_size should not be defined when defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE) is not defined!"
 #   endif
 # endif
 
@@ -93,16 +93,16 @@
 #   endif
 # endif
 
-# if !defined(_LIBCPP_VERSION)
+# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
 #   ifndef __cpp_lib_hardware_interference_size
 #     error "__cpp_lib_hardware_interference_size should be defined in c++20"
 #   endif
 #   if __cpp_lib_hardware_interference_size != 201703L
 #     error "__cpp_lib_hardware_interference_size should have the value 201703L in c++20"
 #   endif
-# else // _LIBCPP_VERSION
+# else
 #   ifdef __cpp_lib_hardware_interference_size
-#     error "__cpp_lib_hardware_interference_size should not be defined because it is unimplemented in libc++!"
+#     error "__cpp_lib_hardware_interference_size should not be defined when defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE) is not defined!"
 #   endif
 # endif
 
@@ -128,16 +128,16 @@
 #   endif
 # endif
 
-# if !defined(_LIBCPP_VERSION)
+# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
 #   ifndef __cpp_lib_hardware_interference_size
 #     error "__cpp_lib_hardware_interference_size should be defined in c++2b"
 #   endif
 #   if __cpp_lib_hardware_interference_size != 201703L
 #     error "__cpp_lib_hardware_interference_size should have the value 201703L in c++2b"
 #   endif
-# else // _LIBCPP_VERSION
+# else
 #   ifdef __cpp_lib_hardware_interference_size
-#     error "__cpp_lib_hardware_interference_size should not be defined because it is unimplemented in libc++!"
+#     error "__cpp_lib_hardware_interference_size should not be defined when defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE) is not defined!"
 #   endif
 # endif
 

diff  --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
index 57022878f987..3e4e3a854e06 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
@@ -1806,16 +1806,16 @@
 #   error "__cpp_lib_generic_unordered_lookup should not be defined before c++20"
 # endif
 
-# if !defined(_LIBCPP_VERSION)
+# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
 #   ifndef __cpp_lib_hardware_interference_size
 #     error "__cpp_lib_hardware_interference_size should be defined in c++17"
 #   endif
 #   if __cpp_lib_hardware_interference_size != 201703L
 #     error "__cpp_lib_hardware_interference_size should have the value 201703L in c++17"
 #   endif
-# else // _LIBCPP_VERSION
+# else
 #   ifdef __cpp_lib_hardware_interference_size
-#     error "__cpp_lib_hardware_interference_size should not be defined because it is unimplemented in libc++!"
+#     error "__cpp_lib_hardware_interference_size should not be defined when defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE) is not defined!"
 #   endif
 # endif
 
@@ -2851,16 +2851,16 @@
 #   error "__cpp_lib_generic_unordered_lookup should have the value 201811L in c++20"
 # endif
 
-# if !defined(_LIBCPP_VERSION)
+# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
 #   ifndef __cpp_lib_hardware_interference_size
 #     error "__cpp_lib_hardware_interference_size should be defined in c++20"
 #   endif
 #   if __cpp_lib_hardware_interference_size != 201703L
 #     error "__cpp_lib_hardware_interference_size should have the value 201703L in c++20"
 #   endif
-# else // _LIBCPP_VERSION
+# else
 #   ifdef __cpp_lib_hardware_interference_size
-#     error "__cpp_lib_hardware_interference_size should not be defined because it is unimplemented in libc++!"
+#     error "__cpp_lib_hardware_interference_size should not be defined when defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE) is not defined!"
 #   endif
 # endif
 
@@ -4088,16 +4088,16 @@
 #   error "__cpp_lib_generic_unordered_lookup should have the value 201811L in c++2b"
 # endif
 
-# if !defined(_LIBCPP_VERSION)
+# if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
 #   ifndef __cpp_lib_hardware_interference_size
 #     error "__cpp_lib_hardware_interference_size should be defined in c++2b"
 #   endif
 #   if __cpp_lib_hardware_interference_size != 201703L
 #     error "__cpp_lib_hardware_interference_size should have the value 201703L in c++2b"
 #   endif
-# else // _LIBCPP_VERSION
+# else
 #   ifdef __cpp_lib_hardware_interference_size
-#     error "__cpp_lib_hardware_interference_size should not be defined because it is unimplemented in libc++!"
+#     error "__cpp_lib_hardware_interference_size should not be defined when defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE) is not defined!"
 #   endif
 # endif
 

diff  --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index f1977b58b704..0e9ae78efe22 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -329,8 +329,9 @@ def add_version_header(tc):
   }, {
     "name": "__cpp_lib_hardware_interference_size",
     "values": { "c++17": 201703 },
+    "test_suite_guard": "defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)",
+    "libcxx_guard": "defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)",
     "headers": ["new"],
-    "unimplemented": True,
   }, {
     "name": "__cpp_lib_has_unique_object_representations",
     "values": { "c++17": 201606 },


        


More information about the libcxx-commits mailing list