Skip to content

Commit

Permalink
Use __attribute__ ((target("crc32"))) for hw CRC32c function
Browse files Browse the repository at this point in the history
Mark the x86 hardware CRC32c function with `__attribute__
((target("crc32")))` on GCC and compatible compilers.  This makes it
possible to compile the project without explicit `-msse4.2`.
This should work with GCC 4.9.0+ and Clang 3.8+ (roughly confirmed
via godbolt.org).
  • Loading branch information
mgorny committed Feb 27, 2024
1 parent ff7e917 commit ea02db3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions crc32c_adler.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@

#if defined(IS_INTEL)

#if defined(__GNUC__)
# define ATTR_CRC32 __attribute__ ((target("sse4.2")))
#else
# define ATTR_CRC32
#endif

/*
* MSVC/icc don't have __builtin_ia32_crc32_* functions. Instead they have
* the _mm_crc32_* intrinsics, which accomplish the same at the end of the day
Expand Down Expand Up @@ -203,7 +209,7 @@ void crc32c_init_hw_adler( void )
#endif

/* Compute CRC-32C using the Intel hardware instruction. */
uint32_t _crc32c_hw_adler(uint32_t crc, const unsigned char *buf, unsigned long len)
ATTR_CRC32 uint32_t _crc32c_hw_adler(uint32_t crc, const unsigned char *buf, unsigned long len)
{
const unsigned char *next = buf;
const unsigned char *end;
Expand Down Expand Up @@ -344,4 +350,4 @@ uint32_t _crc32c_hw_adler(uint32_t crc, const unsigned char *buf, unsigned long
return ( uint32_t ) crc32bit;
}

#endif // defined(IS_INTEL)
#endif // defined(IS_INTEL)

0 comments on commit ea02db3

Please sign in to comment.