From ab24aaeca303abadd987c2a4ab3a56efe755c37c Mon Sep 17 00:00:00 2001 From: Kirill Smelkov Date: Fri, 16 Nov 2012 00:04:56 +0400 Subject: [PATCH] i386: We can change 'lea 0(%ebp),r' to 'mov %ebp,r' Because that mov is 1 byte shorter, look: int *func() { return __builtin_frame_address(0); } before patch: 00000000 : 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 81 ec 00 00 00 00 sub $0x0,%esp 9: 8d 45 00 lea 0x0(%ebp),%eax // <- here c: e9 00 00 00 00 jmp 11 11: c9 leave 12: c3 ret after patch: 00000000 : 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 81 ec 00 00 00 00 sub $0x0,%esp 9: 89 e8 mov %ebp,%eax // <- here b: e9 00 00 00 00 jmp 10 10: c9 leave 11: c3 ret --- i386-gen.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/i386-gen.c b/i386-gen.c index 66355598..c3f03c78 100644 --- a/i386-gen.c +++ b/i386-gen.c @@ -260,8 +260,13 @@ ST_FUNC void load(int r, SValue *sv) o(0xb8 + r); /* mov $xx, r */ gen_addr32(fr, sv->sym, fc); } else if (v == VT_LOCAL) { - o(0x8d); /* lea xxx(%ebp), r */ - gen_modrm(r, VT_LOCAL, sv->sym, fc); + if (fc) { + o(0x8d); /* lea xxx(%ebp), r */ + gen_modrm(r, VT_LOCAL, sv->sym, fc); + } else { + o(0x89); + o(0xe8 + r); /* mov %ebp, r */ + } } else if (v == VT_CMP) { oad(0xb8 + r, 0); /* mov $0, r */ o(0x0f); /* setxx %br */ -- 2.11.4.GIT