Consolidate Abseil CPU detection and restore Randen HWAES builds

Abseil previously split runtime CPU feature probing across `cpu_detect` and
`randen_detect`, duplicating platform queries while accumulating divergent bugs
(uncached per-call `CPUID` on x86, `dlopen("libc.so")` lookups on Android, and
`ENOMEM` failures reading Darwin's multi-word `hw.optional.arm.caps` into a
`uint64_t`). Meanwhile, build and preprocessor mismatches disabled Randen
hardware AES across CMake, MSVC, `clang-cl`, MinGW, 32-bit ARMv8, and big-endian
`ppc64` builds (or broke `-mavx -mno-aes` builds and silently skipped
`randen_hwaes_test` when HWAES flags were lost).

Unifying detection behind a single cached `CpuFeatures` snapshot in
`absl/base/internal/cpu_detect` and isolating accurate HWAES compiler flags to
`randen_hwaes.cc` fixes both sets of issues in one place and removes
`randen_detect`.

PiperOrigin-RevId: 1026763126
diff --git a/CMake/AbseilDll.cmake b/CMake/AbseilDll.cmake
index 407b72a..1f111cd 100644
--- a/CMake/AbseilDll.cmake
+++ b/CMake/AbseilDll.cmake
@@ -13,8 +13,11 @@
   "base/dynamic_annotations.h"
   "base/fast_type_id.h"
   "base/internal/atomic_hook.h"
-  "base/internal/cpu_detect.cc"
   "base/internal/cpu_detect.h"
+  "base/internal/cpu_detect_arm.cc"
+  "base/internal/cpu_detect_other.cc"
+  "base/internal/cpu_detect_ppc.cc"
+  "base/internal/cpu_detect_x86.cc"
   "base/internal/cycleclock.cc"
   "base/internal/cycleclock.h"
   "base/internal/cycleclock_config.h"
@@ -253,8 +256,6 @@
   "random/internal/platform.h"
   "random/internal/randen.cc"
   "random/internal/randen.h"
-  "random/internal/randen_detect.cc"
-  "random/internal/randen_detect.h"
   "random/internal/randen_engine.h"
   "random/internal/randen_hwaes.cc"
   "random/internal/randen_hwaes.h"
@@ -633,6 +634,18 @@
     SHARED
       ${_dll_files}
   )
+  if (NOT ABSL_INTERNAL_MAKE_DLL_TEST AND ABSL_RANDOM_RANDEN_COPTS)
+    set(_randen_hwaes_copts "")
+    foreach(_flag IN LISTS ABSL_RANDOM_RANDEN_COPTS)
+      string(REGEX REPLACE "^SHELL:" "" _flag "${_flag}")
+      string(APPEND _randen_hwaes_copts " ${_flag}")
+    endforeach()
+    string(STRIP "${_randen_hwaes_copts}" _randen_hwaes_copts)
+    set_source_files_properties(
+      "random/internal/randen_hwaes.cc"
+      PROPERTIES COMPILE_FLAGS "${_randen_hwaes_copts}"
+    )
+  endif()
   target_link_libraries(
     ${_dll}
     PRIVATE
diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel
index 66f173e..a3de7d6 100644
--- a/absl/base/BUILD.bazel
+++ b/absl/base/BUILD.bazel
@@ -63,7 +63,10 @@
 cc_library(
     name = "cpu_detect",
     srcs = [
-        "internal/cpu_detect.cc",
+        "internal/cpu_detect_arm.cc",
+        "internal/cpu_detect_other.cc",
+        "internal/cpu_detect_ppc.cc",
+        "internal/cpu_detect_x86.cc",
     ],
     hdrs = ["internal/cpu_detect.h"],
     copts = ABSL_DEFAULT_COPTS,
diff --git a/absl/base/CMakeLists.txt b/absl/base/CMakeLists.txt
index dc72d45..8afe7b0 100644
--- a/absl/base/CMakeLists.txt
+++ b/absl/base/CMakeLists.txt
@@ -36,9 +36,11 @@
   HDRS
     "internal/cpu_detect.h"
   SRCS
-    "internal/cpu_detect.cc"
+    "internal/cpu_detect_arm.cc"
+    "internal/cpu_detect_other.cc"
+    "internal/cpu_detect_ppc.cc"
+    "internal/cpu_detect_x86.cc"
   DEPS
-    absl::base
     absl::config
   COPTS
     ${ABSL_DEFAULT_COPTS}
@@ -662,6 +664,7 @@
   DEPS
     absl::base_cpu_detect
     absl::config
+    GTest::gmock
     GTest::gtest_main
 )
 
diff --git a/absl/base/internal/cpu_detect.cc b/absl/base/internal/cpu_detect.cc
deleted file mode 100644
index da0a34a..0000000
--- a/absl/base/internal/cpu_detect.cc
+++ /dev/null
@@ -1,566 +0,0 @@
-// Copyright 2022 The Abseil Authors
-//
-// 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
-//
-//     https://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.
-
-#include "absl/base/internal/cpu_detect.h"
-
-#include <cstdint>
-#include <optional>  // IWYU pragma: keep
-#include <string>
-
-#include "absl/base/config.h"
-
-#if defined(__aarch64__) && defined(__linux__)
-#include <asm/hwcap.h>
-#include <sys/auxv.h>
-#endif
-
-#if defined(__aarch64__) && defined(__APPLE__)
-#if __has_include(<arm/cpu_capabilities_public.h>)
-#include <arm/cpu_capabilities_public.h>
-#endif
-#include <sys/sysctl.h>
-#include <sys/types.h>
-#endif
-
-#if defined(_WIN32) || defined(_WIN64)
-#include <intrin.h>
-#if defined(__aarch64__) || defined(_M_ARM64)
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
-#ifndef PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
-#define PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE 30
-#endif
-#ifndef PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
-#define PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE 31
-#endif
-#ifndef PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE
-#define PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE 64
-#endif
-#endif  // defined(__aarch64__) || defined(_M_ARM64)
-#endif
-
-#if defined(__x86_64__) || defined(_M_X64)
-#if ABSL_HAVE_BUILTIN(__cpuid)
-// MSVC-equivalent __cpuid intrinsic declaration for clang-like compilers
-// for non-Windows build environments.
-extern void __cpuid(int[4], int);
-extern void __cpuidex(int[4], int, int);
-#elif !defined(_WIN32) && !defined(_WIN64)
-// MSVC defines this function for us.
-// https://learn.microsoft.com/en-us/cpp/intrinsics/cpuid-cpuidex
-static void __cpuid(int cpu_info[4], int info_type) {
-  __asm__ volatile("cpuid \n\t"
-                   : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]),
-                     "=d"(cpu_info[3])
-                   : "a"(info_type), "c"(0));
-}
-static void __cpuidex(int cpu_info[4], int info_type, int ecx) {
-  __asm__ volatile("cpuid \n\t"
-                   : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]),
-                     "=d"(cpu_info[3])
-                   : "a"(info_type), "c"(ecx));
-}
-#endif  // !defined(_WIN32) && !defined(_WIN64)
-#endif  // defined(__x86_64__) || defined(_M_X64)
-
-namespace absl {
-ABSL_NAMESPACE_BEGIN
-namespace base_internal {
-
-#if defined(__x86_64__) || defined(_M_X64)
-
-namespace {
-
-enum class Vendor {
-  kUnknown,
-  kIntel,
-  kAmd,
-};
-
-Vendor GetVendor() {
-  // Get the vendor string (issue CPUID with eax = 0).
-  int cpu_info[4];
-  __cpuid(cpu_info, 0);
-
-  std::string vendor;
-  vendor.append(reinterpret_cast<char*>(&cpu_info[1]), 4);
-  vendor.append(reinterpret_cast<char*>(&cpu_info[3]), 4);
-  vendor.append(reinterpret_cast<char*>(&cpu_info[2]), 4);
-  if (vendor == "GenuineIntel") {
-    return Vendor::kIntel;
-  } else if (vendor == "AuthenticAMD") {
-    return Vendor::kAmd;
-  } else {
-    return Vendor::kUnknown;
-  }
-}
-
-CpuType GetIntelCpuType() {
-  // To get general information and extended features we send eax = 1 and
-  // ecx = 0 to cpuid.  The response is returned in eax, ebx, ecx and edx.
-  // (See Intel 64 and IA-32 Architectures Software Developer's Manual
-  // Volume 2A: Instruction Set Reference, A-M CPUID).
-  // https://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-software-developer-vol-2a-manual.html
-  // https://learn.microsoft.com/en-us/cpp/intrinsics/cpuid-cpuidex
-  int cpu_info[4];
-  __cpuid(cpu_info, 1);
-
-  // Response in eax bits as follows:
-  // 0-3 (stepping id)
-  // 4-7 (model number),
-  // 8-11 (family code),
-  // 12-13 (processor type),
-  // 16-19 (extended model)
-  // 20-27 (extended family)
-
-  int family = (cpu_info[0] >> 8) & 0x0f;
-  int model_num = (cpu_info[0] >> 4) & 0x0f;
-  int ext_family = (cpu_info[0] >> 20) & 0xff;
-  int ext_model_num = (cpu_info[0] >> 16) & 0x0f;
-
-  int brand_id = cpu_info[1] & 0xff;
-
-  // Process the extended family and model info if necessary
-  if (family == 0x0f) {
-    family += ext_family;
-  }
-
-  if (family == 0x0f || family == 0x6) {
-    model_num += (ext_model_num << 4);
-  }
-
-  switch (brand_id) {
-    case 0:  // no brand ID, so parse CPU family/model
-      switch (family) {
-        case 6:  // Most PentiumIII processors are in this category
-          switch (model_num) {
-            case 0x2c:  // Westmere: Gulftown
-              return CpuType::kIntelWestmere;
-            case 0x2d:  // Sandybridge
-              return CpuType::kIntelSandybridge;
-            case 0x3e:  // Ivybridge
-              return CpuType::kIntelIvybridge;
-            case 0x3c:  // Haswell (client)
-            case 0x3f:  // Haswell
-              return CpuType::kIntelHaswell;
-            case 0x4f:  // Broadwell
-            case 0x56:  // BroadwellDE
-              return CpuType::kIntelBroadwell;
-            case 0x55:                         // Skylake Xeon
-              if ((cpu_info[0] & 0x0f) < 5) {  // stepping < 5 is skylake
-                return CpuType::kIntelSkylakeXeon;
-              } else {  // stepping >= 5 is cascadelake
-                return CpuType::kIntelCascadelakeXeon;
-              }
-            case 0x5e:  // Skylake (client)
-              return CpuType::kIntelSkylake;
-            case 0x6a:  // Ice Lake
-              return CpuType::kIntelIcelake;
-            case 0x8f:  // Sapphire Rapids
-              return CpuType::kIntelSapphirerapids;
-            case 0xcf:  // Emerald Rapids
-              return CpuType::kIntelEmeraldrapids;
-            case 0xad:  // Granite Rapids
-              return CpuType::kIntelGraniterapids;
-            default:
-              return CpuType::kUnknown;
-          }
-        default:
-          return CpuType::kUnknown;
-      }
-    default:
-      return CpuType::kUnknown;
-  }
-}
-
-CpuType GetAmdCpuType() {
-  // To get general information and extended features we send eax = 1 and
-  // ecx = 0 to cpuid.  The response is returned in eax, ebx, ecx and edx.
-  // (See Intel 64 and IA-32 Architectures Software Developer's Manual
-  // Volume 2A: Instruction Set Reference, A-M CPUID).
-  // https://learn.microsoft.com/en-us/cpp/intrinsics/cpuid-cpuidex
-  int cpu_info[4];
-  __cpuid(cpu_info, 1);
-
-  // Response in eax bits as follows:
-  // 0-3 (stepping id)
-  // 4-7 (model number),
-  // 8-11 (family code),
-  // 12-13 (processor type),
-  // 16-19 (extended model)
-  // 20-27 (extended family)
-
-  int family = (cpu_info[0] >> 8) & 0x0f;
-  int model_num = (cpu_info[0] >> 4) & 0x0f;
-  int ext_family = (cpu_info[0] >> 20) & 0xff;
-  int ext_model_num = (cpu_info[0] >> 16) & 0x0f;
-
-  if (family == 0x0f) {
-    family += ext_family;
-    model_num += (ext_model_num << 4);
-  }
-
-  switch (family) {
-    case 0x17:
-      switch (model_num) {
-        case 0x0:  // Stepping Ax
-        case 0x1:  // Stepping Bx
-          return CpuType::kAmdNaples;
-        case 0x30:  // Stepping Ax
-        case 0x31:  // Stepping Bx
-          return CpuType::kAmdRome;
-        default:
-          return CpuType::kUnknown;
-      }
-      break;
-    case 0x19:
-      switch (model_num) {
-        case 0x0:  // Stepping Ax
-        case 0x1:  // Stepping B0
-          return CpuType::kAmdMilan;
-        case 0x10:  // Stepping A0
-        case 0x11:  // Stepping B0
-          return CpuType::kAmdGenoa;
-        case 0x44:  // Stepping A0
-          return CpuType::kAmdRyzenV3000;
-        case 0xA0:  // Stepping A0
-          return CpuType::kAmdSiena;
-        default:
-          return CpuType::kUnknown;
-      }
-      break;
-    case 0x1A:
-      if (model_num >= 0x50 && model_num <= 0x5F) {
-        return CpuType::kAmdVenice;
-      }
-      switch (model_num) {
-        case 0x2:
-          return CpuType::kAmdTurin;
-        default:
-          return CpuType::kUnknown;
-      }
-      break;
-    default:
-      return CpuType::kUnknown;
-  }
-}
-
-// Reads extended control register 0 (XCR0). The caller must verify via CPUID
-// that the CPU and OS support OSXSAVE before calling this function.
-uint64_t ReadXcr0() {
-#if defined(_MSC_VER)
-  return _xgetbv(0);
-#elif defined(__GNUC__) || defined(__clang__)
-  uint32_t eax = 0;
-  uint32_t edx = 0;
-  // Use the raw opcode for xgetbv (0F 01 D0) so this compiles without -mxsave
-  // and on assemblers that do not recognize the xgetbv mnemonic.
-  __asm__ volatile(".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c"(0));
-  return (static_cast<uint64_t>(edx) << 32) | eax;
-#else
-  return 0;
-#endif
-}
-
-}  // namespace
-
-CpuType GetCpuType() {
-  switch (GetVendor()) {
-    case Vendor::kIntel:
-      return GetIntelCpuType();
-    case Vendor::kAmd:
-      return GetAmdCpuType();
-    default:
-      return CpuType::kUnknown;
-  }
-}
-
-bool SupportsArmCRC32PMULL() { return false; }
-
-bool SupportsArmSHA3() { return false; }
-
-bool SupportsAvx2() {
-  // Query CPUID and XCR0 directly instead of using __builtin_cpu_supports(),
-  // which pulls in a static initializer (__cpu_indicator_init) from the
-  // compiler runtime.
-  int cpu_info[4];
-  __cpuid(cpu_info, 0);
-  if (cpu_info[0] < 7) {
-    return false;
-  }
-  __cpuid(cpu_info, 1);
-  constexpr int kOsxsaveAndAvx = (1 << 27) | (1 << 28);
-  if ((cpu_info[2] & kOsxsaveAndAvx) != kOsxsaveAndAvx) {
-    return false;
-  }
-  // Check that the OS saves both XMM (bit 1) and YMM (bit 2) state.
-  constexpr uint64_t kXmmAndYmmState = 0x6;
-  if ((ReadXcr0() & kXmmAndYmmState) != kXmmAndYmmState) {
-    return false;
-  }
-  __cpuidex(cpu_info, 7, 0);
-  return (cpu_info[1] & (1 << 5)) != 0;
-}
-
-bool SupportsBmi2() {
-  int cpu_info[4];
-  __cpuid(cpu_info, 0);
-  if (cpu_info[0] < 7) {
-    return false;
-  }
-  __cpuidex(cpu_info, 7, 0);
-  return (cpu_info[1] & (1 << 8)) != 0;
-}
-
-#elif defined(__aarch64__) && defined(__linux__)
-
-#ifndef HWCAP_CPUID
-#define HWCAP_CPUID (1 << 11)
-#endif
-
-#define ABSL_INTERNAL_AARCH64_ID_REG_READ(id, val) \
-  asm("mrs %0, " #id : "=r"(val))
-
-CpuType GetCpuType() {
-  // MIDR_EL1 is not visible to EL0, however the access will be emulated by
-  // linux if AT_HWCAP has HWCAP_CPUID set.
-  //
-  // This method will be unreliable on heterogeneous computing systems (ex:
-  // big.LITTLE) since the value of MIDR_EL1 will change based on the calling
-  // thread.
-  uint64_t hwcaps = getauxval(AT_HWCAP);
-  if (hwcaps & HWCAP_CPUID) {
-    uint64_t midr = 0;
-    ABSL_INTERNAL_AARCH64_ID_REG_READ(MIDR_EL1, midr);
-    uint32_t implementer = (midr >> 24) & 0xff;
-    uint32_t part_number = (midr >> 4) & 0xfff;
-    switch (implementer) {
-      case 0x41:
-        switch (part_number) {
-          case 0xd0c:
-            return CpuType::kArmNeoverseN1;
-          case 0xd40:
-            return CpuType::kArmNeoverseV1;
-          case 0xd49:
-            return CpuType::kArmNeoverseN2;
-          case 0xd4f: {
-            uint64_t isar0 = 0;
-            ABSL_INTERNAL_AARCH64_ID_REG_READ(ID_AA64ISAR0_EL1, isar0);
-            if (((isar0 >> 60) & 0xf) == 0x0) {
-              return CpuType::kNvidiaGrace;
-            }
-            return CpuType::kArmNeoverseV2;
-          }
-          case 0xd84:
-            return CpuType::kArmNeoverseV3;
-          case 0xd8e:
-            return CpuType::kArmNeoverseN3;
-          case 0xd94:
-            return CpuType::kArmNeoverseN4;
-          default:
-            return CpuType::kUnknown;
-        }
-        break;
-      case 0x4e:
-        switch (part_number) {
-          case 0x010:
-            return CpuType::kNvidiaVera;
-          default:
-            return CpuType::kUnknown;
-        }
-        break;
-      case 0xc0:
-        switch (part_number) {
-          case 0xac3:
-            return CpuType::kAmpereSiryn;
-          default:
-            return CpuType::kUnknown;
-        }
-        break;
-      default:
-        return CpuType::kUnknown;
-    }
-  }
-  return CpuType::kUnknown;
-}
-
-bool SupportsArmCRC32PMULL() {
-#if defined(HWCAP_CRC32) && defined(HWCAP_PMULL)
-  static const bool supported = []() {
-    uint64_t hwcaps = getauxval(AT_HWCAP);
-    return (hwcaps & HWCAP_CRC32) && (hwcaps & HWCAP_PMULL);
-  }();
-  return supported;
-#else
-  return false;
-#endif
-}
-
-bool SupportsArmSHA3() {
-#if defined(HWCAP_SHA3)
-  static const bool supported = (getauxval(AT_HWCAP) & HWCAP_SHA3) != 0;
-  return supported;
-#else
-  return false;
-#endif
-}
-
-bool SupportsAvx2() { return false; }
-
-bool SupportsBmi2() { return false; }
-
-#elif defined(__aarch64__) && defined(__APPLE__)
-
-CpuType GetCpuType() { return CpuType::kUnknown; }
-
-template <typename T>
-static std::optional<T> ReadSysctlByName(const char* name) {
-  T val;
-  size_t val_size = sizeof(T);
-  int ret = sysctlbyname(name, &val, &val_size, nullptr, 0);
-  if (ret == -1) {
-    return std::nullopt;
-  }
-  return val;
-}
-
-bool SupportsArmCRC32PMULL() {
-  static const bool supported = []() {
-  // Newer XNU kernels support querying all capabilities in a single
-  // sysctlbyname.
-#if defined(CAP_BIT_CRC32) && defined(CAP_BIT_FEAT_PMULL)
-    const std::optional<uint64_t> caps =
-        ReadSysctlByName<uint64_t>("hw.optional.arm.caps");
-    if (caps.has_value()) {
-      constexpr uint64_t kCrc32AndPmullCaps =
-          (uint64_t{1} << CAP_BIT_CRC32) | (uint64_t{1} << CAP_BIT_FEAT_PMULL);
-      return (*caps & kCrc32AndPmullCaps) == kCrc32AndPmullCaps;
-    }
-#endif
-
-    // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#3915619
-    const std::optional<int> armv8_crc32 =
-        ReadSysctlByName<int>("hw.optional.armv8_crc32");
-    if (armv8_crc32.value_or(0) == 0) {
-      return false;
-    }
-    // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#3918855
-    const std::optional<int> feat_pmull =
-        ReadSysctlByName<int>("hw.optional.arm.FEAT_PMULL");
-    if (feat_pmull.value_or(0) == 0) {
-      return false;
-    }
-    return true;
-  }();
-  return supported;
-}
-
-bool SupportsArmSHA3() {
-  static const bool supported = []() {
-#if defined(CAP_BIT_FEAT_SHA3)
-    const std::optional<uint64_t> caps =
-        ReadSysctlByName<uint64_t>("hw.optional.arm.caps");
-    if (caps.has_value()) {
-      return (*caps & (uint64_t{1} << CAP_BIT_FEAT_SHA3)) != 0;
-    }
-#endif
-    const std::optional<int> feat_sha3 =
-        ReadSysctlByName<int>("hw.optional.armv8_2_sha3");
-    return feat_sha3.value_or(0) != 0;
-  }();
-  return supported;
-}
-
-bool SupportsAvx2() { return false; }
-
-bool SupportsBmi2() { return false; }
-
-#elif (defined(__aarch64__) || defined(_M_ARM64)) && \
-    (defined(_WIN32) || defined(_WIN64))
-
-CpuType GetCpuType() { return CpuType::kUnknown; }
-
-bool SupportsArmCRC32PMULL() {
-  return IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE) &&
-         IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE);
-}
-
-bool SupportsArmSHA3() {
-  return IsProcessorFeaturePresent(PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE);
-}
-
-bool SupportsAvx2() { return false; }
-
-bool SupportsBmi2() { return false; }
-
-#else
-
-CpuType GetCpuType() { return CpuType::kUnknown; }
-
-bool SupportsArmCRC32PMULL() { return false; }
-
-bool SupportsArmSHA3() { return false; }
-
-bool SupportsAvx2() { return false; }
-
-bool SupportsBmi2() { return false; }
-
-#endif
-
-// Returns how many hardware contexts per CPU exist. Note: AMD CPUs prior to Zen
-// 2 (Rome, 2019) do not support CPUID leaf 0xb. We intentionally avoid falling
-// back to leaf 1 ebx[23:16] because it reports total logical processors per
-// package (not threads per core), which risks false positives on older
-// multi-core non-SMT chips. Pre-Zen 2 AMD safely defaults to 1.
-int NumContextsPerCPU() {
-#if defined(__x86_64__) || defined(_M_X64)
-  int info[4];
-  __cpuid(info, 0);
-  if (info[0] < 0xb) {
-    return 1;
-  }
-
-  __cpuid(info, 1);
-  bool has_ht = (info[3] & (1 << 28)) != 0;
-  if (!has_ht) {
-    return 1;
-  }
-
-  for (int sub_leaf = 0; sub_leaf < 4; ++sub_leaf) {
-    __cpuidex(info, 0xb, sub_leaf);
-    int level_type = (info[2] >> 8) & 0xff;
-    if (level_type == 0) {
-      break;
-    }
-    if (level_type == 1) {
-      int num_threads = info[1] & 0x0ffff;
-      if (num_threads >= 1) {
-        return num_threads;
-      }
-    }
-  }
-
-  return 1;
-#else
-  return 1;
-#endif
-}
-
-bool IsSMTEnabled() { return NumContextsPerCPU() > 1; }
-
-}  // namespace base_internal
-ABSL_NAMESPACE_END
-}  // namespace absl
diff --git a/absl/base/internal/cpu_detect.h b/absl/base/internal/cpu_detect.h
index c247e27..96039b8 100644
--- a/absl/base/internal/cpu_detect.h
+++ b/absl/base/internal/cpu_detect.h
@@ -17,6 +17,24 @@
 
 #include "absl/base/config.h"
 
+// Exclude CUDA device compilation and Windows ARM64EC (which defines _M_X64),
+// matching Abseil's SIMD macro guards in absl/base/config.h.
+#if !defined(__CUDA_ARCH__)
+#if defined(__x86_64__) || defined(__x86_64) || defined(__i386__) ||    \
+    defined(__i386) ||                                                  \
+    ((defined(_M_X64) || defined(_M_AMD64)) && !defined(_M_ARM64EC)) || \
+    defined(_M_IX86)
+#define ABSL_INTERNAL_CPU_DETECT_X86 1
+#elif defined(__aarch64__) || defined(__arm64__) || defined(__arm__) ||  \
+    defined(__ARMEL__) || (defined(_M_ARM64) && !defined(_M_ARM64EC)) || \
+    defined(_M_ARM)
+#define ABSL_INTERNAL_CPU_DETECT_ARM 1
+#elif defined(__powerpc64__) || defined(__PPC64__) || defined(__powerpc__) || \
+    defined(__PPC__) || defined(__ppc__)
+#define ABSL_INTERNAL_CPU_DETECT_PPC 1
+#endif
+#endif  // !defined(__CUDA_ARCH__)
+
 namespace absl {
 ABSL_NAMESPACE_BEGIN
 namespace base_internal {
@@ -57,32 +75,113 @@
   kNvidiaVera,
 };
 
-// Returns the type of host CPU this code is running on.  Returns kUnknown if
+// Runtime CPU microarchitecture, SMT topology, and OS-verified instruction-set
+// detection.
+//
+// Features requiring OS register-state support (AVX/YMM and AVX-512/opmask+ZMM
+// on x86) are reported true only when both the CPU and the operating system
+// enable them.
+struct CpuFeatures {
+  CpuType type = CpuType::kUnknown;
+  int num_contexts_per_cpu = 1;
+
+#if defined(ABSL_INTERNAL_CPU_DETECT_X86)
+  bool has_ssse3 = false;     // SSSE3 (CPUID.1:ECX[9]).
+  bool has_sse4_1 = false;    // SSE4.1 (CPUID.1:ECX[19]).
+  bool has_aes = false;       // AES-NI (CPUID.1:ECX[25]).
+  bool has_avx2 = false;      // AVX2 + OS XMM/YMM state (XCR0[2:1]).
+  bool has_bmi2 = false;      // BMI2 GPR bit-manip (CPUID.7.0:EBX[8]).
+  bool has_vaes = false;      // Vector AES + OS YMM state.
+  bool has_avx512f = false;   // AVX-512F + OS opmask/ZMM state.
+  bool has_avx512bw = false;  // AVX-512BW + OS opmask/ZMM state.
+  bool has_avx512vl = false;  // AVX-512VL + OS opmask/ZMM state.
+#elif defined(ABSL_INTERNAL_CPU_DETECT_ARM)
+  bool has_neon = false;   // Advanced SIMD (NEON / ASIMD).
+  bool has_crc32 = false;  // ARMv8 FEAT_CRC32.
+  bool has_aes = false;    // ARMv8 FEAT_AES (AESE/AESD/AESMC/AESIMC).
+  bool has_pmull = false;  // ARMv8 FEAT_PMULL (64x64->128 polynomial mul).
+  bool has_sha3 = false;   // ARMv8.2 FEAT_SHA3 (EOR3/RAX1/XAR/BCAX).
+  bool has_sve2 = false;   // Non-streaming SVE2 (including XAR).
+#elif defined(ABSL_INTERNAL_CPU_DETECT_PPC)
+  bool has_vsx = false;      // Power ISA 2.06 VSX.
+  bool has_vcrypto = false;  // Power ISA 2.07 Vector.Crypto + POWER8 vector.
+#endif
+};
+
+// Returns the CPU features supported by the current host and OS. Thread-safe;
+// queries the hardware/OS once and caches the result.
+CpuFeatures GetCpuFeatures() noexcept;
+
+// Returns the type of host CPU this code is running on. Returns kUnknown if
 // the host CPU is of unknown type, or if detection otherwise fails.
-CpuType GetCpuType();
+inline CpuType GetCpuType() noexcept { return GetCpuFeatures().type; }
 
-// Returns whether the host CPU supports the CPU features needed for our
-// accelerated implementations. The CpuTypes enumerated above apart from
-// kUnknown support the required features. On unknown CPUs, we can use
-// this to see if it's safe to use hardware acceleration, though without any
-// tuning.
-bool SupportsArmCRC32PMULL();
-
-// Returns whether the host CPU supports ARM SHA3 instructions (e.g., EOR3).
-bool SupportsArmSHA3();
-
-// Returns whether the host CPU and OS support AVX2 instructions.
-bool SupportsAvx2();
-
-// Returns whether the host CPU supports BMI2 instructions.
-bool SupportsBmi2();
+// Returns how many hardware contexts per CPU exist.
+inline int NumContextsPerCPU() noexcept {
+  return GetCpuFeatures().num_contexts_per_cpu;
+}
 
 // Returns whether the host CPU supports simultaneous multithreading (SMT) and
 // if it is enabled.
-bool IsSMTEnabled();
+inline bool IsSMTEnabled() noexcept { return NumContextsPerCPU() > 1; }
 
-// Returns how many hardware contexts per CPU exist.
-int NumContextsPerCPU();
+// Returns whether the host CPU and OS support AVX2 instructions.
+inline bool SupportsAvx2() noexcept {
+#if defined(ABSL_INTERNAL_CPU_DETECT_X86)
+  return GetCpuFeatures().has_avx2;
+#else
+  return false;
+#endif
+}
+
+// Returns whether the host CPU supports BMI2 instructions.
+inline bool SupportsBmi2() noexcept {
+#if defined(ABSL_INTERNAL_CPU_DETECT_X86)
+  return GetCpuFeatures().has_bmi2;
+#else
+  return false;
+#endif
+}
+
+// Returns whether the host CPU supports 64-bit ARM CRC32 and PMULL
+// instructions.
+inline bool SupportsArmCRC32PMULL() noexcept {
+#if defined(ABSL_INTERNAL_CPU_DETECT_ARM) &&       \
+    (defined(__aarch64__) || defined(__arm64__) || \
+     (defined(_M_ARM64) && !defined(_M_ARM64EC)))
+  const CpuFeatures f = GetCpuFeatures();
+  return f.has_neon && f.has_crc32 && f.has_pmull;
+#else
+  return false;
+#endif
+}
+
+// Returns whether the host CPU supports 64-bit ARM SHA3 instructions (e.g.,
+// EOR3).
+inline bool SupportsArmSHA3() noexcept {
+#if defined(ABSL_INTERNAL_CPU_DETECT_ARM) &&       \
+    (defined(__aarch64__) || defined(__arm64__) || \
+     (defined(_M_ARM64) && !defined(_M_ARM64EC)))
+  return GetCpuFeatures().has_sha3;
+#else
+  return false;
+#endif
+}
+
+// Returns whether the host CPU supports the cryptographic extensions needed by
+// the hardware-accelerated Randen implementation.
+inline bool SupportsRandenHwAes() noexcept {
+#if defined(ABSL_INTERNAL_CPU_DETECT_X86)
+  return GetCpuFeatures().has_aes;
+#elif defined(ABSL_INTERNAL_CPU_DETECT_ARM)
+  const CpuFeatures f = GetCpuFeatures();
+  return f.has_neon && f.has_aes;
+#elif defined(ABSL_INTERNAL_CPU_DETECT_PPC)
+  return GetCpuFeatures().has_vcrypto;
+#else
+  return false;
+#endif
+}
 
 }  // namespace base_internal
 ABSL_NAMESPACE_END
