1/*
2 *  Copyright (c) 2015 The WebM project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <stdlib.h>
12#include "./macros_msa.h"
13
14void vpx_plane_add_noise_msa(uint8_t *start_ptr, const int8_t *noise,
15                             int blackclamp, int whiteclamp, int width,
16                             int height, int32_t pitch) {
17  int i, j;
18  v16u8 pos0, pos1, ref0, ref1;
19  v16i8 black_clamp, white_clamp, both_clamp;
20
21  black_clamp = __msa_fill_b(blackclamp);
22  white_clamp = __msa_fill_b(whiteclamp);
23  both_clamp = black_clamp + white_clamp;
24  both_clamp = -both_clamp;
25
26  for (i = 0; i < height / 2; ++i) {
27    uint8_t *pos0_ptr = start_ptr + (2 * i) * pitch;
28    const int8_t *ref0_ptr = noise + (rand() & 0xff);
29    uint8_t *pos1_ptr = start_ptr + (2 * i + 1) * pitch;
30    const int8_t *ref1_ptr = noise + (rand() & 0xff);
31    for (j = width / 16; j--;) {
32      pos0 = LD_UB(pos0_ptr);
33      ref0 = LD_UB(ref0_ptr);
34      pos1 = LD_UB(pos1_ptr);
35      ref1 = LD_UB(ref1_ptr);
36      pos0 = __msa_subsus_u_b(pos0, black_clamp);
37      pos1 = __msa_subsus_u_b(pos1, black_clamp);
38      pos0 = __msa_subsus_u_b(pos0, both_clamp);
39      pos1 = __msa_subsus_u_b(pos1, both_clamp);
40      pos0 = __msa_subsus_u_b(pos0, white_clamp);
41      pos1 = __msa_subsus_u_b(pos1, white_clamp);
42      pos0 += ref0;
43      ST_UB(pos0, pos0_ptr);
44      pos1 += ref1;
45      ST_UB(pos1, pos1_ptr);
46      pos0_ptr += 16;
47      pos1_ptr += 16;
48      ref0_ptr += 16;
49      ref1_ptr += 16;
50    }
51  }
52}
53