On 6 January 2012 20:53, Walter Bright <newshound2@digitalmars.com> wrote:
On 1/6/2012 6:05 AM, Manu wrote:
On 6 January 2012 08:22, Walter Bright <newshound2@digitalmars.com
<mailto:newshound2@digitalmars.com>> wrote:

   On 1/5/2012 7:42 PM, Manu wrote:

       Perhaps I misunderstand, I can't see the problem?
       In the function preamble, you just align it... something like:
          mov reg, esp ; take a backup of the stack pointer
          and esp, -16 ; align it

       ... function

          mov esp, reg ; restore the stack pointer
          ret 0


   And now you cannot access the function's parameters anymore, because the
   stack offset for them is now variable rather than fixed.


Hehe, true, but not insurmountable. Scheduling of parameter pops before you
perform the alignment may solve that straight up, or else don't align esp its
self; store the vector to the stack through some other aligned reg copied from
esp...

I just wrote some test functions using __m128 in VisualC, it seems to do
something in between the simplicity of my initial suggestion, and my refined
ideas one above :)
If you have VisualC, check out what it does, it's very simple, looks pretty
good, and I'm sure it's optimal (MS have enough R&D money to assure this)

I can paste some disassemblies if you don't have VC...

I don't have VC. I had thought of using an extra level of indirection for all the aligned stuff, essentially rewrite:

   v128 v;
   v = x;

with:

   v128 v; // goes in aligned stack
   v128 *pv = &v;  // pv is in regular stack
   *pv = x;

but there are still complexities with it, like spilling aligned temps to the stack.

I think we should take this conversation to IRC, or a separate thread?
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...
Have you tested the code that GCC produces? I'm sure it'll be identical to VC...

That said, how do you currently support ANY aligned type? I thought align(n) was a defined keyword in D?