Are you sure the ffs below is correct ? I tried it with something like 0x85400000 as argument and it gave 26 as result ? Inserting 0x80000000 returns 12...
"Bill Pringlemeir" <bpringlem...@yahoo.com> wrote in message
> >>>> On 24 Jan, Phil wrote: > >> Does anyone have any fast source to calculate the number of > >> leading zeros (like the v5 clz instruction) on ARM7TDMI ?
> /* fls (find last set) function: Same as log2. > * on entry R0 is the number you want to find the last bit of > * on exit R0 contains either 0 if the number was 0, or 1-32 for > * the bit set R1 is trashed. > */ > _fls: sub r1,r1,r1 > cmp r0,#0x8000 > addhi r1,r1,#16 > movhi r0,r0, lsr #16 > cmp r0,#0x80 > addhi r1,r1,#8 > movhi r0,r0, lsr #8 > cmp r0,#0x8 > addhi r1,r1,#4 > movhi r0,r0, lsr #4 > cmp r0,#0x2 > addhi r1,r1,#2 > movhi r0,r0, lsr #2 > cmp r0,#0x1 > addhi r1,r1,#1 > movhi r0,r0, lsr #1 > add r0,r0,r1 > mov pc, lr
> I think that you could do something clever by using an add with shift > and flag set (ie. addhis r0,r1,r0,rsr #8) to combine the compare (or > tst) add and mov instructions, for at least part of the algorithm. For > example the accumulated bit count could be done in the lower
> Also, this function finds the last bit. If there is some way to > quickly change a value from 000..0001xxx.. -> 000..0001000.. then you > can use the code below. However, I couldn't come up with anything > when I thought about it briefly.
> /* ffs (find first set) function: > * on entry R0 is the number you want to find the first bit of > * on exit R0 contains either 0 if the number was 0, or 1-32 for > * the bit set R1 is trashed. > */ > _ffs: > rsb r1, r0, #0 > ands r1, r1, r0 /* r1 = X with 0 or 1 bits set */
BP> Also, this function finds the last bit. If there is some way to BP> quickly change a value from 000..0001xxx.. -> 000..0001000.. then you BP> can use the code below. However, I couldn't come up with anything BP> when I thought about it briefly.
Maybe AND with 0xFFFFFFF8?? I mean, your example AND 0xFFFFFFF8?
Could that work?
I must say that I didn't look at the code, but I will now... :) Maybe I said something stupid trying to help here... ;))))))))
-- "Maslinovs li majmuncicu bacu ?" upita Hrvato lize Hitleru crtu. "Nisam ja nikog bombardiro !" rece Dzonia drka "Ja samo Amerikankau masiru sretanm !" By runf
P> Does anyone have any fast source to calculate the number of leading zeros P> (like the v5 clz instruction) on ARM7TDMI ?
:))))
We had this on exam! :)) Not on ARM, but on FRISC (don't ask, CPU developed at our faculty)... :))
And, guess what, I didn't get any points on that, just because they didn't like it! :))))) Nevermind, I have other exam (ARM involved) on saturday... :))
Keep your fingers crossed, people! :))
-- Bugaro jebe imbecilan u svlacionici psihijataro cvrkuce svakih 15 minuta. By runf
> Phil> Are you sure the ffs below is correct ? I tried it with > Phil> something like 0x85400000 as argument and it gave 26 as result > Phil> ? Inserting 0x80000000 returns 12...
> Bill> Sorry, I thought you meant the fls code. It was newer. I did > Bill> several values with the ffs routine. 0x04d7651fUL is suppose > Bill> to be a perfect hash of the set 0x00000001, 0x00000002, > Bill> 0x00000004, ..., 0x40000000, 0x80000000. Either my constant > Bill> multiplication is wrong or I have messed up the table.
> In case you care, this table should work with the same constant > multiplier. Thanks for pointing that out. I did this by hand, so > there might be more errors! I haven't checked it programmatically yet.