Description: SLEEF implements vectorized C99 math functions. It utilizes vector extensions including SSE2, AVX, AVX2, AVX512F for x86, and Advanced SIMD for ARM processors.

# SLEEF Vectorized Math Library

- Download the latest version
- Latest documentation on the web
- GitHub repository
- Mailing list
- Discussion forum
- Wiki pages

## Table of contents

- Introduction
  - Overview
  - Supported environments
  - Credit
  - Partners
  - License
  - History
  - Related projects
  - Publication
- Compiling and installing the library
- Math library reference
- DFT library reference
- Other tools included in the package
- Benchmark results
- Additional notes

## Overview

SLEEF stands for SIMD Library for Evaluating Elementary Functions. It implements vectorized versions of all C99 real floating point math functions. It can utilize SIMD instructions that are available on modern processors. SLEEF is designed to effciently perform computation with SIMD instruction by reducing the use of conditional branches and scatter/gather memory access. Our benchmarks show that the performance of SLEEF is comparable to that of the best commercial library. Unlike vendor-tuned assembly-optimized libraries, SLEEF can be easily ported to other architectures by writing a helper file, which is a thin abstraction layer of SIMD intrinsics. SLEEF is also designed to work with various operating systems and compilers. Link time optimization can be used to reduce the overhead of calling functions.

The library contains implementations of all C99 real FP math functions in double precision and single precision. Different accuracy of the results can be chosen for a subset of the elementary functions; for this subset there are versions with up to 1 ULP error (which is the maximum error, not the average) and even faster versions with a few ULPs of error. For non-finite inputs and outputs, the functions return correct results as specified in the C99 standard. All the functions in the library are thoroughly tested and confirmed that the evaluation error is within the designed limit, by comparing the returned values against high-precision evaluation using the GNU MPFR Library. Especially, we carefully checked the error of the trigonometric functions with arguments close to an integral multiple of π/2.

SLEEF also includes subroutines for discrete Fourier transform(DFT). These subroutines are fully vectorized, heavily unrolled, and parallelized in such a way that modern SIMD instructions and multiple cores can be utilized for efficient computation. It has an API similar to that of FFTW for easy migration, and distributed under BSL, which is a permissive open source license. The subroutines can utilize long vectors up to 2048 bits. The helper files for abstracting SIMD intrinsics are shared with SLEEF libm, and thus it is easy to port DFT subroutines to other architectures. Preliminary results of benchmark are now available.

## Supported environments

This library currently supports several SIMD architectures :

- x86 - SSE2, SSE4.1, AVX, AVX2+FMA3, AVX512F
- AArch64 - Advanced SIMD, SVE
- AArch32 - NEON
- PowerPC64 - VSX
- System/390 - ZVECTOR2

In addition to the SIMD implementation, Pure C (scalar) version is provided. The library provides dispatchers that automatically choose the best subroutines for the computer the library is executed on. The supported combinations of the architecture, operating system and compiler are shown in Table 1.1.

Table 1.1: Environment support matrix
|  | GCC | Clang | Intel Compiler | MSVC
x86_64, Linux |  | Supported | Supported | Supported | N/A
AArch64, Linux |  | Supported | Supported | N/A | N/A
AArch32, Linux |  | Supported(*1) | Supported(*1) | N/A | N/A
PowerPC, Linux |  | Supported | Supported | N/A | N/A
System/390, Linux |  | Supported | Supported | N/A | N/A
x86_64, FreeBSD |  |  | Supported | N/A | N/A
x86_64, OS X |  | Supported(*2) | Supported(*2) |  | N/A
x86_64, Windows |  | Supported(Cygwin)(*3) | Supported(*3) |  | Supported

The supported compiler versions are as follows.

- GCC : version 5 and later
- Clang : version 6 and later
- Intel Compiler : ICC version 17
- MSVC : Visual Studio 2019

*1 NEON has only single precision support. The computation results are not in full accuracy because NEON is not IEEE 754-compliant.

*2 LTO is not supported.

*3 AVX functions are not supported for Cygwin, because AVX is not supported by Cygwin ABI.

All functions in the library are thread safe unless otherwise noted.

## Credit

- The main developer is Naoki Shibata ( shibatch@users.sourceforge.net ) at Nara Institute of Science and Technology.
- Francesco Petrogalli at ARM Ltd. contributed the helper for AArch64 (helperadvsimd.h, helpersve.h) and GNUABI interface of the library. He also worked on migrating the build system to cmake, and reviewed the code, gave precious comments and suggestions.
- Hal Finkel at Argonne Leadership Computing Facility is now working on importing and adapting SLEEF as an LLVM runtime. He also gave precious comments.
- Diana Bite at University of Manchester and Alexandre Mutel at Unity Technologies worked on migrating the build system to cmake.
- Martin Krastev at Chaos Group contributed faster implementation of fmin and fmax functions.
- Mo Zhou is managing packages for Debian and Ubuntu PPA.

