Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
AsmMontRedc32 Namespace Reference

Functions

 rotate (l, x)
 push ()
 pop ()
 MontRedcAdd (plimbs)
 PrintMult (plimbs)
 main (argv)

Variables

 sefOfLimbs = set()
int printOut = 0

Function Documentation

◆ main()

main ( argv)

Definition at line 163 of file AsmMontRedc32.py.

163def main(argv):
164 global printOut
165 if(len(argv) < 2):
166 print(
167 "\nplease specify the prime and type of execution [1 = only printing functions out, 0 = print full assembly]\n")
168 sys.exit()
169 else:
170 printOut = int(argv[1])
171 prime = argv[0]
172 length = 0
173
174 if(prime=="2047k221"):
175 length = 2048
176
177 elif(prime=="4095k256"):
178 length = 4096
179
180 elif(prime=="5119k234"):
181 length = 5120
182
183 elif(prime=="6143k256"):
184 length = 6144
185
186 elif(prime=="8191k332"):
187 length = 8192
188
189 elif(prime=="9215k384"):
190 length = 9216
191
192 else:
193 print("\nError : no prime available for this input\n")
194 sys.exit()
195
196
197 S = ".intel_syntax noprefix\n\n"
198 S = S + ".section .rodata\n\n"
199 S = S + ".section .text\n\n"
200
201 print(S)
202
203 plimbs = length//26
204 plimbs = 80
205
206 S = PrintMult(plimbs)
207
208
209 # S = ".global fp_mult_"+ str(plimbs) + "x" + str(plimbs) + "\n"
210 # S = S + "fp_mult_"+ str(plimbs) + "x" + str(plimbs) + ":\n"
211 # S = S + " mult_"+ str(plimbs) + "x" + str(plimbs) + "\n"
212 # S = S + " ret\n"
213
214 print(S)
215
216 S = MontRedcAdd(plimbs)
217
218 print(S)
219
220 print("\n")
221
int main(void)
Definition checkct.c:52
end if

References if, main(), MontRedcAdd(), and PrintMult().

Here is the call graph for this function:

◆ MontRedcAdd()

MontRedcAdd ( plimbs)

Definition at line 32 of file AsmMontRedc32.py.

32def MontRedcAdd(plimbs):
33
34
35 # registers reserved edi, esi, rdx
36 # eax, rbx = ecx, r8d
37 registers = ["r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d"]
38 registers64 = ["r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"]
39
40 state = registers[:plimbs]
41 state64 = registers64[:plimbs]
42 #state = registers
43
44 S = ""
45 # S = ".intel_syntax noprefix\n\n"
46 # S = S + ".section .rodata\n\n"
47 # S = S + ".section .text\n\n"
48
49 # S = S + ".macro p_times_w\n"
50 # S = S + "mult_"+ str(plimbs) + "x" + str(plimbs) + ":\n"
51
52 S = S + ".global secsidh_internal_2047k221_a_plus_u_i\nsecsidh_internal_2047k221_a_plus_u_i:\n"
53
54 S = S + push()
55
56 S = S + " lea rdx, [rdi + 0]\n"
57# intro
58 S = S + " mov rax, [rsi + 0]\n"
59 S = S + " add eax, [edx + 0]\n"
60 S = S + " mov [rdi + 0], rax\n"
61# loop
62 S = S + " .set k, 1\n"
63 S = S + " .rept " + str(plimbs) + "\n"
64 S = S + " mov rax, [rsi + 4*k]\n"
65 S = S + " adc eax, [edx + 4*k]\n"
66 S = S + " mov [rdi + 4*k], rax\n"
67 S = S + " .set k, k+1\n"
68 S = S + " .endr\n"
69# outro
70 S = S + " mov rax, [rdi + 4*" + str(plimbs+1) + "]\n"
71 S = S + " adc eax, 0\n"
72 S = S + " mov [rdi + 4*" + str(plimbs+1) + "], rax\n"
73 S = S + pop()
74 S = S + " ret\n"
75
76 return S
77

References pop(), and push().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop()

pop ( )

Definition at line 24 of file AsmMontRedc32.py.

24def pop():
25 # S = "# -------------------\n"
26 S = "# pop\n"
27 # S = S + " pop r15d\n pop r14d\n pop r13d\n pop r12d\n pop esi\n pop edi\n pop rbp\n pop rbx\n\n"
28 S = S + " pop r15\n pop r14\n pop r13\n pop r12\n pop rsi\n pop rbp\n pop rbx\n\n"
29 # S = S + " pop esi\n pop edi\n pop rdx\n\n"
30 return S
31

Referenced by MontRedcAdd(), and PrintMult().

Here is the caller graph for this function:

◆ PrintMult()

PrintMult ( plimbs)

Definition at line 78 of file AsmMontRedc32.py.

