From 22f3afe4dd76700bce9e26e140d00930add34f95 Mon Sep 17 00:00:00 2001 From: "d.levin256@gmail.com" Date: Wed, 11 Oct 2023 22:28:37 +0100 Subject: [PATCH] Warning-free build on MSVC --- include/kfr/base/basic_expressions.hpp | 2 +- include/kfr/base/reduce.hpp | 2 +- include/kfr/base/shape.hpp | 4 ++-- include/kfr/cometa.hpp | 4 ++-- include/kfr/dsp/ebu.hpp | 2 +- include/kfr/dsp/fir.hpp | 5 +++++ include/kfr/graphics/color.hpp | 5 +++++ include/kfr/io/python_plot.hpp | 2 +- include/kfr/math/impl/gamma.hpp | 6 +++--- include/kfr/simd/impl/backend_generic.hpp | 4 +--- include/kfr/simd/operators.hpp | 5 +++++ include/kfr/simd/shuffle.hpp | 3 ++- include/kfr/simd/vec.hpp | 1 + tests/unit/base/tensor.cpp | 1 + tests/unit/dsp/biquad.cpp | 5 +++++ tests/unit/dsp/ebu.cpp | 5 +++++ tests/unit/simd/abs.cpp | 5 +++++ tests/unit/simd/min_max.cpp | 6 ++++++ tests/unit/simd/operators.cpp | 6 ++++++ tools/sample_rate_converter.cpp | 2 +- 20 files changed, 59 insertions(+), 16 deletions(-) diff --git a/include/kfr/base/basic_expressions.hpp b/include/kfr/base/basic_expressions.hpp index 5b8d41f7..1634b288 100644 --- a/include/kfr/base/basic_expressions.hpp +++ b/include/kfr/base/basic_expressions.hpp @@ -699,7 +699,7 @@ struct expression_linspace T invsize; expression_linspace(T start, T stop, size_t size, bool endpoint = false) - : start(start), stop(stop), size(size), invsize(1.0 / T(endpoint ? size - 1 : size)) + : start(start), stop(stop), size(size), invsize(T(1.0) / T(endpoint ? size - 1 : size)) { } diff --git a/include/kfr/base/reduce.hpp b/include/kfr/base/reduce.hpp index bdf9856f..4de6c26e 100644 --- a/include/kfr/base/reduce.hpp +++ b/include/kfr/base/reduce.hpp @@ -184,7 +184,7 @@ struct histogram_data KFR_MEM_INTRINSIC void put(T value) { const T x = 1 + value * size(); - ++m_values[std::floor(clamp(x, 0, size() + 1))]; + ++m_values[static_cast(std::floor(clamp(x, 0, size() + 1)))]; } private: diff --git a/include/kfr/base/shape.hpp b/include/kfr/base/shape.hpp index 2e6215aa..0bc6a0f3 100644 --- a/include/kfr/base/shape.hpp +++ b/include/kfr/base/shape.hpp @@ -662,7 +662,7 @@ KFR_INTRINSIC bool compare_indices(const shape& indices, const shape index_t dim = dims - 1) { CMT_LOOP_UNROLL - for (int i = dim; i >= 0; --i) + for (int i = static_cast(dim); i >= 0; --i) { if (CMT_UNLIKELY(indices[i] >= stop[i])) return false; @@ -685,7 +685,7 @@ KFR_INTRINSIC bool increment_indices(shape& indices, const shape& st { indices[dim] += 1; CMT_LOOP_UNROLL - for (int i = dim; i >= 0;) + for (int i = static_cast(dim); i >= 0;) { if (CMT_LIKELY(indices[i] < stop[i])) return true; diff --git a/include/kfr/cometa.hpp b/include/kfr/cometa.hpp index 2da5391f..a3d1ed81 100644 --- a/include/kfr/cometa.hpp +++ b/include/kfr/cometa.hpp @@ -747,11 +747,11 @@ struct cvalseq_impl : cvals_t { }; template -struct cvalseq_impl : cvals_t(Nstart)> +struct cvalseq_impl : cvals_t { }; template -struct cvalseq_impl : cvals_t(Nstart), static_cast(Nstart + Nstep)> +struct cvalseq_impl : cvals_t(Nstart + Nstep)> { }; diff --git a/include/kfr/dsp/ebu.hpp b/include/kfr/dsp/ebu.hpp index 948156d7..dbb4991f 100644 --- a/include/kfr/dsp/ebu.hpp +++ b/include/kfr/dsp/ebu.hpp @@ -216,7 +216,7 @@ struct ebu_channel break; case Speaker::LeftSurround: case Speaker::RightSurround: - m_output_energy_gain = dB_to_power(+1.5); + m_output_energy_gain = static_cast(dB_to_power(+1.5)); break; default: break; diff --git a/include/kfr/dsp/fir.hpp b/include/kfr/dsp/fir.hpp index 6751fe38..7c3c4c02 100644 --- a/include/kfr/dsp/fir.hpp +++ b/include/kfr/dsp/fir.hpp @@ -34,6 +34,9 @@ #include "../base/univector.hpp" #include "../simd/vec.hpp" +CMT_PRAGMA_MSVC(warning(push)) +CMT_PRAGMA_MSVC(warning(disable : 4244)) + namespace kfr { inline namespace CMT_ARCH_NAME @@ -323,3 +326,5 @@ KFR_FUNCTION filter* make_fir_filter(cpu_t cpu, const univector_ref& } #endif } // namespace kfr + +CMT_PRAGMA_MSVC(warning(pop)) diff --git a/include/kfr/graphics/color.hpp b/include/kfr/graphics/color.hpp index 83a00da5..34b81dac 100644 --- a/include/kfr/graphics/color.hpp +++ b/include/kfr/graphics/color.hpp @@ -27,6 +27,9 @@ #include "impl/scaled.hpp" +CMT_PRAGMA_MSVC(warning(push)) +CMT_PRAGMA_MSVC(warning(disable : 4244)) + namespace kfr { @@ -405,3 +408,5 @@ struct representation> } }; } // namespace cometa + +CMT_PRAGMA_MSVC(warning(pop)) diff --git a/include/kfr/io/python_plot.hpp b/include/kfr/io/python_plot.hpp index bc8ccbf7..5d1335af 100644 --- a/include/kfr/io/python_plot.hpp +++ b/include/kfr/io/python_plot.hpp @@ -50,7 +50,7 @@ void python(const std::string& name, const std::string& code) std::string filename; { char curdir[1024]; - (void)cross_getcwd(curdir, arraysize(curdir)); + (void)cross_getcwd(curdir, (int)arraysize(curdir)); filename = curdir; } #ifdef CMT_OS_WIN diff --git a/include/kfr/math/impl/gamma.hpp b/include/kfr/math/impl/gamma.hpp index b9bade1d..53220a88 100644 --- a/include/kfr/math/impl/gamma.hpp +++ b/include/kfr/math/impl/gamma.hpp @@ -38,9 +38,9 @@ namespace intrinsics { template constexpr T gamma_precalc[] = { - 0x2.81b263fec4e08p+0, 0x3.07b4100e04448p+16, -0xa.a0da01d4d4e2p+16, 0xf.05ccb27bb9dbp+16, - -0xa.fa79616b7c6ep+16, 0x4.6dd6c10d4df5p+16, -0xf.a2304199eb4ap+12, 0x1.c21dd4aade3dp+12, - -0x1.62f981f01cf84p+8, 0x5.a937aa5c48d98p+0, -0x3.c640bf82e2104p-8, 0xc.914c540f959cp-24, + T(0x2.81b263fec4e08p+0), T(0x3.07b4100e04448p+16), T(-0xa.a0da01d4d4e2p+16), T(0xf.05ccb27bb9dbp+16), + T(-0xa.fa79616b7c6ep+16), T(0x4.6dd6c10d4df5p+16), T(-0xf.a2304199eb4ap+12), T(0x1.c21dd4aade3dp+12), + T(-0x1.62f981f01cf84p+8), T(0x5.a937aa5c48d98p+0), T(-0x3.c640bf82e2104p-8), T(0xc.914c540f959cp-24), }; template diff --git a/include/kfr/simd/impl/backend_generic.hpp b/include/kfr/simd/impl/backend_generic.hpp index 0ced9cde..5598de3d 100644 --- a/include/kfr/simd/impl/backend_generic.hpp +++ b/include/kfr/simd/impl/backend_generic.hpp @@ -1549,7 +1549,7 @@ KFR_INTRINSIC simd simd_vec_shuffle(simd_t, const simd KFR_INTRINSIC constexpr uint8_t vec_idx(size_t value) { - return value >= max ? 0 : value; + return value >= static_cast(max) ? 0 : static_cast(value); } #ifdef CMT_ARCH_AVX512 @@ -1827,8 +1827,6 @@ KFR_INTRINSIC simd universal_shuffle(simd_t, const simd { using Indices = csizes_t; - constexpr bool floating = typeclass == datatype::f; - constexpr size_t minwidth = minimum_vector_width; constexpr size_t maxwidth = vector_width; constexpr size_t minindex = cminof(Indices{}); diff --git a/include/kfr/simd/operators.hpp b/include/kfr/simd/operators.hpp index 98ff7581..1b68a0c2 100644 --- a/include/kfr/simd/operators.hpp +++ b/include/kfr/simd/operators.hpp @@ -30,6 +30,9 @@ #include #include +CMT_PRAGMA_MSVC(warning(push)) +CMT_PRAGMA_MSVC(warning(disable : 4244)) + namespace kfr { inline namespace CMT_ARCH_NAME @@ -659,3 +662,5 @@ KFR_I_CE vec, N>::vec(const base& v) CMT_NOEXCEPT } // namespace CMT_ARCH_NAME } // namespace kfr + +CMT_PRAGMA_MSVC(warning(pop)) diff --git a/include/kfr/simd/shuffle.hpp b/include/kfr/simd/shuffle.hpp index 69d13b0e..d0b48f16 100644 --- a/include/kfr/simd/shuffle.hpp +++ b/include/kfr/simd/shuffle.hpp @@ -34,6 +34,7 @@ CMT_PRAGMA_MSVC(warning(push)) CMT_PRAGMA_MSVC(warning(disable : 5051)) +CMT_PRAGMA_MSVC(warning(disable : 4244)) namespace kfr { @@ -244,7 +245,7 @@ KFR_INTRINSIC vec concat_and_slice(const vec& x, const vec KFR_INTRINSIC vec concat_and_slice(const vec& x, const vec& y) { - return x.shuffle(csizeseq) + return x.shuffle(csizeseq) .shuffle(y, csizeseq) .shuffle(csizeseq); } diff --git a/include/kfr/simd/vec.hpp b/include/kfr/simd/vec.hpp index 77afe57d..a91c5c8e 100644 --- a/include/kfr/simd/vec.hpp +++ b/include/kfr/simd/vec.hpp @@ -85,6 +85,7 @@ CMT_PRAGMA_GNU(GCC diagnostic ignored "-Wpacked") CMT_PRAGMA_MSVC(warning(push)) CMT_PRAGMA_MSVC(warning(disable : 4814)) +CMT_PRAGMA_MSVC(warning(disable : 4244)) namespace kfr { diff --git a/tests/unit/base/tensor.cpp b/tests/unit/base/tensor.cpp index 2239ebc1..93d2c4fb 100644 --- a/tests/unit/base/tensor.cpp +++ b/tests/unit/base/tensor.cpp @@ -14,6 +14,7 @@ CMT_PRAGMA_MSVC(warning(push)) CMT_PRAGMA_MSVC(warning(disable : 5051)) +CMT_PRAGMA_MSVC(warning(disable : 4244)) namespace kfr { diff --git a/tests/unit/dsp/biquad.cpp b/tests/unit/dsp/biquad.cpp index d9960093..990f2187 100644 --- a/tests/unit/dsp/biquad.cpp +++ b/tests/unit/dsp/biquad.cpp @@ -11,6 +11,9 @@ #include #include +CMT_PRAGMA_MSVC(warning(push)) +CMT_PRAGMA_MSVC(warning(disable : 4305)) + namespace kfr { inline namespace CMT_ARCH_NAME @@ -111,3 +114,5 @@ TEST(biquad_lowpass2) } } // namespace CMT_ARCH_NAME } // namespace kfr + +CMT_PRAGMA_MSVC(warning(pop)) diff --git a/tests/unit/dsp/ebu.cpp b/tests/unit/dsp/ebu.cpp index 1122f9cc..57403b9c 100644 --- a/tests/unit/dsp/ebu.cpp +++ b/tests/unit/dsp/ebu.cpp @@ -7,6 +7,9 @@ #include #include +CMT_PRAGMA_MSVC(warning(push)) +CMT_PRAGMA_MSVC(warning(disable : 4244)) + namespace kfr { inline namespace CMT_ARCH_NAME @@ -268,3 +271,5 @@ TEST(ebu_lra_1_2_3_and_4) } // namespace CMT_ARCH_NAME } // namespace kfr + +CMT_PRAGMA_MSVC(warning(pop)) diff --git a/tests/unit/simd/abs.cpp b/tests/unit/simd/abs.cpp index 615184ec..eea07af3 100644 --- a/tests/unit/simd/abs.cpp +++ b/tests/unit/simd/abs.cpp @@ -8,6 +8,9 @@ #include +CMT_PRAGMA_MSVC(warning(push)) +CMT_PRAGMA_MSVC(warning(disable : 4146)) + namespace kfr { inline namespace CMT_ARCH_NAME @@ -20,3 +23,5 @@ TEST(abs) } } // namespace CMT_ARCH_NAME } // namespace kfr + +CMT_PRAGMA_MSVC(warning(pop)) diff --git a/tests/unit/simd/min_max.cpp b/tests/unit/simd/min_max.cpp index cb3af67e..01212b8a 100644 --- a/tests/unit/simd/min_max.cpp +++ b/tests/unit/simd/min_max.cpp @@ -8,6 +8,9 @@ #include +CMT_PRAGMA_MSVC(warning(push)) +CMT_PRAGMA_MSVC(warning(disable : 4146)) + namespace kfr { inline namespace CMT_ARCH_NAME @@ -68,3 +71,6 @@ TEST(absmax) } } // namespace CMT_ARCH_NAME } // namespace kfr + + +CMT_PRAGMA_MSVC(warning(pop)) diff --git a/tests/unit/simd/operators.cpp b/tests/unit/simd/operators.cpp index 36000258..6e6fe7bf 100644 --- a/tests/unit/simd/operators.cpp +++ b/tests/unit/simd/operators.cpp @@ -8,6 +8,9 @@ #include #include +CMT_PRAGMA_MSVC(warning(push)) +CMT_PRAGMA_MSVC(warning(disable : 4146)) + namespace kfr { inline namespace CMT_ARCH_NAME @@ -268,3 +271,6 @@ TEST(apply) } } // namespace CMT_ARCH_NAME } // namespace kfr + + +CMT_PRAGMA_MSVC(warning(pop)) diff --git a/tools/sample_rate_converter.cpp b/tools/sample_rate_converter.cpp index 7dac2be1..5b003bdc 100644 --- a/tools/sample_rate_converter.cpp +++ b/tools/sample_rate_converter.cpp @@ -28,7 +28,7 @@ int main(int argc, char** argv) // Initialize WAV reader and get file sample rate audio_reader_wav reader(open_file_for_reading(argv[1])); - const size_t input_sr = reader.format().samplerate; + const size_t input_sr = static_cast(reader.format().samplerate); // Read channels of audio univector2d input_channels = reader.read_channels(reader.format().length);