-----Original Message-----
From: <[email protected]> on behalf of Hans Petter Selasky
<[email protected]>
Date: 2022-10-04, Tuesday at 04:53
To: <[email protected]>, <[email protected]>,
<[email protected]>
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 <[email protected]>
AuthorDate: 2022-10-04 10:28:25 +0000
Commit: Hans Petter Selasky <[email protected]>
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;