<commit_before>// Copyright 2017 - , Dr.-Ing. <NAME>
// SPDX-License-Identifier: BSD-2-Clause

#include "kernel_sse.h"

inline __attribute__((always_inline)) void kernel_sse_std( stack_t * data, __m128 s_two, __m128 s_sixteen, __m128 s_sixty  )
{
    __m128 s_ppf_aligned, s_vel_aligned, s_actual, s_above1, s_left1, s_under1, s_right1, s_sum;
    __m128 s_above2, s_under2, s_left2, s_right2;
    
    float min1f[4] = { -1, -1, -1, -1 };
    __m128 min1v = _mm_loadu_ps( min1f );
    __m128 min_sixty_v = _mm_mul_ps( s_sixty, min1v );

    unsigned i, j;
    // spatial loop in x
    for (i=data->x_start; i<data->x_end; i++) {
        // spatial loop in y
        for (j=data->y_start; j<data->y_end; j+=data->y_offset) {
            unsigned r = i * data->height + j;
            unsigned r_min1 = r - data->height;
            unsigned r_min2 = r - (data->height << 1);
            unsigned r_plus1 = r + data->height;
            unsigned r_plus2 = r + (data->height << 1);

            // calculates the pressure field t+1
            s_ppf_aligned = _mm_load_ps( &(data->nppf[ r ]) ); // align it to get _load_ps
            s_vel_aligned = _mm_load_ps( &(data->vel[ r ]) );
            s_actual = _mm_load_ps( &(data->apf[ r ]) );

            s_left1 = _mm_load_ps( &(data->apf[r_min1]) );
            s_left2 = _mm_load_ps( &(data->apf[r_min2]) );
            s_right2 = _mm_load_ps( &(data->apf[r_plus2]) );
            s_right1 = _mm_load_ps( &(data->apf[r_plus1]) );
            s_above1 = _mm_loadu_ps( &(data->apf[ r -1]) );
            s_under1 = _mm_loadu_ps( &(data->apf[ r +1]) );

            s_above2 = _mm_loadl_pi( _mm_shuffle_ps(s_actual, s_actual, _MM_SHUFFLE(1, 0, 0, 0)),
                                     (__m64 const*)&(data->apf[ r -2]));

            s_under2 = _mm_loadh_pi( _mm_shuffle_ps(s_actual, s_actual, _MM_SHUFFLE(0, 0, 3, 2)),
                                     (__m64 const*)&(data->apf[ r +4]));

            s_sum = _mm_add_ps( _mm_sub_ps( _mm_mul_ps( s_two,
                                                        s_actual ),
                                            s_ppf_aligned ),
                                _mm_mul_ps( s_vel_aligned,
                                            _mm_sub_ps( _mm_add_ps( _mm_mul_ps( min_sixty_v,
                                                                                s_actual ),
                                                                    _mm_mul_ps( s_sixteen,
                                                                                _mm_add_ps( _mm_add_ps( _mm_add_ps( s_above1,
                                                                                                                    s_under1 ),
                                                                                                        s_left1 ),
                                                                                            s_right1 ) ) ),
                                                        _mm_add_ps( _mm_add_ps( _mm_add_ps( s_above2,
                                                                                            s_under2 ),
                                                                                s_left2 ),
                                                                    s_right2 ) ) ) );

            _mm_store_ps( &(data->nppf[ r ]), s_sum);
        }
    }
}
<commit_msg>1 vector and 2 scalar loads less for sse_std<commit_after>// Copyright 2017 - , Dr.-Ing. <NAME>
// SPDX-License-Identifier: BSD-2-Clause

#include "kernel_sse.h"

inline __attribute__((always_inline)) void kernel_sse_std( stack_t * data, __m128 s_two, __m128 s_sixteen, __m128 s_sixty  )
{
    __m128 s_ppf_aligned, s_vel_aligned, s_actual, s_above1, s_left1, s_under1, s_right1, s_sum;
    __m128 s_above2, s_under2, s_left2, s_right2;
    
    float min1f[4] = { -1, -1, -1, -1 };
    __m128 min1v = _mm_loadu_ps( min1f );
    __m128 min_sixty_v = _mm_mul_ps( s_sixty, min1v );

    unsigned i, j;
    // spatial loop in x
    for (i=data->x_start; i<data->x_end; i++) {
        // spatial loop in y
        for (j=data->y_start; j<data->y_end; j+=data->y_offset) {
            unsigned r = i * data->height + j;
            unsigned r_min1 = r - data->height;
            unsigned r_min2 = r - (data->height << 1);
            unsigned r_plus1 = r + data->height;
            unsigned r_plus2 = r + (data->height << 1);

            // calculates the pressure field t+1
            s_ppf_aligned = _mm_load_ps( &(data->nppf[ r ]) ); // align it to get _load_ps
            s_vel_aligned = _mm_load_ps( &(data->vel[ r ]) );

            s_above2 = _mm_loadu_ps( &(data->apf[ r - 2]) );
            s_under2 = _mm_loadu_ps( &(data->apf[ r + 2]) );
            s_left1 = _mm_load_ps( &(data->apf[r_min1]) );
            s_left2 = _mm_load_ps( &(data->apf[r_min2]) );
            s_right2 = _mm_load_ps( &(data->apf[r_plus2]) );
            s_right1 = _mm_load_ps( &(data->apf[r_plus1]) );

//           |0 1 2 3|4 5 6 7|
//               |2 3 4 5|
            s_actual = _mm_shuffle_ps( s_above2, s_under2, _MM_SHUFFLE( 1, 0, 3, 2 ) );

//           |0 1 2 3|4 5 6 7|
//               |2 3 4 5|
//             |1 2 3 4|
            s_above1 = _mm_shuffle_ps( s_above2, s_actual, _MM_SHUFFLE( 2, 1, 2, 1 ) );

//           |0 1 2 3|4 5 6 7|
//               |2 3 4 5|
//                 |3 4 5 6|
            s_under1 = _mm_shuffle_ps( s_actual, s_under2, _MM_SHUFFLE( 2, 1, 2, 1 ) );

            s_sum = _mm_add_ps( _mm_sub_ps( _mm_mul_ps( s_two,
                                                        s_actual ),
                                            s_ppf_aligned ),
                                _mm_mul_ps( s_vel_aligned,
                                            _mm_sub_ps( _mm_add_ps( _mm_mul_ps( min_sixty_v,
                                                                                s_actual ),
                                                                    _mm_mul_ps( s_sixteen,
                                                                                _mm_add_ps( _mm_add_ps( _mm_add_ps( s_above1,
                                                                                                                    s_under1 ),
                                                                                                        s_left1 ),
                                                                                            s_right1 ) ) ),
                                                        _mm_add_ps( _mm_add_ps( _mm_add_ps( s_above2,
                                                                                            s_under2 ),
                                                                                s_left2 ),
                                                                    s_right2 ) ) ) );

            _mm_store_ps( &(data->nppf[ r ]), s_sum);
        }
    }
}

{'fraction_non_alphanumeric': 0.10153669395375557, 'fraction_numerical': 0.0315955766192733, 'mean_word_length': 0.9795338260375214, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 78, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4003291', 'n_tokens_mistral': 2218, 'n_tokens_neox': 2102, 'n_words': 436}