[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MiNT 1.10: some optimizations



bios.c:
- do_bconin: use a separate variable for the return value from ioctl
so that r can go into a register.

biosfs.c:
- bios_fscntl, bios_ioctl: use switch instead of if/else if chain

context.spp:
- restore_context: delete unnessesary branch instruction

file.h:
- follow_links: make it a special value instead of a static variable,
since only its address used

filesys.c:
- follow_links: deleted
- ext_paths: make it const

intr.spp:
change `move.w #0,-(sp)' to `clr.w -(sp)' on the 68030, where it is
faster. Not a big win, though :-)

mem.c:
- VgetSize, Vsetmode: use trap_14_ww with gcc

pipefs.c:
- pipe_ioctl: use switch instead of if/else if chain

signal.c:
- check_sigs: don't mask curproc->sigpending twice

syscall.spp:
change `move.w #0,-(sp)' into `clr.w -(sp)' and use index scale on the
68030
- call_dosound: save one instruction. Hey, what the heck! :-)

tosfs.c:
- tos_ioctl: use switch instead of if/else if chain

unifs.c:
- uni_fscntl: same here

util.c:
- mth_start: make it const

-------------------- cut here --------------------
diff -ur orig/bios.c ./bios.c
--- orig/bios.c	Fri Feb 11 19:16:12 1994
+++ ./bios.c	Thu Feb 17 20:51:24 1994
@@ -723,14 +723,15 @@
 {
 	FILEPTR *f;
 	long r;
+	long nread;
 	unsigned char c;
 
 	if (dev < MAX_BHANDLE) {
 		f = curproc->handle[binput[dev]];
 		if (!f) return 0;
-		r = 0;
-		(void)(*f->dev->ioctl)(f, FIONREAD, &r);
-		if (!r) return WOULDBLOCK;	/* data not ready */
+		nread = 0;
+		(void)(*f->dev->ioctl)(f, FIONREAD, &nread);
+		if (!nread) return WOULDBLOCK;	/* data not ready */
 		if (is_terminal(f))
 			r = tty_getchar(f, RAW);
 		else {
diff -ur orig/biosfs.c ./biosfs.c
--- orig/biosfs.c	Fri Feb 11 21:03:02 1994
+++ ./biosfs.c	Thu Feb 17 20:58:18 1994
@@ -746,7 +746,9 @@
 	if (IS_FD_DIR(dir))
 		return EACCDN;
 
-	if ((unsigned)cmd == DEV_INSTALL) {
+	switch ((unsigned) cmd) {
+	case DEV_INSTALL:
+	    {
 		struct dev_descr *d = (struct dev_descr *)arg;
 
 		b = kmalloc(SIZEOF(struct bios_file));
@@ -762,8 +764,9 @@
 		set_xattr(&(b->xattr), S_IFCHR|DEFAULT_MODE, UNK_RDEV|devindex);
 		devindex = (devindex+1) & 0x00ff;
 		return (long)&kernelinfo;
-	}
-	if ((unsigned)cmd == DEV_NEWTTY) {
+	    }
+	case DEV_NEWTTY:
+	    {
 		b = kmalloc(SIZEOF(struct bios_file));
 		if (!b) return ENSMEM;
 		b->tty = kmalloc(SIZEOF(struct tty));
@@ -781,8 +784,9 @@
 		broot = b;
 		set_xattr(&(b->xattr), S_IFCHR|DEFAULT_MODE, BIOS_RDEV|(b->private&0x00ff));
 		return 0;
-	}
-	if ((unsigned)cmd == DEV_NEWBIOS) {
+	    }
+	case DEV_NEWBIOS:
+	    {
 		b = kmalloc(SIZEOF(struct bios_file));
 		if (!b) return ENSMEM;
 		strncpy(b->name, name, BNAME_MAX);
@@ -795,6 +799,7 @@
 		broot = b;
 		set_xattr(&(b->xattr), S_IFCHR|DEFAULT_MODE, BIOS_RDEV|(b->private&0x00ff));
 		return 0;
+	    }
 	}
 	return EINVFN;
 }
@@ -1260,19 +1265,21 @@
 	int i;
 	struct bios_file *b;
 
-	if (mode == FIONREAD) {
+	switch (mode) {
+	case FIONREAD:
 		if (bconstat(f->fc.aux))
 			*r = 1;
 		else
 			*r = 0;
-	}
-	else if (mode == FIONWRITE) {
+		break;
+	case FIONWRITE:
 		if (bcostat(f->fc.aux))
 			*r = 1;
 		else
 			*r = 0;
-	}
-	else if (mode == TIOCFLUSH) {
+		break;
+	case TIOCFLUSH:
+	    {
 		int oldmap;
 		IOREC_T *ior;
 		int flushtype;
@@ -1320,8 +1327,9 @@
 			}
 		}
 		return 0;
-	}
-	else if (mode == TIOCOUTQ) {
+	    }
+	case TIOCOUTQ:
+	    {
 		int oldmap;
 		IOREC_T *ior;
 
@@ -1343,13 +1351,18 @@
  		else
 			*r = 0;
 		return 0;
-	}
-	else if (mode == TIOCGWINSZ && f->fc.aux == 2) {
+	    }
+	case TIOCGWINSZ:
+		if (f->fc.aux != 2)
+		  return EINVFN;
 		aline = lineA0();
 		ws = (struct winsize *)buf;
 		ws->ws_row = *((short *)(aline - 42)) + 1;
 		ws->ws_col = *((short *)(aline - 44)) + 1;
-	} else if (mode == TIOCIBAUD || mode == TIOCOBAUD) {
+		break;
+	case TIOCIBAUD:
+	case TIOCOBAUD:
+	    {
 		long oldbaud, newbaud;
 		int oldmap;
 
@@ -1412,7 +1425,10 @@
 		if (newbaud > 0 && newbaud != oldbaud)
 			return ERANGE;
 		return 0;
-	} else if (mode == TIOCCBRK || mode == TIOCSBRK) {
+	    }
+	case TIOCCBRK:
+	case TIOCSBRK:
+	    {
 		unsigned long bits;
 
 		dev = f->fc.aux;
@@ -1429,7 +1445,11 @@
 		else
 			bits |= 8;
 		(void)rsconf(-1, -1, -1, -1, (int)bits, -1);
-	} else if (mode == TIOCGFLAGS || mode == TIOCSFLAGS) {
+		break;
+	    }
+	case TIOCGFLAGS:
+	case TIOCSFLAGS:
+	    {
 		unsigned short oflags, flags, *sgflags;
 		unsigned long bits;
 		unsigned char ucr;
@@ -1473,18 +1493,32 @@
 		} else {
 			return EINVFN;
 		}
-	} else if ((mode >= TCURSOFF && mode <= TCURSSTEADY) && (f->fc.aux == 2)) {
+		break;
+	    }
+	case TCURSOFF:
+	case TCURSON:
+	case TCURSBLINK:
+	case TCURSSTEADY:
+		if (f->fc.aux != 2)
+		  return EINVFN;
 		return Cursconf(mode - TCURSOFF, 0);
-	} else if ((mode >= TCURSSRATE && mode <= TCURSGRATE) && (f->fc.aux == 2)) {
+	case TCURSSRATE:
+	case TCURSGRATE:
+	    {
 		long r;
 
+		if (f->fc.aux != 2)
+		  return EINVFN;
 		r = Cursconf(mode - TCURSOFF, *((short *)buf));
 		if (r >= 0) {
 			*(short *)buf = r;
 			r = 0;
 		}
 		return r;
-	} else if (mode == F_SETLK || mode == F_SETLKW) {
+	    }
+	case F_SETLK:
+	case F_SETLKW:
+	    {
 		struct flock *lck = (struct flock *)buf;
 
 		b = (struct bios_file *)f->fc.index;
@@ -1508,7 +1542,10 @@
 			b->lockpid = curproc->pid;
 			f->flags |= O_LOCK;
 		}
-	} else if (mode == F_GETLK) {
+		break;
+	    }
+	case F_GETLK:
+	    {
 		struct flock *lck = (struct flock *)buf;
 
 		b = (struct bios_file *)f->fc.index;
@@ -1519,7 +1556,9 @@
 		} else {
 			lck->l_type = F_UNLCK;
 		}
-	} else {
+		break;
+	    }
+	default:
 	/* Fcntl will automatically call tty_ioctl to handle
 	 * terminal calls that we didn't deal with
 	 */
