From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5593BC433E0 for ; Tue, 19 Jan 2021 21:51:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B881A22E01 for ; Tue, 19 Jan 2021 21:51:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B881A22E01 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1yur-0005Qz-EU for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 16:51:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1ytS-0004gX-TL for qemu-devel@nongnu.org; Tue, 19 Jan 2021 16:50:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53272) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1ytO-0002V6-Vc for qemu-devel@nongnu.org; Tue, 19 Jan 2021 16:50:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611093024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2wu/LakUlQP6voavSnC/tnbw5fHcM0WTHBa4ctfEVKc=; b=AjUnbnOASbVIvHh1wKPeL+e/+Qp0m5xwz0CEfb9sm4RsXGe/HcvI3yXrDC7obJxssgVsEa 75+yqYJz3v3exqf8o7qYqFAYkRhQtGtsZZ8RdCYhcKOz1jO9+jasgPOlvQNbAjjJ6Ux8vO QSfM6CA0prQYIDNF2+ZoRYQgpvwziOo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-547-fjGiuKhJMr2yjDEpE8X3jw-1; Tue, 19 Jan 2021 16:50:20 -0500 X-MC-Unique: fjGiuKhJMr2yjDEpE8X3jw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C02CA10054FF; Tue, 19 Jan 2021 21:50:18 +0000 (UTC) Received: from [10.3.113.116] (ovpn-113-116.phx2.redhat.com [10.3.113.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A39D27C50; Tue, 19 Jan 2021 21:50:17 +0000 (UTC) To: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= , Alistair Francis References: <31a5b411-66d8-87ef-865a-6b3d33d0a874@amsat.org> From: Eric Blake Organization: Red Hat, Inc. Subject: Re: [PATCH v1 1/1] riscv: Pass RISCVHartArrayState by pointer Message-ID: Date: Tue, 19 Jan 2021 15:50:17 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <31a5b411-66d8-87ef-865a-6b3d33d0a874@amsat.org> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=216.205.24.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:RISC-V" , "qemu-devel@nongnu.org Developers" , Palmer Dabbelt , Alistair Francis , Bin Meng , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 1/17/21 10:52 AM, Philippe Mathieu-Daudé wrote: > On 1/16/21 11:38 PM, Alistair Francis wrote: >> On Sat, Jan 16, 2021 at 2:32 PM Philippe Mathieu-Daudé wrote: >>> >>> On 1/16/21 12:00 AM, Alistair Francis wrote: >>>> We were accidently passing RISCVHartArrayState by value instead of accidentally >>>> pointer. The type is 824 bytes long so let's correct that and pass it by >>>> pointer instead. >>>> -bool riscv_is_32bit(RISCVHartArrayState harts) >>>> +bool riscv_is_32bit(RISCVHartArrayState *harts) Definitely better, >>>> { >>>> - RISCVCPU hart = harts.harts[0]; >>>> + RISCVCPU hart = harts->harts[0]; but yeah, this still results in a copy (unless the compiler optimizes it). >>> >>> This doesn't look improved. Maybe you want: >>> >>> return riscv_cpu_is_32bit(&harts->harts[0].env); Whereas this is obviously a pointer into the original without relying on the compiler to elide a copy. >> >> I suspect this ends up generating the same code. > > If the compiler is smart enough, but I'm not sure it can figure out > only 1 element from the structure is accessed... > My understanding is "first copy the content pointed at '*harts' in > 'hart' on the stack", then only use "env". > > Cc'ing Eric/Richard to double check. I agree that relying on the compiler optimization is not as straightforward as writing the code to directly access the correct pointer from the get-go. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1l1ytW-0004i6-A0 for mharc-qemu-riscv@gnu.org; Tue, 19 Jan 2021 16:50:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1ytS-0004gW-S4 for qemu-riscv@nongnu.org; Tue, 19 Jan 2021 16:50:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23378) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1ytP-0002V7-18 for qemu-riscv@nongnu.org; Tue, 19 Jan 2021 16:50:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611093024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2wu/LakUlQP6voavSnC/tnbw5fHcM0WTHBa4ctfEVKc=; b=AjUnbnOASbVIvHh1wKPeL+e/+Qp0m5xwz0CEfb9sm4RsXGe/HcvI3yXrDC7obJxssgVsEa 75+yqYJz3v3exqf8o7qYqFAYkRhQtGtsZZ8RdCYhcKOz1jO9+jasgPOlvQNbAjjJ6Ux8vO QSfM6CA0prQYIDNF2+ZoRYQgpvwziOo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-547-fjGiuKhJMr2yjDEpE8X3jw-1; Tue, 19 Jan 2021 16:50:20 -0500 X-MC-Unique: fjGiuKhJMr2yjDEpE8X3jw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C02CA10054FF; Tue, 19 Jan 2021 21:50:18 +0000 (UTC) Received: from [10.3.113.116] (ovpn-113-116.phx2.redhat.com [10.3.113.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A39D27C50; Tue, 19 Jan 2021 21:50:17 +0000 (UTC) To: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= , Alistair Francis Cc: "open list:RISC-V" , Palmer Dabbelt , Bin Meng , Alistair Francis , "qemu-devel@nongnu.org Developers" , Richard Henderson References: <31a5b411-66d8-87ef-865a-6b3d33d0a874@amsat.org> From: Eric Blake Organization: Red Hat, Inc. Subject: Re: [PATCH v1 1/1] riscv: Pass RISCVHartArrayState by pointer Message-ID: Date: Tue, 19 Jan 2021 15:50:17 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <31a5b411-66d8-87ef-865a-6b3d33d0a874@amsat.org> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=216.205.24.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-riscv@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2021 21:50:31 -0000 On 1/17/21 10:52 AM, Philippe Mathieu-Daudé wrote: > On 1/16/21 11:38 PM, Alistair Francis wrote: >> On Sat, Jan 16, 2021 at 2:32 PM Philippe Mathieu-Daudé wrote: >>> >>> On 1/16/21 12:00 AM, Alistair Francis wrote: >>>> We were accidently passing RISCVHartArrayState by value instead of accidentally >>>> pointer. The type is 824 bytes long so let's correct that and pass it by >>>> pointer instead. >>>> -bool riscv_is_32bit(RISCVHartArrayState harts) >>>> +bool riscv_is_32bit(RISCVHartArrayState *harts) Definitely better, >>>> { >>>> - RISCVCPU hart = harts.harts[0]; >>>> + RISCVCPU hart = harts->harts[0]; but yeah, this still results in a copy (unless the compiler optimizes it). >>> >>> This doesn't look improved. Maybe you want: >>> >>> return riscv_cpu_is_32bit(&harts->harts[0].env); Whereas this is obviously a pointer into the original without relying on the compiler to elide a copy. >> >> I suspect this ends up generating the same code. > > If the compiler is smart enough, but I'm not sure it can figure out > only 1 element from the structure is accessed... > My understanding is "first copy the content pointed at '*harts' in > 'hart' on the stack", then only use "env". > > Cc'ing Eric/Richard to double check. I agree that relying on the compiler optimization is not as straightforward as writing the code to directly access the correct pointer from the get-go. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org