diff --git a/groups/bsl/bsl+bslhdrs/bsl_new.h b/groups/bsl/bsl+bslhdrs/bsl_new.h index c68150ad8b..249db0c94f 100644 --- a/groups/bsl/bsl+bslhdrs/bsl_new.h +++ b/groups/bsl/bsl+bslhdrs/bsl_new.h @@ -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 diff --git a/groups/bsl/bslim/bslim_bslstandardheadertest.t.cpp b/groups/bsl/bslim/bslim_bslstandardheadertest.t.cpp index 4ef90d4bb4..4288872e4b 100644 --- a/groups/bsl/bslim/bslim_bslstandardheadertest.t.cpp +++ b/groups/bsl/bslim/bslim_bslstandardheadertest.t.cpp @@ -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` diff --git a/groups/bsl/bsls/bsls_compilerfeatures.h b/groups/bsl/bsls/bsls_compilerfeatures.h index 73d569b365..865bad0706 100644 --- a/groups/bsl/bsls/bsls_compilerfeatures.h +++ b/groups/bsl/bsls/bsls_compilerfeatures.h @@ -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) && \ diff --git a/groups/bsl/bsls/bsls_compilerfeatures.t.cpp b/groups/bsl/bsls/bsls_compilerfeatures.t.cpp index e5567f7223..7937e92770 100644 --- a/groups/bsl/bsls/bsls_compilerfeatures.t.cpp +++ b/groups/bsl/bsls/bsls_compilerfeatures.t.cpp @@ -26,6 +26,10 @@ #include // For testing only #endif +#ifdef BSLS_COMPILERFEATURES_SUPPORT_HARDWARE_INTERFERENCE + #include +#endif + //============================================================================= // TEST PLAN //----------------------------------------------------------------------------- @@ -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 @@ -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 @@ -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); @@ -2184,7 +2196,7 @@ int main(int argc, char *argv[]) } switch (test) { case 0: - case 41: { + case 42: { // -------------------------------------------------------------------- // USAGE EXAMPLE // @@ -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: { // ------------------------------------------------------------------