[PATCH] drivers/net/hamradio/baycom_epp.c: cleanups

The times when tricky goto's produced better codes are long gone.

This patch should express the same in a better way.

(Also fixes the final gcc-4.0 x86 compile error)

Signed-off-by: Adrian Bunk <bunk@stusta.de>
Cc: Jeff Garzik <jgarzik@pobox.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Adrian Bunk and committed by
Linus Torvalds
0fd56f67 c4eb2a93

+36 -90
+36 -90
drivers/net/hamradio/baycom_epp.c
··· 374 374 } 375 375 376 376 /* --------------------------------------------------------------------- */ 377 - /* 378 - * high performance HDLC encoder 379 - * yes, it's ugly, but generates pretty good code 380 - */ 381 - 382 - #define ENCODEITERA(j) \ 383 - ({ \ 384 - if (!(notbitstream & (0x1f0 << j))) \ 385 - goto stuff##j; \ 386 - encodeend##j: ; \ 387 - }) 388 - 389 - #define ENCODEITERB(j) \ 390 - ({ \ 391 - stuff##j: \ 392 - bitstream &= ~(0x100 << j); \ 393 - bitbuf = (bitbuf & (((2 << j) << numbit) - 1)) | \ 394 - ((bitbuf & ~(((2 << j) << numbit) - 1)) << 1); \ 395 - numbit++; \ 396 - notbitstream = ~bitstream; \ 397 - goto encodeend##j; \ 398 - }) 399 - 400 377 401 378 static void encode_hdlc(struct baycom_state *bc) 402 379 { ··· 382 405 int pkt_len; 383 406 unsigned bitstream, notbitstream, bitbuf, numbit, crc; 384 407 unsigned char crcarr[2]; 408 + int j; 385 409 386 410 if (bc->hdlctx.bufcnt > 0) 387 411 return; ··· 407 429 pkt_len--; 408 430 if (!pkt_len) 409 431 bp = crcarr; 410 - ENCODEITERA(0); 411 - ENCODEITERA(1); 412 - ENCODEITERA(2); 413 - ENCODEITERA(3); 414 - ENCODEITERA(4); 415 - ENCODEITERA(5); 416 - ENCODEITERA(6); 417 - ENCODEITERA(7); 418 - goto enditer; 419 - ENCODEITERB(0); 420 - ENCODEITERB(1); 421 - ENCODEITERB(2); 422 - ENCODEITERB(3); 423 - ENCODEITERB(4); 424 - ENCODEITERB(5); 425 - ENCODEITERB(6); 426 - ENCODEITERB(7); 427 - enditer: 432 + for (j = 0; j < 8; j++) 433 + if (unlikely(!(notbitstream & (0x1f0 << j)))) { 434 + bitstream &= ~(0x100 << j); 435 + bitbuf = (bitbuf & (((2 << j) << numbit) - 1)) | 436 + ((bitbuf & ~(((2 << j) << numbit) - 1)) << 1); 437 + numbit++; 438 + notbitstream = ~bitstream; 439 + } 428 440 numbit += 8; 429 441 while (numbit >= 8) { 430 442 *wp++ = bitbuf; ··· 578 610 bc->stats.rx_packets++; 579 611 } 580 612 581 - #define DECODEITERA(j) \ 582 - ({ \ 583 - if (!(notbitstream & (0x0fc << j))) /* flag or abort */ \ 584 - goto flgabrt##j; \ 585 - if ((bitstream & (0x1f8 << j)) == (0xf8 << j)) /* stuffed bit */ \ 586 - goto stuff##j; \ 587 - enditer##j: ; \ 588 - }) 589 - 590 - #define DECODEITERB(j) \ 591 - ({ \ 592 - flgabrt##j: \ 593 - if (!(notbitstream & (0x1fc << j))) { /* abort received */ \ 594 - state = 0; \ 595 - goto enditer##j; \ 596 - } \ 597 - if ((bitstream & (0x1fe << j)) != (0x0fc << j)) /* flag received */ \ 598 - goto enditer##j; \ 599 - if (state) \ 600 - do_rxpacket(dev); \ 601 - bc->hdlcrx.bufcnt = 0; \ 602 - bc->hdlcrx.bufptr = bc->hdlcrx.buf; \ 603 - state = 1; \ 604 - numbits = 7-j; \ 605 - goto enditer##j; \ 606 - stuff##j: \ 607 - numbits--; \ 608 - bitbuf = (bitbuf & ((~0xff) << j)) | ((bitbuf & ~((~0xff) << j)) << 1); \ 609 - goto enditer##j; \ 610 - }) 611 - 612 613 static int receive(struct net_device *dev, int cnt) 613 614 { 614 615 struct baycom_state *bc = netdev_priv(dev); ··· 586 649 unsigned char tmp[128]; 587 650 unsigned char *cp; 588 651 int cnt2, ret = 0; 652 + int j; 589 653 590 654 numbits = bc->hdlcrx.numbits; 591 655 state = bc->hdlcrx.state; ··· 607 669 bitbuf |= (*cp) << 8; 608 670 numbits += 8; 609 671 notbitstream = ~bitstream; 610 - DECODEITERA(0); 611 - DECODEITERA(1); 612 - DECODEITERA(2); 613 - DECODEITERA(3); 614 - DECODEITERA(4); 615 - DECODEITERA(5); 616 - DECODEITERA(6); 617 - DECODEITERA(7); 618 - goto enddec; 619 - DECODEITERB(0); 620 - DECODEITERB(1); 621 - DECODEITERB(2); 622 - DECODEITERB(3); 623 - DECODEITERB(4); 624 - DECODEITERB(5); 625 - DECODEITERB(6); 626 - DECODEITERB(7); 627 - enddec: 672 + for (j = 0; j < 8; j++) { 673 + 674 + /* flag or abort */ 675 + if (unlikely(!(notbitstream & (0x0fc << j)))) { 676 + 677 + /* abort received */ 678 + if (!(notbitstream & (0x1fc << j))) 679 + state = 0; 680 + 681 + /* not flag received */ 682 + else if (!(bitstream & (0x1fe << j)) != (0x0fc << j)) { 683 + if (state) 684 + do_rxpacket(dev); 685 + bc->hdlcrx.bufcnt = 0; 686 + bc->hdlcrx.bufptr = bc->hdlcrx.buf; 687 + state = 1; 688 + numbits = 7-j; 689 + } 690 + } 691 + 692 + /* stuffed bit */ 693 + else if (unlikely((bitstream & (0x1f8 << j)) == (0xf8 << j))) { 694 + numbits--; 695 + bitbuf = (bitbuf & ((~0xff) << j)) | ((bitbuf & ~((~0xff) << j)) << 1); 696 + } 697 + } 628 698 while (state && numbits >= 8) { 629 699 if (bc->hdlcrx.bufcnt >= TXBUFFER_SIZE) { 630 700 state = 0;