Subject: Re: 'pand' MMX instruction -- illegal?
To: None <Havard.Eidnes@runit.sintef.no>
From: Andreas Gustafsson <gson@araneus.fi>
List: port-i386
Date: 01/14/1999 17:49:21
Havard.Eidnes@runit.sintef.no wrote:
> the following minimal test program crashes with an "Illegal
> Instruction" signal when run on a P-II/400MHz system running
> NetBSD-current of 5 Jan 1999:
> 
> --- snip ---

I am using MMX under NetBSD/i386 1.3.2 on an AMD K6.  I had to patch
the 1.3.2 assembler source to add support for the MMX instructions.
You are apparently using the built-in MMX support in as.new which was
only recently integrated into -current for the i386 port; I haven't
yet built a recent enough -current to try it out myself.  In other
words, you are using quite new and untested assembler functionality.

This is what I get with my patched gas 1.92.3:

   $ cc mmx.c
   $ a.out
   184

In other words, it does not bomb, but I don't think the result is
the expected one, either.  

>	__asm("
>		movq %%mm6, %1
>		movq %%mm7, %2
>		pand %%mm6, %%mm7
>		movq %0, %%mm6
>		" : "=m" (c) : "m" (a), "m" (b));

Aha!  The operands are the wrong way around.  NetBSD's assembler
wants the source operand on the left and the destination on 
the right, opposite from Intel's.  Wherever did that silliness
come from, anyway?  I switched the operand order and it printed 
4 as expected.

> Do I stand any chance of getting this to work at all on
> NetBSD/i386, or is this a can of worms not worth contemplating
> opening, related to whether floating point context needs to be
> saved on context switches and other related goo?

MMX works fine on NetBSD/i386 provided you find a working assembler.
You only run into the context switch goo if you are crazy enogh to try
to do MMX in the kernel like I'm doing (http://www.araneus.fi/audsl/).
-- 
Andreas Gustafsson, gson@araneus.fi