third_party/virtualbox/src/VBox/Devices/Network/DevE1000.cpp
/**
 * Search register table for matching register.
 *
 * @returns Index in the register table or -1 if not found.
 *
 * @param   offReg      Register offset in memory-mapped region.
 * @thread  EMT
 */
Search register table for matching register.
@returns Index in the register table or -1 if not found.

@param   offReg      Register offset in memory-mapped region.
@thread  EMT
Search register table for matching register . @returns Index in the register table or - 1 if not found . @param offReg Register offset in memory - mapped region . @thread EMT
static int e1kRegLookup(uint32_t offReg)
{
#if 0
    int index;
    for (index = 0; index < E1K_NUM_OF_REGS; index++)
    {
        if (g_aE1kRegMap[index].offset <= offReg && offReg < g_aE1kRegMap[index].offset + g_aE1kRegMap[index].size)
        {
            return index;
        }
    }
#else
    int iStart = 0;
    int iEnd   = E1K_NUM_OF_BINARY_SEARCHABLE;
    for (;;)
    {
        int i = (iEnd - iStart) / 2 + iStart;
        uint32_t offCur = g_aE1kRegMap[i].offset;
        if (offReg < offCur)
        {
            if (i == iStart)
                break;
            iEnd = i;
        }
        else if (offReg >= offCur + g_aE1kRegMap[i].size)
        {
            i++;
            if (i == iEnd)
                break;
            iStart = i;
        }
        else
            return i;
        Assert(iEnd > iStart);
    }
    for (unsigned i = E1K_NUM_OF_BINARY_SEARCHABLE; i < RT_ELEMENTS(g_aE1kRegMap); i++)
        if (offReg - g_aE1kRegMap[i].offset < g_aE1kRegMap[i].size)
            return i;
# ifdef VBOX_STRICT
    for (unsigned i = 0; i < RT_ELEMENTS(g_aE1kRegMap); i++)
        Assert(offReg - g_aE1kRegMap[i].offset >= g_aE1kRegMap[i].size);
# endif
#endif
    return -1;
}
static int e1kRegLookup ( uint32_t offReg ) { #if 0 int index ; for ( index = 0 ; index < E1K_NUM_OF_REGS ; index ++ ) { if ( g_aE1kRegMap [ index ] . offset <= offReg && offReg < g_aE1kRegMap [ index ] . offset + g_aE1kRegMap [ index ] . size ) { return index ; } } #else int iStart = 0 ; int iEnd = E1K_NUM_OF_BINARY_SEARCHABLE ; for ( ; ; ) { int i = ( iEnd - iStart ) / 2 + iStart ; uint32_t offCur = g_aE1kRegMap [ i ] . offset ; if ( offReg < offCur ) { if ( i == iStart ) break ; iEnd = i ; } else if ( offReg >= offCur + g_aE1kRegMap [ i ] . size ) { i ++ ; if ( i == iEnd ) break ; iStart = i ; } else return i ; Assert ( iEnd > iStart ) ; } for ( unsigned i = E1K_NUM_OF_BINARY_SEARCHABLE ; i < RT_ELEMENTS ( g_aE1kRegMap ) ; i ++ ) if ( offReg - g_aE1kRegMap [ i ] . offset < g_aE1kRegMap [ i ] . size ) return i ; # ifdef VBOX_STRICT for ( unsigned i = 0 ; i < RT_ELEMENTS ( g_aE1kRegMap ) ; i ++ ) Assert ( offReg - g_aE1kRegMap [ i ] . offset >= g_aE1kRegMap [ i ] . size ) ; # endif #endif return -1 ; }
Search register table for matching register.
Search register table for matching register .