[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

General Programming Concepts: Writing and Debugging Programs

librs2.a Library

The /usr/lib/librs2.a library provides statically linked, hardware-specific replacements for the sqrt and itrunc subroutines. These replacement subroutines make use of hardware-specific instructions on some POWER-based, POWERstation, and POWERserver models to increase performance.

Note: Use the hardware-specific versions of these subroutines in programs that will run only on models of POWER-based machines, POWERstations, and POWERservers that support hardware implementations of square root and conversion to integer. Attempting to use them in programs running on other models will result in an illegal instruction trap.

General-Use sqrt and itrunc Subroutines

The general-use version of the sqrt subroutine is in the libm.a library. The sqrt subroutine computes the square root of a floating-point number.

The general-use version of the itrunc subroutine is in the libc.a library. The itrunc subroutine converts a floating-point number to integer format.

POWER2-Specific sqrt and itrunc Subroutines

The /usr/lib/librs2.a library contains the following subroutines:

The subroutine names with leading underscores are used by the C and Fortran compilers. They are functionally identical to the versions without underscores.

For best performance, source code that computes square roots or converts floating-point numbers to integers can be recompiled with the xlc or xlf command using the -qarch=pwrx compiler option. This option enables a program to use the square-root and convert-to-integer instructions.

To use the hardware-specific subroutines in the librs2.a library, link it ahead of the libm.a and libc.a libraries. For example:

xlc -O -o prog prog.c -lrs2 -lm


xlf -O -o prog prog.f -lrs2

You can use the xlf or xlc compiler to rebind a program to use this library. For example, to create a POWER2-specific executable file named progrs2 from an existing non-stripped file named prog in the current directory:

xlc -lrs2 prog -o progrs2


xlf -lrs2 prog -o progrs2

Related Information

itrunc subroutine, sqrt subroutine

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]