Exemplo n.º 1
0
 def test_elaborate_iadd_cout_simple(self):
     # type: () -> None
     x = Var('x')
     y = Var('y')
     a = Var('a')
     c_out = Var('c_out')
     bvc_out = Var('bvc_out')
     bc_out = Var('bc_out')
     bvx = Var('bvx')
     bvy = Var('bvy')
     bva = Var('bva')
     bvone = Var('bvone')
     bvzero = Var('bvzero')
     r = Rtl(
             (a, c_out) << iadd_cout.i32(x, y),
     )
     r.cleanup_concrete_rtl()
     sem = elaborate(r)
     exp = Rtl(
         bvx << prim_to_bv.i32(x),
         bvy << prim_to_bv.i32(y),
         bva << bvadd.bv32(bvx, bvy),
         bc_out << bvult.bv32(bva, bvx),
         bvone << bv_from_imm64(imm64(1)),
         bvzero << bv_from_imm64(imm64(0)),
         bvc_out << bvite(bc_out, bvone, bvzero),
         a << prim_from_bv.i32(bva),
         c_out << prim_from_bv.b1(bvc_out)
     )
     exp.cleanup_concrete_rtl()
     assert concrete_rtls_eq(sem, exp)
Exemplo n.º 2
0
                          chain=shared.expand)

a = Var('a')
dead = Var('dead')
x = Var('x')
xhi = Var('xhi')
y = Var('y')
a1 = Var('a1')
a2 = Var('a2')

#
# Division and remainder.
#
intel_expand.legalize(
    a << insts.udiv(x, y),
    Rtl(xhi << insts.iconst(imm64(0)), (a, dead) << x86.udivmodx(x, xhi, y)))

intel_expand.legalize(
    a << insts.urem(x, y),
    Rtl(xhi << insts.iconst(imm64(0)), (dead, a) << x86.udivmodx(x, xhi, y)))

for ty in [i32, i64]:
    intel_expand.legalize(
        a << insts.sdiv.bind(ty)(x, y),
        Rtl(xhi << insts.sshr_imm(x, imm64(ty.lane_bits() - 1)),
            (a, dead) << x86.sdivmodx(x, xhi, y)))

# The srem expansion requires custom code because srem INT_MIN, -1 is not
# allowed to trap.
intel_expand.custom_legalize(insts.srem, 'expand_srem')
Exemplo n.º 3
0
a = Var('a')
dead = Var('dead')
x = Var('x')
xhi = Var('xhi')
y = Var('y')
a1 = Var('a1')
a2 = Var('a2')

#
# Division and remainder.
#
intel_expand.legalize(
        a << insts.udiv(x, y),
        Rtl(
            xhi << insts.iconst(imm64(0)),
            (a, dead) << x86.udivmodx(x, xhi, y)
        ))

intel_expand.legalize(
        a << insts.urem(x, y),
        Rtl(
            xhi << insts.iconst(imm64(0)),
            (dead, a) << x86.udivmodx(x, xhi, y)
        ))

