This file is indexed.

/usr/include/spandsp/fast_convert.h is in libspandsp-dev 0.0.6~pre20-3.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/*
 * SpanDSP - a series of DSP components for telephony
 *
 * fast_convert.h - Quick ways to convert floating point numbers to integers
 *
 * Written by Steve Underwood <steveu@coppice.org>
 *
 * Copyright (C) 2009 Steve Underwood
 *
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 2.1,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#if !defined(_SPANDSP_FAST_CONVERT_H_)
#define _SPANDSP_FAST_CONVERT_H_

#if defined(__cplusplus)
extern "C"
{
#endif

/* The following code, to handle issues with lrint() and lrintf() on various
 * platforms, is adapted from similar code in libsndfile, which is:
 *
 * Copyright (C) 2001-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 */

/*
 *    On Intel Pentium processors (especially PIII and probably P4), converting
 *    from float to int is very slow. To meet the C specs, the code produced by
 *    most C compilers targeting Pentium needs to change the FPU rounding mode
 *    before the float to int conversion is performed.
 *
 *    Changing the FPU rounding mode causes the FPU pipeline to be flushed. It
 *    is this flushing of the pipeline which is so slow.
 *
 *    Fortunately the ISO C99 specification defines the functions lrint, lrintf,
 *    llrint and llrintf which fix this problem as a side effect.
 *
 *    On Unix-like systems, the configure process should have detected the
 *    presence of these functions. If they weren't found we have to replace them
 *    here with a standard C cast.
 */

/*
 *    The C99 prototypes for these functions are as follows:
 *
 *        int rintf(float x);
 *        int rint(double x);
 *        long int lrintf(float x);
 *        long int lrint(double x);
 *        long long int llrintf(float x);
 *        long long int llrint(double x);
 *
 *    The presence of the required functions are detected during the configure
 *    process and the values HAVE_LRINT and HAVE_LRINTF are set accordingly in
 *    the config file.
 */

#if defined(__CYGWIN__)
#if !defined(__cplusplus)  &&  (__GNUC__ < 4)
    /*
     *    CYGWIN versions prior to 1.7.1 have lrint and lrintf functions, but
     *    they are slow and buggy:
     *        http://sourceware.org/ml/cygwin/2005-06/msg00153.html
     *        http://sourceware.org/ml/cygwin/2005-09/msg00047.html
     *    These replacement functions (pulled from the Public Domain MinGW
     *    math.h header) replace the native versions.
     */
    static __inline__ long int lrint(double x)
    {
        long int retval;

        __asm__ __volatile__
        (
            "fistpl %0"
            : "=m" (retval)
            : "t" (x)
            : "st"
        );

        return retval;
    }

    static __inline__ long int lrintf(float x)
    {
        long int retval;

        __asm__ __volatile__
        (
            "fistpl %0"
            : "=m" (retval)
            : "t" (x)
            : "st"
        );
        return retval;
    }
#endif

    /* The fastest way to convert is the equivalent of lrint() */
    static __inline__ long int lfastrint(double x)
    {
        long int retval;

        __asm__ __volatile__
        (
            "fistpl %0"
            : "=m" (retval)
            : "t" (x)
            : "st"
        );

        return retval;
    }

    static __inline__ long int lfastrintf(float x)
    {
        long int retval;

        __asm__ __volatile__
        (
            "fistpl %0"
            : "=m" (retval)
            : "t" (x)
            : "st"
        );
        return retval;
    }
#elif defined(__GNUC__)  ||  (__SUNPRO_C >= 0x0590)

#if defined(__i386__)
    /* These routines are guaranteed fast on an i386 machine. Using the built in
       lrint() and lrintf() should be similar, but they may not always be enabled.
       Sometimes, especially with "-O0", you might get slow calls to routines. */
    static __inline__ long int lfastrint(double x)
    {
        long int retval;

        __asm__ __volatile__
        (
            "fistpl %0"
            : "=m" (retval)
            : "t" (x)
            : "st"
        );

        return retval;
    }

    static __inline__ long int lfastrintf(float x)
    {
        long int retval;

        __asm__ __volatile__
        (
            "fistpl %0"
            : "=m" (retval)
            : "t" (x)
            : "st"
        );
        return retval;
    }
#elif defined(__x86_64__)
    /* On an x86_64 machine, the fastest thing seems to be a pure assignment from a
       double or float to an int. It looks like the design on the x86_64 took account
       of the default behaviour specified for C. */
    static __inline__ long int lfastrint(double x)
    {
        return (long int) (x);
    }

    static __inline__ long int lfastrintf(float x)
    {
        return (long int) (x);
    }
