Title: bpo-32436: Don't use native popcount() (also fixes bpo-32641) by 1st1 · Pull Request #5292 · python/cpython · GitHub
Open Graph Title: bpo-32436: Don't use native popcount() (also fixes bpo-32641) by 1st1 · Pull Request #5292 · python/cpython
X Title: bpo-32436: Don't use native popcount() (also fixes bpo-32641) by 1st1 · Pull Request #5292 · python/cpython
Description: SSE 4.2 is pretty recent is there's plenty of hardware out there that doesn't support it. To minimize the risk of CPython build not running on older CPUs it's easier to just stop using the popcnt instruction. I used the following micro-benchmark to make a decision to drop native popcount and always use the portable fallback code: import time from _testcapi import hamt h = hamt() for i in range(10000): h = h.set(str(i), i) print(len(h), h.get('123')) st = time.monotonic() for _ in range(10**6): h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') h.get('123') print(f'{time.monotonic() - st:.3f}s') The results were the same on both with/without popcount builds. To test the popcount instruction I've compiled CPython with `CFLAGS="-march=native". lldb session: {pydev} ~/d/p/cpython (master %) » lldb -- ./python.exe t.py (lldb) target create "./python.exe" Current executable set to './python.exe' (x86_64). (lldb) settings set -- target.run-args "t.py" (lldb) breakpoint set --name hamt_bitcount Breakpoint 1: 5 locations. (lldb) run Process 59304 launched: './python.exe' (x86_64) python.exe was compiled with optimization - stepping may behave oddly; variables may not be available. Process 59304 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.3 frame #0: 0x00000001001171f9 python.exe`hamt_node_bitmap_assoc [inlined] hamt_bitcount(i=0) at hamt.c:446 [opt] 443 #if defined(__GNUC__) && (__GNUC__ > 4) 444 return (uint32_t)__builtin_popcountl(i); 445 #elif defined(__clang__) && (__clang_major__ > 3) -> 446 return (uint32_t)__builtin_popcountl(i); 447 #elif defined(_MSC_VER) 448 return (uint32_t)__popcnt(i); 449 #else Target 0: (python.exe) stopped. (lldb) disassemble --pc python.exe`hamt_node_bitmap_assoc: -> 0x1001171f9 <+41>: popcntq %rdi, %r12 0x1001171fe <+46>: btl %r13d, �x 0x100117202 <+50>: jae 0x1001173e6 ; <+534> at hamt.c 0x100117208 <+56>: leal (%r12,%r12), �x https://bugs.python.org/issue32436
Open Graph Description: SSE 4.2 is pretty recent is there's plenty of hardware out there that doesn't support it. To minimize the risk of CPython build not running on older CPUs it's easier to just stop using ...
X Description: SSE 4.2 is pretty recent is there's plenty of hardware out there that doesn't support it. To minimize the risk of CPython build not running on older CPUs it's easier to just...
Opengraph URL: https://github.com/python/cpython/pull/5292
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:15bc912a-c4ba-7e19-2c72-470c870e74fe |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E242:11A2A:A64F8CE:A9C2445:6A50B4A2 |
| html-safe-nonce | fca6a69c80030f7570b07a94a8ea25ef2f3758ed955543b2264587f99fb6d5f8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjQyOjExQTJBOkE2NEY4Q0U6QTlDMjQ0NTo2QTUwQjRBMiIsInZpc2l0b3JfaWQiOiIxMjA5MjY5MjAwOTgxMzc0MTE0IiwicmVnaW9uX2VkZ2UiOiJzZWEiLCJyZWdpb25fcmVuZGVyIjoic2VhIn0= |
| visitor-hmac | a4216bb2dd929daa6cf9b5a3500223cf5126bb341c34d22fa92db28372385a5e |
| hovercard-subject-tag | pull_request:164745363 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/5292/files |
| twitter:image | https://avatars.githubusercontent.com/u/239003?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/239003?s=400&v=4 |
| og:image:alt | SSE 4.2 is pretty recent is there's plenty of hardware out there that doesn't support it. To minimize the risk of CPython build not running on older CPUs it's easier to just stop using ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 63772747707af4093f0d5fc7aa1bb3bb55f412a9865207c4f421aa34c64cc404 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ded53fe94e3ff1bb4dbf8cc77e285396c92580fb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width