From nobody Tue Oct 04 16:38:50 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Mhk1F2Svvz4fCqJ; Tue, 4 Oct 2022 16:38:57 +0000 (UTC) (envelope-from rpokala@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Mhk1F1vT6z46hv; Tue, 4 Oct 2022 16:38:57 +0000 (UTC) (envelope-from rpokala@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664901537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q/9jo4DdQYmOnhzk93/8CrDCsr4yYlgcsRDjTPK4qps=; b=m9eU4iv/6Qz8yFQmoz8bE6RaKHss4ZIjyPyo/PvahjGQbh6f2ypkw9gP4dgGLwsjUV0CWj cZHAPOy2PY97cgO7lmbq1ax+s6U3CEJ93YN3KviFIsTxq5JS5NImqntb7X+H/xRquwubHG sXd93yszcsBJtkagPK4GM+jn7zGjRqEj6GPhBXJHwCOss5rPceJWCvonrwP6v4Fr43Ekc6 mAvHqntnwgwCGOoPoxnGGPpkawbOYNgtOPQlyn3X5sTqxaWXLiAlUXrVTmhBR01bx02u++ TZP51/NVayo3dF9McOz1QgRzABoT42EMQuaMnJvWdEECCFETaqVrbCPLqFoWkg== Received: from [192.168.1.10] (unknown [98.42.164.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: rpokala) by smtp.freebsd.org (Postfix) with ESMTPSA id 4Mhk1D3lJdz1ND7; Tue, 4 Oct 2022 16:38:56 +0000 (UTC) (envelope-from rpokala@freebsd.org) User-Agent: Microsoft-MacOutlook/16.65.22091101 Date: Tue, 04 Oct 2022 09:38:50 -0700 Subject: Re: 1024bb26337b - main - qdivrem: Predict division by zero as false. From: Ravi Pokala To: Hans Petter Selasky , , , Message-ID: <3D44E023-8220-4B65-89A1-B5B8BB77EBD5@panasas.com> Thread-Topic: 1024bb26337b - main - qdivrem: Predict division by zero as false. References: <202210041153.294Br2JP011500@gitrepo.freebsd.org> In-Reply-To: <202210041153.294Br2JP011500@gitrepo.freebsd.org> List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org Mime-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664901537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q/9jo4DdQYmOnhzk93/8CrDCsr4yYlgcsRDjTPK4qps=; b=KQkIInDZVltmMfomuov7DhrMgwEKtuuTSnvoPItKNHAtQQQ9EKrPcjiVoTDxkj/3ac8LzG mYSQHhxFXw1uqn/gBb/wdfgpmsCqm+QYJSOYPJ1w4aRKiWsK2Uj7Un4tyw7MWsZDfHSwht T3RsoFHB8rzT/FsmW/Ug0kPFWm2drk0Woc+25NmxKzlKN3GtodquND8z4DiRQNLvKjZVa0 IuKSvMFwb2z9Wj50RaiIipDTy4+EG3rXo9ZHHCY7SnaZ+zQDZiM+8hCYe1jLq6r0itQOui ogiXrCjJHNzmdIomTCQ7lpm+X4Qw6dEauFvXtD9bSXu3Jv1yqKOKWa19uElRQg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664901537; a=rsa-sha256; cv=none; b=nf33qOS5sOUZV7FoZghV5/jKjVWEgiyQlvo5APb4EerMSU5Ul5BqQJ0HO1YyDJ5AKh8bEL oce5Wy+Rn9B9/1ohnTxvFCXHAADRkpGWSd6NKSNleAi2KoWCLHNrsw2el3Nu7PNDAKcmPM Uk8yBdoHbqSUMHEpBCT00P/jzLEpyItq+beNW6D7P7pjG/QGzlewCboyFQ/u8sQ2mx2GJU hcmSwfDMIwQ9wfL/TN5/HSEd3dZUUBBmkIQ6s0AewXRobpiRs87YqLFaZYBijv2fwLj5/8 JfhZqZwC8ng/w1wgH77UpGEWP3cMvQyuKxRMNXvjgDR+bKNtGmXFUSKtiZxLpw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N -----Original Message----- From: on behalf of Hans Petter Selasky Date: 2022-10-04, Tuesday at 04:53 To: , , Subject: git: 1024bb26337b - main - qdivrem: Predict division by zero as false. The branch main has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=1024bb26337bdc6679af477977247e9155d502bc commit 1024bb26337bdc6679af477977247e9155d502bc Author: Hans Petter Selasky AuthorDate: 2022-10-04 10:28:25 +0000 Commit: Hans Petter Selasky CommitDate: 2022-10-04 11:51:06 +0000 qdivrem: Predict division by zero as false. Division by zero triggers an arithmetic exception and should not be very common. Predict this. Looking at this change with a little more context, I see that (static volatile const unsigned int) 'zero' is set to 0... and then used as the denominator for division. Since these are all integers, I would expect that to cause a fatal divide-by-zero exception. And yet, there's more code after that divide-by-zero. What am I missing? Thanks, Ravi (rpokala@) No functional change intended. MFC after: 1 week Sponsored by: NVIDIA Networking --- lib/libc/quad/qdivrem.c | 2 +- sys/libkern/qdivrem.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libc/quad/qdivrem.c b/lib/libc/quad/qdivrem.c index ea09e7f43f16..7dd7632d39ed 100644 --- a/lib/libc/quad/qdivrem.c +++ b/lib/libc/quad/qdivrem.c @@ -94,7 +94,7 @@ __qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t *arq) /* * Take care of special cases: divide by zero, and u < v. */ - if (vq == 0) { + if (__predict_false(vq == 0)) { /* divide by zero. */ static volatile const unsigned int zero = 0; diff --git a/sys/libkern/qdivrem.c b/sys/libkern/qdivrem.c index 2429fe708d7b..3f2834166450 100644 --- a/sys/libkern/qdivrem.c +++ b/sys/libkern/qdivrem.c @@ -91,7 +91,7 @@ __qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t *arq) /* * Take care of special cases: divide by zero, and u < v. */ - if (vq == 0) { + if (__predict_false(vq == 0)) { /* divide by zero. */ static volatile const unsigned int zero = 0;