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

Fasttext patches



I got some pretty good speedups by avoiding a lot of invocations of the
gotoxy code in the really simple cases... Also, despite the fact that the
tab processing looks gross, it actually is faster and more compact than
the equivalent gotoxy compilation. I last sent this code out for mint 0.96,
but it didn't seem to make it into .97 or .98... (Oh, and there was a typo
in the stuff I sent out for 0.96 causing it to work incorrectly on color
resolutions. It's fixed in this patch.)

I also changed paint16m to paint816m, because I like to use the 8 row high
font in monochrome to get twice as many text lines per screen. Unfortunately
you can't do hardware scrolling if you do this. (Perhaps, since the output
might already be buffered, the code could scroll two lines at a time then? I
haven't investigated that route...)

*** fasttext.c	Wed Dec 23 12:44:06 1992
--- ../src/fasttext.c	Tue Feb  2 17:16:51 1993
***************
*** 24,28 ****
  static void paint P_((SCREEN *, int, char *)),
  	 paint8c P_((SCREEN *, int, char *)),
! 	 paint16m P_((SCREEN *, int, char *));
  
  INLINE static void curs_off P_((SCREEN *)), curs_on P_((SCREEN *));
--- 24,28 ----
  static void paint P_((SCREEN *, int, char *)),
  	 paint8c P_((SCREEN *, int, char *)),
! 	 paint816m P_((SCREEN *, int, char *));
  
  INLINE static void curs_off P_((SCREEN *)), curs_on P_((SCREEN *));
***************
*** 51,54 ****
--- 51,55 ----
  static short hardline;
  static void (*vpaint) P_((SCREEN *, int, char *));
+ static char *rowoff;
  
  void init P_((void));
***************
*** 137,140 ****
--- 138,142 ----
  	char *data, *foo;
  	static char chardata[256*16];
+ 	register int linelen;
  
  	foo = lineA0();
***************
*** 145,149 ****
  	   Erling
  	*/
! 	scrnsize = (v->maxy+1)*(long)v->linelen;
  	if (hardscroll == -1) {
  	/* request for auto-setting */
--- 147,162 ----
  	   Erling
  	*/
! 	linelen = v->linelen;
! 	scrnsize = (v->maxy+1)*(long)linelen;
! 	rowoff = (char *)kmalloc((long)((v->maxy+1) * sizeof(long)));
! 	if (rowoff == 0) {
! 		FATAL("Insufficient memory for screen offset table!");
! 	} else {
! 		long off, *lptr = (long *)rowoff;
! 		for (i=0, off=0; i<=v->maxy; i++) {
! 			*lptr++ = off;
! 			off += linelen;
! 		}
! 	}
  	if (hardscroll == -1) {
  	/* request for auto-setting */
***************
*** 177,187 ****
  			}
  		}
! 	} else if (v->cheight == 16 && v->planes == 1) {
  		foo = &chardata[0];
! 		vpaint = paint16m;
  		for (i = 0; i < 256; i++) {
  			chartab[i] = foo;
  			data = v->fontdata + i;
! 			for (j = 0; j < 16; j++) {
  				*foo++ = *data;
  				data += v->form_width;
--- 190,200 ----
  			}
  		}
! 	} else if ((v->cheight == 16 || v->cheight == 8) && v->planes == 1) {
  		foo = &chardata[0];
! 		vpaint = paint816m;
  		for (i = 0; i < 256; i++) {
  			chartab[i] = foo;
  			data = v->fontdata + i;
! 			for (j = 0; j < v->cheight; j++) {
  				*foo++ = *data;
  				data += v->form_width;
***************
*** 231,242 ****
  	if (y == v->maxy)
  		place += scrnsize - v->linelen;
! 	else if (y) /* Yo, the screen might be bigger than 32767 bytes...
! 		       Do a cast to long.	Erling. */
! 		place += (long)y * v->linelen;
! 
! 	if ((j = v->planes) > 1) {
  		i = (x & 0xfffe);
! 		while (--j > 0)
! 			place += i;
  	}
  	return place;
--- 244,256 ----
  	if (y == v->maxy)
  		place += scrnsize - v->linelen;
! 	else if (y) {
! 		y+=y;	/* Make Y into index for longword array. */
! 		y+=y;	/* Two word-size adds are faster than a 2-bit shift. */
! 		place += *(long *)(rowoff + y);
! 	}
! 	if ((j = v->planes-1)) {
  		i = (x & 0xfffe);
! 		do place += i;
! 		while (--j);
  	}
  	return place;
***************
*** 246,251 ****
   * paint(v, c, place): put character 'c' at position 'place' on screen
   * v. It is assumed that x, y are proper coordinates!
!  * Specialized versions (paint8c and paint16m) of this routine follow;
!  * they assume 8 line high characters, medium res. and 16 line/mono,
   * respectively.
   */
--- 260,265 ----
   * paint(v, c, place): put character 'c' at position 'place' on screen
   * v. It is assumed that x, y are proper coordinates!
!  * Specialized versions (paint8c and paint816m) of this routine follow;
!  * they assume 8 line high characters, medium res. and 8 or 16 line/mono,
   * respectively.
   */
***************
*** 398,402 ****
  
  static void
! paint16m(v, c, place)
  	SCREEN *v;
  	int c;
--- 412,416 ----
  
  static void
! paint816m(v, c, place)
  	SCREEN *v;
  	int c;
***************
*** 431,434 ****
--- 445,450 ----
  	    place += vplanesiz;
  	    *place = d;
+ 	    if (v->cheight == 8)
+ 		return;
  	    place += vplanesiz;
  	    *place = d;
***************
*** 487,490 ****
--- 503,510 ----
  		d = *data++;
  		*place = d;
+ 
+ 		if (v->cheight == 8)
+ 			return;
+ 
  		place += vplanesiz;
  
***************
*** 566,569 ****
--- 586,593 ----
  		d = ~*data++;
  		*place = d;
+ 
+ 		if (v->cheight == 8)
+ 			return;
+ 
  		place += vplanesiz;
  
***************
*** 644,648 ****
  	/* Hey, again the screen might be bigger than 32767 bytes.
  	   Do another cast... */
! 	dst = (int *)(base + ((long)r * v->linelen));
  	if (v->bgcol == 0)
  	  zero((char *)dst, v->linelen);
--- 668,674 ----
  	/* Hey, again the screen might be bigger than 32767 bytes.
  	   Do another cast... */
! 	r += r;
! 	r += r;
! 	dst = (int *)(base + *(long *)(rowoff+r));
  	if (v->bgcol == 0)
  	  zero((char *)dst, v->linelen);
***************
*** 748,761 ****
  	if (hardline < hardscroll) { /* just move the screen */
  		base += v->linelen;
! 		v->cursaddr = PLACE(v, v->cx, v->cy);
! 		Setscreen(base, base, -1);
! 	}
! 	else {
  		hardline = 0;
  		quickmove(hardbase, base + v->linelen, scrnsize - v->linelen);
  		base = hardbase;
- 		v->cursaddr = PLACE(v, v->cx, v->cy);
- 		Setscreen(hardbase, hardbase, -1);
  	}
  }
  
--- 774,784 ----
  	if (hardline < hardscroll) { /* just move the screen */
  		base += v->linelen;
! 	} else {
  		hardline = 0;
  		quickmove(hardbase, base + v->linelen, scrnsize - v->linelen);
  		base = hardbase;
  	}
+ 	v->cursaddr = PLACE(v, v->cx, v->cy);
+ 	Setscreen(base, base, -1);
  }
  
***************
*** 781,787 ****
  		}
  		nbytes = scrnsize - v->linelen;
  	}
- 	else
- 		nbytes = (long)v->linelen * (v->maxy - r);
  
  	/* Sheeze, how many times do we really have to cast... 
--- 804,813 ----
  		}
  		nbytes = scrnsize - v->linelen;
+ 	} else {
+ 		register int i = v->maxy - r;
+ 		i += i;
+ 		i += i;
+ 		nbytes = *(long *)(rowoff+i);
  	}
  
  	/* Sheeze, how many times do we really have to cast... 
***************
*** 789,793 ****
  	*/
  
! 	dst = (long *)(base + ((long)r * v->linelen));
  	src = (long *)( ((long)dst) + v->linelen);
  
--- 815,821 ----
  	*/
  
! 	r += r;
! 	r += r;
! 	dst = (long *)(base + *(long *)(rowoff + r));
  	src = (long *)( ((long)dst) + v->linelen);
  
