Comments (6)
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.
The cost of the constructor
Fr(int)
is almost the same as that ofFr::mul
because it uses Montgomery conversion.i*Fr(100)
is equal toFr(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.
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.
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.
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)
- "Ethereum" Serialization/deserialization HOT 17
- Cmake cross compile question HOT 1
- Curve question HOT 2
- Problems about cross-compile HOT 10
- Hash to G assumes data is in montgomery form HOT 2
- Undefined behavior (signed integer overflow) HOT 5
- Unable to compile cpp file in the sample folder HOT 13
- Generate random number of class Fr HOT 1
- mclBnFr_getBigEndian missing in bn.h HOT 1
- gmp support HOT 4
- IsValid method for GT HOT 1
- SetStr on G2 issue HOT 5
- mclBnG1_setDst not exist in C# version HOT 1
- op_ not initialized HOT 1
- Is there a user manual? HOT 2
- pairing method missing e: G1 x G1 -> G2 HOT 1
- Invalid result when using BLS12-381 HOT 14
- constructing a field from __int128 HOT 2
- Inquiry about Fr::mulSmall HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mcl.