;;
esac
+ if [ -x ccache ]; then
+ ./ccache --version
+ elif command -v wine >/dev/null && [ -f ccache.exe ]; then
+ wine ccache.exe --version
+ fi
+
case "${RUN_TESTS:-all}" in
all)
CC="${TEST_CC}" ctest --output-on-failure -j"${JOBS}" "$@"
;;
unittest-in-wine)
- wine ccache.exe --version
wine unittest/unittest.exe
;;
none)
include(CheckIncludeFile)
set(include_files
+ cpuid.h
dirent.h
linux/fs.h
pwd.h
check_cxx_source_compiles(
[=[
#include <immintrin.h>
- #ifndef _MSC_VER // MSVC does not need explicit enabling of AVX2.
- void func() __attribute__((target("avx2")));
+ #ifndef _MSC_VER
+ __attribute__((target("avx2")))
#endif
void func() { _mm256_abs_epi8(_mm256_set1_epi32(42)); }
int main()
// === Header files ===
+// Define if you have the <cpuid.h> header file.
+#cmakedefine HAVE_CPUID_H
+
// Define if you have the <dirent.h> header file.
#cmakedefine HAVE_DIRENT_H
#include <ccache/util/UmaskScope.hpp>
#include <ccache/util/XXH3_128.hpp>
#include <ccache/util/assertions.hpp>
+#include <ccache/util/cpu.hpp>
#include <ccache/util/environment.hpp>
#include <ccache/util/expected.hpp>
#include <ccache/util/file.hpp>
static std::string
get_version_text(const std::string_view ccache_name)
{
+ auto features = storage::get_features();
+ if (util::cpu_supports_avx2()) {
+ features.emplace_back("avx2");
+ }
+ std::sort(features.begin(), features.end());
return FMT(
- VERSION_TEXT, ccache_name, CCACHE_VERSION, storage::get_features());
+ VERSION_TEXT, ccache_name, CCACHE_VERSION, util::join(features, " "));
}
std::string
#include <ccache/execute.hpp>
#include <ccache/macroskip.hpp>
#include <ccache/util/DirEntry.hpp>
+#include <ccache/util/cpu.hpp>
#include <ccache/util/file.hpp>
#include <ccache/util/format.hpp>
#include <ccache/util/logging.hpp>
# include "InodeCache.hpp"
#endif
-#include <blake3_cpu_supports_avx2.h>
-
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
}
#ifdef HAVE_AVX2
-# ifndef _MSC_VER // MSVC does not need explicit enabling of AVX2.
-HashSourceCodeResult check_for_temporal_macros_avx2(std::string_view str)
- __attribute__((target("avx2")));
-# endif
-
// The following algorithm, which uses AVX2 instructions to find __DATE__,
// __TIME__ and __TIMESTAMP__, is heavily inspired by
// <http://0x80.pl/articles/simd-strfind.html>.
+# ifndef _MSC_VER
+__attribute__((target("avx2")))
+# endif
HashSourceCodeResult
check_for_temporal_macros_avx2(std::string_view str)
{
check_for_temporal_macros(std::string_view str)
{
#ifdef HAVE_AVX2
- if (blake3_cpu_supports_avx2()) {
+ if (util::cpu_supports_avx2()) {
return check_for_temporal_macros_avx2(str);
}
#endif
#endif
};
-std::string
+std::vector<std::string>
get_features()
{
std::vector<std::string> features;
k_remote_storage_implementations.end(),
std::back_inserter(features),
[](auto& entry) { return FMT("{}-storage", entry.first); });
- std::sort(features.begin(), features.end());
- return util::join(features, " ");
+ return features;
}
// Representation of one shard configuration.
constexpr auto k_redacted_password = "********";
-std::string get_features();
+std::vector<std::string> get_features();
struct RemoteStorageBackendEntry;
struct RemoteStorageEntry;
Tokenizer.cpp
UmaskScope.cpp
assertions.cpp
+ cpu.cpp
environment.cpp
error.cpp
file.cpp
--- /dev/null
+// Copyright (C) 2024 Joel Rosdahl and other contributors
+//
+// See doc/AUTHORS.adoc for a complete list of contributors.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+#include "cpu.hpp"
+
+#ifdef _MSC_VER
+# include <intrin.h>
+#endif
+
+#ifdef HAVE_CPUID_H
+# include <cpuid.h>
+#endif
+
+namespace util {
+
+bool
+cpu_supports_avx2()
+{
+ // CPUID with EAX=7 ECX=0 returns AVX2 support in bit 5 of EBX.
+ int registers[4]; // EAX, EBX, ECX, EDX
+#if defined(_MSC_VER) && defined(_M_X64)
+ __cpuidex(registers, 7, 0);
+#elif defined(HAVE_CPUID_H)
+ __cpuid_count(7, 0, registers[0], registers[1], registers[2], registers[3]);
+#elif __x86_64__
+ __asm__ __volatile__("cpuid"
+ : "=a"(registers[0]),
+ "=b"(registers[1]),
+ "=c"(registers[2]),
+ "=d"(registers[3])
+ : "a"(7), "c"(0));
+#else
+ registers[1] = 0;
+#endif
+ return registers[1] & (1 << 5);
+}
+
+} // namespace util
--- /dev/null
+// Copyright (C) 2024 Joel Rosdahl and other contributors
+//
+// See doc/AUTHORS.adoc for a complete list of contributors.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+#pragma once
+
+namespace util {
+
+// --- Interface ---
+
+bool cpu_supports_avx2();
+
+} // namespace util
-add_library(dep_blake3 STATIC blake3.c blake3_dispatch_ccache.c blake3_portable.c)
+add_library(dep_blake3 STATIC blake3.c blake3_dispatch.c blake3_portable.c)
target_include_directories(dep_blake3 INTERFACE "${CMAKE_SOURCE_DIR}/src/third_party/blake3")
target_link_libraries(dep_blake3 PRIVATE standard_settings)
+++ /dev/null
-#ifndef BLAKE3_CPU_SUPPORTS_AVX2_H
-#define BLAKE3_CPU_SUPPORTS_AVX2_H
-
-// This file is a ccache modification to BLAKE3
-
-#include <stdbool.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-bool blake3_cpu_supports_avx2();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-// This file is a ccache modification to BLAKE3
-
-#include "blake3_dispatch.c"
-
-#include "blake3_cpu_supports_avx2.h"
-
-bool blake3_cpu_supports_avx2()
-{
- return get_cpu_features() & AVX2;
-}