From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932344AbcFCJVX (ORCPT ); Fri, 3 Jun 2016 05:21:23 -0400 Received: from merlin.infradead.org ([205.233.59.134]:51610 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752366AbcFCJVU (ORCPT ); Fri, 3 Jun 2016 05:21:20 -0400 Date: Fri, 3 Jun 2016 11:21:15 +0200 From: Peter Zijlstra To: David Carrillo-Cisneros Cc: linux-kernel@vger.kernel.org, "x86@kernel.org" , Ingo Molnar , "Yan, Zheng" , Andi Kleen , Kan Liang , Stephane Eranian Subject: Re: [PATCH 2/3] perf/x86/intel: fix for MSR_LAST_BRANCH_FROM_x quirk when no TSX Message-ID: <20160603092115.GH3190@twins.programming.kicks-ass.net> References: <1464835323-33872-1-git-send-email-davidcc@google.com> <1464835323-33872-3-git-send-email-davidcc@google.com> <20160602085352.GS3193@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 02, 2016 at 05:00:19PM +0000, David Carrillo-Cisneros wrote: > LBR_FROM_FLAG_MISPRED is at bit 63 so the bitshift wouldnt work . But I can > clean the bits unconditionally of the value, just as you said for the read > case. Argh, missed that. Ok, something like so then: #define LBR_FROM_SIGN_MASK (BIT_ULL(61) | BIT_ULL(62)) /* * Sign extend into bits 61,62 while preserving bit 63. * * This works because bits 59 and 60 are guaranteed to be sign * bits themselves. */ val = (val & ~LBR_FROM_SIGN_MASK) | ((val << 2) & LBR_FROM_SIGN_MASK); A superscalar core can evaluate the left and right hand parts of the logical or concurrently. I've not generated the code so see what GCC does with the 64bit literals, ideally it would generate code using 32bit literals and only operate on the high word, but who knows if its smart enough for that. See also: https://graphics.stanford.edu/~seander/bithacks.html#ConditionalSetOrClearBitsWithoutBranching