Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Bernd Petrovitsch
On Fre, 2012-09-14 at 16:25 +0200, Jan Engelhardt wrote: > On Friday 2012-09-14 15:46, Jim Rees wrote: > >Jan Engelhardt wrote: > > >A pure K version would use a string: > > >#define base10len(i) > > "\0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14"[sizeof(i)] > > >(if I converted them properly into

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jan Engelhardt
On Friday 2012-09-14 15:46, Jim Rees wrote: >Jan Engelhardt wrote: > > >A pure K version would use a string: > >#define base10len(i) "\0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14"[sizeof(i)] > >(if I converted them properly into hexadecimal) > The syntax is \x01\x03\x05... > >K doesn't have the

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Jan Engelhardt wrote: Your way does not function as originally desired. * base10len(i) no longer expands to a compile-time constant * you will definitely have a variable base10len_vals in your objects, so you waste a read operation whenever it is used. No, I meant my original

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Bernd Petrovitsch wrote: [] > Pure K: We can (and should) make it "const" too. No "const" in K either. But I think we can assume the kernel will be compiled with something a bit more advance. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Jan Engelhardt wrote: >A pure K version would use a string: >#define base10len(i) "\0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14"[sizeof(i)] >(if I converted them properly into hexadecimal) The syntax is \x01\x03\x05... K doesn't have the \x escape, only \0 (octal). -- To unsubscribe from

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jan Engelhardt
On Friday 2012-09-14 14:30, Jim Rees wrote in an odd quote style (the > are mine): >Bernd Petrovitsch wrote: > > A pure K version would use a string: > snip > #define base10len(i) "\0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14"[sizeof(i)] > snip > (if I converted them

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Bernd Petrovitsch
On Fre, 2012-09-14 at 08:30 -0400, Jim Rees wrote: > Bernd Petrovitsch wrote: [...] > A pure K version would use a string: > snip > #define base10len(i) "\0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14"[sizeof(i)] > snip > (if I converted them properly into hexadecimal)

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread J. Bruce Fields
On Fri, Sep 14, 2012 at 08:30:14AM -0400, Jim Rees wrote: > But I still like my way better. Yeah. It looks less mysterious once you realize it's just a straightforward application of the usual coincidence 2^10 = 1024 ~ 1000 = 10^3 How about this? Also with some more defines because I

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jan Engelhardt
On Friday 2012-09-14 11:17, Bernd Petrovitsch wrote: >Shouldn't that have been > snip >#define base10len(i) ((const int[]){1,3,5,8,10,13,15,17,20}[sizeof(i)]) > snip Yeah. >A pure K version would use a string: >#define base10len(i)

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Bernd Petrovitsch wrote: On Mon, 2012-09-10 at 08:19 +0200, Jan Engelhardt wrote: > On Tuesday 2012-08-21 23:29, J. Bruce Fields wrote: [...] > >+/* > >+ * length of the decimal representation of an unsigned integer. Just an > >+ * approximation, but it's right for types of size 1 to

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Bernd Petrovitsch
On Mon, 2012-09-10 at 08:19 +0200, Jan Engelhardt wrote: > On Tuesday 2012-08-21 23:29, J. Bruce Fields wrote: [...] > >+/* > >+ * length of the decimal representation of an unsigned integer. Just an > >+ * approximation, but it's right for types of size 1 to 36 bytes: > >+ */ > >+#define

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Bernd Petrovitsch
On Mon, 2012-09-10 at 08:19 +0200, Jan Engelhardt wrote: On Tuesday 2012-08-21 23:29, J. Bruce Fields wrote: [...] +/* + * length of the decimal representation of an unsigned integer. Just an + * approximation, but it's right for types of size 1 to 36 bytes: + */ +#define base10len(i)

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Bernd Petrovitsch wrote: On Mon, 2012-09-10 at 08:19 +0200, Jan Engelhardt wrote: On Tuesday 2012-08-21 23:29, J. Bruce Fields wrote: [...] +/* + * length of the decimal representation of an unsigned integer. Just an + * approximation, but it's right for types of size 1 to 36

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jan Engelhardt
On Friday 2012-09-14 11:17, Bernd Petrovitsch wrote: Shouldn't that have been snip #define base10len(i) ((const int[]){1,3,5,8,10,13,15,17,20}[sizeof(i)]) snip Yeah. A pure KR-C version would use a string: #define base10len(i)

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread J. Bruce Fields
On Fri, Sep 14, 2012 at 08:30:14AM -0400, Jim Rees wrote: But I still like my way better. Yeah. It looks less mysterious once you realize it's just a straightforward application of the usual coincidence 2^10 = 1024 ~ 1000 = 10^3 How about this? Also with some more defines because I

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Bernd Petrovitsch
On Fre, 2012-09-14 at 08:30 -0400, Jim Rees wrote: Bernd Petrovitsch wrote: [...] A pure KR-C version would use a string: snip #define base10len(i) \0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14[sizeof(i)] snip (if I converted them properly into hexadecimal) and

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jan Engelhardt
On Friday 2012-09-14 14:30, Jim Rees wrote in an odd quote style (the are mine): Bernd Petrovitsch wrote: A pure KR-C version would use a string: snip #define base10len(i) \0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14[sizeof(i)] snip (if I converted them properly

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Jan Engelhardt wrote: A pure KR-C version would use a string: #define base10len(i) \0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14[sizeof(i)] (if I converted them properly into hexadecimal) The syntax is \x01\x03\x05... KR doesn't have the \x escape, only \0 (octal). -- To unsubscribe from

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Bernd Petrovitsch wrote: [] Pure KR: We can (and should) make it const too. No const in KR either. But I think we can assume the kernel will be compiled with something a bit more advance. -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Jan Engelhardt wrote: Your way does not function as originally desired. * base10len(i) no longer expands to a compile-time constant * you will definitely have a variable base10len_vals in your objects, so you waste a read operation whenever it is used. No, I meant my original

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jan Engelhardt
On Friday 2012-09-14 15:46, Jim Rees wrote: Jan Engelhardt wrote: A pure KR-C version would use a string: #define base10len(i) \0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14[sizeof(i)] (if I converted them properly into hexadecimal) The syntax is \x01\x03\x05... KR doesn't have the \x

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Bernd Petrovitsch
On Fre, 2012-09-14 at 16:25 +0200, Jan Engelhardt wrote: On Friday 2012-09-14 15:46, Jim Rees wrote: Jan Engelhardt wrote: A pure KR-C version would use a string: #define base10len(i) \0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14[sizeof(i)] (if I converted them properly into hexadecimal)

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-10 Thread Jan Engelhardt
On Tuesday 2012-08-21 23:29, J. Bruce Fields wrote: >I've seen a couple examples recently where we've gotten this wrong. >Maybe something like this would help? Is there some better way? >(Approximation due to Jim Rees). > >+/* >+ * length of the decimal representation of an unsigned integer.

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-10 Thread Jan Engelhardt
On Tuesday 2012-08-21 23:29, J. Bruce Fields wrote: I've seen a couple examples recently where we've gotten this wrong. Maybe something like this would help? Is there some better way? (Approximation due to Jim Rees). +/* + * length of the decimal representation of an unsigned integer. Just an

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread Jim Rees
Al Viro wrote: On Tue, Aug 21, 2012 at 05:22:27PM -0400, Jim Rees wrote: > J. Bruce Fields wrote: > > From: "J. Bruce Fields" > > I've seen a couple examples recently where we've gotten this wrong. > Maybe something like this would help? Is there some better way? >

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread J. Bruce Fields
On Tue, Aug 21, 2012 at 11:06:13PM +0100, Al Viro wrote: > On Tue, Aug 21, 2012 at 05:22:27PM -0400, Jim Rees wrote: > > J. Bruce Fields wrote: > > > > From: "J. Bruce Fields" > > > > I've seen a couple examples recently where we've gotten this wrong. > > Maybe something like this would

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread Al Viro
On Tue, Aug 21, 2012 at 05:22:27PM -0400, Jim Rees wrote: > J. Bruce Fields wrote: > > From: "J. Bruce Fields" > > I've seen a couple examples recently where we've gotten this wrong. > Maybe something like this would help? Is there some better way? > > (Approximation due to Jim

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread Jim Rees
J. Bruce Fields wrote: From: "J. Bruce Fields" I've seen a couple examples recently where we've gotten this wrong. Maybe something like this would help? Is there some better way? (Approximation due to Jim Rees). Please add Suggested-by: Jim Rees . I'm thinking of patenting the

[PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread J. Bruce Fields
From: "J. Bruce Fields" I've seen a couple examples recently where we've gotten this wrong. Maybe something like this would help? Is there some better way? (Approximation due to Jim Rees). Signed-off-by: J. Bruce Fields --- include/linux/string.h |6 ++ net/sunrpc/cache.c |2

[PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread J. Bruce Fields
From: J. Bruce Fields bfie...@redhat.com I've seen a couple examples recently where we've gotten this wrong. Maybe something like this would help? Is there some better way? (Approximation due to Jim Rees). Signed-off-by: J. Bruce Fields bfie...@redhat.com --- include/linux/string.h |6

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread Jim Rees
J. Bruce Fields wrote: From: J. Bruce Fields bfie...@redhat.com I've seen a couple examples recently where we've gotten this wrong. Maybe something like this would help? Is there some better way? (Approximation due to Jim Rees). Please add Suggested-by: Jim Rees r...@umich.edu.

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread Al Viro
On Tue, Aug 21, 2012 at 05:22:27PM -0400, Jim Rees wrote: J. Bruce Fields wrote: From: J. Bruce Fields bfie...@redhat.com I've seen a couple examples recently where we've gotten this wrong. Maybe something like this would help? Is there some better way? (Approximation due

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread J. Bruce Fields
On Tue, Aug 21, 2012 at 11:06:13PM +0100, Al Viro wrote: On Tue, Aug 21, 2012 at 05:22:27PM -0400, Jim Rees wrote: J. Bruce Fields wrote: From: J. Bruce Fields bfie...@redhat.com I've seen a couple examples recently where we've gotten this wrong. Maybe something like this

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread Jim Rees
Al Viro wrote: On Tue, Aug 21, 2012 at 05:22:27PM -0400, Jim Rees wrote: J. Bruce Fields wrote: From: J. Bruce Fields bfie...@redhat.com I've seen a couple examples recently where we've gotten this wrong. Maybe something like this would help? Is there some better