www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Using imm8 through inline assembler

reply Etienne <etcimon gmail.com> writes:
I'm trying to write (in DMD) the assembler that handles the function :

__m256i _mm256_permute4x64_epi64(__m256i a, in int M);

This translates to vpermq

The closest thing I could find in DMD assembly is VPERMILPS, which is 
called with:

asm { vpermilps YMM0, YMM1, IMM8; }

However, I cannot find out how to make IMM8 with `in int M`. I can 
convert int -> short[4] -> ubyte, but I can't move it into imm8

asm { mov imm8, ub; } <-- Fails.


Does anyone have an idea of what this is and how to define it?

Thanks in advance.
Oct 28 2014
parent reply "anonymous" <anonymous example.com> writes:
On Tuesday, 28 October 2014 at 21:05:15 UTC, Etienne wrote:
 I'm trying to write (in DMD) the assembler that handles the 
 function :

 __m256i _mm256_permute4x64_epi64(__m256i a, in int M);

 This translates to vpermq

 The closest thing I could find in DMD assembly is VPERMILPS, 
 which is called with:

 asm { vpermilps YMM0, YMM1, IMM8; }

 However, I cannot find out how to make IMM8 with `in int M`. I 
 can convert int -> short[4] -> ubyte, but I can't move it into 
 imm8

 asm { mov imm8, ub; } <-- Fails.


 Does anyone have an idea of what this is and how to define it?
Disclaimer: I only know a little basic X86 assembler, and I'm just going of the first google result for "vpermilps" [1]. "imm8" is not a register. "imm" stands for "immediate", i.e. a constant, hard-coded value. E.g.: asm { vpermilps YMM0, YMM1, 0 /* no idea what would be a meaningful value */; } There are variants of vpermilps that work on three registers. The third register is a XMM/YMM register, too, then. E.g.: asm { vpermilps YMM0, YMM1, YMM2; } I think my CPU doesn't have AVX, so I can't test anything beyond compiling. When running all I get is "Illegal instruction (core dumped)". [1] http://www.felixcloutier.com/x86/VPERMILPS.html
Oct 28 2014
parent Etienne Cimon <etcimon gmail.com> writes:
 "imm8" is not a register. "imm" stands for "immediate", i.e. a
 constant, hard-coded value. E.g.:

 asm { vpermilps YMM0, YMM1, 0 /* no idea what would be a
 meaningful value */; }
Oh, well, that makes sense. This means I should use string mixins to insert the actual value. I couldn't run AVX2 either, I have to work on this blindly until I get my hands on a new Xeon E5-2620 3rd generation processor. :/
 I think my CPU doesn't have AVX, so I can't test anything beyond
compiling. When running all I get is "Illegal instruction (core dumped)". My error is vmovdqu, I get: Error: AVX vector types not supported Anyone know what this is? I can't find a reference to it in the dmd compiler code. Also, 'vpunpcklqdq _ymm, _ymm, _ymm' is undefined in DMD, so I get : avx2.d(23): Error: bad type/size of operands 'vpunpcklqdq' Looks like abunch of work is needed to get avx2 working...
Oct 28 2014