diff -ur orig/context.spp ./context.spp
--- orig/context.spp	Tue Feb  1 04:28:18 1994
+++ ./context.spp	Thu Feb 17 19:43:58 1994
@@ -207,7 +207,6 @@
 	sub.w	d1,sp
 	sub.w	d1,sp
 	move.l	sp,a2
-	bra.s	rcover
 	subq.w	#1,d1		; correct for first time through loop
 rcint:	move.w	(a1)+,(a2)+
 rcover:	dbf	d1,rcint
diff -ur orig/file.h ./file.h
--- orig/file.h	Tue Feb 15 23:21:30 1994
+++ ./file.h	Thu Feb 17 21:14:30 1994
@@ -556,7 +556,7 @@
 
 extern FILESYS *drives[NUM_DRIVES];
 extern struct tty default_tty;
-extern char follow_links[];
+#define follow_links ((char *)-1L)
 #endif
 
 /* internal bios file structure */
diff -ur orig/filesys.c ./filesys.c
--- orig/filesys.c	Wed Feb  2 22:43:44 1994
+++ ./filesys.c	Thu Feb 17 20:15:04 1994
@@ -32,8 +32,6 @@
 
 FILEPTR *flist;		/* a list of free file pointers */
 
-char follow_links[1];	/* dummy "name" used as a parameter to path2cookie */
-
 /* vector of valid drives, according to GEMDOS */
 /* note that this isn't necessarily the same as what the BIOS thinks of
  * as valid
@@ -130,7 +128,7 @@
  *     load_devdriver() need access to it.
  */
 #define NPATHS 3
