Merge pull request #287 from gtsoul-tech/bugFix/cppcheck-cStylecasts-Part4

Part 4 of C-style cast cppcheck
This commit is contained in:
Konstantinos Margaritis
2024-05-21 15:59:51 +03:00
committed by GitHub
26 changed files with 282 additions and 239 deletions

View File

@@ -238,6 +238,7 @@ static really_inline u32 diffrich64_256(m256 a, m256 b) {
// aligned load
static really_inline m256 load256(const void *ptr) {
assert(ISALIGNED_N(ptr, alignof(m256)));
// cppcheck-suppress cstyleCast
m256 rv = { load128(ptr), load128((const char *)ptr + 16) };
return rv;
}
@@ -255,11 +256,13 @@ static really_inline m256 loadu2x128(const void *ptr) {
static really_inline void store256(void *ptr, m256 a) {
assert(ISALIGNED_N(ptr, alignof(m256)));
ptr = vectorscan_assume_aligned(ptr, 16);
// cppcheck-suppress cstyleCast
*(m256 *)ptr = a;
}
// unaligned load
static really_inline m256 loadu256(const void *ptr) {
// cppcheck-suppress cstyleCast
m256 rv = { loadu128(ptr), loadu128((const char *)ptr + 16) };
return rv;
}
@@ -267,6 +270,7 @@ static really_inline m256 loadu256(const void *ptr) {
// unaligned store
static really_inline void storeu256(void *ptr, m256 a) {
storeu128(ptr, a.lo);
// cppcheck-suppress cstyleCast
storeu128((char *)ptr + 16, a.hi);
}
@@ -476,8 +480,8 @@ static really_inline u32 diffrich64_384(m384 a, m384 b) {
// aligned load
static really_inline m384 load384(const void *ptr) {
assert(ISALIGNED_16(ptr));
m384 rv = { load128(ptr), load128((const char *)ptr + 16),
load128((const char *)ptr + 32) };
// cppcheck-suppress cstyleCast
m384 rv = { load128(ptr), load128((const char *)ptr + 16),load128((const char *)ptr + 32) };
return rv;
}
@@ -485,13 +489,14 @@ static really_inline m384 load384(const void *ptr) {
static really_inline void store384(void *ptr, m384 a) {
assert(ISALIGNED_16(ptr));
ptr = vectorscan_assume_aligned(ptr, 16);
// cppcheck-suppress cstyleCast
*(m384 *)ptr = a;
}
// unaligned load
static really_inline m384 loadu384(const void *ptr) {
m384 rv = { loadu128(ptr), loadu128((const char *)ptr + 16),
loadu128((const char *)ptr + 32)};
// cppcheck-suppress cstyleCast
m384 rv = { loadu128(ptr), loadu128((const char *)ptr + 16),loadu128((const char *)ptr + 32)};
return rv;
}
@@ -703,6 +708,7 @@ u32 diffrich64_512(m512 a, m512 b) {
static really_inline
m512 load512(const void *ptr) {
assert(ISALIGNED_N(ptr, alignof(m256)));
// cppcheck-suppress cstyleCast
m512 rv = { load256(ptr), load256((const char *)ptr + 32) };
return rv;
}
@@ -711,6 +717,7 @@ m512 load512(const void *ptr) {
static really_inline
void store512(void *ptr, m512 a) {
assert(ISALIGNED_N(ptr, alignof(m512)));
// cppcheck-suppress cstyleCast
m512 *x = (m512 *)ptr;
store256(&x->lo, a.lo);
store256(&x->hi, a.hi);
@@ -719,6 +726,7 @@ void store512(void *ptr, m512 a) {
// unaligned load
static really_inline
m512 loadu512(const void *ptr) {
// cppcheck-suppress cstyleCast
m512 rv = { loadu256(ptr), loadu256((const char *)ptr + 32) };
return rv;
}

View File

@@ -290,6 +290,7 @@ static really_inline m128 andnot128(m128 a, m128 b) {
static really_inline m128 load128(const void *ptr) {
assert(ISALIGNED_N(ptr, alignof(m128)));
ptr = vectorscan_assume_aligned(ptr, 16);
// cppcheck-suppress cstyleCast
return _mm_load_si128((const m128 *)ptr);
}
@@ -297,16 +298,19 @@ static really_inline m128 load128(const void *ptr) {
static really_inline void store128(void *ptr, m128 a) {
assert(ISALIGNED_N(ptr, alignof(m128)));
ptr = vectorscan_assume_aligned(ptr, 16);
// cppcheck-suppress cstyleCast
*(m128 *)ptr = a;
}
// unaligned load
static really_inline m128 loadu128(const void *ptr) {
// cppcheck-suppress cstyleCast
return _mm_loadu_si128((const m128 *)ptr);
}
// unaligned store
static really_inline void storeu128(void *ptr, m128 a) {
// cppcheck-suppress cstyleCast
_mm_storeu_si128 ((m128 *)ptr, a);
}

View File

@@ -43,12 +43,14 @@ void partial_store_u32(void *ptr, u32 value, u32 numBytes) {
break;
case 3:
unaligned_store_u16(ptr, (u16)value);
// cppcheck-suppress cstyleCast
*((u8 *)ptr + 2) = (u8)(value >> 16);
break;
case 2:
unaligned_store_u16(ptr, (u16)value);
break;
case 1:
// cppcheck-suppress cstyleCast
*(u8 *)ptr = (u8)value;
break;
case 0:
@@ -66,12 +68,14 @@ u32 partial_load_u32(const void *ptr, u32 numBytes) {
return value;
case 3:
value = unaligned_load_u16(ptr);
// cppcheck-suppress cstyleCast
value |= ((u32)(*((const u8 *)ptr + 2)) << 16);
return value;
case 2:
value = unaligned_load_u16(ptr);
return value;
case 1:
// cppcheck-suppress cstyleCast
value = *(const u8 *)ptr;
return value;
case 0:
@@ -90,15 +94,19 @@ void partial_store_u64a(void *ptr, u64a value, u32 numBytes) {
break;
case 7:
unaligned_store_u32(ptr, (u32)value);
// cppcheck-suppress cstyleCast
unaligned_store_u16((u8 *)ptr + 4, (u16)(value >> 32));
// cppcheck-suppress cstyleCast
*((u8 *)ptr + 6) = (u8)(value >> 48);
break;
case 6:
unaligned_store_u32(ptr, (u32)value);
// cppcheck-suppress cstyleCast
unaligned_store_u16((u8 *)ptr + 4, (u16)(value >> 32));
break;
case 5:
unaligned_store_u32(ptr, (u32)value);
// cppcheck-suppress cstyleCast
*((u8 *)ptr + 4) = (u8)(value >> 32);
break;
case 4:
@@ -106,12 +114,14 @@ void partial_store_u64a(void *ptr, u64a value, u32 numBytes) {
break;
case 3:
unaligned_store_u16(ptr, (u16)value);
// cppcheck-suppress cstyleCast
*((u8 *)ptr + 2) = (u8)(value >> 16);
break;
case 2:
unaligned_store_u16(ptr, (u16)value);
break;
case 1:
// cppcheck-suppress cstyleCast
*(u8 *)ptr = (u8)value;
break;
case 0:
@@ -129,15 +139,19 @@ u64a partial_load_u64a(const void *ptr, u32 numBytes) {
return value;
case 7:
value = unaligned_load_u32(ptr);
// cppcheck-suppress cstyleCast
value |= (u64a)unaligned_load_u16((const u8 *)ptr + 4) << 32;
// cppcheck-suppress cstyleCast
value |= (u64a)(*((const u8 *)ptr + 6)) << 48;
return value;
case 6:
value = unaligned_load_u32(ptr);
// cppcheck-suppress cstyleCast
value |= (u64a)unaligned_load_u16((const u8 *)ptr + 4) << 32;
return value;
case 5:
value = unaligned_load_u32(ptr);
// cppcheck-suppress cstyleCast
value |= (u64a)(*((const u8 *)ptr + 4)) << 32;
return value;
case 4:
@@ -145,12 +159,14 @@ u64a partial_load_u64a(const void *ptr, u32 numBytes) {
return value;
case 3:
value = unaligned_load_u16(ptr);
// cppcheck-suppress cstyleCast
value |= (u64a)(*((const u8 *)ptr + 2)) << 16;
return value;
case 2:
value = unaligned_load_u16(ptr);
return value;
case 1:
// cppcheck-suppress cstyleCast
value = *(const u8 *)ptr;
return value;
case 0:

View File

@@ -1112,7 +1112,7 @@ really_inline SuperVector<32> SuperVector<32>::Ones_vshl(uint8_t const N)
template <>
really_inline SuperVector<32> SuperVector<32>::loadu(void const *ptr)
{
return {SuperVector<32>(_mm256_loadu_si256((const m256 *)ptr))};
return {SuperVector<32>(_mm256_loadu_si256(reinterpret_cast<const m256 *>(ptr)))};
}
template <>
@@ -1120,7 +1120,7 @@ really_inline SuperVector<32> SuperVector<32>::load(void const *ptr)
{
assert(ISALIGNED_N(ptr, alignof(SuperVector::size)));
ptr = vectorscan_assume_aligned(ptr, SuperVector::size);
return {SuperVector<32>(_mm256_load_si256((const m256 *)ptr))};
return {SuperVector<32>(_mm256_load_si256(reinterpret_cast<const m256 *>(ptr)))};
}
template <>
@@ -1128,7 +1128,7 @@ really_inline SuperVector<32> SuperVector<32>::loadu_maskz(void const *ptr, uint
{
#ifdef HAVE_AVX512
u32 mask = (~0ULL) >> (32 - len);
SuperVector<32> v = SuperVector<32>(_mm256_mask_loadu_epi8(Zeroes().u.v256[0], mask, (const m256 *)ptr));
SuperVector<32> v = SuperVector<32>(_mm256_mask_loadu_epi8(Zeroes().u.v256[0], mask, reinterpret_cast<const m256 *>(ptr)));
v.print8("v");
return v;
#else
@@ -1136,7 +1136,7 @@ really_inline SuperVector<32> SuperVector<32>::loadu_maskz(void const *ptr, uint
SuperVector<32> mask = Ones_vshr(32 -len);
mask.print8("mask");
(Ones() >> (32 - len)).print8("mask");
SuperVector<32> v = SuperVector<32>(_mm256_loadu_si256((const m256 *)ptr));
SuperVector<32> v = SuperVector<32>(_mm256_loadu_si256(reinterpret_cast<const m256 *>(ptr)));
v.print8("v");
return mask & v;
#endif
@@ -1762,7 +1762,7 @@ really_inline SuperVector<64> SuperVector<64>::operator<<(uint8_t const N) const
template <>
really_inline SuperVector<64> SuperVector<64>::loadu(void const *ptr)
{
return {SuperVector<64>(_mm512_loadu_si512((const m512 *)ptr))};
return {SuperVector<64>(_mm512_loadu_si512(reinterpret_cast<const m512 *>(ptr)))};
}
template <>
@@ -1770,7 +1770,7 @@ really_inline SuperVector<64> SuperVector<64>::load(void const *ptr)
{
assert(ISALIGNED_N(ptr, alignof(SuperVector::size)));
ptr = vectorscan_assume_aligned(ptr, SuperVector::size);
return {SuperVector<64>(_mm512_load_si512((const m512 *)ptr))};
return {SuperVector<64>(_mm512_load_si512(reinterpret_cast<const m512 *>(ptr)))};
}
template <>
@@ -1778,7 +1778,7 @@ really_inline SuperVector<64> SuperVector<64>::loadu_maskz(void const *ptr, uint
{
u64a mask = (~0ULL) >> (64 - len);
DEBUG_PRINTF("mask = %016llx\n", mask);
SuperVector<64> v = SuperVector<64>(_mm512_mask_loadu_epi8(Zeroes().u.v512[0], mask, (const m512 *)ptr));
SuperVector<64> v = SuperVector<64>(_mm512_mask_loadu_epi8(Zeroes().u.v512[0], mask, reinterpret_cast<const m512 *>(ptr)));
v.print8("v");
return v;
}

View File

@@ -41,6 +41,7 @@
static really_inline
u16 unaligned_load_u16(const void *ptr) {
struct unaligned { u16 u; } PACKED__MAY_ALIAS;
// cppcheck-suppress cstyleCast
const struct unaligned *uptr = (const struct unaligned *)ptr;
return uptr->u;
}
@@ -49,6 +50,7 @@ u16 unaligned_load_u16(const void *ptr) {
static really_inline
u32 unaligned_load_u32(const void *ptr) {
struct unaligned { u32 u; } PACKED__MAY_ALIAS;
// cppcheck-suppress cstyleCast
const struct unaligned *uptr = (const struct unaligned *)ptr;
return uptr->u;
}
@@ -57,6 +59,7 @@ u32 unaligned_load_u32(const void *ptr) {
static really_inline
u64a unaligned_load_u64a(const void *ptr) {
struct unaligned { u64a u; } PACKED__MAY_ALIAS;
// cppcheck-suppress cstyleCast
const struct unaligned *uptr = (const struct unaligned *)ptr;
return uptr->u;
}
@@ -65,6 +68,7 @@ u64a unaligned_load_u64a(const void *ptr) {
static really_inline
void unaligned_store_u16(void *ptr, u16 val) {
struct unaligned { u16 u; } PACKED__MAY_ALIAS;
// cppcheck-suppress cstyleCast
struct unaligned *uptr = (struct unaligned *)ptr;
uptr->u = val;
}
@@ -73,6 +77,7 @@ void unaligned_store_u16(void *ptr, u16 val) {
static really_inline
void unaligned_store_u32(void *ptr, u32 val) {
struct unaligned { u32 u; } PACKED__MAY_ALIAS;
// cppcheck-suppress cstyleCast
struct unaligned *uptr = (struct unaligned *)ptr;
uptr->u = val;
}
@@ -81,6 +86,7 @@ void unaligned_store_u32(void *ptr, u32 val) {
static really_inline
void unaligned_store_u64a(void *ptr, u64a val) {
struct unaligned { u64a u; } PACKED__MAY_ALIAS;
// cppcheck-suppress cstyleCast
struct unaligned *uptr = (struct unaligned *)ptr;
uptr->u = val;
}