File: filter.h

package info (click to toggle)
multimon 1.0-7.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 576 kB
  • ctags: 924
  • sloc: ansic: 8,144; makefile: 233; perl: 41
file content (110 lines) | stat: -rw-r--r-- 3,488 bytes parent folder | download | duplicates (7)
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
/*
 *      filter.h -- optimized filter routines
 *
 *      Copyright (C) 1996  
 *          Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu)
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 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 General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* ---------------------------------------------------------------------- */

#ifndef _FILTER_H
#define _FILTER_H

/* ---------------------------------------------------------------------- */

#ifdef ARCH_I386
#include "filter-i386.h"
#endif /* ARCH_I386 */

/* ---------------------------------------------------------------------- */

extern inline unsigned int hweight32(unsigned int w)
        __attribute__ ((unused));
extern inline unsigned int hweight16(unsigned short w)
        __attribute__ ((unused));
extern inline unsigned int hweight8(unsigned char w)
        __attribute__ ((unused));

extern inline unsigned int hweight32(unsigned int w) 
{
        unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
        res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
        res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
        res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
        return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
}

extern inline unsigned int hweight16(unsigned short w)
{
        unsigned short res = (w & 0x5555) + ((w >> 1) & 0x5555);
        res = (res & 0x3333) + ((res >> 2) & 0x3333);
        res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F);
        return (res & 0x00FF) + ((res >> 8) & 0x00FF);
}

extern inline unsigned int hweight8(unsigned char w)
{
        unsigned short res = (w & 0x55) + ((w >> 1) & 0x55);
        res = (res & 0x33) + ((res >> 2) & 0x33);
        return (res & 0x0F) + ((res >> 4) & 0x0F);
}

extern inline unsigned int gcd(unsigned int x, unsigned int y)
        __attribute__ ((unused));
extern inline unsigned int lcm(unsigned int x, unsigned int y)
        __attribute__ ((unused));

extern inline unsigned int gcd(unsigned int x, unsigned int y)
{
        for (;;) {
                if (!x)
                        return y;
                if (!y) 
                        return x;
                if (x > y)
                        x %= y;
                else
                        y %= x;
        }
}

extern inline unsigned int lcm(unsigned int x, unsigned int y)
{
        return x * y / gcd(x, y);
}

/* ---------------------------------------------------------------------- */

#ifndef __HAVE_ARCH_MAC
extern inline float mac(const float *a, const float *b, unsigned int size)
{
	float sum = 0;
	unsigned int i;

	for (i = 0; i < size; i++)
		sum += (*a++) * (*b++);
	return sum;
}
#endif /* __HAVE_ARCH_MAC */

extern inline float fsqr(float f) 
{
	return f*f;
}

/* ---------------------------------------------------------------------- */
#endif /* _FILTER_H */