diff --git a/absl/base/internal/cpu_detect_arm.cc b/absl/base/internal/cpu_detect_arm.cc
new file mode 100644
index 0000000..e038e36
--- /dev/null
+++ b/absl/base/internal/cpu_detect_arm.cc
@@ -0,0 +1,421 @@
+// Copyright 2026 The Abseil Authors
+//
+// 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
+//
+//     https://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.
+
+#include "absl/base/config.h"
+#include "absl/base/internal/cpu_detect.h"
+
+#if defined(ABSL_INTERNAL_CPU_DETECT_ARM)
+
+#include <cstdint>  // IWYU pragma: keep
+
+#if defined(__ANDROID__)
+// Bionic declares getauxval() starting at API level 18.
+#if defined(__ANDROID_API__) && __ANDROID_API__ >= 18
+#define ABSL_INTERNAL_CPU_DETECT_ARM_HAVE_GETAUXVAL 1
+#endif
+#elif defined(__linux__) && !defined(__UCLIBC__)
+#if defined(__GLIBC__)
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16)
+#define ABSL_INTERNAL_CPU_DETECT_ARM_HAVE_GETAUXVAL 1
+#endif
+#elif defined(__has_include)
+#if __has_include(<sys/auxv.h>)
+// Other Linux C libraries such as musl (which provides getauxval() since 1.1.0
+// and defines no macro to identify itself).
+#define ABSL_INTERNAL_CPU_DETECT_ARM_HAVE_GETAUXVAL 1
+#endif
+#endif
+#endif
+
+#if defined(ABSL_INTERNAL_CPU_DETECT_ARM_HAVE_GETAUXVAL)
+#include <sys/auxv.h>
+#elif defined(__linux__) || defined(__ANDROID__)
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <cerrno>
+#include <cstddef>
+#elif defined(__APPLE__)
+#ifdef __has_include
+#if __has_include(<arm/cpu_capabilities_public.h>)
+#include <arm/cpu_capabilities_public.h>
+#endif
+#endif
+#include <sys/sysctl.h>
+#include <sys/types.h>
+
+#include <cstddef>
+#include <optional>
+#elif defined(__Fuchsia__) && (defined(__aarch64__) || defined(__arm64__))
+#include <zircon/features.h>
+#include <zircon/syscalls.h>
+#include <zircon/types.h>
+#elif defined(_WIN32)
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include <windows.h>
+#ifndef PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
+#define PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE 30
+#endif
+#ifndef PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
+#define PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE 31
+#endif
+#ifndef PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE
+#define PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE 64
+#endif
+#endif
+
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+namespace base_internal {
+namespace {
+
+#if defined(__linux__) || defined(__ANDROID__)
+// Queries Linux/Android ELF auxiliary vector entries AT_HWCAP (16) and
+// AT_HWCAP2 (26), using in-memory getauxval() when available (glibc >= 2.16,
+// musl, Android API >= 18) and falling back to /proc/self/auxv on older NDK/
+// libc configurations (works in static binaries without dlopen/libdl).
+void QueryAuxv(unsigned long* hwcap,   // NOLINT(runtime/int)
+               unsigned long* hwcap2)  // NOLINT(runtime/int)
+    noexcept {
+  constexpr unsigned long kAtNull = 0;     // NOLINT(runtime/int)
+  constexpr unsigned long kAtHwcap = 16;   // NOLINT(runtime/int)
+  constexpr unsigned long kAtHwcap2 = 26;  // NOLINT(runtime/int)
+#if defined(ABSL_INTERNAL_CPU_DETECT_ARM_HAVE_GETAUXVAL)
+#ifdef AT_HWCAP
+  static_assert(AT_HWCAP == kAtHwcap, "AT_HWCAP value mismatch");
+#endif
+#ifdef AT_HWCAP2
+  static_assert(AT_HWCAP2 == kAtHwcap2, "AT_HWCAP2 value mismatch");
+#endif
+  (void)kAtNull;
+  *hwcap = getauxval(kAtHwcap);
+  *hwcap2 = getauxval(kAtHwcap2);
+#else
+  *hwcap = 0;
+  *hwcap2 = 0;
+#ifdef O_CLOEXEC
+  constexpr int kOpenFlags = O_RDONLY | O_CLOEXEC;
+#else
+  constexpr int kOpenFlags = O_RDONLY;
+#endif
+  int fd;
+  do {
+    fd = open("/proc/self/auxv", kOpenFlags);
+  } while (fd < 0 && errno == EINTR);
+  if (fd < 0) return;
+  struct AuxvEntry {
+    unsigned long tag;    // NOLINT(runtime/int)
+    unsigned long value;  // NOLINT(runtime/int)
+  };
+  AuxvEntry entries[32];
+  bool done = false;
+  while (!done) {
+    ssize_t n;
+    do {
+      n = read(fd, entries, sizeof(entries));
+    } while (n < 0 && errno == EINTR);
+    if (n < static_cast<ssize_t>(sizeof(AuxvEntry))) break;
+    const size_t count = static_cast<size_t>(n) / sizeof(AuxvEntry);
+    for (size_t i = 0; i < count; ++i) {
+      if (entries[i].tag == kAtNull) {
+        done = true;
+        break;
+      }
+      if (entries[i].tag == kAtHwcap) *hwcap = entries[i].value;
+      if (entries[i].tag == kAtHwcap2) *hwcap2 = entries[i].value;
+    }
+  }
+  close(fd);
+#endif
+}
+
+#if (defined(__aarch64__) || defined(__arm64__)) && \
+    (defined(__GNUC__) || defined(__clang__))
+// MIDR_EL1 is trapped at EL0 and emulated by Linux when AT_HWCAP advertises
+// HWCAP_CPUID (1 << 11). Note: on heterogeneous (big.LITTLE) SoCs, MIDR_EL1
+// reflects the core executing the calling thread; all enumerated CpuType
+// entries below are homogeneous datacenter processors.
+CpuType DetectArm64CpuType(
+    unsigned long hwcap) noexcept {                 // NOLINT(runtime/int)
+  constexpr unsigned long kHwcapCpuid = 1UL << 11;  // NOLINT(runtime/int)
+  if ((hwcap & kHwcapCpuid) == 0) return CpuType::kUnknown;
+  uint64_t midr = 0;
+  __asm__("mrs %0, MIDR_EL1" : "=r"(midr));
+  const uint32_t implementer = static_cast<uint32_t>((midr >> 24) & 0xffU);
+  const uint32_t part_number = static_cast<uint32_t>((midr >> 4) & 0xfffU);
+  switch (implementer) {
+    case 0x41:  // ARM
+      switch (part_number) {
+        case 0xd0c:
+          return CpuType::kArmNeoverseN1;
+        case 0xd40:
+          return CpuType::kArmNeoverseV1;
+        case 0xd49:
+          return CpuType::kArmNeoverseN2;
+        case 0xd4f: {
+          uint64_t isar0 = 0;
+          __asm__("mrs %0, ID_AA64ISAR0_EL1" : "=r"(isar0));
+          // NVIDIA Grace uses Neoverse V2 cores configured without FEAT_RNG
+          // (ID_AA64ISAR0_EL1.RNDR == 0 in bits [63:60]).
+          return ((isar0 >> 60) & 0xfU) == 0 ? CpuType::kNvidiaGrace
+                                             : CpuType::kArmNeoverseV2;
+        }
+        case 0xd84:
+          return CpuType::kArmNeoverseV3;
+        case 0xd8e:
+          return CpuType::kArmNeoverseN3;
+        case 0xd94:
+          return CpuType::kArmNeoverseN4;
+        default:
+          return CpuType::kUnknown;
+      }
+    case 0x4e:  // NVIDIA
+      return part_number == 0x010 ? CpuType::kNvidiaVera : CpuType::kUnknown;
+    case 0xc0:  // Ampere
+      return part_number == 0xac3 ? CpuType::kAmpereSiryn : CpuType::kUnknown;
+    default:
+      return CpuType::kUnknown;
+  }
+}
+#endif
+#endif  // defined(__linux__) || defined(__ANDROID__)
+
+#if defined(__APPLE__)
+std::optional<int> ReadSysctlInt(const char* name) noexcept {
+  int value = 0;
+  size_t size = sizeof(value);
+  if (sysctlbyname(name, &value, &size, nullptr, 0) != 0 ||
+      size != sizeof(value)) {
+    return std::nullopt;
+  }
+  return value;
+}
+
+#if (defined(__aarch64__) || defined(__arm64__)) && defined(CAP_BIT_AdvSIMD)
+bool HasCapBit(const uint8_t* caps, size_t caps_size, size_t bit) noexcept {
+  const size_t byte_index = bit / 8;
+  return byte_index < caps_size &&
+         (caps[byte_index] & static_cast<uint8_t>(1U << (bit % 8))) != 0;
+}
+
+// XNU's hw.optional.arm.caps is a multi-byte bitvector (CAP_BIT_NB > 64 bits,
+// so reading into uint64_t fails with ENOMEM). Read into a byte buffer to
+// query all capabilities in one sysctlbyname call on macOS 13+ / iOS 16+.
+bool PopulateFromAppleArmCaps(CpuFeatures* f) noexcept {
+  uint8_t caps[128] = {};
+  size_t caps_size = sizeof(caps);
+  if (sysctlbyname("hw.optional.arm.caps", caps, &caps_size, nullptr, 0) != 0 ||
+      static_cast<size_t>(CAP_BIT_AdvSIMD) / 8 >= caps_size) {
+    return false;
+  }
+#ifdef CAP_BIT_CRC32
+  if (HasCapBit(caps, caps_size, CAP_BIT_CRC32)) f->has_crc32 = true;
+#endif
+  if (HasCapBit(caps, caps_size, CAP_BIT_AdvSIMD)) {
+    f->has_neon = true;
+#ifdef CAP_BIT_FEAT_AES
+    if (HasCapBit(caps, caps_size, CAP_BIT_FEAT_AES)) f->has_aes = true;
+#endif
+#ifdef CAP_BIT_FEAT_PMULL
+    if (HasCapBit(caps, caps_size, CAP_BIT_FEAT_PMULL)) f->has_pmull = true;
+#endif
+#ifdef CAP_BIT_FEAT_SHA3
+    if (HasCapBit(caps, caps_size, CAP_BIT_FEAT_SHA3)) f->has_sha3 = true;
+#endif
+  }
+  return true;
+}
+#endif
+#endif  // defined(__APPLE__)
+
+CpuFeatures DetectCpuFeatures() noexcept {
+  CpuFeatures f;
+#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
+#if defined(__ARM_NEON) || defined(_M_ARM64)
+  f.has_neon = true;
+#endif
+#if defined(__ARM_FEATURE_CRC32)
+  f.has_crc32 = true;
+#endif
+#if defined(__ARM_FEATURE_AES) || defined(__ARM_FEATURE_CRYPTO)
+  f.has_aes = f.has_neon;
+#endif
+#if defined(__ARM_FEATURE_CRYPTO)
+  f.has_pmull = f.has_neon;
+#endif
+#if defined(__ARM_FEATURE_SHA3)
+  f.has_sha3 = f.has_neon;
+#endif
+#if defined(__ARM_FEATURE_SVE2)
+  f.has_sve2 = f.has_neon;
+#endif
+#if defined(__linux__) || defined(__ANDROID__)
+  // Linux/Android AArch64 uapi/asm/hwcap.h: AT_HWCAP (ASIMD = 1<<1,
+  // AES = 1<<3, PMULL = 1<<4, CRC32 = 1<<7, SHA3 = 1<<17),
+  // AT_HWCAP2 (SVE2 = 1<<1).
+  constexpr unsigned long kHwcapAsimd = 1UL << 1;  // NOLINT(runtime/int)
+  constexpr unsigned long kHwcapAes = 1UL << 3;    // NOLINT(runtime/int)
+  constexpr unsigned long kHwcapPmull = 1UL << 4;  // NOLINT(runtime/int)
+  constexpr unsigned long kHwcapCrc32 = 1UL << 7;  // NOLINT(runtime/int)
+  constexpr unsigned long kHwcapSha3 = 1UL << 17;  // NOLINT(runtime/int)
+  constexpr unsigned long kHwcap2Sve2 = 1UL << 1;  // NOLINT(runtime/int)
+  unsigned long hwcap = 0;                         // NOLINT(runtime/int)
+  unsigned long hwcap2 = 0;                        // NOLINT(runtime/int)
+  QueryAuxv(&hwcap, &hwcap2);
+#if defined(__GNUC__) || defined(__clang__)
+  f.type = DetectArm64CpuType(hwcap);
+#endif
+  if ((hwcap & kHwcapCrc32) != 0) f.has_crc32 = true;
+  if ((hwcap & kHwcapAsimd) != 0) f.has_neon = true;
+  if (f.has_neon) {
+    if ((hwcap & kHwcapAes) != 0) f.has_aes = true;
+    if ((hwcap & kHwcapPmull) != 0) f.has_pmull = true;
+    if ((hwcap & kHwcapSha3) != 0) f.has_sha3 = true;
+    if ((hwcap2 & kHwcap2Sve2) != 0) f.has_sve2 = true;
+  }
+#elif defined(__APPLE__)
+  bool caps_ok = false;
+#if defined(CAP_BIT_AdvSIMD)
+  caps_ok = PopulateFromAppleArmCaps(&f);
+#endif
+  if (!caps_ok) {
+    if (ReadSysctlInt("hw.optional.armv8_crc32").value_or(0) != 0 ||
+        ReadSysctlInt("hw.optional.arm.FEAT_CRC32").value_or(0) != 0) {
+      f.has_crc32 = true;
+    }
+    // Older XNU kernels (such as macOS 11 on Apple M1) predate
+    // hw.optional.arm.caps, hw.optional.arm.FEAT_AES, and
+    // hw.optional.arm.FEAT_PMULL even though all Darwin arm64 hardware mandates
+    // FEAT_AES and FEAT_PMULL; treat missing keys as supported once AdvSIMD is
+    // present.
+    if (ReadSysctlInt("hw.optional.AdvSIMD").value_or(0) != 0) {
+      f.has_neon = true;
+      if (ReadSysctlInt("hw.optional.arm.FEAT_AES").value_or(1) != 0) {
+        f.has_aes = true;
+      }
+      if (ReadSysctlInt("hw.optional.arm.FEAT_PMULL").value_or(1) != 0) {
+        f.has_pmull = true;
+      }
+      if (ReadSysctlInt("hw.optional.armv8_2_sha3").value_or(0) != 0 ||
+          ReadSysctlInt("hw.optional.arm.FEAT_SHA3").value_or(0) != 0) {
+        f.has_sha3 = true;
+      }
+    }
+  }
+  // M1-M3 lack SVE/SVE2, and M4 implements SME2 (streaming mode only, not
+  // non-streaming FEAT_SVE2); query FEAT_SVE2 for future Apple chips.
+  if (f.has_neon &&
+      ReadSysctlInt("hw.optional.arm.FEAT_SVE2").value_or(0) != 0) {
+    f.has_sve2 = true;
+  }
+#elif defined(__Fuchsia__)
+  uint32_t hwcap = 0;
+  if (zx_system_get_features(ZX_FEATURE_KIND_CPU, &hwcap) == ZX_OK) {
+    if ((hwcap & ZX_ARM64_FEATURE_ISA_CRC32) != 0) f.has_crc32 = true;
+    if ((hwcap & ZX_ARM64_FEATURE_ISA_ASIMD) != 0) {
+      f.has_neon = true;
+      if ((hwcap & ZX_ARM64_FEATURE_ISA_AES) != 0) f.has_aes = true;
+      if ((hwcap & ZX_ARM64_FEATURE_ISA_PMULL) != 0) f.has_pmull = true;
+#ifdef ZX_ARM64_FEATURE_ISA_SHA3
+      if ((hwcap & ZX_ARM64_FEATURE_ISA_SHA3) != 0) f.has_sha3 = true;
+#endif
+#if defined(ZX_FEATURE_KIND_CPU_SVE) && defined(ZX_ARM64_FEATURE_ISA_SVE) && \
+    defined(ZX_ARM64_FEATURE_ISA_SVE2)
+      uint32_t sve_hwcap = 0;
+      if ((hwcap & ZX_ARM64_FEATURE_ISA_SVE) != 0 &&
+          zx_system_get_features(ZX_FEATURE_KIND_CPU_SVE, &sve_hwcap) ==
+              ZX_OK &&
+          (sve_hwcap & ZX_ARM64_FEATURE_ISA_SVE2) != 0) {
+        f.has_sve2 = true;
+      }
+#endif
+    }
+  }
+#elif defined(_WIN32)
+  if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE) != 0) {
+    f.has_crc32 = true;
+  }
+  if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0) {
+    f.has_aes = true;
+    f.has_pmull = true;
+  }
+  if (IsProcessorFeaturePresent(PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE) != 0) {
+    f.has_sha3 = true;
+  }
+#endif
+#else  // 32-bit ARM
+#if defined(__ARM_NEON)
+  f.has_neon = true;
+#endif
+#if defined(__ARM_FEATURE_CRC32)
+  f.has_crc32 = true;
+#endif
+#if defined(__ARM_NEON) && \
+    (defined(__ARM_FEATURE_AES) || defined(__ARM_FEATURE_CRYPTO))
+  f.has_aes = true;
+#endif
+#if defined(__ARM_NEON) && defined(__ARM_FEATURE_CRYPTO)
+  f.has_pmull = true;
+#endif
+#if defined(__linux__) || defined(__ANDROID__)
+  // Linux/Android AArch32 uapi/asm/hwcap.h: AT_HWCAP (NEON = 1<<12),
+  // AT_HWCAP2 (AES = 1<<0, PMULL = 1<<1, CRC32 = 1<<4).
+  constexpr unsigned long kHwcapNeon = 1UL << 12;   // NOLINT(runtime/int)
+  constexpr unsigned long kHwcap2Aes = 1UL << 0;    // NOLINT(runtime/int)
+  constexpr unsigned long kHwcap2Pmull = 1UL << 1;  // NOLINT(runtime/int)
+  constexpr unsigned long kHwcap2Crc32 = 1UL << 4;  // NOLINT(runtime/int)
+  unsigned long hwcap = 0;                          // NOLINT(runtime/int)
+  unsigned long hwcap2 = 0;                         // NOLINT(runtime/int)
+  QueryAuxv(&hwcap, &hwcap2);
+  if ((hwcap2 & kHwcap2Crc32) != 0) f.has_crc32 = true;
+  if ((hwcap & kHwcapNeon) != 0) f.has_neon = true;
+  if (f.has_neon) {
+    if ((hwcap2 & kHwcap2Aes) != 0) f.has_aes = true;
+    if ((hwcap2 & kHwcap2Pmull) != 0) f.has_pmull = true;
+  }
+#elif defined(__APPLE__)
+  if (ReadSysctlInt("hw.optional.armv8_crc32").value_or(0) != 0) {
+    f.has_crc32 = true;
+  }
+  if (ReadSysctlInt("hw.optional.neon").value_or(0) != 0) f.has_neon = true;
+  if (f.has_neon) {
+    if (ReadSysctlInt("hw.optional.arm.FEAT_AES").value_or(0) != 0) {
+      f.has_aes = true;
+    }
+    if (ReadSysctlInt("hw.optional.arm.FEAT_PMULL").value_or(0) != 0) {
+      f.has_pmull = true;
+    }
+  }
+#endif
+#endif
+  return f;
+}
+
+}  // namespace
+
+CpuFeatures GetCpuFeatures() noexcept {
+  static const CpuFeatures kFeatures = DetectCpuFeatures();
+  return kFeatures;
+}
+
+}  // namespace base_internal
+ABSL_NAMESPACE_END
+}  // namespace absl
+
+#endif  // defined(ABSL_INTERNAL_CPU_DETECT_ARM)
diff --git a/absl/base/internal/cpu_detect_other.cc b/absl/base/internal/cpu_detect_other.cc
new file mode 100644
index 0000000..0323153
--- /dev/null
+++ b/absl/base/internal/cpu_detect_other.cc
@@ -0,0 +1,34 @@
+// Copyright 2026 The Abseil Authors
+//
+// 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
+//
+//     https://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.
+
+#include "absl/base/config.h"
+#include "absl/base/internal/cpu_detect.h"
+
+// Fallback for architectures without dedicated SIMD backends (e.g., RISC-V,
+// s390x, LoongArch, MIPS, WebAssembly, or CUDA device compilation).
+#if !defined(ABSL_INTERNAL_CPU_DETECT_X86) && \
+    !defined(ABSL_INTERNAL_CPU_DETECT_ARM) && \
+    !defined(ABSL_INTERNAL_CPU_DETECT_PPC)
+
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+namespace base_internal {
+
+CpuFeatures GetCpuFeatures() noexcept { return {}; }
+
+}  // namespace base_internal
+ABSL_NAMESPACE_END
+}  // namespace absl
+
+#endif
diff --git a/absl/base/internal/cpu_detect_ppc.cc b/absl/base/internal/cpu_detect_ppc.cc
new file mode 100644
index 0000000..f02fc42
--- /dev/null
+++ b/absl/base/internal/cpu_detect_ppc.cc
@@ -0,0 +1,143 @@
+// Copyright 2026 The Abseil Authors
+//
+// 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
+//
+//     https://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.
+
+#include "absl/base/config.h"
+#include "absl/base/internal/cpu_detect.h"
+
+#if defined(ABSL_INTERNAL_CPU_DETECT_PPC)
+
+#if defined(__linux__) && !defined(__ANDROID__) && !defined(__UCLIBC__)
+#if defined(__GLIBC__)
+#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16)
+#define ABSL_INTERNAL_CPU_DETECT_PPC_HAVE_GETAUXVAL 1
+#endif
+#elif defined(__has_include)
+#if __has_include(<sys/auxv.h>)
+// Other Linux C libraries such as musl (which provides getauxval() since 1.1.0
+// and defines no macro to identify itself).
+#define ABSL_INTERNAL_CPU_DETECT_PPC_HAVE_GETAUXVAL 1
+#endif
+#endif
+#endif
+
+#if defined(ABSL_INTERNAL_CPU_DETECT_PPC_HAVE_GETAUXVAL)
+#include <sys/auxv.h>
+#elif defined(__linux__)
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <cerrno>
+#include <cstddef>
+#endif
+
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+namespace base_internal {
+namespace {
+
+#if defined(__linux__)
+void QueryAuxv(unsigned long* hwcap,   // NOLINT(runtime/int)
+               unsigned long* hwcap2)  // NOLINT(runtime/int)
+    noexcept {
+  constexpr unsigned long kAtNull = 0;     // NOLINT(runtime/int)
+  constexpr unsigned long kAtHwcap = 16;   // NOLINT(runtime/int)
+  constexpr unsigned long kAtHwcap2 = 26;  // NOLINT(runtime/int)
+#if defined(ABSL_INTERNAL_CPU_DETECT_PPC_HAVE_GETAUXVAL)
+#ifdef AT_HWCAP
+  static_assert(AT_HWCAP == kAtHwcap, "AT_HWCAP value mismatch");
+#endif
+#ifdef AT_HWCAP2
+  static_assert(AT_HWCAP2 == kAtHwcap2, "AT_HWCAP2 value mismatch");
+#endif
+  (void)kAtNull;
+  *hwcap = getauxval(kAtHwcap);
+  *hwcap2 = getauxval(kAtHwcap2);
+#else
+  *hwcap = 0;
+  *hwcap2 = 0;
+#ifdef O_CLOEXEC
+  constexpr int kOpenFlags = O_RDONLY | O_CLOEXEC;
+#else
+  constexpr int kOpenFlags = O_RDONLY;
+#endif
+  int fd;
+  do {
+    fd = open("/proc/self/auxv", kOpenFlags);
+  } while (fd < 0 && errno == EINTR);
+  if (fd < 0) return;
+  struct AuxvEntry {
+    unsigned long tag;    // NOLINT(runtime/int)
+    unsigned long value;  // NOLINT(runtime/int)
+  };
+  AuxvEntry entries[32];
+  bool done = false;
+  while (!done) {
+    ssize_t n;
+    do {
+      n = read(fd, entries, sizeof(entries));
+    } while (n < 0 && errno == EINTR);
+    if (n < static_cast<ssize_t>(sizeof(AuxvEntry))) break;
+    const size_t count = static_cast<size_t>(n) / sizeof(AuxvEntry);
+    for (size_t i = 0; i < count; ++i) {
+      if (entries[i].tag == kAtNull) {
+        done = true;
+        break;
+      }
+      if (entries[i].tag == kAtHwcap) *hwcap = entries[i].value;
+      if (entries[i].tag == kAtHwcap2) *hwcap2 = entries[i].value;
+    }
+  }
+  close(fd);
+#endif
+}
+#endif
+
+CpuFeatures DetectCpuFeatures() noexcept {
+  CpuFeatures f;
+#if defined(__VSX__)
+  f.has_vsx = true;
+#endif
+#if defined(__CRYPTO__) && defined(__VSX__) && defined(__POWER8_VECTOR__)
+  f.has_vcrypto = true;
+#endif
+#if defined(__linux__)
+  // Linux uapi/asm/cputable.h: AT_HWCAP = 16 (HAS_VSX = 0x80), AT_HWCAP2 = 26
+  // (ARCH_2_07 = 0x80000000, VEC_CRYPTO = 0x02000000).
+  constexpr unsigned long kPpcHasVsx = 0x00000080UL;     // NOLINT(runtime/int)
+  constexpr unsigned long kPpcArch207 = 0x80000000UL;    // NOLINT(runtime/int)
+  constexpr unsigned long kPpcVecCrypto = 0x02000000UL;  // NOLINT(runtime/int)
+  unsigned long hwcap = 0;                               // NOLINT(runtime/int)
+  unsigned long hwcap2 = 0;                              // NOLINT(runtime/int)
+  QueryAuxv(&hwcap, &hwcap2);
+  if ((hwcap & kPpcHasVsx) != 0) f.has_vsx = true;
+  if (f.has_vsx && (hwcap2 & kPpcArch207) != 0 &&
+      (hwcap2 & kPpcVecCrypto) != 0) {
+    f.has_vcrypto = true;
+  }
+#endif
+  return f;
+}
+
+}  // namespace
+
+CpuFeatures GetCpuFeatures() noexcept {
+  static const CpuFeatures kFeatures = DetectCpuFeatures();
+  return kFeatures;
+}
+
+}  // namespace base_internal
+ABSL_NAMESPACE_END
+}  // namespace absl
+
+#endif  // defined(ABSL_INTERNAL_CPU_DETECT_PPC)
diff --git a/absl/base/internal/cpu_detect_test.cc b/absl/base/internal/cpu_detect_test.cc
index 1bfc831..c691172 100644
--- a/absl/base/internal/cpu_detect_test.cc
+++ b/absl/base/internal/cpu_detect_test.cc
@@ -14,6 +14,9 @@
 
 #include "absl/base/internal/cpu_detect.h"
 
+#include <type_traits>
+
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include "absl/base/config.h"
 
@@ -22,38 +25,126 @@
 namespace base_internal {
 namespace {
 
-TEST(CpuDetectTest, SupportsArmSHA3) {
-#if defined(__aarch64__) || defined(_M_ARM64)
-  (void)SupportsArmSHA3();
+using ::testing::Eq;
+using ::testing::Ge;
+
+static_assert(std::is_trivially_copyable_v<CpuFeatures>);
+static_assert(std::is_trivially_destructible_v<CpuFeatures>);
+static_assert(noexcept(GetCpuFeatures()));
+static_assert(noexcept(GetCpuType()));
+static_assert(noexcept(NumContextsPerCPU()));
+static_assert(noexcept(IsSMTEnabled()));
+static_assert(noexcept(SupportsAvx2()));
+static_assert(noexcept(SupportsBmi2()));
+static_assert(noexcept(SupportsArmCRC32PMULL()));
+static_assert(noexcept(SupportsArmSHA3()));
+static_assert(noexcept(SupportsRandenHwAes()));
+
+TEST(CpuDetectTest, IsDeterministicAndImplicationConsistent) {
+  const CpuFeatures a = GetCpuFeatures();
+  const CpuFeatures b = GetCpuFeatures();
+
+  EXPECT_THAT(a.type, Eq(b.type));
+  EXPECT_THAT(a.type, Eq(GetCpuType()));
+  EXPECT_THAT(a.num_contexts_per_cpu, Eq(b.num_contexts_per_cpu));
+  EXPECT_THAT(a.num_contexts_per_cpu, Eq(NumContextsPerCPU()));
+  EXPECT_THAT(a.num_contexts_per_cpu, Ge(1));
+  EXPECT_THAT(IsSMTEnabled(), Eq(a.num_contexts_per_cpu > 1));
+
+#if defined(ABSL_INTERNAL_CPU_DETECT_X86)
+  EXPECT_THAT(a.has_ssse3, Eq(b.has_ssse3));
+  EXPECT_THAT(a.has_sse4_1, Eq(b.has_sse4_1));
+  EXPECT_THAT(a.has_aes, Eq(b.has_aes));
+  EXPECT_THAT(a.has_avx2, Eq(b.has_avx2));
+  EXPECT_THAT(a.has_bmi2, Eq(b.has_bmi2));
+  EXPECT_THAT(a.has_vaes, Eq(b.has_vaes));
+  EXPECT_THAT(a.has_avx512f, Eq(b.has_avx512f));
+  EXPECT_THAT(a.has_avx512bw, Eq(b.has_avx512bw));
+  EXPECT_THAT(a.has_avx512vl, Eq(b.has_avx512vl));
+
+  EXPECT_THAT(SupportsAvx2(), Eq(a.has_avx2));
+  EXPECT_THAT(SupportsBmi2(), Eq(a.has_bmi2));
+  EXPECT_FALSE(SupportsArmCRC32PMULL());
+  EXPECT_FALSE(SupportsArmSHA3());
+  EXPECT_THAT(SupportsRandenHwAes(), Eq(a.has_aes && a.has_sse4_1));
+
+  if (a.has_sse4_1) EXPECT_TRUE(a.has_ssse3);
+  if (a.has_avx512bw || a.has_avx512vl) EXPECT_TRUE(a.has_avx512f);
+#elif defined(ABSL_INTERNAL_CPU_DETECT_ARM)
+  EXPECT_THAT(a.has_neon, Eq(b.has_neon));
+  EXPECT_THAT(a.has_crc32, Eq(b.has_crc32));
+  EXPECT_THAT(a.has_aes, Eq(b.has_aes));
+  EXPECT_THAT(a.has_pmull, Eq(b.has_pmull));
+  EXPECT_THAT(a.has_sha3, Eq(b.has_sha3));
+  EXPECT_THAT(a.has_sve2, Eq(b.has_sve2));
+
+  EXPECT_FALSE(SupportsAvx2());
+  EXPECT_FALSE(SupportsBmi2());
+  EXPECT_THAT(SupportsRandenHwAes(), Eq(a.has_neon && a.has_aes));
+#if defined(__aarch64__) || defined(__arm64__) || \
+    (defined(_M_ARM64) && !defined(_M_ARM64EC))
+  EXPECT_TRUE(a.has_neon);
+  EXPECT_THAT(SupportsArmCRC32PMULL(), Eq(a.has_crc32 && a.has_pmull));
+  EXPECT_THAT(SupportsArmSHA3(), Eq(a.has_sha3));
+#if defined(__APPLE__)
+  EXPECT_TRUE(a.has_aes);
+  EXPECT_TRUE(a.has_pmull);
+  EXPECT_TRUE(a.has_crc32);
+#endif
 #else
+  EXPECT_FALSE(SupportsArmCRC32PMULL());
   EXPECT_FALSE(SupportsArmSHA3());
 #endif
-}
-
-TEST(CpuDetectTest, SupportsAvx2) {
-#if defined(__x86_64__) || defined(_M_X64)
-#if ABSL_HAVE_BUILTIN(__builtin_cpu_supports) && defined(__linux__)
-  EXPECT_EQ(SupportsAvx2(), __builtin_cpu_supports("avx2") != 0);
-#else
-  (void)SupportsAvx2();
-#endif
+  if (a.has_aes || a.has_pmull || a.has_sha3 || a.has_sve2) {
+    EXPECT_TRUE(a.has_neon);
+  }
+#elif defined(ABSL_INTERNAL_CPU_DETECT_PPC)
+  EXPECT_THAT(a.has_vsx, Eq(b.has_vsx));
+  EXPECT_THAT(a.has_vcrypto, Eq(b.has_vcrypto));
+  EXPECT_FALSE(SupportsAvx2());
+  EXPECT_FALSE(SupportsBmi2());
+  EXPECT_FALSE(SupportsArmCRC32PMULL());
+  EXPECT_FALSE(SupportsArmSHA3());
+  EXPECT_THAT(SupportsRandenHwAes(), Eq(a.has_vcrypto));
+  if (a.has_vcrypto) EXPECT_TRUE(a.has_vsx);
 #else
   EXPECT_FALSE(SupportsAvx2());
+  EXPECT_FALSE(SupportsBmi2());
+  EXPECT_FALSE(SupportsArmCRC32PMULL());
+  EXPECT_FALSE(SupportsArmSHA3());
+  EXPECT_FALSE(SupportsRandenHwAes());
 #endif
 }
 
-TEST(CpuDetectTest, SupportsBmi2) {
-#if defined(__x86_64__) || defined(_M_X64)
-#if ABSL_HAVE_BUILTIN(__builtin_cpu_supports) && defined(__linux__)
-  EXPECT_EQ(SupportsBmi2(), __builtin_cpu_supports("bmi2") != 0);
-#else
-  // If __builtin_cpu_supports is not available, we just verify it doesn't
-  // crash.
-  (void)SupportsBmi2();
+TEST(CpuDetectTest, MatchesCompilerBuiltinCpuSupportsOnLinuxX86) {
+#if defined(ABSL_INTERNAL_CPU_DETECT_X86) && defined(__linux__) && \
+    (defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_cpu_supports))
+  const CpuFeatures f = GetCpuFeatures();
+  EXPECT_THAT(f.has_ssse3, Eq(__builtin_cpu_supports("ssse3") != 0));
+  EXPECT_THAT(f.has_sse4_1, Eq(__builtin_cpu_supports("sse4.1") != 0));
+  EXPECT_THAT(f.has_aes, Eq(__builtin_cpu_supports("aes") != 0));
+  EXPECT_THAT(SupportsAvx2(), Eq(__builtin_cpu_supports("avx2") != 0));
+  EXPECT_THAT(SupportsBmi2(), Eq(__builtin_cpu_supports("bmi2") != 0));
+  EXPECT_THAT(f.has_avx512f, Eq(__builtin_cpu_supports("avx512f") != 0));
+  EXPECT_THAT(f.has_avx512bw, Eq(__builtin_cpu_supports("avx512bw") != 0));
+  EXPECT_THAT(f.has_avx512vl, Eq(__builtin_cpu_supports("avx512vl") != 0));
 #endif
-#else
-  // On non-x86, SupportsBmi2() must return false.
-  EXPECT_FALSE(SupportsBmi2());
+}
+
+TEST(CpuDetectTest, MatchesCompilerBuiltinCpuSupportsOnLinuxPpc) {
+#if defined(ABSL_INTERNAL_CPU_DETECT_PPC) && defined(__linux__) &&        \
+    defined(__GLIBC__) &&                                                 \
+    (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 23)) &&       \
+    ((defined(__clang__) && ABSL_HAVE_BUILTIN(__builtin_cpu_supports)) || \
+     defined(__PPC_CPU_SUPPORTS__))
+  const CpuFeatures f = GetCpuFeatures();
+  const bool builtin_vsx = __builtin_cpu_supports("vsx") != 0;
+  const bool builtin_vcrypto = builtin_vsx &&
+                               __builtin_cpu_supports("arch_2_07") != 0 &&
+                               __builtin_cpu_supports("vcrypto") != 0;
+  EXPECT_THAT(f.has_vsx, Eq(builtin_vsx));
+  EXPECT_THAT(f.has_vcrypto, Eq(builtin_vcrypto));
+  EXPECT_THAT(SupportsRandenHwAes(), Eq(builtin_vcrypto));
 #endif
 }
 
diff --git a/absl/base/internal/cpu_detect_x86.cc b/absl/base/internal/cpu_detect_x86.cc
new file mode 100644
index 0000000..f5d24f0
--- /dev/null
+++ b/absl/base/internal/cpu_detect_x86.cc
@@ -0,0 +1,265 @@
+// Copyright 2026 The Abseil Authors
+//
+// 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
+//
+//     https://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.
+
+#include "absl/base/config.h"
+#include "absl/base/internal/cpu_detect.h"
+
+#if defined(ABSL_INTERNAL_CPU_DETECT_X86)
+
+#include <cstdint>
+#include <cstring>
+
+#if defined(_MSC_VER) && !defined(__clang__)
+#include <intrin.h>
+#else
+#include <cpuid.h>
+#endif
+#if defined(__APPLE__)
+#include <sys/sysctl.h>
+
+#include <cstddef>
+#endif
+
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+namespace base_internal {
+namespace {
+
+void Cpuid(uint32_t leaf, uint32_t subleaf, uint32_t* eax, uint32_t* ebx,
+           uint32_t* ecx, uint32_t* edx) noexcept {
+#if defined(_MSC_VER) && !defined(__clang__)
+  int info[4];
+  __cpuidex(info, static_cast<int>(leaf), static_cast<int>(subleaf));
+  *eax = static_cast<uint32_t>(info[0]);
+  *ebx = static_cast<uint32_t>(info[1]);
+  *ecx = static_cast<uint32_t>(info[2]);
+  *edx = static_cast<uint32_t>(info[3]);
+#else
+  __cpuid_count(leaf, subleaf, *eax, *ebx, *ecx, *edx);
+#endif
+}
+
+#if defined(__APPLE__)
+bool SysctlBool(const char* name) noexcept {
+  int value = 0;
+  size_t size = sizeof(value);
+  return sysctlbyname(name, &value, &size, nullptr, 0) == 0 &&
+         size == sizeof(value) && value != 0;
+}
+#endif
+
+uint64_t ReadXcr0() noexcept {
+#if defined(_MSC_VER) && !defined(__clang__)
+  return _xgetbv(0);
+#else
+  uint32_t eax = 0;
+  uint32_t edx = 0;
+  // Raw encoding of `xgetbv` with ECX = 0; avoids requiring `-mxsave`.
+  __asm__ volatile(".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c"(0));
+  return (static_cast<uint64_t>(edx) << 32) | eax;
+#endif
+}
+
+CpuType DetectIntelCpuType(uint32_t eax, uint32_t ebx) noexcept {
+  if ((ebx & 0xffU) != 0) return CpuType::kUnknown;  // Non-zero brand ID.
+  const uint32_t stepping = eax & 0x0fU;
+  uint32_t model = (eax >> 4) & 0x0fU;
+  uint32_t family = (eax >> 8) & 0x0fU;
+  const uint32_t ext_model = (eax >> 16) & 0x0fU;
+  const uint32_t ext_family = (eax >> 20) & 0xffU;
+  if (family == 0x0fU) family += ext_family;
+  if (family == 0x0fU || family == 0x06U) model += (ext_model << 4);
+  if (family != 0x06U) return CpuType::kUnknown;
+
+  switch (model) {
+    case 0x2c:
+      return CpuType::kIntelWestmere;
+    case 0x2d:
+      return CpuType::kIntelSandybridge;
+    case 0x3e:
+      return CpuType::kIntelIvybridge;
+    case 0x3c:
+    case 0x3f:
+      return CpuType::kIntelHaswell;
+    case 0x4f:
+    case 0x56:
+      return CpuType::kIntelBroadwell;
+    case 0x55:
+      return stepping < 5 ? CpuType::kIntelSkylakeXeon
+                          : CpuType::kIntelCascadelakeXeon;
+    case 0x5e:
+      return CpuType::kIntelSkylake;
+    case 0x6a:
+      return CpuType::kIntelIcelake;
+    case 0x8f:
+      return CpuType::kIntelSapphirerapids;
+    case 0xad:
+      return CpuType::kIntelGraniterapids;
+    case 0xcf:
+      return CpuType::kIntelEmeraldrapids;
+    default:
+      return CpuType::kUnknown;
+  }
+}
+
+CpuType DetectAmdCpuType(uint32_t eax) noexcept {
+  uint32_t model = (eax >> 4) & 0x0fU;
+  uint32_t family = (eax >> 8) & 0x0fU;
+  const uint32_t ext_model = (eax >> 16) & 0x0fU;
+  const uint32_t ext_family = (eax >> 20) & 0xffU;
+  if (family == 0x0fU) {
+    family += ext_family;
+    model += (ext_model << 4);
+  }
+  switch (family) {
+    case 0x17:
+      switch (model) {
+        case 0x00:
+        case 0x01:
+          return CpuType::kAmdNaples;
+        case 0x30:
+        case 0x31:
+          return CpuType::kAmdRome;
+        default:
+          return CpuType::kUnknown;
+      }
+    case 0x19:
+      switch (model) {
+        case 0x00:
+        case 0x01:
+          return CpuType::kAmdMilan;
+        case 0x10:
+        case 0x11:
+          return CpuType::kAmdGenoa;
+        case 0x44:
+          return CpuType::kAmdRyzenV3000;
+        case 0xa0:
+          return CpuType::kAmdSiena;
+        default:
+          return CpuType::kUnknown;
+      }
+    case 0x1a:
+      if (model >= 0x50 && model <= 0x5f) return CpuType::kAmdVenice;
+      return model == 0x02 ? CpuType::kAmdTurin : CpuType::kUnknown;
+    default:
+      return CpuType::kUnknown;
+  }
+}
+
+// Queries hardware threads per core via CPUID leaf 0xb. AMD CPUs prior to Zen 2
+// (Rome) lack leaf 0xb and intentionally fall back to 1 rather than leaf 1
+// EBX[23:16] (which reports total logical processors per package).
+int DetectNumContextsPerCpu(uint32_t max_leaf, uint32_t leaf1_edx) noexcept {
+  if (max_leaf < 0xbU || (leaf1_edx & (1U << 28)) == 0) return 1;
+  for (uint32_t subleaf = 0; subleaf < 4; ++subleaf) {
+    uint32_t eax = 0;
+    uint32_t ebx = 0;
+    uint32_t ecx = 0;
+    uint32_t edx = 0;
+    Cpuid(0xbU, subleaf, &eax, &ebx, &ecx, &edx);
+    const uint32_t level_type = (ecx >> 8) & 0xffU;
+    if (level_type == 0) break;
+    if (level_type == 1) {
+      const int num_threads = static_cast<int>(ebx & 0xffffU);
+      if (num_threads >= 1) return num_threads;
+    }
+  }
+  return 1;
+}
+
+CpuFeatures DetectCpuFeatures() noexcept {
+  CpuFeatures f;
+  uint32_t eax = 0;
+  uint32_t ebx = 0;
+  uint32_t ecx = 0;
+  uint32_t edx = 0;
+#if defined(_MSC_VER) && !defined(__clang__)
+  int info[4];
+  __cpuid(info, 0);
+  const uint32_t max_leaf = static_cast<uint32_t>(info[0]);
+  if (max_leaf < 1) return f;
+  ebx = static_cast<uint32_t>(info[1]);
+  ecx = static_cast<uint32_t>(info[2]);
+  edx = static_cast<uint32_t>(info[3]);
+#else
+  const uint32_t max_leaf = __get_cpuid_max(0, nullptr);
+  if (max_leaf < 1) return f;
+  Cpuid(0, 0, &eax, &ebx, &ecx, &edx);
+#endif
+  char vendor[12];
+  std::memcpy(vendor, &ebx, 4);
+  std::memcpy(vendor + 4, &edx, 4);
+  std::memcpy(vendor + 8, &ecx, 4);
+  const bool is_intel = std::memcmp(vendor, "GenuineIntel", 12) == 0;
+  const bool is_amd = std::memcmp(vendor, "AuthenticAMD", 12) == 0;
+
+  Cpuid(1, 0, &eax, &ebx, &ecx, &edx);
+  if (is_intel) {
+    f.type = DetectIntelCpuType(eax, ebx);
+  } else if (is_amd) {
+    f.type = DetectAmdCpuType(eax);
+  }
+  f.num_contexts_per_cpu = DetectNumContextsPerCpu(max_leaf, edx);
+
+  f.has_ssse3 = (ecx & (1U << 9)) != 0;
+  f.has_sse4_1 = (ecx & (1U << 19)) != 0;
+  f.has_aes = (ecx & (1U << 25)) != 0;
+
+  const bool osxsave = (ecx & (1U << 27)) != 0;
+  const bool avx_bit = (ecx & (1U << 28)) != 0;
+  bool ymm_ok = false;
+  bool zmm_ok = false;
+  if (osxsave && avx_bit) {
+    const uint64_t xcr0 = ReadXcr0();
+    // XCR0[2:1] = YMM + XMM state enabled by OS.
+    ymm_ok = (xcr0 & 0x6U) == 0x6U;
+    if (ymm_ok) {
+      // XCR0[7:5] = Hi16_ZMM + ZMM_Hi256 + opmask state, plus XCR0[2:1].
+      zmm_ok = (xcr0 & 0xe6U) == 0xe6U;
+#if defined(__APPLE__)
+      // Darwin enables ZMM state lazily on first AVX-512 instruction, leaving
+      // XCR0[7:5] clear prior to use; consult the kernel capability flag.
+      if (!zmm_ok) zmm_ok = SysctlBool("hw.optional.avx512f");
+#endif
+    }
+  }
+
+  if (max_leaf < 7) return f;
+  Cpuid(7, 0, &eax, &ebx, &ecx, &edx);
+  // BMI2 operates on GPRs and does not require OSXSAVE or YMM state.
+  f.has_bmi2 = (ebx & (1U << 8)) != 0;
+  if (ymm_ok) {
+    f.has_avx2 = (ebx & (1U << 5)) != 0;
+    f.has_vaes = (ecx & (1U << 9)) != 0;
+    if (zmm_ok && (ebx & (1U << 16)) != 0) {
+      f.has_avx512f = true;
+      f.has_avx512bw = (ebx & (1U << 30)) != 0;
+      f.has_avx512vl = (ebx & (1U << 31)) != 0;
+    }
+  }
+  return f;
+}
+
+}  // namespace
+
+CpuFeatures GetCpuFeatures() noexcept {
+  static const CpuFeatures kFeatures = DetectCpuFeatures();
+  return kFeatures;
+}
+
+}  // namespace base_internal
+ABSL_NAMESPACE_END
+}  // namespace absl
+
+#endif  // defined(ABSL_INTERNAL_CPU_DETECT_X86)
diff --git a/absl/copts/AbseilConfigureCopts.cmake b/absl/copts/AbseilConfigureCopts.cmake
index f1d8b26..2d67569 100644
--- a/absl/copts/AbseilConfigureCopts.cmake
+++ b/absl/copts/AbseilConfigureCopts.cmake
@@ -10,6 +10,17 @@
   set(ABSL_BUILD_DLL FALSE)
 endif()
 
+set(ABSL_RANDOM_HWAES_ARM64_FLAGS "-march=armv8-a+crypto")
+set(ABSL_RANDOM_HWAES_X64_FLAGS "-maes")
+# Big-endian ppc64 does not enable VSX by default, and -mcrypto alone does not
+# define __VSX__.
+set(ABSL_RANDOM_HWAES_PPC_FLAGS "-mcrypto" "-mvsx")
+
+set(_absl_randen_arch "${CMAKE_SYSTEM_PROCESSOR}")
+if(MSVC AND CMAKE_CXX_COMPILER_ARCHITECTURE_ID)
+  set(_absl_randen_arch "${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
+endif()
+
 if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES [[Clang]])
   # Some CMake targets (not known at the moment of processing) could be set to
   # compile for multiple architectures as specified by the OSX_ARCHITECTURES
@@ -52,23 +63,34 @@
   if(ABSL_RANDOM_RANDEN_COPTS AND NOT ABSL_RANDOM_RANDEN_COPTS_WARNING)
     list(APPEND ABSL_RANDOM_RANDEN_COPTS "-Wno-unused-command-line-argument")
   endif()
-elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64")
-  if (MSVC)
-    set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_MSVC_X64_FLAGS}")
+elseif(_absl_randen_arch MATCHES "^(x86_64|x64|amd64|AMD64)$")
+  if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8" OR
+     CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
+    # MSVC has no -maes equivalent; its AES intrinsics are always available.
+    set(ABSL_RANDOM_RANDEN_COPTS "")
   else()
     set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_X64_FLAGS}")
   endif()
-elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*|aarch64")
-  if (CMAKE_SIZEOF_VOID_P STREQUAL "8")
+elseif(_absl_randen_arch MATCHES "^(arm.*|ARM.*|aarch64|AARCH64)$")
+  if(WIN32)
+    # Windows ARM/ARM64/ARM64EC does not use runtime dispatch in platform.h.
+    set(ABSL_RANDOM_RANDEN_COPTS "")
+  elseif(CMAKE_SIZEOF_VOID_P STREQUAL "8")
     set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_ARM64_FLAGS}")
   elseif(CMAKE_SIZEOF_VOID_P STREQUAL "4")
-    set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_ARM32_FLAGS}")
+    # No flag is passed for 32-bit ARM. "-mfpu=neon" does not enable the AES
+    # extension and would override an ARMv8 toolchain's default FPU, which
+    # does; "-mfpu=crypto-neon-fp-armv8" is rejected for ARMv7 targets.
+    set(ABSL_RANDOM_RANDEN_COPTS "")
   else()
     message(WARNING "Value of CMAKE_SIZEOF_VOID_P (${CMAKE_SIZEOF_VOID_P}) is not supported.")
   endif()
+elseif(_absl_randen_arch MATCHES "^(ppc64|powerpc64)(le)?$")
+  set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_PPC_FLAGS}")
 else()
   set(ABSL_RANDOM_RANDEN_COPTS "")
 endif()
