From owner-freebsd-ppc@FreeBSD.ORG Mon Jul 14 15:42:21 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 29EA6DE0 for ; Mon, 14 Jul 2014 15:42:21 +0000 (UTC) Received: from mx.nsu.ru (mx.nsu.ru [84.237.50.39]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C72EF24C8 for ; Mon, 14 Jul 2014 15:42:19 +0000 (UTC) Received: from regency.nsu.ru ([193.124.210.26]) by mx.nsu.ru with esmtp (Exim 4.72) (envelope-from ) id 1X6iO7-000474-25 for powerpc@freebsd.org; Mon, 14 Jul 2014 22:42:04 +0700 Received: from regency.nsu.ru (localhost [127.0.0.1]) by regency.nsu.ru (8.14.2/8.14.2) with ESMTP id s6EFgTDN030167 for ; Mon, 14 Jul 2014 22:42:39 +0700 (NOVT) (envelope-from danfe@regency.nsu.ru) Received: (from danfe@localhost) by regency.nsu.ru (8.14.2/8.14.2/Submit) id s6EFgOnN030113 for powerpc@freebsd.org; Mon, 14 Jul 2014 22:42:24 +0700 (NOVT) (envelope-from danfe) Date: Mon, 14 Jul 2014 22:42:24 +0700 From: Alexey Dokuchaev To: powerpc@freebsd.org Subject: How to convert SSEish _mm_set1_ps() into AltiVec correctly? Message-ID: <20140714154224.GA28612@regency.nsu.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.1i X-KLMS-Rule-ID: 1 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Lua-Profiles: 63944 [Jul 14 2014] X-KLMS-AntiSpam-Version: 5.5.3 X-KLMS-AntiSpam-Envelope-From: danfe@regency.nsu.ru X-KLMS-AntiSpam-Rate: 0 X-KLMS-AntiSpam-Status: not_detected X-KLMS-AntiSpam-Method: none X-KLMS-AntiSpam-Moebius-Timestamps: 3016612, 3016630, 0 X-KLMS-AntiSpam-Interceptor-Info: scan successful X-KLMS-AntiVirus: Kaspersky Security 8.0 for Linux Mail Server 8.0.0.455, not checked X-KLMS-AntiVirus-Status: NotChecked: not checked, skipped 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 15:42:21 -0000 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