Ejemplo n.º 1
0
def do_it(o, i_name):
    with open(i_name, 'rb') as i:
        code = '\n'.join(chew_code(i))
    comment = P.g_autogenerated_patt % os.path.basename(sys.argv[0])
    o.write(comment.replace('//', '#'))
    P.write_asm_procedure_header(o, g_hooligan)
    P.write_asm_inside(o, code)

    code = P.cutoff_comments(g_code)
    xmm_save = P.save_registers_in_xmm(code, 5)
    P.save_in_xmm(code, xmm_save)

    code = '\n'.join(code).replace('@call', 'call ' + g_hooligan)
    for k, v in xmm_save.items():
        code = code.replace('!restore ' + k, 'movq %s, %s' % (v, k))
    code = P.replace_symbolic_names_wr(code, g_var_map)

    o.write('\n')
    P.write_asm_procedure_header(o, P.guess_subroutine_name(sys.argv[2]))
    P.write_asm_inside(o, code + '\nretq')
Ejemplo n.º 2
0
def do_it(o):
    preamble = P.cutoff_comments(g_preamble)
    xmm_save = {}
    if not g_writing_macro:
        xmm_save = P.save_registers_in_xmm(preamble, 11)
    p = list(range(14))
    code = mul_code(0, preamble, p)
    m1 = P.cutoff_comments(g_mul_1)
    m2 = P.cutoff_comments(g_mul_2)
    code += mul_code(1, m1, p)
    q = [int(x, 16) for x in g_perm.split(' ')]
    for i in range(2, 5):
        code += mul_code(i, m2, p)
        p = P.composition(p, q)
    tail = m2[:-1]
    # extract rp as soon as s6 becomes useless
    tail = [tail[0], 'movq rp, s6'] + tail[1:] + P.cutoff_comments(g_tail)
    code += mul_code(5, tail, p)

    if not g_writing_macro:
        P.save_in_xmm(code, xmm_save)
        P.insert_restore(code, xmm_save)
    cook_asm(o, code, xmm_save, g_var_map)
Ejemplo n.º 3
0
def cook_asm(name, o, code):
    xmm_save = P.save_registers_in_xmm(code, 9)

    P.insert_restore(code, xmm_save)
    code = '\n'.join(code)
    for k, v in xmm_save.items():
        code = code.replace('!restore ' + k, 'movq %s, %s' % (v, k))

    m = 'rp,rdi up,rsi w7,rcx wB,rbp wA,rbx w9,r12 w8,r13 w6,r14 w5,r15 '
    m += 'w0,rax w1,r8 w2,r9 w3,r10 w4,r11 dd,rdx v14,ymm15 v47,ymm14 t0,xmm13'
    r = {}
    for x in m.split(' '):
        y = x.split(',')
        r[y[0]] = '%' + y[1]
    code = P.replace_symbolic_vars_name(code, r)

    # replace ymm with xmm in all movq
    code = '\n'.join([replace_ymm_by_xmm(x) for x in code.split('\n')])

    comment = P.g_autogenerated_patt % os.path.basename(sys.argv[0])
    o.write(comment.replace('//', '#'))
    P.write_asm_procedure_header(o, P.guess_subroutine_name(name))
    P.write_asm_inside(o, code + '\nretq')