81a7889d1b4c169f6e316fa0ac79128acc0ef472
1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Steve Borho <steve@borho.org>
5 * Mandar Gurav <mandar@multicorewareinc.com>
6 * Deepthi Devaki Akkoorath <deepthidevaki@multicorewareinc.com>
7 * Mahesh Pittala <mahesh@multicorewareinc.com>
8 * Rajesh Paulraj <rajesh@multicorewareinc.com>
9 * Min Chen <min.chen@multicorewareinc.com>
10 * Praveen Kumar Tiwari <praveen@multicorewareinc.com>
11 * Nabajit Deka <nabajit@multicorewareinc.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
27 * This program is also available under a commercial proprietary license.
28 * For more information, contact us at license @ x265.com.
29 *****************************************************************************/
32 #include "primitives.h"
33 #include <xmmintrin.h> // SSE
34 #include <smmintrin.h> // SSE4.1
39 void dequant_scaling(const int16_t* quantCoef
, const int32_t *deQuantCoef
, int16_t* coef
, int num
, int per
, int shift
)
41 X265_CHECK(num
<= 32 * 32, "dequant num too large\n");
49 valueToAdd
= 1 << (shift
- per
- 1);
50 __m128i IAdd
= _mm_set1_epi32(valueToAdd
);
52 for (int n
= 0; n
< num
; n
= n
+ 8)
54 __m128i quantCoef1
, quantCoef2
, deQuantCoef1
, deQuantCoef2
, quantCoef12
, sign
;
56 quantCoef12
= _mm_loadu_si128((__m128i
*)(quantCoef
+ n
));
58 deQuantCoef1
= _mm_loadu_si128((__m128i
*)(deQuantCoef
+ n
));
59 deQuantCoef2
= _mm_loadu_si128((__m128i
*)(deQuantCoef
+ n
+ 4));
61 sign
= _mm_srai_epi16(quantCoef12
, 15);
62 quantCoef1
= _mm_unpacklo_epi16(quantCoef12
, sign
);
63 quantCoef2
= _mm_unpackhi_epi16(quantCoef12
, sign
);
65 quantCoef1
= _mm_sra_epi32(_mm_add_epi32(_mm_mullo_epi32(quantCoef1
, deQuantCoef1
), IAdd
), _mm_cvtsi32_si128(shift
- per
));
66 quantCoef2
= _mm_sra_epi32(_mm_add_epi32(_mm_mullo_epi32(quantCoef2
, deQuantCoef2
), IAdd
), _mm_cvtsi32_si128(shift
- per
));
68 quantCoef12
= _mm_packs_epi32(quantCoef1
, quantCoef2
);
69 _mm_storeu_si128((__m128i
*)(coef
+ n
), quantCoef12
);
74 for (int n
= 0; n
< num
; n
= n
+ 8)
76 __m128i quantCoef1
, quantCoef2
, deQuantCoef1
, deQuantCoef2
, quantCoef12
, sign
;
78 quantCoef12
= _mm_loadu_si128((__m128i
*)(quantCoef
+ n
));
80 deQuantCoef1
= _mm_loadu_si128((__m128i
*)(deQuantCoef
+ n
));
81 deQuantCoef2
= _mm_loadu_si128((__m128i
*)(deQuantCoef
+ n
+ 4));
83 sign
= _mm_srai_epi16(quantCoef12
, 15);
84 quantCoef1
= _mm_unpacklo_epi16(quantCoef12
, sign
);
85 quantCoef2
= _mm_unpackhi_epi16(quantCoef12
, sign
);
87 quantCoef1
= _mm_mullo_epi32(quantCoef1
, deQuantCoef1
);
88 quantCoef2
= _mm_mullo_epi32(quantCoef2
, deQuantCoef2
);
90 quantCoef12
= _mm_packs_epi32(quantCoef1
, quantCoef2
);
91 sign
= _mm_srai_epi16(quantCoef12
, 15);
92 quantCoef1
= _mm_unpacklo_epi16(quantCoef12
, sign
);
93 quantCoef2
= _mm_unpackhi_epi16(quantCoef12
, sign
);
95 quantCoef1
= _mm_sll_epi32(quantCoef1
, _mm_cvtsi32_si128(per
- shift
));
96 quantCoef2
= _mm_sll_epi32(quantCoef2
, _mm_cvtsi32_si128(per
- shift
));
98 quantCoef12
= _mm_packs_epi32(quantCoef1
, quantCoef2
);
99 _mm_storeu_si128((__m128i
*)(coef
+ n
), quantCoef12
);
106 void Setup_Vec_DCTPrimitives_sse41(EncoderPrimitives
&p
)
108 p
.dequant_scaling
= dequant_scaling
;