From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astgI-0001gC-H9 for qemu-devel@nongnu.org; Wed, 20 Apr 2016 11:04:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1astgD-0002WT-Gf for qemu-devel@nongnu.org; Wed, 20 Apr 2016 11:04:42 -0400 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]:35293) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1astgD-0002WC-13 for qemu-devel@nongnu.org; Wed, 20 Apr 2016 11:04:37 -0400 Received: by mail-qk0-x241.google.com with SMTP id k126so2190589qke.2 for ; Wed, 20 Apr 2016 08:04:36 -0700 (PDT) Sender: Richard Henderson References: <1460044433-19282-1-git-send-email-sergey.fedorov@linaro.org> <1460044433-19282-6-git-send-email-sergey.fedorov@linaro.org> <87potkvc2h.fsf@linaro.org> From: Richard Henderson Message-ID: <57179A82.4050209@twiddle.net> Date: Wed, 20 Apr 2016 08:04:34 -0700 MIME-Version: 1.0 In-Reply-To: <87potkvc2h.fsf@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 05/11] tcg/i386: Make direct jump patching thread-safe List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Alex_Benn=c3=a9e?= , Sergey Fedorov Cc: qemu-devel@nongnu.org, Sergey Fedorov , Paolo Bonzini , Peter Crosthwaite On 04/20/2016 02:55 AM, Alex Bennée wrote: >> +static void tcg_out_nopn(TCGContext *s, int n) >> +{ >> + static const uint8_t nop1[] = { 0x90 }; >> + static const uint8_t nop2[] = { 0x66, 0x90 }; >> + static const uint8_t nop3[] = { 0x8d, 0x76, 0x00 }; >> + static const uint8_t *const nopn[] = { nop1, nop2, nop3 }; >> + int i; >> + assert(n <= ARRAY_SIZE(nopn)); >> + for (i = 0; i < n; ++i) { >> + tcg_out8(s, nopn[n - 1][i]); >> + } >> +} > > *shudder* I recall x86 instruction encoding is weird. Maybe a comment > for the function to describe the 3 forms of NOP we have here? I think I'd prefer to drop the tables and do /* Emit 1 or 2 operand size prefixes for the standard one byte nop, xchg %eax,%eax, forming xchg %ax,%ax. All cores accept the duplicate prefix, and all of the interesting recent cores can decode and discard the duplicates in a single cycle. */ for (i = 1; i < n; ++i) { tcg_out8(s, 0x66); } tcg_out8(s, 0x90); r~