mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 19:23:26 -03:00
Port to more generally used YASM assembler
This commit is contained in:
parent
d9137bb2d8
commit
fa17bab40d
4 changed files with 19 additions and 21 deletions
2
Makefile
2
Makefile
|
@ -28,7 +28,7 @@ LIBS:=-lgmp obj/lin64.o
|
||||||
SECP256K1_FILES := $(SECP256K1_FILES) num_gmp.h num_gmp.cpp obj/lin64.o
|
SECP256K1_FILES := $(SECP256K1_FILES) num_gmp.h num_gmp.cpp obj/lin64.o
|
||||||
|
|
||||||
obj/lin64.o: lin64.asm
|
obj/lin64.o: lin64.asm
|
||||||
/tmp/jwasm -Fo obj/lin64.o -elf64 lin64.asm
|
yasm -f elf64 -o obj/lin64.o lin64.asm
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -168,7 +168,7 @@ void FieldElem::SetMult(const FieldElem &a, const FieldElem &b) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INLINE_ASM
|
#ifdef INLINE_ASM
|
||||||
_ExSetMult((uint64_t *) a.n,(uint64_t *) b.n, (uint64_t *) n);
|
ExSetMult((uint64_t *) a.n,(uint64_t *) b.n, (uint64_t *) n);
|
||||||
#else
|
#else
|
||||||
unsigned __int128 c = (__int128)a.n[0] * b.n[0];
|
unsigned __int128 c = (__int128)a.n[0] * b.n[0];
|
||||||
uint64_t t0 = c & 0xFFFFFFFFFFFFFULL; c = c >> 52; // c max 0FFFFFFFFFFFFFE0
|
uint64_t t0 = c & 0xFFFFFFFFFFFFFULL; c = c >> 52; // c max 0FFFFFFFFFFFFFE0
|
||||||
|
@ -232,7 +232,7 @@ void FieldElem::SetSquare(const FieldElem &a) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INLINE_ASM
|
#ifdef INLINE_ASM
|
||||||
_ExSetSquare((uint64_t *)a.n,(uint64_t *)n);
|
ExSetSquare((uint64_t *)a.n,(uint64_t *)n);
|
||||||
#else
|
#else
|
||||||
__int128 c = (__int128)a.n[0] * a.n[0];
|
__int128 c = (__int128)a.n[0] * a.n[0];
|
||||||
uint64_t t0 = c & 0xFFFFFFFFFFFFFULL; c = c >> 52; // c max 0FFFFFFFFFFFFFE0
|
uint64_t t0 = c & 0xFFFFFFFFFFFFFULL; c = c >> 52; // c max 0FFFFFFFFFFFFFE0
|
||||||
|
|
30
lin64.asm
30
lin64.asm
|
@ -4,19 +4,13 @@
|
||||||
;; ExSetMult
|
;; ExSetMult
|
||||||
;; ExSetSquare
|
;; ExSetSquare
|
||||||
;;
|
;;
|
||||||
;; Needed tools: JWASM (http://www.japheth.de/JWasm.html)
|
;; Needed tools: YASM (http://www.japheth.de/JWasm.html)
|
||||||
;;
|
|
||||||
;; !!! WARNING !!! !!! WARNING !!! !!! WARNING !!!
|
|
||||||
;;
|
|
||||||
;; Please note that recompiling this binary (jwasm) under a 64-bit OS
|
|
||||||
;; may yield unexpected results and create a corrupted ELF64 header.
|
|
||||||
;;
|
;;
|
||||||
;;
|
;;
|
||||||
|
|
||||||
.x64
|
BITS 64
|
||||||
QTEST EQU 1
|
|
||||||
.code
|
;; Procedure ExSetMult
|
||||||
|
|
||||||
;; Register Layout:
|
;; Register Layout:
|
||||||
;; INPUT: rdi = a.n
|
;; INPUT: rdi = a.n
|
||||||
;; rsi = b.n
|
;; rsi = b.n
|
||||||
|
@ -31,7 +25,10 @@ QTEST EQU 1
|
||||||
;; rcx = b.n[3] / t7
|
;; rcx = b.n[3] / t7
|
||||||
;; rbp = Constant 0FFFFFFFFFFFFFh / t8
|
;; rbp = Constant 0FFFFFFFFFFFFFh / t8
|
||||||
;; rsi = b.n / b.n[4] / t9
|
;; rsi = b.n / b.n[4] / t9
|
||||||
ExSetMult PROC C PUBLIC USES rbx rbp r12 r13 r14 r15
|
|
||||||
|
GLOBAL ExSetMult
|
||||||
|
ALIGN 32
|
||||||
|
ExSetMult:
|
||||||
push rdx
|
push rdx
|
||||||
mov r14,[rsi+8*0] ; preload b.n[0]. This will be the case until
|
mov r14,[rsi+8*0] ; preload b.n[0]. This will be the case until
|
||||||
; b.n[0] is no longer needed, then we reassign
|
; b.n[0] is no longer needed, then we reassign
|
||||||
|
@ -217,7 +214,7 @@ ExSetMult PROC C PUBLIC USES rbx rbp r12 r13 r14 r15
|
||||||
mov rsi,r8 ; load c into t9 and destroy b.n[4]
|
mov rsi,r8 ; load c into t9 and destroy b.n[4]
|
||||||
|
|
||||||
;; *******************************************************
|
;; *******************************************************
|
||||||
common_exit_norm::
|
common_exit_norm:
|
||||||
mov rdi,01000003D10h ; load constant
|
mov rdi,01000003D10h ; load constant
|
||||||
|
|
||||||
mov rax,r15 ; get t5
|
mov rax,r15 ; get t5
|
||||||
|
@ -290,9 +287,9 @@ common_exit_norm::
|
||||||
add r8,r11
|
add r8,r11
|
||||||
mov [rbx+1*8],r8 ; -> this.n[1]
|
mov [rbx+1*8],r8 ; -> this.n[1]
|
||||||
ret
|
ret
|
||||||
ExSetMult ENDP
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; PROC ExSetSquare
|
||||||
;; Register Layout:
|
;; Register Layout:
|
||||||
;; INPUT: rdi = a.n
|
;; INPUT: rdi = a.n
|
||||||
;; rsi = this.a
|
;; rsi = this.a
|
||||||
|
@ -305,7 +302,9 @@ ExSetMult ENDP
|
||||||
;; rcx = a.n[3] / t7
|
;; rcx = a.n[3] / t7
|
||||||
;; rbp = 0FFFFFFFFFFFFFh / t8
|
;; rbp = 0FFFFFFFFFFFFFh / t8
|
||||||
;; rsi = a.n[4] / a.n[4] /t9
|
;; rsi = a.n[4] / a.n[4] /t9
|
||||||
ExSetSquare PROC C PUBLIC USES rbx rbp r12 r13 r14 r15
|
GLOBAL ExSetSquare
|
||||||
|
ALIGN 32
|
||||||
|
ExSetSquare:
|
||||||
push rsi
|
push rsi
|
||||||
mov rbp,0FFFFFFFFFFFFFh
|
mov rbp,0FFFFFFFFFFFFFh
|
||||||
|
|
||||||
|
@ -440,7 +439,6 @@ ExSetSquare PROC C PUBLIC USES rbx rbp r12 r13 r14 r15
|
||||||
|
|
||||||
;; *******************************************************
|
;; *******************************************************
|
||||||
jmp common_exit_norm
|
jmp common_exit_norm
|
||||||
ExSetSquare ENDP
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
4
lin64.h
4
lin64.h
|
@ -2,8 +2,8 @@
|
||||||
#define _SECP256K1_LIN64
|
#define _SECP256K1_LIN64
|
||||||
|
|
||||||
#ifdef INLINE_ASM
|
#ifdef INLINE_ASM
|
||||||
extern "C" void _ExSetMult(uint64_t *, uint64_t *, uint64_t *);
|
extern "C" void __attribute__ ((sysv_abi)) ExSetMult(uint64_t *, uint64_t *, uint64_t *);
|
||||||
extern "C" void _ExSetSquare(uint64_t *, uint64_t *);
|
extern "C" void __attribute__ ((sysv_abi)) ExSetSquare(uint64_t *, uint64_t *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue