shithub: qk1

Download patch

ref: 151064726ca94693fc6c552c29d98eff2353a2d8
parent: 42b8dcf44db9868526a12ae6ce1215024c9e76aa
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Jan 5 13:34:56 EST 2024

make a pretty stupid inlining for Plan 9

--- a/d_scan.c
+++ b/d_scan.c
@@ -3,6 +3,8 @@
 
 int *r_turb_turb;
 
+#include "d_scan.h"
+
 /*
 =============
 D_WarpScreen
@@ -47,306 +49,6 @@
 	}
 }
 
-static inline void
-dospan_solid(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, uzint *pz, uzint izi, int izistep)
-{
-	if(((t + tstep*spancount) >> 16) == (t >> 16)){
-		pbase += (t >> 16) * width;
-		do{
-			*pdest++ = pbase[s >> 16];
-			*pz++ = izi;
-			s += sstep;
-			izi += izistep;
-		}while(--spancount);
-	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
-		pbase += s >> 16;
-		do{
-			*pdest++ = pbase[(t >> 16) * width];
-			*pz++ = izi;
-			t += tstep;
-			izi += izistep;
-		}while(--spancount);
-	}else{
-		do{
-			*pdest++ = pbase[(s >> 16) + (t >> 16) * width];
-			*pz++ = izi;
-			s += sstep;
-			t += tstep;
-			izi += izistep;
-		}while(--spancount);
-	}
-}
-
-static inline void
-dospan_solid_f1(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, uzint *pz, uzint izi, int izistep, fog_t *fog)
-{
-	if(((t + tstep*spancount) >> 16) == (t >> 16)){
-		pbase += (t >> 16) * width;
-		do{
-			*pz++ = izi;
-			izi += izistep;
-			*pdest++ = blendfog(pbase[s >> 16], *fog);
-			fogstep(*fog);
-			s += sstep;
-		}while(--spancount);
-	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
-		pbase += s >> 16;
-		do{
-			*pz++ = izi;
-			izi += izistep;
-			*pdest++ = blendfog(pbase[(t >> 16) * width], *fog);
-			fogstep(*fog);
-			t += tstep;
-		}while(--spancount);
-	}else{
-		do{
-			*pz++ = izi;
-			izi += izistep;
-			*pdest++ = blendfog(pbase[(s >> 16) + (t >> 16) * width], *fog);
-			fogstep(*fog);
-			s += sstep;
-			t += tstep;
-		}while(--spancount);
-	}
-}
-
-static inline void
-dospan_blend(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, byte alpha, uzint *pz, uzint izi, int izistep)
-{
-	pixel_t pix;
-
-	if(((t + tstep*spancount) >> 16) == (t >> 16)){
-		pbase += (t >> 16) * width;
-		do{
-			pix = pbase[s >> 16];
-			s += sstep;
-			if(opaque(pix) && *pz <= izi)
-				*pdest = blendalpha(pix, *pdest, alpha);
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
-		pbase += s >> 16;
-		do{
-			pix = pbase[(t >> 16) * width];
-			t += tstep;
-			if(opaque(pix) && *pz <= izi)
-				*pdest = blendalpha(pix, *pdest, alpha);
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}else{
-		do{
-			pix = pbase[(s >> 16) + (t >> 16) * width];
-			s += sstep;
-			t += tstep;
-			if(opaque(pix) && *pz <= izi)
-				*pdest = blendalpha(pix, *pdest, alpha);
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}
-}
-
-static inline void
-dospan_blend_f1(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, byte alpha, uzint *pz, uzint izi, int izistep, fog_t *fog)
-{
-	pixel_t pix;
-
-	if(((t + tstep*spancount) >> 16) == (t >> 16)){
-		pbase += (t >> 16) * width;
-		do{
-			pix = pbase[s >> 16];
-			s += sstep;
-			if(opaque(pix) && *pz <= izi)
-				*pdest = blendalpha(0xff<<24 | blendfog(pix, *fog), *pdest, alpha);
-			fogstep(*fog);
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
-		pbase += s >> 16;
-		do{
-			pix = pbase[(t >> 16) * width];
-			t += tstep;
-			if(opaque(pix) && *pz <= izi)
-				*pdest = blendalpha(0xff<<24 | blendfog(pix, *fog), *pdest, alpha);
-			fogstep(*fog);
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}else{
-		do{
-			pix = pbase[(s >> 16) + (t >> 16) * width];
-			s += sstep;
-			t += tstep;
-			if(opaque(pix) && *pz <= izi)
-				*pdest = blendalpha(0xff<<24 | blendfog(pix, *fog), *pdest, alpha);
-			fogstep(*fog);
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}
-}
-
-static inline void
-dospan_fence(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, uzint *pz, uzint izi, int izistep)
-{
-	pixel_t pix;
-
-	if(((t + tstep*spancount) >> 16) == (t >> 16)){
-		pbase += (t >> 16) * width;
-		do{
-			pix = pbase[s >> 16];
-			s += sstep;
-			if(opaque(pix) && *pz <= izi){
-				*pdest = pix;
-				*pz = izi;
-			}
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
-		pbase += s >> 16;
-		do{
-			pix = pbase[(t >> 16) * width];
-			t += tstep;
-			if(opaque(pix) && *pz <= izi){
-				*pdest = pix;
-				*pz = izi;
-			}
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}else{
-		do{
-			pix = pbase[(s >> 16) + (t >> 16) * width];
-			s += sstep;
-			t += tstep;
-			if(opaque(pix) && *pz <= izi){
-				*pdest = pix;
-				*pz = izi;
-			}
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}
-}
-
-static inline void
-dospan_fence_f1(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, uzint *pz, uzint izi, int izistep, fog_t *fog)
-{
-	pixel_t pix;
-
-	if(((t + tstep*spancount) >> 16) == (t >> 16)){
-		pbase += (t >> 16) * width;
-		do{
-			pix = pbase[s >> 16];
-			s += sstep;
-			if(opaque(pix) && *pz <= izi){
-				*pdest = blendfog(pix, *fog);
-				*pz = izi;
-			}
-			fogstep(*fog);
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
-		pbase += s >> 16;
-		do{
-			pix = pbase[(t >> 16) * width];
-			t += tstep;
-			if(opaque(pix) && *pz <= izi){
-				*pdest = blendfog(pix, *fog);
-				*pz = izi;
-			}
-			fogstep(*fog);
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}else{
-		do{
-			pix = pbase[(s >> 16) + (t >> 16) * width];
-			s += sstep;
-			t += tstep;
-			if(opaque(pix) && *pz <= izi){
-				*pdest = blendfog(pix, *fog);
-				*pz = izi;
-			}
-			fogstep(*fog);
-			izi += izistep;
-			pdest++;
-			pz++;
-		}while(--spancount);
-	}
-}
-
-static void
-dospan_turb(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, byte alpha, uzint *pz, uzint izi, int izistep)
-{
-	int sturb, tturb;
-	bool noblend;
-
-	noblend = (r_drawflags & DRAW_BLEND) == 0;
-	s &= (CYCLE<<16)-1;
-	t &= (CYCLE<<16)-1;
-
-	do{
-		if(noblend || *pz <= izi){
-			sturb = ((s + r_turb_turb[(t>>16)&(CYCLE-1)])>>16)&63;
-			tturb = ((t + r_turb_turb[(s>>16)&(CYCLE-1)])>>16)&63;
-			*pdest = blendalpha(*(pbase + (tturb<<6) + sturb), *pdest, alpha);
-			if(noblend)
-				*pz = izi;
-		}
-		s += sstep;
-		t += tstep;
-		izi += izistep;
-		pdest++;
-		pz++;
-	}while(--spancount > 0);
-
-}
-
-static void
-dospan_turb_f1(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, byte alpha, uzint *pz, uzint izi, int izistep, fog_t *fog)
-{
-	int sturb, tturb;
-	bool noblend;
-
-	noblend = (r_drawflags & DRAW_BLEND) == 0;
-	s &= (CYCLE<<16)-1;
-	t &= (CYCLE<<16)-1;
-
-	do{
-		if(noblend || *pz <= izi){
-			sturb = ((s + r_turb_turb[(t>>16)&(CYCLE-1)])>>16)&63;
-			tturb = ((t + r_turb_turb[(s>>16)&(CYCLE-1)])>>16)&63;
-			*pdest = blendalpha(0xff<<24 | blendfog(*(pbase + (tturb<<6) + sturb), *fog), *pdest, alpha);
-			if(noblend)
-				*pz = izi;
-		}
-		s += sstep;
-		t += tstep;
-		izi += izistep;
-		pdest++;
-		pz++;
-		fogstep(*fog);
-	}while(--spancount > 0);
-
-}
-
 static int
 D_DrawSpanGetMax(float u, float v)
 {
@@ -465,34 +167,38 @@
 				}
 			}
 
+			pixel_t *pdest_ = pdest, *pbase_ = pbase;
+			uzint *pz_ = pz;
+			fog_t *fog_ = &fog;
+			int spancount_ = spancount, izi_ = izi;
 			if(fogged){
 				switch(spanfunc){
 				case SPAN_SOLID:
-					dospan_solid_f1(pdest, pbase, s, t, sstep, tstep, spancount, width, pz, izi, izistep, &fog);
+					dospan_solid_f1(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, pz_, izi_, izistep, fog_);
 					break;
 				case SPAN_TURB:
-					dospan_turb_f1(pdest, pbase, s, t, sstep, tstep, spancount, alpha, pz, izi, izistep, &fog);
+					dospan_turb_f1(pdest_, pbase_, s, t, sstep, tstep, spancount_, alpha, pz_, izi_, izistep, fog_);
 					break;
 				case SPAN_BLEND:
-					dospan_blend_f1(pdest, pbase, s, t, sstep, tstep, spancount, width, alpha, pz, izi, izistep, &fog);
+					dospan_blend_f1(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, alpha, pz_, izi_, izistep, fog_);
 					break;
 				case SPAN_FENCE:
-					dospan_fence_f1(pdest, pbase, s, t, sstep, tstep, spancount, width, pz, izi, izistep, &fog);
+					dospan_fence_f1(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, pz_, izi_, izistep, fog_);
 					break;
 				}
 			}else{
 				switch(spanfunc){
 				case SPAN_SOLID:
-					dospan_solid(pdest, pbase, s, t, sstep, tstep, spancount, width, pz, izi, izistep);
+					dospan_solid(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, pz_, izi_, izistep);
 					break;
 				case SPAN_TURB:
-					dospan_turb(pdest, pbase, s, t, sstep, tstep, spancount, alpha, pz, izi, izistep);
+					dospan_turb(pdest_, pbase_, s, t, sstep, tstep, spancount_, alpha, pz_, izi_, izistep);
 					break;
 				case SPAN_BLEND:
-					dospan_blend(pdest, pbase, s, t, sstep, tstep, spancount, width, alpha, pz, izi, izistep);
+					dospan_blend(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, alpha, pz_, izi_, izistep);
 					break;
 				case SPAN_FENCE:
-					dospan_fence(pdest, pbase, s, t, sstep, tstep, spancount, width, pz, izi, izistep);
+					dospan_fence(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, pz_, izi_, izistep);
 					break;
 				}
 			}
--- /dev/null
+++ b/plan9/d_scan.h
@@ -1,0 +1,291 @@
+#define dospan_solid(pdest, pbase, s, t, sstep, tstep, spancount, width, pz, izi, izistep)\
+{\
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){\
+		pbase += (t >> 16) * width;\
+		do{\
+			*pdest++ = pbase[s >> 16];\
+			*pz++ = izi;\
+			s += sstep;\
+			izi += izistep;\
+		}while(--spancount);\
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){\
+		pbase += s >> 16;\
+		do{\
+			*pdest++ = pbase[(t >> 16) * width];\
+			*pz++ = izi;\
+			t += tstep;\
+			izi += izistep;\
+		}while(--spancount);\
+	}else{\
+		do{\
+			*pdest++ = pbase[(s >> 16) + (t >> 16) * width];\
+			*pz++ = izi;\
+			s += sstep;\
+			t += tstep;\
+			izi += izistep;\
+		}while(--spancount);\
+	}\
+}
+
+#define dospan_solid_f1(pdest, pbase, s, t, sstep, tstep, spancount, width, pz, izi, izistep, fog)\
+{\
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){\
+		pbase += (t >> 16) * width;\
+		do{\
+			*pz++ = izi;\
+			izi += izistep;\
+			*pdest++ = blendfog(pbase[s >> 16], *fog);\
+			fogstep(*fog);\
+			s += sstep;\
+		}while(--spancount);\
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){\
+		pbase += s >> 16;\
+		do{\
+			*pz++ = izi;\
+			izi += izistep;\
+			*pdest++ = blendfog(pbase[(t >> 16) * width], *fog);\
+			fogstep(*fog);\
+			t += tstep;\
+		}while(--spancount);\
+	}else{\
+		do{\
+			*pz++ = izi;\
+			izi += izistep;\
+			*pdest++ = blendfog(pbase[(s >> 16) + (t >> 16) * width], *fog);\
+			fogstep(*fog);\
+			s += sstep;\
+			t += tstep;\
+		}while(--spancount);\
+	}\
+}
+
+#define dospan_blend(pdest, pbase, s, t, sstep, tstep, spancount, width, alpha, pz, izi, izistep)\
+{\
+	pixel_t pix;\
+\
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){\
+		pbase += (t >> 16) * width;\
+		do{\
+			pix = pbase[s >> 16];\
+			s += sstep;\
+			if(opaque(pix) && *pz <= izi)\
+				*pdest = blendalpha(pix, *pdest, alpha);\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){\
+		pbase += s >> 16;\
+		do{\
+			pix = pbase[(t >> 16) * width];\
+			t += tstep;\
+			if(opaque(pix) && *pz <= izi)\
+				*pdest = blendalpha(pix, *pdest, alpha);\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}else{\
+		do{\
+			pix = pbase[(s >> 16) + (t >> 16) * width];\
+			s += sstep;\
+			t += tstep;\
+			if(opaque(pix) && *pz <= izi)\
+				*pdest = blendalpha(pix, *pdest, alpha);\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}\
+}
+
+#define dospan_blend_f1(pdest, pbase, s, t, sstep, tstep, spancount, width, alpha, pz, izi, izistep, fog)\
+{\
+	pixel_t pix;\
+\
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){\
+		pbase += (t >> 16) * width;\
+		do{\
+			pix = pbase[s >> 16];\
+			s += sstep;\
+			if(opaque(pix) && *pz <= izi)\
+				*pdest = blendalpha(0xff<<24 | blendfog(pix, *fog), *pdest, alpha);\
+			fogstep(*fog);\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){\
+		pbase += s >> 16;\
+		do{\
+			pix = pbase[(t >> 16) * width];\
+			t += tstep;\
+			if(opaque(pix) && *pz <= izi)\
+				*pdest = blendalpha(0xff<<24 | blendfog(pix, *fog), *pdest, alpha);\
+			fogstep(*fog);\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}else{\
+		do{\
+			pix = pbase[(s >> 16) + (t >> 16) * width];\
+			s += sstep;\
+			t += tstep;\
+			if(opaque(pix) && *pz <= izi)\
+				*pdest = blendalpha(0xff<<24 | blendfog(pix, *fog), *pdest, alpha);\
+			fogstep(*fog);\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}\
+}
+
+#define dospan_fence(pdest, pbase, s, t, sstep, tstep, spancount, width, pz, izi, izistep)\
+{\
+	pixel_t pix;\
+\
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){\
+		pbase += (t >> 16) * width;\
+		do{\
+			pix = pbase[s >> 16];\
+			s += sstep;\
+			if(opaque(pix) && *pz <= izi){\
+				*pdest = pix;\
+				*pz = izi;\
+			}\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){\
+		pbase += s >> 16;\
+		do{\
+			pix = pbase[(t >> 16) * width];\
+			t += tstep;\
+			if(opaque(pix) && *pz <= izi){\
+				*pdest = pix;\
+				*pz = izi;\
+			}\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}else{\
+		do{\
+			pix = pbase[(s >> 16) + (t >> 16) * width];\
+			s += sstep;\
+			t += tstep;\
+			if(opaque(pix) && *pz <= izi){\
+				*pdest = pix;\
+				*pz = izi;\
+			}\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}\
+}
+
+#define dospan_fence_f1(pdest, pbase, s, t, sstep, tstep, spancount, width, pz, izi, izistep, fog)\
+{\
+	pixel_t pix;\
+\
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){\
+		pbase += (t >> 16) * width;\
+		do{\
+			pix = pbase[s >> 16];\
+			s += sstep;\
+			if(opaque(pix) && *pz <= izi){\
+				*pdest = blendfog(pix, *fog);\
+				*pz = izi;\
+			}\
+			fogstep(*fog);\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){\
+		pbase += s >> 16;\
+		do{\
+			pix = pbase[(t >> 16) * width];\
+			t += tstep;\
+			if(opaque(pix) && *pz <= izi){\
+				*pdest = blendfog(pix, *fog);\
+				*pz = izi;\
+			}\
+			fogstep(*fog);\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}else{\
+		do{\
+			pix = pbase[(s >> 16) + (t >> 16) * width];\
+			s += sstep;\
+			t += tstep;\
+			if(opaque(pix) && *pz <= izi){\
+				*pdest = blendfog(pix, *fog);\
+				*pz = izi;\
+			}\
+			fogstep(*fog);\
+			izi += izistep;\
+			pdest++;\
+			pz++;\
+		}while(--spancount);\
+	}\
+}
+
+static void
+dospan_turb(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, byte alpha, uzint *pz, uzint izi, int izistep)
+{
+	int sturb, tturb;
+	bool noblend;
+
+	noblend = (r_drawflags & DRAW_BLEND) == 0;
+	s &= (CYCLE<<16)-1;
+	t &= (CYCLE<<16)-1;
+
+	do{
+		if(noblend || *pz <= izi){
+			sturb = ((s + r_turb_turb[(t>>16)&(CYCLE-1)])>>16)&63;
+			tturb = ((t + r_turb_turb[(s>>16)&(CYCLE-1)])>>16)&63;
+			*pdest = blendalpha(*(pbase + (tturb<<6) + sturb), *pdest, alpha);
+			if(noblend)
+				*pz = izi;
+		}
+		s += sstep;
+		t += tstep;
+		izi += izistep;
+		pdest++;
+		pz++;
+	}while(--spancount > 0);
+}
+
+static void
+dospan_turb_f1(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, byte alpha, uzint *pz, uzint izi, int izistep, fog_t *fog)
+{
+	int sturb, tturb;
+	bool noblend;
+
+	noblend = (r_drawflags & DRAW_BLEND) == 0;
+	s &= (CYCLE<<16)-1;
+	t &= (CYCLE<<16)-1;
+
+	do{
+		if(noblend || *pz <= izi){
+			sturb = ((s + r_turb_turb[(t>>16)&(CYCLE-1)])>>16)&63;
+			tturb = ((t + r_turb_turb[(s>>16)&(CYCLE-1)])>>16)&63;
+			*pdest = blendalpha(0xff<<24 | blendfog(*(pbase + (tturb<<6) + sturb), *fog), *pdest, alpha);
+			if(noblend)
+				*pz = izi;
+		}
+		s += sstep;
+		t += tstep;
+		izi += izistep;
+		pdest++;
+		pz++;
+		fogstep(*fog);
+	}while(--spancount > 0);
+}
--- /dev/null
+++ b/plan9/inline
@@ -1,0 +1,14 @@
+#!/bin/rc
+
+awk '
+	/ inline / { inlining = 1; striptypes = 1; printf "#define "; next }
+	/^}$/ && inlining { inlining = 0; print; next }
+	inlining {
+		if(striptypes)
+			gsub(/[a-zA-Z_0-9]+ [*]?/, "")
+		striptypes = 0
+		printf "%s\\\n", $0
+		next
+	}
+	!inlining { print }
+' $*
--- /dev/null
+++ b/unix/d_scan.h
@@ -1,0 +1,297 @@
+static inline void
+dospan_solid(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, uzint *pz, uzint izi, int izistep)
+{
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){
+		pbase += (t >> 16) * width;
+		do{
+			*pdest++ = pbase[s >> 16];
+			*pz++ = izi;
+			s += sstep;
+			izi += izistep;
+		}while(--spancount);
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
+		pbase += s >> 16;
+		do{
+			*pdest++ = pbase[(t >> 16) * width];
+			*pz++ = izi;
+			t += tstep;
+			izi += izistep;
+		}while(--spancount);
+	}else{
+		do{
+			*pdest++ = pbase[(s >> 16) + (t >> 16) * width];
+			*pz++ = izi;
+			s += sstep;
+			t += tstep;
+			izi += izistep;
+		}while(--spancount);
+	}
+}
+
+static inline void
+dospan_solid_f1(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, uzint *pz, uzint izi, int izistep, fog_t *fog)
+{
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){
+		pbase += (t >> 16) * width;
+		do{
+			*pz++ = izi;
+			izi += izistep;
+			*pdest++ = blendfog(pbase[s >> 16], *fog);
+			fogstep(*fog);
+			s += sstep;
+		}while(--spancount);
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
+		pbase += s >> 16;
+		do{
+			*pz++ = izi;
+			izi += izistep;
+			*pdest++ = blendfog(pbase[(t >> 16) * width], *fog);
+			fogstep(*fog);
+			t += tstep;
+		}while(--spancount);
+	}else{
+		do{
+			*pz++ = izi;
+			izi += izistep;
+			*pdest++ = blendfog(pbase[(s >> 16) + (t >> 16) * width], *fog);
+			fogstep(*fog);
+			s += sstep;
+			t += tstep;
+		}while(--spancount);
+	}
+}
+
+static inline void
+dospan_blend(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, byte alpha, uzint *pz, uzint izi, int izistep)
+{
+	pixel_t pix;
+
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){
+		pbase += (t >> 16) * width;
+		do{
+			pix = pbase[s >> 16];
+			s += sstep;
+			if(opaque(pix) && *pz <= izi)
+				*pdest = blendalpha(pix, *pdest, alpha);
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
+		pbase += s >> 16;
+		do{
+			pix = pbase[(t >> 16) * width];
+			t += tstep;
+			if(opaque(pix) && *pz <= izi)
+				*pdest = blendalpha(pix, *pdest, alpha);
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}else{
+		do{
+			pix = pbase[(s >> 16) + (t >> 16) * width];
+			s += sstep;
+			t += tstep;
+			if(opaque(pix) && *pz <= izi)
+				*pdest = blendalpha(pix, *pdest, alpha);
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}
+}
+
+static inline void
+dospan_blend_f1(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, byte alpha, uzint *pz, uzint izi, int izistep, fog_t *fog)
+{
+	pixel_t pix;
+
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){
+		pbase += (t >> 16) * width;
+		do{
+			pix = pbase[s >> 16];
+			s += sstep;
+			if(opaque(pix) && *pz <= izi)
+				*pdest = blendalpha(0xff<<24 | blendfog(pix, *fog), *pdest, alpha);
+			fogstep(*fog);
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
+		pbase += s >> 16;
+		do{
+			pix = pbase[(t >> 16) * width];
+			t += tstep;
+			if(opaque(pix) && *pz <= izi)
+				*pdest = blendalpha(0xff<<24 | blendfog(pix, *fog), *pdest, alpha);
+			fogstep(*fog);
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}else{
+		do{
+			pix = pbase[(s >> 16) + (t >> 16) * width];
+			s += sstep;
+			t += tstep;
+			if(opaque(pix) && *pz <= izi)
+				*pdest = blendalpha(0xff<<24 | blendfog(pix, *fog), *pdest, alpha);
+			fogstep(*fog);
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}
+}
+
+static inline void
+dospan_fence(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, uzint *pz, uzint izi, int izistep)
+{
+	pixel_t pix;
+
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){
+		pbase += (t >> 16) * width;
+		do{
+			pix = pbase[s >> 16];
+			s += sstep;
+			if(opaque(pix) && *pz <= izi){
+				*pdest = pix;
+				*pz = izi;
+			}
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
+		pbase += s >> 16;
+		do{
+			pix = pbase[(t >> 16) * width];
+			t += tstep;
+			if(opaque(pix) && *pz <= izi){
+				*pdest = pix;
+				*pz = izi;
+			}
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}else{
+		do{
+			pix = pbase[(s >> 16) + (t >> 16) * width];
+			s += sstep;
+			t += tstep;
+			if(opaque(pix) && *pz <= izi){
+				*pdest = pix;
+				*pz = izi;
+			}
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}
+}
+
+static inline void
+dospan_fence_f1(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, int width, uzint *pz, uzint izi, int izistep, fog_t *fog)
+{
+	pixel_t pix;
+
+	if(((t + tstep*spancount) >> 16) == (t >> 16)){
+		pbase += (t >> 16) * width;
+		do{
+			pix = pbase[s >> 16];
+			s += sstep;
+			if(opaque(pix) && *pz <= izi){
+				*pdest = blendfog(pix, *fog);
+				*pz = izi;
+			}
+			fogstep(*fog);
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}else if(((s + sstep*spancount) >> 16) == (s >> 16)){
+		pbase += s >> 16;
+		do{
+			pix = pbase[(t >> 16) * width];
+			t += tstep;
+			if(opaque(pix) && *pz <= izi){
+				*pdest = blendfog(pix, *fog);
+				*pz = izi;
+			}
+			fogstep(*fog);
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}else{
+		do{
+			pix = pbase[(s >> 16) + (t >> 16) * width];
+			s += sstep;
+			t += tstep;
+			if(opaque(pix) && *pz <= izi){
+				*pdest = blendfog(pix, *fog);
+				*pz = izi;
+			}
+			fogstep(*fog);
+			izi += izistep;
+			pdest++;
+			pz++;
+		}while(--spancount);
+	}
+}
+
+static void
+dospan_turb(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, byte alpha, uzint *pz, uzint izi, int izistep)
+{
+	int sturb, tturb;
+	bool noblend;
+
+	noblend = (r_drawflags & DRAW_BLEND) == 0;
+	s &= (CYCLE<<16)-1;
+	t &= (CYCLE<<16)-1;
+
+	do{
+		if(noblend || *pz <= izi){
+			sturb = ((s + r_turb_turb[(t>>16)&(CYCLE-1)])>>16)&63;
+			tturb = ((t + r_turb_turb[(s>>16)&(CYCLE-1)])>>16)&63;
+			*pdest = blendalpha(*(pbase + (tturb<<6) + sturb), *pdest, alpha);
+			if(noblend)
+				*pz = izi;
+		}
+		s += sstep;
+		t += tstep;
+		izi += izistep;
+		pdest++;
+		pz++;
+	}while(--spancount > 0);
+}
+
+static void
+dospan_turb_f1(pixel_t *pdest, pixel_t *pbase, int s, int t, int sstep, int tstep, int spancount, byte alpha, uzint *pz, uzint izi, int izistep, fog_t *fog)
+{
+	int sturb, tturb;
+	bool noblend;
+
+	noblend = (r_drawflags & DRAW_BLEND) == 0;
+	s &= (CYCLE<<16)-1;
+	t &= (CYCLE<<16)-1;
+
+	do{
+		if(noblend || *pz <= izi){
+			sturb = ((s + r_turb_turb[(t>>16)&(CYCLE-1)])>>16)&63;
+			tturb = ((t + r_turb_turb[(s>>16)&(CYCLE-1)])>>16)&63;
+			*pdest = blendalpha(0xff<<24 | blendfog(*(pbase + (tturb<<6) + sturb), *fog), *pdest, alpha);
+			if(noblend)
+				*pz = izi;
+		}
+		s += sstep;
+		t += tstep;
+		izi += izistep;
+		pdest++;
+		pz++;
+		fogstep(*fog);
+	}while(--spancount > 0);
+}