Port to more generally used YASM assembler

This commit is contained in:
Diederik Huys 2013-03-27 14:13:52 +01:00
parent d9137bb2d8
commit fa17bab40d
4 changed files with 19 additions and 21 deletions

View File

@ -28,7 +28,7 @@ LIBS:=-lgmp obj/lin64.o
SECP256K1_FILES := $(SECP256K1_FILES) num_gmp.h num_gmp.cpp obj/lin64.o
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

View File

@ -168,7 +168,7 @@ void FieldElem::SetMult(const FieldElem &a, const FieldElem &b) {
#endif
#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
unsigned __int128 c = (__int128)a.n[0] * b.n[0];
uint64_t t0 = c & 0xFFFFFFFFFFFFFULL; c = c >> 52; // c max 0FFFFFFFFFFFFFE0
@ -232,7 +232,7 @@ void FieldElem::SetSquare(const FieldElem &a) {
#endif
#ifdef INLINE_ASM
_ExSetSquare((uint64_t *)a.n,(uint64_t *)n);
ExSetSquare((uint64_t *)a.n,(uint64_t *)n);
#else
__int128 c = (__int128)a.n[0] * a.n[0];
uint64_t t0 = c & 0xFFFFFFFFFFFFFULL; c = c >> 52; // c max 0FFFFFFFFFFFFFE0

View File

@ -4,19 +4,13 @@
;; ExSetMult
;; ExSetSquare
;;
;; Needed tools: JWASM (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.
;; Needed tools: YASM (http://www.japheth.de/JWasm.html)
;;
;;
.x64
QTEST EQU 1
.code
BITS 64
;; Procedure ExSetMult
;; Register Layout:
;; INPUT: rdi = a.n
;; rsi = b.n
@ -31,7 +25,10 @@ QTEST EQU 1
;; rcx = b.n[3] / t7
;; rbp = Constant 0FFFFFFFFFFFFFh / t8
;; 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
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
@ -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]
;; *******************************************************
common_exit_norm::
common_exit_norm:
mov rdi,01000003D10h ; load constant
mov rax,r15 ; get t5
@ -290,9 +287,9 @@ common_exit_norm::
add r8,r11
mov [rbx+1*8],r8 ; -> this.n[1]
ret
ExSetMult ENDP
;; PROC ExSetSquare
;; Register Layout:
;; INPUT: rdi = a.n
;; rsi = this.a
@ -305,7 +302,9 @@ ExSetMult ENDP
;; rcx = a.n[3] / t7
;; rbp = 0FFFFFFFFFFFFFh / t8
;; 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
mov rbp,0FFFFFFFFFFFFFh
@ -440,7 +439,6 @@ ExSetSquare PROC C PUBLIC USES rbx rbp r12 r13 r14 r15
;; *******************************************************
jmp common_exit_norm
ExSetSquare ENDP
end

View File

@ -2,8 +2,8 @@
#define _SECP256K1_LIN64
#ifdef INLINE_ASM
extern "C" void _ExSetMult(uint64_t *, uint64_t *, uint64_t *);
extern "C" void _ExSetSquare(uint64_t *, uint64_t *);
extern "C" void __attribute__ ((sysv_abi)) ExSetMult(uint64_t *, uint64_t *, uint64_t *);
extern "C" void __attribute__ ((sysv_abi)) ExSetSquare(uint64_t *, uint64_t *);
#endif
#endif