11pub ( crate ) const MSM_ASSEMBLY : & str = "
22 ; We are passed three pointers and one usize.
3- ; d0 points to the points. Points are represented by (x: Field, y: Field, is_infinite: bool)
3+ ; d0 points to the points. Points are represented by (x: Field, y: Field).
44 ; d1 points to the scalars. Scalars are represented by (lo: Field, hi: Field) both range checked to 128 bits.
55 ; d2 contains the number of points.
66 ; d3 points to the result. The result is a point.
77 ADD d3, /*the reserved register 'one_usize'*/ $2, d4; Compute the pointer to the result y.
8- ADD d4, $2, d5; Compute the pointer to the result is_infinite
98 ; Initialize the msm result: point at infinity
109 SET i3, 0 ff
1110 SET i4, 0 ff
12- SET i5, 1 u1
1311 ; Loop globals
1412 SET d6, 0 u32; Initialize the outer loop variable, ranging from 0 to the number of points
1513 SET d8, 0 ff; Initialize a 0 FF
@@ -18,13 +16,12 @@ pub(crate) const MSM_ASSEMBLY: &str = "
1816 SET d10, 128 u32; Initialize a constant 128
1917 SET d11, 1 u1; Initialize a constant true
2018 SET d12, 0 u1; Initialize a constant false
21- SET d13, 2 u32; Initialize a constant 2
22- SET d14, 3 u32; Initialize a constant 3 for computing pointers to the point components
19+ SET d13, 2 u32; Initialize a constant 2 for computing pointers to point and scalar components
2320 ; Main loop: iterate over the points/scalars
2421OUTER_HEAD: LT d6, d2, d15 ; Check if we are done with the outer loop
2522 JUMPI d15, OUTER_BODY
2623 JUMP OUTER_END
27- OUTER_BODY: MUL d6, d14 , d16; Compute the pointer to the point
24+ OUTER_BODY: MUL d6, d13 , d16; Compute the pointer to the point
2825 ADD d16, d0, d16;
2926 MUL d6, d13, d17; Compute the pointer to the scalar lo
3027 ADD d17, d1, d17
@@ -51,35 +48,32 @@ FIND_MSB_BODY: JUMPI i19, FIND_MSB_END; Check if the current bit is one
5148 JUMP FIND_MSB_BODY
5249 ; Now we have the pointer of the MSB in d19
5350
54- ; Now store the result of the scalar multiplication in d22, d23, d24
51+ ; Now store the result of the scalar multiplication in d22, d23
5552FIND_MSB_END: MOV i16, d22; x
5653 ADD d16, $2, d25; pointer to y
5754 MOV i25, d23; y
58- ADD d25, $2, d25; pointer to is_infinite
59- MOV i25, d24; is_infinite
60- ; Also store the original point in d25, d26, d27
55+ ; Also store the original point in d25, d26
6156 MOV d22, d25; x
6257 MOV d23, d26; y
63- MOV d24, d27; is_infinite
6458
6559 ; Now we need to do the inner loop, that will do double then add
6660 ; We need to iterate from the pointer of the MSB + 1 to the end pointer (d21)
6761 ADD d19, $2, d19; We start from the pointer of the MSB + 1
6862INNER_HEAD: LT d19, d21, d28; Check if we are done with the loop
6963 JUMPI d28, INNER_BODY
7064 JUMP INNER_END
71- INNER_BODY: ECADD d22, d23, d24, d22, d23, d24, /*not indirect, so the result is stored in d22, d23, d24 */ d22; Double the current result.
65+ INNER_BODY: ECADD d22, d23, d22, d23, /*not indirect, so the result is stored in d22, d23*/ d22; Double the current result.
7266 EQ i19, d12, d28; Check if the current bit is zero
7367 JUMPI d28, INNER_INC; If the current bit is zero, continue
74- ECADD d25, d26, d27, d22, d23, d24, /*not indirect, so the result is stored in d22, d23, d24 */ d22; Add the original point to the result
68+ ECADD d25, d26, d22, d23, /*not indirect, so the result is stored in d22, d23*/ d22; Add the original point to the result
7569INNER_INC: ADD d19, $2, d19; Increment the pointer
7670 JUMP INNER_HEAD
7771
7872 ; After the inner loop we have computed the scalar multiplication. Add it to the msm result
79- INNER_END: ECADD i3, i4, i5, d22, d23, d24 , i3; Add the result to the msm result
73+ INNER_END: ECADD i3, i4, d22, d23, i3; Add the result to the msm result
8074OUTER_INC: ADD d6, $2, d6; Increment the outer loop variable
8175 JUMP OUTER_HEAD
82- ; After the outer loop we have computed the msm. We can return since we wrote the result in i3, i4, i5
76+ ; After the outer loop we have computed the msm. We can return since we wrote the result in i3, i4
8377OUTER_END: INTERNALRETURN
8478" ;
8579
0 commit comments