From patchwork Wed Feb 13 23:09:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 220298 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6FE232C0085 for ; Thu, 14 Feb 2013 10:09:33 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1361401774; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Subject:Message-ID:User-Agent:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=IlPMFpp hI1L6AsDRwfIh0po8wi0=; b=P/BXvI4J5s1DkOLVb8QvF1tnmyBWOk1LOzg7lEl TYWMO/TdpaEZw35XGgke7jNvpjANQ7bshW5QduT5ktRFn6gO9n7TSqqTa5UCmLvx EO3vuc0IRLCOG3/rqJmaz+zYRJNz/IN4CaKf7csxlPdaXVx0oJmy19vjklGiI6cY 07f0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Date:From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=AatWs8N6YtpZTndcfYamJoPChN6CNv9vCqnIWf1nbFql1onO4/S/mKG1mlwXqO USdzX89YY6fZEALnrnt/pCdze+II4eqOqYSsfheJk9cFW2x+XVugwXtIkXHin/Cx K3lrM7CuyTTOcfmMORCm3FTvIHY2JcEpCdVbMGk1+KF5E=; Received: (qmail 19676 invoked by alias); 13 Feb 2013 23:09:23 -0000 Received: (qmail 19639 invoked by uid 22791); 13 Feb 2013 23:09:22 -0000 X-SWARE-Spam-Status: No, hits=-7.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail2-relais-roc.national.inria.fr (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Feb 2013 23:09:15 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 14 Feb 2013 00:09:13 +0100 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1U5lRx-000680-Cz for gcc-patches@gcc.gnu.org; Thu, 14 Feb 2013 00:09:13 +0100 Date: Thu, 14 Feb 2013 00:09:13 +0100 (CET) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: Document ?: for vectors Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hello, today I found this patch that I had written a couple months ago, and I am wondering whether we want it for 4.8. I am tempted to keep ?: undocumented as long as the C front-end doesn't have it. The fact that very few optimizations are done on it (and some might still be broken) is another argument in this direction. On the other hand, it is there, we might as well document it. 2013-02-13 Marc Glisse * doc/extend.texi (Vector Extensions): Document ?: in C++. Index: gcc/doc/extend.texi =================================================================== --- gcc/doc/extend.texi (revision 196034) +++ gcc/doc/extend.texi (working copy) @@ -6990,20 +6990,30 @@ otherwise. Consider the following exampl typedef int v4si __attribute__ ((vector_size (16))); v4si a = @{1,2,3,4@}; v4si b = @{3,2,1,4@}; v4si c; c = a > b; /* The result would be @{0, 0,-1, 0@} */ c = a == b; /* The result would be @{0,-1, 0,-1@} */ @end smallexample +In C++, the ternary operator @code{?:} is available. @code{a?b:c}, where +@code{b} and @code{c} are vectors of the same type and @code{a} is an +integer vector of the same size and number of elements as @code{b} and +@code{c}, computes all three arguments and creates a vector +@code{@{a[0]?b[0]:c[0], a[1]?b[1]:c[1], @dots{}@}}. Note that unlike in +OpenCL, @code{a} is thus interpreted as @code{a != 0} and not @code{a < 0}. +As in the case of binary operations, this syntax is also accepted when +one of @code{b} or @code{c} is a scalar that is then transformed into a +vector. + Vector shuffling is available using functions @code{__builtin_shuffle (vec, mask)} and @code{__builtin_shuffle (vec0, vec1, mask)}. Both functions construct a permutation of elements from one or two vectors and return a vector of the same type as the input vector(s). The @var{mask} is an integral vector with the same width (@var{W}) and element count (@var{N}) as the output vector. The elements of the input vectors are numbered in memory ordering of @var{vec0} beginning at 0 and @var{vec1} beginning at @var{N}. The