Sign in to follow this  
Followers 0
BITS N BYTES

COMPARE MULTIPLE WORDS

8 posts in this topic

I am using used the BCNT instruction to obtain the number of ON bits in 16 words of data. Does any one have a simple yet FAST [least # instructions] that will achieve the same result but on a word array. The array spans 160 words from D1-D160. Each word contains either a value or a 0. I have found the TCMP instruction that seems to satisfy my needs, but I have to do this 16 times, either with 16 instructions or a single instruction with a FOR NEXT loop. Each TCMP instruction compares the values of in 16 word groups with 0 and outputs the results in D201 thru D216. A final BCNT on D210-260 gives the total words between D1-D160 that are greater than 0. This is used within an interrupt on a CJ1M and I need the speed to be as fast as possible. Any neat ideas from the GURUS?? Need to know how many

Share this post


Link to post
Share on other sites
I meant to say "repeat TCMP instruction 10 times" NOT 16.

Share this post


Link to post
Share on other sites
1. Use TCMP instruction ina FOR-NEXT loop set for 10 times. 2. If you have a Version 2 or Version 3 CPU, there is a new instruction which compares the source word (#0000) to 256 words - BCMP2(502).

Share this post


Link to post
Share on other sites
NOT DOING TOO WELL TODAY!! Should read:- "Each TCMP instruction compares the values in 16 word groups [D1-D16 then D17-D32 etc. etc] with 0 and outputs the results in D201 thru D216 [TCMP on D1-16 outputs in D201 then TCMP on D17-D32 outputs in D202 etc. etc.] A final BCNT on D201-216 gives the total words between D1-D160 that are greater than 0."

Share this post


Link to post
Share on other sites
The above suggestions would still do the job.

Share this post


Link to post
Share on other sites
Thanks again Jay. Found this new instruction in the latest manual you sent. As a matter of interest how does one estimate instruction times for Omron instructions when the multiple word execution times are NOT a direct multiple of the single word times. For example the BCNT2 instruction execution times for a CJ1M-CPU21 is quoted as 16 microseconds for 1 word and 757.67 for 1000 words. How do you recommend one should estimate the execution time for 160 words? How do you apply this to similar instructions where single and multiple word execution times do not appear to be directly proportional?

Share this post


Link to post
Share on other sites
No way without tables from the Japanese engineers. Suggest you run it in a loop for 1000 times and check increase in cycle time. Then divide by 1000 for exact overhead.

Share this post


Link to post
Share on other sites
THNX I'll try the test in my application. If the Japanese engineers have tables, do they also have chairs and desks?? Maybe they've been on the Saki too much!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0