digitalmars.D.announce - core.checkedint added to druntime
- Walter Bright (9/9) Jun 17 2014 https://github.com/D-Programming-Language/druntime/pull/839
- bearophile (20/23) Jun 18 2014 Why aren't functions with ubyte/byte/short/ushort arguments
- Walter Bright (3/6) Jun 18 2014 Because there is no ubyte/byte/short/ushort math in C, C++ or D. There i...
- bearophile (26/28) Jun 18 2014 A little of ubyte math is present, perhaps for this you add
- David Bregman (4/5) Jun 18 2014 I think the mulu implementation is incorrect. There can be an
- David Nadlinger (4/7) Jun 20 2014 I also noticed this; another easy counter-example would be 1<<32
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (9/12) Jun 22 2014 I did this in C/C++ a while ago, out of which I have forgotten
- Walter Bright (2/13) Jun 22 2014 Thank you, that's very generous.
- Paul D Anderson (2/15) Jul 01 2014
- David Nadlinger (5/6) Jul 01 2014 It's currently in Git master, so yes – but we definitely need to
https://github.com/D-Programming-Language/druntime/pull/839 While being a very modest piece of code in and of itself, I believe this offers a significant opportunity that both D compilers and user defined types can exploit. Not only can it be used to create an efficient safeint data type, it can be used to implement multi-precision integer arithmetic types. I'd also like to see it used to replace the various ad-hoc schemes currently in use. It should also be used in dmd itself for things like detecting array size overflows, which is currently done ad-hoc, and detecting overflows in CTFE. For background information and rationale, see http://blog.regehr.org/archives/1139
Jun 17 2014
Walter Bright:https://github.com/D-Programming-Language/druntime/pull/839Why aren't functions with ubyte/byte/short/ushort arguments included? -------------- Here Lionello Lunesu has suggested a __traits(valueRange, <expression>) for built-in values: http://forum.dlang.org/thread/lnrc8l$1254$1 digitalmars.com Once such trait is working on checkedint values, can this help the compiler remove some useless tests and increase the performance of checked ints?it can be used to implement multi-precision integer arithmetic types.It looks very useful for the "small value optimization" for BigIntegers, to not allocate on the heap when the numbers are small, and switch to the heap allocation when they grow. If you use such improved bigintegers to write code that is not supposed to overflow the range of normal integers, you obtain code that is only moderately slower than using checkedints, but it also gives the correct results if some overflow has occurred :-) Bye, bearophile
Jun 18 2014
On 6/18/2014 2:43 AM, bearophile wrote:Walter Bright:Because there is no ubyte/byte/short/ushort math in C, C++ or D. There is only int/long math.https://github.com/D-Programming-Language/druntime/pull/839Why aren't functions with ubyte/byte/short/ushort arguments included?
Jun 18 2014
Walter Bright:Because there is no ubyte/byte/short/ushort math in C, C++ or D. There is only int/long math.A little of ubyte math is present, perhaps for this you add "uinc", "sinc", "udec", "sdec" functions to core.checkedint that support ubyte/byte/short/ushort types too: void main() { ubyte x = 100; x++; } But you are right, in D if you sum two ubytes you get an int: void main() { ubyte x = 100; ubyte y = 200; pragma(msg, typeof(x + y)); // Prints "int" } Yet sometimes you want to perform safe math operations on ubytes/bytes/shorts/ushorts, and keep the same type for the results. So I presume a future Phobos Safe math based on core.checkedint will need to check the ranges by itself, to allow checked assignments back to the same types: void main() { Safe!ubyte x = 100; Safe!ubyte y = 200; Safe!ubyte z = x + y; } Bye, bearophile
Jun 18 2014
On Wednesday, 18 June 2014 at 01:26:16 UTC, Walter Bright wrote:https://github.com/D-Programming-Language/druntime/pull/839I think the mulu implementation is incorrect. There can be an overflow even when r = 0. For example consider the int version with x = y = 1<<16.
Jun 18 2014
On Thursday, 19 June 2014 at 03:42:11 UTC, David Bregman wrote:I think the mulu implementation is incorrect. There can be an overflow even when r = 0. For example consider the int version with x = y = 1<<16.I also noticed this; another easy counter-example would be 1<<32 for ulong multiplication. Filed as: https://issues.dlang.org/show_bug.cgi?id=12958
Jun 20 2014
While being a very modest piece of code in and of itself, I believe this offers a significant opportunity that both D compilers and user defined types can exploit.I did this in C/C++ a while ago, out of which I have forgotten most of it :) https://github.com/nordlow/justcxx/blob/master/sadd.h https://github.com/nordlow/justcxx/blob/master/ssub.h https://github.com/nordlow/justcxx/blob/master/smul.h Tests are here: https://github.com/nordlow/justcxx/blob/master/t_ranged_and_saturated.cpp Maybe there's something more here that could give further ideas. Pick what you want.
Jun 22 2014
On 6/22/2014 12:37 AM, "Nordlöw" wrote:Thank you, that's very generous.While being a very modest piece of code in and of itself, I believe this offers a significant opportunity that both D compilers and user defined types can exploit.I did this in C/C++ a while ago, out of which I have forgotten most of it :) https://github.com/nordlow/justcxx/blob/master/sadd.h https://github.com/nordlow/justcxx/blob/master/ssub.h https://github.com/nordlow/justcxx/blob/master/smul.h Tests are here: https://github.com/nordlow/justcxx/blob/master/t_ranged_and_saturated.cpp Maybe there's something more here that could give further ideas. Pick what you want.
Jun 22 2014
Will this be in the 2.066 Beta? On Wednesday, 18 June 2014 at 01:26:16 UTC, Walter Bright wrote:https://github.com/D-Programming-Language/druntime/pull/839 While being a very modest piece of code in and of itself, I believe this offers a significant opportunity that both D compilers and user defined types can exploit. Not only can it be used to create an efficient safeint data type, it can be used to implement multi-precision integer arithmetic types. I'd also like to see it used to replace the various ad-hoc schemes currently in use. It should also be used in dmd itself for things like detecting array size overflows, which is currently done ad-hoc, and detecting overflows in CTFE. For background information and rationale, see http://blog.regehr.org/archives/1139
Jul 01 2014
On Tuesday, 1 July 2014 at 22:07:01 UTC, Paul D Anderson wrote:Will this be in the 2.066 Beta?It's currently in Git master, so yes – but we definitely need to fix https://issues.dlang.org/show_bug.cgi?id=12958 before the release (mul is horribily broken). David
Jul 01 2014