Skip to content

Commit

Permalink
Introduce new misra c++ quality fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Jun 4, 2024
1 parent 7e52eff commit 8448332
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 83 deletions.
44 changes: 22 additions & 22 deletions modules/core/include/visp3/core/vpImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ class vpDisplay;
template <class Type> class vpImage; // forward declare to make function declaration possible

// declarations
template <class Type> std::ostream &operator<<(std::ostream &, const vpImage<Type> &);
template <class Type> std::ostream &operator<<(std::ostream &s, const vpImage<Type> &I);

std::ostream &operator<<(std::ostream &, const vpImage<unsigned char> &);
std::ostream &operator<<(std::ostream &, const vpImage<char> &);
std::ostream &operator<<(std::ostream &, const vpImage<float> &);
std::ostream &operator<<(std::ostream &, const vpImage<double> &);
std::ostream &operator<<(std::ostream &s, const vpImage<unsigned char> &I);
std::ostream &operator<<(std::ostream &s, const vpImage<char> &I);
std::ostream &operator<<(std::ostream &s, const vpImage<float> &I);
std::ostream &operator<<(std::ostream &s, const vpImage<double> &I);
END_VISP_NAMESPACE

template <class Type> void swap(VISP_NAMESPACE_ADDRESSING vpImage<Type> &first, VISP_NAMESPACE_ADDRESSING vpImage<Type> &second);
Expand Down Expand Up @@ -273,7 +273,7 @@ template <class Type> class vpImage
\return Value of the image point (i, j).
*/
inline Type operator()(unsigned int i, unsigned int j) const { return bitmap[i * width + j]; }
inline Type operator()(unsigned int i, unsigned int j) const { return bitmap[(i * width) + j]; }

/*!
Set the value \e v of an image point with coordinates (i, j), with i the
Expand Down Expand Up @@ -1829,22 +1829,22 @@ template <class Type> void vpImage<Type>::doubleSizeImage(vpImage<Type> &res)
// interpolate pixels B and I
for (unsigned int i = 0; i < h; i += 2) {
for (unsigned int j = 1; j < (w - 1); j += 2) {
res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1]));
res[i][j] = static_cast<Type>(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1]));
}
}

// interpolate pixels E and G
for (unsigned int i = 1; i < (h - 1); i += 2) {
for (unsigned int j = 0; j < w; j += 2) {
res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[(i >> 1) + 1][j >> 1]));
res[i][j] = static_cast<Type>(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[(i >> 1) + 1][j >> 1]));
}
}

// interpolate pixel F
for (unsigned int i = 1; i < (h - 1); i += 2) {
for (unsigned int j = 1; j < (w - 1); j += 2) {
res[i][j] = (Type)(0.25 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1] +
(*this)[(i >> 1) + 1][j >> 1] + (*this)[(i >> 1) + 1][(j >> 1) + 1]));
res[i][j] = static_cast<Type>(0.25 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1] +
(*this)[(i >> 1) + 1][j >> 1] + (*this)[(i >> 1) + 1][(j >> 1) + 1]));
}
}
}
Expand Down Expand Up @@ -1958,21 +1958,21 @@ template <> inline unsigned char vpImage<unsigned char>::getValue(double i, doub
// alpha architecture is bi-endianness. The following optimization makes testImageGetValue failing
#if (defined(VISP_LITTLE_ENDIAN) || defined(VISP_BIG_ENDIAN)) && !(defined(__alpha__) || defined(_M_ALPHA))
// Fixed-point arithmetic
const int32_t precision = 1 << 16;
int64_t y = static_cast<int64_t>(i * precision);
int64_t x = static_cast<int64_t>(j * precision);
const uint32_t precision = 1U << 16;
uint64_t y = static_cast<uint64_t>(i * precision);
uint64_t x = static_cast<uint64_t>(j * precision);

int64_t iround = y & (~0xFFFF);
int64_t jround = x & (~0xFFFF);
uint64_t iround = y & (~0xFFFFU);
uint64_t jround = x & (~0xFFFFU);

int64_t rratio = y - iround;
int64_t cratio = x - jround;
uint64_t rratio = y - iround;
uint64_t cratio = x - jround;

int64_t rfrac = precision - rratio;
int64_t cfrac = precision - cratio;
uint64_t rfrac = precision - rratio;
uint64_t cfrac = precision - cratio;

int64_t x_ = x >> 16;
int64_t y_ = y >> 16;
uint64_t x_ = x >> 16;
uint64_t y_ = y >> 16;

if (((y_ + 1) < height) && ((x_ + 1) < width)) {
uint16_t up = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + (y_ * width) + x_);
Expand All @@ -1983,7 +1983,7 @@ template <> inline unsigned char vpImage<unsigned char>::getValue(double i, doub
32);
}
else if ((y_ + 1) < height) {
return static_cast<unsigned char>(((row[y_][x_] * rfrac + row[y_ + 1][x_] * rratio)) >> 16);
return static_cast<unsigned char>((row[y_][x_] * rfrac + row[y_ + 1][x_] * rratio) >> 16);
}
else if ((x_ + 1) < width) {
uint16_t up = vpEndian::reinterpret_cast_uchar_to_uint16_LE(bitmap + (y_ * width) + x_);
Expand Down
4 changes: 2 additions & 2 deletions modules/core/include/visp3/core/vpImageTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -1465,9 +1465,9 @@ void vpImageTools::warpLinear(const vpImage<Type> &src, const vpMatrix &T, vpIma
{
if (fixedPoint && (!centerCorner)) {
const int nbits = 16;
const int64_t precision = 1 << nbits;
const uint64_t precision = 1 << nbits;
const float precision_1 = 1 / static_cast<float>(precision);
const int64_t precision2 = 1ULL << (2 * nbits);
const uint64_t precision2 = 1ULL << (2 * nbits);
const float precision_2 = 1 / static_cast<float>(precision2);

int64_t a0_i64 = static_cast<int64_t>(T[0][0] * precision);
Expand Down
78 changes: 39 additions & 39 deletions modules/core/src/tools/cpu-features/x86/cpu_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ bool cpu_x86::detect_OS_AVX()

bool avxSupported = false;

int cpuInfo[4];
uint32_t cpuInfo[4];
cpuid(cpuInfo, 1);

bool osUsesXSAVE_XRSTORE = (cpuInfo[2] & (1 << 27)) != 0;
bool cpuAVXSuport = (cpuInfo[2] & (1 << 28)) != 0;
bool osUsesXSAVE_XRSTORE = (cpuInfo[2] & (1U << 27)) != 0;
bool cpuAVXSuport = (cpuInfo[2] & (1U << 28)) != 0;

if (osUsesXSAVE_XRSTORE && cpuAVXSuport) {
uint64_t xcrFeatureMask = xgetbv(_XCR_XFEATURE_ENABLED_MASK);
avxSupported = (xcrFeatureMask & 0x6) == 0x6;
avxSupported = (xcrFeatureMask & 0x6U) == 0x6U;
}

return avxSupported;
Expand All @@ -125,15 +125,15 @@ bool cpu_x86::detect_OS_AVX512()
}

uint64_t xcrFeatureMask = xgetbv(_XCR_XFEATURE_ENABLED_MASK);
return (xcrFeatureMask & 0xe6) == 0xe6;
return (xcrFeatureMask & 0xe6U) == 0xe6U;
#else
return false;
#endif
}
std::string cpu_x86::get_vendor_string()
{
#ifndef UNKNOWN_ARCH
int32_t CPUInfo[4];
uint32_t CPUInfo[4];
char name[13];

cpuid(CPUInfo, 0);
Expand Down Expand Up @@ -168,7 +168,7 @@ void cpu_x86::detect_host()
Vendor_AMD = true;
}

int info[4];
uint32_t info[4];
cpuid(info, 0);
int nIds = info[0];

Expand All @@ -178,49 +178,49 @@ void cpu_x86::detect_host()
// Detect Features
if (nIds >= 0x00000001) {
cpuid(info, 0x00000001);
HW_MMX = (info[3] & ((int)1 << 23)) != 0;
HW_SSE = (info[3] & ((int)1 << 25)) != 0;
HW_SSE2 = (info[3] & ((int)1 << 26)) != 0;
HW_SSE3 = (info[2] & ((int)1 << 0)) != 0;
HW_MMX = (info[3] & (1U << 23)) != 0U;
HW_SSE = (info[3] & (1U << 25)) != 0U;
HW_SSE2 = (info[3] & (1U << 26)) != 0U;
HW_SSE3 = (info[2] & (1U << 0)) != 0U;

HW_SSSE3 = (info[2] & ((int)1 << 9)) != 0;
HW_SSE41 = (info[2] & ((int)1 << 19)) != 0;
HW_SSE42 = (info[2] & ((int)1 << 20)) != 0;
HW_AES = (info[2] & ((int)1 << 25)) != 0;
HW_SSSE3 = (info[2] & (1U << 9)) != 0U;
HW_SSE41 = (info[2] & (1U << 19)) != 0U;
HW_SSE42 = (info[2] & (1U << 20)) != 0U;
HW_AES = (info[2] & (1U << 25)) != 0U;

HW_AVX = (info[2] & ((int)1 << 28)) != 0;
HW_FMA3 = (info[2] & ((int)1 << 12)) != 0;
HW_AVX = (info[2] & (1U << 28)) != 0U;
HW_FMA3 = (info[2] & (1U << 12)) != 0U;

HW_RDRAND = (info[2] & ((int)1 << 30)) != 0;
HW_RDRAND = (info[2] & (1U << 30)) != 0U;
}
if (nIds >= 0x00000007) {
cpuid(info, 0x00000007);
HW_AVX2 = (info[1] & ((int)1 << 5)) != 0;
HW_AVX2 = (info[1] & (1U << 5)) != 0U;

HW_BMI1 = (info[1] & ((int)1 << 3)) != 0;
HW_BMI2 = (info[1] & ((int)1 << 8)) != 0;
HW_ADX = (info[1] & ((int)1 << 19)) != 0;
HW_MPX = (info[1] & ((int)1 << 14)) != 0;
HW_SHA = (info[1] & ((int)1 << 29)) != 0;
HW_PREFETCHWT1 = (info[2] & ((int)1 << 0)) != 0;
HW_BMI1 = (info[1] & (1U << 3)) != 0U;
HW_BMI2 = (info[1] & (1U << 8)) != 0U;
HW_ADX = (info[1] & (1U << 19)) != 0U;
HW_MPX = (info[1] & (1U << 14)) != 0U;
HW_SHA = (info[1] & (1U << 29)) != 0U;
HW_PREFETCHWT1 = (info[2] & (1U << 0)) != 0U;

HW_AVX512_F = (info[1] & ((int)1 << 16)) != 0;
HW_AVX512_CD = (info[1] & ((int)1 << 28)) != 0;
HW_AVX512_PF = (info[1] & ((int)1 << 26)) != 0;
HW_AVX512_ER = (info[1] & ((int)1 << 27)) != 0;
HW_AVX512_VL = (info[1] & ((int)1 << 31)) != 0;
HW_AVX512_BW = (info[1] & ((int)1 << 30)) != 0;
HW_AVX512_DQ = (info[1] & ((int)1 << 17)) != 0;
HW_AVX512_IFMA = (info[1] & ((int)1 << 21)) != 0;
HW_AVX512_VBMI = (info[2] & ((int)1 << 1)) != 0;
HW_AVX512_F = (info[1] & (1U << 16)) != 0U;
HW_AVX512_CD = (info[1] & (1U << 28)) != 0U;
HW_AVX512_PF = (info[1] & (1U << 26)) != 0U;
HW_AVX512_ER = (info[1] & (1U << 27)) != 0U;
HW_AVX512_VL = (info[1] & (1U << 31)) != 0U;
HW_AVX512_BW = (info[1] & (1U << 30)) != 0U;
HW_AVX512_DQ = (info[1] & (1U << 17)) != 0U;
HW_AVX512_IFMA = (info[1] & (1U << 21)) != 0U;
HW_AVX512_VBMI = (info[2] & (1U << 1)) != 0U;
}
if (nExIds >= 0x80000001) {
cpuid(info, 0x80000001);
HW_x64 = (info[3] & ((int)1 << 29)) != 0;
HW_ABM = (info[2] & ((int)1 << 5)) != 0;
HW_SSE4a = (info[2] & ((int)1 << 6)) != 0;
HW_FMA4 = (info[2] & ((int)1 << 16)) != 0;
HW_XOP = (info[2] & ((int)1 << 11)) != 0;
HW_x64 = (info[3] & (1U << 29)) != 0U;
HW_ABM = (info[2] & (1U << 5)) != 0U;
HW_SSE4a = (info[2] & (1U << 6)) != 0U;
HW_FMA4 = (info[2] & (1U << 16)) != 0U;
HW_XOP = (info[2] & (1U << 11)) != 0U;
}
#endif
}
Expand Down
7 changes: 4 additions & 3 deletions modules/core/src/tools/cpu-features/x86/cpu_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ namespace FeatureDetector
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
struct cpu_x86 {
// Vendor
struct cpu_x86
{
// Vendor
bool Vendor_AMD;
bool Vendor_Intel;

Expand Down Expand Up @@ -108,7 +109,7 @@ struct cpu_x86 {

void print() const;

static void cpuid(int32_t out[4], int32_t x);
static void cpuid(uint32_t out[4], uint32_t x);
static std::string get_vendor_string();

private:
Expand Down
Loading

0 comments on commit 8448332

Please sign in to comment.