Commit 0fd56f67 authored by Adrian Bunk's avatar Adrian Bunk Committed by Linus Torvalds

[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: default avatarAdrian Bunk <bunk@stusta.de>
Cc: Jeff Garzik <jgarzik@pobox.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent c4eb2a93
...@@ -374,29 +374,6 @@ static inline void do_kiss_params(struct baycom_state *bc, ...@@ -374,29 +374,6 @@ static inline void do_kiss_params(struct baycom_state *bc,
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/*
* high performance HDLC encoder
* yes, it's ugly, but generates pretty good code
*/
#define ENCODEITERA(j) \
({ \
if (!(notbitstream & (0x1f0 << j))) \
goto stuff##j; \
encodeend##j: ; \
})
#define ENCODEITERB(j) \
({ \
stuff##j: \
bitstream &= ~(0x100 << j); \
bitbuf = (bitbuf & (((2 << j) << numbit) - 1)) | \
((bitbuf & ~(((2 << j) << numbit) - 1)) << 1); \
numbit++; \
notbitstream = ~bitstream; \
goto encodeend##j; \
})
static void encode_hdlc(struct baycom_state *bc) static void encode_hdlc(struct baycom_state *bc)
{ {
...@@ -405,6 +382,7 @@ static void encode_hdlc(struct baycom_state *bc) ...@@ -405,6 +382,7 @@ static void encode_hdlc(struct baycom_state *bc)
int pkt_len; int pkt_len;
unsigned bitstream, notbitstream, bitbuf, numbit, crc; unsigned bitstream, notbitstream, bitbuf, numbit, crc;
unsigned char crcarr[2]; unsigned char crcarr[2];
int j;
if (bc->hdlctx.bufcnt > 0) if (bc->hdlctx.bufcnt > 0)
return; return;
...@@ -429,24 +407,14 @@ static void encode_hdlc(struct baycom_state *bc) ...@@ -429,24 +407,14 @@ static void encode_hdlc(struct baycom_state *bc)
pkt_len--; pkt_len--;
if (!pkt_len) if (!pkt_len)
bp = crcarr; bp = crcarr;
ENCODEITERA(0); for (j = 0; j < 8; j++)
ENCODEITERA(1); if (unlikely(!(notbitstream & (0x1f0 << j)))) {
ENCODEITERA(2); bitstream &= ~(0x100 << j);
ENCODEITERA(3); bitbuf = (bitbuf & (((2 << j) << numbit) - 1)) |
ENCODEITERA(4); ((bitbuf & ~(((2 << j) << numbit) - 1)) << 1);
ENCODEITERA(5); numbit++;
ENCODEITERA(6); notbitstream = ~bitstream;
ENCODEITERA(7); }
goto enditer;
ENCODEITERB(0);
ENCODEITERB(1);
ENCODEITERB(2);
ENCODEITERB(3);
ENCODEITERB(4);
ENCODEITERB(5);
ENCODEITERB(6);
ENCODEITERB(7);
enditer:
numbit += 8; numbit += 8;
while (numbit >= 8) { while (numbit >= 8) {
*wp++ = bitbuf; *wp++ = bitbuf;
...@@ -610,37 +578,6 @@ static void do_rxpacket(struct net_device *dev) ...@@ -610,37 +578,6 @@ static void do_rxpacket(struct net_device *dev)
bc->stats.rx_packets++; bc->stats.rx_packets++;
} }
#define DECODEITERA(j) \
({ \
if (!(notbitstream & (0x0fc << j))) /* flag or abort */ \
goto flgabrt##j; \
if ((bitstream & (0x1f8 << j)) == (0xf8 << j)) /* stuffed bit */ \
goto stuff##j; \
enditer##j: ; \
})
#define DECODEITERB(j) \
({ \
flgabrt##j: \
if (!(notbitstream & (0x1fc << j))) { /* abort received */ \
state = 0; \
goto enditer##j; \
} \
if ((bitstream & (0x1fe << j)) != (0x0fc << j)) /* flag received */ \
goto enditer##j; \
if (state) \
do_rxpacket(dev); \
bc->hdlcrx.bufcnt = 0; \
bc->hdlcrx.bufptr = bc->hdlcrx.buf; \
state = 1; \
numbits = 7-j; \
goto enditer##j; \
stuff##j: \
numbits--; \
bitbuf = (bitbuf & ((~0xff) << j)) | ((bitbuf & ~((~0xff) << j)) << 1); \
goto enditer##j; \
})
static int receive(struct net_device *dev, int cnt) static int receive(struct net_device *dev, int cnt)
{ {
struct baycom_state *bc = netdev_priv(dev); struct baycom_state *bc = netdev_priv(dev);
...@@ -649,6 +586,7 @@ static int receive(struct net_device *dev, int cnt) ...@@ -649,6 +586,7 @@ static int receive(struct net_device *dev, int cnt)
unsigned char tmp[128]; unsigned char tmp[128];
unsigned char *cp; unsigned char *cp;
int cnt2, ret = 0; int cnt2, ret = 0;
int j;
numbits = bc->hdlcrx.numbits; numbits = bc->hdlcrx.numbits;
state = bc->hdlcrx.state; state = bc->hdlcrx.state;
...@@ -669,24 +607,32 @@ static int receive(struct net_device *dev, int cnt) ...@@ -669,24 +607,32 @@ static int receive(struct net_device *dev, int cnt)
bitbuf |= (*cp) << 8; bitbuf |= (*cp) << 8;
numbits += 8; numbits += 8;
notbitstream = ~bitstream; notbitstream = ~bitstream;
DECODEITERA(0); for (j = 0; j < 8; j++) {
DECODEITERA(1);
DECODEITERA(2); /* flag or abort */
DECODEITERA(3); if (unlikely(!(notbitstream & (0x0fc << j)))) {
DECODEITERA(4);
DECODEITERA(5); /* abort received */
DECODEITERA(6); if (!(notbitstream & (0x1fc << j)))
DECODEITERA(7); state = 0;
goto enddec;
DECODEITERB(0); /* not flag received */
DECODEITERB(1); else if (!(bitstream & (0x1fe << j)) != (0x0fc << j)) {
DECODEITERB(2); if (state)
DECODEITERB(3); do_rxpacket(dev);
DECODEITERB(4); bc->hdlcrx.bufcnt = 0;
DECODEITERB(5); bc->hdlcrx.bufptr = bc->hdlcrx.buf;
DECODEITERB(6); state = 1;
DECODEITERB(7); numbits = 7-j;
enddec: }
}
/* stuffed bit */
else if (unlikely((bitstream & (0x1f8 << j)) == (0xf8 << j))) {
numbits--;
bitbuf = (bitbuf & ((~0xff) << j)) | ((bitbuf & ~((~0xff) << j)) << 1);
}
}
while (state && numbits >= 8) { while (state && numbits >= 8) {
if (bc->hdlcrx.bufcnt >= TXBUFFER_SIZE) { if (bc->hdlcrx.bufcnt >= TXBUFFER_SIZE) {
state = 0; state = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment