Re: [2.6 patch] drivers/net/hamradio/baycom_epp.c: cleanups

2005-04-21 Thread Benoit Boissinot
On 4/20/05, Adrian Bunk <[EMAIL PROTECTED]> wrote:
> The times when tricky goto's produced better codes are long gone.
> 
> This patch should express the same in a better way, please check whether
> I made any mistake.
> 

By the way, it solves compile errors with gcc-4:
a lot of
drivers/net/hamradio/baycom_epp.c:690: error: jump into statement expression

regards,

Benoit
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [2.6 patch] drivers/net/hamradio/baycom_epp.c: cleanups

2005-04-21 Thread Benoit Boissinot
On 4/20/05, Adrian Bunk [EMAIL PROTECTED] wrote:
 The times when tricky goto's produced better codes are long gone.
 
 This patch should express the same in a better way, please check whether
 I made any mistake.
 

By the way, it solves compile errors with gcc-4:
a lot of
drivers/net/hamradio/baycom_epp.c:690: error: jump into statement expression

regards,

Benoit
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[2.6 patch] drivers/net/hamradio/baycom_epp.c: cleanups

2005-04-20 Thread Adrian Bunk
The times when tricky goto's produced better codes are long gone.

This patch should express the same in a better way, please check whether 
I made any mistake.

Signed-off-by: Adrian Bunk <[EMAIL PROTECTED]>

---

 drivers/net/hamradio/baycom_epp.c |  126 --
 1 files changed, 36 insertions(+), 90 deletions(-)

--- linux-2.6.12-rc2-mm3/drivers/net/hamradio/baycom_epp.c.old  2005-04-20 
16:18:47.0 +0200
+++ linux-2.6.12-rc2-mm3/drivers/net/hamradio/baycom_epp.c  2005-04-20 
17:14:36.0 +0200
@@ -374,29 +374,6 @@
 }
 
 /* - */
-/*
- * 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)
 {
@@ -405,6 +382,7 @@
int pkt_len;
 unsigned bitstream, notbitstream, bitbuf, numbit, crc;
unsigned char crcarr[2];
+   int j;

if (bc->hdlctx.bufcnt > 0)
return;
@@ -429,24 +407,14 @@
pkt_len--;
if (!pkt_len)
bp = crcarr;
-   ENCODEITERA(0);
-   ENCODEITERA(1);
-   ENCODEITERA(2);
-   ENCODEITERA(3);
-   ENCODEITERA(4);
-   ENCODEITERA(5);
-   ENCODEITERA(6);
-   ENCODEITERA(7);
-   goto enditer;
-   ENCODEITERB(0);
-   ENCODEITERB(1);
-   ENCODEITERB(2);
-   ENCODEITERB(3);
-   ENCODEITERB(4);
-   ENCODEITERB(5);
-   ENCODEITERB(6);
-   ENCODEITERB(7);
-   enditer:
+   for (j = 0; j < 8; j++)
+   if (unlikely(!(notbitstream & (0x1f0 << j {
+   bitstream &= ~(0x100 << j);
+   bitbuf = (bitbuf & (((2 << j) << numbit) - 1)) |
+   ((bitbuf & ~(((2 << j) << numbit) - 1)) 
<< 1);
+   numbit++;
+   notbitstream = ~bitstream;
+   }
numbit += 8;
while (numbit >= 8) {
*wp++ = bitbuf;
@@ -612,37 +580,6 @@
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;

[2.6 patch] drivers/net/hamradio/baycom_epp.c: cleanups

2005-04-20 Thread Adrian Bunk
The times when tricky goto's produced better codes are long gone.

This patch should express the same in a better way, please check whether 
I made any mistake.

Signed-off-by: Adrian Bunk [EMAIL PROTECTED]

---

 drivers/net/hamradio/baycom_epp.c |  126 --
 1 files changed, 36 insertions(+), 90 deletions(-)

--- linux-2.6.12-rc2-mm3/drivers/net/hamradio/baycom_epp.c.old  2005-04-20 
16:18:47.0 +0200
+++ linux-2.6.12-rc2-mm3/drivers/net/hamradio/baycom_epp.c  2005-04-20 
17:14:36.0 +0200
@@ -374,29 +374,6 @@
 }
 
 /* - */
-/*
- * 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)
 {
@@ -405,6 +382,7 @@
int pkt_len;
 unsigned bitstream, notbitstream, bitbuf, numbit, crc;
unsigned char crcarr[2];
+   int j;

if (bc-hdlctx.bufcnt  0)
return;
@@ -429,24 +407,14 @@
pkt_len--;
if (!pkt_len)
bp = crcarr;
-   ENCODEITERA(0);
-   ENCODEITERA(1);
-   ENCODEITERA(2);
-   ENCODEITERA(3);
-   ENCODEITERA(4);
-   ENCODEITERA(5);
-   ENCODEITERA(6);
-   ENCODEITERA(7);
-   goto enditer;
-   ENCODEITERB(0);
-   ENCODEITERB(1);
-   ENCODEITERB(2);
-   ENCODEITERB(3);
-   ENCODEITERB(4);
-   ENCODEITERB(5);
-   ENCODEITERB(6);
-   ENCODEITERB(7);
-   enditer:
+   for (j = 0; j  8; j++)
+   if (unlikely(!(notbitstream  (0x1f0  j {
+   bitstream = ~(0x100  j);
+   bitbuf = (bitbuf  (((2  j)  numbit) - 1)) |
+   ((bitbuf  ~(((2  j)  numbit) - 1)) 
 1);
+   numbit++;
+   notbitstream = ~bitstream;
+   }
numbit += 8;
while (numbit = 8) {
*wp++ = bitbuf;
@@ -612,37 +580,6 @@
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 =