#elif defined(__ppc__)  ||   defined(__powerpc__)
    static __inline__ long int lfastrint(register double x)
    {
        int res[2];

        __asm__ __volatile__
        (
            "fctiw %1, %1\n\t"
            "stfd %1, %0"
            : "=m" (res)    /* Output */
            : "f" (x)       /* Input */
            : "memory"
        );

        return res[1];
    }

    static __inline__ long int lfastrintf(register float x)
    {
        int res[2];

        __asm__ __volatile__
        (
            "fctiw %1, %1\n\t"
            "stfd %1, %0"
            : "=m" (res)    /* Output */
            : "f" (x)       /* Input */
            : "memory"
        );

        return res[1];
    }
#else
    /* Fallback routines, for unrecognised platforms */
    static __inline__ long int lfastrint(double x)
    {
        return (long int) x;
    }

    static __inline__ long int lfastrintf(float x)
    {
        return (long int) x;
    }
#endif

#elif defined(_M_IX86)
    /* Visual Studio i386 */
    /*
     *    Win32 doesn't seem to have the lrint() and lrintf() functions.
     *    Therefore implement inline versions of these functions here.
     */

    __inline long int lrint(double x)
    {
        long int i;

        _asm
        {
            fld x
            fistp i
        };
        return i;
    }

    __inline long int lrintf(float x)
    {
        long int i;

        _asm
        {
            fld x
            fistp i
        };
        return i;
    }

    __inline float rintf(float flt)
    {
    	_asm
    	{	fld flt
    		frndint
    	}
    }

    __inline double rint(double dbl)
    {
        _asm 
    	{
            fld dbl
            frndint
        }
    }

    __inline long int lfastrint(double x)
    {
        long int i;

        _asm
        {
            fld x
            fistp i
        };
        return i;
    }

    __inline long int lfastrintf(float x)
    {
        long int i;

        _asm
        {
            fld x
            fistp i
        };
        return i;
    }
#elif defined(_M_X64)
    /* Visual Studio x86_64 */
    /* x86_64 machines will do best with a simple assignment. */
#include <intrin.h>

    __inline long int lrint(double x)
    {
		return (long int)_mm_cvtsd_si64x( _mm_loadu_pd ((const double*)&x) );
    }

    __inline long int lrintf(float x)
    {
		return _mm_cvt_ss2si( _mm_load_ss((const float*)&x) );
    }

    __inline long int lfastrint(double x)
    {
        return (long int) (x);
    }

    __inline long int lfastrintf(float x)
    {
        return (long int) (x);
    }
#elif defined(__MWERKS__)  &&  defined(macintosh)
    /* This MacOS 9 solution was provided by Stephane Letz */

    long int __inline__ lfastrint(register double x)
    {
        long int res[2];

        asm
        {
            fctiw x, x
            stfd x, res
        }
        return res[1];
    }

    long int __inline__ lfastrintf(register float x)
    {
        long int res[2];

        asm
        {
            fctiw x, x
            stfd x, res
        }
        return res[1];
    }
#elif defined(__MACH__)  &&  defined(__APPLE__)  &&  (defined(__ppc__)  ||  defined(__powerpc__))
    /* For Apple Mac OS/X - do recent versions still need this? */

    static __inline__ long int lfastrint(register double x)
    {
        int res[2];

        __asm__ __volatile__
        (
            "fctiw %1, %1\n\t"
            "stfd %1, %0"
            : "=m" (res)    /* Output */
            : "f" (x)       /* Input */
            : "memory"
        );

        return res[1];
    }

    static __inline__ long int lfastrintf(register float x)
    {
        int res[2];

        __asm__ __volatile__
        (
            "fctiw %1, %1\n\t"
            "stfd %1, %0"
            : "=m" (res)    /* Output */
            : "f" (x)       /* Input */
            : "memory"
        );

        return res[1];
    }
#else
    /* There is nothing else to do, but use a simple casting operation, instead of a real
       rint() type function. Since we are only trying to use rint() to speed up conversions,
       the accuracy issues related to changing the rounding scheme are of little concern
       to us. */

    #if !defined(__sgi)  &&  !defined(__sunos)  &&  !defined(__solaris)  &&  !defined(__sun)
        #warning "No usable lrint() and lrintf() functions available."
        #warning "Replacing these functions with a simple C cast."
    #endif

    static __inline__ long int lrint(double x)
    {
        return (long int) (x);
    }

    static __inline__ long int lrintf(float x)
    {
        return (long int) (x);
    }

    static __inline__ long int lfastrint(double x)
    {
        return (long int) (x);
    }

    static __inline__ long int lfastrintf(float x)
    {
        return (long int) (x);
    }
#endif

#if defined(__cplusplus)
}
#endif

#endif

/*- End of file ------------------------------------------------------------*/