MOD operator 
Author Message
 MOD operator

Hi,

I am trying to use the mod operator in my VHDL code, but my synthesis tool
only supports X MOD Y; where Y is a power of 2; X an integer.

What would be the equivalency between X MOD 255 and X MOD 256 ?
I would also like to find the equivalency between X MOD (2**m - 1) and
X MOD (2**m); where m is an integer.

Any help will be highly appreciated.

Thanks,
Michele



Mon, 28 Feb 2000 03:00:00 GMT  
 MOD operator

X= aY + r = Xn-1... X1 X0

X/Y = a
X mod Y = r    si Y=2**m   r=Xm-1...X1 X0,
that's why it's so trivial do perform X mod 2**m

X= a (Y-1+1) + r = a (Y-1) + (a+r)

=> X mod Y-1 = (X/Y + X mod Y ) mod Y-1 = Xn-1 ... Xm + Xm-1... X0 mod (Y-1)    
(if Y=2**m)

The advantage is that ^^ may be smaller than X. You can iterate the operation till
the result of the addition is less than Y-1. Note that it is easy to know the
maximum number of stages of addition you will need to perform the modulo.

Olivier



Mon, 28 Feb 2000 03:00:00 GMT  
 MOD operator


Quote:
>Hi,
>I am trying to use the mod operator in my VHDL code, but my synthesis tool
>only supports X MOD Y; where Y is a power of 2; X an integer.
>What would be the equivalency between X MOD 255 and X MOD 256 ?
>I would also like to find the equivalency between X MOD (2**m - 1) and
>X MOD (2**m); where m is an integer.
>Any help will be highly appreciated.
>Thanks,
>Michele

What synthesis tool are you using?  Possibly there is some
built-in function/component within a library for handling mod.

I had the same problem when I was trying to do multiply once, and the tool
required the second operand to be a power of 2.

-Bob



Wed, 01 Mar 2000 03:00:00 GMT  
 MOD operator

Quote:

>>I am trying to use the mod operator in my VHDL code, but my synthesis tool
>>only supports X MOD Y; where Y is a power of 2; X an integer.

>>What would be the equivalency between X MOD 255 and X MOD 256 ?
>>I would also like to find the equivalency between X MOD (2**m - 1) and
>>X MOD (2**m); where m is an integer.

There's not really any equivalency; knowing X mod 256 doesn't
help you compute X mod 255 in the general case.

However your problem is simpler if the range of X is restricted.
For example, If as I suspect you're doing Galois-field
operations, you might need to take X mod 255 where X is in
the range 0 through 509.  In that case

    X mod 255  = X       (if X < 255)
                 X-255   (otherwise)

Hope this helps a bit --

Steve



Fri, 03 Mar 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. awk's mod operator % question (application: log base2 non-integer result)

2. beginners:Synthesability of mod operator,and division query

3. Mod operator

4. Mod operator in Eclipse

5. MOD and /MOD with Pygmy Forth

6. SM/REM FM/MOD and UM/MOD on a 32bit cell ix86 Forth

7. Utils.Mod, ET.Mod

8. Mod-2 or Mod-3 for Mac

9. Mod-2 and Mod-3 compiler

10. Mod-2 and Mod-3 compiler for the IBM PC and compatibles

11. search algorithm for a math mod function (5 mod[2]=1)

12. operator overloading and user definable operators.

 

 
Powered by phpBB® Forum Software