From owner-freebsd-hackers Wed Sep 2 10:03:08 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id KAA23645 for freebsd-hackers-outgoing; Wed, 2 Sep 1998 10:03:08 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from labinfo.iet.unipi.it (labinfo.iet.unipi.it [131.114.9.5]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id KAA23640 for ; Wed, 2 Sep 1998 10:02:59 -0700 (PDT) (envelope-from luigi@labinfo.iet.unipi.it) Received: from localhost (luigi@localhost) by labinfo.iet.unipi.it (8.6.5/8.6.5) id RAA10910; Wed, 2 Sep 1998 17:06:30 +0200 From: Luigi Rizzo Message-Id: <199809021506.RAA10910@labinfo.iet.unipi.it> Subject: bcmp abuse in networking code ? To: hackers@FreeBSD.ORG Date: Wed, 2 Sep 1998 17:06:30 +0200 (MET DST) X-Mailer: ELM [version 2.4 PL23] Content-Type: text Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG poking around in /sys/net and /sys/netinet, i frequently see bcmp() being used to compare ethernet addresses (but not only those). In some cases, even against the ethernet broadcast address. In my revised bridge code i have the following macros #define ETH_MATCH(a,b) ( \ ((unsigned short *)(a))[2] == ((unsigned short *)(b))[2] && \ *((unsigned int *)(a)) == *((unsigned int *)(b)) ) #define IS_ETHER_BROADCAST(a) ( \ *((unsigned int *)(a)) == 0xffffffff && \ ((unsigned short *)(a))[2] == 0xffff ) which seem to do a decent job in terms of performance. On a Pentium90, they save about 40-50 ticks per call, which is not bad considering how frequently they are used on a bridge or on a multicast router. I suppose the macros as above might have some alignment problems on the Alpha, but one could always make them conditionals and resort to the old method for the Alpha. How about putting something similar in, say, sys/net/ethernet.h (and BTW eliminate the useless etherbroadcastaddr[] variable from /sys/net/if_ethersubr.c, whose prototype is in /sys/netinet/if_ether.h where i am not really sure it belongs to!) cheers luigi To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message