<div class="gmail_quote">On 6 January 2012 20:53, Walter Bright <span dir="ltr"><<a href="mailto:newshound2@digitalmars.com">newshound2@digitalmars.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 1/6/2012 6:05 AM, Manu wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On 6 January 2012 08:22, Walter Bright <<a href="mailto:newshound2@digitalmars.com" target="_blank">newshound2@digitalmars.com</a><br></div><div><div class="h5">
<mailto:<a href="mailto:newshound2@digitalmars.com" target="_blank">newshound2@<u></u>digitalmars.com</a>>> wrote:<br>
<br>
    On 1/5/2012 7:42 PM, Manu wrote:<br>
<br>
        Perhaps I misunderstand, I can't see the problem?<br>
        In the function preamble, you just align it... something like:<br>
           mov reg, esp ; take a backup of the stack pointer<br>
           and esp, -16 ; align it<br>
<br>
        ... function<br>
<br>
           mov esp, reg ; restore the stack pointer<br>
           ret 0<br>
<br>
<br>
    And now you cannot access the function's parameters anymore, because the<br>
    stack offset for them is now variable rather than fixed.<br>
<br>
<br></div></div><div class="im">
Hehe, true, but not insurmountable. Scheduling of parameter pops before you<br>
perform the alignment may solve that straight up, or else don't align esp its<br>
self; store the vector to the stack through some other aligned reg copied from<br>
esp...<br>
<br>
I just wrote some test functions using __m128 in VisualC, it seems to do<br>
something in between the simplicity of my initial suggestion, and my refined<br>
ideas one above :)<br>
If you have VisualC, check out what it does, it's very simple, looks pretty<br>
good, and I'm sure it's optimal (MS have enough R&D money to assure this)<br>
<br></div><div class="im">
I can paste some disassemblies if you don't have VC...<br>
</div></blockquote>
<br>
I don't have VC. I had thought of using an extra level of indirection for all the aligned stuff, essentially rewrite:<br>
<br>
    v128 v;<br>
    v = x;<br>
<br>
with:<br>
<br>
    v128 v; // goes in aligned stack<br>
    v128 *pv = &v;  // pv is in regular stack<br>
    *pv = x;<br>
<br>
but there are still complexities with it, like spilling aligned temps to the stack.<br>
</blockquote></div><br><div>I think we should take this conversation to IRC, or a separate thread?</div><div>I'll generate some examples from VC for you in various situations. If you can write me a short list of trouble cases as you see them, I'll make sure to address them specifically...</div>
<div>Have you tested the code that GCC produces? I'm sure it'll be identical to VC...</div><div><br></div><div>That said, how do you currently support ANY aligned type? I thought align(n) was a defined keyword in D?</div>