www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Implementing C23 _Float16 in ImportC

reply Walter Bright <newshound2 digitalmars.com> writes:
_Float16 is new in C23 Appendix H.11-6

https://github.com/dlang/dmd/issues/20516

For the moment, I submitted a PR with a workaround:

https://github.com/dlang/dmd/pull/20699

Amazingly, some years ago I implemented 16 bit floats in D:

https://github.com/DigitalMars/sargon/blob/master/src/sargon/halffloat.d

Would anyone like to put halffloat.d into Druntime and make it our 
implementation of _Float16?
Jan 13
next sibling parent reply Sergey <kornburn yandex.ru> writes:
On Tuesday, 14 January 2025 at 06:13:04 UTC, Walter Bright wrote:
 _Float16 is new in C23 Appendix H.11-6

 https://github.com/dlang/dmd/issues/20516

 For the moment, I submitted a PR with a workaround:

 https://github.com/dlang/dmd/pull/20699

 Amazingly, some years ago I implemented 16 bit floats in D:

 https://github.com/DigitalMars/sargon/blob/master/src/sargon/halffloat.d

 Would anyone like to put halffloat.d into Druntime and make it 
 our implementation of _Float16?
Amazing. Is it extendable to Float8? Is it compatible with LLVM/GCC and other implementations?
Jan 13
next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 1/13/2025 11:43 PM, Sergey wrote:
 Amazing. Is it extendable to Float8?
The idea is sound, so probably.
 Is it compatible with LLVM/GCC and other implementations?
That I don't know. But it could be modified to be.
Jan 14
prev sibling parent Tim <tim.dlang t-online.de> writes:
On Tuesday, 14 January 2025 at 07:43:42 UTC, Sergey wrote:
 On Tuesday, 14 January 2025 at 06:13:04 UTC, Walter Bright 
 wrote:
 _Float16 is new in C23 Appendix H.11-6

 https://github.com/dlang/dmd/issues/20516

 For the moment, I submitted a PR with a workaround:

 https://github.com/dlang/dmd/pull/20699

 Amazingly, some years ago I implemented 16 bit floats in D:

 https://github.com/DigitalMars/sargon/blob/master/src/sargon/halffloat.d

 Would anyone like to put halffloat.d into Druntime and make it 
 our implementation of _Float16?
Amazing. Is it extendable to Float8?
Phobos also contains CustomFloat: https://dlang.org/library/std/numeric/custom_float.html This allows to have floats with a custom number of bits, including 8 bits.
Jan 14
prev sibling next sibling parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Tuesday, 14 January 2025 at 06:13:04 UTC, Walter Bright wrote:
 _Float16 is new in C23 Appendix H.11-6

 https://github.com/dlang/dmd/issues/20516

 For the moment, I submitted a PR with a workaround:

 https://github.com/dlang/dmd/pull/20699

 Amazingly, some years ago I implemented 16 bit floats in D:

 https://github.com/DigitalMars/sargon/blob/master/src/sargon/halffloat.d

 Would anyone like to put halffloat.d into Druntime and make it 
 our implementation of _Float16?
Why should it be a "runtime" module? Obviously you know better than most of us, but does it feel good to have to import a module for such thing, is it compelling for people looking for an alternative to C? What the young competition doing? https://ziglang.org/documentation/master/#Primitive-Types https://odin-lang.org/docs/overview/#basic-types https://c3-lang.org/language-overview/types/
Jan 14
next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 1/14/2025 12:33 AM, ryuukk_ wrote:
 Why should it be a "runtime" module?
If it is to be part of the core language, that's where it goes.
 Obviously you know better than most of us, but does it feel good to have to 
 import a module for such thing, is it compelling for people looking for an 
 alternative to C?
 
 What the young competition doing?
 
 https://ziglang.org/documentation/master/#Primitive-Types
 https://odin-lang.org/docs/overview/#basic-types
 https://c3-lang.org/language-overview/types/
The interesting thing is not the existence of the types. It's how they are implemented. The X86_64 architecture does not support a 16 bit floating point type.
Jan 14
parent reply Sergey <kornburn yandex.ru> writes:
On Tuesday, 14 January 2025 at 22:14:01 UTC, Walter Bright wrote:
 The interesting thing is not the existence of the types. It's 
 how they are implemented. The X86_64 architecture does not 
 support a 16 bit floating point type.
