Support Windows/MSVC build with Bazel

PiperOrigin-RevId: 307017940
diff --git a/BUILD.bazel b/BUILD.bazel
index 492754f..1b2323c 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -6,7 +6,7 @@
 # Description:
 #   XNNPACK - optimized floating-point neural network operators library
 
-load(":build_defs.bzl", "xnnpack_aggregate_library", "xnnpack_benchmark", "xnnpack_binary", "xnnpack_cc_library", "xnnpack_min_size_copts", "xnnpack_optional_armcl_copts", "xnnpack_optional_armcl_deps", "xnnpack_optional_dnnl_copts", "xnnpack_optional_dnnl_deps", "xnnpack_optional_gemmlowp_copts", "xnnpack_optional_gemmlowp_deps", "xnnpack_optional_ruy_copts", "xnnpack_optional_ruy_deps", "xnnpack_optional_tflite_copts", "xnnpack_optional_tflite_deps", "xnnpack_std_copts", "xnnpack_std_cxxopts", "xnnpack_unit_test", "xnnpack_visibility")
+load(":build_defs.bzl", "xnnpack_aggregate_library", "xnnpack_benchmark", "xnnpack_binary", "xnnpack_cc_library", "xnnpack_gcc_std_copts", "xnnpack_min_size_copts", "xnnpack_msvc_std_copts", "xnnpack_optional_armcl_copts", "xnnpack_optional_armcl_deps", "xnnpack_optional_dnnl_copts", "xnnpack_optional_dnnl_deps", "xnnpack_optional_gemmlowp_copts", "xnnpack_optional_gemmlowp_deps", "xnnpack_optional_ruy_copts", "xnnpack_optional_ruy_deps", "xnnpack_optional_tflite_copts", "xnnpack_optional_tflite_deps", "xnnpack_std_cxxopts", "xnnpack_unit_test", "xnnpack_visibility")
 
 licenses(["notice"])
 
@@ -1639,7 +1639,8 @@
     name = "tables",
     srcs = TABLE_SRCS,
     hdrs = INTERNAL_HDRS,
