aboutsummaryrefslogtreecommitdiff
path: root/src/common/tuklib_integer.h (follow)
AgeCommit message (Collapse)AuthorFilesLines
2023-11-22tuklib_integer: Fix typo discovered by codespell.Jia Tan1-1/+1
Based on internet dictionary searches, 'choise' is an outdated spelling of 'choice'.
2023-10-18tuklib_integer: Revise unaligned reads and writes on strict-align archs.Lasse Collin1-67/+189
In XZ Utils context this doesn't matter much because unaligned reads and writes aren't used in hot code when TUKLIB_FAST_UNALIGNED_ACCESS isn't #defined.
2023-10-18tuklib_integer: Add missing write64be and write64le fallback functions.Lasse Collin1-0/+34
2023-05-04tuklib_integer.h: Reverts previous commit.Jia Tan1-2/+2
Previous commit 6be460dde07113fe3f08f814b61ddc3264125a96 would cause an error if the integer size was 32 bit.
2023-05-04tuklib_integer.h: Changes two other UINT_MAX == UINT32_MAX to >=.Jia Tan1-2/+2
2023-05-03tuklib_integer.h: Fix a recent copypaste error in Clang detection.Lasse Collin1-2/+2
Wrong line was changed in 7062348bf35c1e4cbfee00ad9fffb4a21aa6eff7. Also, this has >= instead of == since ints larger than 32 bits would work too even if not relevant in practice.
2023-04-19Windows: Include <intrin.h> when needed.Jia Tan1-0/+6
Legacy Windows did not need to #include <intrin.h> to use the MSVC intrinsics. Newer versions likely just issue a warning, but the MSVC documentation says to include the header file for the intrinsics we use. GCC and Clang can "pretend" to be MSVC on Windows, so extra checks are needed in tuklib_integer.h to only include <intrin.h> when it will is actually needed.
2023-04-19tuklib_integer: Use __builtin_clz() with Clang.Jia Tan1-3/+3
Clang has support for __builtin_clz(), but previously Clang would fallback to either the MSVC intrinsic or the regular C code. This was discovered due to a bug where a new version of Clang required the <intrin.h> header file in order to use the MSVC intrinsics. Thanks to Anton Kochkov for notifying us about the bug.
2022-10-05tuklib_integer: Add 64-bit endianness-converting reads and writes.Lasse Collin1-2/+44
Also update the comment in liblzma's memcmplen.h. Thanks to Michał Górny for the original patch for the reads.
2019-12-31Rename unaligned_read32ne to read32ne, and similarly for the others.Lasse Collin1-34/+30
2019-12-31Rename read32ne to aligned_read32ne, and similarly for the others.Lasse Collin1-28/+28
Using the aligned methods requires more care to ensure that the address really is aligned, so it's nicer if the aligned methods are prefixed. The next commit will remove the unaligned_ prefix from the unaligned methods which in liblzma are used in more places than the aligned ones.
2019-12-31Revise tuklib_integer.h and .m4.Lasse Collin1-217/+271
Add a configure option --enable-unsafe-type-punning to get the old non-conforming memory access methods. It can be useful with old compilers or in some other less typical situations but shouldn't normally be used. Omit the packed struct trick for unaligned access. While it's best in some cases, this is simpler. If the memcpy trick doesn't work, one can request unsafe type punning from configure. Because CRC32/CRC64 code needs fast aligned reads, if no very safe way to do it is found, type punning is used as a fallback. This sucks but since it currently works in practice, it seems to be the least bad option. It's never needed with GCC >= 4.7 or Clang >= 3.6 since these support __builtin_assume_aligned and thus fast aligned access can be done with the memcpy trick. Other things: - Support GCC/Clang __builtin_bswapXX - Cleaner bswap fallback macros - Minor cleanups
2019-06-23tuklib_integer: Silence warnings from -Wsign-conversion.Lasse Collin1-3/+3
2019-06-20tuklib_integer: Fix usage of conv macros.Lasse Collin1-4/+8
Use a temporary variable instead of e.g. conv32le(unaligned_read32ne(buf)) because the macro can evaluate its argument multiple times.
2019-06-01tuklib_integer: Cleanup MSVC-specific code.Lasse Collin1-11/+9
2019-06-01tuklib_integer: Improve unaligned memory access.Lasse Collin1-12/+168
Now memcpy() or GNU C packed structs for unaligned access instead of type punning. See the comment in this commit for details. Avoiding type punning with unaligned access is needed to silence gcc -fsanitize=undefined. New functions: unaliged_readXXne and unaligned_writeXXne where XX is 16, 32, or 64.
2018-01-10tuklib_integer: New Intel C compiler needs immintrin.h.Lasse Collin1-0/+11
Thanks to Melanie Blower (Intel) for the patch.
2015-02-03Add a few casts to tuklib_integer.h to silence possible warnings.Lasse Collin1-12/+12
I heard that Visual Studio 2013 gave warnings without the casts. Thanks to Gabi Davar.
2009-11-22Update tuklib_integer.h with bit scan functions.Lasse Collin1-8/+181
Thanks to Joachim Henke for the original patch.
2009-10-04Use a tuklib module for integer handling.Lasse Collin1-0/+350
This replaces bswap.h and integer.h. The tuklib module uses <byteswap.h> on GNU, <sys/endian.h> on *BSDs and <sys/byteorder.h> on Solaris, which may contain optimized code like inline assembly.