datapath-windows/ovsext/Offload.c
/*
 *----------------------------------------------------------------------------
 * CopyAndCalculateOnesComplement --
 *
 *  Given the start address and buffer length, calculate the 1's complement
 *  at same time, copt the data from src to dst.
 *
 *  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
 *----------------------------------------------------------------------------
 */
CopyAndCalculateOnesComplement
Given the start address and buffer length, calculate the 1's complement
at same time, copt the data from src to dst.

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
CopyAndCalculateOnesComplement Given the start address and buffer length calculate the 1 ' s complement at same time copt the data from src to dst . 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
CopyAndCalculateOnesComplement(UINT8 *dst,
                               UINT8 *src,
                               UINT16 length,
                               UINT64 initial,
                               BOOLEAN isEvenStart)
{
    UINT64  sum =0, val;
    UINT64 *src64, *dst64;
    union {
        UINT32 val;
        UINT8  b8[4];
    } tmp;
    src64 = (UINT64 *)src;
    dst64 = (UINT64 *)dst;
    while (length > 7) {
        val = *src64;
        *dst64 = val;
        sum += (val >> 32) + (val & 0xffffffff);
        src64++;
        dst64++;
        length -= 8;
    }
    if (length > 3) {
        val = *(UINT32 *)src64;
        *(UINT32 *)dst64 = (UINT32)val;
        sum += (UINT32)val;
        dst64 = (UINT64 *)((UINT8 *)dst64 + 4);
        src64 = (UINT64 *)((UINT8 *)src64 + 4);
        length -= 4;
    }
    src = (UINT8 *)src64;
    dst = (UINT8 *)dst64;
    tmp.val = 0;
    switch (length) {
    case 3:
        dst[2] = src[2];
        tmp.b8[2] = src[2];
    case 2:
        dst[1] = src[1];
        tmp.b8[1] = src[1];
    case 1:
        dst[0] = src[0];
        tmp.b8[0] = src[0];
        sum += tmp.val;
    }
    sum = (isEvenStart ? sum : swap64(sum)) + initial;
    return sum;
}
UINT64 CopyAndCalculateOnesComplement ( UINT8 * dst , UINT8 * src , UINT16 length , UINT64 initial , BOOLEAN isEvenStart ) { UINT64 sum = 0 , val ; UINT64 * src64 , * dst64 ; union { UINT32 val ; UINT8 b8 [ 4 ] ; } tmp ; src64 = ( UINT64 * ) src ; dst64 = ( UINT64 * ) dst ; while ( length > 7 ) { val = * src64 ; * dst64 = val ; sum += ( val >> 32 ) + ( val & 0xffffffff ) ; src64 ++ ; dst64 ++ ; length -= 8 ; } if ( length > 3 ) { val = * ( UINT32 * ) src64 ; * ( UINT32 * ) dst64 = ( UINT32 ) val ; sum += ( UINT32 ) val ; dst64 = ( UINT64 * ) ( ( UINT8 * ) dst64 + 4 ) ; src64 = ( UINT64 * ) ( ( UINT8 * ) src64 + 4 ) ; length -= 4 ; } src = ( UINT8 * ) src64 ; dst = ( UINT8 * ) dst64 ; tmp . val = 0 ; switch ( length ) { case 3 : dst [ 2 ] = src [ 2 ] ; tmp . b8 [ 2 ] = src [ 2 ] ; case 2 : dst [ 1 ] = src [ 1 ] ; tmp . b8 [ 1 ] = src [ 1 ] ; case 1 : dst [ 0 ] = src [ 0 ] ; tmp . b8 [ 0 ] = src [ 0 ] ; sum += tmp . val ; } sum = ( isEvenStart ? sum : swap64 ( sum ) ) + initial ; return sum ; }
CopyAndCalculateOnesComplement
  Given the start address and buffer length, calculate the 1's complement
  at same time, copt the data from src to dst.
CopyAndCalculateOnesComplement Given the start address and buffer length calculate the 1 ' s complement at same time copt the data from src to dst .