1dbbd9e4bSmacallan/*
2dbbd9e4bSmacallan * Acceleration for the Creator and Creator3D framebuffer - fast inner loops.
3dbbd9e4bSmacallan *
4dbbd9e4bSmacallan * Copyright (C) 1999 David S. Miller (davem@redhat.com)
5dbbd9e4bSmacallan * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
6dbbd9e4bSmacallan *
7dbbd9e4bSmacallan * Permission is hereby granted, free of charge, to any person obtaining a copy
8dbbd9e4bSmacallan * of this software and associated documentation files (the "Software"), to deal
9dbbd9e4bSmacallan * in the Software without restriction, including without limitation the rights
10dbbd9e4bSmacallan * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11dbbd9e4bSmacallan * copies of the Software, and to permit persons to whom the Software is
12dbbd9e4bSmacallan * furnished to do so, subject to the following conditions:
13dbbd9e4bSmacallan *
14dbbd9e4bSmacallan * The above copyright notice and this permission notice shall be included in
15dbbd9e4bSmacallan * all copies or substantial portions of the Software.
16dbbd9e4bSmacallan *
17dbbd9e4bSmacallan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18dbbd9e4bSmacallan * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19dbbd9e4bSmacallan * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20dbbd9e4bSmacallan * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21dbbd9e4bSmacallan * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22dbbd9e4bSmacallan * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23dbbd9e4bSmacallan * IN THE SOFTWARE.
24dbbd9e4bSmacallan *
25dbbd9e4bSmacallan */
26dbbd9e4bSmacallan
27dbbd9e4bSmacallan#ifndef FFBLOOPS_H
28dbbd9e4bSmacallan#define FFBLOOPS_H
29dbbd9e4bSmacallan
30dbbd9e4bSmacallan#ifdef USE_VIS
31dbbd9e4bSmacallanextern void FFB_STIPPLE_LOAD(volatile unsigned int *d,
32dbbd9e4bSmacallan			     unsigned int *s);
33dbbd9e4bSmacallan
34dbbd9e4bSmacallanextern void FFB_PPT_BOX_LOOP(FFBPtr ffbpriv,
35dbbd9e4bSmacallan			     ffb_fbcPtr ffb,
36dbbd9e4bSmacallan			     BoxPtr pbox, BoxPtr pbox_last,
37dbbd9e4bSmacallan			     DDXPointPtr ppt);
38dbbd9e4bSmacallan
39dbbd9e4bSmacallanextern void FFB_BOX_LOOP(FFBPtr ffbpriv,
40dbbd9e4bSmacallan			 ffb_fbcPtr ffb,
41dbbd9e4bSmacallan			 BoxPtr pbox,
42dbbd9e4bSmacallan			 BoxPtr pbox_last);
43dbbd9e4bSmacallan
44dbbd9e4bSmacallanextern void FFB_RECT_LOOP(FFBPtr ffbpriv,
45dbbd9e4bSmacallan			  ffb_fbcPtr ffb,
46dbbd9e4bSmacallan			  xRectangle *prect,
47dbbd9e4bSmacallan			  xRectangle *prect_last,
48dbbd9e4bSmacallan			  int xOrg, int yOrg);
49dbbd9e4bSmacallan
50dbbd9e4bSmacallanextern void FFB_PPT_WIDTH_LOOP(FFBPtr ffbpriv,
51dbbd9e4bSmacallan			       ffb_fbcPtr ffb,
52dbbd9e4bSmacallan			       DDXPointPtr ppt, DDXPointPtr ppt_last,
53dbbd9e4bSmacallan			       int *pwidth);
54dbbd9e4bSmacallan
55dbbd9e4bSmacallanextern DDXPointPtr FFB_PPT_LOOP1(FFBPtr ffbpriv,
56dbbd9e4bSmacallan				 ffb_fbcPtr ffb,
57dbbd9e4bSmacallan				 DDXPointPtr ppt, DDXPointPtr ppt_last,
58dbbd9e4bSmacallan				 int xOrg, int yOrg);
59dbbd9e4bSmacallan
60dbbd9e4bSmacallanextern DDXPointPtr FFB_PPT_LOOP2(FFBPtr ffbpriv,
61dbbd9e4bSmacallan				 ffb_fbcPtr ffb,
62dbbd9e4bSmacallan				 DDXPointPtr ppt, DDXPointPtr ppt_last,
63dbbd9e4bSmacallan				 int x, int y);
64dbbd9e4bSmacallan
65dbbd9e4bSmacallanextern DDXPointPtr FFB_LINE_LOOP1(FFBPtr ffbpriv,
66dbbd9e4bSmacallan				  ffb_fbcPtr ffb,
67dbbd9e4bSmacallan				  DDXPointPtr ppt, DDXPointPtr ppt_last,
68dbbd9e4bSmacallan				  int xOrg, int yOrg);
69dbbd9e4bSmacallan
70dbbd9e4bSmacallanextern DDXPointPtr FFB_LINE_LOOP2(FFBPtr ffbpriv,
71dbbd9e4bSmacallan				  ffb_fbcPtr ffb,
72dbbd9e4bSmacallan				  DDXPointPtr ppt, DDXPointPtr ppt_last,
73dbbd9e4bSmacallan				  int *x, int *y);
74dbbd9e4bSmacallan
75dbbd9e4bSmacallan#else /* !USE_VIS */
76dbbd9e4bSmacallan
77dbbd9e4bSmacallan#define FFB_STIPPLE_LOAD(_d,_s)				\
78dbbd9e4bSmacallando {							\
79dbbd9e4bSmacallan	volatile unsigned int *d = (_d);		\
80dbbd9e4bSmacallan	unsigned int *s = (_s);				\
81dbbd9e4bSmacallan	int i;						\
82dbbd9e4bSmacallan							\
83dbbd9e4bSmacallan	for (i = 0; i < (32 / 2); i++, d+=2, s+=2)	\
84dbbd9e4bSmacallan		FFB_WRITE64(d, s[0], s[1]);		\
85dbbd9e4bSmacallan} while (0)
86dbbd9e4bSmacallan
87dbbd9e4bSmacallan#define FFB_PPT_BOX_LOOP(pFfb, ffb, pbox, _pbox_last, ppt)				\
88dbbd9e4bSmacallando {											\
89dbbd9e4bSmacallan	BoxPtr pbox_last = (BoxPtr)(_pbox_last);					\
90dbbd9e4bSmacallan	while (pbox <= pbox_last) {							\
91dbbd9e4bSmacallan		FFBFifo(pFfb, 7);							\
92dbbd9e4bSmacallan		ffb->drawop = FFB_DRAWOP_VSCROLL;					\
93dbbd9e4bSmacallan		FFB_WRITE64(&ffb->by, ppt->y, ppt->x);					\
94dbbd9e4bSmacallan		FFB_WRITE64_2(&ffb->dy, pbox->y1, pbox->x1);				\
95dbbd9e4bSmacallan		FFB_WRITE64_3(&ffb->bh, (pbox->y2 - pbox->y1), (pbox->x2 - pbox->x1));	\
96dbbd9e4bSmacallan		pbox++; ppt++;								\
97dbbd9e4bSmacallan	}										\
98dbbd9e4bSmacallan} while (0)
99dbbd9e4bSmacallan
100dbbd9e4bSmacallan#define FFB_BOX_LOOP(pFfb, ffb, pbox, _pbox_last)					\
101dbbd9e4bSmacallando {											\
102dbbd9e4bSmacallan	BoxPtr pbox_last = (BoxPtr)(_pbox_last);					\
103dbbd9e4bSmacallan	while (pbox <= pbox_last) {							\
104dbbd9e4bSmacallan		FFBFifo(pFfb, 4);							\
105dbbd9e4bSmacallan		FFB_WRITE64(&ffb->by, pbox->y1, pbox->x1);				\
106dbbd9e4bSmacallan		FFB_WRITE64_2(&ffb->bh, (pbox->y2 - pbox->y1), (pbox->x2 - pbox->x1));	\
107dbbd9e4bSmacallan		pbox++;									\
108dbbd9e4bSmacallan	}										\
109dbbd9e4bSmacallan} while (0)
110dbbd9e4bSmacallan
111dbbd9e4bSmacallan#define FFB_RECT_LOOP(pFfb, ffb, prect, _prect_last, xOrg, yOrg)			\
112dbbd9e4bSmacallando {											\
113dbbd9e4bSmacallan	xRectangle *prect_last = (xRectangle *)(_prect_last);				\
114dbbd9e4bSmacallan	for (; prect <= prect_last; prect++) {						\
115dbbd9e4bSmacallan		register int x, y, w, h;						\
116dbbd9e4bSmacallan		x = prect->x + xOrg;							\
117dbbd9e4bSmacallan		y = prect->y + yOrg;							\
118dbbd9e4bSmacallan		w = prect->width;							\
119dbbd9e4bSmacallan		h = prect->height;							\
120dbbd9e4bSmacallan		if (extents->x2 <= x ||							\
121dbbd9e4bSmacallan		    extents->x1 >= x + w ||						\
122dbbd9e4bSmacallan		    extents->y2 <= y ||							\
123dbbd9e4bSmacallan		    extents->y1 >= y + h)						\
124dbbd9e4bSmacallan			continue;							\
125dbbd9e4bSmacallan		FFBFifo(pFfb, 4);							\
126dbbd9e4bSmacallan		FFB_WRITE64(&ffb->by, y, x);						\
127dbbd9e4bSmacallan		FFB_WRITE64_2(&ffb->bh, h, w);						\
128dbbd9e4bSmacallan	}										\
129dbbd9e4bSmacallan} while (0)
130dbbd9e4bSmacallan
131dbbd9e4bSmacallan#define FFB_PPT_WIDTH_LOOP(pFfb, ffb, ppt, _ppt_last, pwidth)			\
132dbbd9e4bSmacallando {											\
133dbbd9e4bSmacallan	DDXPointPtr ppt_last = (DDXPointPtr)(_ppt_last);				\
134dbbd9e4bSmacallan	while (ppt <= ppt_last) {							\
135dbbd9e4bSmacallan		register int x, y, w;							\
136dbbd9e4bSmacallan		x = ppt->x;								\
137dbbd9e4bSmacallan		y = ppt->y;								\
138dbbd9e4bSmacallan		w = *pwidth++;								\
139dbbd9e4bSmacallan		FFBFifo(pFfb, 5);							\
140dbbd9e4bSmacallan		ffb->ppc = 0;								\
141dbbd9e4bSmacallan		FFB_WRITE64(&ffb->by, y, x);						\
142dbbd9e4bSmacallan		FFB_WRITE64_2(&ffb->bh, y, (x + w));					\
143dbbd9e4bSmacallan		ppt++;									\
144dbbd9e4bSmacallan	}										\
145dbbd9e4bSmacallan} while (0)
146dbbd9e4bSmacallan
147dbbd9e4bSmacallanstatic __inline__ DDXPointPtr FFB_PPT_LOOP1(FFBPtr pFfb,
148dbbd9e4bSmacallan				 ffb_fbcPtr ffb,
149dbbd9e4bSmacallan				 DDXPointPtr ppt, DDXPointPtr ppt_last,
150dbbd9e4bSmacallan				 int xOrg, int yOrg)
151dbbd9e4bSmacallan{
152dbbd9e4bSmacallan	while (ppt <= ppt_last) {
153dbbd9e4bSmacallan		FFBFifo(pFfb, 2);
154dbbd9e4bSmacallan		FFB_WRITE64_2(&ffb->bh, (ppt->y + yOrg), (ppt->x + xOrg));
155dbbd9e4bSmacallan		ppt++;
156dbbd9e4bSmacallan	}
157dbbd9e4bSmacallan	return ppt;
158dbbd9e4bSmacallan}
159dbbd9e4bSmacallan
160dbbd9e4bSmacallanstatic __inline__ DDXPointPtr FFB_PPT_LOOP2(FFBPtr pFfb,
161dbbd9e4bSmacallan					    ffb_fbcPtr ffb,
162dbbd9e4bSmacallan					    DDXPointPtr ppt, DDXPointPtr ppt_last,
163dbbd9e4bSmacallan					    int x, int y)
164dbbd9e4bSmacallan{
165dbbd9e4bSmacallan	register int __x = x, __y = y;
166dbbd9e4bSmacallan	while (ppt <= ppt_last) {
167dbbd9e4bSmacallan		FFBFifo(pFfb, 2);
168dbbd9e4bSmacallan		__x += ppt->x;
169dbbd9e4bSmacallan		__y += ppt->y;
170dbbd9e4bSmacallan		FFB_WRITE64_2(&ffb->bh, __y, __x);
171dbbd9e4bSmacallan		ppt++;
172dbbd9e4bSmacallan	}
173dbbd9e4bSmacallan	return ppt;
174dbbd9e4bSmacallan}
175dbbd9e4bSmacallan
176dbbd9e4bSmacallanstatic __inline__ DDXPointPtr FFB_LINE_LOOP1(FFBPtr pFfb,
177dbbd9e4bSmacallan					     ffb_fbcPtr ffb,
178dbbd9e4bSmacallan					     DDXPointPtr ppt, DDXPointPtr ppt_last,
179dbbd9e4bSmacallan					     int xOrg, int yOrg)
180dbbd9e4bSmacallan{
181dbbd9e4bSmacallan	while (ppt <= ppt_last) {
182dbbd9e4bSmacallan		FFBFifo(pFfb, 3);
183dbbd9e4bSmacallan		ffb->ppc = 0;
184dbbd9e4bSmacallan		FFB_WRITE64_2(&ffb->bh, (ppt->y + yOrg), (ppt->x + xOrg));
185dbbd9e4bSmacallan		ppt++;
186dbbd9e4bSmacallan	}
187dbbd9e4bSmacallan	return ppt;
188dbbd9e4bSmacallan}
189dbbd9e4bSmacallan
190dbbd9e4bSmacallanstatic __inline__ DDXPointPtr FFB_LINE_LOOP2(FFBPtr pFfb,
191dbbd9e4bSmacallan					     ffb_fbcPtr ffb,
192dbbd9e4bSmacallan					     DDXPointPtr ppt, DDXPointPtr ppt_last,
193dbbd9e4bSmacallan					     int *x, int *y)
194dbbd9e4bSmacallan{
195dbbd9e4bSmacallan	register int __x = *x, __y = *y;
196dbbd9e4bSmacallan	while (ppt <= ppt_last) {
197dbbd9e4bSmacallan		FFBFifo(pFfb, 3);
198dbbd9e4bSmacallan		ffb->ppc = 0;
199dbbd9e4bSmacallan		__x += ppt->x;
200dbbd9e4bSmacallan		__y += ppt->y;
201dbbd9e4bSmacallan		FFB_WRITE64_2(&ffb->bh, __y, __x);
202dbbd9e4bSmacallan		ppt++;
203dbbd9e4bSmacallan	}
204dbbd9e4bSmacallan	*x = __x;
205dbbd9e4bSmacallan	*y = __y;
206dbbd9e4bSmacallan	return ppt;
207dbbd9e4bSmacallan}
208dbbd9e4bSmacallan
209dbbd9e4bSmacallan#endif /* !USE_VIS */
210dbbd9e4bSmacallan
211dbbd9e4bSmacallan#endif /* FFBLOOPS_H */
212