//static const unsigned short mm_wone[4] __attribute__ ((aligned(8))) = { 0x1, 0x1, 0x1, 0x1 };
//static const unsigned short mm_wtwo[4] __attribute__ ((aligned(8))) = { 0x2, 0x2, 0x2, 0x2 };
+#define JUMPALIGN() __asm __volatile (".balign 8"::)
+#define MOVQ_ZERO(regd) __asm __volatile ("pxor %%" #regd ", %%" #regd ::)
+
+#ifndef PIC
+#define MOVQ_WONE(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_wone))
+#define MOVQ_WTWO(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_wtwo))
+#else
+// for shared library it's better to use this way for accessing constants
+// pcmpeqd -> -1
+#define MOVQ_WONE(regd) \
+ __asm __volatile ( \
+ "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
+ "psrlw $15, %%" #regd ::)
+
+#define MOVQ_WTWO(regd) \
+ __asm __volatile ( \
+ "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
+ "psrlw $15, %%" #regd " \n\t" \
+ "psllw $1, %%" #regd ::)
+#endif
+
/***********************************/
/* 3Dnow specific */
/* read the pixels */
p = block;
pix = pixels;
- __asm __volatile("pxor %%mm7, %%mm7":);
+ MOVQ_ZERO(mm7);
for(i=0;i<4;i++) {
__asm __volatile(
"movq %1, %%mm0\n\t"
{
const DCTELEM *p;
UINT8 *pix;
- int i;
/* read the pixels */
p = block;
pix = pixels;
- for(i=0;i<2;i++) {
+ /* unrolled loop */
__asm __volatile(
"movq %3, %%mm0\n\t"
"movq 8%3, %%mm1\n\t"
:"memory");
pix += line_size*4;
p += 32;
- }
+
+ // if here would be an exact copy of the code above
+ // compiler would generate some very strange code
+ // thus using "r"
+ __asm __volatile(
+ "movq (%3), %%mm0\n\t"
+ "movq 8(%3), %%mm1\n\t"
+ "movq 16(%3), %%mm2\n\t"
+ "movq 24(%3), %%mm3\n\t"
+ "movq 32(%3), %%mm4\n\t"
+ "movq 40(%3), %%mm5\n\t"
+ "movq 48(%3), %%mm6\n\t"
+ "movq 56(%3), %%mm7\n\t"
+ "packuswb %%mm1, %%mm0\n\t"
+ "packuswb %%mm3, %%mm2\n\t"
+ "packuswb %%mm5, %%mm4\n\t"
+ "packuswb %%mm7, %%mm6\n\t"
+ "movq %%mm0, (%0)\n\t"
+ "movq %%mm2, (%0, %1)\n\t"
+ "movq %%mm4, (%0, %1, 2)\n\t"
+ "movq %%mm6, (%0, %2)\n\t"
+ ::"r" (pix), "r" (line_size), "r" (line_size*3), "r"(p)
+ :"memory");
}
static void add_pixels_clamped_mmx(const DCTELEM *block, UINT8 *pixels, int line_size)
/* read the pixels */
p = block;
pix = pixels;
- __asm __volatile("pxor %%mm7, %%mm7":);
- for(i=0;i<4;i++) {
+ MOVQ_ZERO(mm7);
+ i = 4;
+ while (i) {
__asm __volatile(
"movq %2, %%mm0\n\t"
"movq 8%2, %%mm1\n\t"
:"memory");
pix += line_size*2;
p += 16;
- }
+ i--;
+ };
}
static void put_pixels_mmx(UINT8 *block, const UINT8 *pixels, int line_size, int h)
{
- int dh, hh;
+ int hh;
UINT8 *p;
const UINT8 *pix;
+
p = block;
- pix = pixels;
+ pix = pixels; // 2s
+#if 0
+ do {
+ __asm __volatile(
+ "movq %1, %%mm0\n\t"
+ "movq %%mm0, %0\n\t"
+ :"=m"(*p)
+ :"m"(*pix)
+ :"memory");
+ pix += line_size;
+ p += line_size;
+ } while (--h);
+#else
+ // this optimized code is not very usefull
+ // the above loop is definitely faster
+ // at least on Celeron 500MHz
+ hh = h & 3;
+ while (hh) {
+ __asm __volatile(
+ "movq %1, %%mm0\n\t"
+ "movq %%mm0, %0\n\t"
+ :"=m"(*p)
+ :"m"(*pix)
+ :"memory");
+ pix += line_size;
+ p += line_size;
+ hh--;
+ }
hh=h>>2;
- dh=h&3;
- while(hh--) {
+ while (hh) {
__asm __volatile(
"movq (%1), %%mm0 \n\t"
"movq (%1, %2), %%mm1 \n\t"
"movq %%mm3, (%0, %3) \n\t"
::"r"(p), "r"(pix), "r"(line_size), "r"(line_size*3)
:"memory");
- pix = pix + line_size*4;
- p = p + line_size*4;
- }
- while(dh--) {
- __asm __volatile(
- "movq %1, %%mm0\n\t"
- "movq %%mm0, %0\n\t"
- :"=m"(*p)
- :"m"(*pix)
- :"memory");
- pix = pix + line_size;
- p = p + line_size;
+ pix += line_size*4;
+ p += line_size*4;
+ hh--;
}
+#endif
}
static void put_pixels_x2_mmx(UINT8 *block, const UINT8 *pixels, int line_size, int h)
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm4\n\t"
- ::"m"(mm_wone));
+ MOVQ_ZERO(mm7);
+ MOVQ_WONE(mm4);
+ JUMPALIGN();
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm4\n\t"
- ::"m"(mm_wone));
+ MOVQ_ZERO(mm7);
+ MOVQ_WONE(mm4);
+ JUMPALIGN();
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
UINT8 *p;
const UINT8 *pix;
p = block;
- pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm6\n\t"
- ::"m"(mm_wtwo));
+ pix = pixels; // 1s
+ MOVQ_ZERO(mm7);
+ MOVQ_WTWO(mm6);
+ JUMPALIGN();
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile("pxor %%mm7, %%mm7\n\t":);
+ MOVQ_ZERO(mm7);
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile("pxor %%mm7, %%mm7\n\t":);
+ MOVQ_ZERO(mm7);
+ JUMPALIGN();
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm6\n\t"
- ::"m"(mm_wone));
+ MOVQ_ZERO(mm7);
+ MOVQ_WONE(mm6);
+ JUMPALIGN();
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm6\n\t"
- ::"m"(mm_wone));
+ MOVQ_ZERO(mm7);
+ MOVQ_WONE(mm6);
+ JUMPALIGN();
do {
__asm __volatile(
"movq %0, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm6\n\t"
- ::"m"(mm_wone));
+ MOVQ_ZERO(mm7);
+ MOVQ_WONE(mm6);
+ JUMPALIGN();
do {
__asm __volatile(
"movq %1, %%mm1\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm6\n\t"
- ::"m"(mm_wone));
+ MOVQ_ZERO(mm7);
+ MOVQ_WONE(mm6);
+ JUMPALIGN();
do {
__asm __volatile(
"movq %1, %%mm1\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm6\n\t"
- ::"m"(mm_wtwo));
+ MOVQ_ZERO(mm7);
+ // this doesn't seem to be used offten - so
+ // the inside usage of mm_wone is not optimized
+ MOVQ_WTWO(mm6);
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile("pxor %%mm7, %%mm7\n\t":);
+ MOVQ_ZERO(mm7);
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t":);
+ MOVQ_ZERO(mm7);
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t":);
+ MOVQ_ZERO(mm7);
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm6\n\t"
- ::"m"(mm_wone));
+ MOVQ_ZERO(mm7);
+ MOVQ_WONE(mm6);
+ JUMPALIGN();
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile("pxor %%mm7, %%mm7":);
+ MOVQ_ZERO(mm7);
do {
__asm __volatile(
"movq %0, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm6"
- ::"m"(mm_wone));
+ MOVQ_ZERO(mm7);
+ MOVQ_WONE(mm6);
+ JUMPALIGN();
do {
__asm __volatile(
"movq %0, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm6"
- ::"m"(mm_wone));
+ MOVQ_ZERO(mm7);
+ MOVQ_WONE(mm6);
do {
__asm __volatile(
"movq %0, %%mm0\n\t"
const UINT8 *pix;
p = block;
pix = pixels;
- __asm __volatile(
- "pxor %%mm7, %%mm7\n\t"
- "movq %0, %%mm6\n\t"
- ::"m"(mm_wtwo));
+ MOVQ_ZERO(mm7);
+ MOVQ_WTWO(mm6);
+ JUMPALIGN();
do {
__asm __volatile(
"movq %1, %%mm0\n\t"
} while(--h);
}
+static void just_return() { return; }
+
void dsputil_init_mmx(void)
{
mm_flags = mm_support();
ff_idct = simple_idct_mmx;
#endif
}
+
+#if 0
+ // for speed testing
+ get_pixels = just_return;
+ put_pixels_clamped = just_return;
+ add_pixels_clamped = just_return;
+
+ pix_abs16x16 = just_return;
+ pix_abs16x16_x2 = just_return;
+ pix_abs16x16_y2 = just_return;
+ pix_abs16x16_xy2 = just_return;
+
+ put_pixels_tab[0] = just_return;
+ put_pixels_tab[1] = just_return;
+ put_pixels_tab[2] = just_return;
+ put_pixels_tab[3] = just_return;
+
+ put_no_rnd_pixels_tab[0] = just_return;
+ put_no_rnd_pixels_tab[1] = just_return;
+ put_no_rnd_pixels_tab[2] = just_return;
+ put_no_rnd_pixels_tab[3] = just_return;
+
+ avg_pixels_tab[0] = just_return;
+ avg_pixels_tab[1] = just_return;
+ avg_pixels_tab[2] = just_return;
+ avg_pixels_tab[3] = just_return;
+
+ avg_no_rnd_pixels_tab[0] = just_return;
+ avg_no_rnd_pixels_tab[1] = just_return;
+ avg_no_rnd_pixels_tab[2] = just_return;
+ avg_no_rnd_pixels_tab[3] = just_return;
+
+ sub_pixels_tab[0] = just_return;
+ sub_pixels_tab[1] = just_return;
+ sub_pixels_tab[2] = just_return;
+ sub_pixels_tab[3] = just_return;
+
+ //av_fdct = just_return;
+ //ff_idct = just_return;
+#endif
}