Git Product home page Git Product logo

Comments (6)

herumi avatar herumi commented on August 19, 2024

The cost of the constructor Fr(int) is almost the same as that of Fr::mul because it uses Montgomery conversion.
i*Fr(100) is equal to Fr(i)*Fr(100).

If you need many small integer multiplication, then, for example, how about making a table of Fr and using it?

const int N = 256;
static Fr FrTbl[N];
for (int i = 0; i < N; i++) {
  FrTbl[i] = i;
}

Or you can use Fr::mulSmall(Fr& z, const Fr& x, uint32_t y) for y in [0, 9].

from mcl.

quwenjie avatar quwenjie commented on August 19, 2024

The cost of the constructor Fr(int) is almost the same as that of Fr::mul because it uses Montgomery conversion. i*Fr(100) is equal to Fr(i)*Fr(100).

If you need many small integer multiplication, then, for example, how about making a table of Fr and using it?

const int N = 256;
static Fr FrTbl[N];
for (int i = 0; i < N; i++) {
  FrTbl[i] = i;
}

Or you can use Fr::mulSmall(Fr& z, const Fr& x, uint32_t y) for y in [0, 9].

Thanks for your reply. Actually I want is a dot product between a vector of many field elements, and a vector of many small integers(0-255). I am wondering whether there is a better way to implement it instead of directly using Fr(int) then multiply with the field elements.

from mcl.

herumi avatar herumi commented on August 19, 2024

Fr::mul is one of the fastest implementations in the world.
How much faster do you expect it to be if I implement the multiplication of Fr and an integer?
If implemented, it would not be many times faster.
Fr::mulSmall contains mulUnit 256bit x 64bit -> 320bit, table lookup (or 2-time mulUnit), and 2-time sub or some bit operations.
The benchmark of Fr::mulSmall (Fr is a 256-bit integer) and Fp::mul is the following:

func Fr::mul Fr::mulSmall
clk 31 24

If you still want it, I will consider implementing it, but it is not a high priority.

from mcl.

quwenjie avatar quwenjie commented on August 19, 2024

Thanks, I found out that modifying the constant 9 to 255 in gmp_utils.hpp seems to work. Is this the correct way?

from mcl.

herumi avatar herumi commented on August 19, 2024

I'm sorry I missed your question. I think it's probably okay. I'll check back later when I get more time.

from mcl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.