78def PrintMult(plimbs):
79
80
81 # registers reserved edi, esi, rdx
82 # eax, rbx = ecx, r8d
83 registers = ["r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d"]
84 registers64 = ["r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"]
85
86 # if(plimbs > len(registers)):
87 # print("ERROR: Index out range")
88 # exit()
89 state = registers[:plimbs]
90 state64 = registers64[:plimbs]
91
92 S = ""
93 # S = ".intel_syntax noprefix\n\n"
94 # S = S + ".section .rodata\n\n"
95 # S = S + ".section .text\n\n"
96
97 # S = S + ".macro p_times_w\n"
98 # S = S + "mult_"+ str(plimbs) + "x" + str(plimbs) + ":\n"
99
100 S = S + ".global secsidh_internal_2047k221_p_times_w\nsecsidh_internal_2047k221_p_times_w:\n"
101
102 S = S + push()
103
104 S = S + " mov r15d, edx\n"
105 S = S + " mov eax, r15d\n"
106 S = S + " mov " + state[0] + ", [esi + 0*4]\n"
107 S = S + " imul " + state[0] + "\n"
108 S = S + " mov rbx, rax\n"
109 S = S + " and ebx, 67108863\n"
110 S = S + " mov [rdi + 0*4], rbx\n"
111 S = S + " shr rax, 26\n";
112 S = S + " add rdx, rax\n"
113 S = S + " mov " + state64[0] + ", rdx\n"
114 S = S + "#############################\n"
115 for j in range(1,plimbs):
116 if(j == plimbs-1):
117 S = S + " mov " + state[j%2] + ", [esi + " + str(j) + "*4]\n"
118 S = S + " mov eax, r15d\n"
119 S = S + " imul " + state[j%2] + "\n"
120 S = S + " mov rbx, rax\n"
121 S = S + " add ebx, " + state[(j+1)%2] + "\n";
122 S = S + " and ebx, 67108863\n"
123 S = S + " mov [rdi + " + str(j) + "*4], rbx\n"
124 S = S + " shr rax, 26\n";
125 S = S + " add rdx, rax\n"
126 S = S + " mov " + state64[j%2] + ", rdx\n"
127 S = S + " adc " + state[j%2] + ", 0\n"
128 S = S + " mov [rdi + " + str(j) + "*4], " + state64[(j+1)%2] + "\n"
129 S = S + " mov [rdi + " + str(j+1) + "*4], " + state64[j%2] + "\n"
130 S = S + "#############################\n"
131 elif(j == 1):
132 S = S + " mov " + state[j%2] + ", [esi + " + str(j) + "*4]\n"
133 S = S + " mov eax, r15d\n"
134 S = S + " imul " + state[j%2] + "\n"
135 S = S + " mov rbx, rax\n"
136 S = S + " add ebx, " + state[(j+1)%2] + "\n";
137 S = S + " and ebx, 67108863\n"
138 S = S + " mov [rdi + " + str(j) + "*4], rbx\n"
139 S = S + " shr rax, 26\n";
140 S = S + " add rdx, rax\n"
141 S = S + " mov " + state64[j%2] + ", rdx\n"
142 S = S + "#############################\n"
143 else:
144 S = S + " mov " + state[j%2] + ", [esi + " + str(j) + "*4]\n"
145 S = S + " mov eax, r15d\n"
146 S = S + " imul " + state[j%2] + "\n"
147 S = S + " mov rbx, rax\n"
148 S = S + " add ebx, " + state[(j+1)%2] + "\n";
149 S = S + " and ebx, 67108863\n"
150 S = S + " mov [rdi + " + str(j) + "*4], rbx\n"
151 S = S + " shr rax, 26\n";
152 S = S + " add rdx, rax\n"
153 S = S + " mov " + state64[j%2] + ", rdx\n"
154 S = S + "#############################\n"
155
156 S = S + pop()
157
158 S = S + " ret\n"
159 return S
160
161#//+++++++++++++++ Main ++++++++++++++++++//
162

References if, pop(), and push().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push()

push ( )

Definition at line 16 of file AsmMontRedc32.py.

16def push():
17 # S = "# -------------------\n"
18 S = "# push\n"
19 # S = S + " push rbx\n push rbp\n push edi\n push esi\n push r12d\n push r13d\n push r14d\n push r15d\n\n"
20 S = S + " push rbx\n push rbp\n push rsi\n push r12\n push r13\n push r14\n push r15\n\n"
21 # S = S + " push rdx\n push edi\n push esi\n\n"
22 return S
23

Referenced by MontRedcAdd(), and PrintMult().

Here is the caller graph for this function:

◆ rotate()

rotate ( l,
x )

Definition at line 13 of file AsmMontRedc32.py.

13def rotate(l, x):
14 return l[-x:] + l[:-x]
15

Variable Documentation

◆ printOut

int printOut = 0

Definition at line 11 of file AsmMontRedc32.py.

◆ sefOfLimbs

sefOfLimbs = set()

Definition at line 10 of file AsmMontRedc32.py.