drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse: sparse: dubious: !x | !y
kernel test robot
build bottree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: a688404b2e20f00cce6d0a2b888ef4ca9154e144 HID: intel-thc-hid: intel-thc: Add THC DMA interfaces date: 3 weeks ago config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20250129/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250129/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse: sparse: dubious: !x | !y
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c: note: in included file (through include/linux/mmzone.h, include/linux/gfp.h, include/linux/mm.h, ...):
include/linux/page-flags.h:237:46: sparse: sparse: self-comparison always evaluates to false
include/linux/page-flags.h:237:46: sparse: sparse: self-comparison always evaluates to false
vim +298 drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
287
288 static void release_dma_buffers(struct thc_device *dev,
289 struct thc_dma_configuration *config)
290 {
291 size_t prd_tbls_size = array_size(PRD_TABLE_SIZE, config->prd_tbl_num);
292 unsigned int i;
293
294 if (!config->is_enabled)
295 return;
296
297 for (i = 0; i < config->prd_tbl_num; i++) {
> 298 if (!config->sgls[i] | !config->sgls_nent[i])
299 continue;
300
301 dma_unmap_sg(dev->dev, config->sgls[i],
302 config->sgls_nent[i],
303 config->dir);
304
305 sgl_free(config->sgls[i]);
306 config->sgls[i] = NULL;
307 }
308
309 memset(config->prd_tbls, 0, prd_tbls_size);
310
311 if (config->prd_tbls) {
312 dma_free_coherent(dev->dev, prd_tbls_size, config->prd_tbls,
313 config->prd_tbls_dma_handle);
314 config->prd_tbls = NULL;
315 config->prd_tbls_dma_handle = 0;
316 }
317 }
318
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 20 lines · On Wed, 29 Jan 2025 22:02:59 +0800 kernel test robot <[email protected]> wrote:
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: a688404b2e20f00cce6d0a2b888ef4ca9154e144 HID: intel-thc-hid: intel-thc: Add THC DMA interfaces date: 3 weeks ago config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20250129/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250129/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/sparse warnings: (new ones prefixed by >>)
Quoted 1 line
Quoted 1 line
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse: sparse: dubious: !x | !y
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c: note: in included file (throughinclude/linux/mmzone.h,include/linux/gfp.h,include/linux/mm.h, ...):
include/linux/page-flags.h:237:46: sparse: sparse: self-comparison always evaluates to false
include/linux/page-flags.h:237:46: sparse: sparse: self-comparison always evaluates to falsevim +298
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
...
Quoted 3 lines
297 for (i = 0; i < config->prd_tbl_num; i++) {Quoted 1 line
298 if (!config->sgls[i] | !config->sgls_nent[i])
299 continue;
...
If zeros are unlikely the bit-wise 'or' is pretty likely to generate better code than a logical 'or'.
David
Quoted 52 lines
-----Original Message-----
From: David Laight <[email protected]>
Sent: Thursday, January 30, 2025 6:22 AM
To: lkp <[email protected]>
Cc: Xu, Even <[email protected]>; [email protected]; linux- [email protected]; Jiri Kosina <[email protected]>; Sun, Xinpeng <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>
Subject: Re:drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse:
sparse: dubious: !x | !yQuoted 3 lines · On Wed, 29 Jan 2025 22:02:59 +0800 kernel test robot <[email protected]> wrote:
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: a688404b2e20f00cce6d0a2b888ef4ca9154e144 HID: intel-thc-hid:intel-thc: Add THC DMA interfaces
Quoted 16 lines
date: 3 weeks ago config: x86_64-allyesconfig(https://download.01.org/0day-ci/archive/20250129/202501292144.eFDq4ov
[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build):
(https://download.01.org/0day-ci/archive/20250129/202501292144.eFDq4ov
[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Closes: | https://lore.kernel.org/oe-kbuild-all/202501292144.eFDq4ovr-lkp@inte | l.com/Quoted 4 lines
sparse warnings: (new ones prefixed by >>)
Quoted 2 lines
Quoted 2 lines
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse:
sparse: dubious: !x | !y
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c: note: in included file(through
include/linux/mmzone.h,include/linux/gfp.h,include/linux/mm.h, ...):Quoted 1 line
include/linux/page-flags.h:237:46: sparse: sparse: self-comparison alwaysevaluates to false
Quoted 4 lines
include/linux/page-flags.h:237:46: sparse: sparse: self-comparison
always evaluates to falsevim +298
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c...
Quoted 3 lines
297 for (i = 0; i < config->prd_tbl_num; i++) {Quoted 1 line
298 if (!config->sgls[i] | !config->sgls_nent[i])
299 continue;
Quoted 6 lines
...
If zeros are unlikely the bit-wise 'or' is pretty likely to generate better code than a logical 'or'.
David
Good suggestion!
So the code can be optimized to:
for (i = 0; i < config->prd_tbl_num; i++) {
if (config->sgls[i] && config->sgls_nent[i]) {
......
}
}Will create a patch for this.
Best Regards,
Even Xu
Quoted 55 lines · Even
Quoted 55 lines
-----Original Message-----
From: David Laight <[email protected]>
Sent: Thursday, January 30, 2025 6:22 AM
To: lkp <[email protected]>
Cc: Xu, Even <[email protected]>; [email protected]; linux- [email protected]; Jiri Kosina <[email protected]>; Sun, Xinpeng <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>
Subject: Re:drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse:
sparse: dubious: !x | !yQuoted 3 lines · On Wed, 29 Jan 2025 22:02:59 +0800 kernel test robot <[email protected]> wrote:
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: a688404b2e20f00cce6d0a2b888ef4ca9154e144 HID: intel-thc-hid:intel-thc: Add THC DMA interfaces
Quoted 16 lines
date: 3 weeks ago config: x86_64-allyesconfig(https://download.01.org/0day-ci/archive/20250129/202501292144.eFDq4ov
[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build):
(https://download.01.org/0day-ci/archive/20250129/202501292144.eFDq4ov
[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Closes: | https://lore.kernel.org/oe-kbuild-all/202501292144.eFDq4ovr-lkp@inte | l.com/Quoted 4 lines
sparse warnings: (new ones prefixed by >>)
Quoted 2 lines
Quoted 2 lines
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse:
sparse: dubious: !x | !y
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c: note: in included file(through
include/linux/mmzone.h,include/linux/gfp.h,include/linux/mm.h, ...):Quoted 1 line
include/linux/page-flags.h:237:46: sparse: sparse: self-comparison alwaysevaluates to false
Quoted 4 lines
include/linux/page-flags.h:237:46: sparse: sparse: self-comparison
always evaluates to falsevim +298
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c...
Quoted 3 lines
297 for (i = 0; i < config->prd_tbl_num; i++) {Quoted 1 line
298 if (!config->sgls[i] | !config->sgls_nent[i])
299 continue;
...
If zeros are unlikely the bit-wise 'or' is pretty likely to generate better code than a logical 'or'.
Quoted 8 lines
Quoted 1 line
David
Good suggestion!
So the code can be optimized to:for (i = 0; i < config->prd_tbl_num; i++) { if (config->sgls[i] && config->sgls_nent[i]) { ...... }
That just adds a level of indentation to the source. It'll generate much the same code as !x || !y. Both will generate two conditional branches.
It almost certainly makes in immeasurable difference here, but !x | !y can be generated using (on x86) the 'sete' instruction to get a 0/1 from the x == 0 compare (that sets the flags), and then doing an 'or' and a single jump.
David
Quoted 8 lines
}Will create a patch for this.
Best Regards,
Even Xu
Quoted 90 lines
-----Original Message-----
From: David Laight <[email protected]>
Sent: Thursday, February 6, 2025 5:57 AM
To: Xu, Even <[email protected]>
Cc: lkp <[email protected]>; [email protected]; linux- [email protected]; Jiri Kosina <[email protected]>; Sun, Xinpeng <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>
Subject: Re:drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse:
sparse: dubious: !x | !yQuoted 10 lines · Even
Quoted 10 lines
-----Original Message-----
From: David Laight <[email protected]>
Sent: Thursday, January 30, 2025 6:22 AM
To: lkp <[email protected]>
Cc: Xu, Even <[email protected]>; [email protected]; linux- [email protected]; Jiri Kosina <[email protected]>; Sun, Xinpeng <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>
Subject: Re:drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38:sparse:
Quoted 6 lines
Quoted 6 lines
sparse: dubious: !x | !y
Quoted 1 line · On Wed, 29 Jan 2025 22:02:59 +0800 kernel test robot <[email protected]> wrote:
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
master
Quoted 23 lines
Quoted 23 lines
Quoted 2 lines
head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: a688404b2e20f00cce6d0a2b888ef4ca9154e144 HID: intel-thc-hid:intel-thc: Add THC DMA interfaces
Quoted 20 lines
date: 3 weeks ago config: x86_64-allyesconfig(https://download.01.org/0day-ci/archive/20250129/202501292144.eFD
q4ov
[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1
build):
(https://download.01.org/0day-ci/archive/20250129/202501292144.eFD
q4ov
[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Closes: | https://lore.kernel.org/oe-kbuild-all/202501292144.eFDq4ovr-lkp@ | inte | l.com/Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
sparse warnings: (new ones prefixed by >>)
Quoted 2 lines
Quoted 2 lines
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse:
sparse: dubious: !x | !y
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c: note: in
included file(through
include/linux/mmzone.h,include/linux/gfp.h,
include/linux/mm.h, ...):Quoted 16 lines
Quoted 16 lines
Quoted 2 lines
include/linux/page-flags.h:237:46: sparse: sparse:self-comparison always
evaluates to false
Quoted 4 lines
include/linux/page-flags.h:237:46: sparse: sparse:self-comparison always evaluates to false
vim +298
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c...
Quoted 3 lines
297 for (i = 0; i < config->prd_tbl_num; i++) {Quoted 1 line
298 if (!config->sgls[i] | !config->sgls_nent[i])
299 continue;
...
If zeros are unlikely the bit-wise 'or' is pretty likely to generate better code than a logical 'or'.
Quoted 8 lines
Quoted 1 line
David
Good suggestion!
So the code can be optimized to:for (i = 0; i < config->prd_tbl_num; i++) { if (config->sgls[i] && config->sgls_nent[i]) { ...... }
Quoted 7 lines
That just adds a level of indentation to the source. It'll generate much the same code as !x || !y. Both will generate two conditional branches.
It almost certainly makes in immeasurable difference here, but !x | !y can be generated using (on x86) the 'sete' instruction to get a 0/1 from the x == 0 compare (that sets the flags), and then doing an 'or' and a single jump.
You are right.
I do a simple testing:
83 7d f8 00 cmpl $0x0,-0x8(%rbp) 0f 94 c2 sete %dl 83 7d fc 00 cmpl $0x0,-0x4(%rbp) 0f 94 c0 sete %al 09 d0 or %edx,%eax 84 c0 test %al,%al 74 0f je 1186 <main+0x3d>
Compare to:
83 7d f8 00 cmpl $0x0,-0x8(%rbp) 74 06 je 116f <main+0x26> 83 7d fc 00 cmpl $0x0,-0x4(%rbp) 75 0f jne 117e <main+0x35>
So you suggest I'd better keep the original (!x | !y) code, if just for unlikely Zero comparing?
Thanks!
Best Regards,
Even Xu
Quoted 11 lines
David
Quoted 8 lines
}Will create a patch for this.
Best Regards,
Even Xu
Quoted 92 lines · Even
Quoted 92 lines
-----Original Message-----
From: David Laight <[email protected]>
Sent: Thursday, February 6, 2025 5:57 AM
To: Xu, Even <[email protected]>
Cc: lkp <[email protected]>; [email protected]; linux- [email protected]; Jiri Kosina <[email protected]>; Sun, Xinpeng <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>
Subject: Re:drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse:
sparse: dubious: !x | !yQuoted 10 lines · Even
Quoted 10 lines
-----Original Message-----
From: David Laight <[email protected]>
Sent: Thursday, January 30, 2025 6:22 AM
To: lkp <[email protected]>
Cc: Xu, Even <[email protected]>; [email protected]; linux- [email protected]; Jiri Kosina <[email protected]>; Sun, Xinpeng <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>
Subject: Re:drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38:sparse:
Quoted 6 lines
Quoted 6 lines
sparse: dubious: !x | !y
Quoted 1 line · On Wed, 29 Jan 2025 22:02:59 +0800 kernel test robot <[email protected]> wrote:
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
master
Quoted 23 lines
Quoted 23 lines
Quoted 2 lines
head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: a688404b2e20f00cce6d0a2b888ef4ca9154e144 HID: intel-thc-hid:intel-thc: Add THC DMA interfaces
Quoted 20 lines
date: 3 weeks ago config: x86_64-allyesconfig(https://download.01.org/0day-ci/archive/20250129/202501292144.eFD
q4ov
[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1
build):
(https://download.01.org/0day-ci/archive/20250129/202501292144.eFD
q4ov
[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Closes: | https://lore.kernel.org/oe-kbuild-all/202501292144.eFDq4ovr-lkp@ | inte | l.com/Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
sparse warnings: (new ones prefixed by >>)
Quoted 2 lines
Quoted 2 lines
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse:
sparse: dubious: !x | !y
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c: note: in
included file(through
include/linux/mmzone.h,include/linux/gfp.h,
include/linux/mm.h, ...):Quoted 16 lines
Quoted 16 lines
Quoted 2 lines
include/linux/page-flags.h:237:46: sparse: sparse:self-comparison always
evaluates to false
Quoted 4 lines
include/linux/page-flags.h:237:46: sparse: sparse:self-comparison always evaluates to false
vim +298
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c...
Quoted 3 lines
297 for (i = 0; i < config->prd_tbl_num; i++) {Quoted 1 line
298 if (!config->sgls[i] | !config->sgls_nent[i])
299 continue;
...
If zeros are unlikely the bit-wise 'or' is pretty likely to generate better code than a logical 'or'.
Quoted 8 lines
Quoted 1 line
David
Good suggestion!
So the code can be optimized to:for (i = 0; i < config->prd_tbl_num; i++) { if (config->sgls[i] && config->sgls_nent[i]) { ...... }That just adds a level of indentation to the source. It'll generate much the same code as !x || !y. Both will generate two conditional branches.
Quoted 5 lines
Quoted 3 lines
It almost certainly makes in immeasurable difference here, but !x | !y can be generated using (on x86) the 'sete' instruction to get a 0/1 from the x == 0 compare (that sets the flags), and then doing an 'or' and a single jump.
You are right.
I'm always right (except when I'm not)
Quoted 6 lines
I do a simple testing:
83 7d f8 00 cmpl $0x0,-0x8(%rbp) 0f 94 c2 sete %dl 83 7d fc 00 cmpl $0x0,-0x4(%rbp) 0f 94 c0 sete %al
On a modern cpu those two pairs will run in parallel.
Quoted 2 lines
09 d0 or %edx,%eax 84 c0 test %al,%al
The compiler needn't to add the 'test' instruction, but doesn't really like the fact that the x86 'sete' is only available for 8-bit registers.
Quoted 10 lines
74 0f je 1186 <
main+0x3d>Compare to:
83 7d f8 00 cmpl $0x0,-0x8(%rbp) 74 06 je 116f <main+0x26> 83 7d fc 00 cmpl $0x0,-0x4(%rbp) 75 0f jne 117e <main+0x35>So you suggest I'd better keep the original (!x | !y) code, if just for unlikely Zero comparing?
Looking at the code I'd guess common case is that both values are non-zero. So in the normal case both tests are needed.
The branch predictor will (hopefully) get the tests right after the first iteration, and I suspect the performance of this code isn't that critical.
So while using | might be an optimisation (rather than a mistake) changing it to || probably doesn't matter.
David
Quoted 18 lines
Thanks!
Best Regards,
Even XuQuoted 11 lines
David
Quoted 8 lines
}Will create a patch for this.
Best Regards,
Even Xu
Quoted 155 lines
-----Original Message-----
From: David Laight <[email protected]>
Sent: Thursday, February 6, 2025 5:05 PM
To: Xu, Even <[email protected]>
Cc: lkp <[email protected]>; [email protected]; linux- [email protected]; Jiri Kosina <[email protected]>; Sun, Xinpeng <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>
Subject: Re:drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse:
sparse: dubious: !x | !yQuoted 10 lines · Even
Quoted 10 lines
-----Original Message-----
From: David Laight <[email protected]>
Sent: Thursday, February 6, 2025 5:57 AM
To: Xu, Even <[email protected]>
Cc: lkp <[email protected]>; [email protected]; linux- [email protected]; Jiri Kosina <[email protected]>; Sun, Xinpeng <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>
Subject: Re:drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38:sparse:
Quoted 18 lines
Quoted 18 lines
sparse: dubious: !x | !y
Quoted 10 lines · Even
Quoted 10 lines
-----Original Message-----
From: David Laight <[email protected]>
Sent: Thursday, January 30, 2025 6:22 AM
To: lkp <[email protected]>
Cc: Xu, Even <[email protected]>; [email protected]; linux- [email protected]; Jiri Kosina <[email protected]>; Sun, Xinpeng <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>
Subject: Re:drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38:sparse:
Quoted 2 lines
Quoted 2 lines
sparse: dubious: !x | !y
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line · On Wed, 29 Jan 2025 22:02:59 +0800 kernel test robot <[email protected]> wrote:
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
master
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
head: 05dbaf8dd8bf537d4b4eb3115ab42a5fb40ff1f5 commit: a688404b2e20f00cce6d0a2b888ef4ca9154e144 HID: intel-thc-hid:
Quoted 58 lines
Quoted 58 lines
Quoted 26 lines
Quoted 26 lines
intel-thc: Add THC DMA interfaces
Quoted 25 lines
date: 3 weeks ago config: x86_64-allyesconfig(https://download.01.org/0day-ci/archive/20250129/202501292144
.eFD
q4ov
[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a
W=1
build):
(https://download.01.org/0day-ci/archive/20250129/202501292144
.eFD
q4ov
[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Closes: | https://lore.kernel.org/oe-kbuild-all/202501292144.eFDq4ovr- | lkp@ | inte | l.com/Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
sparse warnings: (new ones prefixed by >>)
Quoted 2 lines
Quoted 2 lines
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:298:38: sparse:
sparse: dubious: !x | !y
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c: note:
in included file(through
include/linux/mmzone.h,include/linux/gfp.h,
include/linux/mm.h, ...):Quoted 24 lines
Quoted 11 lines
Quoted 2 lines
include/linux/page-flags.h:237:46: sparse: sparse:self-comparison always
evaluates to false
Quoted 4 lines
include/linux/page-flags.h:237:46: sparse: sparse:self-comparison always evaluates to false
vim +298
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c...
Quoted 3 lines
297 for (i = 0; i < config->prd_tbl_num; i++) {Quoted 1 line
298 if (!config->sgls[i] | !config->sgls_nent[i])
299 continue;
Quoted 6 lines
...
If zeros are unlikely the bit-wise 'or' is pretty likely to generate better code than a logical 'or'.
David
Good suggestion!
So the code can be optimized to:for (i = 0; i < config->prd_tbl_num; i++) { if (config->sgls[i] && config->sgls_nent[i]) { ...... }Quoted 7 lines
Quoted 7 lines
That just adds a level of indentation to the source. It'll generate much the same code as !x || !y. Both will generate two conditional branches.
It almost certainly makes in immeasurable difference here, but !x | !y can be generated using (on x86) the 'sete' instruction to get a 0/1 from the x == 0 compare (that sets the flags), and then doing an 'or' and a
single jump.
Quoted 2 lines
You are right.
I'm always right (except when I'm not)
Quoted 6 lines
I do a simple testing:
83 7d f8 00 cmpl $0x0,-0x8(%rbp) 0f 94 c2 sete %dl 83 7d fc 00 cmpl $0x0,-0x4(%rbp) 0f 94 c0 sete %alOn a modern cpu those two pairs will run in parallel.
Quoted 2 lines
09 d0 or %edx,%eax 84 c0 test %al,%alThe compiler needn't to add the 'test' instruction, but doesn't really like the fact that the x86 'sete' is only available for 8-bit registers.
Quoted 10 lines
74 0f je 1186 <
main+0x3d>Compare to:
83 7d f8 00 cmpl $0x0,-0x8(%rbp) 74 06 je 116f <main+0x26> 83 7d fc 00 cmpl $0x0,-0x4(%rbp) 75 0f jne 117e <main+0x35>So you suggest I'd better keep the original (!x | !y) code, if just for unlikely Zero
comparing?
Looking at the code I'd guess common case is that both values are non-zero. So in the normal case both tests are needed.
Quoted 8 lines
The branch predictor will (hopefully) get the tests right after the first iteration, and I suspect the performance of this code isn't that critical.
So while using | might be an optimisation (rather than a mistake) changing it to || probably doesn't matter.
David
Understood.
Thanks for your suggestions and so many details!
Then I prefer to change back to "||" to make it more readable and avoid miss understanding.
Thanks!
Best Regards,
Even
Quoted 19 lines
Quoted 19 lines
Thanks!
Best Regards,
Even XuQuoted 11 lines
David
Quoted 8 lines
}Will create a patch for this.
Best Regards,
Even Xu