Message ID | 20210720132940.1171011-1-sjg@chromium.org |
---|---|
Headers | show |
Series | lib: Add support for a decimal 0m prefix for numbers | expand |
On Tue, Jul 20, 2021 at 07:29:24AM -0600, Simon Glass wrote: > U-Boot mostly uses hex for value input, largely because addresses are much > easier to understand in hex. > > But in some cases a hex value is requested, but it is more convenient to > provide a decimal value. This may be because the value comes from another > source, where its base cannot be controlled. > > This series adds support for a 0m prefix to indicate a decimal number. The I _really_ don't want to invent something here. When the setexpr thread came up before I went and did a little digging. Per https://en.wikipedia.org/wiki/Radix the general way to express a number is (x)y where x is the number and y is the base (and y is in base10, and also a subscript). I thought it was a bit cumbersome for general use and didn't bring it up at the time. If we're going to add some global way to always say a number is decimal, and I'm not sure I think that's a good idea even (I kind of think it might be better on a case by case basis to maybe tweak some prints so that for example "ls mmc 0:10" tells the user it's accessing partition 16 would lead to a quick "oh that's hex, #$%@!"), I think it should follow the radix notation, or if not, some other well known example.
On Tue, Jul 20, 2021 at 07:29:24AM -0600, Simon Glass wrote: > U-Boot mostly uses hex for value input, largely because addresses are much > easier to understand in hex. > > But in some cases a hex value is requested, but it is more convenient to > provide a decimal value. This may be because the value comes from another > source, where its base cannot be controlled. > > This series adds support for a 0m prefix to indicate a decimal number. The > letter 'm' is chosen because: > > - 'm' as in deciMal > - cannot use a-f since they indicate a hex value (e.g. 0d would be > ambiguous) > - 'l' is harder to read since 1 and l look similar (0l123) > - 't' (as in ten) seems a bit obscure NetBSD ddb(4) uses 0t as a prefix for base 10. Jonathan
On Tue, Jul 20, 2021 at 10:00:13AM -0500, Jonathan A. Kollasch wrote: > On Tue, Jul 20, 2021 at 07:29:24AM -0600, Simon Glass wrote: > > U-Boot mostly uses hex for value input, largely because addresses are much > > easier to understand in hex. > > > > But in some cases a hex value is requested, but it is more convenient to > > provide a decimal value. This may be because the value comes from another > > source, where its base cannot be controlled. > > > > This series adds support for a 0m prefix to indicate a decimal number. The > > letter 'm' is chosen because: > > > > - 'm' as in deciMal > > - cannot use a-f since they indicate a hex value (e.g. 0d would be > > ambiguous) > > - 'l' is harder to read since 1 and l look similar (0l123) > > - 't' (as in ten) seems a bit obscure > > NetBSD ddb(4) uses 0t as a prefix for base 10. Oh no... And per https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/n--set-number-base- there's examples of '0t' being decimal and '0n' being decimal. http://web.mit.edu/~jik/sipbsrc/sun4c_53/lsof/lsof_3.61/00FAQ uses 0t the same way NetBSD ddb(4) does. https://docs.oracle.com/cd/E19683-01/806-6545/api-21/index.html is also using 0t for decimal.
Hi Tom, On Tue, 20 Jul 2021 at 08:22, Tom Rini <trini@konsulko.com> wrote: > > On Tue, Jul 20, 2021 at 07:29:24AM -0600, Simon Glass wrote: > > > U-Boot mostly uses hex for value input, largely because addresses are much > > easier to understand in hex. > > > > But in some cases a hex value is requested, but it is more convenient to > > provide a decimal value. This may be because the value comes from another > > source, where its base cannot be controlled. > > > > This series adds support for a 0m prefix to indicate a decimal number. The > > I _really_ don't want to invent something here. When the setexpr thread > came up before I went and did a little digging. Per > https://en.wikipedia.org/wiki/Radix the general way to express a number > is (x)y where x is the number and y is the base (and y is in base10, and > also a subscript). I thought it was a bit cumbersome for general use > and didn't bring it up at the time. Well I don't want to invent something either...but what to do? So for example (10)123 would mean decimal 123? I don't know how we would parse brackets separately from expressions though. > > If we're going to add some global way to always say a number is decimal, > and I'm not sure I think that's a good idea even (I kind of think it > might be better on a case by case basis to maybe tweak some prints so > that for example "ls mmc 0:10" tells the user it's accessing partition > 16 would lead to a quick "oh that's hex, #$%@!"), I think it should > follow the radix notation, or if not, some other well known example. Can you give examples for what you are thinking for radix notation? BTW, quite a bit of the series is a clean-up, so can be reviewed separately. Regards, Simon
On Tue, Jul 20, 2021 at 09:57:55AM -0600, Simon Glass wrote: > Hi Tom, > > On Tue, 20 Jul 2021 at 08:22, Tom Rini <trini@konsulko.com> wrote: > > > > On Tue, Jul 20, 2021 at 07:29:24AM -0600, Simon Glass wrote: > > > > > U-Boot mostly uses hex for value input, largely because addresses are much > > > easier to understand in hex. > > > > > > But in some cases a hex value is requested, but it is more convenient to > > > provide a decimal value. This may be because the value comes from another > > > source, where its base cannot be controlled. > > > > > > This series adds support for a 0m prefix to indicate a decimal number. The > > > > I _really_ don't want to invent something here. When the setexpr thread > > came up before I went and did a little digging. Per > > https://en.wikipedia.org/wiki/Radix the general way to express a number > > is (x)y where x is the number and y is the base (and y is in base10, and > > also a subscript). I thought it was a bit cumbersome for general use > > and didn't bring it up at the time. > > Well I don't want to invent something either...but what to do? > > So for example (10)123 would mean decimal 123? I don't know how we > would parse brackets separately from expressions though. (123)10 would be "123" in decimal. Which is indeed a mouthful. But it would also be generic and (123)16 would be 0x123. So the parsing shouldn't be too hard, for most commands. But then yes, expressions become quite hard. > > If we're going to add some global way to always say a number is decimal, > > and I'm not sure I think that's a good idea even (I kind of think it > > might be better on a case by case basis to maybe tweak some prints so > > that for example "ls mmc 0:10" tells the user it's accessing partition > > 16 would lead to a quick "oh that's hex, #$%@!"), I think it should > > follow the radix notation, or if not, some other well known example. > > Can you give examples for what you are thinking for radix notation? Well, since we don't have subscript in shell, '(number)base' would how it would be. Which I'm not convinced is better than making it clear to users that almost everything is hex input, including a few places that might surprise you such as partition numbers. > BTW, quite a bit of the series is a clean-up, so can be reviewed separately. OK.
On Tue, Jul 20, 2021 at 12:05:47PM -0400, Tom Rini wrote: > On Tue, Jul 20, 2021 at 09:57:55AM -0600, Simon Glass wrote: [..] > > Can you give examples for what you are thinking for radix notation? > > Well, since we don't have subscript in shell, '(number)base' would how > it would be. Which I'm not convinced is better than making it clear to > users that almost everything is hex input, including a few places that > might surprise you such as partition numbers. [FWIW/.02$] As a user, I would be happier to follow a project-wide convention that any decimal command line input is treated as HEX or DEC, rather than being forced to surround any number by its base in the shell. -- Best regards, Eugeniu Rosca
Hi Tom. On Tue, 20 Jul 2021 at 10:05, Tom Rini <trini@konsulko.com> wrote: > > On Tue, Jul 20, 2021 at 09:57:55AM -0600, Simon Glass wrote: > > Hi Tom, > > > > On Tue, 20 Jul 2021 at 08:22, Tom Rini <trini@konsulko.com> wrote: > > > > > > On Tue, Jul 20, 2021 at 07:29:24AM -0600, Simon Glass wrote: > > > > > > > U-Boot mostly uses hex for value input, largely because addresses are much > > > > easier to understand in hex. > > > > > > > > But in some cases a hex value is requested, but it is more convenient to > > > > provide a decimal value. This may be because the value comes from another > > > > source, where its base cannot be controlled. > > > > > > > > This series adds support for a 0m prefix to indicate a decimal number. The > > > > > > I _really_ don't want to invent something here. When the setexpr thread > > > came up before I went and did a little digging. Per > > > https://en.wikipedia.org/wiki/Radix the general way to express a number > > > is (x)y where x is the number and y is the base (and y is in base10, and > > > also a subscript). I thought it was a bit cumbersome for general use > > > and didn't bring it up at the time. > > > > Well I don't want to invent something either...but what to do? > > > > So for example (10)123 would mean decimal 123? I don't know how we > > would parse brackets separately from expressions though. > > (123)10 would be "123" in decimal. Which is indeed a mouthful. But it > would also be generic and (123)16 would be 0x123. So the parsing > shouldn't be too hard, for most commands. But then yes, expressions > become quite hard. > > > > If we're going to add some global way to always say a number is decimal, > > > and I'm not sure I think that's a good idea even (I kind of think it > > > might be better on a case by case basis to maybe tweak some prints so > > > that for example "ls mmc 0:10" tells the user it's accessing partition > > > 16 would lead to a quick "oh that's hex, #$%@!"), I think it should > > > follow the radix notation, or if not, some other well known example. > > > > Can you give examples for what you are thinking for radix notation? > > Well, since we don't have subscript in shell, '(number)base' would how > it would be. Which I'm not convinced is better than making it clear to > users that almost everything is hex input, including a few places that > might surprise you such as partition numbers. After a bit of thought and digging, I think that is a mathematical thing and confusing/unworkable on the command line. Should we consider 0t for decimal? > > > BTW, quite a bit of the series is a clean-up, so can be reviewed separately. > > OK. > > -- > Tom Regards, Simon
On Tue, Jul 20, 2021 at 12:33:14PM -0600, Simon Glass wrote: > Hi Tom. > > On Tue, 20 Jul 2021 at 10:05, Tom Rini <trini@konsulko.com> wrote: > > > > On Tue, Jul 20, 2021 at 09:57:55AM -0600, Simon Glass wrote: > > > Hi Tom, > > > > > > On Tue, 20 Jul 2021 at 08:22, Tom Rini <trini@konsulko.com> wrote: > > > > > > > > On Tue, Jul 20, 2021 at 07:29:24AM -0600, Simon Glass wrote: > > > > > > > > > U-Boot mostly uses hex for value input, largely because addresses are much > > > > > easier to understand in hex. > > > > > > > > > > But in some cases a hex value is requested, but it is more convenient to > > > > > provide a decimal value. This may be because the value comes from another > > > > > source, where its base cannot be controlled. > > > > > > > > > > This series adds support for a 0m prefix to indicate a decimal number. The > > > > > > > > I _really_ don't want to invent something here. When the setexpr thread > > > > came up before I went and did a little digging. Per > > > > https://en.wikipedia.org/wiki/Radix the general way to express a number > > > > is (x)y where x is the number and y is the base (and y is in base10, and > > > > also a subscript). I thought it was a bit cumbersome for general use > > > > and didn't bring it up at the time. > > > > > > Well I don't want to invent something either...but what to do? > > > > > > So for example (10)123 would mean decimal 123? I don't know how we > > > would parse brackets separately from expressions though. > > > > (123)10 would be "123" in decimal. Which is indeed a mouthful. But it > > would also be generic and (123)16 would be 0x123. So the parsing > > shouldn't be too hard, for most commands. But then yes, expressions > > become quite hard. > > > > > > If we're going to add some global way to always say a number is decimal, > > > > and I'm not sure I think that's a good idea even (I kind of think it > > > > might be better on a case by case basis to maybe tweak some prints so > > > > that for example "ls mmc 0:10" tells the user it's accessing partition > > > > 16 would lead to a quick "oh that's hex, #$%@!"), I think it should > > > > follow the radix notation, or if not, some other well known example. > > > > > > Can you give examples for what you are thinking for radix notation? > > > > Well, since we don't have subscript in shell, '(number)base' would how > > it would be. Which I'm not convinced is better than making it clear to > > users that almost everything is hex input, including a few places that > > might surprise you such as partition numbers. > > After a bit of thought and digging, I think that is a mathematical > thing and confusing/unworkable on the command line. I agree. > Should we consider 0t for decimal? My biggest concern is that when I search for "0t prefix" the first relevant answers are the MS links where 0t is for ocTal, and not the other examples where it's decimal (base Ten, I assume).
Dear Simon, In message <20210720132940.1171011-1-sjg@chromium.org> you wrote: > U-Boot mostly uses hex for value input, largely because addresses are much > easier to understand in hex. > > But in some cases a hex value is requested, but it is more convenient to > provide a decimal value. This may be because the value comes from another > source, where its base cannot be controlled. > > This series adds support for a 0m prefix to indicate a decimal number. The > letter 'm' is chosen because: What is the impact of this change on the U-Boot size for typical configurations? Best regards, Wolfgang Denk
Hi, In message <20210720160547.GM9379@bill-the-cat> you wrote: > > > So for example (10)123 would mean decimal 123? I don't know how we > > would parse brackets separately from expressions though. > > (123)10 would be "123" in decimal. Which is indeed a mouthful. But it > would also be generic and (123)16 would be 0x123. So the parsing > shouldn't be too hard, for most commands. But then yes, expressions > become quite hard. Come on, guys, be serious! This is a boot loader. Size matters. Do we _really_ need all this, and is it worth the code size? Simon's patches include some cleanup, which probably even reduces the size, so good. But whether it's 0m123 or 0t123 or 0!123 or ... is pretty much irrelevant - chose one symbol, use it, and be done with that. Best regards, Wolfgang Denk
Hi Tom, On Tue, 20 Jul 2021 at 13:28, Tom Rini <trini@konsulko.com> wrote: > > On Tue, Jul 20, 2021 at 12:33:14PM -0600, Simon Glass wrote: > > Hi Tom. > > > > On Tue, 20 Jul 2021 at 10:05, Tom Rini <trini@konsulko.com> wrote: > > > > > > On Tue, Jul 20, 2021 at 09:57:55AM -0600, Simon Glass wrote: > > > > Hi Tom, > > > > > > > > On Tue, 20 Jul 2021 at 08:22, Tom Rini <trini@konsulko.com> wrote: > > > > > > > > > > On Tue, Jul 20, 2021 at 07:29:24AM -0600, Simon Glass wrote: > > > > > > > > > > > U-Boot mostly uses hex for value input, largely because addresses are much > > > > > > easier to understand in hex. > > > > > > > > > > > > But in some cases a hex value is requested, but it is more convenient to > > > > > > provide a decimal value. This may be because the value comes from another > > > > > > source, where its base cannot be controlled. > > > > > > > > > > > > This series adds support for a 0m prefix to indicate a decimal number. The > > > > > > > > > > I _really_ don't want to invent something here. When the setexpr thread > > > > > came up before I went and did a little digging. Per > > > > > https://en.wikipedia.org/wiki/Radix the general way to express a number > > > > > is (x)y where x is the number and y is the base (and y is in base10, and > > > > > also a subscript). I thought it was a bit cumbersome for general use > > > > > and didn't bring it up at the time. > > > > > > > > Well I don't want to invent something either...but what to do? > > > > > > > > So for example (10)123 would mean decimal 123? I don't know how we > > > > would parse brackets separately from expressions though. > > > > > > (123)10 would be "123" in decimal. Which is indeed a mouthful. But it > > > would also be generic and (123)16 would be 0x123. So the parsing > > > shouldn't be too hard, for most commands. But then yes, expressions > > > become quite hard. > > > > > > > > If we're going to add some global way to always say a number is decimal, > > > > > and I'm not sure I think that's a good idea even (I kind of think it > > > > > might be better on a case by case basis to maybe tweak some prints so > > > > > that for example "ls mmc 0:10" tells the user it's accessing partition > > > > > 16 would lead to a quick "oh that's hex, #$%@!"), I think it should > > > > > follow the radix notation, or if not, some other well known example. > > > > > > > > Can you give examples for what you are thinking for radix notation? > > > > > > Well, since we don't have subscript in shell, '(number)base' would how > > > it would be. Which I'm not convinced is better than making it clear to > > > users that almost everything is hex input, including a few places that > > > might surprise you such as partition numbers. > > > > After a bit of thought and digging, I think that is a mathematical > > thing and confusing/unworkable on the command line. > > I agree. > > > Should we consider 0t for decimal? > > My biggest concern is that when I search for "0t prefix" the first > relevant answers are the MS links where 0t is for ocTal, and not the > other examples where it's decimal (base Ten, I assume). Hmm, so make 0n would make more sense? I know it is a new thing but I think it would be very useful... Regards, Simon
Hi Wolfgang, On Wed, 21 Jul 2021 at 01:53, Wolfgang Denk <wd@denx.de> wrote: > > Hi, > > In message <20210720160547.GM9379@bill-the-cat> you wrote: > > > > > So for example (10)123 would mean decimal 123? I don't know how we > > > would parse brackets separately from expressions though. > > > > (123)10 would be "123" in decimal. Which is indeed a mouthful. But it > > would also be generic and (123)16 would be 0x123. So the parsing > > shouldn't be too hard, for most commands. But then yes, expressions > > become quite hard. > > Come on, guys, be serious! This is a boot loader. Size matters. > > Do we _really_ need all this, and is it worth the code size? > > Simon's patches include some cleanup, which probably even reduces > the size, so good. It reduces U-Boot proper by about 400-700 bytes but not much effect on SPL: 16: RFC: Change simple_strtoul() et al to default to hex arm: evb-ast2500 brppt1_spi brsmarc1 aarch64: (for 300/301 boards) all -754.8 bss +0.0 spl/u-boot-spl:all -9.9 spl/u-boot-spl:text -9.9 text -754.8 arc: (for 10/11 boards) all -242.0 text -242.0 arm: (for 625/627 boards) all -468.7 bss +0.8 data +0.0 rodata +0.0 spl/u-boot-spl:all -1.5 spl/u-boot-spl:bss -0.1 spl/u-boot-spl:text -1.4 text -469.5 m68k: (for 18/18 boards) all -499.1 data +11.8 text -510.9 microblaze: (for 1/1 boards) all -392.0 bss +44.0 data +4.0 rodata -4.0 text -436.0 mips: (for 43/43 boards) all -457.5 bss +1.1 text -458.6 nds32: (for 2/2 boards) all -206.0 text -206.0 nios2: (for 2/2 boards) all -480.0 text -480.0 powerpc: (for 40/98 boards) all -708.4 text -708.4 > > But whether it's 0m123 or 0t123 or 0!123 or ... is pretty much > irrelevant - chose one symbol, use it, and be done with that. Regards, Simon
Hi, On Wed, 21 Jul 2021 at 08:46, Simon Glass <sjg@chromium.org> wrote: > > Hi Wolfgang, > > On Wed, 21 Jul 2021 at 01:53, Wolfgang Denk <wd@denx.de> wrote: > > > > Hi, > > > > In message <20210720160547.GM9379@bill-the-cat> you wrote: > > > > > > > So for example (10)123 would mean decimal 123? I don't know how we > > > > would parse brackets separately from expressions though. > > > > > > (123)10 would be "123" in decimal. Which is indeed a mouthful. But it > > > would also be generic and (123)16 would be 0x123. So the parsing > > > shouldn't be too hard, for most commands. But then yes, expressions > > > become quite hard. > > > > Come on, guys, be serious! This is a boot loader. Size matters. > > > > Do we _really_ need all this, and is it worth the code size? > > > > Simon's patches include some cleanup, which probably even reduces > > the size, so good. > > It reduces U-Boot proper by about 400-700 bytes but not much effect on SPL: > > 16: RFC: Change simple_strtoul() et al to default to hex > arm: evb-ast2500 brppt1_spi brsmarc1 > aarch64: (for 300/301 boards) all -754.8 bss +0.0 > spl/u-boot-spl:all -9.9 spl/u-boot-spl:text -9.9 text -754.8 > arc: (for 10/11 boards) all -242.0 text -242.0 > arm: (for 625/627 boards) all -468.7 bss +0.8 data +0.0 rodata > +0.0 spl/u-boot-spl:all -1.5 spl/u-boot-spl:bss -0.1 > spl/u-boot-spl:text -1.4 text -469.5 > m68k: (for 18/18 boards) all -499.1 data +11.8 text -510.9 > microblaze: (for 1/1 boards) all -392.0 bss +44.0 data +4.0 rodata > -4.0 text -436.0 > mips: (for 43/43 boards) all -457.5 bss +1.1 text -458.6 > nds32: (for 2/2 boards) all -206.0 text -206.0 > nios2: (for 2/2 boards) all -480.0 text -480.0 > powerpc: (for 40/98 boards) all -708.4 text -708.4 > > > > > But whether it's 0m123 or 0t123 or 0!123 or ... is pretty much > > irrelevant - chose one symbol, use it, and be done with that. Given Roland's setexpr thing and the discussion here I think I will resend the series with 0n for decimal and drop the binary/octal for now. It is a tiny size increment and easy to add later if useful. Regards, Simon