Changeset d8e44ec in rtems


Ignore:
Timestamp:
Feb 5, 2013, 5:03:30 PM (7 years ago)
Author:
Jeffrey O. Hill <hill@…>
Branches:
4.11, master
Children:
3ac61e52
Parents:
fad2d38
git-author:
Jeffrey O. Hill <hill@…> (02/05/13 17:03:30)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/11/13 16:57:41)
Message:

nios2: Add optimized IP checksum support

Location:
cpukit/libnetworking
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libnetworking/machine/in_cksum.h

    rfad2d38 rd8e44ec  
    11/*
     2 * Nios II version by Jeffrey O. Hill
     3 *
     4 * Copyright 2012. Los Alamos National Security, LLC.
     5 * The Nios II specific part was produced under U.S. Government contract
     6 * DE-AC52-06NA25396 for Los Alamos National Laboratory (LANL),
     7 * which is operated by Los Alamos National Security, LLC for
     8 * the U.S. Department of Energy. The U.S. Government has rights
     9 * to use, reproduce, and distribute this software.  NEITHER THE
     10 * GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC MAKES ANY
     11 * WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR
     12 * THE USE OF THIS SOFTWARE.
     13 *
    214 * Copyright (c) 1990 The Regents of the University of California.
    315 * All rights reserved.
     
    209221                ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16)); \
    210222        } while(0)
     223
     224/*
     225 *  Optimized version for the Altera Nios II softcore
     226 */
     227#elif defined ( __GNUC__ ) && defined ( __nios2__ )
     228
     229static inline uint32_t _NIOS2_Add_ones_complement ( const uint32_t a,
     230                                                    const uint32_t b )
     231{
     232  uint32_t sum;
     233  uint32_t C;
     234  __asm__ __volatile__ (
     235              "   add     %0, %2, %3  \n" /* sum <= a + b */
     236              "   cmpltu  %1, %0, %2  \n" /* C <= carryBit32 */
     237              "   add     %0, %1, %0  \n" /* sum <= sum + C */
     238              : "=&r"(sum), "=&r"(C)
     239              : "r"(a), "r"(b)
     240  );
     241  return sum;
     242}
     243
     244static inline uint16_t _NIOS2_Add_ones_complement_word_halves
     245                                                ( const uint32_t a )
     246{
     247  uint16_t sum;
     248  uint32_t tmp;
     249  __asm__ __volatile__ (
     250              "   roli    %1, %2, 16   \n"  /* tmp <= a rotate left 16 */
     251              "   add     %1, %2, %1   \n"  /* tmp <= a + tmp + carryBit16 */
     252              "   srli    %0, %1, 16   \n"  /* sum <= tmp shift right 16 */
     253              : "=&r"(sum),"=&r"(tmp)
     254              : "r"(a)
     255  );
     256  return sum;
     257}
     258
     259static __inline u_int in_cksum_hdr ( const struct ip * pHdrIP )
     260{
     261  const uint32_t * const pWd = ( const uint32_t * ) pHdrIP;
     262  uint32_t sum = pWd[0];
     263  sum = _NIOS2_Add_ones_complement ( sum, pWd[1] );
     264  sum = _NIOS2_Add_ones_complement ( sum, pWd[2] );
     265  sum = _NIOS2_Add_ones_complement ( sum, pWd[3] );
     266  sum = _NIOS2_Add_ones_complement ( sum, pWd[4] );
     267  sum = _NIOS2_Add_ones_complement_word_halves ( sum );
     268  sum ^= 0xffff;
     269  return sum;
     270}
     271
     272static __inline void in_cksum_update ( struct ip * pHdrIP )
     273{
     274  uint32_t __tmpsum = ntohs ( pHdrIP->ip_sum );
     275  __tmpsum += 256u;
     276  __tmpsum += __tmpsum >> 16u;
     277  pHdrIP->ip_sum = htons ( ( uint16_t ) __tmpsum );
     278}
     279
    211280/*
    212281 *  Here is the generic, portable, inefficient algorithm.
  • cpukit/libnetworking/netinet/in_cksum.c

    rfad2d38 rd8e44ec  
    5757
    5858#include "in_cksum_powerpc.h"
     59
     60#elif (defined(__GNUC__) && defined(__nios2__))
     61
     62#include "in_cksum_nios2.h"
    5963
    6064#else
Note: See TracChangeset for help on using the changeset viewer.