Received: by 2002:a19:4310:0:0:0:0:0 with SMTP id q16csp528686lfa; Thu, 10 Jun 2021 07:04:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPfRdt9YPHNWWjIR0I1zQL+vJUOC8JC+SbPMU9eonc5M1im+GAQTNdsitvH/2GaWLzkUEb X-Received: by 2002:a17:906:1404:: with SMTP id p4mr4646092ejc.107.1623333872423; Thu, 10 Jun 2021 07:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623333872; cv=none; d=google.com; s=arc-20160816; b=boADhtyJYZh9qN8cKIp0aXD9vcQhy1MJpL3zfaw6KSZvONUixEoDpu4dSMB4WC2WXZ +/JpxBEQlYCp/qkQ9AU0c6tSoIJQznUyH7lQfYx++EG0NVmPc4kLBhAy+KDzPeC+3yVG 4TLRElW2XpscucZJsIFlHo5BTCRMFuOV5SFEpI9S8sqybJVQzDn6ZLthq/tMxkxHRX3G eZKegQzFP1ubgOjPE5z809nE8darskWtnx6AKgiKMilVHdNHbUJHdYJq6qfEobiUrfxW SKWdj+W580v0r/4q2Wfs8n6ZHhOhpnzrn2FnrCc31BcZfArTsztVG3BhCzv2YLacdXEJ 6OEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=AOeGkM9V2dGSKSbFvs7dCmojgraWp0fo6Mi0vZ8ldMQ=; b=PPdfXpyVrMmn4PUI7mv6equb/TNJvDcrIEHOiqHRxvCJy17CGEBq/MLoGIxoMaFnwP U7pdGsm8dnHlb4FszlHgHGSNtnFPscOJPlrIehXE0d+Vys2P4qC/Xm1cQGqqeDNnZomy GikIxVhGD2XbJ/zkIbL2YrDLAbTk9rgqTBCaPBc7mrXuhNCm4MKTQrhIR4lRYZriTcHA XAo+GNDKZ9eQF0HYoWFmeftTA73pKiKtz4sTeapSqbEGud1ln/Ft0OUbzDdbKvDiVKoi V553P2Vy6kJR8MM8LSSMEGpRnA++rxzJCAvuJSuZxrx4m5UsZqOC/1uMR/YN8iDvcopm UwBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TPDtEKnR; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j9si2173330edw.50.2021.06.10.07.04.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jun 2021 07:04:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TPDtEKnR; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrLIN-0000P0-9z for alex.bennee@linaro.org; Thu, 10 Jun 2021 10:04:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrLHO-0007OX-BZ for qemu-arm@nongnu.org; Thu, 10 Jun 2021 10:03:30 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:38859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrLHL-0006Tp-J7 for qemu-arm@nongnu.org; Thu, 10 Jun 2021 10:03:30 -0400 Received: by mail-pg1-x536.google.com with SMTP id t17so6109048pga.5 for ; Thu, 10 Jun 2021 07:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=AOeGkM9V2dGSKSbFvs7dCmojgraWp0fo6Mi0vZ8ldMQ=; b=TPDtEKnRCzxNxfvOrZAHxe5nJQ2Yf6SU0q9F/yLFRlibnZxv3c+KN4AX6ZlaGVh7fR 13IDp/1diWJnT/kHdy7XqeKfageZcgtgQSHqbI7iyjwcECIOio38MbdG/9yA8/Bxhmul +7L1Ya8gvOCfkIq8N0XINwXni893G9imuhF0M9P0SI/1Rfk1ZjkiD9doJUC7ZeVv4uJ5 OGZjcDnD8nec3MtOhDhPrwSOlr+owPjET1jA/ISuLZ8cUSqscmOfBN+AJYXxgJNVLWLG 0dVq4PesWcCTwUZt3tQjN8dgOyZEP5AdSUj9s6DQ5tla/GIL/tmeDRqmoEv/AIjlbydh mCTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=AOeGkM9V2dGSKSbFvs7dCmojgraWp0fo6Mi0vZ8ldMQ=; b=VPNyb7PN3xdH7OMsd4D40gw0425H67cWcRuh1n+VWHgzAewi4nocLpf41Pi5FIHCY/ dAhyniVPdY8jpv5hXg2r8HtbH0aRXdlOtojECMnPrwbtxkInZFQF+TqSp12N//A1wKWb IEbgvUguLd41R3ZPTNyyw800E9VzSC3ZvD9+GyaIroLWeez45LinAGEAloRv71jEit6h mJ2nWuquNF0OlhsVh3TdpeLAV9LAs7CO393h72/MxDfvLSfEzQcJMwSSQSnPqnLvOxRV sXbqfj4PH63S1xz0FYv02qkx3BjNqJh8kt/RmAuzPrbyAN4QNAOcTh6rIrgNRh6ZH17B mCJg== X-Gm-Message-State: AOAM531uZldoCGkaFQ662EAkWd2VQUOZjGQvaLdGhsL99hnHs/3iQax+ IJvzO4ckmfq3KQBKx2Xjx+8GPw== X-Received: by 2002:a63:3ec3:: with SMTP id l186mr5035481pga.371.1623333802426; Thu, 10 Jun 2021 07:03:22 -0700 (PDT) Received: from [192.168.1.11] (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id e2sm2872426pgh.5.2021.06.10.07.03.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Jun 2021 07:03:22 -0700 (PDT) Subject: Re: [PATCH 13/55] target/arm: Implement MVE VCLZ To: Peter Maydell References: <20210607165821.9892-1-peter.maydell@linaro.org> <20210607165821.9892-14-peter.maydell@linaro.org> From: Richard Henderson Message-ID: Date: Thu, 10 Jun 2021 07:03:20 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-arm , QEMU Developers Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: +bqqngxuotmJ On 6/10/21 5:40 AM, Peter Maydell wrote: >>> +#define DO_1OP(OP, ESIZE, TYPE, H, FN) \ >>> + void HELPER(mve_##OP)(CPUARMState *env, void *vd, void *vm) \ >>> + { \ >>> + TYPE *d = vd, *m = vm; \ >>> + uint16_t mask = mve_element_mask(env); \ >>> + unsigned e; \ >>> + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ >>> + TYPE r = FN(m[H(e)]); \ >>> + uint64_t bytemask = mask_to_bytemask##ESIZE(mask); \ >> >> Why uint64_t and not TYPE? Or uint32_t? > > A later patch adds the mask_to_bytemask8(), so I wanted > a type that was definitely unsigned (so TYPE isn't any good) > and which was definitely big enough for 64 bits. Hmm. I was just concerned about the unnecessary type extension involved. What about changing the interface. Not to return a mask as you do here, but to perform the entire merge operation. E.g. static uint8_t mergemask1(uint8_t d, uint8_t r, uint16_t mask) { return mask & 1 ? r : d; } static uint16_t mergemask2(uint16_t d, uint16_t r, uint16_t mask) { uint16_t bmask = array_whotsit[mask & 3]; return (d & ~bmask) | (r & bmask); } etc. Or maybe with a pointer argument for D, so that the load+store is done there as well. In which case you could use QEMU_GENERIC to select the function invoked, instead of using token pasting everywhere. E.g. static void mergemask_ub(uint8_t *d, uint8_r, uint16_t mask) { if (mask & 1) { *d = r; } } static void mergemask_sb(int8_t *d, int8_r, uint16_t mask) { mergemask_ub((uint8_t *)d, r, mask); } static void mergemask_uh(uint16_t *d, uint16_r, uint16_t mask) { uint16_t bmask = array_whotsit[mask & 3]; *d = (*d & ~bmask) | (r & bmask); } ... #define mergemask(D, R, M) \ QEMU_GENERIC(D, (uint8_t *, mergemask_ub), \ (int8_t *, mergemask_sb), \ ... ) BTW, now that we're at minimal gcc 7, I think we can shift to -std=gnu11 so that we can drop QEMU_GENERIC and just use _Generic, which is much easier to read than the above, and will give better error messages for missing cases. Anyway... Which takes your boilerplate down to > +#define DO_1OP(OP, ESIZE, TYPE, H, FN) \ > + void HELPER(mve_##OP)(CPUARMState *env, void *vd, void *vm) \ > + { \ > + TYPE *d = vd, *m = vm; \ > + uint16_t mask = mve_element_mask(env); \ > + for (unsigned e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ > + mergemask(&d[H(e)], FN(m[H(e)]), mask); \ > + } \ > + mve_advance_vpt(env); \ > + } which looks pretty tidy to me. r~