diff --git a/.github/workflows/.aarch64.yml b/.github/workflows/.aarch64.yml index 63ac2d6..adc7bc0 100644 --- a/.github/workflows/.aarch64.yml +++ b/.github/workflows/.aarch64.yml @@ -9,7 +9,7 @@ on: jobs: archs: # The host should always be linux - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 name: Build on aarch64 steps: - uses: actions/checkout@v2.1.0 diff --git a/.github/workflows/.armv6.yml b/.github/workflows/.armv6.yml index ccc5bd2..747eebe 100644 --- a/.github/workflows/.armv6.yml +++ b/.github/workflows/.armv6.yml @@ -9,7 +9,7 @@ on: jobs: archs: # The host should always be linux - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 name: Build on armv6 steps: - uses: actions/checkout@v2.1.0 diff --git a/.github/workflows/.armv7.yml b/.github/workflows/.armv7.yml index decd5bd..f8ed4d7 100644 --- a/.github/workflows/.armv7.yml +++ b/.github/workflows/.armv7.yml @@ -9,7 +9,7 @@ on: jobs: archs: # The host should always be linux - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 name: Build on armv7 steps: - uses: actions/checkout@v2.1.0 diff --git a/.github/workflows/.ppc64le.yml b/.github/workflows/.ppc64le.yml index e8a857c..d520bbf 100644 --- a/.github/workflows/.ppc64le.yml +++ b/.github/workflows/.ppc64le.yml @@ -9,7 +9,7 @@ on: jobs: archs: # The host should always be linux - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 name: Build on ppc64le steps: - uses: actions/checkout@v2.1.0 diff --git a/.github/workflows/.s390x.yml b/.github/workflows/.s390x.yml index fd18b29..1174a12 100644 --- a/.github/workflows/.s390x.yml +++ b/.github/workflows/.s390x.yml @@ -9,7 +9,7 @@ on: jobs: archs: # The host should always be linux - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 name: Build on s390x steps: - uses: actions/checkout@v2.1.0 diff --git a/crc32/CMakeLists.txt b/crc32/CMakeLists.txt index df1158c..835ff7d 100644 --- a/crc32/CMakeLists.txt +++ b/crc32/CMakeLists.txt @@ -41,17 +41,19 @@ if (SC_BUILD_TEST) add_executable(${PROJECT_NAME}_test crc32_test.c sc_crc32.c) # detect x86 - check_c_compiler_flag(-msse4.2 HAVE_CRC32_HARDWARE) - if (${HAVE_CRC32_HARDWARE}) - if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") - message(STATUS "CPU have -msse4.2, defined HAVE_CRC32C") - target_compile_options(${PROJECT_NAME}_test PRIVATE -msse4.2) - target_compile_definitions(${PROJECT_NAME}_test PRIVATE -DHAVE_CRC32C) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") + check_c_compiler_flag(-msse4.2 HAVE_CRC32_HARDWARE) + if (${HAVE_CRC32_HARDWARE}) + if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + message(STATUS "CPU have -msse4.2, defined HAVE_CRC32C") + target_compile_options(${PROJECT_NAME}_test PRIVATE -msse4.2) + target_compile_definitions(${PROJECT_NAME}_test PRIVATE -DHAVE_CRC32C) + endif () endif () endif () # detect aarch64 - if (CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) + if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64|aarch64") message(STATUS "CPU = aarch64, defined HAVE_CRC32C, -march=armv8.1-a") target_compile_definitions(${PROJECT_NAME}_test PRIVATE -DHAVE_CRC32C) target_compile_options(${PROJECT_NAME}_test PRIVATE -march=armv8.1-a) diff --git a/crc32/README.md b/crc32/README.md index 2c1a444..35dbb67 100644 --- a/crc32/README.md +++ b/crc32/README.md @@ -3,7 +3,7 @@ - Same code from : https://stackoverflow.com/a/17646775 - Fixed some alignment issues, replaced asm code with compiler intrinsics - Added aarch64 hardware support -- Requires architecture and endianness detection, CMAKE example is : +- Requires architecture and endianness detection, CMAKE example is: ```cmake ## Cmake @@ -12,16 +12,21 @@ include(CheckCCompilerFlag) include (TestBigEndian) # Detect x86 and sse4.2 support -check_c_compiler_flag(-msse4.2 HAVE_CRC32_HARDWARE) -if (${HAVE_CRC32_HARDWARE}) - message(STATUS "CPU have -msse4.2, defined HAVE_CRC32C") - target_compile_options(${PROJECT_NAME}_test PRIVATE -msse4.2) - target_compile_definitions(${PROJECT_NAME}_test PRIVATE -DHAVE_CRC32C) +if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") + message(STATUS "System is x86_64") + check_c_compiler_flag(-msse4.2 HAVE_CRC32_HARDWARE) + if (${HAVE_CRC32_HARDWARE}) + if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + message(STATUS "CPU have -msse4.2, defined HAVE_CRC32C") + target_compile_options(${PROJECT_NAME}_test PRIVATE -msse4.2) + target_compile_definitions(${PROJECT_NAME}_test PRIVATE -DHAVE_CRC32C) + endif () + endif () endif () # Detect aarch64 and set march=armv8.1-a. armv7 doesn't have CRC32c instruction # so, armv7 will be unsupported with this flag. -if (CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) +if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64|aarch64") message(STATUS "CPU = aarch64, defined HAVE_CRC32C, -march=armv8.1-a") target_compile_definitions(${PROJECT_NAME}_test PRIVATE -DHAVE_CRC32C) target_compile_options(${PROJECT_NAME}_test PRIVATE -march=armv8.1-a) @@ -46,7 +51,7 @@ endif () int main(int argc, char *argv[]) { uint32_t crc; - const uint8_t buf[100] = {0}; + const char buf[100] = {0}; sc_crc32_init(); diff --git a/crc32/crc32_example.c b/crc32/crc32_example.c index b84ac8a..27a4590 100644 --- a/crc32/crc32_example.c +++ b/crc32/crc32_example.c @@ -5,7 +5,7 @@ int main(void) { uint32_t crc; - const uint8_t buf[100] = {0}; + const char buf[100] = {0}; sc_crc32_init(); diff --git a/crc32/crc32_test.c b/crc32/crc32_test.c index 491834a..63621e9 100644 --- a/crc32/crc32_test.c +++ b/crc32/crc32_test.c @@ -8,18 +8,17 @@ int main(int argc, char *argv[]) (void) argv; uint32_t crc1, crc2, crc3; - uint8_t buf[128] = {1, 1, 2, 3}; - uint8_t buf2[4096 * 8] = {2, 5, 6, 5}; + char buf[128] = {1, 1, 2, 3}; + char buf2[4096 * 8] = {2, 5, 6, 5}; sc_crc32_init(); // pre-computed values - assert(sc_crc32(0, (uint8_t *) "", 1) == 1383945041); - assert(sc_crc32(0, (uint8_t *) "1", 2) == 2727214374); - assert(sc_crc32(0, (uint8_t *) "\0\0\0\0\0\0\0\0\0\0", 10) == - 3822973035); - assert(sc_crc32(0, (uint8_t *) "test", 5) == 2440484327); - assert(sc_crc32(0, (uint8_t *) "testtest", 9) == 443192409); + assert(sc_crc32(0, "", 1) == 1383945041); + assert(sc_crc32(0, "1", 2) == 2727214374); + assert(sc_crc32(0, "\0\0\0\0\0\0\0\0\0\0", 10) == 3822973035); + assert(sc_crc32(0, "test", 5) == 2440484327); + assert(sc_crc32(0, "testtest", 9) == 443192409); crc1 = sc_crc32(0, buf, 100); crc2 = sc_crc32(crc1, buf + 100, 28); diff --git a/crc32/sc_crc32.c b/crc32/sc_crc32.c index 705a790..2e19860 100644 --- a/crc32/sc_crc32.c +++ b/crc32/sc_crc32.c @@ -170,7 +170,7 @@ static void crc32_init_hw(void) crc32_zeros(crc32c_short, CRC32_SHORT); } -uint32_t crc32_hw(uint32_t crc, const uint8_t *buf, uint32_t len) +uint32_t crc32_hw(uint32_t crc, const void *buf, size_t len) { const unsigned char *next = buf; const unsigned char *end; @@ -420,7 +420,7 @@ static uint32_t crc32_sw_be(uint32_t crc, const void *buf, size_t len) #endif // HAVE_BIG_ENDIAN #endif -uint32_t sc_crc32(uint32_t crc, const uint8_t *buf, uint32_t len) +uint32_t sc_crc32(uint32_t crc, const void *buf, size_t len) { #ifdef HAVE_CRC32C return crc32_hw(crc, buf, len); diff --git a/crc32/sc_crc32.h b/crc32/sc_crc32.h index dba16a5..3b30a5e 100644 --- a/crc32/sc_crc32.h +++ b/crc32/sc_crc32.h @@ -32,6 +32,7 @@ #ifndef SC_CRC32_H #define SC_CRC32_H +#include #include #define SC_CRC32_VERSION "2.0.0" @@ -48,6 +49,6 @@ void sc_crc32_init(void); * @param len len * @return crc value */ -uint32_t sc_crc32(uint32_t crc, const uint8_t *buf, uint32_t len); +uint32_t sc_crc32(uint32_t crc, const void *buf, size_t len); #endif