circom/c/buildasm/copy.asm.ejs
c/buildasm/copy.asm.ejsRaw
1;;;;;;;;;;;;;;;;;;;;;;
2; copy
3;;;;;;;;;;;;;;;;;;;;;;
4; Copies
5; Params:
6; rsi <= the src
7; rdi <= the dest
8;
9; Nidified registers:
10; rax
11;;;;;;;;;;;;;;;;;;;;;;;
12<%=name%>_copy:
13<% for (let i=0; i<=n64; i++) { %>
14 mov rax, [rsi + <%= i*8 %>]
15 mov [rdi + <%= i*8 %>], rax
16<% } %>
17 ret
18
19;;;;;;;;;;;;;;;;;;;;;;
20; copy an array of integers
21;;;;;;;;;;;;;;;;;;;;;;
22; Copies
23; Params:
24; rsi <= the src
25; rdi <= the dest
26; rdx <= number of integers to copy
27;
28; Nidified registers:
29; rax
30;;;;;;;;;;;;;;;;;;;;;;;
31<%=name%>_copyn:
32<%=name%>_copyn_loop:
33 mov r8, rsi
34 mov r9, rdi
35 mov rax, <%= n64+1 %>
36 mul rdx
37 mov rcx, rax
38 cld
39 rep movsq
40 mov rsi, r8
41 mov rdi, r9
42 ret
43
44;;;;;;;;;;;;;;;;;;;;;;
45; rawCopyS2L
46;;;;;;;;;;;;;;;;;;;;;;
47; Convert a 64 bit integer to a long format field element
48; Params:
49; rsi <= the integer
50; rdi <= Pointer to the overwritted element
51;
52; Nidified registers:
53; rax
54;;;;;;;;;;;;;;;;;;;;;;;
55
56rawCopyS2L:
57 mov al, 0x80
58 shl rax, 56
59 mov [rdi], rax ; set the result to LONG normal
60
61 cmp rsi, 0
62 js u64toLong_adjust_neg
63
64 mov [rdi + 8], rsi
65 xor rax, rax
66<% for (let i=1; i<n64; i++) { %>
67 mov [rdi + <%= 8+i*8 %>], rax
68<% } %>
69 ret
70
71u64toLong_adjust_neg:
72 add rsi, [q] ; Set the first digit
73 mov [rdi + 8], rsi ;
74
75 mov rsi, -1 ; all ones
76<% for (let i=1; i<n64; i++) { %>
77 mov rax, rsi ; Add to q
78 adc rax, [q + <%= i*8 %> ]
79 mov [rdi + <%= (i+1)*8 %>], rax
80<% } %>
81 ret