I was wondering if there is a dag pattern for shuffle masks?<br><br><div class="gmail_quote">On Thu, May 7, 2009 at 5:19 PM, Villmow, Micah <span dir="ltr"><<a href="mailto:Micah.Villmow@amd.com">Micah.Villmow@amd.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Manjunath,<br>
 I had a very similar problem and I solved it using a custom vector shuffle and addition instead of mov.<br>
<br>
For example,<br>
Vector_shuffle s1, s2, <0,3> is mapped to a custom instruction where I transform the swizzle to a 32bit integer mask and an inverted mask.<br>
<br>
So I have dst, src0, src1, imm1, imm2<br>
And I have my asm look similar to:<br>
Add dst, src0.imm1, src1.imm2 and then in the asm printer I intercept vector_shuffle and I convert the integer to x,y,z,w, 0, 1 or _.<br>
For example if the mask is to take x from s1 and yzw from s2, I would generate 0x1000 and 0x0234.<br>
So my result looks like<br>
Iadd d0, s1.x000, s2.0yzw<br>
<br>
This allows you to do your vector shuffle in a single instruction.<br>
<br>
It's not the cleanest approach but it works for me and I can encode up to 8 swizzle per immediate so works on vector sizes up to 8 in length.<br>
<br>
Hope this helps,<br>
<font color="#888888">Micah<br>
</font><div><div></div><div class="h5"><br>
-----Original Message-----<br>
From: <a href="mailto:llvmdev-bounces@cs.uiuc.edu">llvmdev-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:llvmdev-bounces@cs.uiuc.edu">llvmdev-bounces@cs.uiuc.edu</a>] On Behalf Of Manjunath Kudlur<br>
Sent: Thursday, May 07, 2009 5:28 PM<br>
To: LLVM Developers Mailing List<br>
Subject: Re: [LLVMdev] Question on tablegen<br>
<br>
Dan,<br>
<br>
Thanks a lot. Using a modifier in the assembly string works for this<br>
case. I am trying to solve a related problem. I am trying to print out<br>
a set of "mov" ops for the vector_shuffle node. Since the source of<br>
the "mov" is from one of the sources to vector_shuffle, depending on<br>
the mask, I am not sure what assembly string to emit. For example, if<br>
I have<br>
<br>
d <- vector_shuffle s1, s2, <0,3><br>
<br>
I want to emit<br>
<br>
mov d.x, s1.x<br>
mov d.y, s2.y<br>
<br>
For this, I need some thing like<br>
<br>
"mov $d.x, <$src1 or $src2>.<something that depends on the mask>"<br>
<br>
I can use the same modifier trick for which component of the source to<br>
select, but I don't know how to select which of the sources to select<br>
($src1 or $src2) depending on the mask. Do you have any suggestions?<br>
<br>
Thanks,<br>
Manjunath<br>
<br>
On Wed, May 6, 2009 at 10:10 AM, Dan Gohman <<a href="mailto:gohman@apple.com">gohman@apple.com</a>> wrote:<br>
> One way to do this is to handle this in the AsmPrinter, with<br>
> operand modifiers.<br>
><br>
> For example, on x86 there are instructions with ${dst:call} in<br>
> their asm string. The "call" part is interpreted as an operand<br>
> modifier. The assembly printer looks for the "call" modifier<br>
> on MachineOperand::MO_Immediate operands<br>
> (in X86ATTAsmPrinter::printOperand), which lets it perform custom<br>
> printing for that type of operand. You could use a modifier which<br>
> tells the AsmPrinter to print an immediate as the appropriate<br>
> letter.<br>
><br>
> Dan<br>
><br>
><br>
> On May 5, 2009, at 10:23 PM, Manjunath Kudlur wrote:<br>
><br>
>> Hello,<br>
>><br>
>> I am trying to create a machine instruction for "extractelement". I<br>
>> want to translate<br>
>> r <- extractelement v, 0<br>
>> to<br>
>> mov r, v.x<br>
>><br>
>> I was looking at the dag I can use and I found vector_extract. The<br>
>> inputs for this SDnode are a register and a iPtr constant. With that,<br>
>> I need to create 4 separate def's to extract element 0, 1, 2, and 3<br>
>> and translate to v.x, v.y, v.z, and v.w. I was wondering if I can use<br>
>> the dag's 2nd input as an index into a list of strings and form the<br>
>> assembly instruction, something like !strconcat("mov $dst, v.",<br>
>> elemnames[$input]). I am still trying to learn the tablegen syntax and<br>
>> semantics, so how to do this is not clear to me. I will appreciate any<br>
>> suggestions on how to do this, or pointers to other places where<br>
>> similar things are done.<br>
>><br>
>> Thanks,<br>
>> Manjunath<br>
>> _______________________________________________<br>
>> LLVM Developers mailing list<br>
>> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br>