Re: fast bit rotation
- Posted by "Juergen Luethje" <j.lue at gmx.de> Jan 02, 2004
- 452 views
Tommy wrote: > Juergen Luethje wrote: >> >> Rolf wrote: >> >>> I programmed 'true euphorian' rotation functions rotl(objekt x) and >>> rotr(object x), see include file ROTATION.E and test file ROTATION.EXW >>> of attached zip file. To run it under DOS, rename *.EXW to *.EX. >>> >>> On my AMD K6-2, 400MHz I found (under NT 4.0) with ROTATION.EXW >>> 1.91 micro seconds for rotr() and >>> 1.63 micro seconds for rotl() per call. >> >> You can even gain speed by omitting 'pusha' and 'popa'. >> >> I like the idea of wrapping the ASM functions by 'true euphorian' >> functions, especially in order to be able to apply them to any Euphoria >> object. >> >> However, the main disadvantage of Tommy's routines IMHO is the point, >> that they use a fixed count of '1' for any rotation. A versatile library >> routine IMHO should allow the user to specify the count as parameter, so >> that it would look somehow like: >> function rotate_left(value, count) > > Of course it only rotates a fixed count of '1': I didn't mean to create > a versatile library routine, just the fastest possible solution to > jiri's problem, which was integer rotation (left or right) of fixed > count 1 (I think :D). Sorry, I didn't want to offend you or something. I thought Jiri wanted some versatile library routines. > And I believe that if you want the highest > performance possible, my routine (no real Euphoria-function) is perhaps > a bit faster: no stack popping, just 1 poke, 2 moves, a rotation, a > return and 1 peek. > Haven't compared the performance of the 2 routines, but I don't need to. > I know they both perform very well and I also know that maintainability, > ease of use and readable code are much more important than that tiny bit > of extra performance. > So Rolf and Juergen, your routines are in general much better than what > I pulled together in 5 minutes. Please don't forget: I was somehow inspired by your code, and Rolf's routines use yours as a basis. > BTW: wouldn't it be nice if someone made a library of such very general > high-performance routines? I already started modifying your ASM routines, so that they take 'count' as a second parameter. Then I'll wrap them by pure euphoria functions, in order to be able to apply them to any Euphoria object -- very similar to what Rolf did. I'll do the same with my ASM routines, compare the speed, make some tweaks here and there ... I also plan do write some SHIFT functions. > Or perhaps Robert could add some of those > routines to machine.e or one of the general Euphoria-libraries? If you > see how many people could use shifts, rotates and other routines like > that. That would be nice. <snip> Regards, Juergen -- /"\ ASCII ribbon campain | This message has been ROT-13 encrypted \ / against HTML in | twice for higher security. X e-mail and news, | / \ and unneeded MIME | http://home.arcor.de/luethje/prog/