<div dir="ltr">Hello Simon,<div><br></div><div>Thanks for your response. I had written a patch[1] for this and the approach I took was quite similar to what you pointed out. </div><div><br></div><div>data GlobalReg = ...<br>                          |  XmmReg </div><div>                              (Maybe (Length, Width))</div><div>                              (Maybe GlobalVecRegTy)</div><div><br></div><div>data GlobalVecRegTy = Integer | Float</div><div><br></div><div>-- Width and Length are already defined</div><div>data Width = W8 | W16 | W32 .....<br><br></div><div>type Length = Int  </div><div><br></div><div><br></div><div>I wrapped the types inside a `Maybe` because when initializing a GlobalReg (in the `activeStgRegs`[2] function), I was not sure what value to initialize the register with, so I used a `Nothing` when initializing. </div><div><br></div><div>I see now in the case of `VanillaReg` it is initialized with the `VGcPtr` constructor: <span class="gmail-pl-ent" style="box-sizing:border-box;color:rgb(34,134,58);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">VanillaReg</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> </span><span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,92,197);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">1</span><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> </span><span class="gmail-pl-ent" style="box-sizing:border-box;color:rgb(34,134,58);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">VGcPtr etc</span></div><div><span class="gmail-pl-ent" style="box-sizing:border-box;color:rgb(34,134,58);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;white-space:pre;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></span></div><div>I think I should modify my patch as well to remove the Maybe and initialize with some default Length, Width and GlobalRegTy.  Thanks for the help.</div><div><br></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span>Abhiroop</span></span></div><div><br></div><div><br></div><div>[1] <a href="https://phabricator.haskell.org/D4922">https://phabricator.haskell.org/D4922</a></div><div>[2] <a href="https://github.com/ghc/ghc/blob/master/includes/CodeGen.Platform.hs#L450">https://github.com/ghc/ghc/blob/master/includes/CodeGen.Platform.hs#L450-L623</a></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jul 13, 2018 at 10:58 AM Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-GB" link="blue" vlink="purple">
<div class="m_160898050108459242WordSection1">
<p class="MsoNormal"><span style="font-size:12.0pt">Abhiroop<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Did anyone reply?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">My instinct is this. You want to use the same register (say Xmm reg 3) in different ways.  We already have this for ‘VanillaReg’:<u></u><u></u></span></p>
<p class="m_160898050108459242Code">data GlobalReg<u></u><u></u></p>
<p class="m_160898050108459242Code">  = VanillaReg      -- pointers, unboxed ints and chars<u></u><u></u></p>
<p class="m_160898050108459242Code">        Int         -- its number<u></u><u></u></p>
<p class="m_160898050108459242Code">        VGcPtr<u></u><u></u></p>
<p class="m_160898050108459242Code">   | …<u></u><u></u></p>
<p class="m_160898050108459242Code"><u></u> <u></u></p>
<p class="m_160898050108459242Code">data VGcPtr = VGcPtr | VNonGcPtr <span style="font-family:"Calibri",sans-serif">
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">We use VanillaReg for both pointers and non-pointers, so (VanillaReg 3 VGcPtr) is register 3 used as a pointer, and (VanillaReg 3 VNonGcPtr) is register 3 used as a non-pointer.  And notice that globalRegType
 looks at this field to decide what type to return.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">I think you can do exactly the same: add a field to Xmm that explains how you are gong to divide it up.  Would that work?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">Simon<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><u></u> <u></u></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> ghc-devs <<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>>
<b>On Behalf Of </b>Abhiroop Sarkar<br>
<b>Sent:</b> 27 June 2018 22:32<br>
<b>To:</b> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<b>Subject:</b> Is it possible to enhance the vector STG registers(Xmm, Ymm, Zmm) with more information?<u></u><u></u></span></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Hello all,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
I am currently working on adding support for SIMD operations to the native code generator. One of the roadblocks I faced recently was the definition of the `globalRegType` function in "compiler/cmm/CmmExpr.hs". The `globalRegType` function maps the STG registers
 to the respective `CmmType` datatype.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
For Xmm, Ymm, Zmm registers the function defines globalRegType like this: <a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fghc%2Fghc%2Fblob%2Fmaster%2Fcompiler%2Fcmm%2FCmmExpr.hs%23L585-L587&data=02%7C01%7Csimonpj%40microsoft.com%7C982283cef5194f34c1e508d5dc758c48%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C1%7C636657319780067709&sdata=3SB86SoRXM2q%2BPE0tPcbuTsTZ6w7suxPX95qM%2BNLPA8%3D&reserved=0" target="_blank">https://github.com/ghc/ghc/blob/master/compiler/cmm/CmmExpr.hs#L585-L587</a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Consider the case for an Xmm register, the above definition limits an Xmm register to hold only vectors of size 4. However we can store 2 64-bit Doubles or 16 Int8s or 8 Int16s and so on<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
The function `globalRegType` is internally called by the function `cmmRegType` (<a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fghc%2Fghc%2Fblob%2F838b69032566ce6ab3918d70e8d5e098d0bcee02%2Fcompiler%2Fcmm%2FCmmExpr.hs%23L275&data=02%7C01%7Csimonpj%40microsoft.com%7C982283cef5194f34c1e508d5dc758c48%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C1%7C636657319780077717&sdata=V7McH5OXYD%2Bbfl2jjUHmquDxmr1BlZF8q1L%2Bq%2Bscq%2BY%3D&reserved=0" target="_blank">https://github.com/ghc/ghc/blob/838b69032566ce6ab3918d70e8d5e098d0bcee02/compiler/cmm/CmmExpr.hs#L275</a>)
 which is itself used in a number of places in the x86 code generator.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
In fact depending on the result of the `cmmRegType` function is another important function `cmmTypeFormat` defined in Format.hs whose result is used to print the actual assembly instruction.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
I have extended all the other Format types to include VectorFormats, however this definition of the `globalRegType` seems incorrect to me. Looking at the signature of the function itself:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
`globalRegType :: DynFlags -> GlobalReg -> CmmType`<br>
<br>
its actually difficult to predict the CmmType by just looking at the GlobalReg in case of Xmm, Ymm, Zmm. So thats why my original question how do I go about solving this. Should I modify the GlobalReg type to contain more information like Width and Length(for
 Xmm, Ymm, Zmm)  or do I somehow pass the length and width information to the globalRegType function?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Thanks<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Abhiroop Sakar<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>

</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Kloona - Coming Soon!<br></div></div>