Skip to content

Commit

Permalink
Switch from XXH64 to XXH3 for checksums (ccache#657)
Browse files Browse the repository at this point in the history
The latter promises better performance and supports automatic use of vector
instructions where appropriate.
  • Loading branch information
erijo authored Sep 10, 2020
1 parent f4194dd commit 5ca001a
Show file tree
Hide file tree
Showing 14 changed files with 5,530 additions and 1,218 deletions.
10 changes: 4 additions & 6 deletions LICENSE.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,15 @@ SOFTWARE.
-------------------------------------------------------------------------------
src/third_party/xxhash.[hc]
src/third_party/xxh(ash|_x86dispatch).[hc]
~~~~~~~~~~~~~~~~~~~~~~~~~~~
xxHash - Extremely Fast Hash algorithm. Copied from xxHash v0.6.5 downloaded
xxHash - Extremely Fast Hash algorithm. Copied from xxHash v0.8.0 downloaded
from <https://github.com/Cyan4973/xxHash/releases>.
-------------------------------------------------------------------------------
Copyright (C) 2012-2016, Yann Collet.
Copyright (c) 2012-2020 Yann Collet
All rights reserved.
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
Expand All @@ -301,9 +302,6 @@ from <https://github.com/Cyan4973/xxHash/releases>.
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
You can contact the author at :
- xxHash source repository : https://github.com/Cyan4973/xxHash
-------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions doc/MANUAL.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Options for scripting or debugging

*`--checksum-file`* _PATH_::

Print the checksum (64 bit XXH64) of the file at _PATH_.
Print the checksum (64 bit XXH3) of the file at _PATH_.

*`--dump-manifest`* _PATH_::

Expand Down Expand Up @@ -998,7 +998,7 @@ compilation and then using the hash sum to identify the cached output. ccache
uses BLAKE3, a very fast cryptographic hash algorithm, for the hashing. On a
cache hit, ccache is able to supply all of the correct compiler outputs
(including all warnings, dependency file, etc) from the cache. Data stored in
the cache is checksummed with XXH64, an extremely fast non-cryptographic
the cache is checksummed with XXH3, an extremely fast non-cryptographic
algorithm, to detect corruption.

ccache has two ways of gathering information used to look up results in the
Expand Down
2 changes: 1 addition & 1 deletion doc/NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ High-level summary of changes (work in progress)
- BLAKE3 is now used instead of MD4 for hashing input.
- Added checksumming of result files using XXH64 to detect data corruption.
- Added checksumming of result files using XXH3 to detect data corruption.
- Made the hard link mode less error prone.
Expand Down
18 changes: 11 additions & 7 deletions src/Checksum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

#include "system.hpp"

#include "third_party/xxhash.h"
#ifdef USE_XXH_DISPATCH
# include "third_party/xxh_x86dispatch.h"
#else
# include "third_party/xxhash.h"
#endif

class Checksum
{
Expand All @@ -33,33 +37,33 @@ class Checksum
uint64_t digest() const;

private:
XXH64_state_t* m_state;
XXH3_state_t* m_state;
};

inline Checksum::Checksum() : m_state(XXH64_createState())
inline Checksum::Checksum() : m_state(XXH3_createState())
{
reset();
}

inline Checksum::~Checksum()
{
XXH64_freeState(m_state);
XXH3_freeState(m_state);
}

inline void
Checksum::reset()
{
XXH64_reset(m_state, 0);
XXH3_64bits_reset(m_state);
}

inline void
Checksum::update(const void* data, size_t length)
{
XXH64_update(m_state, data, length);
XXH3_64bits_update(m_state, data, length);
}

inline uint64_t
Checksum::digest() const
{
return XXH64_digest(m_state);
return XXH3_64bits_digest(m_state);
}
2 changes: 1 addition & 1 deletion src/Manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
// <include_index> ::= uint32_t
// <name> ::= Digest::size() bytes
// <epilogue> ::= <checksum>
// <checksum> ::= uint64_t ; XXH64 of content bytes
// <checksum> ::= uint64_t ; XXH3 of content bytes
//
// Sketch of concrete layout:

Expand Down
2 changes: 1 addition & 1 deletion src/Result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
// <raw_file_marker> ::= 1 (uint8_t)
// <file_len> ::= uint64_t
// <epilogue> ::= <checksum>
// <checksum> ::= uint64_t ; XXH64 of content bytes
// <checksum> ::= uint64_t ; XXH3 of content bytes
//
// Sketch of concrete layout:
//
Expand Down
2 changes: 1 addition & 1 deletion src/ccache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Common options:
-V, --version print version and copyright information
Options for scripting or debugging:
--checksum-file PATH print the checksum (64 bit XXH64) of the file at
--checksum-file PATH print the checksum (64 bit XXH3) of the file at
PATH
--dump-manifest PATH dump manifest file at PATH in text format
--dump-result PATH dump result file at PATH in text format
Expand Down
23 changes: 23 additions & 0 deletions src/third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@ if(ENABLE_TRACING)
target_sources(third_party_lib PRIVATE minitrace.c)
endif()

set(xxhdispatchtest [=[
#include "xxh_x86dispatch.c"

int main()
{
XXH3_64bits_dispatch("foo", 3);
return 1;
}
]=])

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/xxhdispatchtest.c" "${xxhdispatchtest}")

try_compile(USE_XXH_DISPATCH ${CMAKE_CURRENT_BINARY_DIR}
"${CMAKE_CURRENT_BINARY_DIR}/xxhdispatchtest.c"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CMAKE_CURRENT_SOURCE_DIR}"
COMPILE_DEFINITIONS "-DXXH_STATIC_LINKING_ONLY")

target_compile_definitions(third_party_lib INTERFACE "-DXXH_STATIC_LINKING_ONLY")
if(USE_XXH_DISPATCH)
target_sources(third_party_lib PRIVATE xxh_x86dispatch.c)
target_compile_definitions(third_party_lib INTERFACE "-DUSE_XXH_DISPATCH")
endif()

# Treat third party headers as system files (no warning for those headers).
target_include_directories(
third_party_lib
Expand Down
Loading

0 comments on commit 5ca001a

Please sign in to comment.