Skip to content

Commit d9ae033

Browse files
committed
switching to slee_q
1 parent 814fafb commit d9ae033

File tree

2 files changed

+92
-118
lines changed

2 files changed

+92
-118
lines changed

.github/workflows/big_endian.yml

Lines changed: 87 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Cross-platform testing for quaddtype on big-endian architectures using QEMU.
2-
# This workflow focuses specifically on big-endian systems to test byte order handling
3-
# in quad precision operations, since little-endian systems are already covered by standard CI.
4-
51
name: Big-Endian Architecture Tests
62

73
on:
@@ -35,14 +31,14 @@ jobs:
3531
- [
3632
"s390x (IBM Z Big Endian)",
3733
"s390x-linux-gnu",
38-
"s390x/ubuntu:22.04",
39-
"s390x"
34+
"s390x/ubuntu:22.04",
35+
"s390x",
4036
]
4137
- [
4238
"s390x - baseline(Z13)",
4339
"s390x-linux-gnu",
4440
"s390x/ubuntu:22.04",
45-
"s390x"
41+
"s390x",
4642
]
4743
env:
4844
ARCH_NAME: ${{ matrix.BUILD_PROP[0] }}
@@ -53,94 +49,94 @@ jobs:
5349

5450
name: "${{ matrix.BUILD_PROP[0] }}"
5551
steps:
56-
- uses: actions/checkout@v4
57-
with:
58-
submodules: recursive
59-
fetch-tags: true
60-
persist-credentials: false
61-
62-
- name: Initialize binfmt_misc for qemu-user-static
63-
run: |
64-
# Enable QEMU user-mode emulation for cross-architecture execution
65-
docker run --rm --privileged tonistiigi/binfmt:qemu-v9.2.2-52 --install all
52+
- uses: actions/checkout@v4
53+
with:
54+
submodules: recursive
55+
fetch-tags: true
56+
persist-credentials: false
6657

67-
- name: Install cross-compilation toolchain
68-
run: |
69-
sudo apt update
70-
sudo apt install -y ninja-build gcc-${TOOLCHAIN_NAME} g++-${TOOLCHAIN_NAME} gfortran-${TOOLCHAIN_NAME}
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
7162
72-
- name: Cache docker container
73-
uses: actions/cache@v4
74-
id: container-cache
75-
with:
76-
path: ~/docker_${{ matrix.BUILD_PROP[1] }}
77-
key: container-quaddtype-${{ runner.os }}-${{ matrix.BUILD_PROP[1] }}-${{ matrix.BUILD_PROP[2] }}-${{ hashFiles('quaddtype/pyproject.toml') }}
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}
7867
79-
- name: Create cross-compilation container
80-
if: steps.container-cache.outputs.cache-hit != 'true'
81-
run: |
82-
docker run --platform=linux/${ARCH} --name quaddtype_container --interactive \
83-
-v /:/host -v $(pwd):/workspace ${DOCKER_CONTAINER} /bin/bash -c "
84-
# Update package manager and install essential tools
85-
apt update &&
86-
apt install -y cmake git python3 python-is-python3 python3-dev python3-pip build-essential &&
87-
88-
# Create necessary symlinks for cross-compilation
89-
mkdir -p /lib64 && ln -sf /host/lib64/ld-* /lib64/ || true &&
90-
ln -sf /host/lib/x86_64-linux-gnu /lib/x86_64-linux-gnu || true &&
91-
92-
# Link cross-compilation toolchain from host
93-
rm -rf /usr/${TOOLCHAIN_NAME} && ln -sf /host/usr/${TOOLCHAIN_NAME} /usr/${TOOLCHAIN_NAME} &&
94-
rm -rf /usr/lib/gcc/${TOOLCHAIN_NAME} && ln -sf /host/usr/lib/gcc-cross/${TOOLCHAIN_NAME} /usr/lib/gcc/${TOOLCHAIN_NAME} &&
95-
96-
# Set up compiler symlinks
97-
rm -f /usr/bin/gcc && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-gcc /usr/bin/gcc &&
98-
rm -f /usr/bin/g++ && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-g++ /usr/bin/g++ &&
99-
rm -f /usr/bin/gfortran && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-gfortran /usr/bin/gfortran &&
100-
101-
# Set up binutils
102-
rm -f /usr/bin/ar && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-ar /usr/bin/ar &&
103-
rm -f /usr/bin/as && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-as /usr/bin/as &&
104-
rm -f /usr/bin/ld && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-ld /usr/bin/ld &&
105-
rm -f /usr/bin/ld.bfd && ln -sf /host/usr/bin/${TOOLCHAIN_NAME}-ld.bfd /usr/bin/ld.bfd &&
106-
107-
# Link build tools
108-
rm -f /usr/bin/ninja && ln -sf /host/usr/bin/ninja /usr/bin/ninja &&
109-
rm -f /usr/local/bin/ninja && mkdir -p /usr/local/bin && ln -sf /host/usr/bin/ninja /usr/local/bin/ninja &&
110-
111-
# Configure git for workspace access
112-
git config --global --add safe.directory /workspace &&
113-
114-
# Install Python build dependencies
115-
python -m pip install --upgrade pip &&
116-
python -m pip install meson>=1.3.2 meson-python wheel numpy &&
117-
python -m pip install pytest pytest-run-parallel pytest-timeout &&
118-
119-
# Install system dependencies for quaddtype (SLEEF dependencies)
120-
apt install -y libssl-dev libfftw3-dev pkg-config
121-
"
122-
docker commit quaddtype_container quaddtype_container
123-
mkdir -p "~/docker_${TOOLCHAIN_NAME}"
124-
docker save -o "~/docker_${TOOLCHAIN_NAME}/quaddtype_container.tar" quaddtype_container
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') }}
12574