-    copts = xnnpack_std_copts(),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    msvc_copts = xnnpack_msvc_std_copts(),
 )
 
 xnnpack_cc_library(
@@ -1647,7 +1648,8 @@
     srcs = SCALAR_UKERNELS,
     hdrs = INTERNAL_HDRS,
     aarch32_copts = ["-marm"],
-    copts = xnnpack_std_copts(),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    msvc_copts = xnnpack_msvc_std_copts(),
     deps = [
         ":tables",
         "@FP16",
@@ -1659,7 +1661,8 @@
 xnnpack_cc_library(
     name = "wasm_ukernels",
     hdrs = INTERNAL_HDRS,
-    copts = xnnpack_std_copts(),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    msvc_copts = xnnpack_msvc_std_copts(),
     wasm_srcs = WASM_UKERNELS,
     deps = [
         ":tables",
@@ -1676,15 +1679,14 @@
         "-marm",
         "-mfpu=neon",
     ],
-    copts = xnnpack_std_copts(),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    gcc_x86_copts = ["-msse2"],
+    msvc_copts = xnnpack_msvc_std_copts(),
     optimized_copts = [
         "-O3",
         "-ffast-math",
     ],
     psimd_srcs = PSIMD_FASTMATH_UKERNELS,
-    x86_copts = [
-        "-msse2",
-    ],
     deps = [
         ":tables",
         "@FP16",
@@ -1700,14 +1702,13 @@
         "-marm",
         "-mfpu=neon",
     ],
-    copts = xnnpack_std_copts(),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    gcc_x86_copts = ["-msse2"],
+    msvc_copts = xnnpack_msvc_std_copts(),
     optimized_copts = [
         "-O3",
     ],
     psimd_srcs = PSIMD_ACCMATH_UKERNELS,
-    x86_copts = [
-        "-msse2",
-    ],
     deps = [
         ":tables",
         "@FP16",
@@ -1725,7 +1726,8 @@
     ],
     aarch32_srcs = NEON_UKERNELS,
     aarch64_srcs = NEON_UKERNELS,
-    copts = xnnpack_std_copts(),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    msvc_copts = xnnpack_msvc_std_copts(),
     deps = [
         ":tables",
         "@FP16",
@@ -1742,7 +1744,8 @@
     ],
     aarch32_srcs = NEONFMA_UKERNELS,
     aarch64_srcs = NEONFMA_UKERNELS + AARCH64_NEONFMA_UKERNELS,
-    copts = xnnpack_std_copts(),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    msvc_copts = xnnpack_msvc_std_copts(),
     deps = [
         ":tables",
         "@FP16",
@@ -1755,7 +1758,8 @@
     hdrs = INTERNAL_HDRS,
     aarch64_copts = ["-march=armv8.2-a+fp16"],
     aarch64_srcs = AARCH64_NEONFP16ARITH_UKERNELS,
-    copts = xnnpack_std_copts(),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    msvc_copts = xnnpack_msvc_std_copts(),
     deps = [
         ":tables",
         "@FP16",
@@ -1766,8 +1770,10 @@
 xnnpack_cc_library(
     name = "sse2_ukernels",
     hdrs = INTERNAL_HDRS,
-    copts = xnnpack_std_copts(),
-    x86_copts = ["-msse2"],
+    gcc_copts = xnnpack_gcc_std_copts(),
+    gcc_x86_copts = ["-msse2"],
+    msvc_copts = xnnpack_msvc_std_copts(),
+    msvc_x86_32_copts = ["/arch:SSE2"],
     x86_srcs = SSE_UKERNELS + SSE2_UKERNELS,
     deps = [
         ":tables",
@@ -1779,8 +1785,10 @@
 xnnpack_cc_library(
     name = "ssse3_ukernels",
     hdrs = INTERNAL_HDRS,
-    copts = xnnpack_std_copts(),
-    x86_copts = ["-mssse3"],
+    gcc_copts = xnnpack_gcc_std_copts(),
+    gcc_x86_copts = ["-mssse3"],
+    msvc_copts = xnnpack_msvc_std_copts(),
+    msvc_x86_32_copts = ["/arch:SSE2"],
     x86_srcs = SSSE3_UKERNELS,
     deps = [
         ":tables",
@@ -1792,8 +1800,10 @@
 xnnpack_cc_library(
     name = "sse41_ukernels",
     hdrs = INTERNAL_HDRS,
-    copts = xnnpack_std_copts(),
-    x86_copts = ["-msse4.1"],
+    gcc_copts = xnnpack_gcc_std_copts(),
+    gcc_x86_copts = ["-msse4.1"],
+    msvc_copts = xnnpack_msvc_std_copts(),
+    msvc_x86_32_copts = ["/arch:SSE2"],
     x86_srcs = SSE41_UKERNELS,
     deps = [
         ":tables",
@@ -1805,8 +1815,11 @@
 xnnpack_cc_library(
     name = "avx_ukernels",
     hdrs = INTERNAL_HDRS,
-    copts = xnnpack_std_copts(),
-    x86_copts = ["-mavx"],
+    gcc_copts = xnnpack_gcc_std_copts(),
+    gcc_x86_copts = ["-mavx"],
+    msvc_copts = xnnpack_msvc_std_copts(),
+    msvc_x86_32_copts = ["/arch:AVX"],
+    msvc_x86_64_copts = ["/arch:AVX"],
     x86_srcs = AVX_UKERNELS,
     deps = [
         ":tables",
@@ -1818,10 +1831,11 @@
 xnnpack_cc_library(
     name = "fma3_ukernels",
     hdrs = INTERNAL_HDRS,
-    copts = xnnpack_std_copts(),
-    x86_copts = [
-        "-mfma",
-    ],
+    gcc_copts = xnnpack_gcc_std_copts(),
+    gcc_x86_copts = ["-mfma"],
+    msvc_copts = xnnpack_msvc_std_copts(),
+    msvc_x86_32_copts = ["/arch:AVX"],
+    msvc_x86_64_copts = ["/arch:AVX"],
     x86_srcs = FMA3_UKERNELS,
     deps = [
         ":tables",
@@ -1833,11 +1847,14 @@
 xnnpack_cc_library(
     name = "avx2_ukernels",
     hdrs = INTERNAL_HDRS,
-    copts = xnnpack_std_copts(),
-    x86_copts = [
+    gcc_copts = xnnpack_gcc_std_copts(),
+    gcc_x86_copts = [
         "-mfma",
         "-mavx2",
     ],
+    msvc_copts = xnnpack_msvc_std_copts(),
+    msvc_x86_32_copts = ["/arch:AVX2"],
+    msvc_x86_64_copts = ["/arch:AVX2"],
     x86_srcs = AVX2_UKERNELS,
     deps = [
         ":tables",
@@ -1849,8 +1866,13 @@
 xnnpack_cc_library(
     name = "avx512f_ukernels",
     hdrs = INTERNAL_HDRS,
-    copts = xnnpack_std_copts(),
-    x86_copts = ["-mavx512f"],
+    gcc_copts = xnnpack_gcc_std_copts(),
+    gcc_x86_copts = ["-mavx512f"],
+    mingw_copts = ["-fno-asynchronous-unwind-tables"],
+    msvc_copts = xnnpack_msvc_std_copts(),
+    msvc_x86_32_copts = ["/arch:AVX512"],
+    msvc_x86_64_copts = ["/arch:AVX512"],
+    msys_copts = ["-fno-asynchronous-unwind-tables"],
     x86_srcs = AVX512F_UKERNELS,
     deps = [
         ":tables",
@@ -1905,14 +1927,16 @@
         "src/xnnpack/common.h",
         "src/xnnpack/im2col.h",
     ],
-    copts = xnnpack_std_copts(),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    msvc_copts = xnnpack_msvc_std_copts(),
 )
 
 xnnpack_cc_library(
     name = "indirection",
     srcs = ["src/indirection.c"],
     hdrs = INTERNAL_HDRS,
-    copts = xnnpack_std_copts(),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    msvc_copts = xnnpack_msvc_std_copts(),
     deps = [
         "@FP16",
         "@FXdiv",
@@ -1924,10 +1948,12 @@
     name = "operator_run",
     srcs = ["src/operator-run.c"],
     hdrs = INTERNAL_HDRS + LOGGING_HDRS,
-    copts = xnnpack_std_copts() + LOGGING_COPTS + select({
+    copts = LOGGING_COPTS + select({
         ":xnn_enable_hmp_explicit_false": ["-DXNN_MAX_UARCH_TYPES=1"],
         "//conditions:default": [],
     }),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    msvc_copts = xnnpack_msvc_std_copts(),
     deps = [
         "@FP16",
         "@FXdiv",
@@ -1952,7 +1978,7 @@
         "src/operator-delete.c",
     ],
     hdrs = INTERNAL_HDRS + LOGGING_HDRS,
-    copts = xnnpack_std_copts() + LOGGING_COPTS + [
+    copts = LOGGING_COPTS + [
         "-Isrc",
         "-Iinclude",
     ] + select({
@@ -1962,6 +1988,8 @@
         ":xnn_enable_hmp_explicit_false": ["-DXNN_MAX_UARCH_TYPES=1"],
         "//conditions:default": [],
     }),
+    gcc_copts = xnnpack_gcc_std_copts(),
+    msvc_copts = xnnpack_msvc_std_copts(),
     wasm_srcs = ["src/wasm-stubs.c"],
     wasmsimd_srcs = ["src/wasm-stubs.c"],
     deps = [
@@ -1973,7 +2001,7 @@
     ],
 )
 
-cc_library(
+xnnpack_cc_library(
     name = "XNNPACK",
     srcs = [
         "src/init.c",
@@ -1981,7 +2009,8 @@
         "src/subgraph.c",
         "src/tensor.c",
     ],
-    copts = xnnpack_std_copts() + LOGGING_COPTS + [
+    hdrs = ["include/xnnpack.h"],
+    copts = LOGGING_COPTS + [
         "-Isrc",
         "-Iinclude",
     ] + select({
@@ -1991,9 +2020,9 @@
         ":xnn_enable_hmp_explicit_false": ["-DXNN_MAX_UARCH_TYPES=1"],
         "//conditions:default": [],
     }),
+    gcc_copts = xnnpack_gcc_std_copts(),
     includes = ["include"],
-    linkstatic = True,
-    textual_hdrs = ["include/xnnpack.h"],
+    msvc_copts = xnnpack_msvc_std_copts(),
     visibility = xnnpack_visibility(),
     deps = [
         ":enable_assembly",
@@ -2008,12 +2037,13 @@
     }),
 )
 
-cc_library(
+xnnpack_cc_library(
     name = "xnnpack_operators_nhwc_f32",
     srcs = [
         "src/init.c",
     ],
-    copts = xnnpack_std_copts() + LOGGING_COPTS + [
+    hdrs = ["include/xnnpack.h"],
+    copts = LOGGING_COPTS + [
         "-Isrc",
         "-Iinclude",
     ] + select({
@@ -2029,9 +2059,9 @@
         "XNN_NO_X8_OPERATORS",
         "XNN_NO_NCHW_OPERATORS",
     ],
+    gcc_copts = xnnpack_gcc_std_copts(),
     includes = ["include"],
-    linkstatic = True,
-    textual_hdrs = ["include/xnnpack.h"],
+    msvc_copts = xnnpack_msvc_std_copts(),
     visibility = xnnpack_visibility(),
     deps = [
         ":enable_assembly",
@@ -2050,7 +2080,7 @@
     name = "bench_utils",
     srcs = ["bench/utils.cc"],
     hdrs = ["bench/utils.h"],
-    copts = ["-Wno-unused-result"],
+    gcc_copts = ["-Wno-unused-result"],
     deps = [
         "@com_google_benchmark//:benchmark",
         "@cpuinfo",
@@ -2066,7 +2096,8 @@
         "bench/q8-gemm.cc",
         "src/xnnpack/AlignedAllocator.h",
     ] + WEIGHTS_PACK_HDRS + MICROKERNEL_BENCHMARK_HDRS,
-    copts = ["-Wno-unused-function"] + xnnpack_optional_ruy_copts() + xnnpack_optional_gemmlowp_copts(),
+    copts = xnnpack_optional_ruy_copts() + xnnpack_optional_gemmlowp_copts(),
+    gcc_copts = ["-Wno-unused-function"],
     deps = MICROKERNEL_BENCHMARK_DEPS + xnnpack_optional_ruy_deps() + xnnpack_optional_gemmlowp_deps(),
 )
 
@@ -2077,7 +2108,7 @@
         "bench/gemm.h",
         "src/xnnpack/AlignedAllocator.h",
     ] + WEIGHTS_PACK_HDRS + MICROKERNEL_BENCHMARK_HDRS,
-    copts = ["-Wno-unused-function"],
+    gcc_copts = ["-Wno-unused-function"],
     deps = MICROKERNEL_BENCHMARK_DEPS,
 )
 
@@ -2086,10 +2117,9 @@
     srcs = [
         "bench/f16-spmm.cc",
         "bench/gemm.h",
-        "bench/google/gemm.h",
         "src/xnnpack/AlignedAllocator.h",
     ] + MICROKERNEL_BENCHMARK_HDRS,
-    copts = ["-Wno-unused-function"],
+    gcc_copts = ["-Wno-unused-function"],
     deps = MICROKERNEL_BENCHMARK_DEPS,
 )
 
@@ -2110,7 +2140,7 @@
         "bench/dconv.h",
         "src/xnnpack/AlignedAllocator.h",
     ] + WEIGHTS_PACK_HDRS + MICROKERNEL_BENCHMARK_HDRS,
-    copts = ["-Wno-unused-function"],
+    gcc_copts = ["-Wno-unused-function"],
     deps = MICROKERNEL_BENCHMARK_DEPS,
 )
 
@@ -2121,7 +2151,7 @@
         "bench/dconv.h",
         "src/xnnpack/AlignedAllocator.h",
     ] + WEIGHTS_PACK_HDRS + MICROKERNEL_BENCHMARK_HDRS,
-    copts = ["-Wno-unused-function"],
+    gcc_copts = ["-Wno-unused-function"],
     deps = MICROKERNEL_BENCHMARK_DEPS,
 )
 
@@ -2152,7 +2182,8 @@
         "bench/gemm.h",
         "src/xnnpack/AlignedAllocator.h",
     ] + WEIGHTS_PACK_HDRS + MICROKERNEL_BENCHMARK_HDRS,
-    copts = ["-Wno-unused-function"] + xnnpack_optional_ruy_copts(),
+    copts = xnnpack_optional_ruy_copts(),
+    gcc_copts = ["-Wno-unused-function"],
     deps = MICROKERNEL_BENCHMARK_DEPS + xnnpack_optional_ruy_deps(),
 )
 
@@ -2198,7 +2229,7 @@
         "bench/f32-sigmoid.cc",
         "src/xnnpack/AlignedAllocator.h",
     ] + MICROKERNEL_BENCHMARK_HDRS,
-    copts = ["-Wno-unused-function"],
+    gcc_copts = ["-Wno-unused-function"],
     deps = MICROKERNEL_BENCHMARK_DEPS,
 )
 
@@ -2209,7 +2240,7 @@
         "bench/gemm.h",
         "src/xnnpack/AlignedAllocator.h",
     ] + MICROKERNEL_BENCHMARK_HDRS,
-    copts = ["-Wno-unused-function"],
+    gcc_copts = ["-Wno-unused-function"],
     deps = MICROKERNEL_BENCHMARK_DEPS,
 )
 
@@ -2218,7 +2249,8 @@
     srcs = [
         "bench/f32-softmax.cc",
     ] + MICROKERNEL_BENCHMARK_HDRS,
-    copts = ["-Wno-unused-function"] + xnnpack_optional_dnnl_copts(),
+    copts = xnnpack_optional_dnnl_copts(),
+    gcc_copts = ["-Wno-unused-function"],
     deps = MICROKERNEL_BENCHMARK_DEPS + xnnpack_optional_dnnl_deps(),
 )
 
@@ -2384,7 +2416,7 @@
         "bench/f32-dwconv-e2e.cc",
         "bench/end2end.h",
     ] + MICROKERNEL_BENCHMARK_HDRS,
-    copts = ["-Wno-unused-function"],
+    gcc_copts = ["-Wno-unused-function"],
     deps = MICROKERNEL_BENCHMARK_DEPS + [
         ":XNNPACK",
         ":mobilenet_v1",
@@ -2400,7 +2432,7 @@
         "bench/f32-gemm-e2e.cc",
         "bench/end2end.h",
     ] + MICROKERNEL_BENCHMARK_HDRS,
-    copts = ["-Wno-unused-function"],
+    gcc_copts = ["-Wno-unused-function"],
     deps = MICROKERNEL_BENCHMARK_DEPS + [
         ":XNNPACK",
         ":mobilenet_v1",
@@ -2540,6 +2572,9 @@
         "test/gemm-microkernel-tester.h",
         "src/xnnpack/AlignedAllocator.h",
     ] + WEIGHTS_PACK_HDRS + MICROKERNEL_TEST_HDRS,
+    # Work-around for "too many sections" error
+    mingw_copts = ["-Wa,-mbig-obj"],
+    msys_copts = ["-Wa,-mbig-obj"],
     deps = MICROKERNEL_TEST_DEPS,
 )
 
@@ -3408,13 +3443,32 @@
 )
 
 config_setting(
-    name = "windows_x86",
-    values = {"cpu": "win_x86"},
+    name = "windows_x86_64",
+    values = {"cpu": "x64_windows"},
 )
 
 config_setting(
-    name = "windows_x86_64",
-    values = {"cpu": "win_x64"},
+    name = "windows_x86_64_clang",
+    values = {
+        "compiler": "clang-cl",
+        "cpu": "x64_windows",
+    },
+)
+
+config_setting(
+    name = "windows_x86_64_mingw",
+    values = {
+        "compiler": "mingw-gcc",
+        "cpu": "x64_windows",
+    },
+)
+
+config_setting(
+    name = "windows_x86_64_msys",
+    values = {
+        "compiler": "msys-gcc",
+        "cpu": "x64_windows",
+    },
 )
 
 config_setting(
diff --git a/WORKSPACE b/WORKSPACE
index b1d96b9..9fbf82e 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -37,17 +37,17 @@
 # FXdiv library, used for repeated integer division by the same factor
 http_archive(
     name = "FXdiv",
-    strip_prefix = "FXdiv-f7dd0576a1c8289ef099d4fd8b136b1c4487a873",
-    sha256 = "6e4b6e3c58e67c3bb090e286c4f235902c89b98cf3e67442a18f9167963aa286",
-    urls = ["https://github.com/Maratyszcza/FXdiv/archive/f7dd0576a1c8289ef099d4fd8b136b1c4487a873.zip"],
+    strip_prefix = "FXdiv-b408327ac2a15ec3e43352421954f5b1967701d1",
+    sha256 = "ab7dfb08829bee33dca38405d647868fb214ac685e379ec7ef2bebcd234cd44d",
+    urls = ["https://github.com/Maratyszcza/FXdiv/archive/b408327ac2a15ec3e43352421954f5b1967701d1.zip"],
 )
 
 # pthreadpool library, used for parallelization
 http_archive(
     name = "pthreadpool",
-    strip_prefix = "pthreadpool-a61ed1ab70389c62f6f699ca1a30a2421d3ea594",
-    sha256 = "27c039e73846d0bdfe393833e91afafe45e61ba792cc60e1c62808090554ce4d",
-    urls = ["https://github.com/Maratyszcza/pthreadpool/archive/a61ed1ab70389c62f6f699ca1a30a2421d3ea594.zip"],
+    strip_prefix = "pthreadpool-e918b206d26b1f3b2100b0edabf445c18708d2b7",
+    sha256 = "c4b148fba41fc937fdf96bc195caadf0cf0be83f1c3e335ef5355934d4501f83",
+    urls = ["https://github.com/Maratyszcza/pthreadpool/archive/e918b206d26b1f3b2100b0edabf445c18708d2b7.zip"],
 )
 
 # clog library, used for logging
@@ -75,11 +75,9 @@
 # psimd library, used for fallback 128-bit SIMD micro-kernels
 http_archive(
     name = "psimd",
-    strip_prefix = "psimd-88882f601f8179e1987b7e7cf4a8012c9080ad44",
-    sha256 = "c621f9bb1ff9ab8f0fa4a04f3239d13b345a6e865318d7b464aa80531a1abb2c",
-    urls = [
-        "https://github.com/Maratyszcza/psimd/archive/88882f601f8179e1987b7e7cf4a8012c9080ad44.tar.gz",
-    ],
+    strip_prefix = "psimd-85427dd4c8521cc037a1ffa6fcd25c55fafc8a00",
+    sha256 = "db23c2bc4a58d6f40c181797e43103300edac7cf9d286ca81590543f66ab95d2",
+    urls = ["https://github.com/Maratyszcza/psimd/archive/85427dd4c8521cc037a1ffa6fcd25c55fafc8a00.zip"],
     build_file = "@//third_party:psimd.BUILD",
 )
 
diff --git a/build_defs.bzl b/build_defs.bzl
index 9e5f496..8a18232 100644
--- a/build_defs.bzl
+++ b/build_defs.bzl
@@ -14,10 +14,14 @@
     """Compiler flags for size-optimized builds."""
     return ["-Os"]
 
-def xnnpack_std_copts():
-    """Compiler flags to specify language standard for C sources."""
+def xnnpack_gcc_std_copts():
+    """GCC-like compiler flags to specify language standard for C sources."""
     return ["-std=c99"]
 
+def xnnpack_msvc_std_copts():
+    """MSVC compiler flags to specify language standard for C sources."""
+    return ["/Drestrict="]
+
 def xnnpack_std_cxxopts():
     """Compiler flags to specify language standard for C++ sources."""
     return ["-std=gnu++11"]
@@ -65,6 +69,7 @@
 def xnnpack_cc_library(
         name,
         srcs = [],
+        psimd_srcs = [],
         x86_srcs = [],
         aarch32_srcs = [],
         aarch64_srcs = [],
@@ -72,7 +77,13 @@
         wasm_srcs = [],
         wasmsimd_srcs = [],
         copts = [],
-        x86_copts = [],
+        gcc_copts = [],
+        msvc_copts = [],
+        mingw_copts = [],
+        msys_copts = [],
+        gcc_x86_copts = [],
+        msvc_x86_32_copts = [],
+        msvc_x86_64_copts = [],
         aarch32_copts = [],
         aarch64_copts = [],
         asmjs_copts = [],
@@ -80,7 +91,10 @@
         wasmsimd_copts = [],
         optimized_copts = ["-O2"],
         hdrs = [],
-        deps = []):
+        defines = [],
+        includes = [],
+        deps = [],
+        visibility = []):
     """C/C++/assembly library with architecture-specific configuration.
 
     Define a static library with architecture- and instruction-specific
@@ -99,7 +113,13 @@
       copts: The list of compiler flags to use in all builds. -I flags for
              include/ and src/ directories of XNNPACK are always prepended
              before these user-specified flags.
-      x86_copts: The list of compiler flags to use in x86 builds.
+      gcc_copts: The list of compiler flags to use with GCC-like compilers.
+      msvc_copts: The list of compiler flags to use with MSVC compiler.
+      mingw_copts: The list of compiler flags to use with MinGW GCC compilers.
+      msys_copts: The list of compiler flags to use with MSYS (Cygwin) GCC compilers.
+      gcc_x86_copts: The list of GCC-like compiler flags to use in x86 (32-bit and 64-bit) builds.
+      msvc_x86_32_copts: The list of MSVC compiler flags to use in x86 (32-bit) builds.
+      msvc_x86_64_copts: The list of MSVC compiler flags to use in x86 (64-bit) builds.
       aarch32_copts: The list of compiler flags to use in AArch32 builds.
       aarch64_copts: The list of compiler flags to use in AArch64 builds.
       asmjs_copts: The list of compiler flags to use in Asm.js builds.
@@ -110,7 +130,10 @@
                        Defaults to -O2.
       hdrs: The list of header files published by this library to be textually
             included by sources in dependent rules.
+      defines: List of predefines macros to be added to the compile line.
+      includes: List of include dirs to be added to the compile line.
       deps: The list of other libraries to be linked.
+      visibility: The list of packages that can depend on this target.
     """
     native.cc_library(
         name = name,
@@ -119,8 +142,10 @@
             ":linux_aarch64": psimd_srcs + aarch64_srcs,
             ":linux_armhf": psimd_srcs + aarch32_srcs,
             ":macos_x86_64": psimd_srcs + x86_srcs,
-            ":windows_x86": psimd_srcs + x86_srcs,
-            ":windows_x86_64": psimd_srcs + x86_srcs,
+            ":windows_x86_64_clang": psimd_srcs + x86_srcs,
+            ":windows_x86_64_mingw": psimd_srcs + x86_srcs,
+            ":windows_x86_64_msys": psimd_srcs + x86_srcs,
+            ":windows_x86_64": x86_srcs,
             ":android_armv7": psimd_srcs + aarch32_srcs,
             ":android_arm64": psimd_srcs + aarch64_srcs,
             ":android_x86": psimd_srcs + x86_srcs,
@@ -145,36 +170,46 @@
             "-Iinclude",
             "-Isrc",
         ] + copts + select({
-            ":linux_k8": x86_copts,
+            ":linux_k8": gcc_x86_copts,
             ":linux_aarch64": aarch64_copts,
             ":linux_armhf": aarch32_copts,
-            ":macos_x86_64": x86_copts,
-            ":windows_x86": x86_copts,
-            ":windows_x86_64": x86_copts,
+            ":macos_x86_64": gcc_x86_copts,
+            ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_x86_copts],
+            ":windows_x86_64_mingw": mingw_copts + gcc_x86_copts,
+            ":windows_x86_64_msys": msys_copts + gcc_x86_copts,
+            ":windows_x86_64": msvc_x86_64_copts,
             ":android_armv7": aarch32_copts,
             ":android_arm64": aarch64_copts,
-            ":android_x86": x86_copts,
-            ":android_x86_64": x86_copts,
+            ":android_x86": gcc_x86_copts,
+            ":android_x86_64": gcc_x86_copts,
             ":ios_armv7": aarch32_copts,
             ":ios_arm64": aarch64_copts,
             ":ios_arm64e": aarch64_copts,
-            ":ios_x86": x86_copts,
-            ":ios_x86_64": x86_copts,
+            ":ios_x86": gcc_x86_copts,
+            ":ios_x86_64": gcc_x86_copts,
             ":watchos_armv7k": aarch32_copts,
             ":watchos_arm64_32": aarch64_copts,
-            ":watchos_x86": x86_copts,
-            ":watchos_x86_64": x86_copts,
+            ":watchos_x86": gcc_x86_copts,
+            ":watchos_x86_64": gcc_x86_copts,
             ":tvos_arm64": aarch64_copts,
-            ":tvos_x86_64": x86_copts,
+            ":tvos_x86_64": gcc_x86_copts,
             ":emscripten_asmjs": asmjs_copts,
             ":emscripten_wasm": wasm_copts,
             ":emscripten_wasmsimd": wasmsimd_copts,
             "//conditions:default": [],
         }) + select({
+            ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_copts],
+            ":windows_x86_64_mingw": gcc_copts,
+            ":windows_x86_64_msys": gcc_copts,
+            ":windows_x86_64": msvc_copts,
+            "//conditions:default": gcc_copts,
+        }) + select({
             ":optimized_build": optimized_copts,
             "//conditions:default": [],
         }),
-        includes = ["include", "src"],
+        defines = defines,
+        deps = deps,
+        includes = ["include", "src"] + includes,
         linkstatic = True,
         linkopts = select({
             ":linux_k8": ["-lpthread"],
@@ -184,7 +219,7 @@
             "//conditions:default": [],
         }),
         textual_hdrs = hdrs,
-        deps = deps,
+        visibility = visibility,
     )
 
 def xnnpack_aggregate_library(
@@ -217,8 +252,10 @@
             ":linux_aarch64": psimd_deps + aarch64_deps,
             ":linux_armhf": psimd_deps + aarch32_deps,
             ":macos_x86_64": psimd_deps + x86_deps,
-            ":windows_x86": psimd_deps + x86_deps,
-            ":windows_x86_64": psimd_deps + x86_deps,
+            ":windows_x86_64_clang": psimd_deps + x86_deps,
+            ":windows_x86_64_mingw": psimd_deps + x86_deps,
+            ":windows_x86_64_msys": psimd_deps + x86_deps,
+            ":windows_x86_64": x86_deps,
             ":android_armv7": psimd_deps + aarch32_deps,
             ":android_arm64": psimd_deps + aarch64_deps,
             ":android_x86": psimd_deps + x86_deps,
@@ -240,7 +277,7 @@
         }),
     )
 
-def xnnpack_unit_test(name, srcs, copts = [], deps = []):
+def xnnpack_unit_test(name, srcs, copts = [], mingw_copts = [], msys_copts = [], deps = []):
     """Unit test binary based on Google Test.
 
     Args:
@@ -249,6 +286,8 @@
       copts: The list of additional compiler flags for the target. -I flags
              for include/ and src/ directories of XNNPACK are always prepended
              before these user-specified flags.
+      mingw_copts: The list of compiler flags to use with MinGW GCC compilers.
+      msys_copts: The list of compiler flags to use with MSYS (Cygwin) GCC compilers.
       deps: The list of additional libraries to be linked. Google Test library
             (with main() function) is always added as a dependency and does not
             need to be explicitly specified.
@@ -260,7 +299,11 @@
         copts = xnnpack_std_cxxopts() + [
             "-Iinclude",
             "-Isrc",
-        ] + copts,
+        ] + copts + select({
+            ":windows_x86_64_mingw": mingw_copts,
+            ":windows_x86_64_msys": msys_copts,
+            "//conditions:default": [],
+        }),
         linkopts = select({
             ":emscripten": xnnpack_emscripten_test_linkopts(),
             "//conditions:default": [],
@@ -300,7 +343,7 @@
         deps = deps,
     )
 
-def xnnpack_benchmark(name, srcs, copts = [], deps = []):
+def xnnpack_benchmark(name, srcs, copts = [], gcc_copts = [], msvc_copts = [], deps = []):
     """Microbenchmark binary based on Google Benchmark
 
     Args:
@@ -309,6 +352,8 @@
       copts: The list of additional compiler flags for the target. -I flags
              for include/ and src/ directories of XNNPACK are always prepended
              before these user-specified flags.
+      gcc_copts: The list of compiler flags to use with GCC-like compilers.
+      msvc_copts: The list of compiler flags to use with MSVC compiler.
       deps: The list of additional libraries to be linked. Google Benchmark
             library is always added as a dependency and does not need to be
             explicitly specified.
@@ -319,9 +364,17 @@
         copts = xnnpack_std_cxxopts() + [
             "-Iinclude",
             "-Isrc",
-        ] + copts,
+        ] + copts + select({
+            ":windows_x86_64_clang": ["/clang:" + opt for opt in gcc_copts],
+            ":windows_x86_64_mingw": gcc_copts,
+            ":windows_x86_64_msys": gcc_copts,
+            ":windows_x86_64": msvc_copts,
+            "//conditions:default": gcc_copts,
+        }),
         linkopts = select({
             ":emscripten": xnnpack_emscripten_benchmark_linkopts(),
+            ":windows_x86_64_mingw": ["-lshlwapi"],
+            ":windows_x86_64_msys": ["-lshlwapi"],
             "//conditions:default": [],
         }),
         linkstatic = True,
diff --git a/cmake/DownloadFXdiv.cmake b/cmake/DownloadFXdiv.cmake
index b4dc0ef..9150d20 100644
--- a/cmake/DownloadFXdiv.cmake
+++ b/cmake/DownloadFXdiv.cmake
@@ -12,8 +12,8 @@
 
 INCLUDE(ExternalProject)
 ExternalProject_Add(fxdiv
-  URL https://github.com/Maratyszcza/FXdiv/archive/f7dd0576a1c8289ef099d4fd8b136b1c4487a873.zip
-  URL_HASH SHA256=6e4b6e3c58e67c3bb090e286c4f235902c89b98cf3e67442a18f9167963aa286
+  URL https://github.com/Maratyszcza/FXdiv/archive/b408327ac2a15ec3e43352421954f5b1967701d1.zip
+  URL_HASH SHA256=ab7dfb08829bee33dca38405d647868fb214ac685e379ec7ef2bebcd234cd44d
   SOURCE_DIR "${CMAKE_BINARY_DIR}/FXdiv-source"
   BINARY_DIR "${CMAKE_BINARY_DIR}/FXdiv"
   CONFIGURE_COMMAND ""
diff --git a/cmake/DownloadPSimd.cmake b/cmake/DownloadPSimd.cmake
index b7e2f34..98d1be4 100644
--- a/cmake/DownloadPSimd.cmake
+++ b/cmake/DownloadPSimd.cmake
@@ -12,8 +12,8 @@
 
 INCLUDE(ExternalProject)
 ExternalProject_Add(psimd
-  URL https://github.com/Maratyszcza/psimd/archive/10b4ffc6ea9e2e11668f86969586f88bc82aaefa.tar.gz
-  URL_HASH SHA256=1fefd66702cb2eb3462b962f33d4fb23d59a55d5889ee6372469d286c4512df4
+  URL https://github.com/Maratyszcza/psimd/archive/85427dd4c8521cc037a1ffa6fcd25c55fafc8a00.zip
+  URL_HASH SHA256=db23c2bc4a58d6f40c181797e43103300edac7cf9d286ca81590543f66ab95d2
   SOURCE_DIR "${CMAKE_BINARY_DIR}/psimd-source"
   BINARY_DIR "${CMAKE_BINARY_DIR}/psimd"
   CONFIGURE_COMMAND ""
diff --git a/cmake/DownloadPThreadPool.cmake b/cmake/DownloadPThreadPool.cmake
index 80cd936..7c57d0c 100644
--- a/cmake/DownloadPThreadPool.cmake
+++ b/cmake/DownloadPThreadPool.cmake
@@ -12,8 +12,8 @@
 
 INCLUDE(ExternalProject)
 ExternalProject_Add(pthreadpool
-  URL https://github.com/Maratyszcza/pthreadpool/archive/a61ed1ab70389c62f6f699ca1a30a2421d3ea594.zip
-  URL_HASH SHA256=27c039e73846d0bdfe393833e91afafe45e61ba792cc60e1c62808090554ce4d
+  URL https://github.com/Maratyszcza/pthreadpool/archive/e918b206d26b1f3b2100b0edabf445c18708d2b7.zip
+  URL_HASH SHA256=c4b148fba41fc937fdf96bc195caadf0cf0be83f1c3e335ef5355934d4501f83
   SOURCE_DIR "${CMAKE_BINARY_DIR}/pthreadpool-source"
   BINARY_DIR "${CMAKE_BINARY_DIR}/pthreadpool"
   CONFIGURE_COMMAND ""
diff --git a/third_party/clog.BUILD b/third_party/clog.BUILD
index 68153fb..0b7a778 100644
--- a/third_party/clog.BUILD
+++ b/third_party/clog.BUILD
@@ -12,18 +12,16 @@
     srcs = [
         "deps/clog/src/clog.c",
     ],
-    copts = [
-        "-Wno-unused-result",
-    ],
+    copts = select({
+        ":windows": [],
+        "//conditions:default": ["-Wno-unused-result"],
+    }),
     hdrs = [
         "deps/clog/include/clog.h",
     ],
     linkopts = select({
-        ":android": [
-            "-llog",
-        ],
-        "//conditions:default": [
-        ],
+        ":android": ["-llog"],
+        "//conditions:default": [],
     }),
     strip_include_prefix = "deps/clog/include",
 )
@@ -31,5 +29,9 @@
 config_setting(
     name = "android",
     values = {"crosstool_top": "//external:android/crosstool"},
-    visibility = ["//visibility:public"],
+)
+
+config_setting(
+    name = "windows",
+    values = {"cpu": "x64_windows"},
 )
diff --git a/third_party/cpuinfo.BUILD b/third_party/cpuinfo.BUILD
index 340b3bc..22ec4e2 100644
--- a/third_party/cpuinfo.BUILD
+++ b/third_party/cpuinfo.BUILD
@@ -99,6 +99,7 @@
         ":linux_x86_64": COMMON_SRCS + X86_SRCS + LINUX_SRCS + LINUX_X86_SRCS,
         ":linux_aarch64": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM64_SRCS,
         ":macos_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS,
+        ":windows_x86_64": COMMON_SRCS + X86_SRCS + WINDOWS_X86_SRCS,
         ":android_armv7": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM32_SRCS + ANDROID_ARM_SRCS,
         ":android_arm64": COMMON_SRCS + ARM_SRCS + LINUX_SRCS + LINUX_ARM64_SRCS + ANDROID_ARM_SRCS,
         ":android_x86": COMMON_SRCS + X86_SRCS + LINUX_SRCS + LINUX_X86_SRCS,
@@ -115,7 +116,10 @@
         ":tvos_x86_64": COMMON_SRCS + X86_SRCS + MACH_SRCS + MACH_X86_SRCS,
         ":tvos_arm64": COMMON_SRCS + MACH_SRCS + MACH_ARM_SRCS,
     }),
-    copts = C99OPTS + [
+    copts = select({
+        ":windows_x86_64": [],
+        "//conditions:default": C99OPTS,
+    }) + [
         "-Iexternal/cpuinfo/include",
         "-Iexternal/cpuinfo/src",
     ],
@@ -175,6 +179,11 @@
 )
 
 config_setting(
+    name = "windows_x86_64",
+    values = {"cpu": "x64_windows"},
+)
+
+config_setting(
     name = "android_armv7",
     values = {
         "crosstool_top": "//external:android/crosstool",