SLEEF Documentation - Compiling and installing the library

Table of contents

Compiling and installing the library

Installing library on Ubuntu

You can install via launchpad PPA.

$ sudo add-apt-repository ppa:shibatch/sleef
$ sudo apt-get update
$ sudo apt-get install libsleef3

Fig. 2.1: Commands for installing from Launchpad

Compiling and installing library on Linux

You need to install libmpfr and OpenMP(libmpfr is only required to build the tester, and it is not linked to the library.) Change directory to sleef-3.X directory and run make. The built headers and libraries will be located under include and lib directories.

You can run make install using sudo command to install the library and header. Those files are installed under /usr/lib and /usr/include. You can run make uninstall to uninstall those files.

$ sudo apt-get install libmpfr-dev libgomp1-dev gcc
$ cd sleef-3.X
$ make
$ sudo make install

Fig. 2.2: Commands for compiling SLEEF

Compiling library with Microsoft Visual C++

Below is the instruction for compiling SLEEF with Microsoft Visual C++ 2015.

  1. Install Visual Studio 2015 or later, along with Cygwin
  2. Copy vcvars64.bat to a working directory. This file is usually in the following directory.
    C:\Program Files (x86)\MSVCCommunity2015\VC\bin\amd64
  3. Add the following line at the end of the copy of vcvars64.bat
    if "%SHELL%"=="/bin/bash" c:\cygwin64\bin\bash.exe
  4. Execute the copy of vcvars64.bat within the Cygwin bash shell.
  5. Go to sleef-3.X directory and run "make -f Makefile.vc"

Compiling and running "Hello SLEEF!"

Now, let's try compiling the source code shown in Fig. 2.3.

#include <stdio.h>
#include <x86intrin.h>
#include <sleef.h>

int main(int argc, char **argv) {
  double a[] = {2, 10};
  double b[] = {3, 20};

  __m128d va, vb, vc;
  
  va = _mm_loadu_pd(a);
  vb = _mm_loadu_pd(b);

  vc = Sleef_powd2_u10(va, vb);

  double c[2];

  _mm_storeu_pd(c, vc);

  printf("pow(%g, %g) = %g\n", a[0], b[0], c[0]);
  printf("pow(%g, %g) = %g\n", a[1], b[1], c[1]);
}

Fig. 2.3: Source code for testing

Fig.2.3 shows typical commands for compiling and executing the hello code on Linux computers.

$ gcc hellox86.c -o hellox86 -lsleef
$ ./hellox86
pow(2, 3) = 8
pow(10, 20) = 1e+20

Fig. 2.3: Commands for compiling and executing hellox86.c

You may need to set LD_LIBRARY_PATH environment variable appropriately. If you are trying to execute the program on Mac OSX or Windows, try copying the DLLs to the current directory.