Debian Codegraph @

rpython/jit/backend/riscv/instruction_util.py

raw symbols SCIP
1 #!/usr/bin/env python
2
3 from rpython.jit.backend.riscv.arch import SINT12_IMM_MAX, SINT12_IMM_MIN
4 from rpython.jit.metainterp.resoperation import rop
5
6
7 _COMPARE_OPS_FOR_BRANCH_INST = {
8 rop.INT_LT: None,
9 rop.INT_LE: None,
10 rop.INT_EQ: None,
11 rop.INT_NE: None,
12 rop.INT_GT: None,
13 rop.INT_GE: None,
14
15 rop.UINT_LT: None,
16 rop.UINT_LE: None,
17 rop.UINT_GT: None,
18 rop.UINT_GE: None,
19
20 rop.INT_IS_ZERO: None,
21 rop.INT_IS_TRUE: None,
22
23 rop.PTR_EQ: None,
24 rop.PTR_NE: None,
25 rop.INSTANCE_PTR_EQ: None,
26 rop.INSTANCE_PTR_NE: None,
27 }
28
29 def can_fuse_into_compare_and_branch(opnum):
30 """Returns whether a ResOperation can be fused into the following
31 GuardResOp or COND_CALL op."""
32 return opnum in _COMPARE_OPS_FOR_BRANCH_INST
33
34 COND_INVALID = 0
35 COND_BEQ = 1
36 COND_BNE = 2
37 COND_BGE = 3
38 COND_BLT = 4
39 COND_BGEU = 5
40 COND_BLTU = 6
41
42 _NEGATED_BRANCH_INST = [
43 COND_INVALID,
44 COND_BNE,
45 COND_BEQ,
46 COND_BLT,
47 COND_BGE,
48 COND_BLTU,
49 COND_BGEU,
50 ]
51
52 def get_negated_branch_inst(branch_inst):
53 """Returns the branch op with the negated condition."""
54 return _NEGATED_BRANCH_INST[branch_inst]
55
56 def check_imm_arg(imm):
57 return imm >= SINT12_IMM_MIN and imm <= SINT12_IMM_MAX
58
59 def check_simm21_arg(imm):
60 return imm >= -2**20 and imm <= 2**20 - 1 and imm & 0x1 == 0