Changeset b3956369 in rtems
- Timestamp:
- 09/11/98 13:12:04 (25 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- c5bb1e02
- Parents:
- 0ea9829
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
c/src/exec/libnetworking/netinet/in_cksum_m68k.c
r0ea9829 rb3956369 38 38 #include <sys/mbuf.h> 39 39 40 #if (defined(__GNUC__) && (defined(__mc68000__) || defined(__m68k__)) && (!__mcf5200__)) 40 #if (defined (__mcf5200__)) 41 # define IS_COLDFIRE 1 42 #else 43 # define IS_COLDFIRE 0 44 #endif 41 45 42 46 #define REDUCE { sum = (sum & 0xFFFF) + (sum >> 16); if (sum > 0xFFFF) sum -= 0xFFFF; } … … 110 114 */ 111 115 { 112 unsigned long tcnt = mlen, t1 ;116 unsigned long tcnt = mlen, t1, t2; 113 117 __asm__ volatile ( 114 118 "movel %2,%3\n\t" … … 116 120 "andl #0x3c,%3 | Then find fractions of a chunk\n\t" 117 121 "negl %3\n\t | Each long uses 4 instruction bytes\n\t" 122 #if IS_COLDFIRE 123 "move %%cc,%4 | Move the CC into a temp reg\n\t" 124 "andil #0xf,%4 | Clear X (extended carry flag)\n\t" 125 "move %4,%%cc | Move the modified value back to the cc\n\t" 126 #else 118 127 "andi #0xf,%%cc | Clear X (extended carry flag)\n\t" 128 #endif 119 129 "jmp %%pc@(lcsum2_lbl-.-2:b,%3) | Jump into loop\n" 120 "lcsum1_lbl: | Begin inner loop...\n\t"130 "lcsum1_lbl: | Begin inner loop...\n\t" 121 131 "movel %1@+,%3 | 0: Fetch 32-bit word\n\t" 122 132 "addxl %3,%0 | Add word + previous carry\n\t" … … 151 161 "movel %1@+,%3 | F: Fetch 32-bit word\n\t" 152 162 "addxl %3,%0 | Add word + previous carry\n" 153 "lcsum2_lbl:\n\tdbf %2,lcsum1_lbl | (NB- dbra doesn't affect X)\n\t" 154 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 155 "swap %3 | (NB- swap doesn't affect X)\n\t" 156 "addxw %3,%0 |\n\t" 157 "moveq #0,%3 | Add in last carry\n\t" 158 "addxw %3,%0 |\n\t" 163 "lcsum2_lbl: | End of unrolled loop\n\t" 164 #if IS_COLDFIRE 165 "moveq #0,%3 | Add in last carry\n\t" 166 "addxl %3,%0 |\n\t" 167 "subql #1,%2 | Update loop count\n\t" 168 "bplb lcsum1_lbl | Loop (with X clear) if not done\n\t" 169 "movel #0xffff,%2 | Get word mask\n\t" 170 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 171 "swap %3 |\n\t" 172 "andl %2,%0 |\n\t" 173 "andl %2,%3 |\n\t" 174 "addl %3,%0 |\n\t" 175 "movel %0,%3 | Add in last carry\n\t" 176 "swap %3 |\n\t" 177 "addl %3,%0 |\n\t" 178 #else 179 "dbf %2,lcsum1_lbl | (NB- dbf doesn't affect X)\n\t" 180 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 181 "swap %3 | (NB- swap doesn't affect X)\n\t" 182 "addxw %3,%0 |\n\t" 183 "moveq #0,%3 | Add in last carry\n\t" 184 "addxw %3,%0 |\n\t" 185 #endif 159 186 "andl #0xffff,%0 | Mask to 16-bit sum\n" : 160 "=d" (sum), "=a" (w), "=d" (tcnt) , "=d" (t1) :187 "=d" (sum), "=a" (w), "=d" (tcnt) , "=d" (t1), "=d" (t2) : 161 188 "0" (sum), "1" (w), "2" (tcnt) : 162 189 "cc", "memory"); … … 194 221 return (~sum & 0xffff); 195 222 } 196 197 198 #else199 /*200 * Checksum routine for Internet Protocol family headers (Portable Version).201 *202 * This routine is very heavily used in the network203 * code and should be modified for each CPU to be as fast as possible.204 */205 206 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)207 #define REDUCE \208 {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);}209 210 int211 in_cksum(m, len)212 register struct mbuf *m;213 register int len;214 {215 register u_short *w;216 register int sum = 0;217 register int mlen = 0;218 int byte_swapped = 0;219 220 union {221 char c[2];222 u_short s;223 } s_util;224 union {225 u_short s[2];226 long l;227 } l_util;228 229 for (;m && len; m = m->m_next) {230 if (m->m_len == 0)231 continue;232 w = mtod(m, u_short *);233 if (mlen == -1) {234 /*235 * The first byte of this mbuf is the continuation236 * of a word spanning between this mbuf and the237 * last mbuf.238 *239 * s_util.c[0] is already saved when scanning previous240 * mbuf.241 */242 s_util.c[1] = *(char *)w;243 sum += s_util.s;244 w = (u_short *)((char *)w + 1);245 mlen = m->m_len - 1;246 len--;247 } else248 mlen = m->m_len;249 if (len < mlen)250 mlen = len;251 len -= mlen;252 /*253 * Force to even boundary.254 */255 if ((1 & (int) w) && (mlen > 0)) {256 REDUCE;257 sum <<= 8;258 s_util.c[0] = *(u_char *)w;259 w = (u_short *)((char *)w + 1);260 mlen--;261 byte_swapped = 1;262 }263 /*264 * Unroll the loop to make overhead from265 * branches &c small.266 */267 while ((mlen -= 32) >= 0) {268 sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];269 sum += w[4]; sum += w[5]; sum += w[6]; sum += w[7];270 sum += w[8]; sum += w[9]; sum += w[10]; sum += w[11];271 sum += w[12]; sum += w[13]; sum += w[14]; sum += w[15];272 w += 16;273 }274 mlen += 32;275 while ((mlen -= 8) >= 0) {276 sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];277 w += 4;278 }279 mlen += 8;280 if (mlen == 0 && byte_swapped == 0)281 continue;282 REDUCE;283 while ((mlen -= 2) >= 0) {284 sum += *w++;285 }286 if (byte_swapped) {287 REDUCE;288 sum <<= 8;289 byte_swapped = 0;290 if (mlen == -1) {291 s_util.c[1] = *(char *)w;292 sum += s_util.s;293 mlen = 0;294 } else295 mlen = -1;296 } else if (mlen == -1)297 s_util.c[0] = *(char *)w;298 }299 if (len)300 printf("cksum: out of data\n");301 if (mlen == -1) {302 /* The last mbuf has odd # of bytes. Follow the303 standard (the odd byte may be shifted left by 8 bits304 or not as determined by endian-ness of the machine) */305 s_util.c[1] = 0;306 sum += s_util.s;307 }308 REDUCE;309 return (~sum & 0xffff);310 }311 #endif -
c/src/lib/libnetworking/netinet/in_cksum_m68k.c
r0ea9829 rb3956369 38 38 #include <sys/mbuf.h> 39 39 40 #if (defined(__GNUC__) && (defined(__mc68000__) || defined(__m68k__)) && (!__mcf5200__)) 40 #if (defined (__mcf5200__)) 41 # define IS_COLDFIRE 1 42 #else 43 # define IS_COLDFIRE 0 44 #endif 41 45 42 46 #define REDUCE { sum = (sum & 0xFFFF) + (sum >> 16); if (sum > 0xFFFF) sum -= 0xFFFF; } … … 110 114 */ 111 115 { 112 unsigned long tcnt = mlen, t1 ;116 unsigned long tcnt = mlen, t1, t2; 113 117 __asm__ volatile ( 114 118 "movel %2,%3\n\t" … … 116 120 "andl #0x3c,%3 | Then find fractions of a chunk\n\t" 117 121 "negl %3\n\t | Each long uses 4 instruction bytes\n\t" 122 #if IS_COLDFIRE 123 "move %%cc,%4 | Move the CC into a temp reg\n\t" 124 "andil #0xf,%4 | Clear X (extended carry flag)\n\t" 125 "move %4,%%cc | Move the modified value back to the cc\n\t" 126 #else 118 127 "andi #0xf,%%cc | Clear X (extended carry flag)\n\t" 128 #endif 119 129 "jmp %%pc@(lcsum2_lbl-.-2:b,%3) | Jump into loop\n" 120 "lcsum1_lbl: | Begin inner loop...\n\t"130 "lcsum1_lbl: | Begin inner loop...\n\t" 121 131 "movel %1@+,%3 | 0: Fetch 32-bit word\n\t" 122 132 "addxl %3,%0 | Add word + previous carry\n\t" … … 151 161 "movel %1@+,%3 | F: Fetch 32-bit word\n\t" 152 162 "addxl %3,%0 | Add word + previous carry\n" 153 "lcsum2_lbl:\n\tdbf %2,lcsum1_lbl | (NB- dbra doesn't affect X)\n\t" 154 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 155 "swap %3 | (NB- swap doesn't affect X)\n\t" 156 "addxw %3,%0 |\n\t" 157 "moveq #0,%3 | Add in last carry\n\t" 158 "addxw %3,%0 |\n\t" 163 "lcsum2_lbl: | End of unrolled loop\n\t" 164 #if IS_COLDFIRE 165 "moveq #0,%3 | Add in last carry\n\t" 166 "addxl %3,%0 |\n\t" 167 "subql #1,%2 | Update loop count\n\t" 168 "bplb lcsum1_lbl | Loop (with X clear) if not done\n\t" 169 "movel #0xffff,%2 | Get word mask\n\t" 170 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 171 "swap %3 |\n\t" 172 "andl %2,%0 |\n\t" 173 "andl %2,%3 |\n\t" 174 "addl %3,%0 |\n\t" 175 "movel %0,%3 | Add in last carry\n\t" 176 "swap %3 |\n\t" 177 "addl %3,%0 |\n\t" 178 #else 179 "dbf %2,lcsum1_lbl | (NB- dbf doesn't affect X)\n\t" 180 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 181 "swap %3 | (NB- swap doesn't affect X)\n\t" 182 "addxw %3,%0 |\n\t" 183 "moveq #0,%3 | Add in last carry\n\t" 184 "addxw %3,%0 |\n\t" 185 #endif 159 186 "andl #0xffff,%0 | Mask to 16-bit sum\n" : 160 "=d" (sum), "=a" (w), "=d" (tcnt) , "=d" (t1) :187 "=d" (sum), "=a" (w), "=d" (tcnt) , "=d" (t1), "=d" (t2) : 161 188 "0" (sum), "1" (w), "2" (tcnt) : 162 189 "cc", "memory"); … … 194 221 return (~sum & 0xffff); 195 222 } 196 197 198 #else199 /*200 * Checksum routine for Internet Protocol family headers (Portable Version).201 *202 * This routine is very heavily used in the network203 * code and should be modified for each CPU to be as fast as possible.204 */205 206 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)207 #define REDUCE \208 {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);}209 210 int211 in_cksum(m, len)212 register struct mbuf *m;213 register int len;214 {215 register u_short *w;216 register int sum = 0;217 register int mlen = 0;218 int byte_swapped = 0;219 220 union {221 char c[2];222 u_short s;223 } s_util;224 union {225 u_short s[2];226 long l;227 } l_util;228 229 for (;m && len; m = m->m_next) {230 if (m->m_len == 0)231 continue;232 w = mtod(m, u_short *);233 if (mlen == -1) {234 /*235 * The first byte of this mbuf is the continuation236 * of a word spanning between this mbuf and the237 * last mbuf.238 *239 * s_util.c[0] is already saved when scanning previous240 * mbuf.241 */242 s_util.c[1] = *(char *)w;243 sum += s_util.s;244 w = (u_short *)((char *)w + 1);245 mlen = m->m_len - 1;246 len--;247 } else248 mlen = m->m_len;249 if (len < mlen)250 mlen = len;251 len -= mlen;252 /*253 * Force to even boundary.254 */255 if ((1 & (int) w) && (mlen > 0)) {256 REDUCE;257 sum <<= 8;258 s_util.c[0] = *(u_char *)w;259 w = (u_short *)((char *)w + 1);260 mlen--;261 byte_swapped = 1;262 }263 /*264 * Unroll the loop to make overhead from265 * branches &c small.266 */267 while ((mlen -= 32) >= 0) {268 sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];269 sum += w[4]; sum += w[5]; sum += w[6]; sum += w[7];270 sum += w[8]; sum += w[9]; sum += w[10]; sum += w[11];271 sum += w[12]; sum += w[13]; sum += w[14]; sum += w[15];272 w += 16;273 }274 mlen += 32;275 while ((mlen -= 8) >= 0) {276 sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];277 w += 4;278 }279 mlen += 8;280 if (mlen == 0 && byte_swapped == 0)281 continue;282 REDUCE;283 while ((mlen -= 2) >= 0) {284 sum += *w++;285 }286 if (byte_swapped) {287 REDUCE;288 sum <<= 8;289 byte_swapped = 0;290 if (mlen == -1) {291 s_util.c[1] = *(char *)w;292 sum += s_util.s;293 mlen = 0;294 } else295 mlen = -1;296 } else if (mlen == -1)297 s_util.c[0] = *(char *)w;298 }299 if (len)300 printf("cksum: out of data\n");301 if (mlen == -1) {302 /* The last mbuf has odd # of bytes. Follow the303 standard (the odd byte may be shifted left by 8 bits304 or not as determined by endian-ness of the machine) */305 s_util.c[1] = 0;306 sum += s_util.s;307 }308 REDUCE;309 return (~sum & 0xffff);310 }311 #endif -
c/src/libnetworking/netinet/in_cksum_m68k.c
r0ea9829 rb3956369 38 38 #include <sys/mbuf.h> 39 39 40 #if (defined(__GNUC__) && (defined(__mc68000__) || defined(__m68k__)) && (!__mcf5200__)) 40 #if (defined (__mcf5200__)) 41 # define IS_COLDFIRE 1 42 #else 43 # define IS_COLDFIRE 0 44 #endif 41 45 42 46 #define REDUCE { sum = (sum & 0xFFFF) + (sum >> 16); if (sum > 0xFFFF) sum -= 0xFFFF; } … … 110 114 */ 111 115 { 112 unsigned long tcnt = mlen, t1 ;116 unsigned long tcnt = mlen, t1, t2; 113 117 __asm__ volatile ( 114 118 "movel %2,%3\n\t" … … 116 120 "andl #0x3c,%3 | Then find fractions of a chunk\n\t" 117 121 "negl %3\n\t | Each long uses 4 instruction bytes\n\t" 122 #if IS_COLDFIRE 123 "move %%cc,%4 | Move the CC into a temp reg\n\t" 124 "andil #0xf,%4 | Clear X (extended carry flag)\n\t" 125 "move %4,%%cc | Move the modified value back to the cc\n\t" 126 #else 118 127 "andi #0xf,%%cc | Clear X (extended carry flag)\n\t" 128 #endif 119 129 "jmp %%pc@(lcsum2_lbl-.-2:b,%3) | Jump into loop\n" 120 "lcsum1_lbl: | Begin inner loop...\n\t"130 "lcsum1_lbl: | Begin inner loop...\n\t" 121 131 "movel %1@+,%3 | 0: Fetch 32-bit word\n\t" 122 132 "addxl %3,%0 | Add word + previous carry\n\t" … … 151 161 "movel %1@+,%3 | F: Fetch 32-bit word\n\t" 152 162 "addxl %3,%0 | Add word + previous carry\n" 153 "lcsum2_lbl:\n\tdbf %2,lcsum1_lbl | (NB- dbra doesn't affect X)\n\t" 154 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 155 "swap %3 | (NB- swap doesn't affect X)\n\t" 156 "addxw %3,%0 |\n\t" 157 "moveq #0,%3 | Add in last carry\n\t" 158 "addxw %3,%0 |\n\t" 163 "lcsum2_lbl: | End of unrolled loop\n\t" 164 #if IS_COLDFIRE 165 "moveq #0,%3 | Add in last carry\n\t" 166 "addxl %3,%0 |\n\t" 167 "subql #1,%2 | Update loop count\n\t" 168 "bplb lcsum1_lbl | Loop (with X clear) if not done\n\t" 169 "movel #0xffff,%2 | Get word mask\n\t" 170 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 171 "swap %3 |\n\t" 172 "andl %2,%0 |\n\t" 173 "andl %2,%3 |\n\t" 174 "addl %3,%0 |\n\t" 175 "movel %0,%3 | Add in last carry\n\t" 176 "swap %3 |\n\t" 177 "addl %3,%0 |\n\t" 178 #else 179 "dbf %2,lcsum1_lbl | (NB- dbf doesn't affect X)\n\t" 180 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 181 "swap %3 | (NB- swap doesn't affect X)\n\t" 182 "addxw %3,%0 |\n\t" 183 "moveq #0,%3 | Add in last carry\n\t" 184 "addxw %3,%0 |\n\t" 185 #endif 159 186 "andl #0xffff,%0 | Mask to 16-bit sum\n" : 160 "=d" (sum), "=a" (w), "=d" (tcnt) , "=d" (t1) :187 "=d" (sum), "=a" (w), "=d" (tcnt) , "=d" (t1), "=d" (t2) : 161 188 "0" (sum), "1" (w), "2" (tcnt) : 162 189 "cc", "memory"); … … 194 221 return (~sum & 0xffff); 195 222 } 196 197 198 #else199 /*200 * Checksum routine for Internet Protocol family headers (Portable Version).201 *202 * This routine is very heavily used in the network203 * code and should be modified for each CPU to be as fast as possible.204 */205 206 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)207 #define REDUCE \208 {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);}209 210 int211 in_cksum(m, len)212 register struct mbuf *m;213 register int len;214 {215 register u_short *w;216 register int sum = 0;217 register int mlen = 0;218 int byte_swapped = 0;219 220 union {221 char c[2];222 u_short s;223 } s_util;224 union {225 u_short s[2];226 long l;227 } l_util;228 229 for (;m && len; m = m->m_next) {230 if (m->m_len == 0)231 continue;232 w = mtod(m, u_short *);233 if (mlen == -1) {234 /*235 * The first byte of this mbuf is the continuation236 * of a word spanning between this mbuf and the237 * last mbuf.238 *239 * s_util.c[0] is already saved when scanning previous240 * mbuf.241 */242 s_util.c[1] = *(char *)w;243 sum += s_util.s;244 w = (u_short *)((char *)w + 1);245 mlen = m->m_len - 1;246 len--;247 } else248 mlen = m->m_len;249 if (len < mlen)250 mlen = len;251 len -= mlen;252 /*253 * Force to even boundary.254 */255 if ((1 & (int) w) && (mlen > 0)) {256 REDUCE;257 sum <<= 8;258 s_util.c[0] = *(u_char *)w;259 w = (u_short *)((char *)w + 1);260 mlen--;261 byte_swapped = 1;262 }263 /*264 * Unroll the loop to make overhead from265 * branches &c small.266 */267 while ((mlen -= 32) >= 0) {268 sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];269 sum += w[4]; sum += w[5]; sum += w[6]; sum += w[7];270 sum += w[8]; sum += w[9]; sum += w[10]; sum += w[11];271 sum += w[12]; sum += w[13]; sum += w[14]; sum += w[15];272 w += 16;273 }274 mlen += 32;275 while ((mlen -= 8) >= 0) {276 sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];277 w += 4;278 }279 mlen += 8;280 if (mlen == 0 && byte_swapped == 0)281 continue;282 REDUCE;283 while ((mlen -= 2) >= 0) {284 sum += *w++;285 }286 if (byte_swapped) {287 REDUCE;288 sum <<= 8;289 byte_swapped = 0;290 if (mlen == -1) {291 s_util.c[1] = *(char *)w;292 sum += s_util.s;293 mlen = 0;294 } else295 mlen = -1;296 } else if (mlen == -1)297 s_util.c[0] = *(char *)w;298 }299 if (len)300 printf("cksum: out of data\n");301 if (mlen == -1) {302 /* The last mbuf has odd # of bytes. Follow the303 standard (the odd byte may be shifted left by 8 bits304 or not as determined by endian-ness of the machine) */305 s_util.c[1] = 0;306 sum += s_util.s;307 }308 REDUCE;309 return (~sum & 0xffff);310 }311 #endif -
cpukit/libnetworking/netinet/in_cksum_m68k.c
r0ea9829 rb3956369 38 38 #include <sys/mbuf.h> 39 39 40 #if (defined(__GNUC__) && (defined(__mc68000__) || defined(__m68k__)) && (!__mcf5200__)) 40 #if (defined (__mcf5200__)) 41 # define IS_COLDFIRE 1 42 #else 43 # define IS_COLDFIRE 0 44 #endif 41 45 42 46 #define REDUCE { sum = (sum & 0xFFFF) + (sum >> 16); if (sum > 0xFFFF) sum -= 0xFFFF; } … … 110 114 */ 111 115 { 112 unsigned long tcnt = mlen, t1 ;116 unsigned long tcnt = mlen, t1, t2; 113 117 __asm__ volatile ( 114 118 "movel %2,%3\n\t" … … 116 120 "andl #0x3c,%3 | Then find fractions of a chunk\n\t" 117 121 "negl %3\n\t | Each long uses 4 instruction bytes\n\t" 122 #if IS_COLDFIRE 123 "move %%cc,%4 | Move the CC into a temp reg\n\t" 124 "andil #0xf,%4 | Clear X (extended carry flag)\n\t" 125 "move %4,%%cc | Move the modified value back to the cc\n\t" 126 #else 118 127 "andi #0xf,%%cc | Clear X (extended carry flag)\n\t" 128 #endif 119 129 "jmp %%pc@(lcsum2_lbl-.-2:b,%3) | Jump into loop\n" 120 "lcsum1_lbl: | Begin inner loop...\n\t"130 "lcsum1_lbl: | Begin inner loop...\n\t" 121 131 "movel %1@+,%3 | 0: Fetch 32-bit word\n\t" 122 132 "addxl %3,%0 | Add word + previous carry\n\t" … … 151 161 "movel %1@+,%3 | F: Fetch 32-bit word\n\t" 152 162 "addxl %3,%0 | Add word + previous carry\n" 153 "lcsum2_lbl:\n\tdbf %2,lcsum1_lbl | (NB- dbra doesn't affect X)\n\t" 154 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 155 "swap %3 | (NB- swap doesn't affect X)\n\t" 156 "addxw %3,%0 |\n\t" 157 "moveq #0,%3 | Add in last carry\n\t" 158 "addxw %3,%0 |\n\t" 163 "lcsum2_lbl: | End of unrolled loop\n\t" 164 #if IS_COLDFIRE 165 "moveq #0,%3 | Add in last carry\n\t" 166 "addxl %3,%0 |\n\t" 167 "subql #1,%2 | Update loop count\n\t" 168 "bplb lcsum1_lbl | Loop (with X clear) if not done\n\t" 169 "movel #0xffff,%2 | Get word mask\n\t" 170 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 171 "swap %3 |\n\t" 172 "andl %2,%0 |\n\t" 173 "andl %2,%3 |\n\t" 174 "addl %3,%0 |\n\t" 175 "movel %0,%3 | Add in last carry\n\t" 176 "swap %3 |\n\t" 177 "addl %3,%0 |\n\t" 178 #else 179 "dbf %2,lcsum1_lbl | (NB- dbf doesn't affect X)\n\t" 180 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 181 "swap %3 | (NB- swap doesn't affect X)\n\t" 182 "addxw %3,%0 |\n\t" 183 "moveq #0,%3 | Add in last carry\n\t" 184 "addxw %3,%0 |\n\t" 185 #endif 159 186 "andl #0xffff,%0 | Mask to 16-bit sum\n" : 160 "=d" (sum), "=a" (w), "=d" (tcnt) , "=d" (t1) :187 "=d" (sum), "=a" (w), "=d" (tcnt) , "=d" (t1), "=d" (t2) : 161 188 "0" (sum), "1" (w), "2" (tcnt) : 162 189 "cc", "memory"); … … 194 221 return (~sum & 0xffff); 195 222 } 196 197 198 #else199 /*200 * Checksum routine for Internet Protocol family headers (Portable Version).201 *202 * This routine is very heavily used in the network203 * code and should be modified for each CPU to be as fast as possible.204 */205 206 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)207 #define REDUCE \208 {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);}209 210 int211 in_cksum(m, len)212 register struct mbuf *m;213 register int len;214 {215 register u_short *w;216 register int sum = 0;217 register int mlen = 0;218 int byte_swapped = 0;219 220 union {221 char c[2];222 u_short s;223 } s_util;224 union {225 u_short s[2];226 long l;227 } l_util;228 229 for (;m && len; m = m->m_next) {230 if (m->m_len == 0)231 continue;232 w = mtod(m, u_short *);233 if (mlen == -1) {234 /*235 * The first byte of this mbuf is the continuation236 * of a word spanning between this mbuf and the237 * last mbuf.238 *239 * s_util.c[0] is already saved when scanning previous240 * mbuf.241 */242 s_util.c[1] = *(char *)w;243 sum += s_util.s;244 w = (u_short *)((char *)w + 1);245 mlen = m->m_len - 1;246 len--;247 } else248 mlen = m->m_len;249 if (len < mlen)250 mlen = len;251 len -= mlen;252 /*253 * Force to even boundary.254 */255 if ((1 & (int) w) && (mlen > 0)) {256 REDUCE;257 sum <<= 8;258 s_util.c[0] = *(u_char *)w;259 w = (u_short *)((char *)w + 1);260 mlen--;261 byte_swapped = 1;262 }263 /*264 * Unroll the loop to make overhead from265 * branches &c small.266 */267 while ((mlen -= 32) >= 0) {268 sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];269 sum += w[4]; sum += w[5]; sum += w[6]; sum += w[7];270 sum += w[8]; sum += w[9]; sum += w[10]; sum += w[11];271 sum += w[12]; sum += w[13]; sum += w[14]; sum += w[15];272 w += 16;273 }274 mlen += 32;275 while ((mlen -= 8) >= 0) {276 sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];277 w += 4;278 }279 mlen += 8;280 if (mlen == 0 && byte_swapped == 0)281 continue;282 REDUCE;283 while ((mlen -= 2) >= 0) {284 sum += *w++;285 }286 if (byte_swapped) {287 REDUCE;288 sum <<= 8;289 byte_swapped = 0;290 if (mlen == -1) {291 s_util.c[1] = *(char *)w;292 sum += s_util.s;293 mlen = 0;294 } else295 mlen = -1;296 } else if (mlen == -1)297 s_util.c[0] = *(char *)w;298 }299 if (len)300 printf("cksum: out of data\n");301 if (mlen == -1) {302 /* The last mbuf has odd # of bytes. Follow the303 standard (the odd byte may be shifted left by 8 bits304 or not as determined by endian-ness of the machine) */305 s_util.c[1] = 0;306 sum += s_util.s;307 }308 REDUCE;309 return (~sum & 0xffff);310 }311 #endif -
cpukit/libnetworking/netinet/in_cksum_m68k.h
r0ea9829 rb3956369 38 38 #include <sys/mbuf.h> 39 39 40 #if (defined(__GNUC__) && (defined(__mc68000__) || defined(__m68k__)) && (!__mcf5200__)) 40 #if (defined (__mcf5200__)) 41 # define IS_COLDFIRE 1 42 #else 43 # define IS_COLDFIRE 0 44 #endif 41 45 42 46 #define REDUCE { sum = (sum & 0xFFFF) + (sum >> 16); if (sum > 0xFFFF) sum -= 0xFFFF; } … … 110 114 */ 111 115 { 112 unsigned long tcnt = mlen, t1 ;116 unsigned long tcnt = mlen, t1, t2; 113 117 __asm__ volatile ( 114 118 "movel %2,%3\n\t" … … 116 120 "andl #0x3c,%3 | Then find fractions of a chunk\n\t" 117 121 "negl %3\n\t | Each long uses 4 instruction bytes\n\t" 122 #if IS_COLDFIRE 123 "move %%cc,%4 | Move the CC into a temp reg\n\t" 124 "andil #0xf,%4 | Clear X (extended carry flag)\n\t" 125 "move %4,%%cc | Move the modified value back to the cc\n\t" 126 #else 118 127 "andi #0xf,%%cc | Clear X (extended carry flag)\n\t" 128 #endif 119 129 "jmp %%pc@(lcsum2_lbl-.-2:b,%3) | Jump into loop\n" 120 "lcsum1_lbl: | Begin inner loop...\n\t"130 "lcsum1_lbl: | Begin inner loop...\n\t" 121 131 "movel %1@+,%3 | 0: Fetch 32-bit word\n\t" 122 132 "addxl %3,%0 | Add word + previous carry\n\t" … … 151 161 "movel %1@+,%3 | F: Fetch 32-bit word\n\t" 152 162 "addxl %3,%0 | Add word + previous carry\n" 153 "lcsum2_lbl:\n\tdbf %2,lcsum1_lbl | (NB- dbra doesn't affect X)\n\t" 154 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 155 "swap %3 | (NB- swap doesn't affect X)\n\t" 156 "addxw %3,%0 |\n\t" 157 "moveq #0,%3 | Add in last carry\n\t" 158 "addxw %3,%0 |\n\t" 163 "lcsum2_lbl: | End of unrolled loop\n\t" 164 #if IS_COLDFIRE 165 "moveq #0,%3 | Add in last carry\n\t" 166 "addxl %3,%0 |\n\t" 167 "subql #1,%2 | Update loop count\n\t" 168 "bplb lcsum1_lbl | Loop (with X clear) if not done\n\t" 169 "movel #0xffff,%2 | Get word mask\n\t" 170 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 171 "swap %3 |\n\t" 172 "andl %2,%0 |\n\t" 173 "andl %2,%3 |\n\t" 174 "addl %3,%0 |\n\t" 175 "movel %0,%3 | Add in last carry\n\t" 176 "swap %3 |\n\t" 177 "addl %3,%0 |\n\t" 178 #else 179 "dbf %2,lcsum1_lbl | (NB- dbf doesn't affect X)\n\t" 180 "movel %0,%3 | Fold 32 bit sum to 16 bits\n\t" 181 "swap %3 | (NB- swap doesn't affect X)\n\t" 182 "addxw %3,%0 |\n\t" 183 "moveq #0,%3 | Add in last carry\n\t" 184 "addxw %3,%0 |\n\t" 185 #endif 159 186 "andl #0xffff,%0 | Mask to 16-bit sum\n" : 160 "=d" (sum), "=a" (w), "=d" (tcnt) , "=d" (t1) :187 "=d" (sum), "=a" (w), "=d" (tcnt) , "=d" (t1), "=d" (t2) : 161 188 "0" (sum), "1" (w), "2" (tcnt) : 162 189 "cc", "memory"); … … 194 221 return (~sum & 0xffff); 195 222 } 196 197 198 #else199 /*200 * Checksum routine for Internet Protocol family headers (Portable Version).201 *202 * This routine is very heavily used in the network203 * code and should be modified for each CPU to be as fast as possible.204 */205 206 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)207 #define REDUCE \208 {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);}209 210 int211 in_cksum(m, len)212 register struct mbuf *m;213 register int len;214 {215 register u_short *w;216 register int sum = 0;217 register int mlen = 0;218 int byte_swapped = 0;219 220 union {221 char c[2];222 u_short s;223 } s_util;224 union {225 u_short s[2];226 long l;227 } l_util;228 229 for (;m && len; m = m->m_next) {230 if (m->m_len == 0)231 continue;232 w = mtod(m, u_short *);233 if (mlen == -1) {234 /*235 * The first byte of this mbuf is the continuation236 * of a word spanning between this mbuf and the237 * last mbuf.238 *239 * s_util.c[0] is already saved when scanning previous240 * mbuf.241 */242 s_util.c[1] = *(char *)w;243 sum += s_util.s;244 w = (u_short *)((char *)w + 1);245 mlen = m->m_len - 1;246 len--;247 } else248 mlen = m->m_len;249 if (len < mlen)250 mlen = len;251 len -= mlen;252 /*253 * Force to even boundary.254 */255 if ((1 & (int) w) && (mlen > 0)) {256 REDUCE;257 sum <<= 8;258 s_util.c[0] = *(u_char *)w;259 w = (u_short *)((char *)w + 1);260 mlen--;261 byte_swapped = 1;262 }263 /*264 * Unroll the loop to make overhead from265 * branches &c small.266 */267 while ((mlen -= 32) >= 0) {268 sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];269 sum += w[4]; sum += w[5]; sum += w[6]; sum += w[7];270 sum += w[8]; sum += w[9]; sum += w[10]; sum += w[11];271 sum += w[12]; sum += w[13]; sum += w[14]; sum += w[15];272 w += 16;273 }274 mlen += 32;275 while ((mlen -= 8) >= 0) {276 sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3];277 w += 4;278 }279 mlen += 8;280 if (mlen == 0 && byte_swapped == 0)281 continue;282 REDUCE;283 while ((mlen -= 2) >= 0) {284 sum += *w++;285 }286 if (byte_swapped) {287 REDUCE;288 sum <<= 8;289 byte_swapped = 0;290 if (mlen == -1) {291 s_util.c[1] = *(char *)w;292 sum += s_util.s;293 mlen = 0;294 } else295 mlen = -1;296 } else if (mlen == -1)297 s_util.c[0] = *(char *)w;298 }299 if (len)300 printf("cksum: out of data\n");301 if (mlen == -1) {302 /* The last mbuf has odd # of bytes. Follow the303 standard (the odd byte may be shifted left by 8 bits304 or not as determined by endian-ness of the machine) */305 s_util.c[1] = 0;306 sum += s_util.s;307 }308 REDUCE;309 return (~sum & 0xffff);310 }311 #endif
Note: See TracChangeset
for help on using the changeset viewer.