From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 4C17F3858C50 for ; Sat, 29 Apr 2023 16:44:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C17F3858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-63b5c48ea09so820153b3a.1 for ; Sat, 29 Apr 2023 09:44:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682786686; x=1685378686; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=gHTZBZVABbSXX0w879cnyC/xbhOyLzbMg6h7NLOFsOk=; b=UuCOQKdW4GdvDALwTUZUttFbLMI9sBL5veZYYyRA8/jnTT9aztjVfLE/4J/z2CjhO0 2rEAKs4Sn1FSZTiJqedjXrogM2/YzTdqdq4VAt/ujFxOD3blhxag6ju6km8sHX1fpgCZ UowJlF0vyThtkniwbAu7/dmZ1ZPt6FQHTPfF/iVUlvG25JLFjuB73Eo0fVTM1QyWtWI5 x1cYkatzJ+bWP94tv7JJe3HIqKisOlEWGT0kgmJdyQSvhi8sEGDINuzLEysa1IR9OuZw U6xJ3l5pMIJ69I0T7V1GCMil+cvQP5U26icJfnGfpAgV/zCwUXXDTqbiwVw2+XxEZEhT B6bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682786686; x=1685378686; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gHTZBZVABbSXX0w879cnyC/xbhOyLzbMg6h7NLOFsOk=; b=Arcwhtjfve+8yW2WXFXqc7GmMijaOee7vzk6kzmqSX1igsrihlQpjihEkmPzqsRoPV x5M5+ac/fd6nPClfSK+vhsnDtWPa+jR7olqAcNo3wQAgMI2KgNc4runTQmTRoI3nuJ9E fOtprCwJJMI1Dt/oNun2gD7UlgvWPyOOd51/5ZRk91sR0/n5YyU7m+8DCSNAppKDiOe9 GQLjQbDXCsSlF+DJt5D1ThykpJLpvpuI9Plw3cAhTdw5C2bMqjXD6i4yayjQzw0ELPjS 7/Fln0OCfCWpMqNKIbiXnZtjmoMPKhbJuI1JR/Vbs+4cogGOdW8q3OadJ3fiw/hQLQoO bnAQ== X-Gm-Message-State: AC+VfDzt00SydmufmqH+uw2f9xTe9DfJ1XkBGxupWCW8Am9nH8Ejt0cn WsfFvpvaXw5AtRNPBoLi8UYEuel19EA06g== X-Google-Smtp-Source: ACHHUZ6/P2GfddwG5kxCGVaSSaQ8gtzzQQM/PlqyWkYrQzlLF3gaTVF41JEe6TP8tSZJdwSwIkHxQA== X-Received: by 2002:a05:6a00:1949:b0:641:2d72:562 with SMTP id s9-20020a056a00194900b006412d720562mr8479892pfk.13.1682786686095; Sat, 29 Apr 2023 09:44:46 -0700 (PDT) Received: from ?IPV6:2601:681:8600:13d0::99f? ([2601:681:8600:13d0::99f]) by smtp.gmail.com with ESMTPSA id f195-20020a6238cc000000b0063b8428b0d8sm17057220pfa.152.2023.04.29.09.44.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 29 Apr 2023 09:44:45 -0700 (PDT) Message-ID: <9647ad55-6b6b-d0c9-9fe4-2095b41bf02a@gmail.com> Date: Sat, 29 Apr 2023 10:44:44 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [xstormy16 PATCH] Recognize/support swpn (swap nibbles) instruction. Content-Language: en-US To: Roger Sayle , 'GCC Patches' References: <004001d97ab7$0a1989f0$1e4c9dd0$@nextmovesoftware.com> From: Jeff Law In-Reply-To: <004001d97ab7$0a1989f0$1e4c9dd0$@nextmovesoftware.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 4/29/23 10:24, Roger Sayle wrote: > > This patch adds support for xstormy16's swap nibbles instruction (swpn). > For the test case: > > short foo(short x) { > return (x&0xff00) | ((x<<4)&0xf0) | ((x>>4)&0x0f); > } > > GCC with -O2 currently generates the nine instruction sequence: > foo: mov r7,r2 > asr r2,#4 > and r2,#15 > mov.w r6,#-256 > and r6,r7 > or r2,r6 > shl r7,#4 > and r7,#255 > or r2,r7 > ret > > with this patch, we now generate: > foo: swpn r2 > ret > > To achieve this using combine's four instruction "combinations" requires > a little wizardry. Firstly, define_insn_and_split are introduced to > treat logical shifts followed by bitwise-AND as macro instructions that > are split after reload. This is sufficient to recognize a QImode > nibble swap, which can be implemented by swpn followed by either a > zero-extension or a sign-extension from QImode to HImode. Then finally, > in the correct context, a QImode swap-nibbles pattern can be combined to > preserve the high-byte of a HImode word, matching the xstormy16's swpn > semantics. > > The naming of the new code iterators is taken from i386.md. > The any_rotate code iterator is used in my next (split out) patch. > > This patch has been tested by building a cross-compiler to xstormy16-elf > from x86_64-pc-linux-gnu and confirming the new test cases pass. > Ok for mainline? > > > 2023-04-29 Roger Sayle > > gcc/ChangeLog > * config/stormy16/stormy16.md (any_lshift): New code iterator. > (any_or_plus): Likewise. > (any_rotate): Likewise. > (*_and_internal): New define_insn_and_split to > recognize a logical shift followed by an AND, and split it > again after reload. > (*swpn): New define_insn matching xstormy16's swpn. > (*swpn_zext): New define_insn recognizing swpn followed by > zero_extendqihi2, i.e. with the high byte set to zero. > (*swpn_sext): Likewise, for swpn followed by cbw. > (*swpn_sext_2): Likewise, for an alternate RTL form. > (*swpn_zext_ior): A pre-reload splitter so that an swpn+zext+ior > sequence is split in the correct place to recognize the *swpn_zext > followed by any_or_plus (ior, xor or plus) instruction. > > gcc/testsuite/ChangeLog > * gcc.target/xstormy16/swpn-1.c: New QImode test case. > * gcc.target/xstormy16/swpn-2.c: New zero_extend test case. > * gcc.target/xstormy16/swpn-3.c: New sign_extend test case. > * gcc.target/xstormy16/swpn-4.c: New HImode test case. Ah, bridge patterns. OK for the trunk. jeff