| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include "mmxnow.h" |
| 31 |
#include "mmxnow_private.h" |
| 32 |
|
| 33 |
#include "mmx.h" |
| 34 |
|
| 35 |
|
| 36 |
#include <stdio.h> |
| 37 |
#include <stdlib.h> |
| 38 |
|
| 39 |
|
| 40 |
static const uint64_t mmx_80w = 0x0080008000800080; |
| 41 |
static const uint64_t mmx_10w = 0x1010101010101010; |
| 42 |
static const uint64_t mmx_00ffw = 0x00ff00ff00ff00ff; |
| 43 |
static const uint64_t mmx_Y_coeff = 0x253f253f253f253f; |
| 44 |
|
| 45 |
|
| 46 |
static const uint64_t mmx_U_green = 0xf37df37df37df37d; |
| 47 |
static const uint64_t mmx_U_blue = 0x4093409340934093; |
| 48 |
static const uint64_t mmx_V_red = 0x3312331233123312; |
| 49 |
static const uint64_t mmx_V_green = 0xe5fce5fce5fce5fc; |
| 50 |
|
| 51 |
|
| 52 |
static const uint64_t mmx_redmask = 0xf8f8f8f8f8f8f8f8; |
| 53 |
static const uint64_t mmx_grnmask = 0xfcfcfcfcfcfcfcfc; |
| 54 |
static const uint64_t mmx_grnshift = 0x03; |
| 55 |
static const uint64_t mmx_blueshift = 0x03; |
| 56 |
|
| 57 |
#if 0 |
| 58 |
#ifdef HAVE_MMX2 |
| 59 |
|
| 60 |
#define MOVNTQ "movntq" |
| 61 |
#else |
| 62 |
|
| 63 |
#define MOVNTQ "movq" |
| 64 |
#endif |
| 65 |
#endif |
| 66 |
|
| 67 |
|
| 68 |
#define MOVNTQ "movq" |
| 69 |
|
| 70 |
static int yuv420_rgb16_mmx(struct mmxnow_context_t* ctx) |
| 71 |
{ |
| 72 |
mmxnow_image_data_t* data = (mmxnow_image_data_t*) ctx->data; |
| 73 |
|
| 74 |
uint8_t* py = data->in.plane_y; |
| 75 |
uint8_t* pu = data->in.plane_u; |
| 76 |
uint8_t* pv = data->in.plane_v; |
| 77 |
int y_stride = data->in.stride_y; |
| 78 |
int uv_stride = data->in.stride_uv; |
| 79 |
int v_size = data->in.width; |
| 80 |
int h_size = data->in.height; |
| 81 |
|
| 82 |
uint8_t* image = data->out.image; |
| 83 |
int rgb_stride = data->out.stride; |
| 84 |
|
| 85 |
int even = 1; |
| 86 |
int x, y; |
| 87 |
|
| 88 |
__asm__ __volatile__ ("pxor %mm4, %mm4;" ); |
| 89 |
|
| 90 |
for (y = v_size; --y >= 0; ) { |
| 91 |
uint8_t *_image = image; |
| 92 |
uint8_t *_py = py; |
| 93 |
uint8_t *_pu = pu; |
| 94 |
uint8_t *_pv = pv; |
| 95 |
|
| 96 |
|
| 97 |
__asm__ __volatile__ ( |
| 98 |
"movd (%1), %%mm0;" |
| 99 |
"movd (%2), %%mm1;" |
| 100 |
"movq (%0), %%mm6;" |
| 101 |
|
| 102 |
: : "r" (_py), "r" (_pu), "r" (_pv)); |
| 103 |
|
| 104 |
for (x = h_size >> 3; --x >= 0; ) { |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
__asm__ __volatile__ ( |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
"punpcklbw %%mm4, %%mm0;" |
| 116 |
"punpcklbw %%mm4, %%mm1;" |
| 117 |
|
| 118 |
"psubsw mmx_80w, %%mm0;" |
| 119 |
"psubsw mmx_80w, %%mm1;" |
| 120 |
|
| 121 |
"psllw $3, %%mm0;" |
| 122 |
"psllw $3, %%mm1;" |
| 123 |
|
| 124 |
"movq %%mm0, %%mm2;" |
| 125 |
"movq %%mm1, %%mm3;" |
| 126 |
|
| 127 |
"pmulhw mmx_U_green, %%mm2;" |
| 128 |
"pmulhw mmx_V_green, %%mm3;" |
| 129 |
|
| 130 |
"pmulhw mmx_U_blue, %%mm0;" |
| 131 |
"pmulhw mmx_V_red, %%mm1;" |
| 132 |
|
| 133 |
"paddsw %%mm3, %%mm2;" |
| 134 |
|
| 135 |
|
| 136 |
"psubusb mmx_10w, %%mm6;" |
| 137 |
|
| 138 |
"movq %%mm6, %%mm7;" |
| 139 |
"pand mmx_00ffw, %%mm6;" |
| 140 |
|
| 141 |
"psrlw $8, %%mm7;" |
| 142 |
|
| 143 |
"psllw $3, %%mm6;" |
| 144 |
"psllw $3, %%mm7;" |
| 145 |
|
| 146 |
"pmulhw mmx_Y_coeff, %%mm6;" |
| 147 |
"pmulhw mmx_Y_coeff, %%mm7;" |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
"movq %%mm0, %%mm3;" |
| 155 |
"movq %%mm1, %%mm4;" |
| 156 |
"movq %%mm2, %%mm5;" |
| 157 |
|
| 158 |
"paddsw %%mm6, %%mm0;" |
| 159 |
"paddsw %%mm7, %%mm3;" |
| 160 |
|
| 161 |
"paddsw %%mm6, %%mm1;" |
| 162 |
"paddsw %%mm7, %%mm4;" |
| 163 |
|
| 164 |
"paddsw %%mm6, %%mm2;" |
| 165 |
"paddsw %%mm7, %%mm5;" |
| 166 |
|
| 167 |
|
| 168 |
"packuswb %%mm0, %%mm0;" |
| 169 |
"packuswb %%mm1, %%mm1;" |
| 170 |
"packuswb %%mm2, %%mm2;" |
| 171 |
|
| 172 |
|
| 173 |
"packuswb %%mm3, %%mm3;" |
| 174 |
"packuswb %%mm4, %%mm4;" |
| 175 |
"packuswb %%mm5, %%mm5;" |
| 176 |
|
| 177 |
|
| 178 |
"punpcklbw %%mm3, %%mm0;" |
| 179 |
"punpcklbw %%mm4, %%mm1;" |
| 180 |
"punpcklbw %%mm5, %%mm2;" |
| 181 |
|
| 182 |
|
| 183 |
"pand mmx_redmask, %%mm0;" |
| 184 |
"pand mmx_grnmask, %%mm2;" |
| 185 |
"pand mmx_redmask, %%mm1;" |
| 186 |
|
| 187 |
"psrlw mmx_blueshift,%%mm0;" |
| 188 |
"pxor %%mm4, %%mm4;" |
| 189 |
|
| 190 |
"movq %%mm0, %%mm5;" |
| 191 |
"movq %%mm2, %%mm7;" |
| 192 |
|
| 193 |
|
| 194 |
"punpcklbw %%mm4, %%mm2;" |
| 195 |
"punpcklbw %%mm1, %%mm0;" |
| 196 |
|
| 197 |
"psllw mmx_blueshift,%%mm2;" |
| 198 |
"por %%mm2, %%mm0;" |
| 199 |
|
| 200 |
"movq 8 (%0), %%mm6;" |
| 201 |
MOVNTQ " %%mm0, (%3);" |
| 202 |
|
| 203 |
|
| 204 |
"punpckhbw %%mm4, %%mm7;" |
| 205 |
"punpckhbw %%mm1, %%mm5;" |
| 206 |
|
| 207 |
"psllw mmx_blueshift,%%mm7;" |
| 208 |
"movd 4 (%1), %%mm0;" |
| 209 |
|
| 210 |
"por %%mm7, %%mm5;" |
| 211 |
"movd 4 (%2), %%mm1;" |
| 212 |
|
| 213 |
MOVNTQ " %%mm5, 8 (%3);" |
| 214 |
: : "r" (_py), "r" (_pu), "r" (_pv), "r" (_image)); |
| 215 |
|
| 216 |
_py += 8; |
| 217 |
_pu += 4; |
| 218 |
_pv += 4; |
| 219 |
_image += 16; |
| 220 |
} |
| 221 |
|
| 222 |
if (!even) { |
| 223 |
pu += uv_stride; |
| 224 |
pv += uv_stride; |
| 225 |
} |
| 226 |
|
| 227 |
py += y_stride; |
| 228 |
image += rgb_stride; |
| 229 |
|
| 230 |
even = (!even); |
| 231 |
} |
| 232 |
|
| 233 |
emms(); |
| 234 |
return 0; |
| 235 |
} |
| 236 |
|
| 237 |
static int yuv420_argb32_mmx (struct mmxnow_context_t* ctx) |
| 238 |
|
| 239 |
{ |
| 240 |
mmxnow_image_data_t* data = (mmxnow_image_data_t*) ctx->data; |
| 241 |
|
| 242 |
uint8_t* py = data->in.plane_y; |
| 243 |
uint8_t* pu = data->in.plane_u; |
| 244 |
uint8_t* pv = data->in.plane_v; |
| 245 |
int y_stride = data->in.stride_y; |
| 246 |
int uv_stride = data->in.stride_uv; |
| 247 |
int v_size = data->in.width; |
| 248 |
int h_size = data->in.height; |
| 249 |
|
| 250 |
uint8_t* image = data->out.image; |
| 251 |
int rgb_stride = data->out.stride; |
| 252 |
|
| 253 |
int even = 1; |
| 254 |
int x, y; |
| 255 |
|
| 256 |
__asm__ __volatile__ ("pxor %mm4, %mm4;" ); |
| 257 |
|
| 258 |
for (y = v_size; --y >= 0; ) { |
| 259 |
uint8_t *_image = image; |
| 260 |
uint8_t *_py = py; |
| 261 |
uint8_t *_pu = pu; |
| 262 |
uint8_t *_pv = pv; |
| 263 |
|
| 264 |
|
| 265 |
__asm__ __volatile__ |
| 266 |
( |
| 267 |
"movd (%1), %%mm0;" |
| 268 |
"movd (%2), %%mm1;" |
| 269 |
"movq (%0), %%mm6;" |
| 270 |
: : "r" (_py), "r" (_pu), "r" (_pv) |
| 271 |
); |
| 272 |
|
| 273 |
for (x = h_size >> 3; --x >= 0; ) { |
| 274 |
|
| 275 |
|
| 276 |
__asm__ __volatile__ ( |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
"punpcklbw %%mm4, %%mm0;" |
| 285 |
"punpcklbw %%mm4, %%mm1;" |
| 286 |
|
| 287 |
"psubsw mmx_80w, %%mm0;" |
| 288 |
"psubsw mmx_80w, %%mm1;" |
| 289 |
|
| 290 |
"psllw $3, %%mm0;" |
| 291 |
"psllw $3, %%mm1;" |
| 292 |
|
| 293 |
"movq %%mm0, %%mm2;" |
| 294 |
"movq %%mm1, %%mm3;" |
| 295 |
|
| 296 |
"pmulhw mmx_U_green, %%mm2;" |
| 297 |
"pmulhw mmx_V_green, %%mm3;" |
| 298 |
|
| 299 |
"pmulhw mmx_U_blue, %%mm0;" |
| 300 |
"pmulhw mmx_V_red, %%mm1;" |
| 301 |
|
| 302 |
"paddsw %%mm3, %%mm2;" |
| 303 |
|
| 304 |
|
| 305 |
"psubusb mmx_10w, %%mm6;" |
| 306 |
|
| 307 |
"movq %%mm6, %%mm7;" |
| 308 |
"pand mmx_00ffw, %%mm6;" |
| 309 |
|
| 310 |
"psrlw $8, %%mm7;" |
| 311 |
|
| 312 |
"psllw $3, %%mm6;" |
| 313 |
"psllw $3, %%mm7;" |
| 314 |
|
| 315 |
"pmulhw mmx_Y_coeff, %%mm6;" |
| 316 |
"pmulhw mmx_Y_coeff, %%mm7;" |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
"movq %%mm0, %%mm3;" |
| 325 |
"movq %%mm1, %%mm4;" |
| 326 |
"movq %%mm2, %%mm5;" |
| 327 |
|
| 328 |
"paddsw %%mm6, %%mm0;" |
| 329 |
"paddsw %%mm7, %%mm3;" |
| 330 |
|
| 331 |
"paddsw %%mm6, %%mm1;" |
| 332 |
"paddsw %%mm7, %%mm4;" |
| 333 |
|
| 334 |
"paddsw %%mm6, %%mm2;" |
| 335 |
"paddsw %%mm7, %%mm5;" |
| 336 |
|
| 337 |
|
| 338 |
"packuswb %%mm0, %%mm0;" |
| 339 |
"packuswb %%mm1, %%mm1;" |
| 340 |
"packuswb %%mm2, %%mm2;" |
| 341 |
|
| 342 |
|
| 343 |
"packuswb %%mm3, %%mm3;" |
| 344 |
"packuswb %%mm4, %%mm4;" |
| 345 |
"packuswb %%mm5, %%mm5;" |
| 346 |
|
| 347 |
|
| 348 |
"punpcklbw %%mm3, %%mm0;" |
| 349 |
"punpcklbw %%mm4, %%mm1;" |
| 350 |
"punpcklbw %%mm5, %%mm2;" |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
"pxor %%mm3, %%mm3;" |
| 357 |
|
| 358 |
"movq %%mm0, %%mm6;" |
| 359 |
"movq %%mm1, %%mm7;" |
| 360 |
|
| 361 |
"movq %%mm0, %%mm4;" |
| 362 |
"movq %%mm1, %%mm5;" |
| 363 |
|
| 364 |
"punpcklbw %%mm2, %%mm6;" |
| 365 |
"punpcklbw %%mm3, %%mm7;" |
| 366 |
|
| 367 |
"punpcklwd %%mm7, %%mm6;" |
| 368 |
MOVNTQ " %%mm6, (%3);" |
| 369 |
|
| 370 |
"movq %%mm0, %%mm6;" |
| 371 |
"punpcklbw %%mm2, %%mm6;" |
| 372 |
|
| 373 |
"punpckhwd %%mm7, %%mm6;" |
| 374 |
MOVNTQ " %%mm6, 8 (%3);" |
| 375 |
|
| 376 |
"punpckhbw %%mm2, %%mm4;" |
| 377 |
"punpckhbw %%mm3, %%mm5;" |
| 378 |
|
| 379 |
"punpcklwd %%mm5, %%mm4;" |
| 380 |
MOVNTQ " %%mm4, 16 (%3);" |
| 381 |
|
| 382 |
"movq %%mm0, %%mm4;" |
| 383 |
"punpckhbw %%mm2, %%mm4;" |
| 384 |
|
| 385 |
"punpckhwd %%mm5, %%mm4;" |
| 386 |
MOVNTQ " %%mm4, 24 (%3);" |
| 387 |
|
| 388 |
"movd 4 (%1), %%mm0;" |
| 389 |
"movd 4 (%2), %%mm1;" |
| 390 |
|
| 391 |
"pxor %%mm4, %%mm4;" |
| 392 |
"movq 8 (%0), %%mm6;" |
| 393 |
|
| 394 |
: : "r" (_py), "r" (_pu), "r" (_pv), "r" (_image)); |
| 395 |
|
| 396 |
_py += 8; |
| 397 |
_pu += 4; |
| 398 |
_pv += 4; |
| 399 |
_image += 32; |
| 400 |
} |
| 401 |
|
| 402 |
if (!even) { |
| 403 |
pu += uv_stride; |
| 404 |
pv += uv_stride; |
| 405 |
} |
| 406 |
|
| 407 |
py += y_stride; |
| 408 |
image += rgb_stride; |
| 409 |
|
| 410 |
even = (!even); |
| 411 |
} |
| 412 |
|
| 413 |
emms(); |
| 414 |
return 0; |
| 415 |
} |
| 416 |
|
| 417 |
void create_yuv2rgb_mmx(mmxnow_context_t* ctx, int method) |
| 418 |
{ |
| 419 |
if ((ctx->flags & MMXNOW_MMX) && ctx->method == NULL) |
| 420 |
{ |
| 421 |
switch (method) |
| 422 |
{ |
| 423 |
case MMXNOW_YV12_TO_RGB16: |
| 424 |
ctx->method = yuv420_rgb16_mmx; |
| 425 |
ctx->data = calloc(1, sizeof(mmxnow_image_data_t)); |
| 426 |
ctx->name = "yuv2rgb_mmx YV12 to RGB16"; |
| 427 |
break; |
| 428 |
case MMXNOW_YV12_TO_RGB32: |
| 429 |
ctx->method = yuv420_argb32_mmx; |
| 430 |
ctx->data = calloc(1, sizeof(mmxnow_image_data_t)); |
| 431 |
ctx->name = "yuv2rgb_mmx YV12 to RGB32"; |
| 432 |
break; |
| 433 |
} |
| 434 |
} |
| 435 |
} |