From owner-freebsd-ppc@FreeBSD.ORG Mon Jul 14 16:20:56 2014 Return-Path: Delivered-To: powerpc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7A642C37 for ; Mon, 14 Jul 2014 16:20:56 +0000 (UTC) Received: from mail-qc0-x22f.google.com (mail-qc0-x22f.google.com [IPv6:2607:f8b0:400d:c01::22f]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3D60E2839 for ; Mon, 14 Jul 2014 16:20:56 +0000 (UTC) Received: by mail-qc0-f175.google.com with SMTP id i8so3719418qcq.6 for ; Mon, 14 Jul 2014 09:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=BaHT85dZX+b6A89IdeXEITRefW4If9CP4zftlHk3GpE=; b=zfAkJ2osX2mjuwxlwTFScbHKFlUhGA43mQrLPuRBlt9qXng7CnhXubLRGIvE51i84p mukSeCTJkVR/KHAh6jcDlDQHoEKCvK2ZXNei9darHK+6IPX4iC1SA+Tv5E5p83ctN9pd Uodqm5tAfQU4lFy/0NEeBNXNulkytARjUh1VeDWbzw0akCukh19KQfD6S4owB8qz7pLG u4fsxLFJkg73VXqGvvincWA1J+GQUuczpCjREi9ziYz0BbSoOdINjMWpsw00ygIZosxZ Blm24wGxxI6ZyA6xSVod5JvvI74ycRjmgwCkHqgmpuiBtXnkjZwu+UXX+5aWlORBWojd w2/Q== MIME-Version: 1.0 X-Received: by 10.224.152.5 with SMTP id e5mr23572248qaw.65.1405354855304; Mon, 14 Jul 2014 09:20:55 -0700 (PDT) Sender: chmeeedalf@gmail.com Received: by 10.140.23.84 with HTTP; Mon, 14 Jul 2014 09:20:55 -0700 (PDT) In-Reply-To: <20140714154224.GA28612@regency.nsu.ru> References: <20140714154224.GA28612@regency.nsu.ru> Date: Mon, 14 Jul 2014 09:20:55 -0700 X-Google-Sender-Auth: fPgnn9NhNspX4jKtX9HIZ8aQlGY Message-ID: Subject: Re: How to convert SSEish _mm_set1_ps() into AltiVec correctly? From: Justin Hibbits To: Alexey Dokuchaev Content-Type: text/plain; charset=UTF-8 Cc: powerpc@freebsd.org X-BeenThere: freebsd-ppc@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Porting FreeBSD to the PowerPC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Jul 2014 16:20:56 -0000 On Mon, Jul 14, 2014 at 8:42 AM, Alexey Dokuchaev wrote: > Hi there, > > I'm a bit confused about how to convert _mm_set1_ps() [1] SSE function into > its AltiVec equivalent. To start with, I need to set all four floats of a > vector to the same value. So far, I've come up with two versions that work > with GCC or Clang, but I want to have a code that works with any compiler, > and is technically correct (works not just by accident). > > On PowerPC, there are two altivec.h files provided by GCC 4.2 and Clang: > > /usr/include/clang/3.4.1/altivec.h > /usr/include/gcc/4.2/altivec.h > > The problem is that they are substantially different (read: offer different > APIs). For Clang, I can simply write something like this: > > union { > float f1, f2, f3, f4; > vector float f; > } foo; > > foo.f = vec_splats(42.f); > // all f1, f2, f3, f4 are 42.f now > > But this does not work with GCC: it simply does not offer vec_splats(float); > however, I can do this: > > float init = 42.f; > foo.f = vec_ld(0, &init); > > And it will set all four components to 42.f. Yet this is technically wrong, > as apparently I'm supposed to pass an entire array of floats, e.g. if built > with Clang all floats are "nan". Lets change the code to this: > > float init[4] = { 42.f }; > foo.f = vec_ld(0, init); > > This works with both compilers, but I'm not sure if it is correct. Can any > of our AltiVec experts give me some hint here? Thanks. > > ./danfe > > [1] http://msdn.microsoft.com/en-us/library/vstudio/2x1se8ha%28v=vs.100%29.aspx I just tried the following: vector float a = (vector float){42.0f}; vector float b = vec_splat(a, 0); Haven't done anything more than compile test it, but it builds with both gcc and clang. GCC uses vspltw, while clang uses vperm. - Justin