x86 intrinsics for sale cheap

Cecil Ward cecil at cecilward.com
Wed May 31 16:07:28 UTC 2023


On Wednesday, 31 May 2023 at 15:58:53 UTC, Cecil Ward wrote:
> On Wednesday, 31 May 2023 at 15:56:45 UTC, Cecil Ward wrote:
>> I have been working on simple wrappers around new(ish) x86 
>> instructions that are not otherwise accessible. Also with 
>> replacement functions in straight D for machines where the 
>> instruction is not available. Currently only for GDC as LDC 
>> doesn’t support some of the features of GCC inline asm that I 
>> am relying on  - named parameters in the asm with %[name] 
>> syntax. But hopefully that will get fixed by the LDC 
>> maintainers, so I will be able to work with either compiler. 
>> My routines need more testing and a vast amount of cleanup. So 
>> it’s early days.
>>
>> Is that something that you would be interested in for the D 
>> runtime library? (For GDC / LDC ?) I unfortunately haven’t 
>> attacked DMD yet because that uses a different inline asm 
>> syntax, and would mean a rewrite. But that isn’t a problem 
>> because thr DMD user gets the pure D replacement anyway due to 
>> conditional compilation.
>>
>> If you are interested, then let me know. I do need help 
>> testing though and some advice about unit tests.
>
> The instructions are those that were new with the Haswell micro 
> architecture so that’s what ten years ago now, so now is the 
> time that these instructions will become more usable for 
> programmers worried about older machines, and there are the 
> fallbacks too, as far as I have got with that.

It’s been a project to help me learn D and explore the code 
quality of these compilers. I wrote various assembler languages 
for a living when I was working some years back, although when C 
compilers rose to sufficient quality of code generation then we 
switched to C for x86 at work and asm was much less of a thing, 
as for everyone.

I have also written a module that allows cached querying of 
results of calls to cpuid so that users can test for availability 
once only getting all the checks done before main so that there’s 
minimal overhead inside the real code in loops or wherever. The 
module calls cpuid many times in a loop with all the leaf 
subfunction queries that you might be interested in. That needs 
more work to be selective, maybe, and I haven’t yet enumerated 
all of the possibilities, because there are potentially a lot of 
them, and possibly many that users are not interested in in their 
use case. So I could perhaps do with a bit of advice there. Again 
if this is something that might be of interest then let me know. 
Needs a lot of cleanup once again to make the code look pretty.


More information about the Digitalmars-d mailing list