<commit_before>/*
 * Copyright © 2018, VideoLAN and dav1d authors
 * Copyright © 2018, Two Orioles, LLC
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "config.h"

#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>

#include "common/attributes.h"
#include "common/intops.h"

#include "src/itx.h"

#include "src/itx_1d.c"

typedef void (*itx_1d_fn)(const coef *in, ptrdiff_t in_s,
                          coef *out, ptrdiff_t out_s, const int range);

static void NOINLINE
inv_txfm_add_c(pixel *dst, const ptrdiff_t stride,
               coef *const coeff, const int eob,
               const int w, const int h, const int shift1, const int shift2,
               const itx_1d_fn first_1d_fn, const itx_1d_fn second_1d_fn
               HIGHBD_DECL_SUFFIX)
{
    int i, j;
    const ptrdiff_t sh = imin(h, 32), sw = imin(w, 32);
    assert((h >= 4 || h <= 64) && (w >= 4 || w <= 64));
    // Maximum value for h and w is 64
    coef tmp[4096 /* w * h */], out[64 /* h */], in_mem[64 /* w */];
    const int is_rect2 = w * 2 == h || h * 2 == w;
    const int bitdepth = bitdepth_from_max(bitdepth_max);
    const int row_clip_max = (1 << (bitdepth + 8 - 1)) - 1;
    const int col_clip_max = (1 << (imax(bitdepth + 6, 16) - 1)) -1;
    const int col_clip_min = -col_clip_max - 1;

    if (w != sw) memset(&in_mem[sw], 0, (w - sw) * sizeof(*in_mem));
    const int rnd1 = (1 << shift1) >> 1;
    for (i = 0; i < sh; i++) {
        if (w != sw || is_rect2) {
            for (j = 0; j < sw; j++) {
                in_mem[j] = coeff[i + j * sh];
                if (is_rect2)
                    in_mem[j] = (in_mem[j] * 2896 + 2048) >> 12;
            }
            first_1d_fn(in_mem, 1, &tmp[i * w], 1, row_clip_max);
        } else {
            first_1d_fn(&coeff[i], sh, &tmp[i * w], 1, row_clip_max);
        }
        for (j = 0; j < w; j++)
            tmp[i * w + j] = iclip((tmp[i * w + j] + (rnd1)) >> shift1,
                                   col_clip_min, col_clip_max);
    }

    if (h != sh) memset(&tmp[sh * w], 0, w * (h - sh) * sizeof(*tmp));
    const int rnd2 = (1 << shift2) >> 1;
    for (i = 0; i < w; i++) {
        second_1d_fn(&tmp[i], w, out, 1, col_clip_max);
        for (j = 0; j < h; j++)
            dst[i + j * PXSTRIDE(stride)] =
                iclip_pixel(dst[i + j * PXSTRIDE(stride)] +
                            ((out[j] + (rnd2)) >> shift2));
    }
    memset(coeff, 0, sizeof(*coeff) * sh * sw);
}<commit_msg>Avoid a redundant clip in 8-bit itx<commit_after>/*
 * Copyright © 2018, VideoLAN and dav1d authors
 * Copyright © 2018, Two Orioles, LLC
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "config.h"

#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>

#include "common/attributes.h"
#include "common/intops.h"

#include "src/itx.h"

#include "src/itx_1d.c"

typedef void (*itx_1d_fn)(const coef *in, ptrdiff_t in_s,
                          coef *out, ptrdiff_t out_s, const int range);

static void NOINLINE
inv_txfm_add_c(pixel *dst, const ptrdiff_t stride,
               coef *const coeff, const int eob,
               const int w, const int h, const int shift1, const int shift2,
               const itx_1d_fn first_1d_fn, const itx_1d_fn second_1d_fn
               HIGHBD_DECL_SUFFIX)
{
    int i, j;
    const ptrdiff_t sh = imin(h, 32), sw = imin(w, 32);
    assert((h >= 4 || h <= 64) && (w >= 4 || w <= 64));
    // Maximum value for h and w is 64
    coef tmp[4096 /* w * h */], out[64 /* h */], in_mem[64 /* w */];
    const int is_rect2 = w * 2 == h || h * 2 == w;
    const int bitdepth = bitdepth_from_max(bitdepth_max);
    const int row_clip_max = (1 << (bitdepth + 8 - 1)) - 1;
    const int col_clip_max = (1 << (imax(bitdepth + 6, 16) - 1)) -1;

    if (w != sw) memset(&in_mem[sw], 0, (w - sw) * sizeof(*in_mem));
    const int rnd1 = (1 << shift1) >> 1;
    for (i = 0; i < sh; i++) {
        if (w != sw || is_rect2) {
            for (j = 0; j < sw; j++) {
                in_mem[j] = coeff[i + j * sh];
                if (is_rect2)
                    in_mem[j] = (in_mem[j] * 2896 + 2048) >> 12;
            }
            first_1d_fn(in_mem, 1, &tmp[i * w], 1, row_clip_max);
        } else {
            first_1d_fn(&coeff[i], sh, &tmp[i * w], 1, row_clip_max);
        }
        for (j = 0; j < w; j++)
#if BITDEPTH == 8
            tmp[i * w + j] = (tmp[i * w + j] + (rnd1)) >> shift1;
#else
            tmp[i * w + j] = iclip((tmp[i * w + j] + (rnd1)) >> shift1,
                                   -col_clip_max - 1, col_clip_max);
#endif
    }

    if (h != sh) memset(&tmp[sh * w], 0, w * (h - sh) * sizeof(*tmp));
    const int rnd2 = (1 << shift2) >> 1;
    for (i = 0; i < w; i++) {
        second_1d_fn(&tmp[i], w, out, 1, col_clip_max);
        for (j = 0; j < h; j++)
            dst[i + j * PXSTRIDE(stride)] =
                iclip_pixel(dst[i + j * PXSTRIDE(stride)] +
                            ((out[j] + (rnd2)) >> shift2));
    }
    memset(coeff, 0, sizeof(*coeff) * sh * sw);
}
{'fraction_non_alphanumeric': 0.12549173878835562, 'fraction_numerical': 0.024652504589562026, 'mean_word_length': 2.5050551470588234, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '56116', 'n_tokens_mistral': 2758, 'n_tokens_neox': 2517, 'n_words': 923}