12.2.1. On Linux - 5.2 English - 57404

AOCL User Guide (57404)

Document ID
57404
Release Date
2025-12-29
Version
5.2 English

To use AOCL-LibM in your application, complete the following steps:

  1. Include math.h as a standard way to use the C Standard library math functions.

  2. Link in the appropriate version of the library in your program.

    The Linux libraries may have a dependency on the system math library. When linking AOCL-LibM, ensure that it precedes the system math library in the link order, that is, -lalm must appear before -lm. The explicit linking of the system math library is required when using the GCC or AOCC compilers. Such explicit linking is not required with the g++ compiler (for C++).

Sample Commands and Code Snippets:

Example: myprogram.c

#include <stdio.h>
#include <math.h>

int main() {
  float f = 3.14f;
  printf ("%f\n", expf(f));
  return 0;
}

To use AOCL-LibM scalar functions, use the following commands:

$ export LD_LIBRARY_PATH=<Path to libalm.so>:$LD_LIBRARY_PATH
$ cc -Wall -std=c99 myprogram.c -o myprogram -L<Path to libalm.so> -lalm -lm (cc can be 'gcc' or 'clang').
$ ./myprogram

Faster but less accurate versions of some of the scalar functions are available in the library libalmfast.so.

Fast versions can be selected by setting LD_PRELOAD=/path-to/libalmfast.so or enabled using certain flags by the AOCC compiler. For more information, refer to the AOCC user guide at https://docs.amd.com/r/en-US/57222-AOCC-user-guide/Linking-AMD-Library.

Vector Functions Usage:

You can access the vector calls by using the AOCC compiler with the flags -ffast-math -fveclib=AMDLIBM.

You can also call the functions directly, which requires manual packing and unpacking. To do so, you must include the header file amdlibm_vec.h. The following program shows such an example. For simplicity, the size and other checks are omitted.

Example: myprogram.c

#include "amdlibm_vec.h"

__m128 vrs4_expf ( __m128 x);
__m128 test_expf_v4s(float *ip, float *out)
{
  __m128 ip4 = _mm_set_ps(ip[3], ip[2], ip[1], ip[0]);
  __m128 op4 = vrs4_expf(ip4);
  _mm_store_ps(&out[0], op4);

  return op4;
}

Compile the program:

$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/path/to/AOCL-LibM
$ clang -Wall -std=c99 -ffast-math myprogram.c -o myprogram -L<path to libalm.so> -lalm -lm