-static const char *ext_paths[NPATHS] = {"", "\\MINT", "\\MULTITOS"};
+static const char *const ext_paths[NPATHS] = {"", "\\MINT", "\\MULTITOS"};
 
 
 void
diff -ur orig/intr.spp ./intr.spp
--- orig/intr.spp	Wed Feb  2 17:52:32 1994
+++ ./intr.spp	Thu Feb 17 21:16:32 1994
@@ -100,7 +100,11 @@
 	jsr	_build_context		; build context
 	move.l	_curproc,a0
 	move.l	(a0),sp			; use curproc->sysstack
+%ifdef ONLY030
+	clr.w	-(sp)			; not a system call
+%else
 	move.w	#0,-(sp)		; not a system call
+%endif
 	jsr	_enter_kernel		; enter kernel
 	addq.w	#2,sp
 	jsr	_preempt		; yield processor
@@ -270,7 +274,11 @@
 	jsr	_build_context
 	move.l	_curproc,a4
 	move.l	(a4),sp			; put us in the system stack
+%ifdef ONLY030
+	clr.w	-(sp)			; not a GEMDOS call
+%else
 	move.w	#0,-(sp)		; not a GEMDOS call
+%endif
 	jsr	_enter_kernel		; set up kernel vectors
 	addq.w	#2,sp
 	move.l	_sig_routine,a1		; get signal handling routine
diff -ur orig/mem.c ./mem.c
--- orig/mem.c	Tue Feb  1 04:31:44 1994
+++ ./mem.c	Thu Feb 17 20:21:08 1994
@@ -12,10 +12,15 @@
 #include "fasttext.h" /* for line A stuff */
 
 #ifndef VgetSize
+#ifdef __GNUC__
+#define	VgetSize(mode) (long)trap_14_ww((short)91,(short)(mode))
+#define Vsetmode(mode) (short)trap_14_ww((short)88,(short)(mode))
+#else
 extern long xbios();
 #define VgetSize(mode) xbios(91, (short)(mode))
 #define Vsetmode(mode) xbios(88, (short)(mode))
 #endif
+#endif
 
 static long core_malloc P_((long, int));
 static void core_free P_((long));
diff -ur orig/pipefs.c ./pipefs.c
--- orig/pipefs.c	Wed Feb  9 23:08:10 1994
+++ ./pipefs.c	Thu Feb 17 21:19:24 1994
@@ -750,7 +750,8 @@
 
 	this = (struct fifo *)f->fc.index;
 
