Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add lots missed instructions and allow ignore some symbols #3

Merged
merged 2 commits into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion asm2asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ def __call__(self, *args, **kwargs):
'MOVABSQ' : x86_64.MOV,
'VCMPEQPS' : VectorCompare(x86_64.VCMPPS, 0x00),
'VCMPTRUEPS' : VectorCompare(x86_64.VCMPPS, 0x0f),
'VCVTSI2SDL' : x86_64.VCVTSI2SD,
'VCVTSI2SDQ' : x86_64.VCVTSI2SD,
'CVTSI2SDQ' : x86_64.CVTSI2SD,
'CVTSI2SDL' : x86_64.CVTSI2SD,
}

@functools.cached_property
Expand Down Expand Up @@ -532,6 +536,14 @@ def _instr_size(self) -> Optional[int]:
'MOVSBQ' : 1,
'MOVSWQ' : 2,
'MOVSLQ' : 4,
'SETNE' : 1,
'SETNZ' : 1,
'SETLE' : 1,
'SETNLE' : 1,
'SETG' : 1,
'SETNG' : 1,
'SETGE' : 1,
'SETNGE' : 1,
}

@staticmethod
Expand Down Expand Up @@ -1846,6 +1858,7 @@ def _alloc_instr(self, instr: Instruction):
__instr_repl__ = {
'movdqa' : 'movdqu',
'movaps' : 'movups',
'movapd' : 'movupd',
'vmovdqa' : 'vmovdqu',
'vmovaps' : 'vmovups',
'vmovapd' : 'vmovupd',
Expand Down Expand Up @@ -2493,6 +2506,12 @@ def make_subr_filename(name: str) -> str:
else:
return '%s_subr_%s.go' % ('_'.join(base[:-1]), base[-1])


IGNORED_STUBS = {
"_do_xprintf",
"_write_syscall"
}

def main():
# check for arguments
if len(sys.argv) < 3:
Expand Down Expand Up @@ -2576,6 +2595,13 @@ def main():
print('import (\n\t`github.com/bytedance/sonic/loader`\n)', file = fp)
print(file = fp)
print('const (', file = fp)

# remove duplicated symbols
keys = list(asm.code.funcs.keys())
for name in keys:
if name in IGNORED_STUBS:
asm.code.funcs.pop(name)

for name in asm.code.funcs.keys():
addr = asm.code.get(name)
if addr is not None:
Expand Down Expand Up @@ -2614,7 +2640,7 @@ def main():
print('var _cfunc%s = []loader.CFunc{' % name, file = fp)
print(' {"%s_entry", 0, _entry_%s, 0, nil},' % (name, name), file = fp)
print(' {"%s", _entry_%s, _size_%s, _stack_%s, _pcsp_%s},' % (name, name, name, name, name), file = fp)
print('}', file = fp)
print('}', file = fp)

else:
print(file = fp)
Expand Down
Loading