This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Unsaved register?


On Tue, 29 May 2001, Michael Meissner wrote:

> You need to also provide specific clobbers for all of the floating point
> registers, since they are overlaid on top of the mmx registers.  You also
> increment the stack with the pushes without decrementing them.  Note, that eax,
> ebx, and ecx are clobbered across calls (and esi/dsi seem to be clobbered in
> 64-bit mode).  I would encode it something like:
>
> 	extern __inline__
> 	uint32_t bitstream_get_mmx(bitstream_t *bs, uint32_t num_bits)
> 	{
> 	  int32_t bits;
> 	  uint32_t result;
>
> 	  bits = bs->current_bits - num_bits;
> 	  if (bits < 0)
> 	    return bitstream_get_bh_mmx (bs, num_bits);
>
> 	  __asm__ volatile ("movq %1, %%mm7\n\t"	// put current bits into mm7
> 			    "movd %8, %%mm5\n\t"	// put the shift count into mm5
> 			    "movq %%mm7, %%mm6\n\t"	// working copy in mm6
> 			    "movd %4, %%mm4\n\t"	// get the bit count again
> 			    "psrlq %%mm5, %%mm6\n\t"	// shift mm6 right by 64 - numbits
> 							// mm6 now has the right data
> 			    "movl %3, %2\n\t"		// save back the modified curbits
> 			    "movd %%mm6, %0\n\t"	// write the resulting bits out
> 			    "psllq %%mm4, %%mm7\n\t"	// strip those bits off mm7
> 			    "movq %%mm7, %1\n\t"	// save the remaining bits back
> 		: "=r" (result),
> 		  "+m" (bs->current.u64),
> 		  "+m" (bs->current_bits)
> 		: "r" (bits),
> 		  "r" (num_bits),
> 		  "rm" (_bitstream_mmx_64_minus[num_bits])
> 		// clobber all FPU registers
> 		: "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)"
> #if (__GNUC__ >= 3) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
> 		// and also the mmx registers used if we have a new enough compiler
> 		  , "mm5", "mm6", "mm7"
> #endif
> 	  );
>
> 	  return result;
> 	}
>
> However, since it has been awhile since I supported the x86, I suspect somebody
> who has worked with it more recently should look it over.

OK, that looks good.  I'll give it a try and see how it compiles down (I'd
hope it compiles down to the same code I have).  I just had an idea too.
Would it be possible for the compiler to automatically insert 'emms' where
needed?  Hrm, maybe not, it could be very hard to figure out where that
is, except at the end of a function.  Maybe any time a function (after
inline expansion) clobbers an mm register, the last instruction is an
emms?  Is that a possibility?

      Erik Walthinsen <omega@temple-baptist.com> - System Administrator
        __
       /  \                GStreamer - The only way to stream!
      |    | M E G A        ***** http://gstreamer.net/ *****
      _\  /_


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]