Deleted Added
sdiff udiff text old ( 313537 ) new ( 327234 )
full compact
1/*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and

--- 6 unchanged lines hidden (view full) ---

15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22/*
23 * Macros to extract possibly-unaligned big-endian integral values.
24 */
25#ifdef LBL_ALIGN
26/*
27 * The processor doesn't natively handle unaligned loads.
28 */
29#if defined(__GNUC__) && defined(HAVE___ATTRIBUTE__) && \
30 (defined(__alpha) || defined(__alpha__) || \
31 defined(__mips) || defined(__mips__))
32
33/*
34 * This is a GCC-compatible compiler and we have __attribute__, which
35 * we assume that mean we have __attribute__((packed)), and this is
36 * MIPS or Alpha, which has instructions that can help when doing
37 * unaligned loads.
38 *
39 * Declare packed structures containing a uint16_t and a uint32_t,
40 * cast the pointer to point to one of those, and fetch through it;
41 * the GCC manual doesn't appear to explicitly say that
42 * __attribute__((packed)) causes the compiler to generate unaligned-safe

--- 40 unchanged lines hidden (view full) ---

83typedef struct {
84 uint16_t val;
85} __attribute__((packed)) unaligned_uint16_t;
86
87typedef struct {
88 uint32_t val;
89} __attribute__((packed)) unaligned_uint32_t;
90
91static inline uint16_t
92EXTRACT_16BITS(const void *p)
93{
94 return ((uint16_t)ntohs(((const unaligned_uint16_t *)(p))->val));
95}
96
97static inline uint32_t
98EXTRACT_32BITS(const void *p)
99{
100 return ((uint32_t)ntohl(((const unaligned_uint32_t *)(p))->val));
101}
102
103static inline uint64_t
104EXTRACT_64BITS(const void *p)
105{
106 return ((uint64_t)(((uint64_t)ntohl(((const unaligned_uint32_t *)(p) + 0)->val)) << 32 |
107 ((uint64_t)ntohl(((const unaligned_uint32_t *)(p) + 1)->val)) << 0));
108}
109
110#else /* have to do it a byte at a time */
111/*

--- 21 unchanged lines hidden (view full) ---

133 ((uint64_t)(*((const uint8_t *)(p) + 6)) << 8) | \
134 ((uint64_t)(*((const uint8_t *)(p) + 7)) << 0)))
135#endif /* must special-case unaligned accesses */
136#else /* LBL_ALIGN */
137/*
138 * The processor natively handles unaligned loads, so we can just
139 * cast the pointer and fetch through it.
140 */
141static inline uint16_t
142EXTRACT_16BITS(const void *p)
143{
144 return ((uint16_t)ntohs(*(const uint16_t *)(p)));
145}
146
147static inline uint32_t
148EXTRACT_32BITS(const void *p)
149{
150 return ((uint32_t)ntohl(*(const uint32_t *)(p)));
151}
152
153static inline uint64_t
154EXTRACT_64BITS(const void *p)
155{
156 return ((uint64_t)(((uint64_t)ntohl(*((const uint32_t *)(p) + 0))) << 32 |
157 ((uint64_t)ntohl(*((const uint32_t *)(p) + 1))) << 0));
158
159}
160
161#endif /* LBL_ALIGN */

--- 26 unchanged lines hidden (view full) ---

188 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 16) | \
189 ((uint64_t)(*((const uint8_t *)(p) + 5)) << 8) | \
190 ((uint64_t)(*((const uint8_t *)(p) + 6)) << 0)))
191
192/*
193 * Macros to extract possibly-unaligned little-endian integral values.
194 * XXX - do loads on little-endian machines that support unaligned loads?
195 */
196#define EXTRACT_LE_8BITS(p) (*(p))
197#define EXTRACT_LE_16BITS(p) \
198 ((uint16_t)(((uint16_t)(*((const uint8_t *)(p) + 1)) << 8) | \
199 ((uint16_t)(*((const uint8_t *)(p) + 0)) << 0)))
200#define EXTRACT_LE_32BITS(p) \
201 ((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 3)) << 24) | \
202 ((uint32_t)(*((const uint8_t *)(p) + 2)) << 16) | \
203 ((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
204 ((uint32_t)(*((const uint8_t *)(p) + 0)) << 0)))

--- 32 unchanged lines hidden (view full) ---

237#define ND_TTEST_48BITS(p) ND_TTEST2(*(p), 6)
238#define ND_TCHECK_48BITS(p) ND_TCHECK2(*(p), 6)
239
240#define ND_TTEST_56BITS(p) ND_TTEST2(*(p), 7)
241#define ND_TCHECK_56BITS(p) ND_TCHECK2(*(p), 7)
242
243#define ND_TTEST_64BITS(p) ND_TTEST2(*(p), 8)
244#define ND_TCHECK_64BITS(p) ND_TCHECK2(*(p), 8)