+unset(_absl_randen_arch)
 
 
 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "QCC")
diff --git a/absl/random/CMakeLists.txt b/absl/random/CMakeLists.txt
index cef4ab5..2406fbc 100644
--- a/absl/random/CMakeLists.txt
+++ b/absl/random/CMakeLists.txt
@@ -843,8 +843,10 @@
   LINKOPTS
     ${ABSL_DEFAULT_LINKOPTS}
   DEPS
+    absl::base_cpu_detect
+    absl::config
     absl::random_internal_platform
-    absl::random_internal_randen_hwaes
+    absl::random_internal_randen_hwaes_impl
     absl::random_internal_randen_slow
 )
 
@@ -868,12 +870,11 @@
 # Internal-only target, do not depend on directly.
 absl_cc_library(
   NAME
-    random_internal_randen_hwaes
+    random_internal_randen_hwaes_impl
   HDRS
-    "internal/randen_detect.h"
-  SRCS
-    "internal/randen_detect.cc"
     "internal/randen_hwaes.h"
+  SRCS
+    "internal/randen_hwaes.cc"
   COPTS
     ${ABSL_DEFAULT_COPTS}
     ${ABSL_RANDOM_RANDEN_COPTS}
@@ -882,24 +883,7 @@
   DEPS
     absl::config
     absl::core_headers
-    absl::random_internal_platform
-    absl::random_internal_randen_hwaes_impl
-)
-
-# Internal-only target, do not depend on directly.
-absl_cc_library(
-  NAME
-    random_internal_randen_hwaes_impl
-  SRCS
-    "internal/randen_hwaes.cc"
-    "internal/randen_hwaes.h"
-  COPTS
-    ${ABSL_DEFAULT_COPTS}
-    ${ABSL_RANDOM_RANDEN_COPTS}
-  LINKOPTS
-    ${ABSL_DEFAULT_LINKOPTS}
-  DEPS
-    absl::config
+    absl::int128
     absl::random_internal_platform
 )
 
@@ -1191,9 +1175,9 @@
   LINKOPTS
     ${ABSL_DEFAULT_LINKOPTS}
   DEPS
+    absl::base_cpu_detect
     absl::log
     absl::random_internal_platform
-    absl::random_internal_randen_hwaes
     absl::random_internal_randen_hwaes_impl
     absl::str_format
     GTest::gmock
diff --git a/absl/random/internal/BUILD.bazel b/absl/random/internal/BUILD.bazel
index 04f9a27..2532f6f 100644
--- a/absl/random/internal/BUILD.bazel
+++ b/absl/random/internal/BUILD.bazel
@@ -43,22 +43,33 @@
 
 licenses(["notice"])
 
-# Used to select on compilers that support GCC-compatible options
-# (e.g. "-maes").
+# Matches compilers that reject GCC-style target feature flags
+# (e.g. "-march=armv8-a+crypto", "-mfpu=neon", "-mcrypto").
 selects.config_setting_group(
-    name = "gcc_compatible",
+    name = "non_gcc_compatible",
     match_any = [
-        "@rules_cc//cc/compiler:clang",
-        "@rules_cc//cc/compiler:gcc",
+        "@rules_cc//cc/compiler:msvc-cl",
+        "@rules_cc//cc/compiler:clang-cl",
+        "@rules_cc//cc/compiler:emscripten",
     ],
 )
 
 selects.config_setting_group(
-    name = "gcc_compatible-aarch32",
-    match_all = [
-        ":gcc_compatible",
-        "@platforms//cpu:aarch32",
-    ],
+    name = "always",
+    match_any = ["//conditions:default"],
+)
+
+# Matches every compiler that is not :non_gcc_compatible. This is an exclusion
+# list rather than an allowlist of compilers so that toolchains reporting other
+# compiler names (e.g. MinGW variants) still receive the hardware AES flags.
+# select() has no negation, so when :non_gcc_compatible matches this resolves to
+# compiler:gcc, which cannot also match because the compiler is single-valued.
+alias(
+    name = "gcc_compatible",
+    actual = select({
+        ":non_gcc_compatible": "@rules_cc//cc/compiler:gcc",
+        "//conditions:default": ":always",
+    }),
 )
 
 selects.config_setting_group(
@@ -73,7 +84,6 @@
     name = "ppc_crypto",
     match_any = [
         "@platforms//cpu:ppc",
-        "@platforms//cpu:ppc32",
         "@platforms//cpu:ppc64le",
     ],
 )
@@ -94,18 +104,31 @@
     ],
 )
 
+# clang-cl rejects the other GCC-style flags above but accepts "-maes".
+selects.config_setting_group(
+    name = "clang-cl-x86_64",
+    match_all = [
+        "@rules_cc//cc/compiler:clang-cl",
+        "@platforms//cpu:x86_64",
+    ],
+)
+
 # Some libraries are compiled with options to generate AES-NI
 # instructions, and runtime dispatch is used to determine if the host
 # microarchitecture supports AES-NI or if a portable fallback library
 # should be called.
+#
+# No flag is passed for 32-bit ARM: "-mfpu=neon" does not enable the AES
+# extension and would override an ARMv8 toolchain's default FPU, which does.
 ABSL_RANDOM_RANDEN_COPTS = select({
-    ":gcc_compatible-aarch32": ["-mfpu=neon"],
     ":gcc_compatible-aarch64": ["-march=armv8-a+crypto"],
-    ":gcc_compatible-ppc_crypto": ["-mcrypto"],
-    ":gcc_compatible-x86_64": [
-        "-maes",
-        "-msse4.1",
+    # Big-endian ppc64 does not enable VSX by default.
+    ":gcc_compatible-ppc_crypto": [
+        "-mcrypto",
+        "-mvsx",
     ],
+    ":gcc_compatible-x86_64": ["-maes"],
+    ":clang-cl-x86_64": ["-maes"],
     "//conditions:default": [],
 })
 
@@ -375,10 +398,10 @@
     linkopts = ABSL_DEFAULT_LINKOPTS,
     deps = [
         ":platform",
-        ":randen_hwaes",
         ":randen_hwaes_impl",
         ":randen_slow",
         "//absl/base:config",
+        "//absl/base:cpu_detect",
     ],
 )
 
@@ -397,22 +420,6 @@
     ],
 )
 
-cc_library(
-    name = "randen_hwaes",
-    srcs = [
-        "randen_detect.cc",
-    ],
-    hdrs = [
-        "randen_detect.h",
-    ],
-    copts = ABSL_DEFAULT_COPTS,
-    linkopts = ABSL_DEFAULT_LINKOPTS,
-    deps = [
-        ":platform",
-        "//absl/base:config",
-    ],
-)
-
 # build with --save_temps to see assembly language output.
 cc_library(
     name = "randen_hwaes_impl",
@@ -743,13 +750,13 @@
     name = "randen_hwaes_test",
     size = "small",
     srcs = ["randen_hwaes_test.cc"],
-    copts = ABSL_TEST_COPTS + ABSL_RANDOM_RANDEN_COPTS,
+    copts = ABSL_TEST_COPTS,
     linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = ABSL_RANDOM_NONPORTABLE_TAGS,
     deps = [
         ":platform",
-        ":randen_hwaes",
         ":randen_hwaes_impl",  # build_cleaner: keep
+        "//absl/base:cpu_detect",
         "//absl/log",
         "@googletest//:gtest",
     ],
@@ -838,7 +845,7 @@
     size = "medium",
     timeout = "long",
     srcs = ["randen_benchmarks.cc"],
-    copts = ABSL_TEST_COPTS + ABSL_RANDOM_RANDEN_COPTS,
+    copts = ABSL_TEST_COPTS,
     flaky = 1,
     linkopts = ABSL_DEFAULT_LINKOPTS,
     tags = ABSL_RANDOM_NONPORTABLE_TAGS + ["benchmark"],
@@ -846,9 +853,9 @@
         ":nanobenchmark",
         ":randen",
         ":randen_engine",
-        ":randen_hwaes",
         ":randen_hwaes_impl",
         ":randen_slow",
+        "//absl/base:cpu_detect",
         "//absl/base:raw_logging_internal",
         "//absl/strings",
     ],
diff --git a/absl/random/internal/platform.h b/absl/random/internal/platform.h
index a6fde4b..37a377a 100644
--- a/absl/random/internal/platform.h
+++ b/absl/random/internal/platform.h
@@ -59,13 +59,17 @@
 // including necessary headers to support hardware AES.
 //
 // ABSL_ARCH_{X86/PPC/ARM} macros determine the platform.
-#if defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || \
+//
+// AArch64 is checked first because MSVC defines both _M_ARM64EC and _M_X64
+// (and _M_AMD64) when targeting ARM64EC.
+#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || \
+    defined(_M_ARM64EC)
+#define ABSL_ARCH_AARCH64
+#elif defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) || \
     defined(_M_X64)
 #define ABSL_ARCH_X86_64
 #elif defined(__i386) || defined(_M_IX86)
 #define ABSL_ARCH_X86_32
-#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
-#define ABSL_ARCH_AARCH64
 #elif defined(__arm__) || defined(__ARMEL__) || defined(_M_ARM)
 #define ABSL_ARCH_ARM
 #elif defined(__powerpc64__) || defined(__PPC64__) || defined(__powerpc__) || \
@@ -99,7 +103,8 @@
 
 #if defined(ABSL_ARCH_X86_64)
 
-#if defined(__AES__) || defined(__AVX__)
+// MSVC has no -maes equivalent; its AES intrinsics are always available.
+#if defined(__AES__) || (defined(_MSC_VER) && !defined(__clang__))
 #undef ABSL_HAVE_ACCELERATED_AES
 #define ABSL_HAVE_ACCELERATED_AES 1
 #endif
@@ -116,8 +121,10 @@
 #elif defined(ABSL_ARCH_ARM) || defined(ABSL_ARCH_AARCH64)
 
 // http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053c/IHI0053C_acle_2_0.pdf
-// Rely on NEON+CRYPTO extensions for ARM.
-#if defined(__ARM_NEON) && defined(__ARM_FEATURE_CRYPTO)
+// Rely on NEON+AES extensions for ARM. ACLE deprecated __ARM_FEATURE_CRYPTO
+// (which also requires SHA1/SHA2) in favor of __ARM_FEATURE_AES.
+#if defined(__ARM_NEON) && \
+    (defined(__ARM_FEATURE_AES) || defined(__ARM_FEATURE_CRYPTO))
 #undef ABSL_HAVE_ACCELERATED_AES
 #define ABSL_HAVE_ACCELERATED_AES 1
 #endif
diff --git a/absl/random/internal/randen.cc b/absl/random/internal/randen.cc
index e42013c..04d35dd 100644
--- a/absl/random/internal/randen.cc
+++ b/absl/random/internal/randen.cc
@@ -15,8 +15,8 @@
 #include "absl/random/internal/randen.h"
 
 #include "absl/base/config.h"
+#include "absl/base/internal/cpu_detect.h"
 #include "absl/random/internal/platform.h"
-#include "absl/random/internal/randen_detect.h"
 #include "absl/random/internal/randen_hwaes.h"
 #include "absl/random/internal/randen_slow.h"
 
@@ -58,7 +58,8 @@
     RandenState tmp;
 #if ABSL_RANDOM_INTERNAL_AES_DISPATCH
     // HW AES Dispatch.
