From 388dfa7112211ab5544079a04de020583c3d5376 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Tue, 24 Sep 1996 17:47:59 +0000 Subject: [PATCH] Fixed a few hundred warnings (2400 in LINT) for signed vs unsigned comparisons in the inb() and outb() macros. I decided that int args are OK here. Any type that can hold a u_int16_t without overflow is correct, and 32-bit types are optimal. Introduced a few tens of warnings (100 in LINT) for use of pessimized (short) types for the port arg. Only a few drivers are affected by this. u_short pessimizations aren't detected. Added `__extension__' before the statement-expression in inb() so that it can be compiled without warnings by gcc -pedantic. --- sys/amd64/include/cpufunc.h | 19 +++++++++++++------ sys/i386/include/cpufunc.h | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/sys/amd64/include/cpufunc.h b/sys/amd64/include/cpufunc.h index 7f23b8ea087..83acd1d6e51 100644 --- a/sys/amd64/include/cpufunc.h +++ b/sys/amd64/include/cpufunc.h @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cpufunc.h,v 1.54 1996/08/01 20:29:28 wollman Exp $ + * $Id: cpufunc.h,v 1.55 1996/09/12 11:08:07 asami Exp $ */ /* @@ -112,18 +112,25 @@ fls(int mask) * Use an expression-statement instead of a conditional expression * because gcc-2.6.0 would promote the operands of the conditional * and produce poor code for "if ((inb(var) & const1) == const2)". + * + * The unnecessary test `(port) < 0x10000' is to generate a warning if + * the `port' has type u_short or smaller. Such types are pessimal. + * This actually only works for signed types. The range check is + * careful to avoid generating warnings. */ -#define inb(port) ({ \ +#define inb(port) __extension__ ({ \ u_char _data; \ - if (__builtin_constant_p((int) (port)) && (port) < 256ul) \ + if (__builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ + && (port) < 0x10000) \ _data = inbc(port); \ else \ _data = inbv(port); \ _data; }) -#define outb(port, data) \ - (__builtin_constant_p((int) (port)) && (port) < 256ul \ - ? outbc(port, data) : outbv(port, data)) +#define outb(port, data) ( \ + __builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ + && (port) < 0x10000 \ + ? outbc(port, data) : outbv(port, data)) static __inline u_char inbc(u_int port) diff --git a/sys/i386/include/cpufunc.h b/sys/i386/include/cpufunc.h index 7f23b8ea087..83acd1d6e51 100644 --- a/sys/i386/include/cpufunc.h +++ b/sys/i386/include/cpufunc.h @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cpufunc.h,v 1.54 1996/08/01 20:29:28 wollman Exp $ + * $Id: cpufunc.h,v 1.55 1996/09/12 11:08:07 asami Exp $ */ /* @@ -112,18 +112,25 @@ fls(int mask) * Use an expression-statement instead of a conditional expression * because gcc-2.6.0 would promote the operands of the conditional * and produce poor code for "if ((inb(var) & const1) == const2)". + * + * The unnecessary test `(port) < 0x10000' is to generate a warning if + * the `port' has type u_short or smaller. Such types are pessimal. + * This actually only works for signed types. The range check is + * careful to avoid generating warnings. */ -#define inb(port) ({ \ +#define inb(port) __extension__ ({ \ u_char _data; \ - if (__builtin_constant_p((int) (port)) && (port) < 256ul) \ + if (__builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ + && (port) < 0x10000) \ _data = inbc(port); \ else \ _data = inbv(port); \ _data; }) -#define outb(port, data) \ - (__builtin_constant_p((int) (port)) && (port) < 256ul \ - ? outbc(port, data) : outbv(port, data)) +#define outb(port, data) ( \ + __builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \ + && (port) < 0x10000 \ + ? outbc(port, data) : outbv(port, data)) static __inline u_char inbc(u_int port)