It had some limited support starting from 2018 had AVX512-FP16. And some newer models of x86 support both FP16 and BF16. * https://networkbuilders.intel.com/docs/networkbuilders/intel-avx-512-fp16-instruction-set-for-intel-xeon-processor-based-products-technology-guide-1651874188.pdf * https://stackoverflow.com/questions/49995594/half-precision-floating-point-arithmetic-on-intel-chips Also it is important for AI/ML models, which can run on ARM CPUs, GPUs and TPUs
Jan 14
next sibling parent Bruce Carneal <bcarneal gmail.com> writes:
On Wednesday, 15 January 2025 at 06:42:45 UTC, Sergey wrote:
 On Tuesday, 14 January 2025 at 22:14:01 UTC, Walter Bright 
 wrote:
 The interesting thing is not the existence of the types. It's 
 how they are implemented. The X86_64 architecture does not 
 support a 16 bit floating point type.
It had some limited support starting from 2018 had AVX512-FP16. And some newer models of x86 support both FP16 and BF16. * https://networkbuilders.intel.com/docs/networkbuilders/intel-avx-512-fp16-instruction-set-for-intel-xeon-processor-based-products-technology-guide-1651874188.pdf * https://stackoverflow.com/questions/49995594/half-precision-floating-point-arithmetic-on-intel-chips Also it is important for AI/ML models, which can run on ARM CPUs, GPUs and TPUs
ARM architecture is also evolving (8.2A, 9) to better support data parallelism with both FP16 and BF16 as well as SVE2 but the uptake by manufacturers is uneven. Some may be betting that CPU data parallelism is a dead end, that NEON is more than enough. In the GPU world (dcompute) mini/micro floats are very important for a variety of workloads, AI/ML chief among them.
Jan 15
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
I didn't know that. Thanks for the info.
Jan 15
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 1/14/2025 12:33 AM, ryuukk_ wrote:
 What the young competition doing?
I implemented halffloat a decade ago. It didn't go into the library then because there was zero interest in it.
Jan 14
prev sibling parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
I forgot to introduce this for a decision at the last meeting (lucky 
given how many items we had).

A new policy, that anyone could implement a C numeric type as long as it 
bound to a druntime module, and not exposed to D. D would need a DIP due 
to the identifier needing confirmation.

Note: this would also mean anyone could implement (u)cent and it would 
be pre-approved work.

Also did you see my email from the day after the meeting?
Jan 14
next sibling parent reply Bruce Carneal <bcarneal gmail.com> writes:
On Tuesday, 14 January 2025 at 14:34:13 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 ...

 A new policy, that anyone could implement a C numeric type as 
 long as it bound to a druntime module, and not exposed to D. D 
 would need a DIP due to the identifier needing confirmation.

 
Is this a good path to full integration with the back ends? I'd love to see auto vectorization and other optimizations when using the new types.
Jan 14
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 15/01/2025 4:06 AM, Bruce Carneal wrote:
 On Tuesday, 14 January 2025 at 14:34:13 UTC, Richard (Rikki) Andrew 
 Cattermole wrote:
 ...

 A new policy, that anyone could implement a C numeric type as long as 
 it bound to a druntime module, and not exposed to D. D would need a 
 DIP due to the identifier needing confirmation.
Is this a good path to full integration with the back ends?  I'd love to see auto vectorization and other optimizations when using the new types.
Yes. The functions involved can be recognized as intrinsics, and swapped out for the IR version of it.
Jan 14
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 1/14/2025 6:34 AM, Richard (Rikki) Andrew Cattermole wrote:
 Also did you see my email from the day after the meeting?
No. What was the subject title?
Jan 14
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 15/01/2025 11:16 AM, Walter Bright wrote:
 On 1/14/2025 6:34 AM, Richard (Rikki) Andrew Cattermole wrote:
 Also did you see my email from the day after the meeting?
No. What was the subject title?
"DFA - a potential strategy?" Oh and expect Bruce to want to talk about it next local meetup!
Jan 14
parent Walter Bright <newshound2 digitalmars.com> writes:
On 1/14/2025 2:19 PM, Richard (Rikki) Andrew Cattermole wrote:
 "DFA - a potential strategy?"
 
 Oh and expect Bruce to want to talk about it next local meetup!
 
Ok, I found it.
Jan 14