Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b7a80d54
Commit
b7a80d54
authored
Jan 23, 2018
by
Yury Selivanov
Committed by
GitHub
Jan 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-32436: Don't use native popcount() (also fixes bpo-32641) (#5292)
parent
6b273f7f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
15 deletions
+13
-15
Python/context.c
Python/context.c
+1
-1
Python/hamt.c
Python/hamt.c
+12
-14
No files found.
Python/context.c
View file @
b7a80d54
...
...
@@ -1171,7 +1171,7 @@ get_token_missing(void)
int
PyContext_ClearFreeList
(
void
)
{
in
t
size
=
ctx_freelist_len
;
Py_ssize_
t
size
=
ctx_freelist_len
;
while
(
ctx_freelist_len
)
{
PyContext
*
ctx
=
ctx_freelist
;
ctx_freelist
=
(
PyContext
*
)
ctx
->
ctx_weakreflist
;
...
...
Python/hamt.c
View file @
b7a80d54
...
...
@@ -4,11 +4,6 @@
#include "internal/pystate.h"
#include "internal/hamt.h"
/* popcnt support in Visual Studio */
#ifdef _MSC_VER
#include <intrin.h>
#endif
/*
This file provides an implemention of an immutable mapping using the
Hash Array Mapped Trie (or HAMT) datastructure.
...
...
@@ -440,18 +435,21 @@ hamt_bitpos(int32_t hash, uint32_t shift)
static
inline
uint32_t
hamt_bitcount
(
uint32_t
i
)
{
#if defined(__GNUC__) && (__GNUC__ > 4)
return
(
uint32_t
)
__builtin_popcountl
(
i
);
#elif defined(__clang__) && (__clang_major__ > 3)
return
(
uint32_t
)
__builtin_popcountl
(
i
);
#elif defined(_MSC_VER)
return
(
uint32_t
)
__popcnt
(
i
);
#else
/* https://graphics.stanford.edu/~seander/bithacks.html */
/* We could use native popcount instruction but that would
require to either add configure flags to enable SSE4.2
support or to detect it dynamically. Otherwise, we have
a risk of CPython not working properly on older hardware.
In practice, there's no observable difference in
performance between using a popcount instruction or the
following fallback code.
The algorithm is copied from:
https://graphics.stanford.edu/~seander/bithacks.html
*/
i
=
i
-
((
i
>>
1
)
&
0x55555555
);
i
=
(
i
&
0x33333333
)
+
((
i
>>
2
)
&
0x33333333
);
return
((
i
+
(
i
>>
4
)
&
0xF0F0F0F
)
*
0x1010101
)
>>
24
;
#endif
}
static
inline
uint32_t
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment