Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- c++ -*- */ |
2 |
|
|
/* |
3 |
|
|
* Copyright 2012, 2014 Free Software Foundation, Inc. |
4 |
|
|
* |
5 |
|
|
* This file is part of VOLK |
6 |
|
|
* |
7 |
|
|
* SPDX-License-Identifier: LGPL-3.0-or-later |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
/*! |
11 |
|
|
* \page volk_32u_popcnt |
12 |
|
|
* |
13 |
|
|
* \b Overview |
14 |
|
|
* |
15 |
|
|
* Computes the population count (popcnt), or Hamming distance of a |
16 |
|
|
* binary string. This kernel takes in a single unsigned 32-bit value |
17 |
|
|
* and returns the count of 1's that the value contains. |
18 |
|
|
* |
19 |
|
|
* <b>Dispatcher Prototype</b> |
20 |
|
|
* \code |
21 |
|
|
* void volk_32u_popcnt(uint32_t* ret, const uint32_t value) |
22 |
|
|
* \endcode |
23 |
|
|
* |
24 |
|
|
* \b Inputs |
25 |
|
|
* \li value: The input value. |
26 |
|
|
* |
27 |
|
|
* \b Outputs |
28 |
|
|
* \li ret: The return value containing the popcnt. |
29 |
|
|
* |
30 |
|
|
* \b Example |
31 |
|
|
* \code |
32 |
|
|
int N = 10; |
33 |
|
|
unsigned int alignment = volk_get_alignment(); |
34 |
|
|
|
35 |
|
|
uint32_t bitstring = 0x55555555; |
36 |
|
|
uint32_t hamming_distance = 0; |
37 |
|
|
|
38 |
|
|
volk_32u_popcnt(&hamming_distance, bitstring); |
39 |
|
|
printf("hamming distance of %x = %i\n", bitstring, hamming_distance); |
40 |
|
|
* \endcode |
41 |
|
|
*/ |
42 |
|
|
|
43 |
|
|
#ifndef INCLUDED_VOLK_32u_POPCNT_A16_H |
44 |
|
|
#define INCLUDED_VOLK_32u_POPCNT_A16_H |
45 |
|
|
|
46 |
|
|
#include <inttypes.h> |
47 |
|
|
#include <stdio.h> |
48 |
|
|
|
49 |
|
|
#ifdef LV_HAVE_GENERIC |
50 |
|
|
|
51 |
|
262142 |
static inline void volk_32u_popcnt_generic(uint32_t* ret, const uint32_t value) |
52 |
|
|
{ |
53 |
|
|
// This is faster than a lookup table |
54 |
|
262142 |
uint32_t retVal = value; |
55 |
|
|
|
56 |
|
262142 |
retVal = (retVal & 0x55555555) + (retVal >> 1 & 0x55555555); |
57 |
|
262142 |
retVal = (retVal & 0x33333333) + (retVal >> 2 & 0x33333333); |
58 |
|
262142 |
retVal = (retVal + (retVal >> 4)) & 0x0F0F0F0F; |
59 |
|
262142 |
retVal = (retVal + (retVal >> 8)); |
60 |
|
262142 |
retVal = (retVal + (retVal >> 16)) & 0x0000003F; |
61 |
|
|
|
62 |
|
262142 |
*ret = retVal; |
63 |
|
262142 |
} |
64 |
|
|
|
65 |
|
|
#endif /*LV_HAVE_GENERIC*/ |
66 |
|
|
|
67 |
|
|
|
68 |
|
|
#ifdef LV_HAVE_SSE4_2 |
69 |
|
|
|
70 |
|
|
#include <nmmintrin.h> |
71 |
|
|
|
72 |
|
262142 |
static inline void volk_32u_popcnt_a_sse4_2(uint32_t* ret, const uint32_t value) |
73 |
|
|
{ |
74 |
|
262142 |
*ret = _mm_popcnt_u32(value); |
75 |
|
262142 |
} |
76 |
|
|
|
77 |
|
|
#endif /*LV_HAVE_SSE4_2*/ |
78 |
|
|
|
79 |
|
|
#endif /*INCLUDED_VOLK_32u_POPCNT_A16_H*/ |
80 |
|
|
|