Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 82a96af

Browse files
echesakovjkotas
authored andcommitted
Use macro _countof instead of explicit sizeof(arr) / sizeof(arr[0]) or sizeof(arr) / sizeof(*arr) in clrjit. (#15474)
1 parent 739b71d commit 82a96af

22 files changed

+48
-49
lines changed

src/jit/assertionprop.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ void Compiler::optAssertionInit(bool isLocalProp)
542542
// Note this tracks at most only 256 assertions.
543543
static const AssertionIndex countFunc[] = {64, 128, 256, 64};
544544
static const unsigned lowerBound = 0;
545-
static const unsigned upperBound = sizeof(countFunc) / sizeof(countFunc[0]) - 1;
545+
static const unsigned upperBound = _countof(countFunc) - 1;
546546
const unsigned codeSize = info.compILCodeSize / 512;
547547
optMaxAssertionCount = countFunc[isLocalProp ? lowerBound : min(upperBound, codeSize)];
548548

src/jit/codegenlegacy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6178,7 +6178,7 @@ bool CodeGen::genCodeForQmarkWithCMOV(GenTreePtr tree, regMaskTP destReg, regMas
61786178
INS_cmove, INS_cmovne, INS_cmovbe, INS_cmova, INS_cmovs, INS_cmovns,
61796179
INS_cmovpe, INS_cmovpo, INS_cmovl, INS_cmovge, INS_cmovle, INS_cmovg};
61806180

6181-
noway_assert((unsigned)jumpKind < (sizeof(EJtoCMOV) / sizeof(EJtoCMOV[0])));
6181+
noway_assert((unsigned)jumpKind < _countof(EJtoCMOV));
61826182
instruction cmov_ins = EJtoCMOV[jumpKind];
61836183

61846184
noway_assert(insIsCMOV(cmov_ins));

src/jit/compiler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7818,7 +7818,7 @@ void CompTimeSummaryInfo::Print(FILE* f)
78187818
extraHdr2);
78197819

