Skip to content

Commit c4c1def

Browse files
authored
Merge pull request #152 from SwayamInSync/big-endian-ci
CI: Adding and testing Big-Endian support for quaddtype
2 parents 0397aa2 + 19231fc commit c4c1def

File tree

3 files changed

+148
-1
lines changed

3 files changed

+148
-1
lines changed

.github/workflows/big_endian.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Big-Endian Architecture Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- "quaddtype/**"
9+
- ".github/workflows/**"
10+
workflow_dispatch:
11+
12+
defaults:
13+
run:
14+
shell: bash
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
18+
cancel-in-progress: true
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
big_endian_tests:
25+
runs-on: ubuntu-22.04
26+
continue-on-error: true
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
BUILD_PROP:
31+
- [
32+
"s390x (IBM Z Big Endian)",
33+
"s390x-linux-gnu",
34+
"s390x/ubuntu:22.04",
35+
"s390x",
36+
]
37+
- [
38+
"s390x - baseline(Z13)",
39+
"s390x-linux-gnu",
40+
"s390x/ubuntu:22.04",
41+
"s390x",
42+
]
43+
env:
44+
ARCH_NAME: ${{ matrix.BUILD_PROP[0] }}
45+
TOOLCHAIN_NAME: ${{ matrix.BUILD_PROP[1] }}
46+
DOCKER_CONTAINER: ${{ matrix.BUILD_PROP[2] }}
47+
ARCH: ${{ matrix.BUILD_PROP[3] }}
48+
TERM: xterm-256color
49+
50+
name: "${{ matrix.BUILD_PROP[0] }}"
51+
steps:
52+
- uses: actions/checkout@v4
53+
with:
54+
submodules: recursive
55+
fetch-tags: true
56+
persist-credentials: false
57+
58+
- name: Initialize binfmt_misc for qemu-user-static
59+
run: |
60+
# Enable QEMU user-mode emulation for cross-architecture execution
61+
docker run --rm --privileged tonistiigi/binfmt:qemu-v9.2.2-52 --install all
62+
63+
- name: Install cross-compilation toolchain
64+
run: |
65+
sudo apt update
66+
sudo apt install -y ninja-build gcc-${TOOLCHAIN_NAME} g++-${TOOLCHAIN_NAME} gfortran-${TOOLCHAIN_NAME}
67+
68+
- name: Cache docker container
69+
uses: actions/cache@v4
70+
id: container-cache
71+
with:
72+
path: ~/docker_${{ matrix.BUILD_PROP[1] }}
73+
key: container-quaddtype-${{ runner.os }}-${{ matrix.BUILD_PROP[1] }}-${{ matrix.BUILD_PROP[2] }}-${{ hashFiles('quaddtype/pyproject.toml') }}
74+
75+
- name: Create cross-compilation container
76+
if: steps.container-cache.outputs.cache-hit != 'true'
77+
run: |
78+
docker run --platform=linux/${ARCH} --name quaddtype_container --interactive \
79+
-v /:/host -v $(pwd):/workspace ${DOCKER_CONTAINER} /bin/bash -c "
80+
# Update package manager and install essential tools
81+
apt update &&
82+
apt install -y cmake git python3 python-is-python3 python3-dev python3-pip build-essential &&
83+
84+
# Create necessary symlinks for cross-compilation
85+
mkdir -p /lib64 && ln -sf /host/lib64/ld-* /lib64/ || true &&
86+
ln -sf /host/lib/x86_64-linux-gnu /lib/x86_64-linux-gnu || true &&
87+
88+
# Link cross-compilation toolchain from host
89+
rm -rf /usr/${TOOLCHAIN_NAME} && ln -sf /host/usr/${TOOLCHAIN_NAME} /usr/${TOOLCHAIN_NAME} &&
90+
rm -rf /usr/lib/gcc/${TOOLCHAIN_NAME} && ln -sf /host/usr/lib/gcc-cross/${TOOLCHAIN_NAME} /usr/lib/gcc/${TOOLCHAIN_NAME} &&
91+
92+
# Set up compiler symlinks
93+
rm -f /usr/bin/gcc && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-gcc /usr/bin/gcc &&
94+
rm -f /usr/bin/g++ && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-g++ /usr/bin/g++ &&
95+
rm -f /usr/bin/gfortran && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-gfortran /usr/bin/gfortran &&
96+
97+
# Set up binutils
98+
rm -f /usr/bin/ar && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-ar /usr/bin/ar &&
99+
rm -f /usr/bin/as && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-as /usr/bin/as &&
100+
rm -f /usr/bin/ld && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-ld /usr/bin/ld &&
101+
rm -f /usr/bin/ld.bfd && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-ld.bfd /usr/bin/ld.bfd &&
102+
103+
# Link build tools
104+
rm -f /usr/bin/ninja && ln -sf /host/usr/bin/ninja /usr/bin/ninja &&
105+
rm -f /usr/local/bin/ninja && mkdir -p /usr/local/bin && ln -sf /host/usr/bin/ninja /usr/local/bin/ninja &&
106+
107+
# Configure git for workspace access
108+
git config --global --add safe.directory /workspace &&
109+
110+
# Install Python build dependencies
111+
python -m pip install --upgrade pip &&
112+
python -m pip install meson>=1.3.2 meson-python wheel numpy &&
113+
python -m pip install pytest pytest-run-parallel pytest-timeout &&
114+
115+
# Install system dependencies for quaddtype (SLEEF dependencies)
116+
apt install -y libssl-dev libfftw3-dev pkg-config
117+
"
118+
docker commit quaddtype_container quaddtype_container
119+
mkdir -p "~/docker_${TOOLCHAIN_NAME}"
120+
docker save -o "~/docker_${TOOLCHAIN_NAME}/quaddtype_container.tar" quaddtype_container
121+
122+
- name: Load container from cache
123+
if: steps.container-cache.outputs.cache-hit == 'true'
124+
run: docker load -i "~/docker_${TOOLCHAIN_NAME}/quaddtype_container.tar"
125+
126+
- name: Build quaddtype with cross-compilation and testing
127+
run: |
128+
docker run --rm --platform=linux/${ARCH} -e "TERM=xterm-256color" \
129+
-v $(pwd):/workspace -v /:/host quaddtype_container \
130+
/bin/script -e -q -c "/bin/bash --noprofile --norc -eo pipefail -c '
131+
cd /workspace/quaddtype &&
132+
echo \"Building quaddtype for ${ARCH_NAME}...\" &&
133+
134+
# Set OpenMP linking for cross-compilation
135+
export LDFLAGS=\"-fopenmp\" &&
136+
137+
# Install quaddtype with test dependencies
138+
python -m pip install .[test] -v --no-build-isolation --force-reinstall
139+
140+
cd ..
141+
python -m pytest -vvv --color=yes --timeout=600 --tb=short quaddtype/tests/
142+
'"

