All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Richard Henderson <rth@twiddle.net>,
	"Li, Liang Z" <liang.z.li@intel.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "amit.shah@redhat.com" <amit.shah@redhat.com>,
	"quintela@redhat.com" <quintela@redhat.com>,
	"dgilbert@redhat.com" <dgilbert@redhat.com>,
	"stefanha@redhat.com" <stefanha@redhat.com>,
	"mst@redhat.com" <mst@redhat.com>
Subject: Re: [Qemu-devel] [v3 1/3] cutils: add avx2 instruction optimization
Date: Thu, 10 Dec 2015 10:03:50 +0100	[thread overview]
Message-ID: <56693FF6.6020807@redhat.com> (raw)
In-Reply-To: <56684141.5020504@twiddle.net>



On 09/12/2015 15:57, Richard Henderson wrote:
>> I think you means the ' __attribute__((target("avx2")))', I have tried
>> this way, the issue here is:
>>   without the ' -mavx2' option for gcc, there are compiling error: 
>> '__m256i undeclared', the __attribute__((target("avx2")))
>> can't solve this issue.  Any idea?
> 
> You're right that you can't use the normal __m256i, as it doesn't get
> declared.

It should be declared.  *intrin.h uses #pragma GCC target and always
defines all vector types.

In fact, the following compiles for me with just "gcc foo.c" under
GCC 5.x:

#include <immintrin.h>

// #if defined CONFIG_IFUNC && defined CONFIG_AVX2
#pragma GCC push_options
#pragma GCC target("avx2")
#define AVX2_VECTYPE        __m256i
#define AVX2_SPLAT(p)       _mm256_set1_epi8(*(p))
#define AVX2_ALL_EQ(v1, v2) \
    (_mm256_movemask_epi8(_mm256_cmpeq_epi8(v1, v2)) == 0xFFFFFFFF)
#define AVX2_VEC_OR(v1, v2) (_mm256_or_si256(v1, v2))

size_t buffer_find_nonzero_offset_avx2(const void *buf, size_t len)
{
    const AVX2_VECTYPE *p = buf;
    const AVX2_VECTYPE zero = (AVX2_VECTYPE){0};
    size_t i;

    if (!len) {
        return 0;
    }

    for (i = 0; i < 4; i++) {
        if (!AVX2_ALL_EQ(p[i], zero)) {
            return i * sizeof(AVX2_VECTYPE);
        }
    }

    for (i = 4; i < len / sizeof(AVX2_VECTYPE); i += 4) {
        AVX2_VECTYPE tmp0 = AVX2_VEC_OR(p[i + 0], p[i + 1]);
        AVX2_VECTYPE tmp1 = AVX2_VEC_OR(p[i + 2], p[i + 3]);
        AVX2_VECTYPE tmp2 = AVX2_VEC_OR(p[i + 4], p[i + 5]);
        AVX2_VECTYPE tmp3 = AVX2_VEC_OR(p[i + 6], p[i + 7]);
        AVX2_VECTYPE tmp01 = AVX2_VEC_OR(tmp0, tmp1);
        AVX2_VECTYPE tmp23 = AVX2_VEC_OR(tmp2, tmp3);
        if (!AVX2_ALL_EQ(AVX2_VEC_OR(tmp01, tmp23), zero)) {
            break;
        }
    }

    return i * sizeof(AVX2_VECTYPE);
}

#pragma GCC pop_options
// #endif

so perhaps the configure test is testing the wrong thing?

Paolo

  parent reply	other threads:[~2015-12-10  9:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-08 12:08 [Qemu-devel] [v3 0/3] add avx2 instruction optimization Liang Li
2015-12-08 12:08 ` [Qemu-devel] [v3 1/3] cutils: " Liang Li
2015-12-08 16:09   ` Richard Henderson
2015-12-09  9:32     ` Li, Liang Z
2015-12-09 14:57       ` Richard Henderson
2015-12-10  1:10         ` Li, Liang Z
2015-12-10  9:03         ` Paolo Bonzini [this message]
2015-12-10  9:22           ` Li, Liang Z
2015-12-10  9:51             ` Paolo Bonzini
2015-12-08 12:08 ` [Qemu-devel] [v3 2/3] configure: detect ifunc attribute Liang Li
2015-12-08 12:08 ` [Qemu-devel] [v3 3/3] configure: add options to config avx2 Liang Li
2015-12-08 12:54   ` Peter Maydell
2015-12-08 14:18     ` Li, Liang Z

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56693FF6.6020807@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=liang.z.li@intel.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=rth@twiddle.net \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.