Enabling floating point non-standard mode using LD_PRELOAD

Subnormal numbers are explained in a previous post, together with the use of the flag -fns to flush these to zero if they cause a performance impact.

Of course, it's possible that parts of the code need to be computed with subnormals and parts with them flushed to zero. There are programmatic controls to do this in libsunmath, the routines are nonstandard_arithmetic and standard_arithmetic.

Sometimes it may be that they are occurring in code that cannot be recompiled, it is still possible to disable them. One approach is to write a LD_PRELOAD library, containing the following code:

#include <sunmath.h>
#include <stdio.h>

#pragma init(go)

void go()
{
  nonstandard_arithmetic();
  printf("NONSTANDARD MODE\\n");
}

The printf is just to demonstrate that the code is actually called. Taking the same code from the previous post we can confirm that this approach works:

$ cc -O ft.c
$ a.out
...
4.940656e-324
$ cc -O -G -Kpic libns.c -o libns.so -lsunmath
$ export LD_PRELOAD=./libns.so
$ a.out
NONSTANDARD MODE
...
2.225074e-308
Comments:

Post a Comment:
Comments are closed for this entry.
About

Darryl Gove is a senior engineer in the Solaris Studio team, working on optimising applications and benchmarks for current and future processors. He is also the author of the books:
Multicore Application Programming
Solaris Application Programming
The Developer's Edge

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
5
6
8
9
10
12
13
14
15
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Bookmarks
The Developer's Edge
Solaris Application Programming
Publications
Webcasts
Presentations
OpenSPARC Book
Multicore Application Programming
Docs