datapath-windows/ovsext/Offload.c
/*
 *----------------------------------------------------------------------------
 * CalculateOnesComplement --
 *
 *  Given the start address and buffer length, calculate the 1's complement
 *  This routine can be used when multiple buffers are used for a packets.
 *
 *  PLEASE NOTE, even though the last parameter is UINT64, but the assumption
 *  is it will not overflowed after adding the extra data.
 *     ------------------------------------------------
 *
 * Result:
 *    As name indicate, the final data is not 1's complemnent
 *----------------------------------------------------------------------------
 */
CalculateOnesComplement
Given the start address and buffer length, calculate the 1's complement
This routine can be used when multiple buffers are used for a packets.

PLEASE NOTE, even though the last parameter is UINT64, but the assumption
is it will not overflowed after adding the extra data.

As name indicate, the final data is not 1's complemnent
CalculateOnesComplement Given the start address and buffer length calculate the 1 ' s complement This routine can be used when multiple buffers are used for a packets . PLEASE NOTE even though the last parameter is UINT64 but the assumption is it will not overflowed after adding the extra data . As name indicate the final data is not 1 ' s complemnent
UINT64
CalculateOnesComplement(UINT8 *start,
                        UINT16 totalLength,
                        UINT64 initial,
                        BOOLEAN isEvenStart)
{
    UINT64  sum = 0, val64;
    UINT64  *src = (UINT64 *)start;
    while (totalLength > 7) {
        val64 = *src;
        sum += val64;
        if (sum < val64) sum++;
        src++;
        totalLength -= 8;
    }
    start = (UINT8 *)src;
    if (totalLength > 3) {
        UINT32 val = *(UINT32 *)start;
        sum += val;
        if (sum < val) sum++;
        start += 4;
        totalLength -= 4;
    }
    if (totalLength > 1) {
        UINT16 val = *(UINT16 *)start;
        sum += val;
        if (sum < val) sum++;
        start += 2;
        totalLength -= 2;
    }
    if (totalLength > 0) {
        UINT8 val = *start;
        sum += val;
        if (sum < val) sum++;
        start += 1;
        totalLength -= 1;
    }
    ASSERT(totalLength == 0);
    if (!isEvenStart) {
        sum = _byteswap_uint64(sum);
    }
    sum += initial;
    if (sum < initial) sum++;
    return sum;
}
UINT64 CalculateOnesComplement ( UINT8 * start , UINT16 totalLength , UINT64 initial , BOOLEAN isEvenStart ) { UINT64 sum = 0 , val64 ; UINT64 * src = ( UINT64 * ) start ; while ( totalLength > 7 ) { val64 = * src ; sum += val64 ; if ( sum < val64 ) sum ++ ; src ++ ; totalLength -= 8 ; } start = ( UINT8 * ) src ; if ( totalLength > 3 ) { UINT32 val = * ( UINT32 * ) start ; sum += val ; if ( sum < val ) sum ++ ; start += 4 ; totalLength -= 4 ; } if ( totalLength > 1 ) { UINT16 val = * ( UINT16 * ) start ; sum += val ; if ( sum < val ) sum ++ ; start += 2 ; totalLength -= 2 ; } if ( totalLength > 0 ) { UINT8 val = * start ; sum += val ; if ( sum < val ) sum ++ ; start += 1 ; totalLength -= 1 ; } ASSERT ( totalLength == 0 ) ; if ( ! isEvenStart ) { sum = _byteswap_uint64 ( sum ) ; } sum += initial ; if ( sum < initial ) sum ++ ; return sum ; }
CalculateOnesComplement
  Given the start address and buffer length, calculate the 1's complement
  This routine can be used when multiple buffers are used for a packets.
CalculateOnesComplement Given the start address and buffer length calculate the 1 ' s complement This routine can be used when multiple buffers are used for a packets .