From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 6066F385C6C2 for ; Tue, 11 Jun 2024 16:25:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6066F385C6C2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6066F385C6C2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718123147; cv=none; b=hYFdJxFiGB+RbKejK3xvyGV003g7mJtSIvwJHxXmT3TFZpQOlWmd1c5U32NYautZcZPDKH1X7r1lzlOA7v87W4Su1Ch55Ymyp/7BI0HhXdUa7Y0x5WUScuEHZzXf4OtgSczlP79ip8MPXfRlUcIFlujxQXG3Ssj+B7790LO1SDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718123147; c=relaxed/simple; bh=Yu9Hra8nptKrywTEUNIOQpk1QIbNBXVRsK4eKHnpDwU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=x51VDdw6L+jhF/Fs7meGXLBjlBvrOBA64HqF9ZVUsjDCB1kjwmndN6M4qw1wphApc3qWmsYoDLX1iyyr86AghjJNQlGXwMl52uQtB5XlvZwQR41pnCDG/odYGvQSxAAfRiL0bI1jFNUgx2cje9zp45EHFxjO4IdTBsEA3RvepW4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718123146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=r7fqp5XsCnTc4hoXUfdSTLn/AGTBGs5LYwg9SUBNRGg=; b=ZWxRXFrcJV0uNiEjcF156DaAVLY9hTXTKDapGmbFg+NYz54wg9WLW/zPG/iTjXw3CWgw8z sGnod0UvtvNvlIegI6zPDlfCp/C3u93Dlrmc8KuSZ8XD+fQz4KYjj2OpGKDozMWUx5rfnI 32fR/JfM8PynYuywdhGsMgCr/n/mzvE= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-118-VIuVTqXYPN2GFl5KlUC0GA-1; Tue, 11 Jun 2024 12:25:44 -0400 X-MC-Unique: VIuVTqXYPN2GFl5KlUC0GA-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-35f271c5b17so675498f8f.0 for ; Tue, 11 Jun 2024 09:25:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718123142; x=1718727942; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=r7fqp5XsCnTc4hoXUfdSTLn/AGTBGs5LYwg9SUBNRGg=; b=BTUuZGPawuUNofXVBY3MatkpR/791rFlyCNq79kXvDvfnbdBqPxVAdbXED09sFiyw6 3OTaUZZBv974GqWdTGty8P0ZBRcRmtDrDIEVP5EkMHJpU/yL2DAmasMj0a9s1wLmMca8 O2h3yQKjLXSDjuKUdS4F6s1xnUXpNs1rylVgzPAabXlPqYcDPmBmD8lkiZQuERoPu+ST O1DiQQePoD+2qyDrokhinOWMXuUrBk4Ow4q4r0l6SuEqbHelTGefXVc6kfi17bcpG9OO Vae1+7TGQng4rboQu0Kor2+8IMe1aabqOiRqwdpFTsUn6PhdJrQApBBktmffuHqqD+A2 bA/Q== X-Forwarded-Encrypted: i=1; AJvYcCV3Dj6lL2biV2j36DUGzBVxgN9HiASLIdDlQhCYmgatcu1KftTArYIzo68guucj9OJV8pktvjIpq1Wqp6Nkq+bzFdvw6BO4kt6Mjw== X-Gm-Message-State: AOJu0YxMVS6/4OZfU2pKCI1Ibd5/VklaS/PEP+FWstbS3belTF4QovCB HD8YqVK9ecUwhOTbjqPYFJxMx1ac9BCxiB5+btIH0wiax02WaDoLqB7GGkAANp4Qa3t08fPQUBs ax3E0+s1yzUdI35Foz0+XdYDZ2yjnIlMCdAyLON/iym7f9Ljg5XJ2xA1uxGGCJSPTu18= X-Received: by 2002:a05:6000:11cd:b0:35f:1d1e:5255 with SMTP id ffacd0b85a97d-35f1d1e5487mr8203256f8f.23.1718123142602; Tue, 11 Jun 2024 09:25:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IER7Gs8Esbkkql0V5GhXCcaVsd1R+yBpgJiBzMS3KCQGaIAaOqoPVcf5g59LKE5RXTxHcjjKw== X-Received: by 2002:a05:6000:11cd:b0:35f:1d1e:5255 with SMTP id ffacd0b85a97d-35f1d1e5487mr8203240f8f.23.1718123142043; Tue, 11 Jun 2024 09:25:42 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35f2f67b5b8sm1545802f8f.12.2024.06.11.09.25.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 09:25:41 -0700 (PDT) From: Andrew Burgess To: Bernd Edlinger , "gdb-patches@sourceware.org" Subject: Re: [PATCH 2/2] sim: riscv: Simplify the signed div by -1 code In-Reply-To: References: Date: Tue, 11 Jun 2024 17:25:40 +0100 Message-ID: <87frtja1kr.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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: Bernd Edlinger writes: > This uses the idea from the previous patch to > simplify the code for non-overflowing signed > divisions by -1. This is no bug-fix but it > simplifies the code and avoids some unnecessary > branches. > --- > sim/riscv/sim-main.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/sim/riscv/sim-main.c b/sim/riscv/sim-main.c > index 515ff835223..e4b15b533ba 100644 > --- a/sim/riscv/sim-main.c > +++ b/sim/riscv/sim-main.c > @@ -700,18 +700,16 @@ execute_m (SIM_CPU *cpu, unsigned_word iw, const struct riscv_opcode *op) > const char *rd_name = riscv_gpr_names_abi[rd]; > const char *rs1_name = riscv_gpr_names_abi[rs1]; > const char *rs2_name = riscv_gpr_names_abi[rs2]; > - unsigned_word tmp, dividend_max; > + unsigned_word tmp; > sim_cia pc = riscv_cpu->pc + 4; > > - dividend_max = -((unsigned_word) 1 << (WITH_TARGET_WORD_BITSIZE - 1)); I really don't understand what this was trying to calculate. It's not the max value of an unsigned_word. Nor is it the bit representation of the maximum signed_word value... but you're removing it, so I guess I can not worry about that :) > - > switch (op->match) > { > case MATCH_DIV: > TRACE_INSN (cpu, "div %s, %s, %s; // %s = %s / %s", > rd_name, rs1_name, rs2_name, rd_name, rs1_name, rs2_name); > - if (riscv_cpu->regs[rs1] == dividend_max && riscv_cpu->regs[rs2] == -1) > - tmp = dividend_max; > + if (riscv_cpu->regs[rs2] == -1) > + tmp = -riscv_cpu->regs[rs1]; As with the previous commit, can't we drop this whole if check and block? I think we should add some tests for this too. The test I proposed in the previous commit can be modified to give us div.s and rem.s tests. Thanks, Andrew > else if (riscv_cpu->regs[rs2]) > tmp = (signed_word) riscv_cpu->regs[rs1] / > (signed_word) riscv_cpu->regs[rs2]; > @@ -793,7 +791,7 @@ execute_m (SIM_CPU *cpu, unsigned_word iw, const struct riscv_opcode *op) > case MATCH_REM: > TRACE_INSN (cpu, "rem %s, %s, %s; // %s = %s %% %s", > rd_name, rs1_name, rs2_name, rd_name, rs1_name, rs2_name); > - if (riscv_cpu->regs[rs1] == dividend_max && riscv_cpu->regs[rs2] == -1) > + if (riscv_cpu->regs[rs2] == -1) > tmp = 0; > else if (riscv_cpu->regs[rs2]) > tmp = (signed_word) riscv_cpu->regs[rs1] > -- > 2.39.2