-	if (mode == FIONREAD) {
+	switch (mode) {
+	case FIONREAD:
 			p = (f->flags & O_HEAD) ? this->outp : this->inp;
 			assert(p != 0);
 			if (p->writers <= 0 || p->writers == VIRGIN_PIPE) {
@@ -763,8 +764,8 @@
 					r = r >> 2;	/* r /= 4 */
 			}
 			*((long *) buf) = r;
-	}
-	else if (mode == FIONWRITE) {
+			break;
+	case FIONWRITE:
 			p = (f->flags & O_HEAD) ? this->inp : this->outp;
 			assert(p != 0);
 			if (p->readers <= 0) {
@@ -777,8 +778,9 @@
 					r = r >> 2;	/* r /= 4 */
 			}
 			*((long *) buf) = r;
-	}
-	else if (mode == F_SETLK || mode == F_SETLKW) {
+			break;
+	case F_SETLK:
+	case F_SETLKW:
 		lck = (struct flock *)buf;
 		while (this->flags & O_LOCK) {
 			if (this->lockpid != curproc->pid) {
@@ -806,8 +808,8 @@
 			this->lockpid = curproc->pid;
 			f->flags |= O_LOCK;
 		}
-	}
-	else if (mode == F_GETLK) {
+		break;
+	case F_GETLK:
 		lck = (struct flock *)buf;
 		if (this->flags & O_LOCK) {
 			lck->l_type = F_WRLCK;
@@ -816,8 +818,9 @@
 		}
 		else
 			lck->l_type = F_UNLCK;
-	}
-	else if (mode == TIOCFLUSH) {
+		break;
+	case TIOCFLUSH:
+	    {
 		long flushtype;
 		long *which;
 
@@ -835,7 +838,9 @@
 			this->outp->head = this->outp->tail;
 			wake(IO_Q, (long)this->outp);
 		}
-	} else if (mode == TIOCOUTQ) {
+		break;
+	    }
+	case TIOCOUTQ:
 			p = (f->flags & O_HEAD) ? this->inp : this->outp;
 			assert(p != 0);
 			if (p->readers <= 0) {
@@ -847,11 +852,20 @@
 					r = r >> 2;	/* r /= 4 */
 			}
 			*((long *) buf) = r;
-	} else if (mode == TIOCIBAUD || mode == TIOCOBAUD) {
+			break;
+	case TIOCIBAUD:
+	case TIOCOBAUD:
 		*(long *)buf = -1L;
-	} else if (mode == TIOCGFLAGS) {
+		break;
+	case TIOCGFLAGS:
 		*((unsigned short *)buf) = 0;
-	} else if (mode >= TCURSOFF && mode <= TCURSGRATE) {
+		break;
+	case TCURSOFF:
+	case TCURSON:
+	case TCURSSRATE:
+	case TCURSBLINK:
+	case TCURSSTEADY:
+	case TCURSGRATE:
 	/* kludge: this assumes TOSWIN style escape sequences */
 		tty_putchar(f, (long)'\033', RAW);
 		switch (mode) {
@@ -875,7 +889,8 @@
 		case TCURSGRATE:
 			return this->cursrate;
 		}
-	} else {
+		break;
+	default:
 	/* if the file is a terminal, Fcntl will automatically
 	 * call tty_ioctl for us to handle 'generic' terminal
 	 * functions
diff -ur orig/signal.c ./signal.c
--- orig/signal.c	Wed Feb  9 23:10:02 1994
+++ ./signal.c	Thu Feb 17 20:36:14 1994
@@ -129,7 +129,6 @@
 				} else {
 					ulong omask;
 
-					curproc->sigpending &= ~sigm;
 					omask = curproc->sigmask;
 
 		/* sigextra gives which extra signals should also be masked */
diff -ur orig/syscall.spp ./syscall.spp
--- orig/syscall.spp	Fri Feb 11 19:23:02 1994
+++ ./syscall.spp	Thu Feb 17 22:11:32 1994
@@ -139,7 +139,11 @@
 	move.l	8(a1),-(sp)
 	move.l	4(a1),-(sp)
 	move.l	(a1),-(sp)
+%ifdef ONLY030
+	clr.w	-(sp)			; flag: NOT GEMDOS
+%else
 	move.w	#0,-(sp)		; flag: NOT GEMDOS
+%endif
 	jsr	_enter_kernel		; set up vectors appropriately
 	addq.w	#2,sp
 	bra	_syscall
@@ -166,7 +170,11 @@
 ;
 ; the shortcuts are also turned off if BIOSBUF=n
 ;
+%ifdef ONLY030
+	clr.w	-(sp)			; flag: NOT a GEMDOS call
+%else
 	move.w	#0,-(sp)		; flag: NOT a GEMDOS call
+%endif
 	jsr	_enter_kernel		; set up BIOS vectors
 	addq.w	#2,sp
 	tst.w	_bconbdev		; is BIOS buffering on?
@@ -267,9 +275,13 @@
 check_max:
 	cmp.w	d5,d0
 	bcc.s	error
+%ifdef ONLY030
+	move.l	0(a5,d0.w*4),d0		; d0 = syscall_tab[d0]
+%else
 	add.w	d0,d0
 	add.w	d0,d0			; multiply by 4
 	move.l	0(a5,d0.w),d0		; d0 = syscall_tab[d0]
+%endif
 	beq.s	error			; null entry means invalid call
 	addq.w	#2,sp			; pop function number off stack
 	move.l	d0,a0
@@ -399,8 +411,7 @@
 ;
 	XDEF	_call_dosound
 _call_dosound:
-	move.l	4(sp),d0
-	move.l	d0,-(sp)
+	move.l	4(sp),-(sp)
 	move.w	#32,-(sp)
 	trap	#14
 	addq.w	#6,sp
diff -ur orig/tosfs.c ./tosfs.c
--- orig/tosfs.c	Wed Feb  2 20:36:50 1994
+++ ./tosfs.c	Thu Feb 17 20:43:22 1994
@@ -1150,11 +1150,14 @@
 	struct tindex *ti;
 	extern int flk;		/* set in main.c if _FLK already installed */
 
-	if (mode == FIONREAD || mode == FIONWRITE) {
+	switch (mode) {
+	case FIONREAD:
+	case FIONWRITE:
 		*((long *)buf) = 1;
 		return 0;
-	}
-	else if (mode == F_SETLK || mode == F_SETLKW || mode == F_GETLK) {
+	case F_SETLK:
+	case F_SETLKW:
+	case F_GETLK:
 		fl = ((struct flock *)buf);
 		t.l = *fl;
 		switch(t.l.l_whence) {
diff -ur orig/unifs.c ./unifs.c
--- orig/unifs.c	Fri Feb 11 19:28:04 1994
+++ ./unifs.c	Thu Feb 17 21:32:06 1994
@@ -690,7 +702,10 @@
 	extern struct kerinfo kernelinfo;
 	extern FILESYS *active_fs;
 
-	if (cmd == FS_INSTALL) { /* install a new filesystem */
+	switch (cmd) {
+	case FS_INSTALL:
+	    {
+	/* install a new filesystem */
 		struct fs_descr *d = (struct fs_descr*)arg;
 		FILESYS *fs;
 
@@ -701,7 +704,10 @@
 		d->file_system->next = active_fs;
 		active_fs = d->file_system;
 		return (long)&kernelinfo;  /* return pointer to kernel info as OK */
-	} else if (cmd == FS_MOUNT) {  /* install a new gemdos-only device for this FS */
+	    }
+	case FS_MOUNT:
+	    {
+	/* install a new gemdos-only device for this FS */
 		struct fs_descr *d = (struct fs_descr*)arg;
 		FILESYS *fs;
 		UNIFILE *u;
@@ -732,7 +738,10 @@
 		u->next = u_root;
 		u_root = u;
 		return (long)u->dev;
-	} else if (cmd == FS_UNMOUNT) {  /* remove a file system's directory */
+	    }
+	case FS_UNMOUNT:
+	    {
+	/* remove a file system's directory */
 		struct fs_descr *d = (struct fs_descr*)arg;
 		FILESYS *fs;
 		UNIFILE *u;
@@ -765,7 +774,10 @@
 		u->mode &= ~S_IFMT;
 		u->mode |= S_IFLNK;
 		return uni_remove(dir, name);
-	} else if (cmd == FS_UNINSTALL) {    /* remove file system from kernel list */
+	    }
+	case FS_UNINSTALL:
+	    {
+	/* remove file system from kernel list */
 		struct fs_descr *d = (struct fs_descr*)arg;
 		FILESYS *fs, *last_fs;
 		UNIFILE *u;
@@ -791,7 +803,8 @@
 			fs = fs->next;
 		}
 		return EFILNF;
-	} else {
+	    }
+	default:
 	/* see if we should just pass this along to another file system */
 		r = uni_lookup(dir, name, &fc);
 		if (r == 0) {
diff -ur orig/util.c ./util.c
--- orig/util.c	Wed Sep 15 02:44:12 1993
+++ ./util.c	Thu Feb 17 20:50:10 1994
@@ -297,7 +297,7 @@
  * a Unix time (seconds from midnight Jan 1., 1970)
  */
 
-static int
+static int const
 mth_start[13] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
 
 long ARGS_ON_STACK