forked from miracl/MIRACL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsse2.txt
82 lines (53 loc) · 2.69 KB
/
sse2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
If you have a Pentium 4 or clone processor that supports the SSE2
extensions, then using these instructions can be faster.
The file sse2.mcs is provided as a plug-in alternative for ms86.mcs, and
gccsse2.mcs is provided as an alternative for gcc386.mcs
Using the COMBA or KCM methods and these provided macros, PCs will execute
big number code up to 60% faster. Ideal for a Pentium 4 based Crypto server.
See kcmcomba.txt
It is the programmers responsibility to ensure that their hardware and their
compiler supports SSE2 extensions.
Tested with latest Microsoft (use sse2.mcs) and GCC compilers (V3.3 or greater
- use gccsse2.mcs)
The key instruction is PMULUDQ which multiplies two pairs of 32-bit numbers in
a single instruction. Unfortunately trying to exploit this capability is very
difficult. But even just using it for a single multiplication is faster than
the standard x386 MUL instruction. However SSE2 instructions do not support a
carry flag :(. But the PADDQ instruction adds 64-bit numbers.
Consider the following trick:-
The 64-bit result of a PMULUDQ is written to a 128-bit SSE2 register thus
< 32 bits >
+--------+---------+----------+-----------+
| | | | |
|00000000|000000000| Hi | Lo |
| | | | |
+--------+---------+----------+-----------+
<---------------- 128 bits --------------->
Now shuffle this (using PSHUFD) so it becomes
+--------+---------+----------+-----------+
| | | | |
|00000000| Hi |0000000000| Lo |
| | | | |
+--------+---------+----------+-----------+
Now accumulate (by simple addition) partial products like these
(see makemcs.txt) in an SSE2 register, using the PADDQ instruction
+--------+---------+----------+-----------+
| | | | |
|00000CHi| SumHi |0000000CLo| SumLo |
| | | | |
+--------+---------+----------+-----------+
where CHi and CLo are accumulated carries from each half
At the bottom of each column of partial products, the sum for the column is
SumLo, and the Carry for the next column is the sum of
+--------+---------+----------+-----------+
| | | | |
| 0 | 0 |0000000CHi| SumHi |
| | | | |
+--------+---------+----------+-----------+
and
+--------+---------+----------+-----------+
| | | | |
| 0 | 0 | 0 |00000000Clo|
| | | | |
+--------+---------+----------+-----------+
This can easily be achieved using the available shift instructions and PADDQ.