From fa17bab40dad2cccc17c6c9418f4f6d2cf1fd060 Mon Sep 17 00:00:00 2001 From: Diederik Huys Date: Wed, 27 Mar 2013 14:13:52 +0100 Subject: [PATCH] Port to more generally used YASM assembler --- Makefile | 2 +- field.cpp | 4 ++-- lin64.asm | 30 ++++++++++++++---------------- lin64.h | 4 ++-- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 90f5402..bbe02e6 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/field.cpp b/field.cpp index ad3aef1..de51953 100644 --- a/field.cpp +++ b/field.cpp @@ -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 diff --git a/lin64.asm b/lin64.asm index 7d320dc..a59ce4d 100644 --- a/lin64.asm +++ b/lin64.asm @@ -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 diff --git a/lin64.h b/lin64.h index 6dc1367..b5c53ac 100644 --- a/lin64.h +++ b/lin64.h @@ -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