1 /*
2 * Copyright (c) 2016, 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 <stdlib.h>
13
14 #include "aom_dsp/mips/macros_msa.h"
15
aom_plane_add_noise_msa(uint8_t * start_ptr,char * noise,char blackclamp[16],char whiteclamp[16],char bothclamp[16],uint32_t width,uint32_t height,int32_t pitch)16 void aom_plane_add_noise_msa(uint8_t *start_ptr, char *noise,
17 char blackclamp[16], char whiteclamp[16],
18 char bothclamp[16], uint32_t width,
19 uint32_t height, int32_t pitch) {
20 uint32_t i, j;
21
22 for (i = 0; i < height / 2; ++i) {
23 uint8_t *pos0_ptr = start_ptr + (2 * i) * pitch;
24 int8_t *ref0_ptr = (int8_t *)(noise + (rand() & 0xff));
25 uint8_t *pos1_ptr = start_ptr + (2 * i + 1) * pitch;
26 int8_t *ref1_ptr = (int8_t *)(noise + (rand() & 0xff));
27 for (j = width / 16; j--;) {
28 v16i8 temp00_s, temp01_s;
29 v16u8 temp00, temp01, black_clamp, white_clamp;
30 v16u8 pos0, ref0, pos1, ref1;
31 v16i8 const127 = __msa_ldi_b(127);
32
33 pos0 = LD_UB(pos0_ptr);
34 ref0 = LD_UB(ref0_ptr);
35 pos1 = LD_UB(pos1_ptr);
36 ref1 = LD_UB(ref1_ptr);
37 black_clamp = (v16u8)__msa_fill_b(blackclamp[0]);
38 white_clamp = (v16u8)__msa_fill_b(whiteclamp[0]);
39 temp00 = (pos0 < black_clamp);
40 pos0 = __msa_bmnz_v(pos0, black_clamp, temp00);
41 temp01 = (pos1 < black_clamp);
42 pos1 = __msa_bmnz_v(pos1, black_clamp, temp01);
43 XORI_B2_128_UB(pos0, pos1);
44 temp00_s = __msa_adds_s_b((v16i8)white_clamp, const127);
45 temp00 = (v16u8)(temp00_s < pos0);
46 pos0 = (v16u8)__msa_bmnz_v((v16u8)pos0, (v16u8)temp00_s, temp00);
47 temp01_s = __msa_adds_s_b((v16i8)white_clamp, const127);
48 temp01 = (temp01_s < pos1);
49 pos1 = (v16u8)__msa_bmnz_v((v16u8)pos1, (v16u8)temp01_s, temp01);
50 XORI_B2_128_UB(pos0, pos1);
51 pos0 += ref0;
52 ST_UB(pos0, pos0_ptr);
53 pos1 += ref1;
54 ST_UB(pos1, pos1_ptr);
55 pos0_ptr += 16;
56 pos1_ptr += 16;
57 ref0_ptr += 16;
58 ref1_ptr += 16;
59 }
60 }
61 }
62