-    if (HasRandenHwAesImplementation() && CPUSupportsRandenHwAes()) {
+    if (HasRandenHwAesImplementation() &&
+        absl::base_internal::SupportsRandenHwAes()) {
       tmp.has_crypto = true;
       tmp.keys = RandenHwAes::GetKeys();
     } else {
diff --git a/absl/random/internal/randen_benchmarks.cc b/absl/random/internal/randen_benchmarks.cc
index 51e6a50..0e90552 100644
--- a/absl/random/internal/randen_benchmarks.cc
+++ b/absl/random/internal/randen_benchmarks.cc
@@ -16,10 +16,10 @@
 #include <cstdio>
 #include <cstring>
 
+#include "absl/base/internal/cpu_detect.h"
 #include "absl/base/internal/raw_logging.h"
 #include "absl/random/internal/nanobenchmark.h"
 #include "absl/random/internal/randen.h"
-#include "absl/random/internal/randen_detect.h"
 #include "absl/random/internal/randen_engine.h"
 #include "absl/random/internal/randen_hwaes.h"
 #include "absl/random/internal/randen_slow.h"
@@ -27,7 +27,8 @@
 
 namespace {
 
-using absl::random_internal::CPUSupportsRandenHwAes;
+using absl::base_internal::SupportsRandenHwAes;
+using absl::random_internal::HasRandenHwAesImplementation;
 using absl::random_internal::Randen;
 using absl::random_internal::RandenHwAes;
 using absl::random_internal::RandenSlow;
@@ -151,12 +152,16 @@
   const FuncInput unpredictable = (argc != 999);
   static const FuncInput inputs[] = {unpredictable * 100, unpredictable * 1000};
 
-  if (CPUSupportsRandenHwAes()) {
+  // RandenHwAes is a stub that exits when the implementation is not built.
+  const bool measure_hwaes =
+      HasRandenHwAesImplementation() && SupportsRandenHwAes();
+
+  if (measure_hwaes) {
     Measure<AbsorbFn<RandenHwAes>>("Absorb (HwAes)", inputs);
   }
   Measure<AbsorbFn<RandenSlow>>("Absorb (Slow)", inputs);
 
-  if (CPUSupportsRandenHwAes()) {
+  if (measure_hwaes) {
     Measure<GenerateFn<RandenHwAes>>("Generate (HwAes)", inputs);
   }
   Measure<GenerateFn<RandenSlow>>("Generate (Slow)", inputs);
diff --git a/absl/random/internal/randen_detect.cc b/absl/random/internal/randen_detect.cc
deleted file mode 100644
index 888e36f..0000000
--- a/absl/random/internal/randen_detect.cc
+++ /dev/null
@@ -1,279 +0,0 @@
-// Copyright 2017 The Abseil Authors.
-//
-// 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
-//
-//      https://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.
-
-// HERMETIC NOTE: The randen_hwaes target must not introduce duplicate
-// symbols from arbitrary system and other headers, since it may be built
-// with different flags from other targets, using different levels of
-// optimization, potentially introducing ODR violations.
-
-#include "absl/random/internal/randen_detect.h"
-
-#include <optional>  // IWYU pragma: keep
-
-#include "absl/base/config.h"
-#include "absl/random/internal/platform.h"
-
-#if defined(__APPLE__) && defined(__aarch64__)
-#if __has_include(<arm/cpu_capabilities_public.h>)
-#include <arm/cpu_capabilities_public.h>
-#endif
-#include <sys/sysctl.h>
-#include <sys/types.h>
-#endif
-
-#if !defined(__UCLIBC__) && defined(__GLIBC__) && \
-    (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16))
-#define ABSL_HAVE_GETAUXVAL
-#endif
-
-#if defined(ABSL_ARCH_X86_64)
-#define ABSL_INTERNAL_USE_X86_CPUID
-#elif defined(ABSL_ARCH_PPC) || defined(ABSL_ARCH_ARM) || \
-    defined(ABSL_ARCH_AARCH64)
-#if defined(__ANDROID__)
-#define ABSL_INTERNAL_USE_ANDROID_GETAUXVAL
-#define ABSL_INTERNAL_USE_GETAUXVAL
-#elif defined(__linux__) && defined(ABSL_HAVE_GETAUXVAL)
-#define ABSL_INTERNAL_USE_LINUX_GETAUXVAL
-#define ABSL_INTERNAL_USE_GETAUXVAL
-#endif
-#endif
-
-#if defined(ABSL_INTERNAL_USE_X86_CPUID)
-#if defined(_WIN32) || defined(_WIN64)
-#include <intrin.h>  // NOLINT(build/include_order)
-#elif ABSL_HAVE_BUILTIN(__cpuid)
-// MSVC-equivalent __cpuid intrinsic declaration for clang-like compilers
-// for non-Windows build environments.
-extern void __cpuid(int[4], int);
-#else
-// MSVC-equivalent __cpuid intrinsic function.
-static void __cpuid(int cpu_info[4], int info_type) {
-  __asm__ volatile("cpuid \n\t"
-                   : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]),
-                     "=d"(cpu_info[3])
-                   : "a"(info_type), "c"(0));
-}
-#endif
-#endif  // ABSL_INTERNAL_USE_X86_CPUID
-
-// On linux, just use the c-library getauxval call.
-#if defined(ABSL_INTERNAL_USE_LINUX_GETAUXVAL)
-
-#include <sys/auxv.h>
-
-static uint32_t GetAuxval(uint32_t hwcap_type) {
-  return static_cast<uint32_t>(getauxval(hwcap_type));
-}
-
-#endif
-
-// On android, probe the system's C library for getauxval().
-// This is the same technique used by the android NDK cpu features library
-// as well as the google open-source cpu_features library.
-//
-// TODO(absl-team): Consider implementing a fallback of directly reading
-// /proc/self/auxval.
-#if defined(ABSL_INTERNAL_USE_ANDROID_GETAUXVAL)
-#include <dlfcn.h>
-
-#include <cstring>
-
-static uint32_t GetAuxval(uint32_t hwcap_type) {
-  // NOLINTNEXTLINE(runtime/int)
-  typedef unsigned long (*getauxval_func_t)(unsigned long);
-
-  dlerror();  // Cleaning error state before calling dlopen.
-  void* libc_handle = dlopen("libc.so", RTLD_NOW);
-  if (!libc_handle) {
-    return 0;
-  }
-  uint32_t result = 0;
-  void* sym = dlsym(libc_handle, "getauxval");
-  if (sym) {
-    getauxval_func_t func;
-    memcpy(&func, &sym, sizeof(func));
-    result = static_cast<uint32_t>((*func)(hwcap_type));
-  }
-  dlclose(libc_handle);
-  return result;
-}
-
-#endif
-
-#if defined(__APPLE__) && defined(ABSL_ARCH_AARCH64)
-template <typename T>
-static std::optional<T> ReadSysctlByName(const char* name) {
-  T val;
-  size_t val_size = sizeof(T);
-  int ret = sysctlbyname(name, &val, &val_size, nullptr, 0);
-  if (ret == -1) {
-    return std::nullopt;
-  }
-  return val;
-}
-#endif
-
-namespace absl {
-ABSL_NAMESPACE_BEGIN
-namespace random_internal {
-
-// The default return at the end of the function might be unreachable depending
-// on the configuration. Ignore that warning.
-#if defined(__clang__)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunreachable-code-return"
-#endif
-
-// CPUSupportsRandenHwAes returns whether the CPU is a microarchitecture
-// which supports the crpyto/aes instructions or extensions necessary to use the
-// accelerated RandenHwAes implementation.
-//
-// 1. For x86 it is sufficient to use the CPUID instruction to detect whether
-//    the cpu supports AES instructions. Done.
-//
-// Fon non-x86 it is much more complicated.
-//
-// 2. When ABSL_INTERNAL_USE_GETAUXVAL is defined, use getauxval() (either
-//    the direct c-library version, or the android probing version which loads
-//    libc), and read the hardware capability bits.
-//    This is based on the technique used by boringssl uses to detect
-//    cpu capabilities, and should allow us to enable crypto in the android
-//    builds where it is supported.
-//
-// 3. When __APPLE__ is defined on AARCH64, use sysctlbyname().
-//
-// 4. Use the default for the compiler architecture.
-//
-
-bool CPUSupportsRandenHwAes() {
-#if defined(ABSL_INTERNAL_USE_X86_CPUID)
-  // 1. For x86: Use CPUID to detect the required AES instruction set.
-  int regs[4];
-  __cpuid(reinterpret_cast<int*>(regs), 1);
-  return regs[2] & (1 << 25);  // AES
-
-#elif defined(ABSL_INTERNAL_USE_GETAUXVAL)
-  // 2. Use getauxval() to read the hardware bits and determine
-  // cpu capabilities.
-
-#define AT_HWCAP 16
-#define AT_HWCAP2 26
-#if defined(ABSL_ARCH_PPC)
-  // For Power / PPC: Expect that the cpu supports VCRYPTO
-  // See https://members.openpowerfoundation.org/document/dl/576
-  // VCRYPTO should be present in POWER8 >= 2.07.
-  // Uses Linux kernel constants from arch/powerpc/include/uapi/asm/cputable.h
-  static const uint32_t kVCRYPTO = 0x02000000;
-  const uint32_t hwcap = GetAuxval(AT_HWCAP2);
-  return (hwcap & kVCRYPTO) != 0;
-
-#elif defined(ABSL_ARCH_ARM)
-  // For ARM: Require crypto+neon
-  // http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0500f/CIHBIBBA.html
-  // Uses Linux kernel constants from arch/arm64/include/asm/hwcap.h
-  static const uint32_t kNEON = 1 << 12;
-  uint32_t hwcap = GetAuxval(AT_HWCAP);
-  if ((hwcap & kNEON) == 0) {
-    return false;
-  }
-
-  // And use it again to detect AES.
-  static const uint32_t kAES = 1 << 0;
-  const uint32_t hwcap2 = GetAuxval(AT_HWCAP2);
-  return (hwcap2 & kAES) != 0;
-
-#elif defined(ABSL_ARCH_AARCH64)
-  // For AARCH64: Require crypto+neon
-  // http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0500f/CIHBIBBA.html
-  static const uint32_t kNEON = 1 << 1;
-  static const uint32_t kAES = 1 << 3;
-  const uint32_t hwcap = GetAuxval(AT_HWCAP);
-  return ((hwcap & kNEON) != 0) && ((hwcap & kAES) != 0);
-#endif
-
-#elif defined(__APPLE__) && defined(ABSL_ARCH_AARCH64)
-  // 3. Use sysctlbyname.
-
-  // Newer XNU kernels support querying all capabilities in a single
-  // sysctlbyname.
-#if defined(CAP_BIT_AdvSIMD) && defined(CAP_BIT_FEAT_AES)
-  static const std::optional<uint64_t> caps =
-      ReadSysctlByName<uint64_t>("hw.optional.arm.caps");
-  if (caps.has_value()) {
-    constexpr uint64_t kNeonAndAesCaps =
-        (uint64_t{1} << CAP_BIT_AdvSIMD) | (uint64_t{1} << CAP_BIT_FEAT_AES);
-    return (*caps & kNeonAndAesCaps) == kNeonAndAesCaps;
-  }
-#endif
-
-  // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#overview
-  static const std::optional<int> adv_simd =
-      ReadSysctlByName<int>("hw.optional.AdvSIMD");
-  if (adv_simd.value_or(0) == 0) {
-    return false;
-  }
-  // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics#3918855
-  static const std::optional<int> feat_aes =
-      ReadSysctlByName<int>("hw.optional.arm.FEAT_AES");
-  if (feat_aes.value_or(0) == 0) {
-    return false;
-  }
-  return true;
-#else  // ABSL_INTERNAL_USE_GETAUXVAL
-  // 4. By default, assume that the compiler default.
-  return ABSL_HAVE_ACCELERATED_AES ? true : false;
-
-#endif
-  // NOTE: There are some other techniques that may be worth trying:
-  //
-  // * Use an environment variable: ABSL_RANDOM_USE_HWAES
-  //
-  // * Rely on compiler-generated target-based dispatch.
-  // Using x86/gcc it might look something like this:
-  //
-  // __attribute__((target("aes"))) int HasAes() { return 1; }
-  // __attribute__((target("default"))) int HasAes() { return 0; }
-  //
-  // This does not work on all architecture/compiler combinations.
-  //
-  // * On Linux consider reading /proc/cpuinfo and/or /proc/self/auxv.
-  // These files have lines which are easy to parse; for ARM/AARCH64 it is quite
-  // easy to find the Features: line and extract aes / neon. Likewise for
-  // PPC.
-  //
-  // * Fork a process and test for SIGILL:
-  //
-  // * Many architectures have instructions to read the ISA. Unfortunately
-  //   most of those require that the code is running in ring 0 /
-  //   protected-mode.
-  //
-  //   There are several examples. e.g. Valgrind detects PPC ISA 2.07:
-  //   https://github.com/lu-zero/valgrind/blob/master/none/tests/ppc64/test_isa_2_07_part1.c
-  //
-  //   MRS <Xt>, ID_AA64ISAR0_EL1 ; Read ID_AA64ISAR0_EL1 into Xt
-  //
-  //   uint64_t val;
-  //   __asm __volatile("mrs %0, id_aa64isar0_el1" :"=&r" (val));
-  //
-  // * Use a CPUID-style heuristic database.
-}
-
-#if defined(__clang__)
-#pragma clang diagnostic pop
-#endif
-
-}  // namespace random_internal
-ABSL_NAMESPACE_END
-}  // namespace absl
diff --git a/absl/random/internal/randen_detect.h b/absl/random/internal/randen_detect.h
deleted file mode 100644
index f283f43..0000000
--- a/absl/random/internal/randen_detect.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2017 The Abseil Authors.
-//
-// 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
-//
-//      https://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.
-
-#ifndef ABSL_RANDOM_INTERNAL_RANDEN_DETECT_H_
-#define ABSL_RANDOM_INTERNAL_RANDEN_DETECT_H_
-
-#include "absl/base/config.h"
-
-namespace absl {
-ABSL_NAMESPACE_BEGIN
-namespace random_internal {
-
-// Returns whether the current CPU supports RandenHwAes implementation.
-// This typically involves supporting cryptographic extensions on whichever
-// platform is currently running.
-bool CPUSupportsRandenHwAes();
-
-}  // namespace random_internal
-ABSL_NAMESPACE_END
-}  // namespace absl
-
-#endif  // ABSL_RANDOM_INTERNAL_RANDEN_DETECT_H_
diff --git a/absl/random/internal/randen_hwaes_test.cc b/absl/random/internal/randen_hwaes_test.cc
index 956e9d6..263c3b0 100644
--- a/absl/random/internal/randen_hwaes_test.cc
+++ b/absl/random/internal/randen_hwaes_test.cc
@@ -18,9 +18,9 @@
 #include <cstring>
 
 #include "gtest/gtest.h"
+#include "absl/base/internal/cpu_detect.h"
 #include "absl/log/log.h"
 #include "absl/random/internal/platform.h"
-#include "absl/random/internal/randen_detect.h"
 #include "absl/random/internal/randen_traits.h"
 
 namespace {
@@ -28,8 +28,23 @@
 using absl::random_internal::RandenHwAes;
 using absl::random_internal::RandenTraits;
 
+// Whether the build is expected to compile the accelerated implementation
+// into randen_hwaes.cc. On these configurations a missing implementation means
+// that the hardware AES compiler flags were lost, so the test must fail rather
+// than be skipped. ILP32 ABIs (such as x32) are excluded because the CMake
+// build does not pass the flags for them.
+#if ABSL_RANDOM_INTERNAL_AES_DISPATCH && !defined(__ILP32__) && \
+    (defined(ABSL_ARCH_X86_64) ||                               \
+     (defined(ABSL_ARCH_AARCH64) && !defined(__ANDROID__))) &&  \
+    (defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER))
+constexpr bool kExpectHwAesImplementation = true;
+#else
+constexpr bool kExpectHwAesImplementation = false;
+#endif
+
 TEST(RandenHwAesTest, Default) {
-  EXPECT_TRUE(absl::random_internal::CPUSupportsRandenHwAes());
+  ASSERT_TRUE(absl::random_internal::HasRandenHwAesImplementation());
+  EXPECT_TRUE(absl::base_internal::SupportsRandenHwAes());
 
   constexpr uint8_t kGolden[] = {
       0xee, 0xd3, 0xe6, 0x0e, 0x09, 0x34, 0x65, 0x6c, 0xc6, 0x33, 0x53, 0x9d,
@@ -89,10 +104,12 @@
   int x = absl::random_internal::HasRandenHwAesImplementation();
   LOG(INFO) << "HasRandenHwAesImplementation = " << x;
 
-  int y = absl::random_internal::CPUSupportsRandenHwAes();
-  LOG(INFO) << "CPUSupportsRandenHwAes = " << y;
+  int y = absl::base_internal::SupportsRandenHwAes();
+  LOG(INFO) << "SupportsRandenHwAes = " << y;
 
-  if (!x || !y) {
+  // When the implementation is expected, run the tests even if it is missing
+  // so that RandenHwAesTest.Default reports the failure.
+  if (!y || (!x && !kExpectHwAesImplementation)) {
     LOG(INFO) << "Skipping Randen HWAES tests.";
     return 0;
   }