Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp30569imu; Tue, 27 Nov 2018 08:36:33 -0800 (PST) X-Google-Smtp-Source: AJdET5eozCctBzWUwtKFchgY+P1rItXsvG3lhEtPC86qBAWDKv4xxl2TqwKtkBJ/yC2nWhSIZiZI X-Received: by 2002:a62:1f9d:: with SMTP id l29mr33517208pfj.14.1543336593787; Tue, 27 Nov 2018 08:36:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543336593; cv=none; d=google.com; s=arc-20160816; b=H0kA2J9mB/XZgm+QwVZ6sHtonVQMd9QW14zjK1LP5WGLHp6k6iIfRczQPWiYybhUGw MuCLNhP3mGruGDPvjtn+zbjtp9rKWBaTDeK27Z13yzrTeAF8+bYU9o+S0BbiIgaVx7yG e4415GrOLGRgd2jn3ks6/Bh5kdMnoHuBB/CjD/wfrZMziWakRroB/I/XbGLZ3pENU1zA kGcNBr3XQqKpdd/wxpps8shO4Yek8b8RS1pJg37iTZrxGMqX4KPDMVMiPe6X0pPsipvP AKhtnYjIKBX//dHpDguF/PQkssPgkYRVwalQ5P+1CVdFO/QlvodfCdiTFFOavLp2mKU/ 3A8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=WEAXi5PmoKSThdEFLDBFTe/SdBhfVRaO+Iu35VNImpY=; b=FP4utivCG2sRe1CC0vfqtTIC3qzv8QIH0/ttchY7MMpU2NY58h1TycQstS133f4g/m 2Gh4nt/m+vvtyJX1tah/gBzthWZCeq38D/sGsvHWlVv+YR4ursqfM7fg4B2G0jAYg6Td xRQs0dsRjHL59nqOy467C9hWrFKcYdJ87P2nmnJLLC9XEsCR5i3nhdkKQtcyGGIBmJWC DDVXZAoD3/aaoLrp6LXjxi8xZkk3/tMN1p6XLO7W/Z7nSOgIcSEeIdDPjAfchqmmGVpa qUsrX8wVxVdTJ46nHi16Qa8t10Cs8dr3WaabHfi6pWB5f7k9ukvN8CitH+cDQq+1UpCs +fWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1si3821983pgs.417.2018.11.27.08.36.07; Tue, 27 Nov 2018 08:36:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731183AbeK1Dak (ORCPT + 99 others); Tue, 27 Nov 2018 22:30:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45974 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726402AbeK1Dak (ORCPT ); Tue, 27 Nov 2018 22:30:40 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 77F0A83F3D; Tue, 27 Nov 2018 16:32:13 +0000 (UTC) Received: from vitty.brq.redhat.com.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73B2E100191D; Tue, 27 Nov 2018 16:32:11 +0000 (UTC) From: Vitaly Kuznetsov To: Michael Kelley , Roman Kagan , "KY Srinivasan" , Haiyang Zhang , Stephen Hemminger Cc: "kvm\@vger.kernel.org" , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , "linux-kernel\@vger.kernel.org" , "x86\@kernel.org" Subject: RE: [PATCH v2 1/4] x86/hyper-v: move synic/stimer control structures definitions to hyperv-tlfs.h In-Reply-To: References: <20181126154732.23025-1-vkuznets@redhat.com> <20181126154732.23025-2-vkuznets@redhat.com> <20181126200413.GA7852@rkaganb.sw.ru> <87wooyk6na.fsf@vitty.brq.redhat.com> Date: Tue, 27 Nov 2018 17:32:10 +0100 Message-ID: <87in0ijxbp.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 27 Nov 2018 16:32:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Out of pure curiosity I decided to check what 'gcc -O3' produces when we use bitfields and masks. As of 'gcc version 8.2.1 20181105 (Red Hat 8.2.1-5) (GCC)' 1) bitfields: struct abc { int enabled:1; int _pad:7; int vec:8; }; int is_good(struct abc *s) { if (s->enabled) return s->vec; else return 0; } results in is_good: xorl %eax, %eax testb $1, (%rdi) je .L1 movsbl 1(%rdi), %eax .L1: ret 2) masks #include #define S_ENABLED 1 #define S_VEC_MASK 0xff00 #define S_VEC_SHIFT 8 int is_good(uint16_t *s) { if (*s & S_ENABLED) return (*s & S_VEC_MASK) >> S_VEC_SHIFT; else return 0; } results in is_good: movzwl (%rdi), %edx movzbl %dh, %eax andl $1, %edx movl $0, %edx cmove %edx, %eax ret so bitfields version looks somewhat more efficient. I'm not sure if my example is too synthetic though. -- Vitaly