***************
*** 809,823 ****
  {
  	long *src, *dst;
! 	int i, limit;
  
! 	limit = v->maxy;
! 	for (i = limit-1; i >= r ; --i) {
  	/* move line i to line i+1 */
! 	/* AND do some casting to support big screens.
! 	   Erling
! 	*/
! 		src = (long *)(base + ((long)i * v->linelen));
! 		dst = (long *)(base + ((i+1)*(long)v->linelen));
! 		quickmove(dst, src, v->linelen);
  	}
  
--- 837,855 ----
  {
  	long *src, *dst;
! 	int i, j, linelen;
  
! 	i = v->maxy - 1;
! 	i += i;
! 	i += i;
! 	j = r+r;
! 	j += j;
! 	linelen = v->linelen;
! 	src = (long *)(base + *(long *)(rowoff + i));
! 	dst = (long *)((long)src + linelen);
! 	for (; i >= j ; i -= 4) {
  	/* move line i to line i+1 */
! 		quickmove(dst, src, linelen);
! 		dst = src;
! 		src = (long *)((long) src - linelen);
  	}
  
***************
*** 864,887 ****
  	(*vpaint)(v, c, v->cursaddr);
  	state = normal_putch;
- 	v->cx++;
- 	if (v->cx > v->maxx) {
- 		if (v->flags & FWRAP) {
- 			v->cx = 0;
- 			normal_putch(v, '\n');
- 			v->cursaddr = PLACE(v, v->cx, v->cy);
- 		} else {
- 			v->cx = v->maxx;
- 		}
- 	} else {
- #if 0
- 		v->cursaddr = PLACE(v, v->cx, v->cy);
- #else
- 		v->cursaddr++;
- 		if ( (v->cx & 1) == 0 && v->planes > 1) { /* new word */
- 			short skipwords = v->planes - 1;
- 			v->cursaddr += skipwords+skipwords;
- 		}
- #endif
- 	}
  }
  
--- 896,899 ----
***************
*** 895,898 ****
--- 907,911 ----
  	int c;
  {
+ 	int i;
  	int cx, cy;
  
***************
*** 901,914 ****
  	switch (c) {
  	case 'A':		/* cursor up */
! 		gotoxy(v, cx, cy-1);
  		break;
  	case 'B':		/* cursor down */
! 		gotoxy(v, cx, cy+1);
  		break;
  	case 'C':		/* cursor right */
! 		gotoxy(v, cx+1, cy);
  		break;
  	case 'D':		/* cursor left */
! 		gotoxy(v, cx-1, cy);
  		break;
  	case 'E':		/* clear home */
--- 914,943 ----
  	switch (c) {
  	case 'A':		/* cursor up */
! 		if (cy) {
! moveup:			v->cy = --cy;
! 			v->cursaddr -= v->linelen;
! 		}
  		break;
  	case 'B':		/* cursor down */
! 		if (cy < v->maxy) {
! 			v->cy = ++cy;
! 			v->cursaddr += v->linelen;
! 		}
  		break;
  	case 'C':		/* cursor right */
! 		if (cx < v->maxx) {
! 			if ((i = v->planes-1) && (cx & 1))
! 				v->cursaddr += i + i;
! 			v->cx = ++cx;
! 			v->cursaddr++;
! 		}
  		break;
  	case 'D':		/* cursor left */
! 		if (cx) {
! 			v->cx = --cx;
! 			v->cursaddr--;
! 			if ((i = v->planes-1) && (cx & 1))
! 				v->cursaddr -= i + i;
! 		}
  		break;
  	case 'E':		/* clear home */
***************
*** 916,920 ****
  		/* fall through... */
  	case 'H':		/* cursor home */
! 		gotoxy(v, 0, 0);
  		break;
  	case 'I':		/* cursor up, insert line */
--- 945,950 ----
  		/* fall through... */
  	case 'H':		/* cursor home */
! 		v->cx = 0; v->cy = 0;
! 		v->cursaddr = base;
  		break;
  	case 'I':		/* cursor up, insert line */
***************
*** 923,927 ****
  		}
  		else
! 			gotoxy(v, cx, cy-1);
  		break;
  	case 'J':		/* clear below cursor */
--- 953,957 ----
  		}
  		else
! 			goto moveup;
  		break;
  	case 'J':		/* clear below cursor */
***************
*** 932,940 ****
  		break;
  	case 'L':		/* insert a line */
! 		gotoxy(v, 0, cy);
  		insert_line(v, cy);
  		break;
  	case 'M':		/* delete line */
! 		gotoxy(v, 0, cy);
  		delete_line(v, cy);
  		break;
--- 962,976 ----
  		break;
  	case 'L':		/* insert a line */
! 		v->cx = 0;
! 		i = cy + cy;
! 		i += i;
! 		v->cursaddr = base + *(long *)(rowoff + i);
  		insert_line(v, cy);
  		break;
  	case 'M':		/* delete line */
! 		v->cx = 0;
! 		i = cy + cy;
! 		i += i;
! 		v->cursaddr = base + *(long *)(rowoff + i);
  		delete_line(v, cy);
  		break;
***************
*** 971,975 ****
  		break;
  	case 'l':		/* clear line */
! 		gotoxy(v, 0, cy);
  		clrline(v, cy);
  		break;
--- 1007,1014 ----
  		break;
  	case 'l':		/* clear line */
! 		v->cx = 0;
! 		i = cy + cy;
! 		i += i;
! 		v->cursaddr = base + *(long *)(rowoff + i);
  		clrline(v, cy);
  		break;
***************
*** 1028,1031 ****
--- 1067,1072 ----
  	int c;
  {
+ 	register int i;
+ 
  /* control characters */
  	if (c < ' ') {
***************
*** 1032,1036 ****
  		switch (c) {
  		case '\r':
! 			gotoxy(v, 0, v->cy);
  			return;
  		case '\n':
--- 1073,1080 ----
  		switch (c) {
  		case '\r':
! col0:			v->cx = 0;
! 			i = v->cy + v->cy;
! 			i += i;
! 			v->cursaddr = base + *(long *)(rowoff + i);
  			return;
  		case '\n':
***************
*** 1037,1046 ****
  			if (v->cy == v->maxy) {
  				scroll(v);
  			}
- 			else
- 				gotoxy(v, v->cx, v->cy+1);
  			return;
  		case '\b':
! 			gotoxy(v, v->cx-1, v->cy);
  			return;
  		case '\007':		/* BELL */
--- 1081,1096 ----
  			if (v->cy == v->maxy) {
  				scroll(v);
+ 			} else {
+ 				v->cy++;
+ 				v->cursaddr += v->linelen;
  			}
  			return;
  		case '\b':
! 			if (v->cx) {
! 				v->cx--;
! 				v->cursaddr--;
! 				if ((i = v->planes-1) && (v->cx & 1))
! 					v->cursaddr -= i+i;
! 			}
  			return;
  		case '\007':		/* BELL */
***************
*** 1051,1055 ****
  			return;
  		case '\t':
! 			gotoxy(v, (v->cx + 8) & ~7, v->cy);
  			return;
  		default:
--- 1101,1124 ----
  			return;
  		case '\t':
! 			if (v->cx < v->maxx) {
! 				register union {
! 					long l;
! 					short i[2];
! 				} j;
! 				j.l = 0;
! 				j.i[1] = 8 - (v->cx & 7);
! 				v->cx += j.i[1];
! 				if (v->cx - v->maxx > 0) {
! 					j.i[1] = v->cx - v->maxx;
! 					v->cx = v->maxx;
! 				}
! 				v->cursaddr += j.l;
! 				if ((i = v->planes-1)) {
! 					if (j.l & 1)
! 						j.i[1]++;
! 					do v->cursaddr += j.l;
! 					while (--i);
! 				}
! 			}
  			return;
  		default:
***************
*** 1062,1068 ****
  	if (v->cx > v->maxx) {
  		if (v->flags & FWRAP) {
- 			v->cx = 0;
  			normal_putch(v, '\n');
! 			v->cursaddr = PLACE(v, v->cx, v->cy);
  		} else {
  			v->cx = v->maxx;
--- 1131,1136 ----
  	if (v->cx > v->maxx) {
  		if (v->flags & FWRAP) {
  			normal_putch(v, '\n');
! 			goto col0;
  		} else {
  			v->cx = v->maxx;
***************
*** 1069,1081 ****
  		}
  	} else {
- #if 0
- 		v->cursaddr = PLACE(v, v->cx, v->cy);
- #else
  		v->cursaddr++;
! 		if ( (v->cx & 1) == 0 && v->planes > 1) { /* new word */
! 			short skipwords = v->planes - 1;
! 			v->cursaddr += skipwords+skipwords;
! 		}
! #endif
  	}
  }
--- 1137,1143 ----
  		}
  	} else {
  		v->cursaddr++;
! 		if ((i = v->planes-1) && !(v->cx & 1))	/* new word */
! 			v->cursaddr += i + i;
  	}
  }