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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
//======================================================================
//
// Copyright (c) 2019, NORDUnet A/S All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// - Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// - Neither the name of the NORDUnet nor the names of its contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//======================================================================
localparam UOP_OPCODE_W = 5;
localparam UOP_CRT_W = 1;
localparam UOP_NPQ_W = 1;
localparam UOP_AUX_W = 1;
localparam UOP_LADDER_W = 2;
localparam UOP_SEL_W = 4 * BANK_ADDR_W;
localparam UOP_ADDR_W = 7; // 128 instructions
localparam [UOP_ADDR_W -1:0] UOP_ADDR_OFFSET_USING_CRT = 7'd0;
localparam [UOP_ADDR_W -1:0] UOP_ADDR_OFFSET_WITHOUT_CRT = 7'd64;
// 5 1 1 1 2 4*3=12
localparam UOP_W = UOP_OPCODE_W + UOP_CRT_W + UOP_NPQ_W + UOP_AUX_W + UOP_LADDER_W + UOP_SEL_W;
// [21:17] [16] [15] [14] [13:12] [11:9][8:6][5:3][2:0]
//
// OPCODE
//
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_STOP = 5'd00;
/* all fields are don't care
*/
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_INPUT_TO_WIDE = 5'd01;
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_INPUT_TO_NARROW = 5'd02;
/* CRT tells into which of the dual MMM to write
* NPQ specifies the width of the operand
* AUX specifies from which INPUT to read
* LADDER is don't care
*/
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_OUTPUT_FROM_NARROW = 5'd03;
/* CRT tells from which of the dual MMM to read
* NPQ specifies the width of the operand
* AUX is don't care
* LADDER is don't care
*/
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_COPY_CRT_Y2X = 5'd04;
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_COPY_LADDERS_X2Y = 5'd05;
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_CROSS_LADDERS_X2Y = 5'd06;
/* CRT is don't care
* NPQ specifies the width of the operand
* AUX is don't care
* LADDER is don't care
*/
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_MODULAR_MULTIPLY = 5'd07;
/* CRT is don't care
* NPQ specifies the width of the operand
* AUX = AUX_2 forces B input to 1 (AUX_1 reads from source NARROW as usual)
* LADDER specifies Montgomery ladder mode
*/
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_MODULAR_SUBTRACT_X = 5'd08;
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_MODULAR_SUBTRACT_Y = 5'd09;
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_MODULAR_SUBTRACT_Z = 5'd10;
/* CRT is don't care
* NPQ specifies the width of the operand
* AUX is don't care
* LADDER is don't care
*/
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_MODULAR_REDUCE_INIT = 5'd11;
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_MODULAR_REDUCE_PROC = 5'd12;
/* CRT
* NPQ
* AUX
* LADDER is don't care
*/
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_PROPAGATE_CARRIES = 5'd13;
/* CRT is don't care
* NPQ specifies the width of the operand
* AUX is don't care
* LADDER is don't care
* source and destination WIDE are don't care
*/
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_MERGE_LH = 5'd14;
/*
*/
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_REGULAR_MULTIPLY = 5'd15;
/*
*/
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_REGULAR_ADD_UNEVEN = 5'd16;
/*
*/
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_LADDER_INIT = 5'd17;
localparam [UOP_OPCODE_W -1:0] UOP_OPCODE_LADDER_STEP = 5'd18;
/* CRT is don't care
* NPQ is don't care
* AUX is don't care
* LADDER is don't care
*/
//
// CRT
//
localparam [UOP_CRT_W -1:0] UOP_CRT_X = 1'b0;
localparam [UOP_CRT_W -1:0] UOP_CRT_Y = 1'b1;
localparam [UOP_CRT_W -1:0] UOP_CRT_DNC = 1'bX;
//
// NPQ
//
localparam [UOP_NPQ_W -1:0] UOP_NPQ_N = 1'b0;
localparam [UOP_NPQ_W -1:0] UOP_NPQ_PQ = 1'b1;
localparam [UOP_NPQ_W -1:0] UOP_NPQ_DNC = 1'bX;
//
// AUX
//
localparam [UOP_AUX_W -1:0] UOP_AUX_1 = 1'b0;
localparam [UOP_AUX_W -1:0] UOP_AUX_2 = 1'b1;
localparam [UOP_AUX_W -1:0] UOP_AUX_DNC = 1'bX;
//
// LADDER
//
localparam [UOP_LADDER_W -1:0] UOP_LADDER_00 = 2'b00;
localparam [UOP_LADDER_W -1:0] UOP_LADDER_11 = 2'b11;
localparam [UOP_LADDER_W -1:0] UOP_LADDER_D = 2'b01;
localparam [UOP_LADDER_W -1:0] UOP_LADDER_PQ = 2'b10;
localparam [UOP_LADDER_W -1:0] UOP_LADDER_DNC = 2'bXX;
|