Skip to content

Commit

Permalink
CRC big endian support (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin authored Oct 29, 2024
1 parent 1fa3f2d commit b23b2e2
Show file tree
Hide file tree
Showing 7 changed files with 663 additions and 23 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ jobs:
id: test
uses: cross-platform-actions/[email protected]
with:
#note: sanitizer seems to be broken on s390x (fails trying to allocate several tbs of mem) and package manager works slightly differently that on regular ubuntu
operating_system: freebsd
architecture: x86-64
version: '14.0'
Expand All @@ -243,6 +244,30 @@ jobs:
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }}
s390x: #big-endian
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: uraimo/run-on-arch-action@v2
name: Run commands
id: runcmd
with:
arch: s390x
distro: ubuntu22.04
install: |
apt-get update -q -y
apt-get -y install sudo
apt-get -y install cmake
apt-get -y install make
apt-get -y install g++
apt-get -y install python3
apt-get -y install git
run: |
lscpu | grep Endian
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }} --variant s390x --cmake-extra=-DENABLE_SANITIZERS=OFF
openbsd:
runs-on: ubuntu-24.04 # latest
strategy:
Expand Down
12 changes: 11 additions & 1 deletion builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,15 @@
"test_steps": [
"test",
"{install_dir}/bin/checksum-profile{exe}"
]
],

"variants": {
"s390x": {
"hosts": {
"ubuntu": {
"!pkg_setup": []
}
}
}
}
}
36 changes: 36 additions & 0 deletions include/aws/checksums/private/crc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* SPDX-License-Identifier: Apache-2.0.
*/

#include <aws/common/byte_order.h>
#include <aws/common/stdint.h>
#include <limits.h>
#include <stdlib.h>

#define large_buffer_apply_impl(Name, T) \
static T aws_large_buffer_apply_##Name( \
Expand All @@ -21,4 +23,38 @@
return val; \
}

/* helper function to reverse byte order on big-endian platforms*/
static inline uint32_t aws_bswap32_if_be(uint32_t x) {
if (!aws_is_big_endian()) {
return x;
}

#if _MSC_VER
return _byteswap_ulong(x);
#elif defined(__GNUC__) || defined(__clang__)
return __builtin_bswap32(x);
#else
return (
((x & 0xff000000u) >> 24) | ((x & 0x00ff0000u) >> 8) | ((x & 0x0000ff00u) << 8) | ((x & 0x000000ffu) << 24));
#endif
}

/* Reverse the bytes in a 64-bit word. */
static inline uint64_t aws_bswap64_if_be(uint64_t x) {
if (!aws_is_big_endian()) {
return x;
}

#if _MSC_VER
return _byteswap_uint64(x);
#elif defined(__GNUC__) || defined(__clang__)
return __builtin_bswap64(x);
#else
return ((x << 56) & 0xff00000000000000ULL) | ((x << 40) & 0x00ff000000000000ULL) |
((x << 24) & 0x0000ff0000000000ULL) | ((x << 8) & 0x000000ff00000000ULL) |
((x >> 8) & 0x00000000ff000000ULL) | ((x >> 24) & 0x0000000000ff0000ULL) |
((x >> 40) & 0x000000000000ff00ULL) | ((x >> 56) & 0x00000000000000ffULL);
#endif
}

#endif /* AWS_CHECKSUMS_PRIVATE_CRC_UTIL_H */
Loading

0 comments on commit b23b2e2

Please sign in to comment.