quaddtype/numpy_quaddtype/src/dragon4.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,8 +1885,13 @@ Dragon4_PrintFloat_Sleef_quad(Sleef_quad *value, Dragon4_Options *opt)
18851885
union {
18861886
Sleef_quad q;
18871887
struct {
1888+
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
1889+
npy_uint64 hi;
1890+
npy_uint64 lo;
1891+
#else
18881892
npy_uint64 lo;
18891893
npy_uint64 hi;
1894+
#endif
18901895
} i;
18911896
} u;
18921897
u.q = *value;

quaddtype/numpy_quaddtype/src/quaddtype_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ py_is_longdouble_128(PyObject *self, PyObject *args)
3333
#ifdef SLEEF_QUAD_C
3434
static const Sleef_quad SMALLEST_SUBNORMAL_VALUE = SLEEF_QUAD_DENORM_MIN;
3535
#else
36-
// Use the exact same struct layout as the original buggy code
3736
static const union {
3837
struct {
3938
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
@@ -94,6 +93,7 @@ get_sleef_constant(PyObject *self, PyObject *args)
9493
result->value.sleef_value = SLEEF_QUAD_MIN;
9594
}
9695
else if (strcmp(constant_name, "smallest_subnormal") == 0) {
96+
// or just use sleef_q(+0x0000000000000LL, 0x0000000000000001ULL, -16383);
9797
result->value.sleef_value = SMALLEST_SUBNORMAL_VALUE;
9898
}
9999
else if (strcmp(constant_name, "bits") == 0) {

0 commit comments

Comments
 (0)