KernelUtils.h - add describeArch() am: 47ddbe066c am: 73bc010668

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/libs/net/+/23391172

Change-Id: I705da3610685cb70a4380a9eec7ee38480463b5a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/common/native/bpf_headers/include/bpf/KernelUtils.h b/common/native/bpf_headers/include/bpf/KernelUtils.h
index 865f856..b3dd86c 100644
--- a/common/native/bpf_headers/include/bpf/KernelUtils.h
+++ b/common/native/bpf_headers/include/bpf/KernelUtils.h
@@ -118,7 +118,7 @@
     return !isKernel64Bit();
 }
 
-static __unused constexpr bool isArm() {
+static constexpr bool isArm() {
 #if defined(__arm__) || defined(__aarch64__)
     return true;
 #else
@@ -126,7 +126,7 @@
 #endif
 }
 
-static __unused constexpr bool isX86() {
+static constexpr bool isX86() {
 #if defined(__i386__) || defined(__x86_64__)
     return true;
 #else
@@ -134,7 +134,7 @@
 #endif
 }
 
-static __unused constexpr bool isRiscV() {
+static constexpr bool isRiscV() {
 #if defined(__riscv)
     static_assert(isUserspace64bit(), "riscv must be 64 bit");
     return true;
@@ -145,6 +145,21 @@
 
 static_assert(isArm() || isX86() || isRiscV(), "Unknown architecture");
 
+static __unused const char * describeArch() {
+    // ordered so as to make it easier to compile time optimize,
+    // only thing not known at compile time is isKernel64Bit()
+    if (isUserspace64bit()) {
+        if (isArm()) return "64-on-aarch64";
+        if (isX86()) return "64-on-x86-64";
+        if (isRiscV()) return "64-on-riscv64";
+    } else if (isKernel64Bit()) {
+        if (isArm()) return "32-on-aarch64";
+        if (isX86()) return "32-on-x86-64";
+    } else {
+        if (isArm()) return "32-on-arm32";
+        if (isX86()) return "32-on-x86-32";
+    }
+}
 
 }  // namespace bpf
 }  // namespace android