Print this page
5007142 Add ntohll and htonll to sys/byteorder.h
6717509 Need to use bswap/bswapq for byte swap of 64-bit integer on x32/x64
PSARC 2008/474

Split Close
Expand all
Collapse all
          --- old/usr/src/common/crypto/md5/md5_byteswap.h
          +++ new/usr/src/common/crypto/md5/md5_byteswap.h
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23      - * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
       23 + * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
  27   27  #ifndef _MD5_BYTESWAP_H
  28   28  #define _MD5_BYTESWAP_H
  29   29  
  30      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  31      -
  32   30  /*
  33   31   * definitions for inline functions for little-endian loads.
  34   32   *
  35   33   * This file has special definitions for UltraSPARC architectures,
  36   34   * which have a special address space identifier for loading 32 and 16 bit
  37   35   * integers in little-endian byte order.
  38   36   *
  39   37   * This file and common/crypto/md5/sparc/sun4[uv]/byteswap.il implement the
  40   38   * same thing and must be changed together.
  41   39   */
  42   40  
       41 +#include <sys/types.h>
  43   42  #if defined(__sparc)
  44   43  #include <v9/sys/asi.h>
       44 +#elif defined(_LITTLE_ENDIAN)
       45 +#include <sys/byteorder.h>
  45   46  #endif
  46   47  
  47   48  #ifdef  __cplusplus
  48   49  extern "C" {
  49   50  #endif
  50   51  
  51   52  #if defined(_LITTLE_ENDIAN)
  52   53  
  53   54  /*
  54   55   * Little-endian optimization:  I don't need to do any weirdness.   On
↓ open down ↓ 33 lines elided ↑ open up ↑
  88   89  
  89   90  #if !defined(__lint) && defined(__GNUC__)
  90   91  
  91   92  static __inline__ uint32_t
  92   93  load_little_32(uint32_t *addr)
  93   94  {
  94   95          uint32_t value;
  95   96  
  96   97          __asm__(
  97   98              "lduwa      [%1] %2, %0\n\t"
  98      -        : "=r" (value)
  99      -        : "r" (addr), "i" (ASI_PL));
       99 +            : "=r" (value)
      100 +            : "r" (addr), "i" (ASI_PL));
 100  101  
 101  102          return (value);
 102  103  }
 103      -
 104      -static __inline__ uint16_t
 105      -load_little_16(uint16_t *addr)
 106      -{
 107      -        uint16_t value;
 108      -
 109      -        __asm__(
 110      -            "lduha      [%1] %2, %0\n\t"
 111      -        : "=r" (value)
 112      -        : "r" (addr), "i" (ASI_PL));
 113      -
 114      -        return (value);
 115      -}
 116      -
 117  104  #endif  /* !__lint && __GNUC__ */
 118  105  
 119  106  #if !defined(__GNUC__)
 120  107  extern  uint32_t load_little_32(uint32_t *);
 121  108  #endif  /* !__GNUC__ */
 122  109  
 123  110  /* Placate lint */
 124  111  #if defined(__lint)
 125  112  uint32_t
 126  113  load_little_32(uint32_t *addr)
 127  114  {
 128  115          return (*addr);
 129  116  }
 130  117  #endif  /* __lint */
 131  118  
 132      -#else   /* !sun4u */
      119 +#elif defined(_LITTLE_ENDIAN)
      120 +#define LOAD_LITTLE_32(addr)    htonl(addr)
 133  121  
      122 +#else
 134  123  /* big endian -- will work on little endian, but slowly */
 135  124  /* Since we do byte operations, we don't have to check for alignment. */
 136  125  #define LOAD_LITTLE_32(addr)    \
 137  126          ((addr)[0] | ((addr)[1] << 8) | ((addr)[2] << 16) | ((addr)[3] << 24))
 138      -
 139  127  #endif  /* sun4u */
 140  128  
 141  129  #if defined(sun4v)
 142  130  
 143  131  /*
 144  132   * For N1 want to minimize number of arithmetic operations. This is best
 145  133   * achieved by using the %asi register to specify ASI for the lduwa operations.
 146  134   * Also, have a separate inline template for each word, so can utilize the
 147  135   * immediate offset in lduwa, without relying on the compiler to do the right
 148  136   * thing.
↓ open down ↓ 19 lines elided ↑ open up ↑
 168  156  
 169  157  #if !defined(__lint) && defined(__GNUC__)
 170  158  
 171  159  /*
 172  160   * This actually sets the ASI register, not necessarily to ASI_PL.
 173  161   */
 174  162  static __inline__ void
 175  163  set_little(uint8_t asi)
 176  164  {
 177  165          __asm__ __volatile__(
 178      -                "wr     %%g0, %0, %%asi\n\t"
 179      -        : /* Nothing */
 180      -        : "r" (asi));
      166 +            "wr %%g0, %0, %%asi\n\t"
      167 +            : /* Nothing */
      168 +            : "r" (asi));
 181  169  }
 182  170  
 183  171  static __inline__ uint8_t
 184  172  get_little(void)
 185  173  {
 186  174          uint8_t asi;
 187  175  
 188  176          __asm__ __volatile__(
 189      -                "rd     %%asi, %0\n\t"
 190      -        : "=r" (asi));
      177 +            "rd %%asi, %0\n\t"
      178 +            : "=r" (asi));
 191  179  
 192  180          return (asi);
 193  181  }
 194  182  
 195  183  /*
 196  184   * We have 16 functions which differ only in the offset from which they
 197  185   * load.  Use this preprocessor template to simplify maintenance.  Its
 198  186   * argument is the offset in hex, without the 0x.
 199  187   */
 200  188  #define LL_TEMPLATE(__off)                      \
↓ open down ↓ 68 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX