aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-08-13 14:13:44 +0000
committerlloyd <[email protected]>2006-08-13 14:13:44 +0000
commit4a6516c195b932854a4def113e832bd292fe3785 (patch)
treede6d95856fe939f28ac96e87f7ff47f98897dbdf /modules
parente08628827ae27dc29fcaa4465849198168b2e9af (diff)
Clean up the macros, add comment headers, add a couple of helper macros
for spilling/restoring registers. Reorder some instructions for slightly better scheduling across rounds
Diffstat (limited to 'modules')
-rw-r--r--modules/alg_ia32/asm_macr.h53
-rw-r--r--modules/alg_ia32/sha1core.S38
2 files changed, 63 insertions, 28 deletions
diff --git a/modules/alg_ia32/asm_macr.h b/modules/alg_ia32/asm_macr.h
index 582184080..a4409a211 100644
--- a/modules/alg_ia32/asm_macr.h
+++ b/modules/alg_ia32/asm_macr.h
@@ -6,6 +6,9 @@
#ifndef BOTAN_EXT_ASM_MACROS_H__
#define BOTAN_EXT_ASM_MACROS_H__
+/*************************************************
+* General/Global Macros *
+*************************************************/
#define ALIGN .p2align 4,,15
#define START_LISTING(FILENAME) \
@@ -13,13 +16,22 @@
.text; \
.p2align 4,,15;
-#define FUNCTION(func_name) \
- .align 8; \
- ALIGN; \
- .global func_name; \
- .type func_name,@function; \
+/*************************************************
+* Function Definitions *
+*************************************************/
+#define START_FUNCTION(func_name) \
+ .align 8; \
+ 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:
@@ -28,6 +40,9 @@ func_name:
cmpl NUM, REG; \
jne LABEL##_LOOP
+/*************************************************
+* Register Names *
+*************************************************/
#define EAX %eax
#define EBX %ebx
#define ECX %ecx
@@ -37,11 +52,9 @@ func_name:
#define ESI %esi
#define ESP %esp
-#define IMM(VAL) $VAL
-
-#define PUSH(REG) pushl REG
-#define POP(REG) popl REG
-
+/*************************************************
+* Memory Access Operations *
+*************************************************/
#define ARRAY1(REG, NUM) NUM(REG)
#define ARRAY4(REG, NUM) 4*NUM(REG)
#define ARRAY4_INDIRECT(BASE, OFFSET, NUM) 4*NUM(BASE,OFFSET,4)
@@ -50,6 +63,26 @@ func_name:
#define ASSIGN(TO, FROM) movl FROM, TO
#define ASSIGN_BYTE(TO, FROM) movzbl FROM, TO
+#define PUSH(REG) pushl REG
+#define POP(REG) popl REG
+
+#define SPILL_REGS() \
+ PUSH(EBP) ; \
+ PUSH(EDI) ; \
+ PUSH(ESI) ; \
+ PUSH(EBX)
+
+#define RESTORE_REGS() \
+ POP(EBX) ; \
+ POP(ESI) ; \
+ POP(EDI) ; \
+ POP(EBP)
+
+/*************************************************
+* ALU Operations *
+*************************************************/
+#define IMM(VAL) $VAL
+
#define ADD(TO, FROM) addl FROM, TO
#define ADD_IMM(TO, NUM) addl IMM(NUM), TO
#define SUB_IMM(TO, NUM) subl IMM(NUM), TO
diff --git a/modules/alg_ia32/sha1core.S b/modules/alg_ia32/sha1core.S
index f439a45f6..ed9d697ef 100644
--- a/modules/alg_ia32/sha1core.S
+++ b/modules/alg_ia32/sha1core.S
@@ -7,11 +7,8 @@
START_LISTING(sha1core.S)
-FUNCTION(sha160_core)
- PUSH(EBP)
- PUSH(EDI)
- PUSH(ESI)
- PUSH(EBX)
+START_FUNCTION(sha160_core)
+ SPILL_REGS()
#define PUSHED 4
@@ -103,19 +100,19 @@ LOOP_UNTIL(ESI, IMM(80), .EXPANSION)
XOR(T, D) ; \
ROTR_IMM(B, 2) ; \
ADD(E, A) ; \
- ROTR_IMM(A, 5) ; \
- ADD3_IMM(E, T, MAGIC1) ;
+ ADD3_IMM(E, T, MAGIC1) ; \
+ ROTR_IMM(A, 5) ;
#define F2_OR_F4(A, B, C, D, E, T, MSG, MAGIC) \
ROTL_IMM(A, 5) ; \
ADD(E, ARRAY4(EDI, MSG)) ; \
- ASSIGN(T, B) ; \
- XOR(T, D) ; \
+ ASSIGN(T, D) ; \
XOR(T, C) ; \
+ XOR(T, B) ; \
ROTR_IMM(B, 2) ; \
ADD(E, A) ; \
- ROTR_IMM(A, 5) ; \
- ADD3_IMM(E, T, MAGIC) ;
+ ADD3_IMM(E, T, MAGIC) ; \
+ ROTR_IMM(A, 5) ;
#define F3(A, B, C, D, E, T, MSG) \
ROTL_IMM(A, 5) ; \
@@ -128,8 +125,8 @@ LOOP_UNTIL(ESI, IMM(80), .EXPANSION)
OR(T, ARRAY4(EDI, MSG)) ; \
ROTR_IMM(B, 2) ; \
ADD(E, A) ; \
- ROTR_IMM(A, 5) ; \
- ADD3_IMM(E, T, MAGIC3) ;
+ ADD3_IMM(E, T, MAGIC3) ; \
+ ROTR_IMM(A, 5) ;
#define F2(A, B, C, D, E, T, MSG) \
F2_OR_F4(A, B, C, D, E, T, MSG, MAGIC2)
@@ -144,6 +141,14 @@ LOOP_UNTIL(ESI, IMM(80), .EXPANSION)
F(ECX, EDX, ESI, EAX, EBX, EBP, (MSG+3)) \
F(EBX, ECX, EDX, ESI, EAX, EBP, (MSG+4))
+ #if 0
+ F2(EAX, EBX, ECX, EDX, ESI, EBP, 0)
+ F2(ESI, EAX, EBX, ECX, EDX, EBP, 1)
+ F2(EDX, ESI, EAX, EBX, ECX, EBP, 2)
+ F2(ECX, EDX, ESI, EAX, EBX, EBP, 3)
+ F2(EBX, ECX, EDX, ESI, EAX, EBP, 4)
+ #endif
+
F_BLOCK(F1, 0)
F_BLOCK(F1, 5)
F_BLOCK(F1, 10)
@@ -171,8 +176,5 @@ LOOP_UNTIL(ESI, IMM(80), .EXPANSION)
ADD(ARRAY4(EBP, 3), EDX)
ADD(ARRAY4(EBP, 4), ESI)
- POP(EBX)
- POP(ESI)
- POP(EDI)
- POP(EBP)
- ret
+ RESTORE_REGS()
+END_FUNCTION(sha160_core)