Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRC big endian support #97

Merged
merged 25 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/action@v0.24.0
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