add arch and target macros for RVV

PiperOrigin-RevId: 350509453
diff --git a/hwy/base.h b/hwy/base.h
index 8b16ad7..d6b4e38 100644
--- a/hwy/base.h
+++ b/hwy/base.h
@@ -202,7 +202,14 @@
 #define HWY_ARCH_WASM 0
 #endif
 
-#if HWY_ARCH_X86 + HWY_ARCH_PPC + HWY_ARCH_ARM + HWY_ARCH_WASM != 1
+#ifdef __riscv
+#define HWY_ARCH_RVV 1
+#else
+#define HWY_ARCH_RVV 0
+#endif
+
+#if (HWY_ARCH_X86 + HWY_ARCH_PPC + HWY_ARCH_ARM + HWY_ARCH_WASM + \
+     HWY_ARCH_RVV) != 1
 #error "Must detect exactly one platform"
 #endif
 
@@ -307,7 +314,7 @@
 // Undefined results for x == 0.
 HWY_API size_t Num0BitsBelowLS1Bit_Nonzero32(const uint32_t x) {
 #ifdef _MSC_VER
-  unsigned long index;
+  unsigned long index;  // NOLINT
   _BitScanForward(&index, x);
   return index;
 #else
diff --git a/hwy/highway.h b/hwy/highway.h
index e3b0027..09ebe5a 100644
--- a/hwy/highway.h
+++ b/hwy/highway.h
@@ -120,6 +120,12 @@
 #define HWY_CHOOSE_WASM(FUNC_NAME) nullptr
 #endif
 
+#if HWY_TARGETS & HWY_RVV
+#define HWY_CHOOSE_RVV(FUNC_NAME) &N_RVV::FUNC_NAME
+#else
+#define HWY_CHOOSE_RVV(FUNC_NAME) nullptr
+#endif
+
 #if HWY_TARGETS & HWY_NEON
 #define HWY_CHOOSE_NEON(FUNC_NAME) &N_NEON::FUNC_NAME
 #else
@@ -241,6 +247,9 @@
 #include "hwy/ops/arm_neon-inl.h"
 #elif HWY_TARGET == HWY_WASM
 #include "hwy/ops/wasm_128-inl.h"
+#elif HWY_TARGET == HWY_RVV
+// TODO(janwas): header
+#include "hwy/ops/shared-inl.h"
 #elif HWY_TARGET == HWY_SCALAR
 #include "hwy/ops/scalar-inl.h"
 #else
@@ -276,7 +285,8 @@
 }
 
 // CombineShiftRightBytes (and ..Lanes) are not available for the scalar target.
-#if HWY_TARGET != HWY_SCALAR
+// TODO(janwas): implement for RVV
+#if HWY_TARGET != HWY_SCALAR && HWY_TARGET != HWY_RVV
 
 template <size_t kLanes, class V>
 HWY_API V CombineShiftRightLanes(const V hi, const V lo) {
diff --git a/hwy/ops/set_macros-inl.h b/hwy/ops/set_macros-inl.h
index cc7f62f..06ea00c 100644
--- a/hwy/ops/set_macros-inl.h
+++ b/hwy/ops/set_macros-inl.h
@@ -184,6 +184,29 @@
 #define HWY_TARGET_STR "simd128"
 
 //-----------------------------------------------------------------------------
+// RVV
+#elif HWY_TARGET == HWY_RVV
+
+#define HWY_ALIGN
+#define HWY_LANES(T) (4096 / sizeof(T))
+
+#define HWY_GATHER_LANES(T) HWY_LANES(T)
+#define HWY_VARIABLE_SHIFT_LANES(T) HWY_LANES(T)
+#define HWY_COMPARE64_LANES HWY_LANES(T)
+#define HWY_MINMAX64_LANES HWY_LANES(T)
+
+// TODO(janwas): enable after implementing
+#define HWY_CAP_INTEGER64 0
+#define HWY_CAP_FLOAT64 0
+#define HWY_CAP_GE256 0
+#define HWY_CAP_GE512 0
+
+#define HWY_NAMESPACE N_RVV
+
+// HWY_TARGET_STR remains undefined so HWY_ATTR is a no-op.
+// (rv64gcv is not a valid target)
+
+//-----------------------------------------------------------------------------
 // SCALAR
 #elif HWY_TARGET == HWY_SCALAR
 
diff --git a/hwy/targets.h b/hwy/targets.h
index fcc1145..bf2665a 100644
--- a/hwy/targets.h
+++ b/hwy/targets.h
@@ -81,8 +81,13 @@
 
 #define HWY_HIGHEST_TARGET_BIT_WASM 20
 
-// 0x200000, 0x400000, 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000,
-// 0x10000000 reserved
+// 0x200000, 0x400000, 0x800000 reserved
+
+#define HWY_RVV 0x1000000
+
+#define HWY_HIGHEST_TARGET_BIT_RVV 24
+
+// 0x2000000, 0x4000000, 0x8000000, 0x10000000 reserved
 
 #define HWY_SCALAR 0x20000000
 // Cannot use higher values, otherwise HWY_TARGETS computation might overflow.
@@ -177,9 +182,16 @@
 #define HWY_BASELINE_AVX3 0
 #endif
 
+#ifdef __riscv_vector
+#define HWY_BASELINE_RVV HWY_RVV
+#else
+#define HWY_BASELINE_RVV 0
+#endif
+
 #define HWY_BASELINE_TARGETS                                                \
   (HWY_SCALAR | HWY_BASELINE_WASM | HWY_BASELINE_PPC8 | HWY_BASELINE_NEON | \
-   HWY_BASELINE_SSE4 | HWY_BASELINE_AVX2 | HWY_BASELINE_AVX3)
+   HWY_BASELINE_SSE4 | HWY_BASELINE_AVX2 | HWY_BASELINE_AVX3 |              \
+   HWY_BASELINE_RVV)
 
 #endif  // HWY_BASELINE_TARGETS
 
@@ -325,6 +337,11 @@
       return "Wasm";
 #endif
 
+#if HWY_ARCH_RVV
+    case HWY_RVV:
+      return "RVV";
+#endif
+
     case HWY_SCALAR:
       return "Scalar";
 
@@ -427,6 +444,18 @@
 
 #endif  // HWY_ARCH_WASM
 
+#if HWY_ARCH_RVV
+// See HWY_ARCH_X86 above for details.
+#define HWY_MAX_DYNAMIC_TARGETS 4
+#define HWY_HIGHEST_TARGET_BIT HWY_HIGHEST_TARGET_BIT_RVV
+#define HWY_CHOOSE_TARGET_LIST(func_name)       \
+  nullptr,                       /* reserved */ \
+      nullptr,                   /* reserved */ \
+      nullptr,                   /* reserved */ \
+      HWY_CHOOSE_RVV(func_name) /* RVV */
+
+#endif  // HWY_ARCH_RVV
+
 struct ChosenTarget {
  public:
   // Update the ChosenTarget mask based on the current CPU supported