diff options
author | lloyd <[email protected]> | 2006-09-24 14:34:51 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-09-24 14:34:51 +0000 |
commit | 877f1a962e2b4b57dbef914eda3ef9b40a771b55 (patch) | |
tree | d485327d4dd499a07f150db7dc2f55af16d9fe6f | |
parent | 623917ff27073b3471b7e2fc200d4f2e9217fd86 (diff) |
Initial x86-64 assembly code for the inner multiply-add loop.
-rw-r--r-- | modules/alg_amd64/asm_macr.h | 81 | ||||
-rw-r--r-- | modules/alg_amd64/modinfo.txt | 34 | ||||
-rw-r--r-- | modules/alg_amd64/mp_muladd.S | 60 |
3 files changed, 175 insertions, 0 deletions
diff --git a/modules/alg_amd64/asm_macr.h b/modules/alg_amd64/asm_macr.h new file mode 100644 index 000000000..689bfa3cb --- /dev/null +++ b/modules/alg_amd64/asm_macr.h @@ -0,0 +1,81 @@ +/************************************************* +* Assembly Macros Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_EXT_ASM_MACROS_H__ +#define BOTAN_EXT_ASM_MACROS_H__ + +/************************************************* +* General/Global Macros * +*************************************************/ +#define ALIGN .p2align 4,,15 + +#define START_LISTING(FILENAME) \ + .file #FILENAME; \ + .text; \ + ALIGN; + +/************************************************* +* Function Definitions * +*************************************************/ +#define START_FUNCTION(func_name) \ + ALIGN; \ + .global func_name; \ + .type func_name,@function; \ +func_name: + +#define END_FUNCTION(func_name) \ + ret + +/************************************************* +* Loop Control * +*************************************************/ +#define START_LOOP(LABEL) \ + ALIGN; \ + LABEL##_LOOP: + +#define LOOP_UNTIL_EQ(REG, NUM, LABEL) \ + cmp IMM(NUM), REG; \ + jne LABEL##_LOOP + +#define LOOP_UNTIL_LT(REG, NUM, LABEL) \ + cmp IMM(NUM), REG; \ + jge LABEL##_LOOP + +/************************************************* + Conditional Jumps * +*************************************************/ +#define JUMP_IF_ZERO(REG, LABEL) \ + cmp IMM(0), REG; \ + jz LABEL + +#define JUMP_IF_LT(REG, NUM, LABEL) \ + cmp IMM(NUM), REG; \ + jl LABEL + +/************************************************* +* Memory Access Operations * +*************************************************/ +#define ARRAY8(REG, NUM) 8*(NUM)(REG) + +#define ASSIGN(TO, FROM) mov FROM, TO + +/************************************************* +* ALU Operations * +*************************************************/ +#define IMM(VAL) $VAL + +#define ADD(TO, FROM) addq FROM, TO +#define ADD_IMM(TO, NUM) ADD(TO, IMM(NUM)) +#define ADD_W_CARRY(TO1, TO2, FROM) addq FROM, TO1; adcq IMM(0), TO2; +#define SUB_IMM(TO, NUM) sub IMM(NUM), TO +#define MUL(REG) mulq REG + +#define XOR(TO, FROM) xorq FROM, TO +#define AND(TO, FROM) andq FROM, TO +#define OR(TO, FROM) orq FROM, TO +#define NOT(REG) notq REG +#define ZEROIZE(REG) XOR(REG, REG) + +#endif diff --git a/modules/alg_amd64/modinfo.txt b/modules/alg_amd64/modinfo.txt new file mode 100644 index 000000000..5f1a98ea3 --- /dev/null +++ b/modules/alg_amd64/modinfo.txt @@ -0,0 +1,34 @@ +realname "Algorithm x86-64 Assembler" + +mp_bits 64 + +<replace> +#sha160.cpp +</replace> + +<ignore> +mp_muladd.cpp +</ignore> + +<add> +asm_macr.h +mp_muladd.S +#sha1core.S +</add> + +<arch> +amd64 +</arch> + +<cc> +gcc +</cc> + +# ELF systems +<os> +linux +freebsd +netbsd +openbsd +solaris +</os> diff --git a/modules/alg_amd64/mp_muladd.S b/modules/alg_amd64/mp_muladd.S new file mode 100644 index 000000000..e34b855bb --- /dev/null +++ b/modules/alg_amd64/mp_muladd.S @@ -0,0 +1,60 @@ +/************************************************* +* Multiply/Add Algorithm Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include <botan/asm_macr.h> + +START_LISTING(mp_muladd.S) + +START_FUNCTION(bigint_mul_add_words) +#define LOOP_CTR %r11d +#define X_ARR %rsi +#define Z_ARR %rdi +#define Y %rcx +#define CARRY %r8 + + ZEROIZE(CARRY) + + ASSIGN(LOOP_CTR, %edx) + + JUMP_IF_ZERO(LOOP_CTR, .DONE) + JUMP_IF_LT(LOOP_CTR, 8, .MULADD1_LOOP) + +#define MULADD_OP(N) \ + ASSIGN(%rax, ARRAY8(X_ARR, N)) ; \ + ASSIGN(%r9, ARRAY8(Z_ARR, N)) ; \ + MUL(Y) ; \ + ADD_W_CARRY(%rax, %rdx, CARRY) ; \ + ADD_W_CARRY(%rax, %rdx, %r9) ; \ + ASSIGN(CARRY, %rdx) ; \ + ASSIGN(ARRAY8(Z_ARR, N), %rax) + +START_LOOP(.MULADD8) + MULADD_OP(0) + MULADD_OP(1) + MULADD_OP(2) + MULADD_OP(3) + MULADD_OP(4) + MULADD_OP(5) + MULADD_OP(6) + MULADD_OP(7) + + SUB_IMM(LOOP_CTR, 8) + ADD_IMM(Z_ARR, 64) + ADD_IMM(X_ARR, 64) +LOOP_UNTIL_LT(LOOP_CTR, 8, .MULADD8) + + JUMP_IF_ZERO(LOOP_CTR, .DONE) + +START_LOOP(.MULADD1) + MULADD_OP(0) + + SUB_IMM(LOOP_CTR, 1) + ADD_IMM(Z_ARR, 8) + ADD_IMM(X_ARR, 8) +LOOP_UNTIL_EQ(LOOP_CTR, 0, .MULADD1) + +.DONE: + ASSIGN(%rax, CARRY) +END_FUNCTION(bigint_mul_add_words) |