From: Keith W. <ke...@va...> - 2001-03-13 17:11:50
|
Gareth Hughes wrote: > > Josh Vanderhoof wrote: > > > > I'm getting sidetracked here but: > > > > 1. Before you start doing crazy optimizations why wouldn't you rewrite > > it like this (get rid of the "dma.space" variable): > > > > void foo_Vertex3fv( const GLfloat *v ) > > { > > GET_FOO_CONTEXT(fmesa); > > COPY_3V( fmesa->current.o3n3t2.obj, v ); > > if ( fmesa->dma.head + 8 <= fmesa->dma.end_of_space ) { > > COPY_DWORDS( fmesa->dma.head, fmesa->current.o3n3tc2, 8 ); > > fmesa->dma.head += 8; > > } else { > > fmesa->get_dma( fmesa, fmesa->current.o3n3tc2, 8 ); > > } > > } > > Sure -- it was just a cut and paste of some old code Keith sent me. > Minor point. > > > 2. Hard-coding the address would help you, but not by very much. I > > would expect it to save you one MOV instruction. On Intel cpu's, > > the "reg+offset" addressing mode is "free". (You probably knew > > that already.) > > Yep :-) GET_FOO_CONTEXT() is the big one, and perhaps I should have > stressed that a little more. This may involve a function call to > determine the current context, due to thread-safety issues. > > > 3. If you want to go all out on this code, you could probably use > > mprotect() to avoid the buffer overflow test entirely. That would > > only be a good idea if buffer overflows are rare though. > > You need buffer overflows as they end up flushing the DMA buffer. In > this case, get_dma() would flush the current buffer and acquire a new > one. But of course, we should never be getting rid of or aquiring new dma buffers; we should be just aging regions within a buffer we always hold, and perhaps in rare cases growing/shrinking it. However, mprotect doesn't help you here either, as the regions being aged are pretty dynamic. Keith |