## Partner institutes and corporations

| Division of Information Science of Nara Institute of Science and Technology participates through Naoki Shibata.
| As the leading IP company in semiconductors design, ARM participates through Francesco Petrogalli.
| As the leading company in developing a video game engine, Unity Technologies participates through Alexandre Mutel.

## License

SLEEF is distributed under Boost Software License Version 1.0.

Boost Software License is OSI-certified. See this page for more information about Boost Software License.

## History

#### 3.5.1 (Released on Sep 15, 2020)

- Fixed a bug in handling compiler options

#### 3.5 (Released on Sep 1, 2020)

- IBM System/390 support is added (PR #291)
- The library can be built with Clang on Windows (PR #300)
- Static libraries with LTO can be generated (PR #290)
- Alternative division and sqrt methods can be chosen with AArch64 (PR #289)
- Header files for inlining the whole SLEEF functions can be generated (PR #283)
- IEEE remainder function is added (PR #271)
- GCC-10 can now build SLEEF with SVE support (PR #310)

#### 3.4.1 (Released on Oct 1, 2019)

- Fixed accuracy problem with tan_u35, atan_u10, log2f_u35 and exp10f_u10 (PR #260, #265, #267)
- SVE intrinsics that are not supported in newer ACLE are replaced (PR #268)
- FMA4 detection problem is fixed (PR #262)
- Compilation problem under Windows with MinGW is fixed (PR #266)

#### 3.4 (Released on Apr 28, 2019)

- Faster and low precision functions are added (PR #229)
- Functions that return consistent results across platforms are added (PR #216, #224)
- Many functions are now faster (PR #239)
- Quad precision math library(libsleefquad) is added (PR #235, #237, #240)
- Testers are now faster (PR #223)

#### 3.3.1 (Released on Aug 21, 2018)

- i386 build problem is fixed
- FreeBSD support is added
- Trigonometric functions now evaluate correctly with full FP domain. (PR #210)

#### 3.3 (Released on July 6, 2018)

- AArch64 SVE target support is added (PR #180, #182)
- DFT is now faster (PR #186)
- 3.5-ULP hyperbolic functions are added (PR #192)
- PowerPC VSX target support is added (PR #195)
- Modified Payne-Hanek argument reduction is added to the trigonometric functions in libsleef (PR #197)

#### 3.2 (Released on Feb 26, 2018)

- The whole build system of the project migrated from makefiles to cmake. The makefile build system is now removed.
- GNUABI version of the library with compatibility tests is added.
- Benchmarks that compare `libsleef` vs `SVML` on X86 Linux are available in the project tree under src/libm-benchmarks directory.
- Extensive upstream testing via Travis CI and Appveyor
- log2 is added.
- The library can be compiled to an LLVM bitcode object
- Added masked interface to the library to support AVX512F masked vectorization.
- Use native instructions if available for `sqrt`.
- Removed `libm` dependency.
- fmod(FP remainder), asin, acos, log, pow, log10, exp2, exp10 and log1p functions are now faster.
- Fixed a bug that was making the error of sinpi, cospi, sincospi, and tgamma functions larger than the specifications on very rare occasions.
- Fixed a bug that was preventing the dispatcher from choosing the FMA4 implementation.

See Changelog for older changes.

## Related projects and links

- SLEEF is adopted in the Burst Comipler in Unity, and also in the Android version.
- SLEEF is now included in Arm Compiler for HPC.
- Work for making SLEEF usable from the vectorizer in LLVM is now carried out(D53927, D53928, D54412).
- Mustafa A. Mohamad is developing a pure Julia port of the SLEEF math library.
- Hal Finkel has adapted SLEEF to PowerPC/QPX. SLEEF is running on Mira IBM BG/Q supercomputer at Argonne National Laboratory.
- Gonzalo Brito Gadeschi is developing a Rust FFI bindings to SLEEF.
- SLEEF is adopted in the following projects.
  - MenuetOS
  - RawTherapee
  - John's ECMA-55 Minimal BASIC Compiler
  - Portable Computing Language(pocl)
  - PyTorch
  - The Region Vectorizer(Compiler Design Lab at Saarland University)
  - Agenium Scale NSIMD
  - J Language
  - SIMD Everywhere
  - Minocore
  - OctaSine
  - Simdeez

## Publication

- Naoki Shibata and Francesco Petrogalli : SLEEF: A Portable Vectorized Library of C Standard Mathematical Functions, in IEEE Transactions on Parallel and Distributed Systems, DOI:10.1109/TPDS.2019.2960333 (Dec. 2019). [PDF]
- Francesco Petrogalli and Paul Walker : LLVM and the automatic vectorization of loops invoking math routines: -fsimdmath, 2018 IEEE/ACM 5th Workshop on the LLVM Compiler Infrastructure in HPC (LLVM-HPC), pp. 30-38., DOI:10.1109/LLVM-HPC.2018.8639354 (Nov. 2018). [PDF]