126-
- name: Load container from cache
127-
if: steps.container-cache.outputs.cache-hit == 'true'
128-
run: docker load -i "~/docker_${TOOLCHAIN_NAME}/quaddtype_container.tar"
129-
130-
- name: Build quaddtype with cross-compilation and testing
131-
run: |
132-
docker run --rm --platform=linux/${ARCH} -e "TERM=xterm-256color" \
133-
-v $(pwd):/workspace -v /:/host quaddtype_container \
134-
/bin/script -e -q -c "/bin/bash --noprofile --norc -eo pipefail -c '
135-
cd /workspace/quaddtype &&
136-
echo \"Building quaddtype for ${ARCH_NAME}...\" &&
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} &&
13791
138-
# Set OpenMP linking for cross-compilation
139-
export LDFLAGS=\"-fopenmp\" &&
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 &&
14096
141-
# Install quaddtype with test dependencies
142-
python -m pip install .[test] -v --no-build-isolation --force-reinstall
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 &&
143102
144-
cd ..
145-
python -m pytest -vvv --color=yes --timeout=600 --tb=short quaddtype/tests/
146-
'"
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/quaddtype_main.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,6 @@ py_is_longdouble_128(PyObject *self, PyObject *args)
3131
}
3232
}
3333

34-
#ifdef SLEEF_QUAD_C
35-
static const Sleef_quad SMALLEST_SUBNORMAL_VALUE = SLEEF_QUAD_DENORM_MIN;
36-
#else
37-
static const union {
38-
struct {
39-
#if NPY_BYTE_ORDER == NPY_BIG_ENDIAN
40-
uint64_t high;
41-
uint64_t low;
42-
#elif NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN
43-
uint64_t low;
44-
uint64_t high;
45-
#else
46-
#error "Unknown endianness - NPY_BYTE_ORDER not properly defined"
47-
#endif
48-
} parts;
49-
Sleef_quad value;
50-
} smallest_subnormal_const = {
51-
.parts = {
52-
.low = 0x0000000000000001ULL,
53-
.high = 0x0000000000000000ULL
54-
}
55-
};
56-
57-
#define SMALLEST_SUBNORMAL_VALUE (smallest_subnormal_const.value)
58-
#endif
59-
6034
static PyObject *
6135
get_sleef_constant(PyObject *self, PyObject *args)
6236
{
@@ -98,7 +72,11 @@ get_sleef_constant(PyObject *self, PyObject *args)
9872
result->value.sleef_value = SLEEF_QUAD_MIN;
9973
}
10074
else if (strcmp(constant_name, "smallest_subnormal") == 0) {
101-
result->value.sleef_value = SMALLEST_SUBNORMAL_VALUE;
75+
#ifdef SLEEF_QUAD_C
76+
result->value.sleef_value = SLEEF_QUAD_DENORM_MIN;
77+
#else
78+
result->value.sleef_value = sleef_q(+0x0000000000000LL, 0x0000000000000001ULL, -16383);
79+
#endif
10280
}
10381
else if (strcmp(constant_name, "bits") == 0) {
10482
Py_DECREF(result);

0 commit comments

Comments
 (0)