From 909386110488fa94735072ae8ec23d400f611608 Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Wed, 4 May 2022 15:59:09 -0700 Subject: [PATCH 01/22] [benchmark] add gbenchmark --- .gitmodules | 3 + CMakeLists.txt | 5 + NOTICE.txt | 204 ++++++++++++++++++++++++++++++++++++ benchmarks/CMakeLists.txt | 102 ++++++++++++++++++ benchmarks/google-benchmark | 1 + benchmarks/inc/udt.hpp | 42 ++++++++ benchmarks/src/copy.cpp | 118 +++++++++++++++++++++ docs/cgmanifest.json | 9 ++ stl/CMakeLists.txt | 44 +++++--- 9 files changed, 515 insertions(+), 13 deletions(-) create mode 100644 benchmarks/CMakeLists.txt create mode 160000 benchmarks/google-benchmark create mode 100644 benchmarks/inc/udt.hpp create mode 100644 benchmarks/src/copy.cpp diff --git a/.gitmodules b/.gitmodules index d9ff8484bf9..a9b9368a9c4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "boost-math"] path = boost-math url = https://github.com/boostorg/math.git +[submodule "benchmarks/google-benchmark"] + path = benchmarks/google-benchmark + url = https://github.com/google/benchmark diff --git a/CMakeLists.txt b/CMakeLists.txt index f2724310240..16153a1b764 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ if(TARGET run-validate) endif() option(BUILD_TESTING "Enable testing" ON) +option(STL_BUILD_BENCHMARKING "Enable benchmarking" OFF) set(VCLIBS_SUFFIX "_oss" CACHE STRING "suffix for built DLL names to avoid conflicts with distributed DLLs") set(CMAKE_CXX_FLAGS "") @@ -121,3 +122,7 @@ if(BUILD_TESTING) enable_testing() add_subdirectory(tests) endif() + +if(STL_BUILD_BENCHMARKING) + add_subdirectory(benchmarks) +endif() diff --git a/NOTICE.txt b/NOTICE.txt index 8c846a8667a..d4bfe6ee380 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -216,3 +216,207 @@ In addition, certain files include the notices provided below. // shall not be used in advertising or otherwise to promote the sale, // use or other dealings in these Data Files or Software without prior // written authorization of the copyright holder. + +---------------------- + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt new file mode 100644 index 00000000000..968daf54e44 --- /dev/null +++ b/benchmarks/CMakeLists.txt @@ -0,0 +1,102 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +set(STL_BENCHMARK_FLAVOR_DYNAMIC_OR_STATIC + static + CACHE STRING "Whether to use the dynamic or static standard library" +) +set(STL_BENCHMARK_FLAVOR_DEBUG_OR_RELEASE + release + CACHE STRING "Whether to use the debug or release library" +) +set(STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING + default + CACHE STRING "What level of iterator debugging to use" +) + +if(STL_BENCHMARK_FLAVOR_DYNAMIC_OR_STATIC MATCHES "^[Dd][Yy][Nn][Aa][Mm][Ii][Cc]$") + set(stl_is_dynamic ON) +elseif(STL_BENCHMARK_FLAVOR_DYNAMIC_OR_STATIC MATCHES "^[Ss][Tt][Aa][Tt][Ii][Cc]$") + set(stl_is_dynamic OFF) +else() + message(FATAL_ERROR + "Invalid setting for STL_BENCHMARK_FLAVOR_DYNAMIC_OR_STATIC (${STL_BENCHMARK_FLAVOR_DYNAMIC_OR_STATIC})\n" + " expected one of 'dynamic', 'static'" + ) +endif() + +if(STL_BENCHMARK_FLAVOR_DEBUG_OR_RELEASE MATCHES "^[Rr][Ee][Ll][Ee][Aa][Ss][Ee]$") + set(stl_is_release ON) +elseif(STL_BENCHMARK_FLAVOR_DEBUG_OR_RELEASE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$") + set(stl_is_release OFF) +else() + message(FATAL_ERROR + "Invalid setting for STL_BENCHMARK_FLAVOR_DEBUG_OR_RELEASE (${STL_BENCHMARK_FLAVOR_DEBUG_OR_RELEASE})\n" + " expected one of 'release', 'debug'" + ) +endif() + +if(stl_is_release) + set(debug_flavor "") +else() + set(debug_flavor "d") +endif() + +set(iterator_debugging "") +if(STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING MATCHES "^[Dd][Ee][Ff][Aa][Uu][Ll][Tt]$") + # default +elseif(STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING STREQUAL "0") + if(NOT stl_is_release) + set(iterator_debugging "0") + endif() +elseif(STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING STREQUAL "1") + set(iterator_debugging "1") +elseif(STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING STREQUAL "2") + if(stl_is_release) + message(FATAL_ERROR "The release libraries do not support full iterator debugging") + endif() +else() + message(FATAL_ERROR + "Invalid setting for STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING (${STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING})\n" + " expected one of 'default', '0', '1', 2'" + ) +endif() + +if(stl_is_dynamic) + if(NOT iterator_debugging STREQUAL "") + message(FATAL_ERROR "The dynamic STL does not support non-default iterator debugging") + endif() + set(cxx_library "msvcp${debug_flavor}_implib") + set(c_library "msvcrt${debug_flavor}") +else() + set(cxx_library "libcpmt${debug_flavor}${iterator_debugging}") + set(c_library "libcmt${debug_flavor}") +endif() + +if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/google-benchmark") + message(FATAL_ERROR "google-benchmark is not checked out; make sure to run `git submodule update --init benchmarks/google-benchmark`") +endif() + +set(BENCHMARK_ENABLE_DOXYGEN OFF) +set(BENCHMARK_ENABLE_INSTALL OFF) +set(BENCHMARK_ENABLE_TESTING OFF) +set(HAVE_LIB_RT OFF) # for some reason, check_library_exists(rt) succeeds and it should not +add_subdirectory(google-benchmark) +target_link_libraries(benchmark PUBLIC "${cxx_library}" "${c_library}") +target_compile_options(benchmark PRIVATE ${VCLIBS_RELEASE_OPTIONS} /EHsc) +target_compile_options(benchmark_main PRIVATE ${VCLIBS_RELEASE_OPTIONS} /EHsc) + +file(GLOB benchmark_sources "src/*.cpp") + +add_executable(stl-benchmark + ${benchmark_sources} +) +target_include_directories(stl-benchmark PRIVATE inc) +target_link_libraries(stl-benchmark PRIVATE benchmark::benchmark benchmark::benchmark_main) +target_compile_options(stl-benchmark PRIVATE ${VCLIBS_RELEASE_OPTIONS} /EHsc) + +export( + TARGETS ${${cxx_library}_all_targets} + NAMESPACE "msvc_standard_library" + FILE "${CMAKE_CURRENT_BINARY_DIR}/stl-phony-targets-for-debug.cmake" +) diff --git a/benchmarks/google-benchmark b/benchmarks/google-benchmark new file mode 160000 index 00000000000..0d98dba29d6 --- /dev/null +++ b/benchmarks/google-benchmark @@ -0,0 +1 @@ +Subproject commit 0d98dba29d66e93259db7daa53a9327df767a415 diff --git a/benchmarks/inc/udt.hpp b/benchmarks/inc/udt.hpp new file mode 100644 index 00000000000..8fba92c02d4 --- /dev/null +++ b/benchmarks/inc/udt.hpp @@ -0,0 +1,42 @@ +#pragma once + +template +struct trivial { + Contained c; +}; + +template +inline bool operator==(const trivial& lhs, const trivial& rhs) { + return lhs.c == rhs.c; +} + +template +inline bool operator!=(const trivial& lhs, const trivial& rhs) { + return lhs.c != rhs.c; +} + +template +struct non_trivial { + Contained c; + non_trivial() : c() { /* user provided */ + } + non_trivial(const Contained& src) : c(src) {} + non_trivial(const non_trivial& other) : c(other.c) {} + non_trivial& operator=(const non_trivial& other) { + c = other.c; + return *this; + } + + ~non_trivial() { /* user provided */ + } +}; + +template +inline bool operator==(const non_trivial& lhs, const non_trivial& rhs) { + return lhs.c == rhs.c; +} + +template +inline bool operator!=(const non_trivial& lhs, const non_trivial& rhs) { + return lhs.c != rhs.c; +} diff --git a/benchmarks/src/copy.cpp b/benchmarks/src/copy.cpp new file mode 100644 index 00000000000..a5c32c19907 --- /dev/null +++ b/benchmarks/src/copy.cpp @@ -0,0 +1,118 @@ +#include +#include +#include +#include + +#include + +template +static void handwritten_loop(benchmark::State& state) { + const size_t r0 = static_cast(state.range(0)); + std::vector in_buffer(r0); + std::vector out_buffer(r0); + for (auto _ : state) { + (void) _; + benchmark::DoNotOptimize(in_buffer); + Contained* in_ptr = in_buffer.data(); + Contained* in_ptr_end = in_ptr + r0; + Contained* out_ptr = out_buffer.data(); + while (in_ptr != in_ptr_end) { + *out_ptr++ = *in_ptr++; + } + + benchmark::DoNotOptimize(out_buffer); + } +} + +template +static void handwritten_loop_n(benchmark::State& state) { + const size_t r0 = static_cast(state.range(0)); + std::vector in_buffer(r0); + std::vector out_buffer(r0); + for (auto _ : state) { + (void) _; + benchmark::DoNotOptimize(in_buffer); + Contained* in_ptr = in_buffer.data(); + Contained* out_ptr = out_buffer.data(); + for (size_t idx = 0, max = r0; idx < max; ++idx) { + out_ptr[idx] = in_ptr[idx]; + } + + benchmark::DoNotOptimize(out_buffer); + } +} + +template +static void memcpy_call(benchmark::State& state) { + const size_t r0 = static_cast(state.range(0)); + std::vector in_buffer(r0); + std::vector out_buffer(r0); + for (auto _ : state) { + (void) _; + benchmark::DoNotOptimize(in_buffer); + memcpy(in_buffer.data(), out_buffer.data(), r0 * sizeof(Contained)); + benchmark::DoNotOptimize(out_buffer); + } +} + +template +static void std_copy_call(benchmark::State& state) { + const size_t r0 = static_cast(state.range(0)); + std::vector in_buffer(r0); + std::vector out_buffer(r0); + for (auto _ : state) { + (void) _; + benchmark::DoNotOptimize(in_buffer); + std::copy(in_buffer.begin(), in_buffer.end(), out_buffer.begin()); + benchmark::DoNotOptimize(out_buffer); + } +} + +template +static void std_copy_n_call(benchmark::State& state) { + const size_t r0 = static_cast(state.range(0)); + std::vector in_buffer(r0); + std::vector out_buffer(r0); + for (auto _ : state) { + (void) _; + benchmark::DoNotOptimize(in_buffer); + std::copy_n(in_buffer.begin(), r0, out_buffer.begin()); + benchmark::DoNotOptimize(out_buffer); + } +} + +BENCHMARK_TEMPLATE1(handwritten_loop, char)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(handwritten_loop_n, char)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(memcpy_call, char)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(std_copy_call, char)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(std_copy_n_call, char)->Range(0, 1 << 18); + +BENCHMARK_TEMPLATE1(handwritten_loop, trivial)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(handwritten_loop_n, trivial)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(memcpy_call, trivial)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(std_copy_call, trivial)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(std_copy_n_call, trivial)->Range(0, 1 << 18); + +BENCHMARK_TEMPLATE1(handwritten_loop, non_trivial)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(handwritten_loop_n, non_trivial)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(std_copy_call, non_trivial)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(std_copy_n_call, non_trivial)->Range(0, 1 << 18); + +BENCHMARK_TEMPLATE1(handwritten_loop, int)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(handwritten_loop_n, int)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(memcpy_call, int)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(std_copy_call, int)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(std_copy_n_call, int)->Range(0, 1 << 15); + +BENCHMARK_TEMPLATE1(handwritten_loop, trivial)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(handwritten_loop_n, trivial)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(memcpy_call, trivial)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(std_copy_call, trivial)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(std_copy_n_call, trivial)->Range(0, 1 << 15); + +BENCHMARK_TEMPLATE1(handwritten_loop, non_trivial)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(handwritten_loop_n, non_trivial)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(std_copy_call, non_trivial)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(std_copy_n_call, non_trivial)->Range(0, 1 << 15); + +BENCHMARK_MAIN(); diff --git a/docs/cgmanifest.json b/docs/cgmanifest.json index 51c60a330bb..80cd8febcbc 100644 --- a/docs/cgmanifest.json +++ b/docs/cgmanifest.json @@ -44,6 +44,15 @@ "commitHash": "59661c3f883dfd39cef6dc8eaf2fcbaae53597e8" } } + }, + { + "component": { + "type": "git", + "git": { + "repositoryUrl": "https://github.com/google/benchmark", + "commitHash": "0d98dba29d66e93259db7daa53a9327df767a415" + } + } } ], "Version": 1 diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index ddc59d3df77..0491db76799 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -460,15 +460,15 @@ endif() function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIONS GL_FLAG THIS_CONFIG_LINK_OPTIONS) # msvcp140.dll add_library(msvcp${D_SUFFIX}_objects OBJECT ${DLL_SOURCES} ${SOURCES}) - target_compile_definitions(msvcp${D_SUFFIX}_objects PRIVATE "CRTDLL2;_DLL;${THIS_CONFIG_DEFINITIONS}") + target_compile_definitions(msvcp${D_SUFFIX}_objects PRIVATE CRTDLL2 PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) target_compile_options(msvcp${D_SUFFIX}_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") add_library(msvcp${D_SUFFIX}_init_objects OBJECT ${INITIALIZER_SOURCES}) - target_compile_definitions(msvcp${D_SUFFIX}_init_objects PRIVATE "CRTDLL2;_DLL;${THIS_CONFIG_DEFINITIONS}") + target_compile_definitions(msvcp${D_SUFFIX}_init_objects PRIVATE CRTDLL2 PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) target_compile_options(msvcp${D_SUFFIX}_init_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};/EHsc") add_library(msvcp${D_SUFFIX}_eha_objects OBJECT ${EHA_SOURCES}) - target_compile_definitions(msvcp${D_SUFFIX}_eha_objects PRIVATE "CRTDLL2;_DLL;${THIS_CONFIG_DEFINITIONS}") + target_compile_definitions(msvcp${D_SUFFIX}_eha_objects PRIVATE CRTDLL2 PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) target_compile_options(msvcp${D_SUFFIX}_eha_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHa") add_library(msvcp${D_SUFFIX} SHARED) @@ -480,16 +480,16 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO # import library 'statics' add_library(msvcp${D_SUFFIX}_implib_objects OBJECT ${IMPLIB_SOURCES}) - target_compile_definitions(msvcp${D_SUFFIX}_implib_objects PRIVATE "_DLL;${THIS_CONFIG_DEFINITIONS}") - target_compile_options(msvcp${D_SUFFIX}_implib_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};$<$:/EHsc>") # No /GL! + target_compile_definitions(msvcp${D_SUFFIX}_implib_objects PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) + target_compile_options(msvcp${D_SUFFIX}_implib_objects PRIVATE ${THIS_CONFIG_COMPILE_OPTIONS} /EHsc) # No /GL! add_library(msvcp${D_SUFFIX}_satellite_objects OBJECT ${SATELLITE_DLL_SOURCES}) + target_compile_definitions(msvcp${D_SUFFIX}_satellite_objects PRIVATE PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) target_compile_options(msvcp${D_SUFFIX}_satellite_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") - target_compile_definitions(msvcp${D_SUFFIX}_satellite_objects PRIVATE "_DLL;${THIS_CONFIG_DEFINITIONS}") # msvcp140_1.dll (the memory_resource satellite) add_library(msvcp_1${D_SUFFIX}_objects OBJECT ${SOURCES_SATELLITE_1}) - target_compile_definitions(msvcp_1${D_SUFFIX}_objects PRIVATE "_BUILDING_SATELLITE_1;_DLL;${THIS_CONFIG_DEFINITIONS}") + target_compile_definitions(msvcp_1${D_SUFFIX}_objects PRIVATE _BUILDING_SATELLITE_1 PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) target_compile_options(msvcp_1${D_SUFFIX}_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") add_library(msvcp_1${D_SUFFIX} SHARED) @@ -501,7 +501,7 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO # msvcp140_2.dll (the special math satellite) add_library(msvcp_2${D_SUFFIX}_objects OBJECT ${SOURCES_SATELLITE_2}) - target_compile_definitions(msvcp_2${D_SUFFIX}_objects PRIVATE "_BUILDING_SATELLITE_2;_DLL;${THIS_CONFIG_DEFINITIONS}") + target_compile_definitions(msvcp_2${D_SUFFIX}_objects PRIVATE _BUILDING_SATELLITE_2 PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) target_compile_options(msvcp_2${D_SUFFIX}_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") target_link_libraries(msvcp_2${D_SUFFIX}_objects PRIVATE Boost::math) @@ -514,7 +514,7 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO # msvcp140_atomic_wait.dll (the atomic wait satellite) add_library(msvcp${D_SUFFIX}_atomic_wait_objects OBJECT ${SOURCES_SATELLITE_ATOMIC_WAIT}) - target_compile_definitions(msvcp${D_SUFFIX}_atomic_wait_objects PRIVATE "_BUILDING_SATELLITE_ATOMIC_WAIT;_DLL;${THIS_CONFIG_DEFINITIONS}") + target_compile_definitions(msvcp${D_SUFFIX}_atomic_wait_objects PRIVATE _BUILDING_SATELLITE_ATOMIC_WAIT PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) target_compile_options(msvcp${D_SUFFIX}_atomic_wait_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") # generate the .def for msvcp140_atomic_wait.dll @@ -536,7 +536,7 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO # msvcp140_codecvt_ids.dll add_library(msvcp${D_SUFFIX}_codecvt_ids_objects OBJECT ${SOURCES_SATELLITE_CODECVT_IDS}) - target_compile_definitions(msvcp${D_SUFFIX}_codecvt_ids_objects PRIVATE "_BUILDING_SATELLITE_CODECVT_IDS;_DLL;${THIS_CONFIG_DEFINITIONS}") + target_compile_definitions(msvcp${D_SUFFIX}_codecvt_ids_objects PRIVATE _BUILDING_SATELLITE_CODECVT_IDS PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) target_compile_options(msvcp${D_SUFFIX}_codecvt_ids_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") add_library(msvcp${D_SUFFIX}_codecvt_ids SHARED) @@ -552,6 +552,15 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO add_dependencies(msvcp${D_SUFFIX}_implib msvcp${D_SUFFIX} msvcp_1${D_SUFFIX} msvcp_2${D_SUFFIX} msvcp${D_SUFFIX}_atomic_wait msvcp${D_SUFFIX}_codecvt_ids) set_target_properties(msvcp${D_SUFFIX}_implib PROPERTIES STATIC_LIBRARY_OPTIONS "/NOLOGO;/NODEFAULTLIB;/IGNORE:4006;$;$;$;$;$") set_target_properties(msvcp${D_SUFFIX}_implib PROPERTIES ARCHIVE_OUTPUT_NAME "msvcprt${D_SUFFIX}") + + # HACK: for benchmarking, we need to export the standard library since we link google benchmark to the stl targets, + # and CMake requires all targets depended upon by exported targets to themselves be exported. + set(msvcp${D_SUFFIX}_all_targets + boost_math + stl_alias_objects + msvcp${D_SUFFIX}_implib + CACHE INTERNAL "" + ) endfunction() add_stl_dlls("" "" "${VCLIBS_RELEASE_OPTIONS}" "/GL" "/LTCG;/opt:ref,icf") @@ -559,13 +568,22 @@ add_stl_dlls("d" "_DEBUG" "${VCLIBS_DEBUG_OPTIONS}" "" "/opt:ref,noicf") function(add_stl_statics FLAVOR_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIONS) add_library(libcpmt${FLAVOR_SUFFIX}_eha OBJECT ${EHA_SOURCES}) - target_compile_definitions(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE "${THIS_CONFIG_DEFINITIONS};_ANNOTATE_VECTOR;_ANNOTATE_STRING") + target_compile_definitions(libcpmt${FLAVOR_SUFFIX}_eha PUBLIC ${THIS_CONFIG_DEFINITIONS} PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING) target_compile_options(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};/EHa") - add_library(libcpmt${FLAVOR_SUFFIX} STATIC ${HEADERS} ${IMPLIB_SOURCES} ${SOURCES} ${INITIALIZER_SOURCES} ${STATIC_SOURCES}) - target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PRIVATE "${THIS_CONFIG_DEFINITIONS};_ANNOTATE_VECTOR;_ANNOTATE_STRING") + target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PUBLIC ${THIS_CONFIG_DEFINITIONS} PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING) target_compile_options(libcpmt${FLAVOR_SUFFIX} PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};$<$:/EHsc>") target_link_libraries(libcpmt${FLAVOR_SUFFIX} PRIVATE Boost::math stl_alias_objects libcpmt${FLAVOR_SUFFIX}_eha) + + # HACK: for benchmarking, we need to export the standard library since we link google benchmark to the stl targets, + # and CMake requires all targets depended upon by exported targets to themselves be exported. + set(libcpmt${FLAVOR_SUFFIX}_all_targets + boost_math + stl_alias_objects + libcpmt${FLAVOR_SUFFIX}_eha + libcpmt${FLAVOR_SUFFIX} + CACHE INTERNAL "" + ) endfunction() add_stl_statics("" "_ITERATOR_DEBUG_LEVEL=0" "${VCLIBS_RELEASE_OPTIONS}") From ecb07e6d5c88d9f908df0b8b75dd3935f175d72b Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Mon, 13 Jun 2022 09:07:53 -0700 Subject: [PATCH 02/22] [wip] (doesn't link rn) start working on comments --- .vscode/settings.json | 1 + NOTICE.txt | 204 -------------------------------------- benchmarks/CMakeLists.txt | 98 ++++-------------- benchmarks/inc/udt.hpp | 3 + benchmarks/src/copy.cpp | 3 + docs/cgmanifest.json | 9 -- stl/CMakeLists.txt | 19 ---- 7 files changed, 29 insertions(+), 308 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ed784500484..8bc25e769e7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,7 @@ }, "files.eol": "\r\n", "files.exclude": { + "benchmarks/google-benchmark": true, "llvm-project": true, "stl/msbuild": true, "boost-math": true diff --git a/NOTICE.txt b/NOTICE.txt index d4bfe6ee380..8c846a8667a 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -216,207 +216,3 @@ In addition, certain files include the notices provided below. // shall not be used in advertising or otherwise to promote the sale, // use or other dealings in these Data Files or Software without prior // written authorization of the copyright holder. - ----------------------- - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 968daf54e44..527eaea4307 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -1,77 +1,22 @@ # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -set(STL_BENCHMARK_FLAVOR_DYNAMIC_OR_STATIC - static - CACHE STRING "Whether to use the dynamic or static standard library" +set(STL_BENCHMARK_MSVC_RUNTIME_LIBRARY + MultiThreaded + CACHE STRING "The version of the standard library to use; see https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html for more information.") +set_property(CACHE STL_BENCHMARK_MSVC_RUNTIME_LIBRARY + PROPERTY STRINGS + "MultiThreaded;MultiThreadedDLL;MultiThreadedDebug;MultiThreadedDebugDLL" ) -set(STL_BENCHMARK_FLAVOR_DEBUG_OR_RELEASE - release - CACHE STRING "Whether to use the debug or release library" -) -set(STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING + +set(STL_BENCHMARK_ITERATOR_DEBUG_LEVEL default - CACHE STRING "What level of iterator debugging to use" + CACHE STRING "What level of iterator debugging to use." +) +set_property(CACHE STL_BENCHMARK_ITERATOR_DEBUG_LEVEL + PROPERTY STRINGS + "default;0;1;2" ) - -if(STL_BENCHMARK_FLAVOR_DYNAMIC_OR_STATIC MATCHES "^[Dd][Yy][Nn][Aa][Mm][Ii][Cc]$") - set(stl_is_dynamic ON) -elseif(STL_BENCHMARK_FLAVOR_DYNAMIC_OR_STATIC MATCHES "^[Ss][Tt][Aa][Tt][Ii][Cc]$") - set(stl_is_dynamic OFF) -else() - message(FATAL_ERROR - "Invalid setting for STL_BENCHMARK_FLAVOR_DYNAMIC_OR_STATIC (${STL_BENCHMARK_FLAVOR_DYNAMIC_OR_STATIC})\n" - " expected one of 'dynamic', 'static'" - ) -endif() - -if(STL_BENCHMARK_FLAVOR_DEBUG_OR_RELEASE MATCHES "^[Rr][Ee][Ll][Ee][Aa][Ss][Ee]$") - set(stl_is_release ON) -elseif(STL_BENCHMARK_FLAVOR_DEBUG_OR_RELEASE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$") - set(stl_is_release OFF) -else() - message(FATAL_ERROR - "Invalid setting for STL_BENCHMARK_FLAVOR_DEBUG_OR_RELEASE (${STL_BENCHMARK_FLAVOR_DEBUG_OR_RELEASE})\n" - " expected one of 'release', 'debug'" - ) -endif() - -if(stl_is_release) - set(debug_flavor "") -else() - set(debug_flavor "d") -endif() - -set(iterator_debugging "") -if(STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING MATCHES "^[Dd][Ee][Ff][Aa][Uu][Ll][Tt]$") - # default -elseif(STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING STREQUAL "0") - if(NOT stl_is_release) - set(iterator_debugging "0") - endif() -elseif(STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING STREQUAL "1") - set(iterator_debugging "1") -elseif(STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING STREQUAL "2") - if(stl_is_release) - message(FATAL_ERROR "The release libraries do not support full iterator debugging") - endif() -else() - message(FATAL_ERROR - "Invalid setting for STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING (${STL_BENCHMARK_FLAVOR_ITERATOR_DEBUGGING})\n" - " expected one of 'default', '0', '1', 2'" - ) -endif() - -if(stl_is_dynamic) - if(NOT iterator_debugging STREQUAL "") - message(FATAL_ERROR "The dynamic STL does not support non-default iterator debugging") - endif() - set(cxx_library "msvcp${debug_flavor}_implib") - set(c_library "msvcrt${debug_flavor}") -else() - set(cxx_library "libcpmt${debug_flavor}${iterator_debugging}") - set(c_library "libcmt${debug_flavor}") -endif() if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/google-benchmark") message(FATAL_ERROR "google-benchmark is not checked out; make sure to run `git submodule update --init benchmarks/google-benchmark`") @@ -80,11 +25,15 @@ endif() set(BENCHMARK_ENABLE_DOXYGEN OFF) set(BENCHMARK_ENABLE_INSTALL OFF) set(BENCHMARK_ENABLE_TESTING OFF) -set(HAVE_LIB_RT OFF) # for some reason, check_library_exists(rt) succeeds and it should not +set(BUILD_SHARED_LIBS OFF) +set(CMAKE_MSVC_RUNTIME_LIBRARY "${STL_BENCHMARK_MSVC_RUNTIME_LIBRARY}") add_subdirectory(google-benchmark) -target_link_libraries(benchmark PUBLIC "${cxx_library}" "${c_library}") +target_include_directories(benchmark BEFORE PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/out/inc") target_compile_options(benchmark PRIVATE ${VCLIBS_RELEASE_OPTIONS} /EHsc) target_compile_options(benchmark_main PRIVATE ${VCLIBS_RELEASE_OPTIONS} /EHsc) +if(NOT STL_BENCHMARK_ITERATOR_DEBUG_LEVEL STREQUAL "default") + target_compile_definitions(benchmark PUBLIC "-D_ITERATOR_DEBUG_LEVEL=${STL_BENCHMARK_ITERATOR_DEBUG_LEVEL}") +endif() file(GLOB benchmark_sources "src/*.cpp") @@ -94,9 +43,6 @@ add_executable(stl-benchmark target_include_directories(stl-benchmark PRIVATE inc) target_link_libraries(stl-benchmark PRIVATE benchmark::benchmark benchmark::benchmark_main) target_compile_options(stl-benchmark PRIVATE ${VCLIBS_RELEASE_OPTIONS} /EHsc) - -export( - TARGETS ${${cxx_library}_all_targets} - NAMESPACE "msvc_standard_library" - FILE "${CMAKE_CURRENT_BINARY_DIR}/stl-phony-targets-for-debug.cmake" -) +target_link_directories(stl-benchmark + BEFORE + PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/lib/${VCLIBS_I386_OR_AMD64}") diff --git a/benchmarks/inc/udt.hpp b/benchmarks/inc/udt.hpp index 8fba92c02d4..2657fe8d61f 100644 --- a/benchmarks/inc/udt.hpp +++ b/benchmarks/inc/udt.hpp @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + #pragma once template diff --git a/benchmarks/src/copy.cpp b/benchmarks/src/copy.cpp index a5c32c19907..3dd90973136 100644 --- a/benchmarks/src/copy.cpp +++ b/benchmarks/src/copy.cpp @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + #include #include #include diff --git a/docs/cgmanifest.json b/docs/cgmanifest.json index 80cd8febcbc..51c60a330bb 100644 --- a/docs/cgmanifest.json +++ b/docs/cgmanifest.json @@ -44,15 +44,6 @@ "commitHash": "59661c3f883dfd39cef6dc8eaf2fcbaae53597e8" } } - }, - { - "component": { - "type": "git", - "git": { - "repositoryUrl": "https://github.com/google/benchmark", - "commitHash": "0d98dba29d66e93259db7daa53a9327df767a415" - } - } } ], "Version": 1 diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index 0491db76799..cdb4f2e9950 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -552,15 +552,6 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO add_dependencies(msvcp${D_SUFFIX}_implib msvcp${D_SUFFIX} msvcp_1${D_SUFFIX} msvcp_2${D_SUFFIX} msvcp${D_SUFFIX}_atomic_wait msvcp${D_SUFFIX}_codecvt_ids) set_target_properties(msvcp${D_SUFFIX}_implib PROPERTIES STATIC_LIBRARY_OPTIONS "/NOLOGO;/NODEFAULTLIB;/IGNORE:4006;$;$;$;$;$") set_target_properties(msvcp${D_SUFFIX}_implib PROPERTIES ARCHIVE_OUTPUT_NAME "msvcprt${D_SUFFIX}") - - # HACK: for benchmarking, we need to export the standard library since we link google benchmark to the stl targets, - # and CMake requires all targets depended upon by exported targets to themselves be exported. - set(msvcp${D_SUFFIX}_all_targets - boost_math - stl_alias_objects - msvcp${D_SUFFIX}_implib - CACHE INTERNAL "" - ) endfunction() add_stl_dlls("" "" "${VCLIBS_RELEASE_OPTIONS}" "/GL" "/LTCG;/opt:ref,icf") @@ -574,16 +565,6 @@ function(add_stl_statics FLAVOR_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPI target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PUBLIC ${THIS_CONFIG_DEFINITIONS} PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING) target_compile_options(libcpmt${FLAVOR_SUFFIX} PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};$<$:/EHsc>") target_link_libraries(libcpmt${FLAVOR_SUFFIX} PRIVATE Boost::math stl_alias_objects libcpmt${FLAVOR_SUFFIX}_eha) - - # HACK: for benchmarking, we need to export the standard library since we link google benchmark to the stl targets, - # and CMake requires all targets depended upon by exported targets to themselves be exported. - set(libcpmt${FLAVOR_SUFFIX}_all_targets - boost_math - stl_alias_objects - libcpmt${FLAVOR_SUFFIX}_eha - libcpmt${FLAVOR_SUFFIX} - CACHE INTERNAL "" - ) endfunction() add_stl_statics("" "_ITERATOR_DEBUG_LEVEL=0" "${VCLIBS_RELEASE_OPTIONS}") From 8dd601ae81b3a78b22feb7202047ffd92f55fcfc Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Tue, 14 Jun 2022 11:17:17 -0700 Subject: [PATCH 03/22] fix linking --- CMakeLists.txt | 35 ++---------- benchmarks/CMakeLists.txt | 23 ++++---- stl/CMakeLists.txt | 115 ++++++++++++++++++++++++++++---------- 3 files changed, 102 insertions(+), 71 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16153a1b764..51d4b5a42a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ check_cxx_source_compiles([=[ static_assert(WDK_NTDDI_VERSION >= NTDDI_WIN10_CO, "Inspecting WDK_NTDDI_VERSION, the Windows SDK version."); int main() {} ]=] WINDOWS_SDK_VERSION_CHECK) + if(NOT WINDOWS_SDK_VERSION_CHECK) message(FATAL_ERROR "The STL must be built with the Windows 11 SDK (10.0.22000.0) or later. Make sure it's available by selecting it in the Individual Components tab of the VS Installer.") endif() @@ -18,6 +19,7 @@ endif() if(NOT DEFINED VCLIBS_TARGET_ARCHITECTURE) set(VCLIBS_TARGET_ARCHITECTURE "${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}") endif() + string(TOLOWER "${VCLIBS_TARGET_ARCHITECTURE}" VCLIBS_TARGET_ARCHITECTURE) if(VCLIBS_TARGET_ARCHITECTURE MATCHES "^x64$|^x86$") @@ -26,12 +28,14 @@ endif() # add the tools subdirectory _before_ we change all the flags add_subdirectory(tools EXCLUDE_FROM_ALL) + # these allow the targets to show up in the top-level # (as opposed to under the tools subdirectory) if(TARGET run-format) add_custom_target(format) add_dependencies(format run-format) endif() + if(TARGET run-validate) add_custom_target(validate) add_dependencies(validate run-validate) @@ -41,17 +45,11 @@ option(BUILD_TESTING "Enable testing" ON) option(STL_BUILD_BENCHMARKING "Enable benchmarking" OFF) set(VCLIBS_SUFFIX "_oss" CACHE STRING "suffix for built DLL names to avoid conflicts with distributed DLLs") -set(CMAKE_CXX_FLAGS "") -set(CMAKE_CXX_FLAGS_DEBUG "") -set(CMAKE_CXX_FLAGS_RELEASE "") -set(CMAKE_CXX_STANDARD_LIBRARIES "kernel32.lib") -set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "kernel32.lib") -set(CMAKE_MSVC_RUNTIME_LIBRARY "") - if("${VCLIBS_TARGET_ARCHITECTURE}" MATCHES "^x86$") set(VCLIBS_TARGET_ARCHITECTURE "x86") set(VCLIBS_I386_OR_AMD64 "i386") set(VCLIBS_X86_OR_X64 "x86") + # Note that we set _WIN32_WINNT to a high level to make declarations available, but still engage downlevel # runtime dynamic linking by setting our own _STL_WIN32_WINNT back to Windows XP. add_compile_definitions(_X86_ _VCRT_WIN32_WINNT=0x0501 _STL_WIN32_WINNT=0x0501) @@ -81,11 +79,6 @@ add_compile_definitions( _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH WIN32_LEAN_AND_MEAN STRICT _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS _CRT_DECLARE_NONSTDC_NAMES=1 _WIN32_WINNT=0x0A00 NTDDI_VERSION=NTDDI_WIN10_CO) -add_compile_options(/WX /Gy - "$<$:/diagnostics:caret;/W4;/w14265;/w15038;/d1FastFail;/guard:cf;/Z7;/Zp8;/std:c++latest;/permissive-;/Zc:threadSafeInit-;/Zl>" - # note that /Zi generates debug info inside the object file, it's the same as /Z7 for msvc - "$<$:/Zi;/W3;/nologo>") - set(VCLIBS_DEBUG_OPTIONS "$<$:/Od>") # TRANSITION: Potentially remove `/Os` if it results in speed improvements. @@ -97,24 +90,6 @@ set(VCLIBS_DEBUG_OPTIONS "$<$:/Od>") # See GH-2108 for more info. set(VCLIBS_RELEASE_OPTIONS "$<$:/O2;/Os>") -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}") -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/bin/${VCLIBS_I386_OR_AMD64}") - -set(CMAKE_STATIC_LINKER_FLAGS "/WX") -set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "") -set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "") -set(CMAKE_SHARED_LINKER_FLAGS "/DEBUG:FULL /WX /RELEASE /SUBSYSTEM:Console /NODEFAULTLIB /INCREMENTAL:NO /MANIFEST:NO /DLL /profile /guard:cf /DEBUGTYPE:cv,fixup /LARGEADDRESSAWARE") -set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "") -set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "") - -get_filename_component(TOOLSET_BINARIES_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) # Example: $\VC\Tools\MSVC\14.23.27931\bin\Hostx86\x86 -get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_BINARIES_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931\bin\Hostx86 -get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931\bin -get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931 - -set(TOOLSET_LIB "${TOOLSET_ROOT_DIR}/lib/${VCLIBS_X86_OR_X64}") - add_subdirectory(boost-math) add_subdirectory(stl) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 527eaea4307..c11110daafd 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -6,8 +6,9 @@ set(STL_BENCHMARK_MSVC_RUNTIME_LIBRARY CACHE STRING "The version of the standard library to use; see https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html for more information.") set_property(CACHE STL_BENCHMARK_MSVC_RUNTIME_LIBRARY PROPERTY STRINGS - "MultiThreaded;MultiThreadedDLL;MultiThreadedDebug;MultiThreadedDebugDLL" + "MultiThreaded;MultiThreadedDLL;MultiThreadedDebug;MultiThreadedDebugDLL" ) +set(CMAKE_MSVC_RUNTIME_LIBRARY "${STL_BENCHMARK_MSVC_RUNTIME_LIBRARY}") set(STL_BENCHMARK_ITERATOR_DEBUG_LEVEL default @@ -15,25 +16,26 @@ set(STL_BENCHMARK_ITERATOR_DEBUG_LEVEL ) set_property(CACHE STL_BENCHMARK_ITERATOR_DEBUG_LEVEL PROPERTY STRINGS - "default;0;1;2" + "default;0;1;2" ) -if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/google-benchmark") - message(FATAL_ERROR "google-benchmark is not checked out; make sure to run `git submodule update --init benchmarks/google-benchmark`") +if(NOT STL_BENCHMARK_ITERATOR_DEBUG_LEVEL STREQUAL "default") + add_compile_definitions("-D_ITERATOR_DEBUG_LEVEL=${STL_BENCHMARK_ITERATOR_DEBUG_LEVEL}") +endif() + +set(CMAKE_BUILD_TYPE Release) + +if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/google-benchmark/.git") + message(FATAL_ERROR "google-benchmark is not checked out; make sure to run\n git submodule update --init benchmarks/google-benchmark") endif() set(BENCHMARK_ENABLE_DOXYGEN OFF) set(BENCHMARK_ENABLE_INSTALL OFF) set(BENCHMARK_ENABLE_TESTING OFF) set(BUILD_SHARED_LIBS OFF) -set(CMAKE_MSVC_RUNTIME_LIBRARY "${STL_BENCHMARK_MSVC_RUNTIME_LIBRARY}") +set(HAVE_LIB_RT OFF) # on some machines, the google benchmark CMakeLists.txt finds librt despite it not existing add_subdirectory(google-benchmark) target_include_directories(benchmark BEFORE PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/out/inc") -target_compile_options(benchmark PRIVATE ${VCLIBS_RELEASE_OPTIONS} /EHsc) -target_compile_options(benchmark_main PRIVATE ${VCLIBS_RELEASE_OPTIONS} /EHsc) -if(NOT STL_BENCHMARK_ITERATOR_DEBUG_LEVEL STREQUAL "default") - target_compile_definitions(benchmark PUBLIC "-D_ITERATOR_DEBUG_LEVEL=${STL_BENCHMARK_ITERATOR_DEBUG_LEVEL}") -endif() file(GLOB benchmark_sources "src/*.cpp") @@ -42,7 +44,6 @@ add_executable(stl-benchmark ) target_include_directories(stl-benchmark PRIVATE inc) target_link_libraries(stl-benchmark PRIVATE benchmark::benchmark benchmark::benchmark_main) -target_compile_options(stl-benchmark PRIVATE ${VCLIBS_RELEASE_OPTIONS} /EHsc) target_link_directories(stl-benchmark BEFORE PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/lib/${VCLIBS_I386_OR_AMD64}") diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index cdb4f2e9950..5bab61c135c 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -442,10 +442,35 @@ set(STATIC_SOURCES # Objs that exist in all satellite DLLs set(SATELLITE_DLL_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/dllmain_satellite.cpp - ) +) add_compile_definitions(_CRTBLD _VCRT_ALLOW_INTERNALS _HAS_OLD_IOSTREAMS_MEMBERS=1 _STL_CONCRT_SUPPORT) +set(CMAKE_CXX_FLAGS "") +set(CMAKE_CXX_FLAGS_DEBUG "") +set(CMAKE_CXX_FLAGS_RELEASE "") +set(CMAKE_CXX_STANDARD_LIBRARIES "kernel32.lib") +set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "kernel32.lib") +set(CMAKE_MSVC_RUNTIME_LIBRARY "") + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/bin/${VCLIBS_I386_OR_AMD64}") + +set(CMAKE_STATIC_LINKER_FLAGS "/WX") +set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "") +set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "") +set(CMAKE_SHARED_LINKER_FLAGS "/DEBUG:FULL /WX /RELEASE /SUBSYSTEM:Console /NODEFAULTLIB /INCREMENTAL:NO /MANIFEST:NO /DLL /profile /guard:cf /DEBUGTYPE:cv,fixup /LARGEADDRESSAWARE") +set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "") +set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "") + +get_filename_component(TOOLSET_BINARIES_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) # Example: $\VC\Tools\MSVC\14.23.27931\bin\Hostx86\x86 +get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_BINARIES_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931\bin\Hostx86 +get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931\bin +get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931 + +set(TOOLSET_LIB "${TOOLSET_ROOT_DIR}/lib/${VCLIBS_X86_OR_X64}") + include_directories(BEFORE "${CMAKE_CURRENT_LIST_DIR}/inc" "${TOOLSET_ROOT_DIR}/crt/src/vcruntime" @@ -457,19 +482,40 @@ else() add_library(stl_alias_objects INTERFACE) endif() -function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIONS GL_FLAG THIS_CONFIG_LINK_OPTIONS) +add_compile_options(/WX /Gy + "$<$:/diagnostics:caret;/W4;/w14265;/w15038;/d1FastFail;/guard:cf;/Z7;/Zp8;/std:c++latest;/permissive-;/Zc:threadSafeInit-;/Zl>" + + # note that /Zi generates debug info inside the object file, it's the same as /Z7 for msvc + "$<$:/Zi;/W3;/nologo>" +) + +function(target_stl_compile_options tgt rel_or_dbg) + if(rel_or_dbg STREQUAL "Release") + target_compile_options(${tgt} PRIVATE ${VCLIBS_RELEASE_OPTIONS}) + elseif(rel_or_dbg STREQUAL "Debug") + target_compile_options(${tgt} PRIVATE ${VCLIBS_DEBUG_OPTIONS}) + target_compile_definitions(${tgt} PRIVATE "_DEBUG") + else() + message(FATAL_ERROR "INTERNAL ERROR: unexpected value for rel_or_dbg: '${rel_or_dbg}'") + endif() +endfunction() + +function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) # msvcp140.dll add_library(msvcp${D_SUFFIX}_objects OBJECT ${DLL_SOURCES} ${SOURCES}) - target_compile_definitions(msvcp${D_SUFFIX}_objects PRIVATE CRTDLL2 PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) - target_compile_options(msvcp${D_SUFFIX}_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") + target_compile_definitions(msvcp${D_SUFFIX}_objects PRIVATE CRTDLL2 _DLL) + target_compile_options(msvcp${D_SUFFIX}_objects PRIVATE ${GL_FLAG} /EHsc) + target_stl_compile_options(msvcp${D_SUFFIX}_objects ${REL_OR_DBG}) add_library(msvcp${D_SUFFIX}_init_objects OBJECT ${INITIALIZER_SOURCES}) - target_compile_definitions(msvcp${D_SUFFIX}_init_objects PRIVATE CRTDLL2 PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) - target_compile_options(msvcp${D_SUFFIX}_init_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};/EHsc") + target_compile_definitions(msvcp${D_SUFFIX}_init_objects PRIVATE CRTDLL2 _DLL) + target_compile_options(msvcp${D_SUFFIX}_init_objects PRIVATE /EHsc) + target_stl_compile_options(msvcp${D_SUFFIX}_init_objects ${REL_OR_DBG}) add_library(msvcp${D_SUFFIX}_eha_objects OBJECT ${EHA_SOURCES}) - target_compile_definitions(msvcp${D_SUFFIX}_eha_objects PRIVATE CRTDLL2 PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) - target_compile_options(msvcp${D_SUFFIX}_eha_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHa") + target_compile_definitions(msvcp${D_SUFFIX}_eha_objects PRIVATE CRTDLL2 _DLL) + target_compile_options(msvcp${D_SUFFIX}_eha_objects PRIVATE ${GL_FLAG} /EHa) + target_stl_compile_options(msvcp${D_SUFFIX}_eha_objects ${REL_OR_DBG}) add_library(msvcp${D_SUFFIX} SHARED) target_link_libraries(msvcp${D_SUFFIX} PRIVATE msvcp${D_SUFFIX}_eha_objects msvcp${D_SUFFIX}_objects msvcp${D_SUFFIX}_init_objects "${TOOLSET_LIB}/vcruntime${D_SUFFIX}.lib" "${TOOLSET_LIB}/msvcrt${D_SUFFIX}.lib" "ucrt${D_SUFFIX}.lib" "ole32.lib") @@ -480,17 +526,20 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO # import library 'statics' add_library(msvcp${D_SUFFIX}_implib_objects OBJECT ${IMPLIB_SOURCES}) - target_compile_definitions(msvcp${D_SUFFIX}_implib_objects PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) - target_compile_options(msvcp${D_SUFFIX}_implib_objects PRIVATE ${THIS_CONFIG_COMPILE_OPTIONS} /EHsc) # No /GL! + target_compile_definitions(msvcp${D_SUFFIX}_implib_objects PUBLIC _DLL) + target_compile_options(msvcp${D_SUFFIX}_implib_objects PRIVATE /EHsc) # No /GL! + target_stl_compile_options(msvcp${D_SUFFIX}_implib_objects ${REL_OR_DBG}) add_library(msvcp${D_SUFFIX}_satellite_objects OBJECT ${SATELLITE_DLL_SOURCES}) - target_compile_definitions(msvcp${D_SUFFIX}_satellite_objects PRIVATE PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) - target_compile_options(msvcp${D_SUFFIX}_satellite_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") + target_compile_definitions(msvcp${D_SUFFIX}_satellite_objects PRIVATE _DLL) + target_compile_options(msvcp${D_SUFFIX}_satellite_objects PRIVATE ${GL_FLAG} /EHsc) + target_stl_compile_options(msvcp${D_SUFFIX}_satellite_objects ${REL_OR_DBG}) # msvcp140_1.dll (the memory_resource satellite) add_library(msvcp_1${D_SUFFIX}_objects OBJECT ${SOURCES_SATELLITE_1}) - target_compile_definitions(msvcp_1${D_SUFFIX}_objects PRIVATE _BUILDING_SATELLITE_1 PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) - target_compile_options(msvcp_1${D_SUFFIX}_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") + target_compile_definitions(msvcp_1${D_SUFFIX}_objects PRIVATE _BUILDING_SATELLITE_1 _DLL) + target_compile_options(msvcp_1${D_SUFFIX}_objects PRIVATE ${GL_FLAG} /EHsc) + target_stl_compile_options(msvcp_1${D_SUFFIX}_objects ${REL_OR_DBG}) add_library(msvcp_1${D_SUFFIX} SHARED) target_link_libraries(msvcp_1${D_SUFFIX} PRIVATE msvcp_1${D_SUFFIX}_objects msvcp${D_SUFFIX}_satellite_objects "msvcp${D_SUFFIX}" "${TOOLSET_LIB}/vcruntime${D_SUFFIX}.lib" "${TOOLSET_LIB}/msvcrt${D_SUFFIX}.lib" "ucrt${D_SUFFIX}.lib") @@ -501,9 +550,10 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO # msvcp140_2.dll (the special math satellite) add_library(msvcp_2${D_SUFFIX}_objects OBJECT ${SOURCES_SATELLITE_2}) - target_compile_definitions(msvcp_2${D_SUFFIX}_objects PRIVATE _BUILDING_SATELLITE_2 PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) - target_compile_options(msvcp_2${D_SUFFIX}_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") + target_compile_definitions(msvcp_2${D_SUFFIX}_objects PRIVATE _BUILDING_SATELLITE_2 _DLL) + target_compile_options(msvcp_2${D_SUFFIX}_objects PRIVATE ${GL_FLAG} /EHsc) target_link_libraries(msvcp_2${D_SUFFIX}_objects PRIVATE Boost::math) + target_stl_compile_options(msvcp_2${D_SUFFIX}_objects ${REL_OR_DBG}) add_library(msvcp_2${D_SUFFIX} SHARED) target_link_libraries(msvcp_2${D_SUFFIX} PRIVATE msvcp_2${D_SUFFIX}_objects msvcp${D_SUFFIX}_satellite_objects msvcp${D_SUFFIX}_implib_objects "msvcp${D_SUFFIX}" "${TOOLSET_LIB}/vcruntime${D_SUFFIX}.lib" "${TOOLSET_LIB}/msvcrt${D_SUFFIX}.lib" "ucrt${D_SUFFIX}.lib") @@ -514,8 +564,9 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO # msvcp140_atomic_wait.dll (the atomic wait satellite) add_library(msvcp${D_SUFFIX}_atomic_wait_objects OBJECT ${SOURCES_SATELLITE_ATOMIC_WAIT}) - target_compile_definitions(msvcp${D_SUFFIX}_atomic_wait_objects PRIVATE _BUILDING_SATELLITE_ATOMIC_WAIT PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) - target_compile_options(msvcp${D_SUFFIX}_atomic_wait_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") + target_compile_definitions(msvcp${D_SUFFIX}_atomic_wait_objects PRIVATE _BUILDING_SATELLITE_ATOMIC_WAIT _DLL) + target_compile_options(msvcp${D_SUFFIX}_atomic_wait_objects PRIVATE ${GL_FLAG} /EHsc) + target_stl_compile_options(msvcp${D_SUFFIX}_atomic_wait_objects ${REL_OR_DBG}) # generate the .def for msvcp140_atomic_wait.dll set(_ATOMIC_WAIT_OUTPUT_NAME "msvcp140${D_SUFFIX}_atomic_wait${VCLIBS_SUFFIX}") @@ -538,6 +589,7 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO add_library(msvcp${D_SUFFIX}_codecvt_ids_objects OBJECT ${SOURCES_SATELLITE_CODECVT_IDS}) target_compile_definitions(msvcp${D_SUFFIX}_codecvt_ids_objects PRIVATE _BUILDING_SATELLITE_CODECVT_IDS PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) target_compile_options(msvcp${D_SUFFIX}_codecvt_ids_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") + target_stl_compile_options(msvcp${D_SUFFIX}_codecvt_ids_objects ${REL_OR_DBG}) add_library(msvcp${D_SUFFIX}_codecvt_ids SHARED) target_link_libraries(msvcp${D_SUFFIX}_codecvt_ids PRIVATE msvcp${D_SUFFIX}_codecvt_ids_objects msvcp${D_SUFFIX}_satellite_objects "msvcp${D_SUFFIX}" "${TOOLSET_LIB}/vcruntime${D_SUFFIX}.lib" "${TOOLSET_LIB}/msvcrt${D_SUFFIX}.lib" "ucrt${D_SUFFIX}.lib") @@ -554,24 +606,27 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO set_target_properties(msvcp${D_SUFFIX}_implib PROPERTIES ARCHIVE_OUTPUT_NAME "msvcprt${D_SUFFIX}") endfunction() -add_stl_dlls("" "" "${VCLIBS_RELEASE_OPTIONS}" "/GL" "/LTCG;/opt:ref,icf") -add_stl_dlls("d" "_DEBUG" "${VCLIBS_DEBUG_OPTIONS}" "" "/opt:ref,noicf") +add_stl_dlls("" Release "/GL" "/LTCG;/opt:ref,icf") +add_stl_dlls("d" Debug "${VCLIBS_DEBUG_OPTIONS}" "" "/opt:ref,noicf") -function(add_stl_statics FLAVOR_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIONS) +function(add_stl_statics FLAVOR_SUFFIX REL_OR_DBG ITERATOR_DEBUG_LEVEL) add_library(libcpmt${FLAVOR_SUFFIX}_eha OBJECT ${EHA_SOURCES}) - target_compile_definitions(libcpmt${FLAVOR_SUFFIX}_eha PUBLIC ${THIS_CONFIG_DEFINITIONS} PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING) - target_compile_options(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};/EHa") + target_compile_definitions(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "-D_ITERATOR_DEBUG_LEVEL=${ITERATOR_DEBUG_LEVEL}") + target_compile_options(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE /EHa) + target_stl_compile_options(libcpmt${FLAVOR_SUFFIX}_eha ${REL_OR_DBG}) + add_library(libcpmt${FLAVOR_SUFFIX} STATIC ${HEADERS} ${IMPLIB_SOURCES} ${SOURCES} ${INITIALIZER_SOURCES} ${STATIC_SOURCES}) - target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PUBLIC ${THIS_CONFIG_DEFINITIONS} PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING) - target_compile_options(libcpmt${FLAVOR_SUFFIX} PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};$<$:/EHsc>") + target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "-D_ITERATOR_DEBUG_LEVEL=${ITERATOR_DEBUG_LEVEL}") + target_compile_options(libcpmt${FLAVOR_SUFFIX} PRIVATE "$<$:/EHsc>") target_link_libraries(libcpmt${FLAVOR_SUFFIX} PRIVATE Boost::math stl_alias_objects libcpmt${FLAVOR_SUFFIX}_eha) + target_stl_compile_options(libcpmt${FLAVOR_SUFFIX} ${REL_OR_DBG}) endfunction() -add_stl_statics("" "_ITERATOR_DEBUG_LEVEL=0" "${VCLIBS_RELEASE_OPTIONS}") -add_stl_statics("1" "_ITERATOR_DEBUG_LEVEL=1" "${VCLIBS_RELEASE_OPTIONS}") -add_stl_statics("d" "_DEBUG;_ITERATOR_DEBUG_LEVEL=2" "${VCLIBS_DEBUG_OPTIONS}") -add_stl_statics("d1" "_DEBUG;_ITERATOR_DEBUG_LEVEL=1" "${VCLIBS_DEBUG_OPTIONS}") -add_stl_statics("d0" "_DEBUG;_ITERATOR_DEBUG_LEVEL=0" "${VCLIBS_DEBUG_OPTIONS}") +add_stl_statics("" Release 0) +add_stl_statics("1" Release 1) +add_stl_statics("d" Debug 2) +add_stl_statics("d1" Debug 1) +add_stl_statics("d0" Debug 0) add_library(stl_asan STATIC ${ASAN_SOURCES}) From 3bb30f0ca9ddd05df619135cc53fed50d122376b Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Tue, 14 Jun 2022 11:35:52 -0700 Subject: [PATCH 04/22] fix CR comments --- .gitmodules | 6 +++--- azure-devops/checkout-sources.yml | 23 +++++++++++++++++++++++ azure-devops/cmake-configure-build.yml | 1 + benchmarks/inc/udt.hpp | 8 ++++---- tools/format/CMakeLists.txt | 7 +++++++ tools/validate/validate.cpp | 1 + 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/.gitmodules b/.gitmodules index a9b9368a9c4..e9685545179 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,6 +7,6 @@ [submodule "boost-math"] path = boost-math url = https://github.com/boostorg/math.git -[submodule "benchmarks/google-benchmark"] - path = benchmarks/google-benchmark - url = https://github.com/google/benchmark +[submodule "benchmarks/google-benchmark"] + path = benchmarks/google-benchmark + url = https://github.com/google/benchmark diff --git a/azure-devops/checkout-sources.yml b/azure-devops/checkout-sources.yml index cd03e3fd28b..49d0b5cd018 100644 --- a/azure-devops/checkout-sources.yml +++ b/azure-devops/checkout-sources.yml @@ -24,6 +24,9 @@ steps: Write-Host "##vso[task.setvariable variable=${{ parameters.llvmSHAVar }};]$llvmSHA" $boostMathSHA = git submodule status --cached boost-math | %{$_ -replace $regexSubmoduleSHA, '$1'} Write-Host "##vso[task.setvariable variable=${{ parameters.boostMathSHAVar }};]$boostMathSHA" + $googleBenchmarkSHA = git submodule status --cached benchmarks/google-benchmark ` + | %{$_ -replace $regexSubmoduleSHA, '$1'} + Write-Host "##vso[task.setvariable variable=${{ parameters.googleBenchmarkSHAVar }};]$googleBenchmarkSHA" - script: | cd $(Build.SourcesDirectory) if not exist "llvm-project" ( @@ -66,3 +69,23 @@ steps: git fetch --filter=tree:0 --depth=1 boostorg $(${{ parameters.boostMathSHAVar }}) git checkout -f FETCH_HEAD displayName: "Checkout boost-math source" +- script: | + cd $(Build.SourcesDirectory)/benchmarks + if not exist "google-benchmark" ( + mkdir google-benchmark + ) + cd google-benchmark + + if not exist ".git" ( + del /S /Q * + git init + ) + + git remote get-url googlebenchmark + if errorlevel 1 ( + git remote add googlebenchmark https://github.com/google/benchmark.git + ) + + git fetch --filter=tree:0 --depth=1 googlebenchmark $(${{ parameters.googleBenchmarkSHAVar }}) + git checkout -f FETCH_HEAD + displayName: "Checkout google benchmark source" diff --git a/azure-devops/cmake-configure-build.yml b/azure-devops/cmake-configure-build.yml index c0d0cb989d1..dceb4753ae0 100644 --- a/azure-devops/cmake-configure-build.yml +++ b/azure-devops/cmake-configure-build.yml @@ -32,6 +32,7 @@ steps: cmake ${{ parameters.cmakeAdditionalFlags}} -G Ninja ^ -DCMAKE_CXX_COMPILER=cl ^ -DCMAKE_BUILD_TYPE=Release ^ + -DSTL_BUILD_BENCHMARKING=ON ^ -DLIT_FLAGS=$(litFlags) ^ -DCMAKE_CXX_FLAGS=/analyze:autolog- ^ -S $(Build.SourcesDirectory) -B $(${{ parameters.buildOutputLocationVar }}) diff --git a/benchmarks/inc/udt.hpp b/benchmarks/inc/udt.hpp index 2657fe8d61f..0e0695bfc93 100644 --- a/benchmarks/inc/udt.hpp +++ b/benchmarks/inc/udt.hpp @@ -9,12 +9,12 @@ struct trivial { }; template -inline bool operator==(const trivial& lhs, const trivial& rhs) { +bool operator==(const trivial& lhs, const trivial& rhs) { return lhs.c == rhs.c; } template -inline bool operator!=(const trivial& lhs, const trivial& rhs) { +bool operator!=(const trivial& lhs, const trivial& rhs) { return lhs.c != rhs.c; } @@ -35,11 +35,11 @@ struct non_trivial { }; template -inline bool operator==(const non_trivial& lhs, const non_trivial& rhs) { +bool operator==(const non_trivial& lhs, const non_trivial& rhs) { return lhs.c == rhs.c; } template -inline bool operator!=(const non_trivial& lhs, const non_trivial& rhs) { +bool operator!=(const non_trivial& lhs, const non_trivial& rhs) { return lhs.c != rhs.c; } diff --git a/tools/format/CMakeLists.txt b/tools/format/CMakeLists.txt index d1af0734451..fdf213aa192 100644 --- a/tools/format/CMakeLists.txt +++ b/tools/format/CMakeLists.txt @@ -5,6 +5,7 @@ cmake_minimum_required(VERSION 3.22) project(msvc_standard_libraries_format NONE) set(did_search OFF) + if(NOT DEFINED CLANG_FORMAT) message(STATUS "Searching for VS clang-format") set(did_search ON) @@ -26,21 +27,26 @@ find_program(CLANG_FORMAT NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH ) + if(CLANG_FORMAT) if(did_search) message(STATUS "Searching for VS clang-format - found") endif() file(GLOB_RECURSE maybe_clang_format_files + "../../benchmarks/inc/*" + "../../benchmarks/src/*" "../../stl/inc/*" "../../stl/src/*" "../../tests/*" "../../tools/*" ) set(clang_format_files "") + foreach(maybe_file IN LISTS maybe_clang_format_files) cmake_path(GET maybe_file FILENAME filename) cmake_path(GET maybe_file EXTENSION LAST_ONLY extension) + if(extension MATCHES [[^(|\.cpp|\.h|\.hpp)$]] AND NOT filename MATCHES [[^\.]]) list(APPEND clang_format_files "${maybe_file}") endif() @@ -51,6 +57,7 @@ if(CLANG_FORMAT) endif() add_custom_target(run-format) + foreach(file IN LISTS clang_format_files) cmake_path(RELATIVE_PATH file BASE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../.." diff --git a/tools/validate/validate.cpp b/tools/validate/validate.cpp index c590c7dd9ea..9870cb6c0a2 100644 --- a/tools/validate/validate.cpp +++ b/tools/validate/validate.cpp @@ -208,6 +208,7 @@ int main() { L"__pycache__"sv, L"boost-math"sv, L"build"sv, + L"google-benchmark"sv, L"llvm-project"sv, L"out"sv, }; From 056aceb6b39265dd93d4f5524e3ddec120f51f05 Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Tue, 14 Jun 2022 12:38:32 -0700 Subject: [PATCH 05/22] fix azp --- azure-devops/checkout-sources.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/azure-devops/checkout-sources.yml b/azure-devops/checkout-sources.yml index 49d0b5cd018..6bc3ed83181 100644 --- a/azure-devops/checkout-sources.yml +++ b/azure-devops/checkout-sources.yml @@ -8,6 +8,9 @@ parameters: - name: boostMathSHAVar type: string default: boostMathSHA +- name: googleBenchmarkSHAVar + type: string + default: googleBenchmarkSHA steps: - checkout: self clean: true From d4e416d6664493dd63779e6d44ec541e9d859a80 Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Tue, 14 Jun 2022 13:58:55 -0700 Subject: [PATCH 06/22] stop removing /EHsc --- azure-devops/cmake-configure-build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/azure-devops/cmake-configure-build.yml b/azure-devops/cmake-configure-build.yml index dceb4753ae0..b74e1ae5c62 100644 --- a/azure-devops/cmake-configure-build.yml +++ b/azure-devops/cmake-configure-build.yml @@ -34,7 +34,6 @@ steps: -DCMAKE_BUILD_TYPE=Release ^ -DSTL_BUILD_BENCHMARKING=ON ^ -DLIT_FLAGS=$(litFlags) ^ - -DCMAKE_CXX_FLAGS=/analyze:autolog- ^ -S $(Build.SourcesDirectory) -B $(${{ parameters.buildOutputLocationVar }}) displayName: 'Configure the STL' timeoutInMinutes: 2 From 9bd8744fb52ba0e355d17de0587ffa57e159051d Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Tue, 14 Jun 2022 14:30:09 -0700 Subject: [PATCH 07/22] fix tests --- CMakeLists.txt | 11 +++++++++++ stl/CMakeLists.txt | 17 +++++------------ tests/libcxx/lit.site.cfg.in | 4 ++-- tests/std/lit.site.cfg.in | 4 ++-- tests/tr1/lit.site.cfg.in | 4 ++-- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51d4b5a42a3..221cca5bf47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,17 @@ else() message(FATAL_ERROR "Could not determine target architecture: VCLIBS_TARGET_ARCHITECTURE: ${VCLIBS_TARGET_ARCHITECTURE}") endif() +get_filename_component(TOOLSET_BINARIES_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) # Example: $\VC\Tools\MSVC\14.23.27931\bin\Hostx86\x86 +get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_BINARIES_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931\bin\Hostx86 +get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931\bin +get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931 + +set(TOOLSET_LIB "${TOOLSET_ROOT_DIR}/lib/${VCLIBS_X86_OR_X64}") + +set(STL_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}") +set(STL_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}") +set(STL_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/bin/${VCLIBS_I386_OR_AMD64}") + add_compile_definitions( _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH WIN32_LEAN_AND_MEAN STRICT _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS _CRT_DECLARE_NONSTDC_NAMES=1 _WIN32_WINNT=0x0A00 NTDDI_VERSION=NTDDI_WIN10_CO) diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index 5bab61c135c..521fd2bc8ef 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -453,9 +453,9 @@ set(CMAKE_CXX_STANDARD_LIBRARIES "kernel32.lib") set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "kernel32.lib") set(CMAKE_MSVC_RUNTIME_LIBRARY "") -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}") -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/bin/${VCLIBS_I386_OR_AMD64}") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${STL_ARCHIVE_OUTPUT_DIRECTORY}") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${STL_LIBRARY_OUTPUT_DIRECTORY}") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${STL_RUNTIME_OUTPUT_DIRECTORY}") set(CMAKE_STATIC_LINKER_FLAGS "/WX") set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "") @@ -464,13 +464,6 @@ set(CMAKE_SHARED_LINKER_FLAGS "/DEBUG:FULL /WX /RELEASE /SUBSYSTEM:Console /NODE set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "") set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "") -get_filename_component(TOOLSET_BINARIES_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) # Example: $\VC\Tools\MSVC\14.23.27931\bin\Hostx86\x86 -get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_BINARIES_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931\bin\Hostx86 -get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931\bin -get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931 - -set(TOOLSET_LIB "${TOOLSET_ROOT_DIR}/lib/${VCLIBS_X86_OR_X64}") - include_directories(BEFORE "${CMAKE_CURRENT_LIST_DIR}/inc" "${TOOLSET_ROOT_DIR}/crt/src/vcruntime" @@ -526,7 +519,7 @@ function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) # import library 'statics' add_library(msvcp${D_SUFFIX}_implib_objects OBJECT ${IMPLIB_SOURCES}) - target_compile_definitions(msvcp${D_SUFFIX}_implib_objects PUBLIC _DLL) + target_compile_definitions(msvcp${D_SUFFIX}_implib_objects PRIVATE _DLL) target_compile_options(msvcp${D_SUFFIX}_implib_objects PRIVATE /EHsc) # No /GL! target_stl_compile_options(msvcp${D_SUFFIX}_implib_objects ${REL_OR_DBG}) @@ -556,7 +549,7 @@ function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) target_stl_compile_options(msvcp_2${D_SUFFIX}_objects ${REL_OR_DBG}) add_library(msvcp_2${D_SUFFIX} SHARED) - target_link_libraries(msvcp_2${D_SUFFIX} PRIVATE msvcp_2${D_SUFFIX}_objects msvcp${D_SUFFIX}_satellite_objects msvcp${D_SUFFIX}_implib_objects "msvcp${D_SUFFIX}" "${TOOLSET_LIB}/vcruntime${D_SUFFIX}.lib" "${TOOLSET_LIB}/msvcrt${D_SUFFIX}.lib" "ucrt${D_SUFFIX}.lib") + target_link_libraries(msvcp_2${D_SUFFIX} PRIVATE msvcp_2${D_SUFFIX}_objects msvcp${D_SUFFIX}_satellite_objects msvcp${D_SUFFIX}_implib_objects msvcp${D_SUFFIX} "${TOOLSET_LIB}/vcruntime${D_SUFFIX}.lib" "${TOOLSET_LIB}/msvcrt${D_SUFFIX}.lib" "ucrt${D_SUFFIX}.lib") set_target_properties(msvcp_2${D_SUFFIX} PROPERTIES ARCHIVE_OUTPUT_NAME "msvcp140_2${D_SUFFIX}${VCLIBS_SUFFIX}") set_target_properties(msvcp_2${D_SUFFIX} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") set_target_properties(msvcp_2${D_SUFFIX} PROPERTIES OUTPUT_NAME "msvcp140_2${D_SUFFIX}${VCLIBS_SUFFIX}") diff --git a/tests/libcxx/lit.site.cfg.in b/tests/libcxx/lit.site.cfg.in index 0557736b467..edbd6a04f9a 100644 --- a/tests/libcxx/lit.site.cfg.in +++ b/tests/libcxx/lit.site.cfg.in @@ -25,10 +25,10 @@ lit_config.test_subdirs = getattr(lit_config, 'test_subdirs', dict()) lit_config.expected_results[config.name] = stl.test.file_parsing.parse_result_file('@LIBCXX_EXPECTED_RESULTS@') lit_config.include_dirs[config.name] = ['@STL_TESTED_HEADERS_DIR@', '@LIBCXX_SOURCE_DIR@/test/support'] -lit_config.library_dirs[config.name] = ['@CMAKE_LIBRARY_OUTPUT_DIRECTORY@', '@TOOLSET_LIB@'] +lit_config.library_dirs[config.name] = ['@STL_LIBRARY_OUTPUT_DIRECTORY@', '@TOOLSET_LIB@'] lit_config.test_subdirs[config.name] = ['@LIBCXX_SOURCE_DIR@/test/std'] -lit_config.cxx_runtime = '@CMAKE_RUNTIME_OUTPUT_DIRECTORY@' +lit_config.cxx_runtime = '@STL_RUNTIME_OUTPUT_DIRECTORY@' lit_config.target_arch = '@VCLIBS_TARGET_ARCHITECTURE@' lit_config.build_only = '@TESTS_BUILD_ONLY@'.lower() in ['1', 'true', 'on'] diff --git a/tests/std/lit.site.cfg.in b/tests/std/lit.site.cfg.in index 653f76d16a3..06680843d1f 100644 --- a/tests/std/lit.site.cfg.in +++ b/tests/std/lit.site.cfg.in @@ -24,11 +24,11 @@ lit_config.test_subdirs = getattr(lit_config, 'test_subdirs', dict()) lit_config.expected_results[config.name] = stl.test.file_parsing.parse_result_file('@STD_EXPECTED_RESULTS@') lit_config.include_dirs[config.name] = \ ['@STL_TESTED_HEADERS_DIR@', '@LIBCXX_SOURCE_DIR@/test/support', '@STL_SOURCE_DIR@/tests/std/include'] -lit_config.library_dirs[config.name] = ['@CMAKE_LIBRARY_OUTPUT_DIRECTORY@', '@TOOLSET_LIB@'] +lit_config.library_dirs[config.name] = ['@STL_LIBRARY_OUTPUT_DIRECTORY@', '@TOOLSET_LIB@'] lit_config.test_subdirs[config.name] = ['@CMAKE_CURRENT_SOURCE_DIR@/tests'] lit_config.cxx_headers = '@STL_TESTED_HEADERS_DIR@' -lit_config.cxx_runtime = '@CMAKE_RUNTIME_OUTPUT_DIRECTORY@' +lit_config.cxx_runtime = '@STL_RUNTIME_OUTPUT_DIRECTORY@' lit_config.target_arch = '@VCLIBS_TARGET_ARCHITECTURE@' lit_config.build_only = '@TESTS_BUILD_ONLY@'.lower() in ['1', 'true', 'on'] diff --git a/tests/tr1/lit.site.cfg.in b/tests/tr1/lit.site.cfg.in index a0d226bca8c..aaddf346eea 100644 --- a/tests/tr1/lit.site.cfg.in +++ b/tests/tr1/lit.site.cfg.in @@ -24,10 +24,10 @@ lit_config.test_subdirs = getattr(lit_config, 'test_subdirs', dict()) lit_config.expected_results[config.name] = stl.test.file_parsing.parse_result_file('@TR1_EXPECTED_RESULTS@') lit_config.include_dirs[config.name] = \ ['@STL_TESTED_HEADERS_DIR@', '@STL_SOURCE_DIR@/tests/tr1/include', '@STL_SOURCE_DIR@/tests/std/include'] -lit_config.library_dirs[config.name] = ['@CMAKE_LIBRARY_OUTPUT_DIRECTORY@', '@TOOLSET_LIB@'] +lit_config.library_dirs[config.name] = ['@STL_LIBRARY_OUTPUT_DIRECTORY@', '@TOOLSET_LIB@'] lit_config.test_subdirs[config.name] = ['@CMAKE_CURRENT_SOURCE_DIR@/tests'] -lit_config.cxx_runtime = '@CMAKE_RUNTIME_OUTPUT_DIRECTORY@' +lit_config.cxx_runtime = '@STL_RUNTIME_OUTPUT_DIRECTORY@' lit_config.target_arch = '@VCLIBS_TARGET_ARCHITECTURE@' lit_config.build_only = '@TESTS_BUILD_ONLY@'.lower() in ['1', 'true', 'on'] From 677f46735744d7fee7eca2b62f08c3403a750a89 Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Tue, 14 Jun 2022 14:42:37 -0700 Subject: [PATCH 08/22] don't format cmake --- .vscode/settings.json | 5 ++++- CMakeLists.txt | 9 --------- stl/CMakeLists.txt | 1 - 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8bc25e769e7..4c357e60026 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception { "C_Cpp.autoAddFileAssociations": false, - "editor.formatOnSave": true, + "editor.formatOnSave": false, + "[cpp]": { + "editor.formatOnSave": true + }, "files.associations": { ".clang-format": "yaml", "header-units.json": "jsonc", diff --git a/CMakeLists.txt b/CMakeLists.txt index 221cca5bf47..e04812e2648 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,6 @@ check_cxx_source_compiles([=[ static_assert(WDK_NTDDI_VERSION >= NTDDI_WIN10_CO, "Inspecting WDK_NTDDI_VERSION, the Windows SDK version."); int main() {} ]=] WINDOWS_SDK_VERSION_CHECK) - if(NOT WINDOWS_SDK_VERSION_CHECK) message(FATAL_ERROR "The STL must be built with the Windows 11 SDK (10.0.22000.0) or later. Make sure it's available by selecting it in the Individual Components tab of the VS Installer.") endif() @@ -19,7 +18,6 @@ endif() if(NOT DEFINED VCLIBS_TARGET_ARCHITECTURE) set(VCLIBS_TARGET_ARCHITECTURE "${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}") endif() - string(TOLOWER "${VCLIBS_TARGET_ARCHITECTURE}" VCLIBS_TARGET_ARCHITECTURE) if(VCLIBS_TARGET_ARCHITECTURE MATCHES "^x64$|^x86$") @@ -28,14 +26,12 @@ endif() # add the tools subdirectory _before_ we change all the flags add_subdirectory(tools EXCLUDE_FROM_ALL) - # these allow the targets to show up in the top-level # (as opposed to under the tools subdirectory) if(TARGET run-format) add_custom_target(format) add_dependencies(format run-format) endif() - if(TARGET run-validate) add_custom_target(validate) add_dependencies(validate run-validate) @@ -49,7 +45,6 @@ if("${VCLIBS_TARGET_ARCHITECTURE}" MATCHES "^x86$") set(VCLIBS_TARGET_ARCHITECTURE "x86") set(VCLIBS_I386_OR_AMD64 "i386") set(VCLIBS_X86_OR_X64 "x86") - # Note that we set _WIN32_WINNT to a high level to make declarations available, but still engage downlevel # runtime dynamic linking by setting our own _STL_WIN32_WINNT back to Windows XP. add_compile_definitions(_X86_ _VCRT_WIN32_WINNT=0x0501 _STL_WIN32_WINNT=0x0501) @@ -79,13 +74,10 @@ get_filename_component(TOOLSET_BINARIES_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) # get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_BINARIES_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931\bin\Hostx86 get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931\bin get_filename_component(TOOLSET_ROOT_DIR "${TOOLSET_ROOT_DIR}" DIRECTORY) # $\VC\Tools\MSVC\14.23.27931 - set(TOOLSET_LIB "${TOOLSET_ROOT_DIR}/lib/${VCLIBS_X86_OR_X64}") - set(STL_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}") set(STL_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}") set(STL_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/out/bin/${VCLIBS_I386_OR_AMD64}") - add_compile_definitions( _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH WIN32_LEAN_AND_MEAN STRICT _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS _CRT_DECLARE_NONSTDC_NAMES=1 _WIN32_WINNT=0x0A00 NTDDI_VERSION=NTDDI_WIN10_CO) @@ -108,7 +100,6 @@ if(BUILD_TESTING) enable_testing() add_subdirectory(tests) endif() - if(STL_BUILD_BENCHMARKING) add_subdirectory(benchmarks) endif() diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index 521fd2bc8ef..3b77ceccdbb 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -477,7 +477,6 @@ endif() add_compile_options(/WX /Gy "$<$:/diagnostics:caret;/W4;/w14265;/w15038;/d1FastFail;/guard:cf;/Z7;/Zp8;/std:c++latest;/permissive-;/Zc:threadSafeInit-;/Zl>" - # note that /Zi generates debug info inside the object file, it's the same as /Z7 for msvc "$<$:/Zi;/W3;/nologo>" ) From d5895aaea898c51b1eb3a7d061fba2468f57b62c Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Wed, 15 Jun 2022 13:30:31 -0700 Subject: [PATCH 09/22] fix all the things --- CMakeLists.txt | 2 -- benchmarks/CMakeLists.txt | 16 +++++++++------- benchmarks/inc/udt.hpp | 31 ++++++------------------------- benchmarks/src/copy.cpp | 36 ++++++++++++++++-------------------- stl/CMakeLists.txt | 3 +++ 5 files changed, 34 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e04812e2648..0d96ccbf214 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,13 +59,11 @@ elseif(VCLIBS_TARGET_ARCHITECTURE MATCHES "^armv7$") set(VCLIBS_I386_OR_AMD64 "arm") set(VCLIBS_X86_OR_X64 "arm") add_compile_definitions(_ARM_ _VCRT_WIN32_WINNT=0x0602 _STL_WIN32_WINNT=0x0602) - string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " Synchronization.lib") elseif(VCLIBS_TARGET_ARCHITECTURE MATCHES "^arm64$") set(VCLIBS_TARGET_ARCHITECTURE "arm64") set(VCLIBS_I386_OR_AMD64 "arm64") set(VCLIBS_X86_OR_X64 "arm64") add_compile_definitions(_ARM64_ _VCRT_WIN32_WINNT=0x0A00 _STL_WIN32_WINNT=0x0A00) - string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " Synchronization.lib") else() message(FATAL_ERROR "Could not determine target architecture: VCLIBS_TARGET_ARCHITECTURE: ${VCLIBS_TARGET_ARCHITECTURE}") endif() diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index c11110daafd..da8440c2bc8 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -20,10 +20,10 @@ set_property(CACHE STL_BENCHMARK_ITERATOR_DEBUG_LEVEL ) if(NOT STL_BENCHMARK_ITERATOR_DEBUG_LEVEL STREQUAL "default") - add_compile_definitions("-D_ITERATOR_DEBUG_LEVEL=${STL_BENCHMARK_ITERATOR_DEBUG_LEVEL}") + add_compile_definitions("_ITERATOR_DEBUG_LEVEL=${STL_BENCHMARK_ITERATOR_DEBUG_LEVEL}") endif() -set(CMAKE_BUILD_TYPE Release) +set(CMAKE_BUILD_TYPE RelWithDebInfo) if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/google-benchmark/.git") message(FATAL_ERROR "google-benchmark is not checked out; make sure to run\n git submodule update --init benchmarks/google-benchmark") @@ -34,16 +34,18 @@ set(BENCHMARK_ENABLE_INSTALL OFF) set(BENCHMARK_ENABLE_TESTING OFF) set(BUILD_SHARED_LIBS OFF) set(HAVE_LIB_RT OFF) # on some machines, the google benchmark CMakeLists.txt finds librt despite it not existing -add_subdirectory(google-benchmark) -target_include_directories(benchmark BEFORE PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/out/inc") + +include_directories(BEFORE "${CMAKE_BINARY_DIR}/out/inc") +link_directories(BEFORE "${STL_LIBRARY_OUTPUT_DIRECTORY}") + +add_subdirectory(google-benchmark EXCLUDE_FROM_ALL) file(GLOB benchmark_sources "src/*.cpp") add_executable(stl-benchmark ${benchmark_sources} ) +target_compile_features(stl-benchmark PRIVATE cxx_std_20) target_include_directories(stl-benchmark PRIVATE inc) + target_link_libraries(stl-benchmark PRIVATE benchmark::benchmark benchmark::benchmark_main) -target_link_directories(stl-benchmark - BEFORE - PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/lib/${VCLIBS_I386_OR_AMD64}") diff --git a/benchmarks/inc/udt.hpp b/benchmarks/inc/udt.hpp index 0e0695bfc93..b4c65b51358 100644 --- a/benchmarks/inc/udt.hpp +++ b/benchmarks/inc/udt.hpp @@ -4,42 +4,23 @@ #pragma once template -struct trivial { +struct aggregate { Contained c; -}; - -template -bool operator==(const trivial& lhs, const trivial& rhs) { - return lhs.c == rhs.c; -} -template -bool operator!=(const trivial& lhs, const trivial& rhs) { - return lhs.c != rhs.c; -} + friend bool operator==(const aggregate& lhs, const aggregate& rhs) = default; +}; template struct non_trivial { Contained c; - non_trivial() : c() { /* user provided */ - } + non_trivial() : c() {} non_trivial(const Contained& src) : c(src) {} non_trivial(const non_trivial& other) : c(other.c) {} non_trivial& operator=(const non_trivial& other) { c = other.c; return *this; } + ~non_trivial() {} - ~non_trivial() { /* user provided */ - } + friend bool operator==(const non_trivial& lhs, const non_trivial& rhs) = default; }; - -template -bool operator==(const non_trivial& lhs, const non_trivial& rhs) { - return lhs.c == rhs.c; -} - -template -bool operator!=(const non_trivial& lhs, const non_trivial& rhs) { - return lhs.c != rhs.c; -} diff --git a/benchmarks/src/copy.cpp b/benchmarks/src/copy.cpp index 3dd90973136..45ce39c840b 100644 --- a/benchmarks/src/copy.cpp +++ b/benchmarks/src/copy.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -13,8 +14,7 @@ static void handwritten_loop(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); std::vector in_buffer(r0); std::vector out_buffer(r0); - for (auto _ : state) { - (void) _; + for (auto [[maybe_unused]] _ : state) { benchmark::DoNotOptimize(in_buffer); Contained* in_ptr = in_buffer.data(); Contained* in_ptr_end = in_ptr + r0; @@ -32,8 +32,7 @@ static void handwritten_loop_n(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); std::vector in_buffer(r0); std::vector out_buffer(r0); - for (auto _ : state) { - (void) _; + for (auto [[maybe_unused]] _ : state) { benchmark::DoNotOptimize(in_buffer); Contained* in_ptr = in_buffer.data(); Contained* out_ptr = out_buffer.data(); @@ -50,8 +49,7 @@ static void memcpy_call(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); std::vector in_buffer(r0); std::vector out_buffer(r0); - for (auto _ : state) { - (void) _; + for (auto [[maybe_unused]] _ : state) { benchmark::DoNotOptimize(in_buffer); memcpy(in_buffer.data(), out_buffer.data(), r0 * sizeof(Contained)); benchmark::DoNotOptimize(out_buffer); @@ -63,8 +61,7 @@ static void std_copy_call(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); std::vector in_buffer(r0); std::vector out_buffer(r0); - for (auto _ : state) { - (void) _; + for (auto [[maybe_unused]] _ : state) { benchmark::DoNotOptimize(in_buffer); std::copy(in_buffer.begin(), in_buffer.end(), out_buffer.begin()); benchmark::DoNotOptimize(out_buffer); @@ -76,8 +73,7 @@ static void std_copy_n_call(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); std::vector in_buffer(r0); std::vector out_buffer(r0); - for (auto _ : state) { - (void) _; + for (auto [[maybe_unused]] _ : state) { benchmark::DoNotOptimize(in_buffer); std::copy_n(in_buffer.begin(), r0, out_buffer.begin()); benchmark::DoNotOptimize(out_buffer); @@ -90,11 +86,11 @@ BENCHMARK_TEMPLATE1(memcpy_call, char)->Range(0, 1 << 18); BENCHMARK_TEMPLATE1(std_copy_call, char)->Range(0, 1 << 18); BENCHMARK_TEMPLATE1(std_copy_n_call, char)->Range(0, 1 << 18); -BENCHMARK_TEMPLATE1(handwritten_loop, trivial)->Range(0, 1 << 18); -BENCHMARK_TEMPLATE1(handwritten_loop_n, trivial)->Range(0, 1 << 18); -BENCHMARK_TEMPLATE1(memcpy_call, trivial)->Range(0, 1 << 18); -BENCHMARK_TEMPLATE1(std_copy_call, trivial)->Range(0, 1 << 18); -BENCHMARK_TEMPLATE1(std_copy_n_call, trivial)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(handwritten_loop, aggregate)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(handwritten_loop_n, aggregate)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(memcpy_call, aggregate)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(std_copy_call, aggregate)->Range(0, 1 << 18); +BENCHMARK_TEMPLATE1(std_copy_n_call, aggregate)->Range(0, 1 << 18); BENCHMARK_TEMPLATE1(handwritten_loop, non_trivial)->Range(0, 1 << 18); BENCHMARK_TEMPLATE1(handwritten_loop_n, non_trivial)->Range(0, 1 << 18); @@ -107,11 +103,11 @@ BENCHMARK_TEMPLATE1(memcpy_call, int)->Range(0, 1 << 15); BENCHMARK_TEMPLATE1(std_copy_call, int)->Range(0, 1 << 15); BENCHMARK_TEMPLATE1(std_copy_n_call, int)->Range(0, 1 << 15); -BENCHMARK_TEMPLATE1(handwritten_loop, trivial)->Range(0, 1 << 15); -BENCHMARK_TEMPLATE1(handwritten_loop_n, trivial)->Range(0, 1 << 15); -BENCHMARK_TEMPLATE1(memcpy_call, trivial)->Range(0, 1 << 15); -BENCHMARK_TEMPLATE1(std_copy_call, trivial)->Range(0, 1 << 15); -BENCHMARK_TEMPLATE1(std_copy_n_call, trivial)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(handwritten_loop, aggregate)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(handwritten_loop_n, aggregate)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(memcpy_call, aggregate)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(std_copy_call, aggregate)->Range(0, 1 << 15); +BENCHMARK_TEMPLATE1(std_copy_n_call, aggregate)->Range(0, 1 << 15); BENCHMARK_TEMPLATE1(handwritten_loop, non_trivial)->Range(0, 1 << 15); BENCHMARK_TEMPLATE1(handwritten_loop_n, non_trivial)->Range(0, 1 << 15); diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index 3b77ceccdbb..e4e8685ab4b 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -473,6 +473,9 @@ if(VCLIBS_TARGET_ARCHITECTURE MATCHES "^(x86|x64)$") add_library(stl_alias_objects OBJECT ${ALIAS_SOURCES_X86_X64}) else() add_library(stl_alias_objects INTERFACE) + + # on ARM64 and ARM, we can unconditionally expect Synchronization.lib to exist + string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " Synchronization.lib") endif() add_compile_options(/WX /Gy From f825bc60199cba5af2be4b329ab24146f05fc7b8 Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Wed, 15 Jun 2022 14:45:16 -0700 Subject: [PATCH 10/22] check flags --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d96ccbf214..c7e69d8ac06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,10 @@ cmake_minimum_required(VERSION 3.22) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) project(msvc_standard_libraries LANGUAGES CXX) +message(STATUS "cmake cxx flags: ${CMAKE_CXX_FLAGS}") +message(STATUS "debug flags : ${CMAKE_CXX_FLAGS_DEBUG}") +message(STATUS "release flags : ${CMAKE_CXX_FLAGS_RELEASE}") + include(CheckCXXSourceCompiles) check_cxx_source_compiles([=[ #include From e3487bc931314251d41af10850f4d740a1a7b55b Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Wed, 15 Jun 2022 17:33:54 -0700 Subject: [PATCH 11/22] hopefully fix CI --- CMakeLists.txt | 7 +++---- azure-devops/cmake-configure-build.yml | 5 ++++- azure-devops/cross-build.yml | 5 ++++- azure-pipelines.yml | 1 + 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7e69d8ac06..93d6f4dc0c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,10 +5,6 @@ cmake_minimum_required(VERSION 3.22) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) project(msvc_standard_libraries LANGUAGES CXX) -message(STATUS "cmake cxx flags: ${CMAKE_CXX_FLAGS}") -message(STATUS "debug flags : ${CMAKE_CXX_FLAGS_DEBUG}") -message(STATUS "release flags : ${CMAKE_CXX_FLAGS_RELEASE}") - include(CheckCXXSourceCompiles) check_cxx_source_compiles([=[ #include @@ -103,5 +99,8 @@ if(BUILD_TESTING) add_subdirectory(tests) endif() if(STL_BUILD_BENCHMARKING) + if(VCLIBS_TARGET_ARCHITECTURE STREQUAL "arm") + message(WARNING "google benchmark does not build on arm32 - this build will likely fail.") + endif() add_subdirectory(benchmarks) endif() diff --git a/azure-devops/cmake-configure-build.yml b/azure-devops/cmake-configure-build.yml index b74e1ae5c62..0c5391cf68e 100644 --- a/azure-devops/cmake-configure-build.yml +++ b/azure-devops/cmake-configure-build.yml @@ -11,6 +11,9 @@ parameters: - name: buildOutputLocationVar type: string default: buildOutputLocation +- name: buildBenchmarks + type: string + default: 'ON' - name: cmakeAdditionalFlags type: string default: '' @@ -32,7 +35,7 @@ steps: cmake ${{ parameters.cmakeAdditionalFlags}} -G Ninja ^ -DCMAKE_CXX_COMPILER=cl ^ -DCMAKE_BUILD_TYPE=Release ^ - -DSTL_BUILD_BENCHMARKING=ON ^ + -DSTL_BUILD_BENCHMARKING=$(buildBenchmarks) ^ -DLIT_FLAGS=$(litFlags) ^ -S $(Build.SourcesDirectory) -B $(${{ parameters.buildOutputLocationVar }}) displayName: 'Configure the STL' diff --git a/azure-devops/cross-build.yml b/azure-devops/cross-build.yml index 0b5644c112c..153d1e7f184 100644 --- a/azure-devops/cross-build.yml +++ b/azure-devops/cross-build.yml @@ -15,6 +15,9 @@ parameters: - name: numShards type: number default: 8 +- name: buildBenchmarks + type: string + default: ON jobs: - job: '${{ parameters.targetPlatform }}' variables: @@ -38,7 +41,7 @@ jobs: targetPlatform: ${{ parameters.targetPlatform }} hostArch: ${{ parameters.hostArch }} targetArch: ${{ parameters.vsDevCmdArch }} - cmakeAdditionalFlags: '-DTESTS_BUILD_ONLY=ON' + cmakeAdditionalFlags: '-DTESTS_BUILD_ONLY=ON -DSTL_BUILD_BENCHMARKING=$(buildBenchmarks)' - template: run-tests.yml parameters: hostArch: ${{ parameters.hostArch }} diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f98b2f81cf7..29fe011da99 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -82,6 +82,7 @@ stages: parameters: targetPlatform: arm vsDevCmdArch: arm + buildBenchmarks: 'OFF' - stage: Build_ARM64 dependsOn: Build_And_Test_x64 From 3e830fe3ad161f69af2dd3d2875aeeda1ab1d350 Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Thu, 16 Jun 2022 09:27:34 -0700 Subject: [PATCH 12/22] bugfix --- azure-devops/cmake-configure-build.yml | 2 +- azure-devops/cross-build.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/azure-devops/cmake-configure-build.yml b/azure-devops/cmake-configure-build.yml index 0c5391cf68e..030b38feae8 100644 --- a/azure-devops/cmake-configure-build.yml +++ b/azure-devops/cmake-configure-build.yml @@ -35,7 +35,7 @@ steps: cmake ${{ parameters.cmakeAdditionalFlags}} -G Ninja ^ -DCMAKE_CXX_COMPILER=cl ^ -DCMAKE_BUILD_TYPE=Release ^ - -DSTL_BUILD_BENCHMARKING=$(buildBenchmarks) ^ + -DSTL_BUILD_BENCHMARKING=${{ parameters.buildBenchmarks }} ^ -DLIT_FLAGS=$(litFlags) ^ -S $(Build.SourcesDirectory) -B $(${{ parameters.buildOutputLocationVar }}) displayName: 'Configure the STL' diff --git a/azure-devops/cross-build.yml b/azure-devops/cross-build.yml index 153d1e7f184..e370a9d2faa 100644 --- a/azure-devops/cross-build.yml +++ b/azure-devops/cross-build.yml @@ -41,7 +41,8 @@ jobs: targetPlatform: ${{ parameters.targetPlatform }} hostArch: ${{ parameters.hostArch }} targetArch: ${{ parameters.vsDevCmdArch }} - cmakeAdditionalFlags: '-DTESTS_BUILD_ONLY=ON -DSTL_BUILD_BENCHMARKING=$(buildBenchmarks)' + buildBenchmarks: '${{ parameters.buildBenchmarks }}' + cmakeAdditionalFlags: '-DTESTS_BUILD_ONLY=ON' - template: run-tests.yml parameters: hostArch: ${{ parameters.hostArch }} From e86dca4cafb1b816259442598fd5d487ccecbfd4 Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Thu, 16 Jun 2022 16:47:26 -0700 Subject: [PATCH 13/22] Casey CRs --- benchmarks/src/copy.cpp | 10 +++++----- stl/CMakeLists.txt | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/benchmarks/src/copy.cpp b/benchmarks/src/copy.cpp index 45ce39c840b..6b8b764dfe5 100644 --- a/benchmarks/src/copy.cpp +++ b/benchmarks/src/copy.cpp @@ -14,7 +14,7 @@ static void handwritten_loop(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); std::vector in_buffer(r0); std::vector out_buffer(r0); - for (auto [[maybe_unused]] _ : state) { + for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer); Contained* in_ptr = in_buffer.data(); Contained* in_ptr_end = in_ptr + r0; @@ -32,7 +32,7 @@ static void handwritten_loop_n(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); std::vector in_buffer(r0); std::vector out_buffer(r0); - for (auto [[maybe_unused]] _ : state) { + for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer); Contained* in_ptr = in_buffer.data(); Contained* out_ptr = out_buffer.data(); @@ -49,7 +49,7 @@ static void memcpy_call(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); std::vector in_buffer(r0); std::vector out_buffer(r0); - for (auto [[maybe_unused]] _ : state) { + for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer); memcpy(in_buffer.data(), out_buffer.data(), r0 * sizeof(Contained)); benchmark::DoNotOptimize(out_buffer); @@ -61,7 +61,7 @@ static void std_copy_call(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); std::vector in_buffer(r0); std::vector out_buffer(r0); - for (auto [[maybe_unused]] _ : state) { + for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer); std::copy(in_buffer.begin(), in_buffer.end(), out_buffer.begin()); benchmark::DoNotOptimize(out_buffer); @@ -73,7 +73,7 @@ static void std_copy_n_call(benchmark::State& state) { const size_t r0 = static_cast(state.range(0)); std::vector in_buffer(r0); std::vector out_buffer(r0); - for (auto [[maybe_unused]] _ : state) { + for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer); std::copy_n(in_buffer.begin(), r0, out_buffer.begin()); benchmark::DoNotOptimize(out_buffer); diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index c0baa9f2449..376863d44bd 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -608,12 +608,12 @@ add_stl_dlls("d" Debug "${VCLIBS_DEBUG_OPTIONS}" "" "/opt:ref,noicf") function(add_stl_statics FLAVOR_SUFFIX REL_OR_DBG ITERATOR_DEBUG_LEVEL) add_library(libcpmt${FLAVOR_SUFFIX}_eha OBJECT ${EHA_SOURCES}) - target_compile_definitions(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "-D_ITERATOR_DEBUG_LEVEL=${ITERATOR_DEBUG_LEVEL}") + target_compile_definitions(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "_ITERATOR_DEBUG_LEVEL=${ITERATOR_DEBUG_LEVEL}") target_compile_options(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE /EHa) target_stl_compile_options(libcpmt${FLAVOR_SUFFIX}_eha ${REL_OR_DBG}) add_library(libcpmt${FLAVOR_SUFFIX} STATIC ${HEADERS} ${IMPLIB_SOURCES} ${SOURCES} ${INITIALIZER_SOURCES} ${STATIC_SOURCES}) - target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "-D_ITERATOR_DEBUG_LEVEL=${ITERATOR_DEBUG_LEVEL}") + target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "_ITERATOR_DEBUG_LEVEL=${ITERATOR_DEBUG_LEVEL}") target_compile_options(libcpmt${FLAVOR_SUFFIX} PRIVATE "$<$:/EHsc>") target_link_libraries(libcpmt${FLAVOR_SUFFIX} PRIVATE Boost::math stl_alias_objects libcpmt${FLAVOR_SUFFIX}_eha) target_stl_compile_options(libcpmt${FLAVOR_SUFFIX} ${REL_OR_DBG}) From 6a2d30d244997fdd5637043c82e8104282e917c0 Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Tue, 21 Jun 2022 08:55:24 -0700 Subject: [PATCH 14/22] Stephan CRs --- .gitmodules | 2 +- azure-devops/cmake-configure-build.yml | 4 +- azure-devops/cross-build.yml | 6 +- azure-pipelines.yml | 2 +- benchmarks/CMakeLists.txt | 13 ++- benchmarks/inc/udt.hpp | 4 +- benchmarks/src/copy.cpp | 131 +++++++++++++------------ stl/CMakeLists.txt | 43 ++++---- 8 files changed, 111 insertions(+), 94 deletions(-) diff --git a/.gitmodules b/.gitmodules index e9685545179..f1618b17f50 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,4 +9,4 @@ url = https://github.com/boostorg/math.git [submodule "benchmarks/google-benchmark"] path = benchmarks/google-benchmark - url = https://github.com/google/benchmark + url = https://github.com/google/benchmark.git diff --git a/azure-devops/cmake-configure-build.yml b/azure-devops/cmake-configure-build.yml index 030b38feae8..0e50fde8949 100644 --- a/azure-devops/cmake-configure-build.yml +++ b/azure-devops/cmake-configure-build.yml @@ -11,7 +11,7 @@ parameters: - name: buildOutputLocationVar type: string default: buildOutputLocation -- name: buildBenchmarks +- name: buildBenchmarking type: string default: 'ON' - name: cmakeAdditionalFlags @@ -35,7 +35,7 @@ steps: cmake ${{ parameters.cmakeAdditionalFlags}} -G Ninja ^ -DCMAKE_CXX_COMPILER=cl ^ -DCMAKE_BUILD_TYPE=Release ^ - -DSTL_BUILD_BENCHMARKING=${{ parameters.buildBenchmarks }} ^ + -DSTL_BUILD_BENCHMARKING=${{ parameters.buildBenchmarking }} ^ -DLIT_FLAGS=$(litFlags) ^ -S $(Build.SourcesDirectory) -B $(${{ parameters.buildOutputLocationVar }}) displayName: 'Configure the STL' diff --git a/azure-devops/cross-build.yml b/azure-devops/cross-build.yml index e370a9d2faa..d6c58c9b433 100644 --- a/azure-devops/cross-build.yml +++ b/azure-devops/cross-build.yml @@ -15,9 +15,9 @@ parameters: - name: numShards type: number default: 8 -- name: buildBenchmarks +- name: buildBenchmarking type: string - default: ON + default: 'ON' jobs: - job: '${{ parameters.targetPlatform }}' variables: @@ -41,7 +41,7 @@ jobs: targetPlatform: ${{ parameters.targetPlatform }} hostArch: ${{ parameters.hostArch }} targetArch: ${{ parameters.vsDevCmdArch }} - buildBenchmarks: '${{ parameters.buildBenchmarks }}' + buildBenchmarking: ${{ parameters.buildBenchmarking }} cmakeAdditionalFlags: '-DTESTS_BUILD_ONLY=ON' - template: run-tests.yml parameters: diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4687b0bd76b..b3e45d44a94 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -82,7 +82,7 @@ stages: parameters: targetPlatform: arm vsDevCmdArch: arm - buildBenchmarks: 'OFF' + buildBenchmarking: 'OFF' - stage: Build_ARM64 dependsOn: Build_And_Test_x64 diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index da8440c2bc8..64b6010f95a 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -3,7 +3,7 @@ set(STL_BENCHMARK_MSVC_RUNTIME_LIBRARY MultiThreaded - CACHE STRING "The version of the standard library to use; see https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html for more information.") + CACHE STRING "The flavor of the standard library to use; see https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html for more information.") set_property(CACHE STL_BENCHMARK_MSVC_RUNTIME_LIBRARY PROPERTY STRINGS "MultiThreaded;MultiThreadedDLL;MultiThreadedDebug;MultiThreadedDebugDLL" @@ -40,12 +40,19 @@ link_directories(BEFORE "${STL_LIBRARY_OUTPUT_DIRECTORY}") add_subdirectory(google-benchmark EXCLUDE_FROM_ALL) -file(GLOB benchmark_sources "src/*.cpp") +set(benchmark_headers + "inc/udt.hpp" +) + +set(benchmark_sources + "src/copy.cpp" +) add_executable(stl-benchmark + ${benchmark_headers} ${benchmark_sources} ) -target_compile_features(stl-benchmark PRIVATE cxx_std_20) +target_compile_features(stl-benchmark PRIVATE cxx_std_23) target_include_directories(stl-benchmark PRIVATE inc) target_link_libraries(stl-benchmark PRIVATE benchmark::benchmark benchmark::benchmark_main) diff --git a/benchmarks/inc/udt.hpp b/benchmarks/inc/udt.hpp index b4c65b51358..b47c58c2c9d 100644 --- a/benchmarks/inc/udt.hpp +++ b/benchmarks/inc/udt.hpp @@ -7,7 +7,7 @@ template struct aggregate { Contained c; - friend bool operator==(const aggregate& lhs, const aggregate& rhs) = default; + friend bool operator==(const aggregate&, const aggregate&) = default; }; template @@ -22,5 +22,5 @@ struct non_trivial { } ~non_trivial() {} - friend bool operator==(const non_trivial& lhs, const non_trivial& rhs) = default; + friend bool operator==(const non_trivial&, const non_trivial&) = default; }; diff --git a/benchmarks/src/copy.cpp b/benchmarks/src/copy.cpp index 6b8b764dfe5..d358f21415c 100644 --- a/benchmarks/src/copy.cpp +++ b/benchmarks/src/copy.cpp @@ -5,80 +5,85 @@ #include #include #include +#include #include #include -template -static void handwritten_loop(benchmark::State& state) { - const size_t r0 = static_cast(state.range(0)); - std::vector in_buffer(r0); - std::vector out_buffer(r0); - for ([[maybe_unused]] auto _ : state) { - benchmark::DoNotOptimize(in_buffer); - Contained* in_ptr = in_buffer.data(); - Contained* in_ptr_end = in_ptr + r0; - Contained* out_ptr = out_buffer.data(); - while (in_ptr != in_ptr_end) { - *out_ptr++ = *in_ptr++; +namespace { + template + void handwritten_loop(benchmark::State& state) { + const size_t r0 = static_cast(state.range(0)); + const std::vector in_buffer(r0); + std::vector out_buffer(r0); + for ([[maybe_unused]] auto _ : state) { + benchmark::DoNotOptimize(in_buffer.data()); + const Contained* in_ptr = in_buffer.data(); + const Contained* const in_ptr_end = in_ptr + r0; + Contained* out_ptr = out_buffer.data(); + while (in_ptr != in_ptr_end) { + *out_ptr++ = *in_ptr++; + } + + benchmark::DoNotOptimize(out_buffer.data()); } - - benchmark::DoNotOptimize(out_buffer); } -} - -template -static void handwritten_loop_n(benchmark::State& state) { - const size_t r0 = static_cast(state.range(0)); - std::vector in_buffer(r0); - std::vector out_buffer(r0); - for ([[maybe_unused]] auto _ : state) { - benchmark::DoNotOptimize(in_buffer); - Contained* in_ptr = in_buffer.data(); - Contained* out_ptr = out_buffer.data(); - for (size_t idx = 0, max = r0; idx < max; ++idx) { - out_ptr[idx] = in_ptr[idx]; - } - benchmark::DoNotOptimize(out_buffer); + template + void handwritten_loop_n(benchmark::State& state) { + const size_t r0 = static_cast(state.range(0)); + const std::vector in_buffer(r0); + std::vector out_buffer(r0); + for ([[maybe_unused]] auto _ : state) { + benchmark::DoNotOptimize(in_buffer.data()); + const Contained* const in_ptr = in_buffer.data(); + Contained* const out_ptr = out_buffer.data(); + for (size_t idx = 0; idx < r0; ++idx) { + out_ptr[idx] = in_ptr[idx]; + } + + benchmark::DoNotOptimize(out_buffer.data()); + } } -} - -template -static void memcpy_call(benchmark::State& state) { - const size_t r0 = static_cast(state.range(0)); - std::vector in_buffer(r0); - std::vector out_buffer(r0); - for ([[maybe_unused]] auto _ : state) { - benchmark::DoNotOptimize(in_buffer); - memcpy(in_buffer.data(), out_buffer.data(), r0 * sizeof(Contained)); - benchmark::DoNotOptimize(out_buffer); + + template + void memcpy_call(benchmark::State& state) { + static_assert( + std::is_trivially_copyable_v, "memcpy must only be called on trivially copyable types"); + const size_t r0 = static_cast(state.range(0)); + const std::vector in_buffer(r0); + std::vector out_buffer(r0); + for ([[maybe_unused]] auto _ : state) { + benchmark::DoNotOptimize(in_buffer.data()); + memcpy(out_buffer.data(), in_buffer.data(), r0 * sizeof(Contained)); + benchmark::DoNotOptimize(out_buffer.data()); + } } -} - -template -static void std_copy_call(benchmark::State& state) { - const size_t r0 = static_cast(state.range(0)); - std::vector in_buffer(r0); - std::vector out_buffer(r0); - for ([[maybe_unused]] auto _ : state) { - benchmark::DoNotOptimize(in_buffer); - std::copy(in_buffer.begin(), in_buffer.end(), out_buffer.begin()); - benchmark::DoNotOptimize(out_buffer); + + template + void std_copy_call(benchmark::State& state) { + const size_t r0 = static_cast(state.range(0)); + const std::vector in_buffer(r0); + std::vector out_buffer(r0); + for ([[maybe_unused]] auto _ : state) { + benchmark::DoNotOptimize(in_buffer.data()); + std::copy(in_buffer.begin(), in_buffer.end(), out_buffer.begin()); + benchmark::DoNotOptimize(out_buffer.data()); + } } -} - -template -static void std_copy_n_call(benchmark::State& state) { - const size_t r0 = static_cast(state.range(0)); - std::vector in_buffer(r0); - std::vector out_buffer(r0); - for ([[maybe_unused]] auto _ : state) { - benchmark::DoNotOptimize(in_buffer); - std::copy_n(in_buffer.begin(), r0, out_buffer.begin()); - benchmark::DoNotOptimize(out_buffer); + + template + void std_copy_n_call(benchmark::State& state) { + const size_t r0 = static_cast(state.range(0)); + const std::vector in_buffer(r0); + std::vector out_buffer(r0); + for ([[maybe_unused]] auto _ : state) { + benchmark::DoNotOptimize(in_buffer.data()); + std::copy_n(in_buffer.begin(), r0, out_buffer.begin()); + benchmark::DoNotOptimize(out_buffer.data()); + } } -} +} // namespace BENCHMARK_TEMPLATE1(handwritten_loop, char)->Range(0, 1 << 18); BENCHMARK_TEMPLATE1(handwritten_loop_n, char)->Range(0, 1 << 18); diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index 376863d44bd..0b070c779b7 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -497,11 +497,17 @@ function(target_stl_compile_options tgt rel_or_dbg) endif() endfunction() -function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) +function(add_stl_dlls D_SUFFIX REL_OR_DBG) + set(link_options_Release "/LTCG;/opt:ref,icf") + set(link_options_Debug "/opt:ref,noicf") + + set(gl_flag_Release "/GL") + set(gl_flag_Debug "") + # msvcp140.dll add_library(msvcp${D_SUFFIX}_objects OBJECT ${DLL_SOURCES} ${SOURCES}) target_compile_definitions(msvcp${D_SUFFIX}_objects PRIVATE CRTDLL2 _DLL) - target_compile_options(msvcp${D_SUFFIX}_objects PRIVATE ${GL_FLAG} /EHsc) + target_compile_options(msvcp${D_SUFFIX}_objects PRIVATE ${gl_flag_${REL_OR_DBG}} /EHsc) target_stl_compile_options(msvcp${D_SUFFIX}_objects ${REL_OR_DBG}) add_library(msvcp${D_SUFFIX}_init_objects OBJECT ${INITIALIZER_SOURCES}) @@ -511,7 +517,7 @@ function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) add_library(msvcp${D_SUFFIX}_eha_objects OBJECT ${EHA_SOURCES}) target_compile_definitions(msvcp${D_SUFFIX}_eha_objects PRIVATE CRTDLL2 _DLL) - target_compile_options(msvcp${D_SUFFIX}_eha_objects PRIVATE ${GL_FLAG} /EHa) + target_compile_options(msvcp${D_SUFFIX}_eha_objects PRIVATE ${gl_flag_${REL_OR_DBG}} /EHa) target_stl_compile_options(msvcp${D_SUFFIX}_eha_objects ${REL_OR_DBG}) add_library(msvcp${D_SUFFIX} SHARED) @@ -519,7 +525,7 @@ function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) set_target_properties(msvcp${D_SUFFIX} PROPERTIES ARCHIVE_OUTPUT_NAME "msvcp140_base${D_SUFFIX}${VCLIBS_SUFFIX}") set_target_properties(msvcp${D_SUFFIX} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") set_target_properties(msvcp${D_SUFFIX} PROPERTIES OUTPUT_NAME "msvcp140${D_SUFFIX}${VCLIBS_SUFFIX}") - target_link_options(msvcp${D_SUFFIX} PRIVATE "${THIS_CONFIG_LINK_OPTIONS}") + target_link_options(msvcp${D_SUFFIX} PRIVATE ${link_options_${REL_OR_DBG}}) # import library 'statics' add_library(msvcp${D_SUFFIX}_implib_objects OBJECT ${IMPLIB_SOURCES}) @@ -529,13 +535,13 @@ function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) add_library(msvcp${D_SUFFIX}_satellite_objects OBJECT ${SATELLITE_DLL_SOURCES}) target_compile_definitions(msvcp${D_SUFFIX}_satellite_objects PRIVATE _DLL) - target_compile_options(msvcp${D_SUFFIX}_satellite_objects PRIVATE ${GL_FLAG} /EHsc) + target_compile_options(msvcp${D_SUFFIX}_satellite_objects PRIVATE ${gl_flag_${REL_OR_DBG}} /EHsc) target_stl_compile_options(msvcp${D_SUFFIX}_satellite_objects ${REL_OR_DBG}) # msvcp140_1.dll (the memory_resource satellite) add_library(msvcp_1${D_SUFFIX}_objects OBJECT ${SOURCES_SATELLITE_1}) target_compile_definitions(msvcp_1${D_SUFFIX}_objects PRIVATE _BUILDING_SATELLITE_1 _DLL) - target_compile_options(msvcp_1${D_SUFFIX}_objects PRIVATE ${GL_FLAG} /EHsc) + target_compile_options(msvcp_1${D_SUFFIX}_objects PRIVATE ${gl_flag_${REL_OR_DBG}} /EHsc) target_stl_compile_options(msvcp_1${D_SUFFIX}_objects ${REL_OR_DBG}) add_library(msvcp_1${D_SUFFIX} SHARED) @@ -543,12 +549,12 @@ function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) set_target_properties(msvcp_1${D_SUFFIX} PROPERTIES ARCHIVE_OUTPUT_NAME "msvcp140_1${D_SUFFIX}${VCLIBS_SUFFIX}") set_target_properties(msvcp_1${D_SUFFIX} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") set_target_properties(msvcp_1${D_SUFFIX} PROPERTIES OUTPUT_NAME "msvcp140_1${D_SUFFIX}${VCLIBS_SUFFIX}") - target_link_options(msvcp_1${D_SUFFIX} PRIVATE "${THIS_CONFIG_LINK_OPTIONS}") + target_link_options(msvcp_1${D_SUFFIX} PRIVATE ${link_options_${REL_OR_DBG}}) # msvcp140_2.dll (the special math satellite) add_library(msvcp_2${D_SUFFIX}_objects OBJECT ${SOURCES_SATELLITE_2}) target_compile_definitions(msvcp_2${D_SUFFIX}_objects PRIVATE _BUILDING_SATELLITE_2 _DLL) - target_compile_options(msvcp_2${D_SUFFIX}_objects PRIVATE ${GL_FLAG} /EHsc) + target_compile_options(msvcp_2${D_SUFFIX}_objects PRIVATE ${gl_flag_${REL_OR_DBG}} /EHsc) target_link_libraries(msvcp_2${D_SUFFIX}_objects PRIVATE Boost::math) target_stl_compile_options(msvcp_2${D_SUFFIX}_objects ${REL_OR_DBG}) @@ -557,12 +563,12 @@ function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) set_target_properties(msvcp_2${D_SUFFIX} PROPERTIES ARCHIVE_OUTPUT_NAME "msvcp140_2${D_SUFFIX}${VCLIBS_SUFFIX}") set_target_properties(msvcp_2${D_SUFFIX} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") set_target_properties(msvcp_2${D_SUFFIX} PROPERTIES OUTPUT_NAME "msvcp140_2${D_SUFFIX}${VCLIBS_SUFFIX}") - target_link_options(msvcp_2${D_SUFFIX} PRIVATE "${THIS_CONFIG_LINK_OPTIONS}") + target_link_options(msvcp_2${D_SUFFIX} PRIVATE ${link_options_${REL_OR_DBG}}) # msvcp140_atomic_wait.dll (the atomic wait satellite) add_library(msvcp${D_SUFFIX}_atomic_wait_objects OBJECT ${SOURCES_SATELLITE_ATOMIC_WAIT}) target_compile_definitions(msvcp${D_SUFFIX}_atomic_wait_objects PRIVATE _BUILDING_SATELLITE_ATOMIC_WAIT _DLL) - target_compile_options(msvcp${D_SUFFIX}_atomic_wait_objects PRIVATE ${GL_FLAG} /EHsc) + target_compile_options(msvcp${D_SUFFIX}_atomic_wait_objects PRIVATE ${gl_flag_${REL_OR_DBG}} /EHsc) target_stl_compile_options(msvcp${D_SUFFIX}_atomic_wait_objects ${REL_OR_DBG}) # generate the .def for msvcp140_atomic_wait.dll @@ -580,12 +586,11 @@ function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) set_target_properties(msvcp${D_SUFFIX}_atomic_wait PROPERTIES ARCHIVE_OUTPUT_NAME "msvcp140_atomic_wait${D_SUFFIX}${VCLIBS_SUFFIX}") set_target_properties(msvcp${D_SUFFIX}_atomic_wait PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") set_target_properties(msvcp${D_SUFFIX}_atomic_wait PROPERTIES OUTPUT_NAME "${_ATOMIC_WAIT_OUTPUT_NAME}") - target_link_options(msvcp${D_SUFFIX}_atomic_wait PRIVATE "${THIS_CONFIG_LINK_OPTIONS}") + target_link_options(msvcp${D_SUFFIX}_atomic_wait PRIVATE ${link_options_${REL_OR_DBG}}) # msvcp140_codecvt_ids.dll add_library(msvcp${D_SUFFIX}_codecvt_ids_objects OBJECT ${SOURCES_SATELLITE_CODECVT_IDS}) - target_compile_definitions(msvcp${D_SUFFIX}_codecvt_ids_objects PRIVATE _BUILDING_SATELLITE_CODECVT_IDS PUBLIC _DLL ${THIS_CONFIG_DEFINITIONS}) - target_compile_options(msvcp${D_SUFFIX}_codecvt_ids_objects PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};${GL_FLAG};/EHsc") + target_compile_definitions(msvcp${D_SUFFIX}_codecvt_ids_objects PRIVATE _BUILDING_SATELLITE_CODECVT_IDS _DLL) target_stl_compile_options(msvcp${D_SUFFIX}_codecvt_ids_objects ${REL_OR_DBG}) add_library(msvcp${D_SUFFIX}_codecvt_ids SHARED) @@ -593,7 +598,7 @@ function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) set_target_properties(msvcp${D_SUFFIX}_codecvt_ids PROPERTIES ARCHIVE_OUTPUT_NAME "msvcp140_codecvt_ids${D_SUFFIX}${VCLIBS_SUFFIX}") set_target_properties(msvcp${D_SUFFIX}_codecvt_ids PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") set_target_properties(msvcp${D_SUFFIX}_codecvt_ids PROPERTIES OUTPUT_NAME "msvcp140${D_SUFFIX}_codecvt_ids${VCLIBS_SUFFIX}") - target_link_options(msvcp${D_SUFFIX}_codecvt_ids PRIVATE "${THIS_CONFIG_LINK_OPTIONS}") + target_link_options(msvcp${D_SUFFIX}_codecvt_ids PRIVATE ${link_options_${REL_OR_DBG}}) # import library add_library(msvcp${D_SUFFIX}_implib STATIC ${HEADERS}) @@ -603,17 +608,17 @@ function(add_stl_dlls D_SUFFIX REL_OR_DBG GL_FLAG THIS_CONFIG_LINK_OPTIONS) set_target_properties(msvcp${D_SUFFIX}_implib PROPERTIES ARCHIVE_OUTPUT_NAME "msvcprt${D_SUFFIX}") endfunction() -add_stl_dlls("" Release "/GL" "/LTCG;/opt:ref,icf") -add_stl_dlls("d" Debug "${VCLIBS_DEBUG_OPTIONS}" "" "/opt:ref,noicf") +add_stl_dlls("" Release) +add_stl_dlls("d" Debug) -function(add_stl_statics FLAVOR_SUFFIX REL_OR_DBG ITERATOR_DEBUG_LEVEL) +function(add_stl_statics FLAVOR_SUFFIX REL_OR_DBG IDL_VALUE) add_library(libcpmt${FLAVOR_SUFFIX}_eha OBJECT ${EHA_SOURCES}) - target_compile_definitions(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "_ITERATOR_DEBUG_LEVEL=${ITERATOR_DEBUG_LEVEL}") + target_compile_definitions(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "_ITERATOR_DEBUG_LEVEL=${IDL_VALUE}") target_compile_options(libcpmt${FLAVOR_SUFFIX}_eha PRIVATE /EHa) target_stl_compile_options(libcpmt${FLAVOR_SUFFIX}_eha ${REL_OR_DBG}) add_library(libcpmt${FLAVOR_SUFFIX} STATIC ${HEADERS} ${IMPLIB_SOURCES} ${SOURCES} ${INITIALIZER_SOURCES} ${STATIC_SOURCES}) - target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "_ITERATOR_DEBUG_LEVEL=${ITERATOR_DEBUG_LEVEL}") + target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PRIVATE _ANNOTATE_VECTOR _ANNOTATE_STRING "_ITERATOR_DEBUG_LEVEL=${IDL_VALUE}") target_compile_options(libcpmt${FLAVOR_SUFFIX} PRIVATE "$<$:/EHsc>") target_link_libraries(libcpmt${FLAVOR_SUFFIX} PRIVATE Boost::math stl_alias_objects libcpmt${FLAVOR_SUFFIX}_eha) target_stl_compile_options(libcpmt${FLAVOR_SUFFIX} ${REL_OR_DBG}) From 8c903ddceafcdb365874cd13ca40f2e21efe2feb Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 21 Jun 2022 15:10:37 -0700 Subject: [PATCH 15/22] codecvt_ids needs `${gl_flag_${REL_OR_DBG}} /EHsc`. --- stl/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/stl/CMakeLists.txt b/stl/CMakeLists.txt index 0b070c779b7..643066112a0 100644 --- a/stl/CMakeLists.txt +++ b/stl/CMakeLists.txt @@ -591,6 +591,7 @@ function(add_stl_dlls D_SUFFIX REL_OR_DBG) # msvcp140_codecvt_ids.dll add_library(msvcp${D_SUFFIX}_codecvt_ids_objects OBJECT ${SOURCES_SATELLITE_CODECVT_IDS}) target_compile_definitions(msvcp${D_SUFFIX}_codecvt_ids_objects PRIVATE _BUILDING_SATELLITE_CODECVT_IDS _DLL) + target_compile_options(msvcp${D_SUFFIX}_codecvt_ids_objects PRIVATE ${gl_flag_${REL_OR_DBG}} /EHsc) target_stl_compile_options(msvcp${D_SUFFIX}_codecvt_ids_objects ${REL_OR_DBG}) add_library(msvcp${D_SUFFIX}_codecvt_ids SHARED) From 25d2a897e423bec6d8a58ae4e4bc2743f55e71c3 Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Wed, 22 Jun 2022 08:07:01 -0700 Subject: [PATCH 16/22] Modify README, change how benchmarks work Instead of adding new files to the same benchmark executable, this will make each benchmark a different executable; due to how Google Benchmark works, afaict, there isn't a good way to group up benchmarks into files, so it's better to just have each file be a separate binary. Additionally, rename copy -> std_copy. --- .gitignore | 1 + README.md | 41 ++++++++++++++++++++--- benchmarks/CMakeLists.txt | 39 +++++++++++++++------ benchmarks/src/{copy.cpp => std_copy.cpp} | 0 4 files changed, 66 insertions(+), 15 deletions(-) rename benchmarks/src/{copy.cpp => std_copy.cpp} (100%) diff --git a/.gitignore b/.gitignore index 693d320cc70..692a1918b27 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ __pycache__/ /out/ /tools/out/ /CMakeLists.txt.user +/*.log diff --git a/README.md b/README.md index b555afdde5d..56566be39b4 100644 --- a/README.md +++ b/README.md @@ -140,11 +140,11 @@ Just try to follow these rules, so we can spend more time fixing bugs and implem # How To Build With The Visual Studio IDE -1. Install Visual Studio 2022 17.3 Preview 2 or later. +1. Install Visual Studio 2022 17.3 Preview 1 or later. * Select "Windows 11 SDK (10.0.22000.0)" in the VS Installer. * We recommend selecting "C++ CMake tools for Windows" in the VS Installer. This will ensure that you're using supported versions of CMake and Ninja. - * Otherwise, install [CMake][] 3.23 or later, and [Ninja][] 1.10.2 or later. + * Otherwise, install [CMake][] 3.22 or later, and [Ninja][] 1.10.2 or later. * We recommend selecting "Python 3 64-bit" in the VS Installer. * Otherwise, make sure [Python][] 3.9 or later is available to CMake. 2. Open Visual Studio, and choose the "Clone or check out code" option. Enter the URL of this repository, @@ -156,11 +156,11 @@ Just try to follow these rules, so we can spend more time fixing bugs and implem # How To Build With A Native Tools Command Prompt -1. Install Visual Studio 2022 17.3 Preview 2 or later. +1. Install Visual Studio 2022 17.3 Preview 1 or later. * Select "Windows 11 SDK (10.0.22000.0)" in the VS Installer. * We recommend selecting "C++ CMake tools for Windows" in the VS Installer. This will ensure that you're using supported versions of CMake and Ninja. - * Otherwise, install [CMake][] 3.23 or later, and [Ninja][] 1.10.2 or later. + * Otherwise, install [CMake][] 3.22 or later, and [Ninja][] 1.10.2 or later. * We recommend selecting "Python 3 64-bit" in the VS Installer. * Otherwise, make sure [Python][] 3.9 or later is available to CMake. 2. Open a command prompt. @@ -397,6 +397,39 @@ build folder to your path: set PATH=C:\STL\out\build\x64\out\bin\amd64;%PATH% ``` +# Benchmarking + +For performance sensitive code – like containers, algorithms, and the like – +you will likely wish to write and/or run benchmarks, and the STL team will likely +run any benchmarks we do have in our PR process. + +All benchmarks are located in `benchmarks`. Adding a new one is as easy as adding a new file +to `benchmarks/src`, and adding a benchmark using that file in `benchmarks/CMakeLists.txt`, +or modifying an existing file in `benchmarks/src`. We use Google's [Benchmark][gbenchmark] library, +so you may find [their documentation][gbenchmark:docs] helpful, and you can also read the existing code +for how _we_ use it. + +To run benchmarks, you'll want to configure the STL with the `-DSTL_BUILD_BENCHMARKING=ON` option: + +```cmd +> cmake -B out\bench -S . -G Ninja -DSTL_BUILD_BENCHMARKING=ON +> cmake --build out\bench +``` + +you can then run your benchmark with: + +```cmd +> out\bench\benchmarks\benchmark- --benchmark_out= --benchmark_out_format=csv +``` + +And then you can copy this csv file into your favorite Excel program. + +If you want to see all the other flags you can pass, run: + +```cmd +> out\bench\benchmarks\benchmark- --help +``` + # Editing And Testing The Debugger Visualizer ### Modify The Visualizer diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 64b6010f95a..7c526b2fe8d 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -33,7 +33,9 @@ set(BENCHMARK_ENABLE_DOXYGEN OFF) set(BENCHMARK_ENABLE_INSTALL OFF) set(BENCHMARK_ENABLE_TESTING OFF) set(BUILD_SHARED_LIBS OFF) -set(HAVE_LIB_RT OFF) # on some machines, the google benchmark CMakeLists.txt finds librt despite it not existing + +# TRANSITION, GH-2816: on some machines, librt is found, despite it being a unix-only library +set(HAVE_LIB_RT OFF) include_directories(BEFORE "${CMAKE_BINARY_DIR}/out/inc") link_directories(BEFORE "${STL_LIBRARY_OUTPUT_DIRECTORY}") @@ -44,15 +46,30 @@ set(benchmark_headers "inc/udt.hpp" ) -set(benchmark_sources - "src/copy.cpp" -) +function(add_benchmark name) + cmake_parse_arguments(PARSE_ARGV 1 "arg" "" "CXX_STANDARD" "") -add_executable(stl-benchmark - ${benchmark_headers} - ${benchmark_sources} -) -target_compile_features(stl-benchmark PRIVATE cxx_std_23) -target_include_directories(stl-benchmark PRIVATE inc) + if(NOT DEFINED arg_CXX_STANDARD) + set(arg_CXX_STANDARD 23) + elseif(NOT arg_CXX_STANDARD MATCHES "^[0-9][0-9]$") + message(FATAL_ERROR "Unexpected value for CXX_STANDARD: ${arg_CXX_STANDARD}") + endif() + + if(NOT DEFINED arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "benchmark ${name} does not have any source files") + endif() -target_link_libraries(stl-benchmark PRIVATE benchmark::benchmark benchmark::benchmark_main) + add_executable(benchmark-${name} + ${benchmark_headers} + ${arg_UNPARSED_ARGUMENTS} + ) + + target_compile_features(benchmark-${name} PRIVATE cxx_std_${arg_CXX_STANDARD}) + target_include_directories(benchmark-${name} PRIVATE inc) + target_link_libraries(benchmark-${name} PRIVATE benchmark::benchmark) +endfunction() + +add_benchmark(std_copy + src/std_copy.cpp + CXX_STANDARD 23 +) diff --git a/benchmarks/src/copy.cpp b/benchmarks/src/std_copy.cpp similarity index 100% rename from benchmarks/src/copy.cpp rename to benchmarks/src/std_copy.cpp From d77f88b1e06e3d0efcf087baeeff726f14337c82 Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Wed, 22 Jun 2022 10:58:26 -0700 Subject: [PATCH 17/22] Casey CRs --- README.md | 25 +++++++++++--------- benchmarks/inc/utility.hpp | 47 +++++++++++++++++++++++++++++++++++++ benchmarks/src/std_copy.cpp | 22 +++++++++-------- 3 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 benchmarks/inc/utility.hpp diff --git a/README.md b/README.md index 56566be39b4..f4332b5599d 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ Just try to follow these rules, so we can spend more time fixing bugs and implem # How To Build With The Visual Studio IDE -1. Install Visual Studio 2022 17.3 Preview 1 or later. +1. Install Visual Studio 2022 17.3 Preview 2 or later. * Select "Windows 11 SDK (10.0.22000.0)" in the VS Installer. * We recommend selecting "C++ CMake tools for Windows" in the VS Installer. This will ensure that you're using supported versions of CMake and Ninja. @@ -156,11 +156,11 @@ Just try to follow these rules, so we can spend more time fixing bugs and implem # How To Build With A Native Tools Command Prompt -1. Install Visual Studio 2022 17.3 Preview 1 or later. +1. Install Visual Studio 2022 17.3 Preview 2 or later. * Select "Windows 11 SDK (10.0.22000.0)" in the VS Installer. * We recommend selecting "C++ CMake tools for Windows" in the VS Installer. This will ensure that you're using supported versions of CMake and Ninja. - * Otherwise, install [CMake][] 3.22 or later, and [Ninja][] 1.10.2 or later. + * Otherwise, install [CMake][] 3.23 or later, and [Ninja][] 1.10.2 or later. * We recommend selecting "Python 3 64-bit" in the VS Installer. * Otherwise, make sure [Python][] 3.9 or later is available to CMake. 2. Open a command prompt. @@ -399,17 +399,20 @@ set PATH=C:\STL\out\build\x64\out\bin\amd64;%PATH% # Benchmarking -For performance sensitive code – like containers, algorithms, and the like – -you will likely wish to write and/or run benchmarks, and the STL team will likely -run any benchmarks we do have in our PR process. +For performance sensitive code – containers, algorithms, and the like – +you may wish to write and/or run benchmarks, and the STL team will likely +run any benchmarks we do have in our PR process. Additionally, +if you are writing a "performance improvement" PR, please add and run benchmarks +to show that the PR does, in fact, improve performance. -All benchmarks are located in `benchmarks`. Adding a new one is as easy as adding a new file -to `benchmarks/src`, and adding a benchmark using that file in `benchmarks/CMakeLists.txt`, -or modifying an existing file in `benchmarks/src`. We use Google's [Benchmark][gbenchmark] library, +The benchmarking code is located in `benchmarks`. Adding a new benchmark is as easy as adding a new file +to `benchmarks/src`, and then adding `add_benchmark( )` +to `benchmarks/CMakeLists.txt`. +You may also modify an existing benchmark file. We use Google's [Benchmark][gbenchmark] library, so you may find [their documentation][gbenchmark:docs] helpful, and you can also read the existing code for how _we_ use it. -To run benchmarks, you'll want to configure the STL with the `-DSTL_BUILD_BENCHMARKING=ON` option: +To run benchmarks, you'll need to configure the STL with the `-DSTL_BUILD_BENCHMARKING=ON` option: ```cmd > cmake -B out\bench -S . -G Ninja -DSTL_BUILD_BENCHMARKING=ON @@ -422,7 +425,7 @@ you can then run your benchmark with: > out\bench\benchmarks\benchmark- --benchmark_out= --benchmark_out_format=csv ``` -And then you can copy this csv file into your favorite Excel program. +And then you can copy this csv file into Excel, or another spreadsheet program. If you want to see all the other flags you can pass, run: diff --git a/benchmarks/inc/utility.hpp b/benchmarks/inc/utility.hpp new file mode 100644 index 00000000000..bba6956745b --- /dev/null +++ b/benchmarks/inc/utility.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include +#include +#include + +struct xoshiro256ss { + xoshiro256ss() = delete; + xoshiro256ss(uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3) : s0_(s0), s1_(s1), s2_(s2), s3_(s3) {} + + static uint64_t rotate_left(uint64_t x, int k) { + return (x << k) | (x >> (64 - k)); + } + + uint64_t next() { + auto result = rotate_left(s1_ * 5, 7) * 9; + + const uint64_t t = s1_ << 17; + + s2_ ^= s0_; + s3_ ^= s1_; + s1_ ^= s2_; + s0_ ^= s3_; + + s2_ ^= t; + + s3_ = rotate_left(s3_, 45); + + return result; + } + +private: + uint64_t s0_; + uint64_t s1_; + uint64_t s2_; + uint64_t s3_; +}; + +template +std::vector random_vector(size_t n) { + std::random_device rd; + xoshiro256ss prng{rd(), rd(), rd(), rd()}; + + std::vector res(n); + std::generate(res.begin(), res.end(), [&prng]() { return static_cast(prng.next()); }); + return res; +} diff --git a/benchmarks/src/std_copy.cpp b/benchmarks/src/std_copy.cpp index d358f21415c..a84d58d19d4 100644 --- a/benchmarks/src/std_copy.cpp +++ b/benchmarks/src/std_copy.cpp @@ -9,12 +9,14 @@ #include #include +#include namespace { + template void handwritten_loop(benchmark::State& state) { - const size_t r0 = static_cast(state.range(0)); - const std::vector in_buffer(r0); + const size_t r0 = static_cast(state.range(0)); + const auto in_buffer = random_vector(r0); std::vector out_buffer(r0); for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer.data()); @@ -31,8 +33,8 @@ namespace { template void handwritten_loop_n(benchmark::State& state) { - const size_t r0 = static_cast(state.range(0)); - const std::vector in_buffer(r0); + const size_t r0 = static_cast(state.range(0)); + const auto in_buffer = random_vector(r0); std::vector out_buffer(r0); for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer.data()); @@ -50,8 +52,8 @@ namespace { void memcpy_call(benchmark::State& state) { static_assert( std::is_trivially_copyable_v, "memcpy must only be called on trivially copyable types"); - const size_t r0 = static_cast(state.range(0)); - const std::vector in_buffer(r0); + const size_t r0 = static_cast(state.range(0)); + const auto in_buffer = random_vector(r0); std::vector out_buffer(r0); for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer.data()); @@ -62,8 +64,8 @@ namespace { template void std_copy_call(benchmark::State& state) { - const size_t r0 = static_cast(state.range(0)); - const std::vector in_buffer(r0); + const size_t r0 = static_cast(state.range(0)); + const auto in_buffer = random_vector(r0); std::vector out_buffer(r0); for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer.data()); @@ -74,8 +76,8 @@ namespace { template void std_copy_n_call(benchmark::State& state) { - const size_t r0 = static_cast(state.range(0)); - const std::vector in_buffer(r0); + const size_t r0 = static_cast(state.range(0)); + const auto in_buffer = random_vector(r0); std::vector out_buffer(r0); for ([[maybe_unused]] auto _ : state) { benchmark::DoNotOptimize(in_buffer.data()); From 756f6c6120b5b79f16572591c04a2500c520a896 Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Wed, 22 Jun 2022 18:14:27 -0700 Subject: [PATCH 18/22] more CRs --- README.md | 2 +- benchmarks/inc/utility.hpp | 42 ++++++++------------------------------ benchmarks/inc/xoshiro.hpp | 38 ++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 35 deletions(-) create mode 100644 benchmarks/inc/xoshiro.hpp diff --git a/README.md b/README.md index f4332b5599d..b3ee4cf7aa5 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ Just try to follow these rules, so we can spend more time fixing bugs and implem * Select "Windows 11 SDK (10.0.22000.0)" in the VS Installer. * We recommend selecting "C++ CMake tools for Windows" in the VS Installer. This will ensure that you're using supported versions of CMake and Ninja. - * Otherwise, install [CMake][] 3.22 or later, and [Ninja][] 1.10.2 or later. + * Otherwise, install [CMake][] 3.23 or later, and [Ninja][] 1.10.2 or later. * We recommend selecting "Python 3 64-bit" in the VS Installer. * Otherwise, make sure [Python][] 3.9 or later is available to CMake. 2. Open Visual Studio, and choose the "Clone or check out code" option. Enter the URL of this repository, diff --git a/benchmarks/inc/utility.hpp b/benchmarks/inc/utility.hpp index bba6956745b..4d838507698 100644 --- a/benchmarks/inc/utility.hpp +++ b/benchmarks/inc/utility.hpp @@ -1,47 +1,21 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + #pragma once -#include +#include #include #include -struct xoshiro256ss { - xoshiro256ss() = delete; - xoshiro256ss(uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3) : s0_(s0), s1_(s1), s2_(s2), s3_(s3) {} - - static uint64_t rotate_left(uint64_t x, int k) { - return (x << k) | (x >> (64 - k)); - } - - uint64_t next() { - auto result = rotate_left(s1_ * 5, 7) * 9; - - const uint64_t t = s1_ << 17; - - s2_ ^= s0_; - s3_ ^= s1_; - s1_ ^= s2_; - s0_ ^= s3_; - - s2_ ^= t; - - s3_ = rotate_left(s3_, 45); - - return result; - } - -private: - uint64_t s0_; - uint64_t s1_; - uint64_t s2_; - uint64_t s3_; -}; +#include template std::vector random_vector(size_t n) { std::random_device rd; - xoshiro256ss prng{rd(), rd(), rd(), rd()}; + std::uniform_int_distribution id64; + xoshiro256ss prng{id64(rd), id64(rd), id64(rd), id64(rd)}; std::vector res(n); - std::generate(res.begin(), res.end(), [&prng]() { return static_cast(prng.next()); }); + std::generate(res.begin(), res.end(), [&prng] { return static_cast(prng.next()); }); return res; } diff --git a/benchmarks/inc/xoshiro.hpp b/benchmarks/inc/xoshiro.hpp new file mode 100644 index 00000000000..070a006d957 --- /dev/null +++ b/benchmarks/inc/xoshiro.hpp @@ -0,0 +1,38 @@ +/* Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) + +To the extent possible under law, the author has dedicated all copyright +and related and neighboring rights to this software to the public domain +worldwide. This software is distributed without any warranty. + +See . */ + +#include +#include + +struct xoshiro256ss { + xoshiro256ss() = delete; + xoshiro256ss(uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3) : s0_(s0), s1_(s1), s2_(s2), s3_(s3) {} + + uint64_t next() { + auto result = std::rotl(s1_ * 5, 7) * 9; + + const uint64_t t = s1_ << 17; + + s2_ ^= s0_; + s3_ ^= s1_; + s1_ ^= s2_; + s0_ ^= s3_; + + s2_ ^= t; + + s3_ = std::rotl(s3_, 45); + + return result; + } + +private: + uint64_t s0_; + uint64_t s1_; + uint64_t s2_; + uint64_t s3_; +}; From b80c5d84ce42218ddb5d71183deb473fff74df21 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 22 Jun 2022 23:08:44 -0700 Subject: [PATCH 19/22] Add SPDX-License-Identifier to xoshiro.hpp --- benchmarks/inc/xoshiro.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmarks/inc/xoshiro.hpp b/benchmarks/inc/xoshiro.hpp index 070a006d957..c356196bf8f 100644 --- a/benchmarks/inc/xoshiro.hpp +++ b/benchmarks/inc/xoshiro.hpp @@ -4,7 +4,8 @@ To the extent possible under law, the author has dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. -See . */ +See . +SPDX-License-Identifier: CC0-1.0 */ #include #include From 36798a7cd9176b5de0b5f45719f0be83dc61ce9c Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 22 Jun 2022 23:17:55 -0700 Subject: [PATCH 20/22] Fix Casey's damage --- benchmarks/inc/xoshiro.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/inc/xoshiro.hpp b/benchmarks/inc/xoshiro.hpp index c356196bf8f..e8fb55cc86e 100644 --- a/benchmarks/inc/xoshiro.hpp +++ b/benchmarks/inc/xoshiro.hpp @@ -4,7 +4,7 @@ To the extent possible under law, the author has dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. -See . +See . SPDX-License-Identifier: CC0-1.0 */ #include From f13531d06fd31af7316e68a16c8d398b62a07fef Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Wed, 29 Jun 2022 10:38:52 -0700 Subject: [PATCH 21/22] add xoshiro notice --- NOTICE.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/NOTICE.txt b/NOTICE.txt index 8c846a8667a..aaf9139363c 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -216,3 +216,13 @@ In addition, certain files include the notices provided below. // shall not be used in advertising or otherwise to promote the sale, // use or other dealings in these Data Files or Software without prior // written authorization of the copyright holder. + +---------------------- + +/* Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) + +To the extent possible under law, the author has dedicated all copyright +and related and neighboring rights to this software to the public domain +worldwide. This software is distributed without any warranty. + +See .*/ From db7ff9452ed71da77942f1724ac51177f3b86fab Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 29 Jun 2022 21:40:35 -0700 Subject: [PATCH 22/22] Code review feedback. --- NOTICE.txt | 2 +- README.md | 22 ++++++++++++++-------- azure-devops/checkout-sources.yml | 3 ++- benchmarks/CMakeLists.txt | 2 ++ benchmarks/inc/utility.hpp | 2 ++ benchmarks/inc/xoshiro.hpp | 2 ++ 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index aaf9139363c..4a81a50be05 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -225,4 +225,4 @@ To the extent possible under law, the author has dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. -See .*/ +See . */ diff --git a/README.md b/README.md index dfadd836057..0a87ab04a22 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ Just try to follow these rules, so we can spend more time fixing bugs and implem 2. Open Visual Studio, and choose the "Clone or check out code" option. Enter the URL of this repository, `https://github.com/microsoft/STL`. 3. Open a terminal in the IDE with `` Ctrl + ` `` (by default) or press on "View" in the top bar, and then "Terminal". -4. In the terminal, invoke `git submodule update --init --progress llvm-project boost-math` +4. In the terminal, invoke `git submodule update --init --progress` 5. Choose the architecture you wish to build in the IDE, and build as you would any other project. All necessary CMake settings are set by `CMakeSettings.json`. @@ -400,7 +400,7 @@ set PATH=C:\STL\out\build\x64\out\bin\amd64;%PATH% # Benchmarking -For performance sensitive code – containers, algorithms, and the like – +For performance-sensitive code – containers, algorithms, and the like – you may wish to write and/or run benchmarks, and the STL team will likely run any benchmarks we do have in our PR process. Additionally, if you are writing a "performance improvement" PR, please add and run benchmarks @@ -416,22 +416,26 @@ for how _we_ use it. To run benchmarks, you'll need to configure the STL with the `-DSTL_BUILD_BENCHMARKING=ON` option: ```cmd -> cmake -B out\bench -S . -G Ninja -DSTL_BUILD_BENCHMARKING=ON -> cmake --build out\bench +cmake -B out\bench -S . -G Ninja -DSTL_BUILD_BENCHMARKING=ON +cmake --build out\bench ``` -you can then run your benchmark with: +You can then run your benchmark with: ```cmd -> out\bench\benchmarks\benchmark- --benchmark_out= --benchmark_out_format=csv +out\bench\benchmarks\benchmark- --benchmark_out= --benchmark_out_format=csv ``` -And then you can copy this csv file into Excel, or another spreadsheet program. +And then you can copy this csv file into Excel, or another spreadsheet program. For example: + +```cmd +out\bench\benchmarks\benchmark-std_copy --benchmark_out=benchmark-std_copy-results.csv --benchmark_out_format=csv +``` If you want to see all the other flags you can pass, run: ```cmd -> out\bench\benchmarks\benchmark- --help +out\bench\benchmarks\benchmark- --help ``` # Editing And Testing The Debugger Visualizer @@ -536,6 +540,8 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [bug tag]: https://github.com/microsoft/STL/issues?q=is%3Aopen+is%3Aissue+label%3Abug [cxx20 tag]: https://github.com/microsoft/STL/issues?q=is%3Aopen+is%3Aissue+label%3Acxx20 [enhancement tag]: https://github.com/microsoft/STL/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement +[gbenchmark]: https://github.com/google/benchmark +[gbenchmark:docs]: https://github.com/google/benchmark/blob/main/docs/user_guide.md [hub]: https://support.microsoft.com/en-us/help/4021566/windows-10-send-feedback-to-microsoft-with-feedback-hub-app [libcxx]: https://libcxx.llvm.org [lit]: https://llvm.org/docs/CommandGuide/lit.html diff --git a/azure-devops/checkout-sources.yml b/azure-devops/checkout-sources.yml index 6bc3ed83181..44a7afbc2ff 100644 --- a/azure-devops/checkout-sources.yml +++ b/azure-devops/checkout-sources.yml @@ -90,5 +90,6 @@ steps: ) git fetch --filter=tree:0 --depth=1 googlebenchmark $(${{ parameters.googleBenchmarkSHAVar }}) - git checkout -f FETCH_HEAD + git reset --quiet --hard FETCH_HEAD + git clean --quiet -x -d -f -f displayName: "Checkout google benchmark source" diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 7c526b2fe8d..4c684445087 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -44,6 +44,8 @@ add_subdirectory(google-benchmark EXCLUDE_FROM_ALL) set(benchmark_headers "inc/udt.hpp" + "inc/utility.hpp" + "inc/xoshiro.hpp" ) function(add_benchmark name) diff --git a/benchmarks/inc/utility.hpp b/benchmarks/inc/utility.hpp index 4d838507698..a27e1bacea6 100644 --- a/benchmarks/inc/utility.hpp +++ b/benchmarks/inc/utility.hpp @@ -5,6 +5,8 @@ #include #include +#include +#include #include #include diff --git a/benchmarks/inc/xoshiro.hpp b/benchmarks/inc/xoshiro.hpp index e8fb55cc86e..82d4856ef52 100644 --- a/benchmarks/inc/xoshiro.hpp +++ b/benchmarks/inc/xoshiro.hpp @@ -7,6 +7,8 @@ worldwide. This software is distributed without any warranty. See . SPDX-License-Identifier: CC0-1.0 */ +#pragma once + #include #include