Skip to content

Commit a62d630

Browse files
committed
Eliminate old-style cast warnings for C++ compilation
This replaces C-style casts with type-safe alternatives to suppress -Wold-style-cast warnings when compiling as C++: - Use vreinterpret_u32_u64() NEON intrinsic for vector type reinterpretation - Use _sse2neon_static_cast() macro for scalar type conversions The _sse2neon_static_cast macro expands to static_cast<T> in C++ and ((T)) in C, maintaining compatibility with both languages.
1 parent 9f3dda7 commit a62d630

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

sse2neon.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ FORCE_INLINE uint16_t _sse2neon_vaddvq_u16(uint16x8_t a)
13591359
uint64x2_t n = vpaddlq_u32(m);
13601360
uint64x1_t o = vget_low_u64(n) + vget_high_u64(n);
13611361

1362-
return vget_lane_u32((uint32x2_t) o, 0);
1362+
return vget_lane_u32(vreinterpret_u32_u64(o), 0);
13631363
}
13641364
#else
13651365
// Wraps vaddvq_u16
@@ -4710,8 +4710,10 @@ FORCE_INLINE __m128d _mm_cvtepi32_pd(__m128i a)
47104710
return vreinterpretq_m128d_f64(
47114711
vcvtq_f64_s64(vmovl_s32(vget_low_s32(vreinterpretq_s32_m128i(a)))));
47124712
#else
4713-
double a0 = (double) vgetq_lane_s32(vreinterpretq_s32_m128i(a), 0);
4714-
double a1 = (double) vgetq_lane_s32(vreinterpretq_s32_m128i(a), 1);
4713+
double a0 = _sse2neon_static_cast(
4714+
double, vgetq_lane_s32(vreinterpretq_s32_m128i(a), 0));
4715+
double a1 = _sse2neon_static_cast(
4716+
double, vgetq_lane_s32(vreinterpretq_s32_m128i(a), 1));
47154717
return _mm_set_pd(a1, a0);
47164718
#endif
47174719
}
@@ -8526,7 +8528,7 @@ FORCE_INLINE __m128i _mm_minpos_epu16(__m128i a)
85268528
int i;
85278529
for (i = 0; i < 8; i++) {
85288530
if (min == vgetq_lane_u16(_a, 0)) {
8529-
idx = (uint16_t) i;
8531+
idx = _sse2neon_static_cast(uint16_t, i);
85308532
break;
85318533
}
85328534
_a = vreinterpretq_u16_s8(
@@ -10459,9 +10461,11 @@ FORCE_INLINE __m128i _mm_aesenc_si128(__m128i a, __m128i RoundKey)
1045910461
veorq_u8(w, vreinterpretq_u8_m128i(RoundKey)));
1046010462

1046110463
#else /* ARMv7-A implementation for a table-based AES */
10462-
#define SSE2NEON_AES_B2W(b0, b1, b2, b3) \
10463-
(((uint32_t) (b3) << 24) | ((uint32_t) (b2) << 16) | \
10464-
((uint32_t) (b1) << 8) | (uint32_t) (b0))
10464+
#define SSE2NEON_AES_B2W(b0, b1, b2, b3) \
10465+
((_sse2neon_static_cast(uint32_t, b3) << 24) | \
10466+
(_sse2neon_static_cast(uint32_t, b2) << 16) | \
10467+
(_sse2neon_static_cast(uint32_t, b1) << 8) | \
10468+
_sse2neon_static_cast(uint32_t, b0))
1046510469
// multiplying 'x' by 2 in GF(2^8)
1046610470
#define SSE2NEON_AES_F2(x) ((x << 1) ^ (((x >> 7) & 1) * 0x011b /* WPOLY */))
1046710471
// multiplying 'x' by 3 in GF(2^8)
@@ -10555,9 +10559,11 @@ FORCE_INLINE __m128i _mm_aesdec_si128(__m128i a, __m128i RoundKey)
1055510559

1055610560
#else /* ARMv7-A implementation using inverse T-tables */
1055710561
// GF(2^8) multiplication helpers for InvMixColumns coefficients
10558-
#define SSE2NEON_AES_DEC_B2W(b0, b1, b2, b3) \
10559-
(((uint32_t) (b3) << 24) | ((uint32_t) (b2) << 16) | \
10560-
((uint32_t) (b1) << 8) | (uint32_t) (b0))
10562+
#define SSE2NEON_AES_DEC_B2W(b0, b1, b2, b3) \
10563+
((_sse2neon_static_cast(uint32_t, b3) << 24) | \
10564+
(_sse2neon_static_cast(uint32_t, b2) << 16) | \
10565+
(_sse2neon_static_cast(uint32_t, b1) << 8) | \
10566+
_sse2neon_static_cast(uint32_t, b0))
1056110567
// xtime: multiply by 2 in GF(2^8), using 0x011b to clear bit 8
1056210568
#define SSE2NEON_AES_DEC_X2(x) ((x << 1) ^ (((x >> 7) & 1) * 0x011b))
1056310569
// multiply by 4 in GF(2^8)
@@ -10994,7 +11000,8 @@ FORCE_INLINE __m128i _mm_aeskeygenassist_si128(__m128i a, const int rcon)
1099411000
sb_[0xC], sb_[0x9], sb_[0x6], sb_[0x3], // SubBytes(X3)
1099511001
sb_[0x9], sb_[0x6], sb_[0x3], sb_[0xC], // ROT(SubBytes(X3))
1099611002
};
10997-
uint32x4_t r = {0, (unsigned) rcon, 0, (unsigned) rcon};
11003+
uint32x4_t r = {0, _sse2neon_static_cast(unsigned, rcon), 0,
11004+
_sse2neon_static_cast(unsigned, rcon)};
1099811005
return vreinterpretq_m128i_u8(dest) ^ vreinterpretq_m128i_u32(r);
1099911006
#else
1100011007
// We have to do this hack because MSVC is strictly adhering to the CPP

0 commit comments

Comments
 (0)