-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logarithmic number system bug fixes (#299)
* bumping SEMVER to v3.58 * adding lns performance baseline * adding dynamic range API to LNS * adding special values constexpr constructor to lns * Fix posit8_str C API declaration/definition mismatch Fixes a warning (gcc12): c_api/pure_c/posit/posit8.c:43:23: warning: argument 1 of type ‘char *’ declared as a pointer [-Warray-parameter=] 43 | void posit8_str(char* str, posit8_t a) include/universal/number/posit/posit_c_macros.h:90:29: note: previously declared as an array ‘char[static 16]’ 90 | void POSIT_MKNAME(str)(char out[static POSIT_MKNAME(str_SIZE)], POSIT_T p); * Fix missing <cstring> include for paranoia.c strrchr The missing #include breaks the build (on gcc12) * Simplify clear() *this = {} copy-assign a default constructed object * Reduce repetitive array code with variadics The blocksignificant(raw,radixPoint) constructor, and the significant_ull() member function were using constexpr-if chains to initialize or read from array elements. Variadic template expansion reduces the code size and the chances of cut-n-paste errors between the different-size code blocks. It does however increase the logic complexity (and compile time). Using std::index_sequence<I...> to deduce I.. requires two stages; a variadic helper constructor is added and delegated to while the significant_ull member function does a recursive bootstrap. * Apply noexcept consistently Universal has a lot of noexcept spec functions, and that seems the right decision for a provider of low level types. The noexcept usage in this blocksignificant file was inconsistent, so I made it more consistent by adding noexcept in most places, apart from on the division functions in case divide by zero is defined as throwing in future. * Remove inline specifier from member functions defined in class They're implicitly inline when defined in-line. Note that the inline spec is left on the free function defined at the end of the file (twosComplementFree) because it is needed there. * Add more constexpr, for consistency * Make more friends, make them public and hidden There were some private friend declarations at the end of the class definition, then the definitions were free function templates. I removed the private label, making them public, and brought the definitions inline, also bringing in other free operators that were not declared inline. * Add missing template disambiguator Stops GCC 12 warnings * Silence type-punning warning GCC warning: dereferencing type-punned pointer will break strict-aliasing rules on e.g. uint32_t f(float f) { return *(uint32_t*)&f; } Silenced by using a union instead. * Add initializers to silence uninitialized warnings These are all due to type_tag(x) implementations that access their argument x. Ironically, it looks like these were modified at some point to access their argument in order to silence warnings about 'unused formal parameter'; a fix for that should be to remove the formal parameter name (and its superfluous use) - I'll do a PR. * Remove type_tag formal arg name, and its use The type_tag(x) overload implementations deduce their argument type: template <typename X> string type_tag(X x); or template <typename X> string type_tag(X const& x); The formal argument x shouldn't be used; only its type X is pertinent. The declarations should drop the name: template <typename X> string type_tag(X); An alternative signature then takes no argument; convenient when there is no variable to use so it saves declaring one uneccesarily: template <typename X> string type_tag(); Here the type cannot be deduced so must be provided: type_tag<X>(). The two overloads can be combined into a one with a default argument: template <typename X> string type_tag(X = {}); (assuming that X is default constructible). Note that type_tag should really be a constexpr function (or a variable template, or a type trait) because it deals only with types. However, relying on C++ runtime typeinfo disallows any compile-time definition, as does returning std::string (and implementing with stringstream). If the signature is changed to return a 'constexpr string' type then I can PR a constexpr type_tag implementation. * adding MSC guard to specialize posit8_str for vc++ * Comment out unused retval variable Looks like it should've been commented out in recent change "cleaning up blocktriple regression tests to reduce output" which commented out retval's useage. Commenting out rather than removing because there's a TODO. (Third time I've prepared this change, it keeps getting lost.) (I think this is the last of the non _block related warnings.) * completing classify regression test * gcc fix for missing fpclassify declaration * WIP: debugging fmod behavior: it appears to use double precision math * bit_cast polyfill, detects and uses std, builtin or non-builtin C++20 introduced std::bit_cast, with clang, gcc and msvc implementing it with a builtin, __builtin_bit_cast(T,v), portable between compilers and available in < c++20 language modes. If compiler-provided constexpr-capable bit_cast is detected it's used, otherwise this header defines a non-constexpr bit_cast, useful as a UB-free alternative to 'type-punning', for trivially copyable types. The BIT_CAST_CONSTEXPR preprocessor symbol is defined as constexpr if sw::bit_cast is constexpr, otherwise it's defined as empty, allowing clients to propagate constexpr on functions that depend on bit_cast, and BIT_CAST_IS_CONSTEXPR symbol is defined as true or false. The earlier BIT_CAST_SUPPORT, and related CONSTEXRESSION, symbols are now redundant and can be deprecated. * removing unused files * adding dev containers for different gcc compilers * adding MSVC compiler flag to enable latest C++20 features * redesigning the lerp function include * WIP: creating a common arithmetic behavior configuration enum * adding negation to lns and streamlining arithmetic type testing * forgot to make lns negation operator-() constexpr Co-authored-by: Will Wray <[email protected]>
- Loading branch information
1 parent
3504810
commit f2b3345
Showing
60 changed files
with
1,772 additions
and
631 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"image": "stillwater/universal:gcc11.builder" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"image": "stillwater/universal:gcc9.builder" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# | ||
# multi-stage build | ||
# docker build --target builder -t stillwater/universal:builder will just build a builder container | ||
# docker build --target release -t stillwater/universal:release will just build a release container | ||
|
||
# BUILDER stage | ||
FROM stillwater/universal:gcc11.builder as builder | ||
LABEL Theodore Omtzigt | ||
ARG target=BUILD_ALL | ||
|
||
# make certain you have a good .dockerignore file installed so that this layer isn't ginormous | ||
COPY --chown=stillwater:stillwater . /home/stillwater/universal | ||
# print contextual information of the container at this state for visual inspection | ||
RUN ls -la /home/stillwater/universal && cmake -version | ||
|
||
# set up the cmake/make environment to issue the build commands | ||
RUN mkdir -p /home/stillwater/universal/build | ||
WORKDIR /home/stillwater/universal/build | ||
# test RUN statement to drive CI testing. ARG target provides override. | ||
# default is SANITY regression level: -DBUILD_REGRESSION_LEVEL_[1,2,3,4]=ON | ||
# or -DBUILD_REGRESSION_STRESS=ON for stress testing | ||
RUN cmake -D$target=ON -DBUILD_CMD_LINE_TOOLS=ON -DBUILD_DEMONSTRATION=OFF .. && make | ||
|
||
# the command 'make test' is run as part of the CI test pipeline of the release container | ||
|
||
|
||
# RELEASE stage | ||
#FROM alpine:latest as release # hitting a segfault during startup of some playground programs | ||
#FROM debian:buster-slim as release | ||
FROM ubuntu:20.04 as release | ||
LABEL Theodore Omtzigt | ||
|
||
#RUN apk add --no-cache libc6-compat libstdc++ cmake make bash gawk sed grep bc coreutils | ||
RUN apt-get update && apt-get update -y && apt-get install -y --no-install-recommends \ | ||
make \ | ||
&& apt-get clean | ||
# create and use user stillwater | ||
RUN useradd -ms /bin/bash stillwater | ||
USER stillwater | ||
|
||
# copy cmake enviroment needed for testing | ||
COPY --from=builder /usr/local/bin/cmake /usr/local/bin/ | ||
COPY --from=builder /usr/local/bin/ctest /usr/local/bin/ | ||
# copy information material | ||
COPY --from=builder /home/stillwater/universal/*.md /home/stillwater/universal/ | ||
# copy the docs | ||
COPY --chown=stillwater:stillwater --from=builder /home/stillwater/universal/docs /home/stillwater/universal/docs | ||
# no need to copy CMakeLists.txt as you don't have a compiler in this container | ||
# and thus 'make -j 8' won't work anyway, only 'make test' which doesn't need CmakeLists.txt | ||
#COPY --from=builder /home/stillwater/universal/CMakeLists.txt /home/stillwater/universal/ | ||
|
||
# after building, the test executables are organized in the build directory under stillwater | ||
# ctest gets its configuration for CTestTestfile.cmake files. There is one at the root of the build tree | ||
# and one for each directory that contains test executables. | ||
# This way we can execute _make test_ in the test stage of the CI/CD pipeline as well as part of an interactive invocation | ||
COPY --chown=stillwater:stillwater --from=builder /home/stillwater/universal/build /home/stillwater/universal/build | ||
|
||
# copy the CLI tools to /usr/local/bin so they are immediately usable | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/areal /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/double /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/fixpnt /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/float /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/float2posit /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/ieee /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/lns /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/longdouble /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/plimits /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/posit /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/prop* /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/signedint /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/unsignedint /usr/local/bin/ | ||
# reenable when you figure out how to make this dependent on the BUILD target | ||
#COPY --from=builder /home/stillwater/universal/build/validation/hw/* /usr/local/bin/ | ||
|
||
# double check we have all the executables of interest | ||
#RUN find /home/stillwater/universal/build | ||
|
||
# until we can figure out how to direct CodeShip to use this dir in the steps.yml file | ||
WORKDIR /home/stillwater/universal/build | ||
|
||
# the command 'make test' is run as part of the CI test pipeline of this release container | ||
|
||
CMD ["echo", "Universal Numbers Release Container"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# | ||
# multi-stage build | ||
# docker build --target builder -t stillwater/universal:builder will just build a builder container | ||
# docker build --target release -t stillwater/universal:release will just build a release container | ||
|
||
# BUILDER stage | ||
FROM stillwater/universal:gcc12.builder as builder | ||
LABEL Theodore Omtzigt | ||
ARG target=BUILD_ALL | ||
|
||
# make certain you have a good .dockerignore file installed so that this layer isn't ginormous | ||
COPY --chown=stillwater:stillwater . /home/stillwater/universal | ||
# print contextual information of the container at this state for visual inspection | ||
RUN ls -la /home/stillwater/universal && cmake -version | ||
|
||
# set up the cmake/make environment to issue the build commands | ||
RUN mkdir -p /home/stillwater/universal/build | ||
WORKDIR /home/stillwater/universal/build | ||
# test RUN statement to drive CI testing. ARG target provides override. | ||
# default is SANITY regression level: -DBUILD_REGRESSION_LEVEL_[1,2,3,4]=ON | ||
# or -DBUILD_REGRESSION_STRESS=ON for stress testing | ||
RUN cmake -D$target=ON -DBUILD_CMD_LINE_TOOLS=ON -DBUILD_DEMONSTRATION=OFF .. && make | ||
|
||
# the command 'make test' is run as part of the CI test pipeline of the release container | ||
|
||
|
||
# RELEASE stage | ||
#FROM alpine:latest as release # hitting a segfault during startup of some playground programs | ||
#FROM debian:buster-slim as release | ||
FROM ubuntu:20.04 as release | ||
LABEL Theodore Omtzigt | ||
|
||
#RUN apk add --no-cache libc6-compat libstdc++ cmake make bash gawk sed grep bc coreutils | ||
RUN apt-get update && apt-get update -y && apt-get install -y --no-install-recommends \ | ||
make \ | ||
&& apt-get clean | ||
# create and use user stillwater | ||
RUN useradd -ms /bin/bash stillwater | ||
USER stillwater | ||
|
||
# copy cmake enviroment needed for testing | ||
COPY --from=builder /usr/local/bin/cmake /usr/local/bin/ | ||
COPY --from=builder /usr/local/bin/ctest /usr/local/bin/ | ||
# copy information material | ||
COPY --from=builder /home/stillwater/universal/*.md /home/stillwater/universal/ | ||
# copy the docs | ||
COPY --chown=stillwater:stillwater --from=builder /home/stillwater/universal/docs /home/stillwater/universal/docs | ||
# no need to copy CMakeLists.txt as you don't have a compiler in this container | ||
# and thus 'make -j 8' won't work anyway, only 'make test' which doesn't need CmakeLists.txt | ||
#COPY --from=builder /home/stillwater/universal/CMakeLists.txt /home/stillwater/universal/ | ||
|
||
# after building, the test executables are organized in the build directory under stillwater | ||
# ctest gets its configuration for CTestTestfile.cmake files. There is one at the root of the build tree | ||
# and one for each directory that contains test executables. | ||
# This way we can execute _make test_ in the test stage of the CI/CD pipeline as well as part of an interactive invocation | ||
COPY --chown=stillwater:stillwater --from=builder /home/stillwater/universal/build /home/stillwater/universal/build | ||
|
||
# copy the CLI tools to /usr/local/bin so they are immediately usable | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/areal /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/double /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/fixpnt /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/float /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/float2posit /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/ieee /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/lns /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/longdouble /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/plimits /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/posit /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/prop* /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/signedint /usr/local/bin/ | ||
COPY --from=builder /home/stillwater/universal/build/tools/cmd/unsignedint /usr/local/bin/ | ||
# reenable when you figure out how to make this dependent on the BUILD target | ||
#COPY --from=builder /home/stillwater/universal/build/validation/hw/* /usr/local/bin/ | ||
|
||
# double check we have all the executables of interest | ||
#RUN find /home/stillwater/universal/build | ||
|
||
# until we can figure out how to direct CodeShip to use this dir in the steps.yml file | ||
WORKDIR /home/stillwater/universal/build | ||
|
||
# the command 'make test' is run as part of the CI test pipeline of this release container | ||
|
||
CMD ["echo", "Universal Numbers Release Container"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# Dockerfile to create the builder container for compiling and testing Universal | ||
# docker build --target gcc10builder -t stillwater/universal:gcc10builder | ||
|
||
# BUILDER stage | ||
FROM gcc:11.3 as gcc11builder | ||
LABEL Theodore Omtzigt | ||
# create a build environment | ||
RUN apt-get update && apt-get install -y --no-install-recommends -V \ | ||
apt-utils \ | ||
build-essential \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
# install a specific cmake version | ||
RUN set -ex \ | ||
&& for key in C6C265324BBEBDC350B513D02D2CEF1034921684; do \ | ||
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys "$key" ; \ | ||
done | ||
|
||
ENV CMAKE_DIR v3.23 | ||
ENV CMAKE_VERSION 3.23.1 | ||
|
||
RUN set -ex \ | ||
&& curl -fsSLO --compressed https://cmake.org/files/${CMAKE_DIR}/cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz \ | ||
&& curl -fsSLO https://cmake.org/files/${CMAKE_DIR}/cmake-${CMAKE_VERSION}-SHA-256.txt.asc \ | ||
&& curl -fsSLO https://cmake.org/files/${CMAKE_DIR}/cmake-${CMAKE_VERSION}-SHA-256.txt \ | ||
&& gpg --verify cmake-${CMAKE_VERSION}-SHA-256.txt.asc cmake-${CMAKE_VERSION}-SHA-256.txt \ | ||
&& grep "cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz\$" cmake-${CMAKE_VERSION}-SHA-256.txt | sha256sum -c - \ | ||
&& tar xzf cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz -C /usr/local --strip-components=1 --no-same-owner \ | ||
&& rm -rf cmake-${CMAKE_VERSION}* | ||
|
||
# create and use user stillwater | ||
RUN useradd -ms /bin/bash stillwater | ||
USER stillwater | ||
|
||
WORKDIR /home/stillwater | ||
|
||
# add a command that when you run the container without a command, it produces something meaningful | ||
ENV CONTAINER_ID "Universal Numbers Library Builder V3 GCC 10.3" | ||
CMD ["/usr/bin/env", "bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# Dockerfile to create the builder container for compiling and testing Universal | ||
# docker build --target gcc10builder -t stillwater/universal:gcc10builder | ||
|
||
# BUILDER stage | ||
FROM gcc:12.1 as gcc12builder | ||
LABEL Theodore Omtzigt | ||
# create a build environment | ||
RUN apt-get update && apt-get install -y --no-install-recommends -V \ | ||
apt-utils \ | ||
build-essential \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
# install a specific cmake version | ||
RUN set -ex \ | ||
&& for key in C6C265324BBEBDC350B513D02D2CEF1034921684; do \ | ||
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys "$key" ; \ | ||
done | ||
|
||
ENV CMAKE_DIR v3.23 | ||
ENV CMAKE_VERSION 3.23.1 | ||
|
||
RUN set -ex \ | ||
&& curl -fsSLO --compressed https://cmake.org/files/${CMAKE_DIR}/cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz \ | ||
&& curl -fsSLO https://cmake.org/files/${CMAKE_DIR}/cmake-${CMAKE_VERSION}-SHA-256.txt.asc \ | ||
&& curl -fsSLO https://cmake.org/files/${CMAKE_DIR}/cmake-${CMAKE_VERSION}-SHA-256.txt \ | ||
&& gpg --verify cmake-${CMAKE_VERSION}-SHA-256.txt.asc cmake-${CMAKE_VERSION}-SHA-256.txt \ | ||
&& grep "cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz\$" cmake-${CMAKE_VERSION}-SHA-256.txt | sha256sum -c - \ | ||
&& tar xzf cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz -C /usr/local --strip-components=1 --no-same-owner \ | ||
&& rm -rf cmake-${CMAKE_VERSION}* | ||
|
||
# create and use user stillwater | ||
RUN useradd -ms /bin/bash stillwater | ||
USER stillwater | ||
|
||
WORKDIR /home/stillwater | ||
|
||
# add a command that when you run the container without a command, it produces something meaningful | ||
ENV CONTAINER_ID "Universal Numbers Library Builder V3 GCC 10.3" | ||
CMD ["/usr/bin/env", "bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.