Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
ARM7TDMI leading zero count source code
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Phil  
View profile  
 More options Jan 24 2002, 5:40 am
Newsgroups: comp.sys.arm
From: "Phil" <p...@miracle-designs-REMOVEME.com>
Date: Thu, 24 Jan 2002 11:32:40 +0100
Local: Thurs, Jan 24 2002 5:32 am
Subject: ARM7TDMI leading zero count source code
Does anyone have any fast source to calculate the number of leading zeros
(like the v5 clz instruction) on ARM7TDMI ?

Any suggestions how to do this are welcome.

Thanks,

Phil


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nemo  
View profile  
 More options Jan 24 2002, 8:03 am
Newsgroups: comp.sys.arm
From: Nemo <n...@20000.org>
Date: Thu, 24 Jan 2002 12:58:16 +0000
Local: Thurs, Jan 24 2002 7:58 am
Subject: Re: ARM7TDMI leading zero count source code
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 ?

The not-particularly-clever version:

; > R0: bitfield to examine
; < R0: number of high zeroes
;   R1,flags: corrupted

HighZeroes      MOVS    R1, R0
                MOVEQ   R0, #32
                MOVMI   R0, #0
                MOVLE   PC, R14

                MOVS    R0, R1, LSR#16
                MOVEQ   R1, R1, LSL#16
                MOVEQ   R0, #16
                MOVNE   R0, #0

                TST     R1, #255<<24
                MOVEQ   R1, R1, LSL#8
                ADDEQ   R0, R0, #8

                TST     R1, #15<<28
                MOVEQ   R1, R1, LSL#4
                ADDEQ   R0, R0, #4

                TST     R1, #3<<30
                MOVEQ   R1, R1, LSL#2
                ADDEQ   R0, R0, #2

                TST     R1, #1<<31
                ADDEQ   R0, R0, #1
                MOV     PC, R14

--
Nemo                                                          n...@20000.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phil  
View profile  
 More options Jan 24 2002, 6:50 pm
Newsgroups: comp.sys.arm
From: "Phil" <p...@miracle-designs.REMOVEME.com>
Date: Thu, 24 Jan 2002 23:50:06 GMT
Local: Thurs, Jan 24 2002 6:50 pm
Subject: Re: ARM7TDMI leading zero count source code
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

news:uelkfvfrf.fsf@yahoo.com...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
calypso  
View profile  
 More options Jan 24 2002, 7:45 pm
Newsgroups: comp.sys.arm
From: caly...@adresa.je.u.sigu.com
Date: 25 Jan 2002 00:44:11 GMT
Local: Thurs, Jan 24 2002 7:44 pm
Subject: Re: ARM7TDMI leading zero count source code
Bill Pringlemeir <bpringlem...@yahoo.com> wrote:

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

                        Damir Lukic
                        caly...@fly.srk.fer.hr


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
calypso  
View profile  
 More options Jan 24 2002, 7:45 pm
Newsgroups: comp.sys.arm
From: caly...@adresa.je.u.sigu.com
Date: 25 Jan 2002 00:41:10 GMT
Local: Thurs, Jan 24 2002 7:41 pm
Subject: Re: ARM7TDMI leading zero count source code
Phil <p...@miracle-designs-removeme.com> wrote:

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

                        Damir Lukic
                        caly...@fly.srk.fer.hr


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phil  
View profile  
 More options Jan 26 2002, 5:22 am
Newsgroups: comp.sys.arm
From: "Phil" <p...@miracle-designs.REMOVEME.com>
Date: Sat, 26 Jan 2002 10:22:33 GMT
Local: Sat, Jan 26 2002 5:22 am
Subject: Re: ARM7TDMI leading zero count source code
Thanks for your help guys!

I went for the binary approach... About 18 instructions for clz (including
0)

"Bill Pringlemeir" <bpringlem...@yahoo.com> wrote in message

news:u4rlbt3ed.fsf@yahoo.com...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Arjan Bakker  
View profile  
 More options Jan 27 2002, 9:12 am
Newsgroups: comp.sys.arm
From: "Arjan Bakker" <abe...@hetnet.nl>
Date: Sun, 27 Jan 2002 15:08:03 +0100
Local: Sun, Jan 27 2002 9:08 am
Subject: Re: ARM7TDMI leading zero count source code

Try this one:

@r0 is reg to clz
clz:
  movs r1,r0,lsr #16
  moveq r1,r0
  moveq r0,#16
  movne r0,#0
  movs r2,r1,lsr #8
  addeq r0,r0,#8
  moveq r2,r1
  movs r1,r2,lsr #4
  addeq r0,r0,#4
  moveq r1,r2
  movs r2,r1,lsr #2
  addeq r0,r0,#2
  moveq r2,r1
  movs r1,r2,lsr #1
  addeq r0,r0,#1
  subne r0,r0,#1
  addcc r0,r0,#1


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vadim Borshchev  
View profile  
 More options Jan 27 2002, 1:00 pm
Newsgroups: comp.sys.arm
From: Vadim Borshchev <vadim.borshc...@picsel.com>
Date: Sun, 27 Jan 2002 16:59:36 +0000
Local: Sun, Jan 27 2002 11:59 am
Subject: Re: ARM7TDMI leading zero count source code

Phil wrote:

> Does anyone have any fast source to calculate the number of leading zeros
> (like the v5 clz instruction) on ARM7TDMI ?

> Any suggestions how to do this are welcome.

Try the following code.  Compile to assembly output and do your best
optimizing it :)

/*  Count leading zeros */

static const unsigned clz_magic = 0x7dcd629;
static const char clz_table[] = {
     0, 31,  9, 30,  3,  8, 18, 29,
     2,  5,  7, 14, 12, 17, 22, 28,
     1, 10,  4, 19,  6, 15, 13, 23,
    11, 20, 16, 24, 21, 25, 26, 27

};

unsigned clz (unsigned x) {
    x |= (x >> 1);
    x |= (x >> 2);
    x |= (x >> 4);
    x |= (x >> 8);
    x |= (x >> 16);
    return x ? clz_table[((clz_magic * x) + clz_magic) >> 27] : 32;

}

/* Count trailing zeros */

static const unsigned ctz_magic = 0xfb9ac52;
static const char ctz_table[] = {
    31,  0, 22,  1, 28, 23, 13,  2,
    29, 26, 24, 17, 19, 14,  9,  3,
    30, 21, 27, 12, 25, 16, 18,  8,
    20, 11, 15,  7, 10,  6,  5,  4

};

unsigned ctz (unsigned x) {
    return (x &= -x) ? ctz_table[(x * ctz_magic) >> 27] : 32;

}

Sincerely,
  Vadim Borshchev

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam SPeight  
View profile  
 More options Jan 31 2002, 7:12 pm
Newsgroups: comp.sys.arm
From: AdamPA...@aol.com (Adam SPeight)
Date: 31 Jan 2002 16:12:40 -0800
Local: Thurs, Jan 31 2002 7:12 pm
Subject: Re: ARM7TDMI leading zero count source code

 3         2         1
10987654321098765432109876543210

-> r0 number
<- r0 =number of leading zero bits
   r1 =0
Compact version

       MOV   R1,R0
       MOV   r0,#0
.loop  MOV   r1,r1,lsl#1
       MOVCS pc,r14
       ADDCC r0,r0,#1
       BCC loop

unrolled version

MOV   r1,r0
MOV   R0,#0
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1
MOV   r1,r1,lsl#1
MOVCS pc,r14
ADDCC r0,r0,#1


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »