From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asunI-0002Rw-Oh for qemu-devel@nongnu.org; Wed, 20 Apr 2016 12:16:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asunF-0007Vj-7U for qemu-devel@nongnu.org; Wed, 20 Apr 2016 12:16:00 -0400 Received: from mail-lf0-x235.google.com ([2a00:1450:4010:c07::235]:33774) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asunE-0007Ve-VZ for qemu-devel@nongnu.org; Wed, 20 Apr 2016 12:15:57 -0400 Received: by mail-lf0-x235.google.com with SMTP id e190so44177443lfe.0 for ; Wed, 20 Apr 2016 09:15:56 -0700 (PDT) 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> <57179A82.4050209@twiddle.net> From: Sergey Fedorov Message-ID: <5717AB3B.3040604@gmail.com> Date: Wed, 20 Apr 2016 19:15:55 +0300 MIME-Version: 1.0 In-Reply-To: <57179A82.4050209@twiddle.net> Content-Type: text/plain; charset=utf-8 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: Richard Henderson , =?UTF-8?Q?Alex_Benn=c3=a9e?= , Sergey Fedorov Cc: qemu-devel@nongnu.org, Paolo Bonzini , Peter Crosthwaite On 20/04/16 18:04, Richard Henderson wrote: > 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); It's fine if you are sure about that :) Kind regards, Sergey