digitalmars.D - When will you implement cent and ucent?
- Murilo (2/2) Mar 25 2022 I have been waiting for years now, can't you guys just add these
- Adam Ruppe (2/2) Mar 25 2022 What would you do with it? There's a number of alternatives
- Murilo (3/5) Mar 25 2022 I would perform calculation with astronomical numbers and atomic
- Era Scarecrow (11/13) Mar 25 2022 If you aren't sure what size of numbers you need, BigInt/BigNum
- Murilo (4/9) Mar 26 2022 I figured BitInt would be slower because it works with strings,
- H. S. Teoh (7/10) Mar 26 2022 That is false. BigInt works with arrays of ulongs, which is as binary
- Era Scarecrow (14/21) Mar 26 2022 It's been a while since we have been doing BCD (*Binary Coded
- Murilo (8/17) Mar 27 2022 Thanks for clearing that up, I guess I'll just stick to BigInt
- Sergey (5/12) Mar 27 2022 There is no D implementation, but there is a good C library for
- IGotD- (2/4) Mar 26 2022 Is there any implementation similar to the C# decimal type?
- deadalnix (5/7) Mar 28 2022 There is literally no way to implement a big number lib that'll
- Adam D Ruppe (4/8) Mar 29 2022 Murilo might not need a big number lib at all.
- 12345swordy (4/13) Mar 29 2022 That not going to work if you are comparing things that are
- H. S. Teoh (13/20) Mar 29 2022 [...]
- Abdulhaq (5/25) Mar 29 2022 Yes, and Adam did take out a double indemnity with "might not"
- 12345swordy (5/25) Mar 29 2022 Where did you get the 1e+1000 number from? That is way bigger
- H. S. Teoh (9/15) Mar 29 2022 [...]
- Mike Parker (5/7) Mar 25 2022 Walter has plans to deprecate cent/ucent in favor of a library
- Era Scarecrow (10/12) Mar 25 2022 I have a library i wrote a few years ago you can use. Compiled
- Salih Dincer (4/6) Mar 26 2022 The code is a bit old, but it works flawlessly and has useful
- Guillaume Piolat (2/8) Mar 26 2022 I think it just need to be in a dub package one can find.
- Era Scarecrow (7/10) Mar 26 2022 Flawless maybe, but definitely slow when you get to division. It
- Walter Bright (7/9) Mar 26 2022 I did some work implementing it as a native type. But after a while I re...
- Era Scarecrow (9/18) Mar 26 2022 Multiplication and division are the only parts needing any real
- Salih Dincer (9/14) Mar 27 2022 I hope you will be successful because we need to use it without
- Era Scarecrow (25/32) Mar 27 2022 One could just use BigInt under the hood and then have it do
- user1234 (12/17) Mar 27 2022 To be called, the remaining work is that a library type must be
- Salih Dincer (5/11) Mar 27 2022 I guess I must have missed this "complexity" detail, as I didn't
- Guillaume Piolat (7/8) Mar 28 2022 I tried to find faults in its divide and modulo so that I could
- deadalnix (90/98) Mar 28 2022 With LDC 1.27.1 :
- Era Scarecrow (19/20) Mar 28 2022 Because different architectures and compilers do different
- deadalnix (21/27) Mar 29 2022 No, I picked the exact same toolchain on purpose so that the
- max haughton (7/30) Mar 29 2022 I agree. Having dmd as a fast backend is OK but if something as
- Guillaume Piolat (7/10) Mar 29 2022 In intel-intrinsics, unsupported vector types are emulated:
- Era Scarecrow (17/34) Mar 29 2022 To me it looked like you did a C++ vs D somewhere in the way.
- Walter Bright (3/5) Mar 30 2022 That's the attractiveness of a builtin function. It'll at least work for...
- Quirin Schroll (9/14) Mar 31 2022 At some point, it’s going to be easier to make those types
- rikki cattermole (6/10) Mar 31 2022 This is something I have long since considered.
- Tejas (7/18) Mar 31 2022 So will this look something like
- Era Scarecrow (7/21) Mar 31 2022 Maybe. Some use int32 as the identifier rather than int.
- rikki cattermole (2/8) Mar 31 2022 The name could be whatever you want, but yeah.
- Steven Schveighoffer (3/13) Apr 01 2022 As long as the compiler errors display the alias and not the traits.
- rikki cattermole (1/1) Apr 01 2022 Indeed, this is one time when typedef's would be better suited to the ta...
- Walter Bright (24/48) Mar 30 2022 You see a similar thing when 32 bit compilation does 64 bit arithmetic:
- deadalnix (6/13) Mar 31 2022 So now that you just killed the library solution by having the
- kinke (10/13) Mar 31 2022 With LDC's support for inline LLVM IR
- max haughton (4/17) Mar 31 2022 It's still quite ugly compared to just implementing cent properly
- kinke (6/9) Mar 31 2022 There's another advantage (besides the main one - not having to
- max haughton (7/16) Mar 31 2022 The few times I have needed wide arithmetic in D, it not being
- Walter Bright (3/5) Mar 31 2022 There are very few uses for a 128 bit type, so all the conveniences are ...
- 12345swordy (2/8) Mar 31 2022 That is a non sequitur statement Walter.
- Petar Kirov [ZombineDev] (7/13) Mar 31 2022 For the past 2.5 years, I've worked on applications that use
- Walter Bright (11/16) Apr 01 2022 A library 128 bit type would be pretty easy to do, now that the computat...
- mee6 (2/16) Apr 01 2022 I'd do it for money lol
- Walter Bright (3/6) Apr 02 2022 What the hell, I'm tired of the jawboning and did it for the greater glo...
- Salih Dincer (4/11) Apr 02 2022 Thank you on behalf of myself. I wish I could a little support
- Salih Dincer (27/29) Apr 02 2022 I don't know how to add it to Github. A small contribution, they
- Murilo (3/10) Feb 21 2023 Thank you for your work, I'm very happy and thankful.
- deadalnix (10/24) Apr 01 2022 I have done that.
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (5/8) Apr 11 2022 Does LLVM support that width good code gen? Intel/AMD have some
- user1234 (6/14) Apr 11 2022 LLVM 128 type (named `i128`) on x86_64 produces standard
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (3/12) Apr 11 2022 Thanks, it appears to use "MULX" if you specify the compiler
- user1234 (7/22) Apr 11 2022 Actually, as said in the beginning of the thread I expect that
- Iain Buclaw (2/8) Apr 02 2022 Yep, they were all written to be CTFE-friendly.
- Walter Bright (6/10) Mar 31 2022 No, because a great deal of the compiler internals would have to be redo...
- Iain Buclaw (7/23) Apr 02 2022 We can do the same as complex numbers here.
- Johan (3/4) Mar 31 2022 Indeed. Bump. People please re-read deadalnix messages.
- Timon Gehr (15/23) Mar 31 2022 Well, I was with deadalnix on this even before reading the messages
- Iain Buclaw (4/24) Apr 02 2022 [--snip--]
- Walter Bright (5/5) Apr 02 2022 Another advantage to core.int128 is any soft implementation of a 128 bit...
- Iain Buclaw (2/9) Apr 02 2022 It's only bsr, the compiler inlines that into one instruction. ;-)
- Walter Bright (3/14) Apr 02 2022 I know. I was dreading doing the work you did for divide, glad you picke...
- Iain Buclaw (4/10) Apr 02 2022 Thanks, I took a page from hacker's delight when re-implementing
- Walter Bright (3/5) Apr 09 2022 Well, I tried.
I have been waiting for years now, can't you guys just add these 2 types to the language?
Mar 25 2022
What would you do with it? There's a number of alternatives available today depending what you need.
Mar 25 2022
On Friday, 25 March 2022 at 23:50:39 UTC, Adam Ruppe wrote:What would you do with it? There's a number of alternatives available today depending what you need.I would perform calculation with astronomical numbers and atomic precision.
Mar 25 2022
On Saturday, 26 March 2022 at 04:02:18 UTC, Murilo wrote:I would perform calculation with astronomical numbers and atomic precision.If you aren't sure what size of numbers you need, BigInt/BigNum would be better. If you need fractions, might be more interested in using GMP, as it will give you floating precision you want. https://gmplib.org/ float/double/real (32/64/80) allow a very large range of rough values within ranges and are built in with the FPU. If you want a fixed int-type, then int/long/cent or others would be practical. So question, what doesn't BigInt do that you need cent/ucent for?
Mar 25 2022
On Saturday, 26 March 2022 at 06:53:32 UTC, Era Scarecrow wrote:On Saturday, 26 March 2022 at 04:02:18 UTC, Murilo wrote:I figured BitInt would be slower because it works with strings, working with pure binary would be faster, if there was a cent and ucent type I would be able to do the math faster.I would perform calculation with astronomical numbers and atomic precision.So question, what doesn't BigInt do that you need cent/ucent for?
Mar 26 2022
On Sat, Mar 26, 2022 at 06:03:57PM +0000, Murilo via Digitalmars-d wrote: [...]I figured BitInt would be slower because it works with strings, working with pure binary would be faster, if there was a cent and ucent type I would be able to do the math faster.That is false. BigInt works with arrays of ulongs, which is as binary as you're gonna get. T -- Mediocrity has been pushed to extremes.
Mar 26 2022
On Saturday, 26 March 2022 at 18:12:08 UTC, H. S. Teoh wrote:On Sat, Mar 26, 2022 at 06:03:57PM +0000, Murilo wrote: [...]It's been a while since we have been doing BCD (*Binary Coded decimals*) which are base-10, which 8bit computers and calculators use to put 2 digits in 1 byte. No, it's far faster to use the built-in larger binary types, rather than lowering to 1 number at a time. My library was on par with BigInt in speed, unless you utilized all instruction sets during compiling; Then BigInt is actually a bit faster making use of a few extra feature sets i haven't coded to take advantage of yet. Trying to compile the data to test and write is annoying. Doing math purely based on string/text certainly can be done and may be easy to do, but will be slow and best for examples of infinite precision and not used for real-time applications.I figured BitInt would be slower because it works with strings, working with pure binary would be faster, if there was a cent and ucent type I would be able to do the math faster.That is false. BigInt works with arrays of ulongs, which is as binary as you're gonna get.
Mar 26 2022
On Saturday, 26 March 2022 at 18:12:08 UTC, H. S. Teoh wrote:On Sat, Mar 26, 2022 at 06:03:57PM +0000, Murilo via Digitalmars-d wrote: [...]Thanks for clearing that up, I guess I'll just stick to BigInt then. I've used it to make a calculator that turns numbers into strings and does the math just like we do it with pen and paper, that way I can calculate decimals with perfect precision. It is able to do around 30k adds/subtracts per seconds, around 25k multiplys per second and around 5.5k divides per second with perfect precision of 20 decimal places.I figured BitInt would be slower because it works with strings, working with pure binary would be faster, if there was a cent and ucent type I would be able to do the math faster.That is false. BigInt works with arrays of ulongs, which is as binary as you're gonna get. T
Mar 27 2022
On Sunday, 27 March 2022 at 19:05:09 UTC, Murilo wrote:Thanks for clearing that up, I guess I'll just stick to BigInt then. I've used it to make a calculator that turns numbers into strings and does the math just like we do it with pen and paper, that way I can calculate decimals with perfect precision. It is able to do around 30k adds/subtracts per seconds, around 25k multiplys per second and around 5.5k divides per second with perfect precision of 20 decimal places.There is no D implementation, but there is a good C library for POSIT Some info could be found here: https://posithub.org/ Maybe will be useful for precise calculation
Mar 27 2022
On Friday, 25 March 2022 at 23:50:39 UTC, Adam Ruppe wrote:What would you do with it? There's a number of alternatives available today depending what you need.
Mar 26 2022
On Friday, 25 March 2022 at 23:50:39 UTC, Adam Ruppe wrote:What would you do with it? There's a number of alternatives available today depending what you need.There is literally no way to implement a big number lib that'll optimize properly without and integer that is 2x what the machine supports. That means 128 bits on 64 bits machines. This is important for cryptography for instance.
Mar 28 2022
On Monday, 28 March 2022 at 18:40:34 UTC, deadalnix wrote:On Friday, 25 March 2022 at 23:50:39 UTC, Adam Ruppe wrote:Murilo might not need a big number lib at all. For astronomy, there's a good chance floating point will do the job.What would you do with it? There's a number of alternatives available today depending what you need.There is literally no way to implement a big number lib
Mar 29 2022
On Tuesday, 29 March 2022 at 12:13:31 UTC, Adam D Ruppe wrote:On Monday, 28 March 2022 at 18:40:34 UTC, deadalnix wrote:That not going to work if you are comparing things that are extremely big with something that is extremely small here. - AlexOn Friday, 25 March 2022 at 23:50:39 UTC, Adam Ruppe wrote:Murilo might not need a big number lib at all. For astronomy, there's a good chance floating point will do the job.What would you do with it? There's a number of alternatives available today depending what you need.There is literally no way to implement a big number lib
Mar 29 2022
On Tue, Mar 29, 2022 at 01:58:46PM +0000, 12345swordy via Digitalmars-d wrote:On Tuesday, 29 March 2022 at 12:13:31 UTC, Adam D Ruppe wrote:[...][...] I think you got that wrong, floating is precisely designed for such comparisons. You can easily compare 1e+1000 with 1e-1000 without running into problems. Where you might run into problems is if you *add* (or subtract) extremely small numbers from extremely big numbers. Or if you divide by extremely small numbers. Or in general perform operations that mix numbers of greatly unlike magnitudes. T -- Error: Keyboard not attached. Press F1 to continue. -- Yoon Ha Lee, CONLANGMurilo might not need a big number lib at all. For astronomy, there's a good chance floating point will do the job.That not going to work if you are comparing things that are extremely big with something that is extremely small here.
Mar 29 2022
On Tuesday, 29 March 2022 at 15:23:45 UTC, H. S. Teoh wrote:On Tue, Mar 29, 2022 at 01:58:46PM +0000, 12345swordy via Digitalmars-d wrote:Yes, and Adam did take out a double indemnity with "might not" and "good chance". The long dormant physicist in me is curious to see an example calculation/formula from Murilo, and his hoped-for precision at the end.On Tuesday, 29 March 2022 at 12:13:31 UTC, Adam D Ruppe wrote:[...][...] I think you got that wrong, floating is precisely designed for such comparisons. You can easily compare 1e+1000 with 1e-1000 without running into problems. Where you might run into problems is if you *add* (or subtract) extremely small numbers from extremely big numbers. Or if you divide by extremely small numbers. Or in general perform operations that mix numbers of greatly unlike magnitudes. TMurilo might not need a big number lib at all. For astronomy, there's a good chance floating point will do the job.That not going to work if you are comparing things that are extremely big with something that is extremely small here.
Mar 29 2022
On Tuesday, 29 March 2022 at 15:23:45 UTC, H. S. Teoh wrote:On Tue, Mar 29, 2022 at 01:58:46PM +0000, 12345swordy via Digitalmars-d wrote:Where did you get the 1e+1000 number from? That is way bigger then the official max size of double. https://docs.microsoft.com/en-us/dotnet/api/system.double.maxvalue?view=net-6.0 -AlexOn Tuesday, 29 March 2022 at 12:13:31 UTC, Adam D Ruppe wrote:[...][...] I think you got that wrong, floating is precisely designed for such comparisons. You can easily compare 1e+1000 with 1e-1000 without running into problems. Where you might run into problems is if you *add* (or subtract) extremely small numbers from extremely big numbers. Or if you divide by extremely small numbers. Or in general perform operations that mix numbers of greatly unlike magnitudes. TMurilo might not need a big number lib at all. For astronomy, there's a good chance floating point will do the job.That not going to work if you are comparing things that are extremely big with something that is extremely small here.
Mar 29 2022
On Tue, Mar 29, 2022 at 05:25:39PM +0000, 12345swordy via Digitalmars-d wrote:On Tuesday, 29 March 2022 at 15:23:45 UTC, H. S. Teoh wrote:[...][...]I think you got that wrong, floating is precisely designed for such comparisons. You can easily compare 1e+1000 with 1e-1000 without running into problems.Where did you get the 1e+1000 number from? That is way bigger then the official max size of double.[...] Oops, meant to write 300, not 1000. :-O The 1000 is for the binary representation, not for decimal. T -- There are three kinds of people in the world: those who can count, and those who can't.
Mar 29 2022
On Friday, 25 March 2022 at 23:33:45 UTC, Murilo wrote:I have been waiting for years now, can't you guys just add these 2 types to the language?Walter has plans to deprecate cent/ucent in favor of a library implementation. See the “128 bit integers” section in the summary of our last meeting here: https://forum.dlang.org/post/qrtjqubrbuqeiffunili forum.dlang.org
Mar 25 2022
On Friday, 25 March 2022 at 23:33:45 UTC, Murilo wrote:I have been waiting for years now, can't you guys just add these 2 types to the language?I have a library i wrote a few years ago you can use. Compiled it recently and had no issues. It may need more testing. Should handle any multiple of 64bits, even odd ones. though doing 128/256 and others should be just fine. https://github.com/rtcvb32/Side-Projects/tree/master/arbitraryint used as **import std.experimental/arbitraryint;** Though i'm not sure if i need to update it for licenses, it has been a while afterall... For now avoid using it in commercial products.
Mar 25 2022
On Friday, 25 March 2022 at 23:33:45 UTC, Murilo wrote:I have been waiting for years now, can't you guys just add these 2 types to the language?The code is a bit old, but it works flawlessly and has useful aliases: https://github.com/d-gamedev-team/gfm/blob/master/integers/gfm/integers/wideint.d
Mar 26 2022
On Saturday, 26 March 2022 at 11:37:28 UTC, Salih Dincer wrote:On Friday, 25 March 2022 at 23:33:45 UTC, Murilo wrote:I think it just need to be in a dub package one can find.I have been waiting for years now, can't you guys just add these 2 types to the language?The code is a bit old, but it works flawlessly and has useful aliases: https://github.com/d-gamedev-team/gfm/blob/master/integers/gfm/integers/wideint.d
Mar 26 2022
On Saturday, 26 March 2022 at 11:37:28 UTC, Salih Dincer wrote:The code is a bit old, but it works flawlessly and has useful aliases: https://github.com/d-gamedev-team/gfm/blob/master/integers/gfm/integers/wideint.dFlawless maybe, but definitely slow when you get to division. It can only double the size of integers. If memory serves me right, it uses shift and subtraction for division, but it also uses 2 lower types so if you do say a 256bit type, it creates and uses 2 128 bit types, which uses 2 64 bit types to do the job.
Mar 26 2022
On 3/25/2022 4:33 PM, Murilo wrote:I have been waiting for years now, can't you guys just add these 2 types to the language?I did some work implementing it as a native type. But after a while I realized that it was not appropriate to implement it that way, it should be a library type like `complex` is. The library type hasn't been implemented (anyone is free to do this!), but the math part has been: https://dlang.org/phobos/core_int128.html
Mar 26 2022
On Saturday, 26 March 2022 at 19:30:13 UTC, Walter Bright wrote:On 3/25/2022 4:33 PM, Murilo wrote:Multiplication and division are the only parts needing any real work, most of it is very simple. As mentioned i have my library written, though i suppose i'd have to fight a bit with github that i never quite got working before when doing bitmanip bitfields. Though, if int128 just forwards calls to my library that would be far easier to implement while keeping the assembly code... I'll see about tinkering with this.I have been waiting for years now, can't you guys just add these 2 types to the language?I did some work implementing it as a native type. But after a while I realized that it was not appropriate to implement it that way, it should be a library type like `complex` is. The library type hasn't been implemented (anyone is free to do this!), but the math part has been: https://dlang.org/phobos/core_int128.html
Mar 26 2022
On Sunday, 27 March 2022 at 03:10:41 UTC, Era Scarecrow wrote:[...] i'd have to fight a bit with github that i never quite got working before when doing bitmanip bitfields. Though, if int128 just forwards calls to my library that would be far easier to implement while keeping the assembly code... I'll see about tinkering with this.I hope you will be successful because we need to use it without writing import. Really, is it that hard? By simply implementing, the codes that we write can run slow! It can be accelerated by 2030. Even if the background BigInt library can work collaboratively. In summary let's use that cent and ucent henceforth, please without import lines! SDB 79
Mar 27 2022
On Sunday, 27 March 2022 at 07:23:59 UTC, Salih Dincer wrote:I hope you will be successful because we need to use it without writing import. Really, is it that hard? By simply implementing, the codes that we write can run slow! It can be accelerated by 2030. Even if the background BigInt library can work collaboratively.One could just use BigInt under the hood and then have it do checks at certain points and modify it to fit in the appropriate 128bit limits. Though i don't see that being useful, plus you would want to run it without any allocation for embedded and low memory devices.In summary let's use that cent and ucent henceforth, please without import lines!Not needing an import would be nice, but it is more syntactical sugar, much like how you don't need to import the basic Object type, just being done under the hood doesn't mean that much. Somewhere it would just be that cent outside of the core would be ```alias cent=Cent;``` otherwise cent/ucent would be reserved words. Though as long as you're at it, if you want to specify 256/512/1024 types now would be the time to decide the names and put them in all at once. I glanced at the work Walter did. Looks like a simple version of wideint. I thought it would just be the function prototypes. Instead it looks like he minimally implemented it, but it is basically just in the wrong spot, or not set to being called at all (*not too familiar with the internals i'm not sure*). If these are ready to be used, I'd just swap out the division/multiplication work for faster variants and call it good. Though there's a number of features there that i hadn't implemented, primarily the bit rotation types that aren't represented in C/D, and thus didn't see the need to at the time.
Mar 27 2022
On Sunday, 27 March 2022 at 16:41:33 UTC, Era Scarecrow wrote:I glanced at the work Walter did. Looks like a simple version of wideint. I thought it would just be the function prototypes. Instead it looks like he minimally implemented it, but it is basically just in the wrong spot, or not set to being called at all (*not too familiar with the internals i'm not sure*).To be called, the remaining work is that a library type must be implemented with operator overloads. Those operators overloads will call the core int128 module routines. Also operators overloads being templates, we can expect to have a size-efficient cg ("pay as you go"). druntime is the right place. For example LDC can patch the default implementation and use the LLVM-specific i128 instructions. The library type will end up using the right thing. At this point it looks like it still *would* be possible to hook cent/ucent operations to the int128 core module even if it's not the way that's been chosen as cent/ucent are now deprecated.
Mar 27 2022
On Saturday, 26 March 2022 at 19:30:13 UTC, Walter Bright wrote:On 3/25/2022 4:33 PM, Murilo wrote:I guess I must have missed this "complexity" detail, as I didn't contribute to development of D. I think it should stay at the library level. Obviously, the library is sufficient for Murilo... SDB 79I have been waiting for years now, can't you guys just add these 2 types to the language?I did some work implementing it as a native type. But after a while I realized that it was not appropriate to implement it that way, it should be a library type like `complex` is.
Mar 27 2022
On Saturday, 26 March 2022 at 19:30:13 UTC, Walter Bright wrote:https://dlang.org/phobos/core_int128.htmlI tried to find faults in its divide and modulo so that I could rant about wideint.d being rewritten, but actually core.int128 seems to be better and correct (possibly more correct with negative modulo even). :) So now it's all about adding the operator overloads, and done with that particular complaint!
Mar 28 2022
On Monday, 28 March 2022 at 18:37:27 UTC, Guillaume Piolat wrote:On Saturday, 26 March 2022 at 19:30:13 UTC, Walter Bright wrote:With LDC 1.27.1 : ```d Cent foobar(Cent a, Cent b) { return mul(a, b); } ``` Codegen: ```asm nothrow nogc safe example.Cent example.foobar(example.Cent, example.Cent): push r15 push r14 push rbx mov r9d, edi mov r8, rdi shr r8, 32 mov r11d, esi mov r10, rsi shr r10, 32 mov ebx, edx mov rax, rbx imul r11, rbx imul rbx, r9 imul rax, r8 mov r14d, ebx shr rbx, 32 add rbx, rax mov eax, ebx shr rbx, 32 add rbx, r11 imul r10d, edx shr rdx, 32 mov r11, rdx imul r11, r9 add rax, r11 mov r11, rdx imul r11, r8 mov r15d, ebx add r15, r11 mov r11, rax shr r11, 32 add r11, r15 imul edx, esi add edx, r10d mov r10d, ecx imul r10, r9 mov esi, r11d add rsi, r10 imul r8d, ecx add r8d, edx shr rcx, 32 imul ecx, edi add ecx, r8d shl rax, 32 or rax, r14 shl rcx, 32 add rcx, rbx movabs rdx, -4294967296 and rcx, rdx add rcx, r11 and rcx, rdx add rsi, rcx mov rdx, rsi pop rbx pop r14 pop r15 ret ``` Now let's see what we can get with clang and __int128_t, same backend so the comparison is fair: ```cpp __uint128_t foobar(__uint128_t a, __uint128_t b) { return a * b; } ``` codegen: ```asm foobar(unsigned __int128, unsigned __int128): mov r8, rdx mov rax, rdx mul rdi imul rsi, r8 add rdx, rsi imul rcx, rdi add rdx, rcx ret ``` Why do I even have to argue that case?https://dlang.org/phobos/core_int128.htmlI tried to find faults in its divide and modulo so that I could rant about wideint.d being rewritten, but actually core.int128 seems to be better and correct (possibly more correct with negative modulo even). :) So now it's all about adding the operator overloads, and done with that particular complaint!
Mar 28 2022
On Monday, 28 March 2022 at 19:35:10 UTC, deadalnix wrote:Why do I even have to argue that case?Because different architectures and compilers do different things. And some people value correctness over speed, especially if later we do get 128bit registers we want it to work exactly as expected when it gets recompiled. Though i'm sure you know this and are just doing raw comparison of size. Writing these functions using purely C you can manage to get the job done but it's a lot more work and takes a lot more steps. I ended up writing some of my hardware specific functions 3 times, 32bit, 64bit and generic. 32/64bit worked quite well with asm to speed things up for any size you'd want. Generic however didn't like it as much and actually is **SLOWER** than 32bit, but should work on anything and even works in CTFE (*to make it as close to a native type as i could*) What i wrote should be close to the level of the cpp example, just won't be inlined; Though i suppose i could write an inline one **just** for 128bit which would be a lot easier to inline for one level up...
Mar 28 2022
On Tuesday, 29 March 2022 at 06:28:17 UTC, Era Scarecrow wrote:On Monday, 28 March 2022 at 19:35:10 UTC, deadalnix wrote:No, I picked the exact same toolchain on purpose so that the approach themselves can be compared. There is no correctness vs speed here, both code are correct. One is going to be significantly faster, but, in addition, one is going to optimize better with it surroundings, so what you'll see in practice is an even wider gap that what is presented above. This approach will not work. I know because I specifically worked on making LLVM optimize this type of code and know how much harder it is to get good code in the presence of 128 bits integers vs in their absence. The CPU has a lot of instructions to help handle large integers. When you let the backend do its magic, it can leverage them. When you instead give it good old small integers code and it has to infer the meaning from it and reconstruct the large integers ops you meant to be doing and optmize that, you introduce so many failure point that it's practically impossible to get a competitive result. Once again, both of the exemple above you *THE EXACT SAME* toolchain, the only different is the approach to 128 bits integers in the frontend.Why do I even have to argue that case?Because different architectures and compilers do different things. And some people value correctness over speed, especially if later we do get 128bit registers we want it to work exactly as expected when it gets recompiled.
Mar 29 2022
On Tuesday, 29 March 2022 at 12:06:54 UTC, deadalnix wrote:On Tuesday, 29 March 2022 at 06:28:17 UTC, Era Scarecrow wrote:I agree. Having dmd as a fast backend is OK but if something as basically trivial as this cannot be implemented the we are in trouble. That being said it may be possible to lower the cent type to the druntime type as a hack, then LDC and GDC can do what they need to do.[...]No, I picked the exact same toolchain on purpose so that the approach themselves can be compared. There is no correctness vs speed here, both code are correct. One is going to be significantly faster, but, in addition, one is going to optimize better with it surroundings, so what you'll see in practice is an even wider gap that what is presented above. This approach will not work. I know because I specifically worked on making LLVM optimize this type of code and know how much harder it is to get good code in the presence of 128 bits integers vs in their absence. The CPU has a lot of instructions to help handle large integers. When you let the backend do its magic, it can leverage them. When you instead give it good old small integers code and it has to infer the meaning from it and reconstruct the large integers ops you meant to be doing and optmize that, you introduce so many failure point that it's practically impossible to get a competitive result. Once again, both of the exemple above you *THE EXACT SAME* toolchain, the only different is the approach to 128 bits integers in the frontend.
Mar 29 2022
On Tuesday, 29 March 2022 at 12:20:21 UTC, max haughton wrote:That being said it may be possible to lower the cent type to the druntime type as a hack, then LDC and GDC can do what they need to do.In intel-intrinsics, unsupported vector types are emulated: - all vectors in DMD 32-bit - all vectors in DMD 64-bit with an option that disable D_SIMD - AVX vectors in GDC without AVX so it's just a matter of adding a version there and some work, to have backend support AND work everywhere.
Mar 29 2022
On Tuesday, 29 March 2022 at 12:06:54 UTC, deadalnix wrote:No, I picked the exact same toolchain on purpose so that the approach themselves can be compared. both of the example above you *THE EXACT SAME* toolchain, the only different is the approach to 128 bits integers in the frontend.To me it looked like you did a C++ vs D somewhere in the way. But instead you're just doing the backend calls. Also speaks of a bunch of my own inexperience in the deeper matters, and why i usually abstain from a number of these conversations I'm not well versed in.The CPU has a lot of instructions to help handle large integers. When you let the backend do its magic, it can leverage them. When you instead give it good old small integers code and it has to infer the meaning from it and reconstruct the large integers ops you meant to be doing and optimize that, you introduce so many failure point that it's practically impossible to get a competitive result.Reminded of reading of specific ways you had to write bswap in C/C++ for GCC to recognize it and reduce it to a single instruction without getting into ASM, while still working with architectures that didn't have that specific instruction.There is no correctness vs speed here, both code are correct. One is going to be significantly faster, but, in addition, one is going to optimize better with it surroundings, so what you'll see in practice is an even wider gap that what is presented above.Still that example does suggest I'd get a bit of a boost by manually writing the 128bit multiply manually which would cut out overhead and a loop that's unneeded. Probably get similar results with a divide (*with long or smaller divisor*). Course those are rather case specific. I wouldn't look forward to re-writing the same code for all the different compilers back ends though.
Mar 29 2022
On 3/29/2022 9:36 AM, Era Scarecrow wrote:I wouldn't look forward to re-writing the same code for all the different compilers back ends though.That's the attractiveness of a builtin function. It'll at least work for other systems.
Mar 30 2022
On Thursday, 31 March 2022 at 06:33:26 UTC, Walter Bright wrote:On 3/29/2022 9:36 AM, Era Scarecrow wrote:At some point, it’s going to be easier to make those types `__traits(signed, 128)`, `__traits(unsigned, 256)`, `__traits(signed, 512)` and so on, plus some `alias ducent = __traits(signed, 256)` in object.d instead of arguing where the right limit is. I’m not entirely sure if I’m being serious here, but on the other hand, I know of no other language that reserved a type keyword and doesn’t use it although it easily could.I wouldn't look forward to re-writing the same code for all the different compilers back ends though.That's the attractiveness of a builtin function. It'll at least work for other systems.
Mar 31 2022
On 01/04/2022 9:18 AM, Quirin Schroll wrote:At some point, it’s going to be easier to make those types `__traits(signed, 128)`, `__traits(unsigned, 256)`, `__traits(signed, 512)` and so on, plus some `alias ducent = __traits(signed, 256)` in object.d instead of arguing where the right limit is.This is something I have long since considered. While dmd may not have been designed for this, it is my belief that this is the only way forward for built in types. As hardware changes over the next hundred years, this will be a major win for whoever does it this way.
Mar 31 2022
On Friday, 1 April 2022 at 03:37:48 UTC, rikki cattermole wrote:On 01/04/2022 9:18 AM, Quirin Schroll wrote:So will this look something like ```d alias i128 = __traits(signed, 128); alias u512 = __traits(unsigned, 512); ``` And so on?At some point, it’s going to be easier to make those types `__traits(signed, 128)`, `__traits(unsigned, 256)`, `__traits(signed, 512)` and so on, plus some `alias ducent = __traits(signed, 256)` in object.d instead of arguing where the right limit is.This is something I have long since considered. While dmd may not have been designed for this, it is my belief that this is the only way forward for built in types. As hardware changes over the next hundred years, this will be a major win for whoever does it this way.
Mar 31 2022
On Friday, 1 April 2022 at 04:48:02 UTC, Tejas wrote:On Friday, 1 April 2022 at 03:37:48 UTC, rikki cattermole wrote:Maybe. Some use int32 as the identifier rather than int. Though my library i specify the bit size and it uses N number of longs to fulfill that so it could fit any type until there's hardware support and you just replace the alias. I don't know. As long as various sizes are supported easily i don't object to whatever people decide on.This is something I have long since considered. While dmd may not have been designed for this, it is my belief that this is the only way forward for built in types. As hardware changes over the next hundred years, this will be a major win for whoever does it this way.So will this look something like ```d alias i128 = __traits(signed, 128); alias u512 = __traits(unsigned, 512); ``` And so on?
Mar 31 2022
On 01/04/2022 5:48 PM, Tejas wrote:So will this look something like ```d alias i128 = __traits(signed, 128); alias u512 = __traits(unsigned, 512); ``` And so on?The name could be whatever you want, but yeah.
Mar 31 2022
On 4/1/22 1:47 AM, rikki cattermole wrote:On 01/04/2022 5:48 PM, Tejas wrote:As long as the compiler errors display the alias and not the traits. -SteveSo will this look something like ```d alias i128 = __traits(signed, 128); alias u512 = __traits(unsigned, 512); ``` And so on?The name could be whatever you want, but yeah.
Apr 01 2022
Indeed, this is one time when typedef's would be better suited to the task.
Apr 01 2022
On 3/28/2022 12:35 PM, deadalnix wrote:Now let's see what we can get with clang and __int128_t, same backend so the comparison is fair: ```cpp __uint128_t foobar(__uint128_t a, __uint128_t b) { return a * b; } ``` codegen: ```asm __int128, unsigned __int128) mov r8, rdx mov rax, rdx mul rdi imul rsi, r8 add rdx, rsi imul rcx, rdi add rdx, rcx ret ``` Why do I even have to argue that case?You see a similar thing when 32 bit compilation does 64 bit arithmetic: ulong foobar(ulong x, ulong y) { return x * y; } dmd -c test.d -vasm -m32 -O _D4test6foobarFmmZm: 0000: 53 push EBX 0001: 8B 54 24 14 mov EDX,014h[ESP] 0005: 8B 44 24 10 mov EAX,010h[ESP] 0009: 8B 4C 24 0C mov ECX,0Ch[ESP] 000d: 8B 5C 24 08 mov EBX,8[ESP] 0011: 0F AF C8 imul ECX,EAX 0014: 0F AF D3 imul EDX,EBX 0017: 03 CA add ECX,EDX 0019: F7 E3 mul EBX 001b: 03 D1 add EDX,ECX 001d: 5B pop EBX 001e: C2 10 00 ret 010h So, yeah, supporting 128 bit arithmetic in the codegen has significant advantages. 3 multiplies and 2 adds. Having the compiler recognize the `mul` function as a builtin would enable this code gen for 128 bits.
Mar 30 2022
On Thursday, 31 March 2022 at 06:31:32 UTC, Walter Bright wrote:You see a similar thing when 32 bit compilation does 64 bit arithmetic: [...] So, yeah, supporting 128 bit arithmetic in the codegen has significant advantages. 3 multiplies and 2 adds. Having the compiler recognize the `mul` function as a builtin would enable this code gen for 128 bits.So now that you just killed the library solution by having the compiler specially recognize it, can we have cent/ucent? Honestly, I don't care if DMD forward the operation to something in druntime, that would at least allow me to have good codegen on LDC/GDC.
Mar 31 2022
On Thursday, 31 March 2022 at 18:40:52 UTC, deadalnix wrote:Honestly, I don't care if DMD forward the operation to something in druntime, that would at least allow me to have good codegen on LDC/GDC.With LDC's support for inline LLVM IR (https://wiki.dlang.org/LDC_inline_IR), I think we can quite easily have a much better `core.int128` solution for LDC at least. Coupled with LLVM's compiler-rt builtins library, which should provide performant library fallbacks for targets with limited hardware support. So that a druntime `Cent` solution should be on-par with clang's `__int128`. The existing generic software implementation is still useful for CTFE.
Mar 31 2022
On Thursday, 31 March 2022 at 22:30:48 UTC, kinke wrote:On Thursday, 31 March 2022 at 18:40:52 UTC, deadalnix wrote:It's still quite ugly compared to just implementing cent properly e.g. lack of VRP and implicit conversions make the library approach a bit meh.Honestly, I don't care if DMD forward the operation to something in druntime, that would at least allow me to have good codegen on LDC/GDC.With LDC's support for inline LLVM IR (https://wiki.dlang.org/LDC_inline_IR), I think we can quite easily have a much better `core.int128` solution for LDC at least. Coupled with LLVM's compiler-rt builtins library, which should provide performant library fallbacks for targets with limited hardware support. So that a druntime `Cent` solution should be on-par with clang's `__int128`. The existing generic software implementation is still useful for CTFE.
Mar 31 2022
On Thursday, 31 March 2022 at 22:35:46 UTC, max haughton wrote:It's still quite ugly compared to just implementing cent properly e.g. lack of VRP and implicit conversions make the library approach a bit meh.There's another advantage (besides the main one - not having to touch the frontend at all) - it's not restricted to 128 bits and *could* thus be a template for integers with N bits. I doubt VRP and implicit conversions are of high priority for the presumably few specialized usages of huge integers.
Mar 31 2022
On Thursday, 31 March 2022 at 22:43:27 UTC, kinke wrote:On Thursday, 31 March 2022 at 22:35:46 UTC, max haughton wrote:The few times I have needed wide arithmetic in D, it not being available has been irritating, having it be available but as a weird library feature is just goading. e.g. Being able to call 128bit functions with narrower types without having to inject Cent(xyz) everywhere is not a small thing.It's still quite ugly compared to just implementing cent properly e.g. lack of VRP and implicit conversions make the library approach a bit meh.There's another advantage (besides the main one - not having to touch the frontend at all) - it's not restricted to 128 bits and *could* thus be a template for integers with N bits. I doubt VRP and implicit conversions are of high priority for the presumably few specialized usages of huge integers.
Mar 31 2022
On 3/31/2022 3:35 PM, max haughton wrote:It's still quite ugly compared to just implementing cent properly e.g. lack of VRP and implicit conversions make the library approach a bit meh.There are very few uses for a 128 bit type, so all the conveniences are not particularly necessary.
Mar 31 2022
On Friday, 1 April 2022 at 02:41:58 UTC, Walter Bright wrote:On 3/31/2022 3:35 PM, max haughton wrote:That is a non sequitur statement Walter.It's still quite ugly compared to just implementing cent properly e.g. lack of VRP and implicit conversions make the library approach a bit meh.There are very few uses for a 128 bit type, so all the conveniences are not particularly necessary.
Mar 31 2022
On Friday, 1 April 2022 at 02:41:58 UTC, Walter Bright wrote:On 3/31/2022 3:35 PM, max haughton wrote:For the past 2.5 years, I've worked on applications that use 256-bit integers for most of the computation (because the inputs are 256-bit numbers typically used to represent fixed point decimals with 18 digits) for computation and it would have been nice to to have uint256/int256 built-in types, instead of having to use a library BigInt type.It's still quite ugly compared to just implementing cent properly e.g. lack of VRP and implicit conversions make the library approach a bit meh.There are very few uses for a 128 bit type, so all the conveniences are not particularly necessary.
Mar 31 2022
On 3/31/2022 10:33 PM, Petar Kirov [ZombineDev] wrote:For the past 2.5 years, I've worked on applications that use 256-bit integers for most of the computation (because the inputs are 256-bit numbers typically used to represent fixed point decimals with 18 digits) for computation and it would have been nice to to have uint256/int256 built-in types, instead of having to use a library BigInt type.A library 128 bit type would be pretty easy to do, now that the computation functions are worked out. 256 bits could leverage that. But frankly, with all the jawboning around it could have already been implemented. Just take: https://github.com/dlang/phobos/blob/master/std/complex.d and de-template it, and delete most of it, and you've got struct Int128 and struct Uint128. The hard part: https://github.com/dlang/druntime/blob/master/src/core/int128.d is already done. Whoever does it first gets the glory :-)
Apr 01 2022
On Friday, 1 April 2022 at 07:22:21 UTC, Walter Bright wrote:On 3/31/2022 10:33 PM, Petar Kirov [ZombineDev] wrote:I'd do it for money lol[...]A library 128 bit type would be pretty easy to do, now that the computation functions are worked out. 256 bits could leverage that. But frankly, with all the jawboning around it could have already been implemented. Just take: https://github.com/dlang/phobos/blob/master/std/complex.d and de-template it, and delete most of it, and you've got struct Int128 and struct Uint128. The hard part: https://github.com/dlang/druntime/blob/master/src/core/int128.d is already done. Whoever does it first gets the glory :-)
Apr 01 2022
On 4/1/2022 7:23 AM, mee6 wrote:What the hell, I'm tired of the jawboning and did it for the greater glory: https://github.com/dlang/phobos/pull/8426Whoever does it first gets the glory :-)I'd do it for money lol
Apr 02 2022
On Saturday, 2 April 2022 at 22:41:52 UTC, Walter Bright wrote:On 4/1/2022 7:23 AM, mee6 wrote:Thank you on behalf of myself. I wish I could a little support but I haven't gotten very far in D Language yet. SDB 79What the hell, I'm tired of the jawboning and did it for the greater glory: https://github.com/dlang/phobos/pull/8426Whoever does it first gets the glory :-)I'd do it for money lol
Apr 02 2022
On Saturday, 2 April 2022 at 23:12:27 UTC, Salih Dincer wrote:I wish I could a little support but I haven't gotten very far in D Language yet.I don't know how to add it to Github. A small contribution, they work: **Lines,70-77** ```d // ++Int128 Int128 opUnary(string op)() const if (op == "++") { return Int128(inc(this.data)); } // --Int128 Int128 opUnary(string op)() const if (op == "--") { return Int128(dec(this.data)); } //... unittest { Int128 idTest; idTest += ulong.max;// hi = 1, lo = 0-> assert(++idTest == Int128(1, 0)); idTest = ++idTest;// hi = 0, lo = ulong.max-> assert(--idTest == Int128(0, -1)); } ``` SDB 79
Apr 02 2022
On Saturday, 2 April 2022 at 22:41:52 UTC, Walter Bright wrote:On 4/1/2022 7:23 AM, mee6 wrote:Thank you for your work, I'm very happy and thankful. I will try to add it to my decimal calculator module now.What the hell, I'm tired of the jawboning and did it for the greater glory: https://github.com/dlang/phobos/pull/8426Whoever does it first gets the glory :-)I'd do it for money lol
Feb 21 2023
On Friday, 1 April 2022 at 05:33:06 UTC, Petar Kirov [ZombineDev] wrote:On Friday, 1 April 2022 at 02:41:58 UTC, Walter Bright wrote:I have done that. While it is not possible to get good codegen with the current provided types, it is possible with a 128bit type. You can then do your operation using a 128 bits accumulator and compiler are smart enough to figure out what to do most of the time. This is why a 128 bit type is absolutely key, it unlocks the ability to write larger integer types in a way that will allow the compiler to generate good code for it.On 3/31/2022 3:35 PM, max haughton wrote:For the past 2.5 years, I've worked on applications that use 256-bit integers for most of the computation (because the inputs are 256-bit numbers typically used to represent fixed point decimals with 18 digits) for computation and it would have been nice to to have uint256/int256 built-in types, instead of having to use a library BigInt type.It's still quite ugly compared to just implementing cent properly e.g. lack of VRP and implicit conversions make the library approach a bit meh.There are very few uses for a 128 bit type, so all the conveniences are not particularly necessary.
Apr 01 2022
On Friday, 1 April 2022 at 12:06:01 UTC, deadalnix wrote:This is why a 128 bit type is absolutely key, it unlocks the ability to write larger integer types in a way that will allow the compiler to generate good code for it.Does LLVM support that width good code gen? Intel/AMD have some instructions intended for higher precision math ([ADX](https://en.wikipedia.org/wiki/Intel_ADX), [MULX](https://en.wikipedia.org/wiki/X86_Bit_manipulation_ins ruction_set#BMI2)). They also have some instructions meant to be used for crypto, e.g. [CLMUL](https://en.wikipedia.org/wiki/CLMUL_instruction_set).
Apr 11 2022
On Monday, 11 April 2022 at 07:24:41 UTC, Ola Fosheim Grøstad wrote:On Friday, 1 April 2022 at 12:06:01 UTC, deadalnix wrote:LLVM 128 type (named `i128`) on x86_64 produces standard instructions, e.g more or less the D library implementation with better code gen, [example]. [example]: https://godbolt.org/z/vfYhc3bTnThis is why a 128 bit type is absolutely key, it unlocks the ability to write larger integer types in a way that will allow the compiler to generate good code for it.Does LLVM support that width good code gen? Intel/AMD have some instructions intended for higher precision math ([ADX](https://en.wikipedia.org/wiki/Intel_ADX), [MULX](https://en.wikipedia.org/wiki/X86_Bit_manipulation_ins ruction_set#BMI2)). They also have some instructions meant to be used for crypto, e.g. [CLMUL](https://en.wikipedia.org/wiki/CLMUL_instruction_set).
Apr 11 2022
On Monday, 11 April 2022 at 07:44:04 UTC, user1234 wrote:On Monday, 11 April 2022 at 07:24:41 UTC, Ola Fosheim Grøstad wrote:Thanks, it appears to use "MULX" if you specify the compiler option `-mattr=bmi2` or a `-mcpu=haswell`.Intel/AMD have some instructions intended for higher precision math ([ADX](https://en.wikipedia.org/wiki/Intel_ADX), [MULX](https://en.wikipedia.org/wiki/X86_Bit_manipulation_ins ruction_set#BMI2)). They also have some instructions meant to be used for crypto, e.g. [CLMUL](https://en.wikipedia.org/wiki/CLMUL_instruction_set).LLVM 128 type (named `i128`) on x86_64 produces standard instructions, e.g more or less the D library implementation with better code gen, [example]. [example]: https://godbolt.org/z/vfYhc3bTn
Apr 11 2022
On Monday, 11 April 2022 at 08:15:09 UTC, Ola Fosheim Grøstad wrote:On Monday, 11 April 2022 at 07:44:04 UTC, user1234 wrote:Actually, as said in the beginning of the thread I expect that eventually LDC developers will patch their fork of the D runtime, assuming `i128` has the same ABI as the structure used in D... although the D implementation must still be there in some way for CTFE.On Monday, 11 April 2022 at 07:24:41 UTC, Ola Fosheim Grøstad wrote:Thanks, it appears to use "MULX" if you specify the compiler option `-mattr=bmi2` or a `-mcpu=haswell`.Intel/AMD have some instructions intended for higher precision math ([ADX](https://en.wikipedia.org/wiki/Intel_ADX), [MULX](https://en.wikipedia.org/wiki/X86_Bit_manipulation_ins ruction_set#BMI2)). They also have some instructions meant to be used for crypto, e.g. [CLMUL](https://en.wikipedia.org/wiki/CLMUL_instruction_set).LLVM 128 type (named `i128`) on x86_64 produces standard instructions, e.g more or less the D library implementation with better code gen, [example]. [example]: https://godbolt.org/z/vfYhc3bTn
Apr 11 2022
On Thursday, 31 March 2022 at 22:30:48 UTC, kinke wrote:On Thursday, 31 March 2022 at 18:40:52 UTC, deadalnix wrote:Yep, they were all written to be CTFE-friendly.Honestly, I don't care if DMD forward the operation to something in druntime, that would at least allow me to have good codegen on LDC/GDC.The existing generic software implementation is still useful for CTFE.
Apr 02 2022
On 3/31/2022 11:40 AM, deadalnix wrote:So now that you just killed the library solution by having the compiler specially recognize it, can we have cent/ucent?No, because a great deal of the compiler internals would have to be redone for it. The compiler will also slow down as a result. (The internals all depend on integral types being able to accommodate the largest integral type.)Honestly, I don't care if DMD forward the operation to something in druntime, that would at least allow me to have good codegen on LDC/GDC.I didn't kill the library solution. 'mul' being specially recognized by the compiler does not change its utility.
Mar 31 2022
On Thursday, 31 March 2022 at 18:40:52 UTC, deadalnix wrote:On Thursday, 31 March 2022 at 06:31:32 UTC, Walter Bright wrote:We can do the same as complex numbers here. enum __c__int128 : core.int128.Cent; enum __c__uint128 : core.int128.Cent; Later, when cent/ucent have been dropped as keywords. alias cent = __c__int128; alias ucent = __c__uint128;You see a similar thing when 32 bit compilation does 64 bit arithmetic: [...] So, yeah, supporting 128 bit arithmetic in the codegen has significant advantages. 3 multiplies and 2 adds. Having the compiler recognize the `mul` function as a builtin would enable this code gen for 128 bits.So now that you just killed the library solution by having the compiler specially recognize it, can we have cent/ucent? Honestly, I don't care if DMD forward the operation to something in druntime, that would at least allow me to have good codegen on LDC/GDC.
Apr 02 2022
On Monday, 28 March 2022 at 19:35:10 UTC, deadalnix wrote:Why do I even have to argue that case?Indeed. Bump. People please re-read deadalnix messages. -Johan
Mar 31 2022
On 31.03.22 18:32, Johan wrote:On Monday, 28 March 2022 at 19:35:10 UTC, deadalnix wrote:Well, I was with deadalnix on this even before reading the messages once. Add cent/ucent as built-in integral types. I was always under the impression that that the plan was to do it eventually. I guess there are some inconvenient features to add to the frontend code, e.g. VRP, where a "library" solution would have an obvious excuse to just not support them. If adding cent/ucent to the DMD backend is not an option, it can just forward to the druntime type, but other backends should be free to leverage their existing implementation. All of this is completely independent of whether or not cent/ucent are built-ins in the frontend anyway. BTW: It's perfectly fine to just add cent/ucent built-in implementation to the vision document and maybe provide a small spec of it, then someone who needs it can implement it.Why do I even have to argue that case?Indeed. Bump. People please re-read deadalnix messages. -Johan
Mar 31 2022
On Monday, 28 March 2022 at 19:35:10 UTC, deadalnix wrote:On Monday, 28 March 2022 at 18:37:27 UTC, Guillaume Piolat wrote:[--snip--] Being free functions, LDC is free to recognize them as intrinsics and do the desirable thing here.On Saturday, 26 March 2022 at 19:30:13 UTC, Walter Bright wrote:With LDC 1.27.1 : ```d Cent foobar(Cent a, Cent b) { return mul(a, b); } ``` Codegen:https://dlang.org/phobos/core_int128.htmlI tried to find faults in its divide and modulo so that I could rant about wideint.d being rewritten, but actually core.int128 seems to be better and correct (possibly more correct with negative modulo even). :) So now it's all about adding the operator overloads, and done with that particular complaint!
Apr 02 2022
Another advantage to core.int128 is any soft implementation of a 128 bit integer does not need to concern itself with the correctness of the arithmetic - just the user side of the integer type. I also like core.int128 does not import anything else, making it a true leaf module. Edit: Oh darn, it imports core.bitop!
Apr 02 2022
On Saturday, 2 April 2022 at 19:06:01 UTC, Walter Bright wrote:Another advantage to core.int128 is any soft implementation of a 128 bit integer does not need to concern itself with the correctness of the arithmetic - just the user side of the integer type. I also like core.int128 does not import anything else, making it a true leaf module. Edit: Oh darn, it imports core.bitop!It's only bsr, the compiler inlines that into one instruction. ;-)
Apr 02 2022
On 4/2/2022 2:40 PM, Iain Buclaw wrote:On Saturday, 2 April 2022 at 19:06:01 UTC, Walter Bright wrote:I know. I was dreading doing the work you did for divide, glad you picked up the flag! I had done the equivalent for DMC's long divide long ago.Another advantage to core.int128 is any soft implementation of a 128 bit integer does not need to concern itself with the correctness of the arithmetic - just the user side of the integer type. I also like core.int128 does not import anything else, making it a true leaf module. Edit: Oh darn, it imports core.bitop!It's only bsr, the compiler inlines that into one instruction. ;-)
Apr 02 2022
On Monday, 28 March 2022 at 18:37:27 UTC, Guillaume Piolat wrote:On Saturday, 26 March 2022 at 19:30:13 UTC, Walter Bright wrote:Thanks, I took a page from hacker's delight when re-implementing the divmod() function, and did quite a bit of back and forth comparing results to wolfram. :-)https://dlang.org/phobos/core_int128.htmlI tried to find faults in its divide and modulo so that I could rant about wideint.d being rewritten, but actually core.int128 seems to be better and correct (possibly more correct with negative modulo even). :)
Apr 02 2022
On 3/25/2022 4:33 PM, Murilo wrote:I have been waiting for years now, can't you guys just add these 2 types to the language?Well, I tried. https://github.com/dlang/phobos/pull/8426
Apr 09 2022