From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932352AbcHHTiX (ORCPT ); Mon, 8 Aug 2016 15:38:23 -0400 Received: from mail.skyhub.de ([78.46.96.112]:46415 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753869AbcHHTRU (ORCPT ); Mon, 8 Aug 2016 15:17:20 -0400 Date: Mon, 8 Aug 2016 21:17:01 +0200 From: Borislav Petkov To: Jiri Kosina Cc: Peter Zijlstra , Linus Torvalds , Ville Syrj??l?? , Linux Kernel Mailing List , the arch/x86 maintainers , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski , Brian Gerst , Denys Vlasenko , Thomas Gleixner , Ingo Molnar Subject: Re: [PATCH] x86/hweight: Don't clobber %rdi Message-ID: <20160808191701.GH511@nazgul.tnic> References: <1470677729-10561-1-git-send-email-ville.syrjala@linux.intel.com> <20160808183208.GB30192@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 08, 2016 at 08:53:16PM +0200, Jiri Kosina wrote: > Ville's patch is the proper thing to do; I still think the comments > probably should be removed as they might provide more confusion than help, > but that's a separate discussion. Right, so while trying to debug this with a pen and paper, I found that adding a subsript to the w variable makes it more understandable. I.e., something like this: w_1 -= (w >> 1) & 0x55555555; w_2 = (w_1 & 0x33333333) + ((w_1 >> 2) & 0x33333333); and then you'd have movl %eax, %edx # w shrl %edx # w >>= 1 andl $0x55555555, %edx # (w >> 1) & 0x55555555 subl %edx, %eax # w_1 = w - ... movl %eax, %edx # w_1 shrl $2, %eax # w_1 >>= 2 andl $0x33333333, %edx # (w_1 >> 2) & 0x33333333 andl $0x33333333, %eax # w_1 &= 0x33333333 addl %edx, %eax # w_2 = ... + ... ... Anyway, something like that. I find that more readable TBH. Thanks and thanks for confirming Ville's patch fixes it on your box. -- Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply. --