Skip to content

Commit

Permalink
Add 'BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE' (2) (#5167)
Browse files Browse the repository at this point in the history
* Add 'BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE' (2)

* Forgot one file
  • Loading branch information
Marshall Clow authored and GitHub Enterprise committed Jan 17, 2025
1 parent 86f88ed commit d53f30b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 5 deletions.
7 changes: 4 additions & 3 deletions groups/bsl/bsl+bslhdrs/bsl_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ namespace bsl {

#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
using std::align_val_t;
// As of Apr-2022, no one (libc++, libstdc++, MSVC) has implemented these.
// using std::hardware_constructive_interference_size;
// using std::hardware_destructive_interference_size;
# ifdef BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE
using std::hardware_constructive_interference_size;
using std::hardware_destructive_interference_size;
# endif // BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE
using std::launder;
#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY

Expand Down
32 changes: 32 additions & 0 deletions groups/bsl/bslim/bslim_bslstandardheadertest.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,38 @@ int main(int argc, char *argv[])
printf("TEST " __FILE__ " CASE %d\n", test);

switch (test) { case 0: // Zero is always the leading case.
case 39: {
// --------------------------------------------------------------------
// HARDWARE_INTERFERENCE
//
// Concerns:
// 1. The `bsl::hardware_constructive_interference_size` variable is
// available in `bsl` to users who include `bsl_new.h`.
// 2. The `bsl::hardware_destructive_interference_size` variable is
// available in `bsl` to users who include `bsl_new.h`.
//
// Plan:
// 1. Create a simple example that uses the variables. Compilation of
// the example demonstrates that the function can be found in `bsl`,
// but only if BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE
// is defined.
//
// Testing
// CONCERN: `hardware_constructive_interference_size` is in `bsl`.
// CONCERN: `hardware_destructive_interference_size` is in `bsl`.
// --------------------------------------------------------------------
if (verbose) puts("\nHARDWARE_INTERFERENCE"
"\n=====================");
#if !defined(BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE)
if (verbose) puts("\nHW Interference variables are not supported "
"on this platform");
#else
const size_t con = bsl::hardware_constructive_interference_size;
const size_t dis = bsl::hardware_destructive_interference_size;
(void) con;
(void) dis;
#endif
} break;
case 38: {
// --------------------------------------------------------------------
// `bsl::copy_n`
Expand Down
5 changes: 5 additions & 0 deletions groups/bsl/bsls/bsls_compilerfeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,11 @@ BSLS_IDENT("$Id: $")
#define BSLS_COMPILERFEATURES_SUPPORT_CONCEPTS 1
#endif

#if defined(__cpp_lib_hardware_interference_size) && \
__cpp_lib_hardware_interference_size >= 201703L
#define BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE 1
#endif

#if defined(__cpp_impl_three_way_comparison) && \
__cpp_impl_three_way_comparison >= 201907L
#if defined(__cpp_lib_three_way_comparison) && \
Expand Down
47 changes: 45 additions & 2 deletions groups/bsl/bsls/bsls_compilerfeatures.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include <type_traits> // For testing only
#endif

#ifdef BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE
#include <new>
#endif

//=============================================================================
// TEST PLAN
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -69,6 +73,7 @@
// [ 8] BSLS_COMPILERFEATURES_SUPPORT_EXTERN_TEMPLATE
// [ 9] BSLS_COMPILERFEATURES_SUPPORT_FINAL
// [10] BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
// [41] BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE
// [23] BSLS_COMPILERFEATURES_SUPPORT_HAS_INCLUDE
// [35] BSLS_COMPILERFEATURES_SUPPORT_HEXFLOAT_LITERALS
// [11] BSLS_COMPILERFEATURES_SUPPORT_INCLUDE_NEXT
Expand All @@ -94,7 +99,7 @@
// [ ] BSLS_COMPILERFEATURES_FORWARD_REF
// [ ] BSLS_COMPILERFEATURES_FORWARD
// ----------------------------------------------------------------------------
// [41] USAGE EXAMPLE
// [42] USAGE EXAMPLE

#ifdef BDE_VERIFY
// Suppress some pedantic bde_verify checks in this test driver
Expand Down Expand Up @@ -1914,6 +1919,13 @@ static void printFlags()
puts("UNDEFINED");
#endif

fputs("\n BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE: ", stdout);
#ifdef BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE
puts(STRINGIFY(BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE));
#else
puts("UNDEFINED");
#endif

puts("\n\n==printFlags: bsls_compilerfeatures Referenced Macros==");

fputs("\n BSLS_COMPILERFEATURES_SIMULATE_FORWARD_WORKAROUND: ", stdout);
Expand Down Expand Up @@ -2184,7 +2196,7 @@ int main(int argc, char *argv[])
}

switch (test) { case 0:
case 41: {
case 42: {
// --------------------------------------------------------------------
// USAGE EXAMPLE
//
Expand Down Expand Up @@ -2265,6 +2277,37 @@ int main(int argc, char *argv[])
// compilers) that further, more complicated or even indeterminate behaviors
// may arise.
#undef THATS_MY_LINE
} break;
case 41: {
// --------------------------------------------------------------------
// BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE
//
// Concerns:
// 1. `BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE` is defined
// when the corresponding constants are defined.
//
// Plan:
// 1. Verify that the constants are defined when the macro is defined.
//
// Testing:
// BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE
// --------------------------------------------------------------------

MACRO_TEST_TITLE("_SUPPORT_HARDWARE_INTERFERENCE",
"==============================");

#ifndef BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE
VERBOSE_PUTS("The feature is not supported in this configuration.");
#else
ASSERT((std::is_same_v<
const size_t,
decltype(std::hardware_destructive_interference_size)>));

ASSERT((std::is_same_v<
const size_t,
decltype(std::hardware_constructive_interference_size)>));

#endif // BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE
} break;
case 40: {
// ------------------------------------------------------------------
Expand Down

0 comments on commit d53f30b

Please sign in to comment.