circom/c/buildasm/copy.asm.ejs
c/buildasm/copy.asm.ejsRaw
1
2;;;;;;;;;;;;;;;;;;;;;;
3; rawCopyS2L
4;;;;;;;;;;;;;;;;;;;;;;
5; Convert a 64 bit integer to a long format field element
6; Params:
7; rsi <= the integer
8; rdi <= Pointer to the overwritted element
9;
10; Nidified registers:
11; rax
12;;;;;;;;;;;;;;;;;;;;;;;
13
14rawCopyS2L:
15 mov al, 0x80
16 shl rax, 56
17 mov [rdi], rax ; set the result to LONG normal
18
19 cmp rsi, 0
20 js u64toLong_adjust_neg
21
22 mov [rdi + 8], rsi
23 xor rax, rax
24<% for (let i=1; i<n64; i++) { %>
25 mov [rdi + <%= 8+i*8 %>], rax
26<% } %>
27 ret
28
29u64toLong_adjust_neg:
30 add rsi, [q] ; Set the first digit
31 mov [rdi + 8], rsi ;
32
33 mov rsi, -1 ; all ones
34<% for (let i=1; i<n64; i++) { %>
35 mov rax, rsi ; Add to q
36 adc rax, [q + <%= i*8 %> ]
37 mov [rdi + <%= (i+1)*8 %>], rax
38<% } %>
39 ret