From bc67f1764ce4c17a269af3dc7de2aa30e333287d Mon Sep 17 00:00:00 2001 From: Tom Kneiphof Date: Thu, 7 Mar 2024 17:48:46 +0100 Subject: [PATCH] Fix sign-compare warnings --- glm/gtc/bitfield.inl | 2 +- test/core/core_func_integer_bit_count.cpp | 22 +++++++++--------- test/core/core_func_integer_find_lsb.cpp | 28 +++++++++++------------ test/core/core_func_integer_find_msb.cpp | 28 +++++++++++------------ test/gtc/gtc_bitfield.cpp | 2 +- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/glm/gtc/bitfield.inl b/glm/gtc/bitfield.inl index e7a0b4f7..cbfd3888 100644 --- a/glm/gtc/bitfield.inl +++ b/glm/gtc/bitfield.inl @@ -231,7 +231,7 @@ namespace detail { GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'mask' accepts only integer values"); - return Bits >= sizeof(genIUType) * 8 ? ~static_cast(0) : (static_cast(1) << Bits) - static_cast(1); + return Bits >= static_cast(sizeof(genIUType) * 8) ? ~static_cast(0) : (static_cast(1) << Bits) - static_cast(1); } #if GLM_COMPILER & GLM_COMPILER_CLANG diff --git a/test/core/core_func_integer_bit_count.cpp b/test/core/core_func_integer_bit_count.cpp index 2b81db88..16316445 100644 --- a/test/core/core_func_integer_bit_count.cpp +++ b/test/core/core_func_integer_bit_count.cpp @@ -208,7 +208,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (pop0(test[i]) != test[i+1]) error(test[i], pop0(test[i]));} + if (pop0(test[i]) != static_cast(test[i+1])) error(test[i], pop0(test[i]));} TimestampEnd = std::clock(); std::printf("pop0: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -216,7 +216,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (pop1(test[i]) != test[i+1]) error(test[i], pop1(test[i]));} + if (pop1(test[i]) != static_cast(test[i+1])) error(test[i], pop1(test[i]));} TimestampEnd = std::clock(); std::printf("pop1: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -224,7 +224,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (pop2(test[i]) != test[i+1]) error(test[i], pop2(test[i]));} + if (pop2(test[i]) != static_cast(test[i+1])) error(test[i], pop2(test[i]));} TimestampEnd = std::clock(); std::printf("pop2: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -232,7 +232,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (pop3(test[i]) != test[i+1]) error(test[i], pop3(test[i]));} + if (pop3(test[i]) != static_cast(test[i+1])) error(test[i], pop3(test[i]));} TimestampEnd = std::clock(); std::printf("pop3: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -240,7 +240,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (pop4(test[i]) != test[i+1]) error(test[i], pop4(test[i]));} + if (pop4(test[i]) != static_cast(test[i+1])) error(test[i], pop4(test[i]));} TimestampEnd = std::clock(); std::printf("pop4: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -248,7 +248,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (pop5(test[i]) != test[i+1]) error(test[i], pop5(test[i]));} + if (pop5(test[i]) != static_cast(test[i+1])) error(test[i], pop5(test[i]));} TimestampEnd = std::clock(); std::printf("pop5: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -256,7 +256,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (pop5a(test[i]) != test[i+1]) error(test[i], pop5a(test[i]));} + if (pop5a(test[i]) != static_cast(test[i+1])) error(test[i], pop5a(test[i]));} TimestampEnd = std::clock(); std::printf("pop5a: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -264,7 +264,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (pop6(test[i]) != test[i+1]) error(test[i], pop6(test[i]));} + if (pop6(test[i]) != static_cast(test[i+1])) error(test[i], pop6(test[i]));} TimestampEnd = std::clock(); std::printf("pop6: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -273,7 +273,7 @@ int main() for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { if ((test[i] & 0xffffff00) == 0) - if (pop7(test[i]) != test[i+1]) error(test[i], pop7(test[i]));} + if (pop7(test[i]) != static_cast(test[i+1])) error(test[i], pop7(test[i]));} TimestampEnd = std::clock(); std::printf("pop7: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -282,7 +282,7 @@ int main() for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { if ((test[i] & 0xffffff80) == 0) - if (pop8(test[i]) != test[i+1]) error(test[i], pop8(test[i]));} + if (pop8(test[i]) != static_cast(test[i+1])) error(test[i], pop8(test[i]));} TimestampEnd = std::clock(); std::printf("pop8: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -291,7 +291,7 @@ int main() for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { if ((test[i] & 0xffff8000) == 0) - if (pop9(test[i]) != test[i+1]) error(test[i], pop9(test[i]));} + if (pop9(test[i]) != static_cast(test[i+1])) error(test[i], pop9(test[i]));} TimestampEnd = std::clock(); std::printf("pop9: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); diff --git a/test/core/core_func_integer_find_lsb.cpp b/test/core/core_func_integer_find_lsb.cpp index ebe8eddc..22b4dfbb 100644 --- a/test/core/core_func_integer_find_lsb.cpp +++ b/test/core/core_func_integer_find_lsb.cpp @@ -312,7 +312,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz1(test[i]) != test[i+1]) error(test[i], ntz1(test[i]));} + if (ntz1(test[i]) != static_cast(test[i+1])) error(test[i], ntz1(test[i]));} TimestampEnd = std::clock(); std::printf("ntz1: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -320,7 +320,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz2(test[i]) != test[i+1]) error(test[i], ntz2(test[i]));} + if (ntz2(test[i]) != static_cast(test[i+1])) error(test[i], ntz2(test[i]));} TimestampEnd = std::clock(); std::printf("ntz2: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -328,7 +328,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz3(test[i]) != test[i+1]) error(test[i], ntz3(test[i]));} + if (ntz3(test[i]) != static_cast(test[i+1])) error(test[i], ntz3(test[i]));} TimestampEnd = std::clock(); std::printf("ntz3: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -336,7 +336,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz4(test[i]) != test[i+1]) error(test[i], ntz4(test[i]));} + if (ntz4(test[i]) != static_cast(test[i+1])) error(test[i], ntz4(test[i]));} TimestampEnd = std::clock(); std::printf("ntz4: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -344,7 +344,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz4a(test[i]) != test[i+1]) error(test[i], ntz4a(test[i]));} + if (ntz4a(test[i]) != static_cast(test[i+1])) error(test[i], ntz4a(test[i]));} TimestampEnd = std::clock(); std::printf("ntz4a: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -366,7 +366,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz6(test[i]) != test[i+1]) error(test[i], ntz6(test[i]));} + if (ntz6(test[i]) != static_cast(test[i+1])) error(test[i], ntz6(test[i]));} TimestampEnd = std::clock(); std::printf("ntz6: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -374,7 +374,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz6a(test[i]) != test[i+1]) error(test[i], ntz6a(test[i]));} + if (ntz6a(test[i]) != static_cast(test[i+1])) error(test[i], ntz6a(test[i]));} TimestampEnd = std::clock(); std::printf("ntz6a: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -382,7 +382,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz7(test[i]) != test[i+1]) error(test[i], ntz7(test[i]));} + if (ntz7(test[i]) != static_cast(test[i+1])) error(test[i], ntz7(test[i]));} TimestampEnd = std::clock(); std::printf("ntz7: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -390,7 +390,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz7_christophe(test[i]) != test[i+1]) error(test[i], ntz7(test[i]));} + if (ntz7_christophe(test[i]) != static_cast(test[i+1])) error(test[i], ntz7(test[i]));} TimestampEnd = std::clock(); std::printf("ntz7_christophe: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -398,7 +398,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz8(test[i]) != test[i+1]) error(test[i], ntz8(test[i]));} + if (ntz8(test[i]) != static_cast(test[i+1])) error(test[i], ntz8(test[i]));} TimestampEnd = std::clock(); std::printf("ntz8: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -406,7 +406,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz8a(test[i]) != test[i+1]) error(test[i], ntz8a(test[i]));} + if (ntz8a(test[i]) != static_cast(test[i+1])) error(test[i], ntz8a(test[i]));} TimestampEnd = std::clock(); std::printf("ntz8a: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -414,7 +414,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz9(test[i]) != test[i+1]) error(test[i], ntz9(test[i]));} + if (ntz9(test[i]) != static_cast(test[i+1])) error(test[i], ntz9(test[i]));} TimestampEnd = std::clock(); std::printf("ntz9: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -422,7 +422,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz10(test[i]) != test[i+1]) error(test[i], ntz10(test[i]));} + if (ntz10(test[i]) != static_cast(test[i+1])) error(test[i], ntz10(test[i]));} TimestampEnd = std::clock(); std::printf("ntz10: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -430,7 +430,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (ntz11(test[i]) != test[i + 1]) error(test[i], ntz11(test[i])); + if (ntz11(test[i]) != static_cast(test[i + 1])) error(test[i], ntz11(test[i])); } TimestampEnd = std::clock(); diff --git a/test/core/core_func_integer_find_msb.cpp b/test/core/core_func_integer_find_msb.cpp index 08e30389..f47ad980 100644 --- a/test/core/core_func_integer_find_msb.cpp +++ b/test/core/core_func_integer_find_msb.cpp @@ -338,7 +338,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz1(test[i]) != test[i+1]) error(test[i], nlz1(test[i]));} + if (nlz1(test[i]) != static_cast(test[i + 1])) error(test[i], nlz1(test[i]));} TimestampEnd = std::clock(); std::printf("nlz1: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -346,7 +346,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz1a(test[i]) != test[i+1]) error(test[i], nlz1a(test[i]));} + if (nlz1a(test[i]) != static_cast(test[i + 1])) error(test[i], nlz1a(test[i]));} TimestampEnd = std::clock(); std::printf("nlz1a: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -354,7 +354,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz2(test[i]) != test[i+1]) error(test[i], nlz2(test[i]));} + if (nlz2(test[i]) != static_cast(test[i + 1])) error(test[i], nlz2(test[i]));} TimestampEnd = std::clock(); std::printf("nlz2: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -362,7 +362,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz2a(test[i]) != test[i+1]) error(test[i], nlz2a(test[i]));} + if (nlz2a(test[i]) != static_cast(test[i + 1])) error(test[i], nlz2a(test[i]));} TimestampEnd = std::clock(); std::printf("nlz2a: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -370,7 +370,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz3(test[i]) != test[i+1]) error(test[i], nlz3(test[i]));} + if (nlz3(test[i]) != static_cast(test[i + 1])) error(test[i], nlz3(test[i]));} TimestampEnd = std::clock(); std::printf("nlz3: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -378,7 +378,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz4(test[i]) != test[i+1]) error(test[i], nlz4(test[i]));} + if (nlz4(test[i]) != static_cast(test[i + 1])) error(test[i], nlz4(test[i]));} TimestampEnd = std::clock(); std::printf("nlz4: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -386,7 +386,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz5(test[i]) != test[i+1]) error(test[i], nlz5(test[i]));} + if (nlz5(test[i]) != static_cast(test[i + 1])) error(test[i], nlz5(test[i]));} TimestampEnd = std::clock(); std::printf("nlz5: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -394,7 +394,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz6(test[i]) != test[i+1]) error(test[i], nlz6(test[i]));} + if (nlz6(test[i]) != static_cast(test[i + 1])) error(test[i], nlz6(test[i]));} TimestampEnd = std::clock(); std::printf("nlz6: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -402,7 +402,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz7(test[i]) != test[i+1]) error(test[i], nlz7(test[i]));} + if (nlz7(test[i]) != static_cast(test[i + 1])) error(test[i], nlz7(test[i]));} TimestampEnd = std::clock(); std::printf("nlz7: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -410,7 +410,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz8(test[i]) != test[i+1]) error(test[i], nlz8(test[i]));} + if (nlz8(test[i]) != static_cast(test[i + 1])) error(test[i], nlz8(test[i]));} TimestampEnd = std::clock(); std::printf("nlz8: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -418,7 +418,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz9(test[i]) != test[i+1]) error(test[i], nlz9(test[i]));} + if (nlz9(test[i]) != static_cast(test[i + 1])) error(test[i], nlz9(test[i]));} TimestampEnd = std::clock(); std::printf("nlz9: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -426,7 +426,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz10(test[i]) != test[i+1]) error(test[i], nlz10(test[i]));} + if (nlz10(test[i]) != static_cast(test[i + 1])) error(test[i], nlz10(test[i]));} TimestampEnd = std::clock(); std::printf("nlz10: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -434,7 +434,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz10a(test[i]) != test[i+1]) error(test[i], nlz10a(test[i]));} + if (nlz10a(test[i]) != static_cast(test[i + 1])) error(test[i], nlz10a(test[i]));} TimestampEnd = std::clock(); std::printf("nlz10a: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); @@ -442,7 +442,7 @@ int main() TimestampBeg = std::clock(); for (std::size_t k = 0; k < Count; ++k) for (i = 0; i < n; i += 2) { - if (nlz10b(test[i]) != test[i+1]) error(test[i], nlz10b(test[i]));} + if (nlz10b(test[i]) != static_cast(test[i + 1])) error(test[i], nlz10b(test[i]));} TimestampEnd = std::clock(); std::printf("nlz10b: %d clocks\n", static_cast(TimestampEnd - TimestampBeg)); diff --git a/test/gtc/gtc_bitfield.cpp b/test/gtc/gtc_bitfield.cpp index f85fbc3b..6142ba3e 100644 --- a/test/gtc/gtc_bitfield.cpp +++ b/test/gtc/gtc_bitfield.cpp @@ -34,7 +34,7 @@ namespace mask static inline int mask_mix(int Bits) { - return Bits >= sizeof(int) * 8 ? 0xffffffff : (static_cast(1) << Bits) - static_cast(1); + return Bits >= static_cast(sizeof(int) * 8) ? 0xffffffff : (static_cast(1) << Bits) - static_cast(1); } #if GLM_COMPILER & GLM_COMPILER_CLANG