Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace for loops in QPL tests with std algorithms #6

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
******************************************************************************/
#include <array>
#include <algorithm>

#include "gtest/gtest.h"
#include "qpl_test_environment.hpp"
Expand Down Expand Up @@ -137,9 +138,7 @@ QPL_UNIT_API_ALGORITHMIC_TEST(qplc_bit_aggregates_8u, base) {

{
uint8_t* p_source_8u = (uint8_t*)source.data();
for (uint32_t indx = 0U; indx < TEST_BUFFER_SIZE; indx++) {
p_source_8u[indx] = 0U;
}
std::fill_n(p_source_8u, TEST_BUFFER_SIZE, 0U);
}

for (uint32_t length = 1U; length <= TEST_BUFFER_SIZE; length++) {
Expand Down Expand Up @@ -273,9 +272,7 @@ QPL_UNIT_API_ALGORITHMIC_TEST(qplc_aggregates_8u, base) {

{
uint8_t* p_source_8u = (uint8_t*)source.data();
for (uint32_t indx = 0U; indx < TEST_BUFFER_SIZE; indx++) {
p_source_8u[indx] = 0U;
}
std::fill_n(p_source_8u, TEST_BUFFER_SIZE, 0U);
}

for (uint32_t length = 1U; length <= TEST_BUFFER_SIZE; length++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
******************************************************************************/
#include <array>
#include <algorithm>

#include "gtest/gtest.h"

Expand Down Expand Up @@ -52,24 +53,16 @@ static inline qplc_slow_deflate_icf_body_t_ptr qplc_slow_deflate_icf_body() {

static void init_hash_table(void)
{
for (uint32_t indx = 0U; indx < D_SIZE_HASH_TABLE; indx++) {
hash_table[indx] = 0x80000000U;
}
for (uint32_t indx = 0U; indx < D_SIZE_HASH_STORE; indx++) {
hash_story[indx] = 0x00000000U;
}
std::fill_n(hash_table, D_SIZE_HASH_TABLE, 0x80000000U);
std::fill(std::begin(hash_story), std::end(hash_story), 0x00000000U);
}

static void init_histogram(isal_mod_hist *str_histogram_ptr)
{
uint32_t* d_hist = str_histogram_ptr->d_hist;
uint32_t* ll_hist = str_histogram_ptr->ll_hist;
for (uint32_t indx = 0U; indx < 0x1e; indx++) {
d_hist[indx] = 0U;
}
for (uint32_t indx = 0U; indx < 0x201; indx++) {
ll_hist[indx] = 0U;
}
std::fill_n(d_hist, 0x1e, 0U);
std::fill_n(ll_hist, 0x201, 0U);
}

static void init_deflate_icf(void)
Expand Down
46 changes: 13 additions & 33 deletions tools/tests/functional/unit_tests/algorithmic/core_expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
******************************************************************************/
#include <array>
#include <algorithm>

#include "gtest/gtest.h"
#include "qpl_test_environment.hpp"
Expand All @@ -24,22 +25,19 @@ qplc_expand_t_ptr qplc_expand(uint32_t index) {
static void fill_buffer_8u(uint8_t* src, uint8_t* dst, uint32_t length) {
uint8_t* p_src_8u = src;
uint8_t* p_dst_8u = dst;
for (uint32_t indx = 0U; indx < length; indx++)
p_dst_8u[indx] = p_src_8u[indx];
std::copy_n(p_src_8u, length, p_dst_8u);
}

static void fill_buffer_16u(uint8_t* src, uint8_t* dst, uint32_t length) {
uint16_t* p_src_16u = (uint16_t*)src;
uint16_t* p_dst_16u = (uint16_t*)dst;
for (uint32_t indx = 0U; indx < length; indx++)
p_dst_16u[indx] = p_src_16u[indx];
std::copy_n(p_src_16u, length, p_dst_16u);
}

static void fill_buffer_32u(uint8_t* src, uint8_t* dst, uint32_t length) {
uint32_t* p_src_32u = (uint32_t*)src;
uint32_t* p_dst_32u = (uint32_t*)dst;
for (uint32_t indx = 0U; indx < length; indx++)
p_dst_32u[indx] = p_src_32u[indx];
std::copy_n(p_src_32u, length, p_dst_32u);
}


Expand Down Expand Up @@ -156,9 +154,7 @@ QPL_UNIT_API_ALGORITHMIC_TEST(qplc_expand_8u, base) {

{
uint8_t* p_buffer_mask = (uint8_t*)mask.data();
for (uint32_t indx = 0U; indx < 16U; indx++) {
p_buffer_mask[indx] = 0U;
}
std::fill_n(p_buffer_mask, 16, 0U);
}

for (uint32_t length = 16U; length <= TEST_BUFFER_SIZE; length++) {
Expand Down Expand Up @@ -194,9 +190,7 @@ QPL_UNIT_API_ALGORITHMIC_TEST(qplc_expand_8u, base) {

{
uint8_t* p_buffer_mask = (uint8_t*)mask.data();
for (uint32_t indx = 0U; indx < 32U; indx++) {
p_buffer_mask[indx] = 0U;
}
std::fill_n(p_buffer_mask, 32, 0U);
}

for (uint32_t length = 33U; length <= TEST_BUFFER_SIZE; length++) {
Expand All @@ -215,9 +209,7 @@ QPL_UNIT_API_ALGORITHMIC_TEST(qplc_expand_8u, base) {

{
uint8_t* p_buffer_mask = (uint8_t*)mask.data();
for (uint32_t indx = 0U; indx < 32U; indx++) {
p_buffer_mask[indx] = 1U;
}
std::fill_n(p_buffer_mask, 32, 1U);
}

for (uint32_t length = 33U; length <= TEST_BUFFER_SIZE; length++) {
Expand Down Expand Up @@ -275,9 +267,7 @@ QPL_UNIT_API_ALGORITHMIC_TEST(qplc_expand_16u, base) {

{
uint8_t* p_buffer_mask = (uint8_t*)mask.data();
for (uint32_t indx = 0U; indx < 16U; indx++) {
p_buffer_mask[indx] = 0U;
}
std::fill_n(p_buffer_mask, 16, 0U);
}

for (uint32_t length = 16U; length <= TEST_BUFFER_SIZE; length++) {
Expand Down Expand Up @@ -313,9 +303,7 @@ QPL_UNIT_API_ALGORITHMIC_TEST(qplc_expand_16u, base) {

{
uint8_t* p_buffer_mask = (uint8_t*)mask.data();
for (uint32_t indx = 0U; indx < 32U; indx++) {
p_buffer_mask[indx] = 0U;
}
std::fill_n(p_buffer_mask, 32, 0U);
}

for (uint32_t length = 33U; length <= TEST_BUFFER_SIZE; length++) {
Expand All @@ -334,9 +322,7 @@ QPL_UNIT_API_ALGORITHMIC_TEST(qplc_expand_16u, base) {

{
uint8_t* p_buffer_mask = (uint8_t*)mask.data();
for (uint32_t indx = 0U; indx < 32U; indx++) {
p_buffer_mask[indx] = 1U;
}
std::fill_n(p_buffer_mask, 32, 1U);
}

for (uint32_t length = 33U; length <= TEST_BUFFER_SIZE; length++) {
Expand Down Expand Up @@ -393,9 +379,7 @@ QPL_UNIT_API_ALGORITHMIC_TEST(qplc_expand_32u, base) {

{
uint8_t* p_buffer_mask = (uint8_t*)mask.data();
for (uint32_t indx = 0U; indx < 16U; indx++) {
p_buffer_mask[indx] = 0U;
}
std::fill_n(p_buffer_mask, 16, 0U);
}

for (uint32_t length = 16U; length <= TEST_BUFFER_SIZE; length++) {
Expand Down Expand Up @@ -431,9 +415,7 @@ QPL_UNIT_API_ALGORITHMIC_TEST(qplc_expand_32u, base) {

{
uint8_t* p_buffer_mask = (uint8_t*)mask.data();
for (uint32_t indx = 0U; indx < 32U; indx++) {
p_buffer_mask[indx] = 0U;
}
std::fill_n(p_buffer_mask, 32, 0U);
}

for (uint32_t length = 33U; length <= TEST_BUFFER_SIZE; length++) {
Expand All @@ -452,9 +434,7 @@ QPL_UNIT_API_ALGORITHMIC_TEST(qplc_expand_32u, base) {

{
uint8_t* p_buffer_mask = (uint8_t*)mask.data();
for (uint32_t indx = 0U; indx < 32U; indx++) {
p_buffer_mask[indx] = 1U;
}
std::fill_n(p_buffer_mask, 32, 1U);
}

for (uint32_t length = 33U; length <= TEST_BUFFER_SIZE; length++) {
Expand Down
17 changes: 5 additions & 12 deletions tools/tests/functional/unit_tests/algorithmic/core_extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
******************************************************************************/
#include <array>
#include <algorithm>
#include <vector>
#include "gtest/gtest.h"

Expand All @@ -30,9 +31,7 @@ qplc_extract_i_t_ptr qplc_extract_i(uint32_t index) {
static void fill_buffer_8u(uint8_t* src, uint8_t* dst, uint32_t length) {
uint8_t* p_src_8u = src;
uint8_t* p_dst_8u = dst;
for (uint32_t indx = 0U; indx < length; indx++) {
p_dst_8u[indx] = p_src_8u[indx];
}
std::copy_n(p_src_8u, length, p_dst_8u);
}

static uint32_t ref_qplc_extract_8u(const uint8_t* src_ptr,
Expand All @@ -55,9 +54,7 @@ static uint32_t ref_qplc_extract_8u(const uint8_t* src_ptr,
const uint32_t stop = ((*index_ptr + length) > high_value) ? (high_value + 1U - *index_ptr) : length;

src_ptr += start;
for (uint32_t idx = 0U; idx < (stop - start); idx++) {
dst_ptr[idx] = src_ptr[idx];
}
std::copy_n(src_ptr, stop - start, dst_ptr);
*index_ptr += length;
return (stop - start);
}
Expand All @@ -84,9 +81,7 @@ static uint32_t ref_qplc_extract_16u(const uint8_t* src_ptr,
const uint32_t stop = ((*index_ptr + length) > high_value) ? (high_value + 1U - *index_ptr) : length;

src_16u_ptr += start;
for (uint32_t idx = 0U; idx < (stop - start); idx++) {
dst_16u_ptr[idx] = src_16u_ptr[idx];
}
std::copy_n(src_16u_ptr, stop - start, dst_16u_ptr);
*index_ptr += length;
return (stop - start);
}
Expand All @@ -113,9 +108,7 @@ static uint32_t ref_qplc_extract_32u(const uint8_t* src_ptr,
const uint32_t stop = ((*index_ptr + length) > high_value) ? (high_value + 1U - *index_ptr) : length;

src_32u_ptr += start;
for (uint32_t idx = 0U; idx < (stop - start); idx++) {
dst_32u_ptr[idx] = src_32u_ptr[idx];
}
std::copy_n(src_32u_ptr, stop - start, dst_32u_ptr);
*index_ptr += length;
return (stop - start);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ static void fill_src_buffer_16u(uint8_t* src, uint8_t* dst, size_t length, uint3
uint16_t *p_src_16u = (uint16_t*)src;
uint16_t *p_dst_16u = (uint16_t*)dst;
const uint16_t mask = (1U << nbits) - 1U;
for (uint32_t indx = 0; indx < length; indx++)
p_dst_16u[indx] = p_src_16u[indx] & mask;
std::transform(p_src_16u, p_src_16u + length, p_dst_16u,
[mask](auto x) { return x & mask; });
}

constexpr uint32_t TEST_BUFFER_SIZE = 64U;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
******************************************************************************/
#include <array>
#include <algorithm>

#include "gtest/gtest.h"
#include "qpl_test_environment.hpp"
Expand Down Expand Up @@ -164,8 +165,8 @@ static void fill_src_buffer_32u(uint8_t* src, uint8_t* dst, size_t length, uint3
uint32_t *p_src_32u = (uint32_t*)src;
uint32_t *p_dst_32u = (uint32_t*)dst;
const uint32_t mask = (1U << nbits) - 1U;
for (uint32_t indx = 0U; indx < length; indx++)
p_dst_32u[indx] = p_src_32u[indx] & mask;
std::transform(p_src_32u, p_src_32u + length, p_dst_32u,
[mask](auto x) { return x & mask; });
}

constexpr uint32_t TEST_BUFFER_SIZE = 64U;
Expand Down
5 changes: 2 additions & 3 deletions tools/tests/functional/unit_tests/algorithmic/core_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
******************************************************************************/
#include <array>
#include <algorithm>

#include "gtest/gtest.h"
#include "qpl_test_environment.hpp"
Expand All @@ -28,9 +29,7 @@ qplc_select_i_t_ptr qplc_select_i(uint32_t index) {
static void fill_buffer_8u(uint8_t* src, uint8_t* dst, uint32_t length) {
uint8_t* p_src_8u = src;
uint8_t* p_dst_8u = dst;
for (uint32_t indx = 0U; indx < length; indx++) {
p_dst_8u[indx] = p_src_8u[indx];
}
std::copy_n(p_src_8u, length, p_dst_8u);
}

static uint32_t ref_qplc_select_8u(const uint8_t* src_ptr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
******************************************************************************/
#include <array>
#include <algorithm>

#include "gtest/gtest.h"
#include "qpl_test_environment.hpp"
Expand All @@ -30,17 +31,15 @@ static void fill_src_buffer_16u(uint8_t* src, uint8_t* dst, uint32_t length, uin
uint16_t* p_src_16u = (uint16_t*)src;
uint16_t* p_dst_16u = (uint16_t*)dst;
const uint16_t mask = (1U << nbits) - 1U;
for (uint32_t indx = 0; indx < length; indx++) {
p_dst_16u[indx] = p_src_16u[indx] & mask;
}
std::transform(p_src_16u, p_src_16u + length,
p_dst_16u,
[&mask](auto x) { return x & mask; });
}

static void fill_reference_buffer_16u(uint8_t* src, uint8_t* dst, uint32_t length) {
uint16_t* p_src_16u = (uint16_t*)src;
uint16_t* p_dst_16u = (uint16_t*)dst;
for (uint32_t indx = 0; indx < length; indx++) {
p_dst_16u[indx] = p_src_16u[indx];
}
std::copy_n(p_src_16u, length, p_dst_16u);
}

constexpr uint32_t TEST_BUFFER_SIZE = 64U;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
******************************************************************************/
#include <array>
#include <algorithm>

#include "gtest/gtest.h"
#include "qpl_test_environment.hpp"
Expand All @@ -30,17 +31,14 @@ static void fill_src_buffer_32u(uint8_t* src, uint8_t* dst, uint32_t length, uin
uint32_t* p_src_32u = (uint32_t*)src;
uint32_t* p_dst_32u = (uint32_t*)dst;
const uint32_t mask = (1U << nbits) - 1U;
for (uint32_t indx = 0; indx < length; indx++) {
p_dst_32u[indx] = p_src_32u[indx] & mask;
}
std::transform(p_src_32u, p_src_32u + length, p_dst_32u,
[mask](auto x) { return x & mask; });
}

static void fill_reference_buffer_32u(uint8_t* src, uint8_t* dst, uint32_t length) {
uint32_t* p_src_32u = (uint32_t*)src;
uint32_t* p_dst_32u = (uint32_t*)dst;
for (uint32_t indx = 0; indx < length; indx++) {
p_dst_32u[indx] = p_src_32u[indx];
}
std::copy_n(p_src_32u, length, p_dst_32u);
}

constexpr uint32_t TEST_BUFFER_SIZE = 64U;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
******************************************************************************/
#include <array>
#include <algorithm>

#include "gtest/gtest.h"
#include "qpl_test_environment.hpp"
Expand All @@ -30,17 +31,13 @@ static void fill_src_buffer_16u(uint8_t* src, uint8_t* dst, uint32_t length, uin
uint16_t* p_src_16u = (uint16_t*)src;
uint16_t* p_dst_16u = (uint16_t*)dst;
const uint16_t mask = (1U << nbits) - 1U;
for (uint32_t indx = 0; indx < length; indx++) {
p_dst_16u[indx] = p_src_16u[indx] & mask;
}
std::transform(p_src_16u, p_src_16u + length, p_dst_16u, [&mask](auto x) { return x & mask; });
}

static void fill_reference_buffer_16u(uint8_t* src, uint8_t* dst, uint32_t length) {
uint16_t* p_src_16u = (uint16_t*)src;
uint16_t* p_dst_16u = (uint16_t*)dst;
for (uint32_t indx = 0; indx < length; indx++) {
p_dst_16u[indx] = p_src_16u[indx];
}
std::copy(p_src_16u, p_src_16u + length, p_dst_16u);
}

constexpr uint32_t TEST_BUFFER_SIZE = 64U;
Expand Down
Loading