// Note this tracks at most only 256 assertions.
static const AssertionIndex countFunc[] = {64, 128, 256, 64};
static const unsigned lowerBound = 0;
- static const unsigned upperBound = sizeof(countFunc) / sizeof(countFunc[0]) - 1;
+ static const unsigned upperBound = _countof(countFunc) - 1;
const unsigned codeSize = info.compILCodeSize / 512;
optMaxAssertionCount = countFunc[isLocalProp ? lowerBound : min(upperBound, codeSize)];
INS_cmove, INS_cmovne, INS_cmovbe, INS_cmova, INS_cmovs, INS_cmovns,
INS_cmovpe, INS_cmovpo, INS_cmovl, INS_cmovge, INS_cmovle, INS_cmovg};
- noway_assert((unsigned)jumpKind < (sizeof(EJtoCMOV) / sizeof(EJtoCMOV[0])));
+ noway_assert((unsigned)jumpKind < _countof(EJtoCMOV));
instruction cmov_ins = EJtoCMOV[jumpKind];
noway_assert(insIsCMOV(cmov_ins));
extraHdr2);
// Ensure that at least the names array and the Phases enum have the same number of entries:
- assert(sizeof(PhaseNames) / sizeof(const char*) == PHASE_NUMBER_OF);
+ assert(_countof(PhaseNames) == PHASE_NUMBER_OF);
for (int i = 0; i < PHASE_NUMBER_OF; i++)
{
double phase_tot_ms = (((double)m_total.m_cyclesByPhase[i]) / countsPerSec) * 1000.0;
fprintf(f, " PHASE inv/meth Mcycles time (ms) %% of total\n");
fprintf(f, " --------------------------------------------------------------------------------------\n");
// Ensure that at least the names array and the Phases enum have the same number of entries:
- assert(sizeof(PhaseNames) / sizeof(const char*) == PHASE_NUMBER_OF);
+ assert(_countof(PhaseNames) == PHASE_NUMBER_OF);
for (int i = 0; i < PHASE_NUMBER_OF; i++)
{
double phase_tot_ms = (((double)m_filtered.m_cyclesByPhase[i]) / countsPerSec) * 1000.0;
template <class T>
inline unsigned genTypeSize(T type)
{
- assert((unsigned)TypeGet(type) < sizeof(genTypeSizes) / sizeof(genTypeSizes[0]));
+ assert((unsigned)TypeGet(type) < _countof(genTypeSizes));
return genTypeSizes[TypeGet(type)];
}
inline unsigned genTypeStSz(var_types type)
{
- assert((unsigned)type < sizeof(genTypeStSzs) / sizeof(genTypeStSzs[0]));
+ assert((unsigned)type < _countof(genTypeStSzs));
return genTypeStSzs[type];
}
}
wchar_t wz[MAX_CLASSNAME_LENGTH];
- pdis->CchFormatInstr(wz, sizeof(wz) / sizeof(wz[0]));
+ pdis->CchFormatInstr(wz, _countof(wz));
if (printit)
{
wchar_t wzBytes[MAX_CLASSNAME_LENGTH];
assert(cchBytesMax < MAX_CLASSNAME_LENGTH);
- size_t cchBytes = pdis->CchFormatBytes(wzBytes, sizeof(wzBytes) / sizeof(wzBytes[0]));
+ size_t cchBytes = pdis->CchFormatBytes(wzBytes, _countof(wzBytes));
if (cchBytes > CCH_INDENT)
{
wchar_t wz[MAX_CLASSNAME_LENGTH];
- pdis->CchFormatAddr(addr, wz, sizeof(wz) / sizeof(wz[0]));
+ pdis->CchFormatAddr(addr, wz, _countof(wz));
size_t cchIndent = (size_t)fprintf(pfile, " %ls: ", wz);
}
wchar_t wzBytes[64];
- size_t cchBytes = pdis->CchFormatBytes(wzBytes, sizeof(wzBytes) / sizeof(wzBytes[0]));
+ size_t cchBytes = pdis->CchFormatBytes(wzBytes, _countof(wzBytes));
wchar_t* pwzBytes;
wchar_t* pwzNext;
if (fFirst)
{
- pdis->CchFormatInstr(wz, sizeof(wz) / sizeof(wz[0]));
+ pdis->CchFormatInstr(wz, _countof(wz));
fprintf(pfile, "%-*ls %ls\n", cchBytesMax, pwzBytes, wz);
}
static char errBuff[32];
- if (f < sizeof(ifNames) / sizeof(*ifNames))
+ if (f < _countof(ifNames))
{
return ifNames[f];
}
};
#ifdef DEBUG
-const unsigned emitter::emitFmtCount = sizeof(emitFmtToOps) / sizeof(emitFmtToOps[0]);
+const unsigned emitter::emitFmtCount = _countof(emitFmtToOps);
#endif
/*****************************************************************************
// clang-format on
#ifdef DEBUG
-unsigned const emitter::emitInsModeFmtCnt = sizeof(emitInsModeFmtTab) / sizeof(emitInsModeFmtTab[0]);
+unsigned const emitter::emitInsModeFmtCnt = _countof(emitInsModeFmtTab);
#endif
/*****************************************************************************
};
// clang-format on
- assert((unsigned)ins < sizeof(insCodes) / sizeof(insCodes[0]));
+ assert((unsigned)ins < _countof(insCodes));
assert((insCodes[ins] != BAD_CODE));
return insCodes[ins];
};
// clang-format on
- assert((unsigned)ins < sizeof(insCodesACC) / sizeof(insCodesACC[0]));
+ assert((unsigned)ins < _countof(insCodesACC));
assert((insCodesACC[ins] != BAD_CODE));
return insCodesACC[ins];
};
// clang-format on
- assert((unsigned)ins < sizeof(insCodesRR) / sizeof(insCodesRR[0]));
+ assert((unsigned)ins < _countof(insCodesRR));
assert((insCodesRR[ins] != BAD_CODE));
return insCodesRR[ins];
// Returns true iff the give CPU instruction has an RM encoding.
inline bool hasCodeRM(instruction ins)
{
- assert((unsigned)ins < sizeof(insCodesRM) / sizeof(insCodesRM[0]));
+ assert((unsigned)ins < _countof(insCodesRM));
return ((insCodesRM[ins] != BAD_CODE));
}
inline size_t insCodeRM(instruction ins)
{
- assert((unsigned)ins < sizeof(insCodesRM) / sizeof(insCodesRM[0]));
+ assert((unsigned)ins < _countof(insCodesRM));
assert((insCodesRM[ins] != BAD_CODE));
return insCodesRM[ins];
// Returns true iff the give CPU instruction has an MI encoding.
inline bool hasCodeMI(instruction ins)
{
- assert((unsigned)ins < sizeof(insCodesMI) / sizeof(insCodesMI[0]));
+ assert((unsigned)ins < _countof(insCodesMI));
return ((insCodesMI[ins] != BAD_CODE));
}
inline size_t insCodeMI(instruction ins)
{
- assert((unsigned)ins < sizeof(insCodesMI) / sizeof(insCodesMI[0]));
+ assert((unsigned)ins < _countof(insCodesMI));
assert((insCodesMI[ins] != BAD_CODE));
return insCodesMI[ins];
// Returns true iff the give CPU instruction has an MR encoding.
inline bool hasCodeMR(instruction ins)
{
- assert((unsigned)ins < sizeof(insCodesMR) / sizeof(insCodesMR[0]));
+ assert((unsigned)ins < _countof(insCodesMR));
return ((insCodesMR[ins] != BAD_CODE));
}
inline size_t insCodeMR(instruction ins)
{
- assert((unsigned)ins < sizeof(insCodesMR) / sizeof(insCodesMR[0]));
+ assert((unsigned)ins < _countof(insCodesMR));
assert((insCodesMR[ins] != BAD_CODE));
return insCodesMR[ins];
};
assert(reg < REG_COUNT);
- assert(reg < sizeof(regNames) / sizeof(regNames[0]));
+ assert(reg < _countof(regNames));
return regNames[reg];
}
};
assert(reg < REG_COUNT);
- assert(reg < sizeof(regNames) / sizeof(regNames[0]));
+ assert(reg < _countof(regNames));
return regNames[reg];
}
const char* GenTree::OpName(genTreeOps op)
{
- assert((unsigned)op < sizeof(opNames) / sizeof(opNames[0]));
+ assert((unsigned)op < _countof(opNames));
return opNames[op];
}
const char* GenTree::OpStructName(genTreeOps op)
{
- assert((unsigned)op < sizeof(opStructNames) / sizeof(opStructNames[0]));
+ assert((unsigned)op < _countof(opStructNames));
return opStructNames[op];
}
char* Compiler::gtGetLclVarName(unsigned lclNum)
{
char buf[BUF_SIZE];
- int charsPrinted = gtGetLclVarName(lclNum, buf, sizeof(buf) / sizeof(buf[0]));
+ int charsPrinted = gtGetLclVarName(lclNum, buf, _countof(buf));
if (charsPrinted < 0)
{
return nullptr;
void Compiler::gtDispLclVar(unsigned lclNum, bool padForBiggestDisp)
{
char buf[BUF_SIZE];
- int charsPrinted = gtGetLclVarName(lclNum, buf, sizeof(buf) / sizeof(buf[0]));
+ int charsPrinted = gtGetLclVarName(lclNum, buf, _countof(buf));
if (charsPrinted < 0)
{
/* Allocate the stack contents */
- if (info.compMaxStack <= sizeof(impSmallStack) / sizeof(impSmallStack[0]))
+ if (info.compMaxStack <= _countof(impSmallStack))
{
/* Use local variable, don't waste time allocating on the heap */
- impStkSize = sizeof(impSmallStack) / sizeof(impSmallStack[0]);
+ impStkSize = _countof(impSmallStack);
verCurrentState.esStack = impSmallStack;
}
else
strncpy(buf, methodName, sizeof(buf));
buf[sizeof(buf) - 1] = 0;
- for (int i = 0; i < sizeof(buf); i++)
+ for (int i = 0; i < _countof(buf); i++)
{
switch (buf[i])
{
};
// clang-format on
- assert((unsigned)ins < sizeof(insNames) / sizeof(insNames[0]));
+ assert((unsigned)ins < _countof(insNames));
assert(insNames[ins] != nullptr);
return insNames[ins];
// static inline
bool CodeGenInterface::instIsFP(instruction ins)
{
- assert((unsigned)ins < sizeof(instInfo) / sizeof(instInfo[0]));
+ assert((unsigned)ins < _countof(instInfo));
return (instInfo[ins] & INST_FP) != 0;
}
//
static JitPrimeInfo NextPrime(unsigned number)
{
- for (int i = 0; i < (int)(sizeof(jitPrimeInfo) / sizeof(jitPrimeInfo[0])); i++)
+ for (int i = 0; i < (int)(_countof(jitPrimeInfo)); i++)
{
if (jitPrimeInfo[i].prime >= number)
{
alloc_order[cur] = 0;
- noway_assert(cur < sizeof(alloc_order) / sizeof(alloc_order[0]));
+ noway_assert(cur < _countof(alloc_order));
// Force first pass to happen
UINT assignMore = 0xFFFFFFFF;
if (varTypeIsFloating(regType))
{
static const regNumber raRegVarOrderFlt[] = {REG_VAR_ORDER_FLT};
- const unsigned raRegVarOrderFltSize = sizeof(raRegVarOrderFlt) / sizeof(raRegVarOrderFlt[0]);
+ const unsigned raRegVarOrderFltSize = _countof(raRegVarOrderFlt);
if (wbVarOrderSize != NULL)
*wbVarOrderSize = raRegVarOrderFltSize;
#endif
{
static const regNumber raRegVarOrder[] = {REG_VAR_ORDER};
- const unsigned raRegVarOrderSize = sizeof(raRegVarOrder) / sizeof(raRegVarOrder[0]);
+ const unsigned raRegVarOrderSize = _countof(raRegVarOrder);
if (wbVarOrderSize != NULL)
*wbVarOrderSize = raRegVarOrderSize;
RBM_ILLEGAL, // TYP_UNKNOWN,
};
- assert((unsigned)type < sizeof(returnMap) / sizeof(returnMap[0]));
+ assert((unsigned)type < _countof(returnMap));
assert(returnMap[TYP_LONG] == RBM_LNGRET);
assert(returnMap[TYP_DOUBLE] == RBM_DOUBLERET);
assert(returnMap[TYP_REF] == RBM_INTRET);
if (rpHasVarIndexForPredict(predictReg))
predictReg = PREDICT_REG;
- noway_assert((unsigned)predictReg < sizeof(rpPredictMap) / sizeof(rpPredictMap[0]));
+ noway_assert((unsigned)predictReg < _countof(rpPredictMap));
noway_assert(rpPredictMap[predictReg] != RBM_ILLEGAL);
regMaskTP regAvailForType = rpPredictMap[predictReg];
return false;
}
- for (unsigned i = 0; i < sizeof(tmpUsed) / sizeof(tmpUsed[0]); i++)
+ for (unsigned i = 0; i < _countof(tmpUsed); i++)
{
if (tmpUsed[i] != nullptr)
{
// TODO-Throughput: implement product shipping solution to query base type.
WCHAR className[256] = {0};
WCHAR* pbuf = &className[0];
- int len = sizeof(className) / sizeof(className[0]);
+ int len = _countof(className);
info.compCompHnd->appendClassName(&pbuf, &len, typeHnd, TRUE, FALSE, FALSE);
noway_assert(pbuf < &className[256]);
JITDUMP("SIMD Candidate Type %S\n", className);
};
// clang-format on
-static_assert_no_msg(NUM_SM_STATES == sizeof(g_SMStates) / sizeof(g_SMStates[0]));
+static_assert_no_msg(NUM_SM_STATES == _countof(g_SMStates));
const SMState* gp_SMStates = g_SMStates;
DEFAULT_WEIGHT_VALUE, // state 249 [ldarga.s -> ldfld -> ldarga.s -> ldfld -> sub]
};
-static_assert_no_msg(NUM_SM_STATES == sizeof(g_StateWeights) / sizeof(g_StateWeights[0]));
+static_assert_no_msg(NUM_SM_STATES == _countof(g_StateWeights));
const short* gp_StateWeights = g_StateWeights;
assert(mathIns[CORINFO_INTRINSIC_Sqrt] == INS_fsqrt);
assert(mathIns[CORINFO_INTRINSIC_Abs] == INS_fabs);
assert(mathIns[CORINFO_INTRINSIC_Round] == INS_frndint);
- assert((unsigned)(tree->gtIntrinsic.gtIntrinsicId) < sizeof(mathIns) / sizeof(mathIns[0]));
+ assert((unsigned)(tree->gtIntrinsic.gtIntrinsicId) < _countof(mathIns));
instGen(mathIns[tree->gtIntrinsic.gtIntrinsicId]);
// mark register that holds tree
else
{
printf(" --- One epilog, unwind codes at %u\n", epilogCount);
- assert(epilogCount < sizeof(epilogStartAt) / sizeof(epilogStartAt[0]));
+ assert(epilogCount < _countof(epilogStartAt));
epilogStartAt[epilogCount] = true; // the one and only epilog starts its unwind codes at this offset
}
#undef DEF_TP
};
- assert((unsigned)vt < sizeof(varTypeNames) / sizeof(varTypeNames[0]));
+ assert((unsigned)vt < _countof(varTypeNames));
return varTypeNames[vt];
}
#include "valuenumfuncs.h"
#undef ValueNumFuncDef
- unsigned n = sizeof(genTreeOpsIllegalAsVNFunc) / sizeof(genTreeOps);
- for (unsigned i = 0; i < n; i++)
+ for (unsigned i = 0; i < _countof(genTreeOpsIllegalAsVNFunc); i++)
{
vnfOpAttribs[genTreeOpsIllegalAsVNFunc[i]] |= VNFOA_IllegalGenTreeOp;
}