lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87in0ijxbp.fsf@vitty.brq.redhat.com>
Date:   Tue, 27 Nov 2018 17:32:10 +0100
From:   Vitaly Kuznetsov <vkuznets@...hat.com>
To:     Michael Kelley <mikelley@...rosoft.com>,
        Roman Kagan <rkagan@...tuozzo.com>,
        "KY Srinivasan" <kys@...rosoft.com>,
        Haiyang Zhang <haiyangz@...rosoft.com>,
        Stephen Hemminger <sthemmin@...rosoft.com>
Cc:     "kvm\@vger.kernel.org" <kvm@...r.kernel.org>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Radim Krčmář <rkrcmar@...hat.com>,
        "linux-kernel\@vger.kernel.org" <linux-kernel@...r.kernel.org>,
        "x86\@kernel.org" <x86@...nel.org>
Subject: RE: [PATCH v2 1/4] x86/hyper-v: move synic/stimer control structures definitions to hyperv-tlfs.h

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 <stdint.h>

#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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