for ty in [i32, i64]:
    intel_expand.legalize(
            a << insts.sdiv.bind(ty)(x, y),
            Rtl(
                xhi << insts.sshr_imm(x, imm64(ty.lane_bits() - 1)),
import base.formats  # noqa

GROUP = InstructionGroup("primitive_macros", "Semantic macros instruction set")
AnyBV = TypeVar('AnyBV', bitvecs=True, doc="")
x = Var('x')
y = Var('y')
imm = Var('imm')
a = Var('a')

#
# Bool-to-bv1
#
BV1 = TypeVar("BV1", bitvecs=(1, 1), doc="")
bv1_op = Operand('bv1_op', BV1, doc="")
cond_op = Operand("cond", b1, doc="")
bool2bv = Instruction('bool2bv',
                      r"""Convert a b1 value to a 1-bit BV""",
                      ins=cond_op,
                      outs=bv1_op)

v1 = Var('v1')
v2 = Var('v2')
bvone = Var('bvone')
bvzero = Var('bvzero')
bool2bv.set_semantics(
    v1 << bool2bv(v2),
    Rtl(bvone << bv_from_imm64(imm64(1)), bvzero << bv_from_imm64(imm64(0)),
        v1 << bvite(v2, bvone, bvzero)))

GROUP.close()
Exemplo n.º 5
0
GROUP = InstructionGroup("primitive_macros", "Semantic macros instruction set")
AnyBV = TypeVar('AnyBV', bitvecs=True, doc="")
x = Var('x')
y = Var('y')
imm = Var('imm')
a = Var('a')

#
# Bool-to-bv1
#
BV1 = TypeVar("BV1", bitvecs=(1, 1), doc="")
bv1_op = Operand('bv1_op', BV1, doc="")
cond_op = Operand("cond", b1, doc="")
bool2bv = Instruction(
        'bool2bv', r"""Convert a b1 value to a 1-bit BV""",
        ins=cond_op, outs=bv1_op)

v1 = Var('v1')
v2 = Var('v2')
bvone = Var('bvone')
bvzero = Var('bvzero')
bool2bv.set_semantics(
        v1 << bool2bv(v2),
        Rtl(
            bvone << bv_from_imm64(imm64(1)),
            bvzero << bv_from_imm64(imm64(0)),
            v1 << bvite(v2, bvone, bvzero)
        ))

GROUP.close()
x86_expand.custom_legalize(insts.fcvt_to_uint, 'expand_fcvt_to_uint')

# Count leading and trailing zeroes, for baseline x86_64
c_minus_one = Var('c_minus_one')
c_thirty_one = Var('c_thirty_one')
c_thirty_two = Var('c_thirty_two')
c_sixty_three = Var('c_sixty_three')
c_sixty_four = Var('c_sixty_four')
index1 = Var('index1')
r2flags = Var('r2flags')
index2 = Var('index2')

x86_expand.legalize(
    a << insts.clz.i64(x),
    Rtl(
        c_minus_one << insts.iconst(imm64(-1)),
        c_sixty_three << insts.iconst(imm64(63)),
        (index1, r2flags) << x86.bsr(x),
        index2 << insts.selectif(intcc.eq, r2flags, c_minus_one, index1),
        a << insts.isub(c_sixty_three, index2),
    ))

x86_expand.legalize(
    a << insts.clz.i32(x),
    Rtl(
        c_minus_one << insts.iconst(imm64(-1)),
        c_thirty_one << insts.iconst(imm64(31)),
        (index1, r2flags) << x86.bsr(x),
        index2 << insts.selectif(intcc.eq, r2flags, c_minus_one, index1),
        a << insts.isub(c_thirty_one, index2),
    ))
Exemplo n.º 7
0
intel_expand.custom_legalize(insts.fcvt_to_uint, 'expand_fcvt_to_uint')

# Count leading and trailing zeroes, for baseline x86_64
c_minus_one = Var('c_minus_one')
c_thirty_one = Var('c_thirty_one')
c_thirty_two = Var('c_thirty_two')
c_sixty_three = Var('c_sixty_three')
c_sixty_four = Var('c_sixty_four')
index1 = Var('index1')
r2flags = Var('r2flags')
index2 = Var('index2')

intel_expand.legalize(
    a << insts.clz.i64(x),
    Rtl(
        c_minus_one << insts.iconst(imm64(-1)),
        c_sixty_three << insts.iconst(imm64(63)),
        (index1, r2flags) << x86.bsr(x),
        index2 << insts.selectif(intcc.eq, r2flags, c_minus_one, index1),
        a << insts.isub(c_sixty_three, index2),
    ))

intel_expand.legalize(
    a << insts.clz.i32(x),
    Rtl(
        c_minus_one << insts.iconst(imm64(-1)),
        c_thirty_one << insts.iconst(imm64(31)),
        (index1, r2flags) << x86.bsr(x),
        index2 << insts.selectif(intcc.eq, r2flags, c_minus_one, index1),
        a << insts.isub(c_thirty_one, index2),
    ))