Why does D not have generics?

Bruce Carneal bcarneal at gmail.com
Sun Jan 17 04:03:30 UTC 2021


On Saturday, 16 January 2021 at 19:43:53 UTC, Ola Fosheim Grøstad 
wrote:
> On Saturday, 16 January 2021 at 17:03:41 UTC, Bruce Carneal 
> wrote:
>> Converting over:
>> 	uint32 mask = -int32(f >> 31) | 0x80000000;
>> 	return f ^ mask;
>> and back:
>> 	uint32 mask = ((f >> 31) - 1) | 0x80000000;
>> 	return f ^ mask;
>
> Thanks, this is the same I have as option 1 above.

Almost certainly the same.  Only the most aggressively stupid 
compiler modes would forego an available/advantageous conversion 
of the subtract to a mono-operand negation.  Even then, once any 
loop got rolling throughput should be identical.  Yes.

>
>> This form is branchless and is easily (SIMD) vectorized.
>
> Yes, and perhaps also better for the CPU pipeline.
>

Unless the data you're dealing with is nearly sorted, the branch 
mispredict penalty could really hurt so, yeah, don't go there.

For the branchless variant, throughput will come down to issue 
capability.  For a dual issue SIMD CPU it looks like a naive loop 
should hit throughput of 2 SIMD vectors every three cycles (I 
don't have real numbers for the standalone case, all my 
transforms appear within larger basic blocks).  SIMT throughput 
should be memory subsystem limited.

>> split, ordering.  For my current work I prefer this to 
>> traditional float behavior and find it a useful bijection 
>> overall.  YMMV.
>
> Out of curiosity, what do you need to sort floats for?

I've been working on my current project for a few months but I'm 
still not ready to talk about it in detail.  I will say that it 
does not sort anything (doesn't have the power/compute budget for 
sorting) and that it does employ the bijection as a type 
erasure/restoration mechanism.



More information about the Digitalmars-d mailing list