From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by sourceware.org (Postfix) with ESMTPS id 8C5653857C7E for ; Thu, 5 Nov 2020 11:03:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8C5653857C7E Received: by mail-qv1-xf34.google.com with SMTP id t20so460380qvv.8 for ; Thu, 05 Nov 2020 03:03:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MTYgodqoKj4EdAIndWMd3Us56aiPXBhOPpoQ4mdA1Xc=; b=eFT0RD9VBrySM8x5CypZacmD4/vRUqmVVcrl3NsLXFjp6ZCQJY4+CypBR1XqE++Mr6 EkONF/yzlhTciNW6+Zfp7UeS3pytZMTrCMjX/QVznDReqFw5XExUnzqnrrSTY2ihO+MI lUcwOvBK9jhO6e5jj1XP7Z1JQs9Wu/bi5o3sklVTys7ACXUeETCgNiZ3zyrwVARJR2Bt fVm0bNAaNcyWsOf7ty2JmZNGeHLjv+UCtPQXwW6/Dh/urT47Pwu7RNwcSRcnSwgjjbRq iLQAp9ZptMalaZCgxPqgZ5GVuoAi+SGlQc/Ma2v4Jn+syEVt9x3SZNmNkuQ7AsBdZTRI 1E0Q== X-Gm-Message-State: AOAM5303hq87qgmTwK8vOBWJ1SptA05sU0HSIc6rZDwBy6Kxm78Tx4MJ cNjpnEbfw5TfvfmsI31Vjmwo60Fpz/ktC0+f/Y8= X-Google-Smtp-Source: ABdhPJymLU/x9gnUY5FVV1V+iWzm1SA3W8mUX7Vy2znNs0w51ct0g3hLCxeCZOzz9+65b0rL/kDl4uWoEeiP/tKl6PY= X-Received: by 2002:ad4:4142:: with SMTP id z2mr1420097qvp.20.1604574202114; Thu, 05 Nov 2020 03:03:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Uros Bizjak Date: Thu, 5 Nov 2020 12:03:10 +0100 Message-ID: Subject: Re: typeof and operands in named address spaces To: Alexander Monakov Cc: Richard Biener , Jakub Jelinek , GCC Development , X86 ML , Andy Lutomirski Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Nov 2020 11:03:23 -0000 On Thu, Nov 5, 2020 at 10:36 AM Alexander Monakov wrote: > > On Thu, 5 Nov 2020, Uros Bizjak via Gcc wrote: > > > > Looks like writing > > > > > > typeof((typeof(_var))0) tmp__; > > > > > > makes it work. Assumes there's a literal zero for the type of course. > > > > This is very limiting assumption, which already breaks for the following test: > > To elaborate Richard's idea, you need a way to decay lvalue to rvalue inside > the typeof to strip the address space; if you need the macro to work for > more types than just scalar types, the following expression may be useful: > > typeof(0?(_var):(_var)) Great, this works well for various operand types. > (though there's a bug: +(_var) should also suffice for scalar types, but > somehow GCC keeps the address space on the resulting rvalue) > > But I wonder if you actually need this at all: The posted example is a bit naive, because assignment and basic operations can be implemented directly, e.g.: __seg_fs int x; void test (void) { x &= 1; } compiles to: andl $1, %fs:x(%rip) without any macro usage at all. However, several operations, such as xadd and cmpxchg are implemented using assembly templates (see e.g. arch/x86/include/asm/percpu.h), where local instances are needed. Uros.