]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-118093: Don't lose confidence when tracing through 100% biased branches (GH-124813)
authorBrandt Bucher <brandtbucher@microsoft.com>
Wed, 2 Oct 2024 19:24:37 +0000 (12:24 -0700)
committerGitHub <noreply@github.com>
Wed, 2 Oct 2024 19:24:37 +0000 (19:24 +0000)
Misc/NEWS.d/next/Core_and_Builtins/2024-09-30-16-39-37.gh-issue-118093.J2A3gz.rst [new file with mode: 0644]
Python/optimizer.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-09-30-16-39-37.gh-issue-118093.J2A3gz.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-30-16-39-37.gh-issue-118093.J2A3gz.rst
new file mode 100644 (file)
index 0000000..2e5c645
--- /dev/null
@@ -0,0 +1,2 @@
+Improve the experimental JIT compiler's ability to stay "on trace" when
+encountering highly-biased branches.
index 978649faa04d45a934615b0ab21de4a354896d5f..b876b6c2bd72fddc61945ae795d6ae1322ec5d48 100644 (file)
@@ -643,14 +643,12 @@ translate_bytecode_to_trace(
                 int bitcount = _Py_popcount32(counter);
                 int jump_likely = bitcount > 8;
                 /* If bitcount is 8 (half the jumps were taken), adjust confidence by 50%.
-                   If it's 16 or 0 (all or none were taken), adjust by 10%
-                   (since the future is still somewhat uncertain).
                    For values in between, adjust proportionally. */
                 if (jump_likely) {
-                    confidence = confidence * (bitcount + 2) / 20;
+                    confidence = confidence * bitcount / 16;
                 }
                 else {
-                    confidence = confidence * (18 - bitcount) / 20;
+                    confidence = confidence * (16 - bitcount) / 16;
                 }
                 uint32_t uopcode = BRANCH_TO_GUARD[opcode - POP_JUMP_IF_FALSE][jump_likely];
                 DPRINTF(2, "%d: %s(%d): counter=%04x, bitcount=%d, likely=%d, confidence=%d, uopcode=%s\n",