78207820
// Ensure that at least the names array and the Phases enum have the same number of entries:
7821-
assert(sizeof(PhaseNames) / sizeof(const char*) == PHASE_NUMBER_OF);
7821+
assert(_countof(PhaseNames) == PHASE_NUMBER_OF);
78227822
for (int i = 0; i < PHASE_NUMBER_OF; i++)
78237823
{
78247824
double phase_tot_ms = (((double)m_total.m_cyclesByPhase[i]) / countsPerSec) * 1000.0;
@@ -7882,7 +7882,7 @@ void CompTimeSummaryInfo::Print(FILE* f)
78827882
fprintf(f, " PHASE inv/meth Mcycles time (ms) %% of total\n");
78837883
fprintf(f, " --------------------------------------------------------------------------------------\n");
78847884
// Ensure that at least the names array and the Phases enum have the same number of entries:
7885-
assert(sizeof(PhaseNames) / sizeof(const char*) == PHASE_NUMBER_OF);
7885+
assert(_countof(PhaseNames) == PHASE_NUMBER_OF);
78867886
for (int i = 0; i < PHASE_NUMBER_OF; i++)
78877887
{
78887888
double phase_tot_ms = (((double)m_filtered.m_cyclesByPhase[i]) / countsPerSec) * 1000.0;

src/jit/compiler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ extern const BYTE genTypeSizes[TYP_COUNT];
569569
template <class T>
570570
inline unsigned genTypeSize(T type)
571571
{
572-
assert((unsigned)TypeGet(type) < sizeof(genTypeSizes) / sizeof(genTypeSizes[0]));
572+
assert((unsigned)TypeGet(type) < _countof(genTypeSizes));
573573

574574
return genTypeSizes[TypeGet(type)];
575575
}
@@ -584,7 +584,7 @@ extern const BYTE genTypeStSzs[TYP_COUNT];
584584

585585
inline unsigned genTypeStSz(var_types type)
586586
{
587-
assert((unsigned)type < sizeof(genTypeStSzs) / sizeof(genTypeStSzs[0]));
587+
assert((unsigned)type < _countof(genTypeStSzs));
588588

589589
return genTypeStSzs[type];
590590
}

src/jit/disasm.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ size_t DisAssembler::CbDisassemble(DIS* pdis,
11061106
}
11071107

11081108
wchar_t wz[MAX_CLASSNAME_LENGTH];
1109-
pdis->CchFormatInstr(wz, sizeof(wz) / sizeof(wz[0]));
1109+
pdis->CchFormatInstr(wz, _countof(wz));
11101110

11111111
if (printit)
11121112
{
@@ -1137,7 +1137,7 @@ size_t DisAssembler::CbDisassemble(DIS* pdis,
11371137
wchar_t wzBytes[MAX_CLASSNAME_LENGTH];
11381138
assert(cchBytesMax < MAX_CLASSNAME_LENGTH);
11391139

1140-
size_t cchBytes = pdis->CchFormatBytes(wzBytes, sizeof(wzBytes) / sizeof(wzBytes[0]));
1140+
size_t cchBytes = pdis->CchFormatBytes(wzBytes, _countof(wzBytes));
11411141

11421142
if (cchBytes > CCH_INDENT)
11431143
{
@@ -1172,7 +1172,7 @@ size_t CbDisassembleWithBytes(DIS* pdis, DIS::ADDR addr, const BYTE* pb, size_t
11721172

11731173
wchar_t wz[MAX_CLASSNAME_LENGTH];
11741174

1175-
pdis->CchFormatAddr(addr, wz, sizeof(wz) / sizeof(wz[0]));
1175+
pdis->CchFormatAddr(addr, wz, _countof(wz));
11761176

11771177
size_t cchIndent = (size_t)fprintf(pfile, " %ls: ", wz);
11781178

@@ -1194,7 +1194,7 @@ size_t CbDisassembleWithBytes(DIS* pdis, DIS::ADDR addr, const BYTE* pb, size_t
11941194
}
11951195

11961196
wchar_t wzBytes[64];
1197-
size_t cchBytes = pdis->CchFormatBytes(wzBytes, sizeof(wzBytes) / sizeof(wzBytes[0]));
1197+
size_t cchBytes = pdis->CchFormatBytes(wzBytes, _countof(wzBytes));
11981198

11991199
wchar_t* pwzBytes;
12001200
wchar_t* pwzNext;
@@ -1232,7 +1232,7 @@ size_t CbDisassembleWithBytes(DIS* pdis, DIS::ADDR addr, const BYTE* pb, size_t
12321232

12331233
if (fFirst)
12341234
{
1235-
pdis->CchFormatInstr(wz, sizeof(wz) / sizeof(wz[0]));
1235+
pdis->CchFormatInstr(wz, _countof(wz));
12361236
fprintf(pfile, "%-*ls %ls\n", cchBytesMax, pwzBytes, wz);
12371237
}
12381238

src/jit/emit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const char* emitter::emitIfName(unsigned f)
9292

9393
static char errBuff[32];
9494

95-
if (f < sizeof(ifNames) / sizeof(*ifNames))
95+
if (f < _countof(ifNames))
9696
{
9797
return ifNames[f];
9898
}
@@ -3118,7 +3118,7 @@ const BYTE emitter::emitFmtToOps[] = {
31183118
};
31193119

31203120
#ifdef DEBUG
3121-
const unsigned emitter::emitFmtCount = sizeof(emitFmtToOps) / sizeof(emitFmtToOps[0]);
3121+
const unsigned emitter::emitFmtCount = _countof(emitFmtToOps);
31223122
#endif
31233123

31243124
/*****************************************************************************

src/jit/emitxarch.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ const BYTE emitter::emitInsModeFmtTab[] =
823823
// clang-format on
824824

825825
#ifdef DEBUG
826-
unsigned const emitter::emitInsModeFmtCnt = sizeof(emitInsModeFmtTab) / sizeof(emitInsModeFmtTab[0]);
826+
unsigned const emitter::emitInsModeFmtCnt = _countof(emitInsModeFmtTab);
827827
#endif
828828

829829
/*****************************************************************************
@@ -938,7 +938,7 @@ inline size_t insCode(instruction ins)
938938
};
939939
// clang-format on
940940

941-
assert((unsigned)ins < sizeof(insCodes) / sizeof(insCodes[0]));
941+
assert((unsigned)ins < _countof(insCodes));
942942
assert((insCodes[ins] != BAD_CODE));
943943

944944
return insCodes[ins];
@@ -971,7 +971,7 @@ inline size_t insCodeACC(instruction ins)
971971
};
972972
// clang-format on
973973

974-
assert((unsigned)ins < sizeof(insCodesACC) / sizeof(insCodesACC[0]));
974+
assert((unsigned)ins < _countof(insCodesACC));
975975
assert((insCodesACC[ins] != BAD_CODE));
976976

977977
return insCodesACC[ins];
@@ -1004,7 +1004,7 @@ inline size_t insCodeRR(instruction ins)
10041004
};
10051005
// clang-format on
10061006

1007-
assert((unsigned)ins < sizeof(insCodesRR) / sizeof(insCodesRR[0]));
1007+
assert((unsigned)ins < _countof(insCodesRR));
10081008
assert((insCodesRR[ins] != BAD_CODE));
10091009

10101010
return insCodesRR[ins];
@@ -1033,7 +1033,7 @@ size_t insCodesRM[] =
10331033
// Returns true iff the give CPU instruction has an RM encoding.
10341034
inline bool hasCodeRM(instruction ins)
10351035
{
1036-
assert((unsigned)ins < sizeof(insCodesRM) / sizeof(insCodesRM[0]));
1036+
assert((unsigned)ins < _countof(insCodesRM));
10371037
return ((insCodesRM[ins] != BAD_CODE));
10381038
}
10391039

@@ -1044,7 +1044,7 @@ inline bool hasCodeRM(instruction ins)
10441044

10451045
inline size_t insCodeRM(instruction ins)
10461046
{
1047-
assert((unsigned)ins < sizeof(insCodesRM) / sizeof(insCodesRM[0]));
1047+
assert((unsigned)ins < _countof(insCodesRM));
10481048
assert((insCodesRM[ins] != BAD_CODE));
10491049

10501050
return insCodesRM[ins];
@@ -1073,7 +1073,7 @@ size_t insCodesMI[] =
10731073
// Returns true iff the give CPU instruction has an MI encoding.
10741074
inline bool hasCodeMI(instruction ins)
10751075
{
1076-
assert((unsigned)ins < sizeof(insCodesMI) / sizeof(insCodesMI[0]));
1076+
assert((unsigned)ins < _countof(insCodesMI));
10771077
return ((insCodesMI[ins] != BAD_CODE));
10781078
}
10791079

@@ -1084,7 +1084,7 @@ inline bool hasCodeMI(instruction ins)
10841084

10851085
inline size_t insCodeMI(instruction ins)
10861086
{
1087-
assert((unsigned)ins < sizeof(insCodesMI) / sizeof(insCodesMI[0]));
1087+
assert((unsigned)ins < _countof(insCodesMI));
10881088
assert((insCodesMI[ins] != BAD_CODE));
10891089

10901090
return insCodesMI[ins];
@@ -1113,7 +1113,7 @@ size_t insCodesMR[] =
11131113
// Returns true iff the give CPU instruction has an MR encoding.
11141114
inline bool hasCodeMR(instruction ins)
11151115
{
1116-
assert((unsigned)ins < sizeof(insCodesMR) / sizeof(insCodesMR[0]));
1116+
assert((unsigned)ins < _countof(insCodesMR));
11171117
return ((insCodesMR[ins] != BAD_CODE));
11181118
}
11191119

@@ -1124,7 +1124,7 @@ inline bool hasCodeMR(instruction ins)
11241124

11251125
inline size_t insCodeMR(instruction ins)
11261126
{
1127-
assert((unsigned)ins < sizeof(insCodesMR) / sizeof(insCodesMR[0]));
1127+
assert((unsigned)ins < _countof(insCodesMR));
11281128
assert((insCodesMR[ins] != BAD_CODE));
11291129

11301130
return insCodesMR[ins];
@@ -5964,7 +5964,7 @@ const char* emitter::emitXMMregName(unsigned reg)
59645964
};
59655965

59665966
assert(reg < REG_COUNT);
5967-
assert(reg < sizeof(regNames) / sizeof(regNames[0]));
5967+
assert(reg < _countof(regNames));
59685968

59695969
return regNames[reg];
59705970
}
@@ -5986,7 +5986,7 @@ const char* emitter::emitYMMregName(unsigned reg)
59865986
};
59875987

59885988
assert(reg < REG_COUNT);
5989-
assert(reg < sizeof(regNames) / sizeof(regNames[0]));
5989+
assert(reg < _countof(regNames));
59905990

59915991
return regNames[reg];
59925992
}

src/jit/gentree.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static const char* opNames[] = {
221221

222222
const char* GenTree::OpName(genTreeOps op)
223223
{
224-
assert((unsigned)op < sizeof(opNames) / sizeof(opNames[0]));
224+
assert((unsigned)op < _countof(opNames));
225225

226226
return opNames[op];
227227
}
@@ -237,7 +237,7 @@ static const char* opStructNames[] = {
237237

238238
const char* GenTree::OpStructName(genTreeOps op)
239239
{
240-
assert((unsigned)op < sizeof(opStructNames) / sizeof(opStructNames[0]));
240+
assert((unsigned)op < _countof(opStructNames));
241241

242242
return opStructNames[op];
243243
}
@@ -10660,7 +10660,7 @@ int Compiler::gtGetLclVarName(unsigned lclNum, char* buf, unsigned buf_remaining
1066010660
char* Compiler::gtGetLclVarName(unsigned lclNum)
1066110661
{
1066210662
char buf[BUF_SIZE];
10663-
int charsPrinted = gtGetLclVarName(lclNum, buf, sizeof(buf) / sizeof(buf[0]));
10663+
int charsPrinted = gtGetLclVarName(lclNum, buf, _countof(buf));
1066410664
if (charsPrinted < 0)
1066510665
{
1066610666
return nullptr;
@@ -10675,7 +10675,7 @@ char* Compiler::gtGetLclVarName(unsigned lclNum)
1067510675
void Compiler::gtDispLclVar(unsigned lclNum, bool padForBiggestDisp)
1067610676
{
1067710677
char buf[BUF_SIZE];
10678-
int charsPrinted = gtGetLclVarName(lclNum, buf, sizeof(buf) / sizeof(buf[0]));
10678+
int charsPrinted = gtGetLclVarName(lclNum, buf, _countof(buf));
1067910679

1068010680
if (charsPrinted < 0)
1068110681
{

src/jit/importer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17333,11 +17333,11 @@ void Compiler::impImport(BasicBlock* method)
1733317333

1733417334
/* Allocate the stack contents */
1733517335

17336-
if (info.compMaxStack <= sizeof(impSmallStack) / sizeof(impSmallStack[0]))
17336+
if (info.compMaxStack <= _countof(impSmallStack))
1733717337
{
1733817338
/* Use local variable, don't waste time allocating on the heap */
1733917339

17340-
impStkSize = sizeof(impSmallStack) / sizeof(impSmallStack[0]);
17340+
impStkSize = _countof(impSmallStack);
1734117341
verCurrentState.esStack = impSmallStack;
1734217342
}
1734317343
else

src/jit/inline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ void InlineStrategy::DumpXml(FILE* file, unsigned indent)
15451545
strncpy(buf, methodName, sizeof(buf));
15461546
buf[sizeof(buf) - 1] = 0;
15471547

1548-
for (int i = 0; i < sizeof(buf); i++)
1548+
for (int i = 0; i < _countof(buf); i++)
15491549
{
15501550
switch (buf[i])
15511551
{

0 commit comments

Comments
 (0)