GH-100982: Break up COMPARE_AND_BRANCH (GH-102801)

This commit is contained in:
Brandt Bucher 2023-03-23 15:25:09 -07:00 committed by GitHub
parent bd063756b3
commit 0444ae2487
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 377 additions and 479 deletions

View file

@ -2800,6 +2800,15 @@ check_compare(struct compiler *c, expr_ty e)
return SUCCESS;
}
static const int compare_masks[] = {
[Py_LT] = COMPARISON_LESS_THAN,
[Py_LE] = COMPARISON_LESS_THAN | COMPARISON_EQUALS,
[Py_EQ] = COMPARISON_EQUALS,
[Py_NE] = COMPARISON_NOT_EQUALS,
[Py_GT] = COMPARISON_GREATER_THAN,
[Py_GE] = COMPARISON_GREATER_THAN | COMPARISON_EQUALS,
};
static int compiler_addcompare(struct compiler *c, location loc,
cmpop_ty op)
{
@ -2840,7 +2849,7 @@ static int compiler_addcompare(struct compiler *c, location loc,
}
/* cmp goes in top bits of the oparg, while the low bits are used by quickened
* versions of this opcode to store the comparison mask. */
ADDOP_I(c, loc, COMPARE_OP, cmp << 4);
ADDOP_I(c, loc, COMPARE_OP, (cmp << 4) | compare_masks[cmp]);
return SUCCESS;
}