2 softfloat and softposit in Python
3 * support for softfloat float16, float32, and float64
4 * support for softposit posit8, quire8, posit16, and quire16
11 ## Building (on Linux x86_64, with bash)
13 ### Python Environment
14 First, make sure a virtual environment is set up with Cython and twine:
18 $ source .env/bin/activate
19 (.env) $ pip install --upgrade -r requirements.txt
25 Compile the Cython extensions to C:
28 (.env) $ cython sfpy/*.pyx
33 The extension module depends on the softposit and softfloat static libraries.
34 They can be built with the following:
37 (.env) $ (cd SoftPosit/build/Linux-x86_64-GCC/; make clean; make)
39 (.env) $ (cd berkeley-softfloat-3/build/Linux-x86_64-GCC/; make clean; make)
44 Note that some changes are needed to the Makefiles so that the libraries are
45 compiled with the correct options. Both libraries need to use -fPIC, and
46 SoftPosit may need -std=c99 to work on older versions of GCC. See the
50 The extension modules can be built in place in the usual way:
53 (.env) $ python setup.py build_ext --inplace
58 A local wheel (compatible with the python version installed in the virtual
59 environment) can be built with the following:
62 (.env) $ python setup.py bdist_wheel
67 The local wheel will be created in the dist/ directory. This is the recommended
68 way to install the package when building it from source locally:
71 $ pip install dist/sfpy*.whl
74 >>> from sfpy import *
80 ### Building manylinux1 wheels for distribution
81 Widely compatible linux wheels can be built with the help of PyPA's manylinux
82 docker image. This requires that Docker is installed, and that the host can pull
83 the proper docker image.
85 To build the manylinux wheels, run:
88 $ sudo docker run -u $(id -u) --rm -v `pwd`:/io quay.io/pypa/manylinux1_x86_64 /io/docker-build-wheels.sh
93 This will create a set of manylinux1 wheel files in the wheelhouse/ directory.
95 The docker build will make its own static libraries as part of the build process,
96 and delete any existing static libraries with `make clean`.
98 The wheels can be uploaded to PyPI (if you're the package maintainer) with
101 (.env) $ twine upload --repository-url https://test.pypi.org/legacy/ wheelhouse/*
106 to test on test PyPI, or
109 (.env) $ twine upload wheelhouse/*
116 ### Makefile customizations
117 The Makefiles used to build the static libraries need a few small tweaks to
118 make sure that all the right flags are given to gcc. The changes are shown
119 in the following diffs.
121 SoftPosit/build/Linux-x86_64/Makefile
124 diff --git a/build/Linux-x86_64-GCC/Makefile b/build/Linux-x86_64-GCC/Makefile
125 index 4409e43..46bb877 100644
126 --- a/build/Linux-x86_64-GCC/Makefile
127 +++ b/build/Linux-x86_64-GCC/Makefile
128 @@ -60,9 +60,9 @@ LINK_PYTHON = \
131 C_INCLUDES = -I. -I$(SOURCE_DIR)/$(SPECIALIZE_TYPE) -I$(SOURCE_DIR)/include
132 -OPTIMISATION = -march=core-avx2 -O2
133 +OPTIMISATION = -fPIC -O2 ^M
135 - gcc -c -Werror-implicit-function-declaration -DSOFTPOSIT_FAST_INT64 \
136 + gcc -std=c99 -c -Werror-implicit-function-declaration -DSOFTPOSIT_FAST_INT64 \^M
137 $(SOFTPOSIT_OPTS) $(C_INCLUDES) $(OPTIMISATION) \
142 berkeley-softfloat-3/build/Linux-x86_64/Makefile
145 diff --git a/build/Linux-x86_64-GCC/Makefile b/build/Linux-x86_64-GCC/Makefile
146 index 2ee5dad..b175964 100644
147 --- a/build/Linux-x86_64-GCC/Makefile
148 +++ b/build/Linux-x86_64-GCC/Makefile
149 @@ -45,7 +45,7 @@ DELETE = rm -f
150 C_INCLUDES = -I. -I$(SOURCE_DIR)/$(SPECIALIZE_TYPE) -I$(SOURCE_DIR)/include
152 gcc -c -Werror-implicit-function-declaration -DSOFTFLOAT_FAST_INT64 \
153 - $(SOFTFLOAT_OPTS) $(C_INCLUDES) -O2 -o $@
154 + $(SOFTFLOAT_OPTS) $(C_INCLUDES) -O2 -fPIC -o $@