COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### How to perform integer div with SIMD?

• Email
• Follow

```Hi,

is there a way to make use of MMX/SSE to do calculations like 'a mod b'
where 'a' and 'b' are integers?

I haven't found any useful instruction for such a task. Maybe this can be
done using floating point arithmetic. If yes - how?

Thanks,
Tom

```
 0

See related articles to this posting

```T.Kaz. wrote:
> Hi,
>
> is there a way to make use of MMX/SSE to do calculations like 'a mod b'
> where 'a' and 'b' are integers?
>
> I haven't found any useful instruction for such a task. Maybe this can be
> done using floating point arithmetic. If yes - how?

Yes, it can:

First, use the approximate reciprocal lookup to generate a set of
starting values, then one or two NR iterations (also in SIMD fp mode) to
get a more precise value.

Do the divisions in SIMD fp by multiplication by the reciprocal, then do
a parallel convert of these approximate/fp results to int.

Finally, you should multiply each of these results (which will either be
correct or maximum one off) by the original divisors, subtract, and
check the remainders:

from the result, add divisor to remainder.

If >= divisor, add one to result, subtract divisor from remainder.

Both of these can of course also be done easily on SIMD values with
parallel compares (which generate 0 or -1 masks), then using the mask to

This will give you both division result and remainder at the same time,
and it should be significantly faster than a single integer MOD operation.

OK?

Terje
--
- <Terje.Mathisen@hda.hydro.com>
"almost all programming can be viewed as an exercise in caching"

```
 0

1 Replies
643 Views

Similar Articles

12/20/2013 12:41:08 PM
page loaded in 286818 ms. (1)

Similar Artilces:

PIII Integer Performance Problems
Initially I posted the problem below to a webforum at SandPile.org, and I was redirected to a post in this group: http://groups.google.com/groups?q=andy+glew+processor+scheduler&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=8as0ju%244pp%40spool.cs.wisc.edu&rnum=2 i don't think that post answered my questions, but I got a nice hint, where the place for asking such thing might be (i.e. here). any help with the anomaly i discuss below will be highly appreciated! My intent is to detect the number and type of functional units in a CPU with running benchmark tests. Just for the sak...

mupip integ performance impact
Hi there, I am developing 24x7 security application running Linux and GT.M in such bl= ack-box (no remote access or administrator). The solution works great, but = after some bad experience we decided to perform regular integrity tests via= mupip integ. Since we are using 5.4 there's no problem to perform integ on= line, but we can't decide the test period. We successfuly tested cron-task = scheduled on every hour with no performance impact (database file size is a= lways 100MB, total count of indices in all globals <1 M), but we can't imag= ine what happens if something goes ...

Integer div and mod together?
Hi, I know I can do integer division with the / operator, and get the modulus with the % operator, but is there any function that calculates both values in one shot? It seems quite wasteful in time to do the division twice in order to get both of those values, when it would be quite easy to return them both from a single function. I saw someone's code implementing a divmod() function using assembler. But it doesn't look like there is a built-in function for doing that in C++, correct? Seeing as how I do a lot of mathematical calculations, I'm thinking of writing ...

Integer multiply performance of UltraSPARC chips
There are a few very negative comments about the performance of UltraSPARC processors on the pages of the GNU multi precision library (GMP), which is used for multiplying large integers. Here, where there are some benchmarks: http://www.swox.com/gmp/gmpbench.html it says "UltraSPARC 3's terrible scores are a result of its uniquely poor integer multiply support (unsuitable architectural support + simplistic integer multiply implementation)." Then here, where it talks about the performance of 32 vs 64 bit processors for computing with very large integers (>> 64 bits):...

scalar integer unit and SIMD share one pipeline
Hi, all There is one difference tween CPU and DSP. In x86, integer SIMD instructions are MMX instructions, but MMX in x86 is one functional unit, which means MMX has its own pipeline. In DSP, scalar integer unit and SIMD share one pipeline. Will it make register allocation in c compiler more complex? I think in x86 MMX has its own register file, register allocation may be less complex. Best Regards Jogging x86 MMX shares the register file with the x87 FPU x86 SSE has its own register file. joggingsong@gmail.com writes: > Hi, all > There is one difference tween CPU and DSP. In x...

Function performance profiling/floating point to integer conversion
Hi all, I often write simple functions to compare two different ways of performing the same/similar actions. Below is my test code for comparing two floating point to integer conversion techniques. Recently I'm wondering if this code is really reporting accurate timing figures - I measure ticks. Does anyone know any better techniques for simple function profiling? I'm using Mac OS X, PowerPC and Intel architectures. I do use my profiler (Shark) for complete applications but I prefer to write quick tests like these. I will start another thread regarding specific techniques for floa...

FAQ 4.8 How do I perform an operation on a series of integers? 228493
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 4.8: How do I perform an operation on a series of integers? To call a function on each element in an array, and collect the results, use: @results = map { my_func(\$_) } @array; For example: ...

FAQ 4.8 How do I perform an operation on a series of integers? 321404
This message is one of several periodic postings to comp.lang.perl.misc intended to make it easier for perl programmers to find answers to common questions. The core of this message represents an excerpt from the documentation provided with Perl. -------------------------------------------------------------------- 4.8: How do I perform an operation on a series of integers? To call a function on each element in an array, and collect the results, use: @results = map { my_func(\$_) } @array; For example: @triple = map { 3 * \$_ } @single; To call a function on...

FAQ 4.8 How do I perform an operation on a series of integers? #6 474425
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 4.8: How do I perform an operation on a series of integers? To call a function on each element in an array, and collect the results, use: @results = map { my_func(\$_) } @array; For e...

FAQ 4.8 How do I perform an operation on a series of integers? #2 215866
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 4.8: How do I perform an operation on a series of integers? To call a function on each element in an array, and collect the results, use: @results = map { my_func(\$_) } @array; For example: ...