include/linux/make_type.h: Helpers for making u16/u32/u64 values
Quoted 1 line
+#define
make_u16(hi__, lo__)((u16)(u8)(hi__) << 8 | (u8)(lo__))
Public Service Announcement
Identifiers representing macro arguments generally don't need to be undescored. They are local to the macro, they don't leak outside.
End of Public Service Announcement
Firstly, make_u16() doesn't return u16.
Secondly,
#define make_u64(hi__, lo__) ((u64)(hi__) << 32 | (u32)(lo__))
doesn't truncate hi, why?
On Wed, Feb 14, 2024 at 08:20:55PM +0300, Alexey Dobriyan wrote:
...
Quoted 5 lines
Secondly,
#define make_u64(hi__, lo__) ((u64)(hi__) << 32 | (u32)(lo__))doesn't truncate hi, why?
Because it's not needed (the whole point AFAIU is to override promotion to a _signed_ type (int) and here it makes no difference)?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 4 lines · Andy Shevchenko
On Wed, Feb 14, 2024 at 08:20:55PM +0300, Alexey Dobriyan wrote:
...
Quoted 8 lines
Quoted 5 lines
Secondly,
#define make_u64(hi__, lo__) ((u64)(hi__) << 32 | (u32)(lo__))doesn't truncate hi, why?
Because it's not needed (the whole point AFAIU is to override promotion to a _signed_ type (int) and here it makes no difference)?
Well,
make_u64((u64)-1, 0)
will return (u64)-1 unlike
make_u16((u64)-1, 0)
which will return 0xff00.
BTW, I'm for truncation, but it should be done everywhere.
Thirdly, there were no users posted.
Quoted 2 lines · Alexey Dobriyan
Quoted 1 line · Andy Shevchenko
On Wed, Feb 14, 2024 at 08:20:55PM +0300, Alexey Dobriyan wrote:
...
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Secondly,
#define make_u64(hi__, lo__) ((u64)(hi__) << 32 | (u32)(lo__))doesn't truncate hi, why?
Quoted 8 lines
Quoted 2 lines
Because it's not needed (the whole point AFAIU is to override promotion to a _signed_ type (int) and here it makes no difference)?
Well,
make_u64((u64)-1, 0)will return (u64)-1 unlike
How? It's shifted by 32 bits. Am I missing something?
Quoted 1 line
BTW, I'm for truncation, but it should be done everywhere.
I'm not against this.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 2 lines · Alexey Dobriyan
Quoted 1 line · Andy Shevchenko
On Wed, Feb 14, 2024 at 08:20:55PM +0300, Alexey Dobriyan wrote:
...
Quoted 2 lines
Thirdly, there were no users posted.
for make_u64() there is already one at [1]
and Jani pointed other potential candidates [2]
[1]
https://elixir.bootlin.com/linux/v6.8-rc4/source/drivers/gpu/drm/xe/xe_gt_pagefault.c#L555
[2]
https://lore.kernel.org/intel-xe/[email protected]/T/#md6577722f9226258c8eb99119707e12db4dd3b79
Quoted 6 lines · Michal Wajdeczko
Quoted 2 lines · Alexey Dobriyan
Quoted 1 line · Andy Shevchenko
On Wed, Feb 14, 2024 at 08:20:55PM +0300, Alexey Dobriyan wrote:
Quoted 8 lines
...
Quoted 2 lines
Thirdly, there were no users posted.
for
make_u64()there is already one at [1]
[1]
https://elixir.bootlin.com/linux/v6.8-rc4/source/drivers/gpu/drm/xe/xe_gt_pagefault.c#L555
OK, this one doesn't truncate too.
Honestly wordpath.h _sucks_ as a name.
I'd go with stdint.h, at least this name is known from userspace.