/src/aom/av1/encoder/x86/model_rd_sse2.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2026, Alliance for Open Media. All rights reserved. |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 2 Clause License and |
5 | | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
6 | | * was not distributed with this source code in the LICENSE file, you can |
7 | | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
8 | | * Media Patent License 1.0 was not distributed with this source code in the |
9 | | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
10 | | */ |
11 | | |
12 | | #include <emmintrin.h> |
13 | | |
14 | | #include "config/av1_rtcd.h" |
15 | | |
16 | | void av1_interp_cubic_rate_dist_sse2(const double *p1, const double *p2, |
17 | 0 | double x, double rate_dist_f[2]) { |
18 | 0 | const __m128d half = _mm_set1_pd(0.5); |
19 | 0 | const __m128d two = _mm_set1_pd(2.0); |
20 | 0 | const __m128d three = _mm_set1_pd(3.0); |
21 | 0 | const __m128d four = _mm_set1_pd(4.0); |
22 | 0 | const __m128d five = _mm_set1_pd(5.0); |
23 | |
|
24 | 0 | const __m128d reg_x = _mm_set1_pd(x); |
25 | 0 | const __m128d reg_p0 = _mm_set_pd(p2[0], p1[0]); |
26 | 0 | const __m128d reg_p1 = _mm_set_pd(p2[1], p1[1]); |
27 | 0 | const __m128d reg_p2 = _mm_set_pd(p2[2], p1[2]); |
28 | 0 | const __m128d reg_p3 = _mm_set_pd(p2[3], p1[3]); |
29 | | |
30 | | // To ensure that results are bit-identical to the C code, we need to perform |
31 | | // exactly the same sequence of operations here as in the C code. |
32 | | // reg_res_0 = x * (3.0 * (p[1] - p[2]) + p[3] - p[0]) |
33 | 0 | __m128d reg_res_0 = _mm_sub_pd(reg_p1, reg_p2); |
34 | 0 | reg_res_0 = _mm_mul_pd(three, reg_res_0); |
35 | 0 | reg_res_0 = _mm_add_pd(reg_res_0, reg_p3); |
36 | 0 | reg_res_0 = _mm_sub_pd(reg_res_0, reg_p0); |
37 | 0 | reg_res_0 = _mm_mul_pd(reg_x, reg_res_0); |
38 | | |
39 | | // reg_res_1 = 2.0 * p[0] - 5.0 * p[1] + 4.0 * p[2]- p[3] |
40 | 0 | const __m128d regp0_x_2 = _mm_mul_pd(two, reg_p0); |
41 | 0 | const __m128d regp1_x_5 = _mm_mul_pd(five, reg_p1); |
42 | 0 | const __m128d regp2_x_4 = _mm_mul_pd(four, reg_p2); |
43 | 0 | __m128d reg_res_1 = _mm_sub_pd(regp0_x_2, regp1_x_5); |
44 | 0 | reg_res_1 = _mm_add_pd(reg_res_1, regp2_x_4); |
45 | 0 | reg_res_1 = _mm_sub_pd(reg_res_1, reg_p3); |
46 | | |
47 | | // reg_res_2 = x * (reg_res_1 + reg_res_0) |
48 | 0 | __m128d reg_res_2 = _mm_add_pd(reg_res_1, reg_res_0); |
49 | 0 | reg_res_2 = _mm_mul_pd(reg_x, reg_res_2); |
50 | | |
51 | | // reg_res_3 = p[2] - p[0] + reg_res_2 |
52 | 0 | __m128d reg_res_3 = _mm_sub_pd(reg_p2, reg_p0); |
53 | 0 | reg_res_3 = _mm_add_pd(reg_res_3, reg_res_2); |
54 | | |
55 | | // reg_res_4 = p[1] + 0.5 * x * reg_res_3 |
56 | 0 | __m128d reg_res_4 = _mm_mul_pd(_mm_mul_pd(half, reg_x), reg_res_3); |
57 | 0 | reg_res_4 = _mm_add_pd(reg_p1, reg_res_4); |
58 | |
|
59 | 0 | _mm_storeu_pd(rate_dist_f, reg_res_4); |
60 | 0 | } |