Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
BSD
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SunMaple
BSD
Commits
6cce9111
Commit
6cce9111
authored
Aug 27, 2025
by
chengshuyao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debug int overflow
parent
c37f5e7c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
249 additions
and
101 deletions
+249
-101
src/BSD.cpp
+13
-9
src/BSD.h
+168
-65
src/next_layer_bit.h
+4
-4
src/tool_function.h
+47
-10
src/top.h
+5
-5
src/write_vec.sh
+12
-8
No files found.
src/BSD.cpp
View file @
6cce9111
...
...
@@ -32,14 +32,14 @@ using namespace std;
//电路的parameter Circuit_parameter
int
circuit_index
=
9999
;
//电路编号
extern
const
int
parameter_max_orders
=
8
;
extern
const
int
parameter_max_orders
=
2
;
//算法的parameter Algorithm_parameter
extern
const
int
parameter_num_threads
=
64
;
//线程数
extern
const
int
parameter_multi_output_index
=
0
;
//BSD从第几层开始化简,前面若干层展开序确定
extern
const
int
parameter_max_BDD_width
=
4
0000
;
//BSD每一层最多多少个节点
extern
const
int
parameter_max_BDD_width
=
32
0000
;
//BSD每一层最多多少个节点
int
parameter_early_stop_depth
=
parameter_input_bit_width
;
//BSD到第几层终止,输出此时的不准确BSD
int
parameter_early_stop_split_nodes
=
1000000
;
//BSD每一层最多多少个节点
...
...
@@ -84,7 +84,7 @@ public:
accuracy_layers
=
new
int
[
parameter_input_bit_width
];
BDD_width_each_layer
=
new
int
[
parameter_input_bit_width
];
}
//int nodes_for_each_start_nod
e[
parameter_max_BDD_width];
//int nodes_for_each_start_nodparameter_max_BDD_width];
};
BSD_features
BSD_features_0
;
...
...
@@ -107,7 +107,7 @@ int main(int argc,char* argv[]){
for
(
int
i
=
0
;
i
<
parameter_output_bit_width
;
i
++
)
default_partition_set
[
i
]
=
1
;
//for(int i=0;i<parameter_output_bit_width;i++)
//
default_partition_set[0] = 1;
default_partition_set
[
0
]
=
1
;
//io generator来自真值表,不来自写好的文件
...
...
@@ -140,7 +140,7 @@ int main(int argc,char* argv[]){
int
*
start_order
=
new
int
[
parameter_input_bit_width
];
int
area_a
=
search_order
(
parameter_search_iterations
,
default_partition_set
,
0
,
start_order
);
int
area_a
=
search_order
(
10
,
default_partition_set
,
0
,
start_order
);
//search_partition(parameter_input_bit_width,start_order);
};
int
search_partition
(
int
start_order_depth
,
int
*
start_order
){
...
...
@@ -157,6 +157,10 @@ int search_partition(int start_order_depth, int* start_order){
best_output_partition_set_a
[
i
]
=
0
;
best_output_partition_set_b
[
i
]
=
0
;
}
best_area
=
search_order
(
1
,
default_partition_set
,
parameter_input_bit_width
,
start_order
);
cout
<<
"###########################################################################"
<<
endl
;
cout
<<
"Best Design Area: "
<<
best_area
<<
" "
<<
best_area_a
<<
" + "
<<
best_area_b
<<
endl
;
cout
<<
"###########################################################################"
<<
endl
;
for
(
int
j
=
0
;
j
<
2
;
j
++
){
bool
*
output_partition_set_a
=
new
bool
[
parameter_output_bit_width
];
bool
*
output_partition_set_b
=
new
bool
[
parameter_output_bit_width
];
...
...
@@ -218,13 +222,13 @@ int BSD_execute(int variable_order_number,int** variable_order, int partition_de
cout
<<
"BSD execute start"
<<
endl
;
BDD_class
BDD_class_main
;
BDD_class_main
.
output_partition_set
=
output_partition_set
;
BDD_class_main
.
which_demo_function
=
GLOBAL_which_demo_function
;
cout
<<
"This variable order: "
<<
variable_order_number
<<
endl
;
for
(
int
j
=
0
;
j
<
parameter_max_orders
;
j
++
){
//cout<<"j"<<j<<endl;
BDD_class_main
.
BSD_variable_order
[
j
]
=
new
int
[
parameter_input_bit_width
];
}
cout
<<
"This variable order: "
<<
variable_order_number
<<
endl
;
BDD_class_main
.
output_partition_set
=
output_partition_set
;
BDD_class_main
.
which_demo_function
=
GLOBAL_which_demo_function
;
//for (int vi=0;vi<partition_parts;vi++){
// BDD_class_main.BSD_variable_order_number = variable_order_number;
// for(int i=0;i<variable_order_number;i++){
...
...
@@ -700,6 +704,6 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
// }
// delete [] variable_order;
// delete [] best_variable_order;
return
area
;
return
reward
;
};
src/BSD.h
View file @
6cce9111
...
...
@@ -81,6 +81,8 @@ public:
double
*
amount_turn
;
bool
**
simplify_list
;
int
*
hash_simplify_list
;
bool
cal_infer_result
(
bool
*
input_data
,
int
which_root_node
,
bool
neg
);
bool
*
io_generator
(
bool
*
input_data
,
bool
*
output_data
);
uint32_t
*
io_generator_vec
(
uint32_t
*
input_data
,
int
*
output_data
);
...
...
@@ -94,8 +96,9 @@ public:
int
next_bit_layer_old
(
int
depth
);
int
next_bit_layer_single
(
int
depth
,
int
which_node_this_layer
);
int
compare_simplify_list
(
int
list_line_amount
,
bool
*
this_line
,
bool
**
simplify_list
);
int
compare_simplify_list_neg
(
int
list_line_amount
,
bool
*
this_line
,
bool
**
simplify_list
);
int
hash_simplify_list_function
(
bool
*
list
,
bool
neg
);
int
compare_simplify_list
(
int
list_line_amount
,
bool
*
this_line
,
bool
**
simplify_list
,
int
*
hash_simplify_list
,
int
hash_number
);
int
compare_simplify_list_neg
(
int
list_line_amount
,
bool
*
this_line
,
bool
**
simplify_list
,
int
*
hash_simplify_list
,
int
hash_neg_number
);
long
total_nodes_amount
=
0
;
long
total_split_nodes
=
0
;
...
...
@@ -134,7 +137,11 @@ public:
bool
*
left_mask_output_data_all
;
bool
*
right_mask_output_data_all
;
int
partition_depth
=
10
;
bool
*
all_one_left_list
;
bool
*
all_zero_left_list
;
bool
*
all_one_right_list
;
bool
*
all_zero_right_list
;
int
partition_depth
=
1000
;
int
partition_parts
=
2
;
int
partition_into_how_many_parts
=
2
;
int
*
partition_start_node_numbers
;
...
...
@@ -164,6 +171,7 @@ public:
mask_input_data
=
new
bool
*
[
parameter_max_samples
*
2
];
mask_output_data
=
new
bool
[
parameter_max_samples
*
2
];
simplify_list
=
new
bool
*
[
parameter_max_BDD_width
];
hash_simplify_list
=
new
int
[
parameter_max_BDD_width
];
BDD
=
new
BDD_node
*
[
1
+
parameter_input_bit_width
];
BDD_mask_this
=
new
BDD_node_mask
[
parameter_max_BDD_width
];
BDD_mask_next
=
new
BDD_node_mask
[
parameter_max_BDD_width
];
...
...
@@ -175,8 +183,12 @@ public:
right_son_mask
=
new
bool
[
parameter_input_bit_width
];
left_mask_output_data
=
new
bool
[
parameter_max_samples
];
right_mask_output_data
=
new
bool
[
parameter_max_samples
];
left_mask_output_data_all
=
new
bool
[
long
(
parameter_max_BDD_width
)
*
long
(
parameter_max_samples
)];
right_mask_output_data_all
=
new
bool
[
long
(
parameter_max_BDD_width
)
*
long
(
parameter_max_samples
)];
left_mask_output_data_all
=
new
bool
[
long
(
parameter_max_BDD_width
*
parameter_max_samples
)];
right_mask_output_data_all
=
new
bool
[
long
(
parameter_max_BDD_width
*
parameter_max_samples
)];
all_one_left_list
=
new
bool
[
parameter_max_BDD_width
];
all_zero_left_list
=
new
bool
[
parameter_max_BDD_width
];
all_one_right_list
=
new
bool
[
parameter_max_BDD_width
];
all_zero_right_list
=
new
bool
[
parameter_max_BDD_width
];
split_nodes_each_layer
=
new
int
[
parameter_input_bit_width
+
1
];
accuracy_each_layer
=
new
int
[
parameter_input_bit_width
+
1
];
...
...
@@ -289,10 +301,6 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
bool
left_son_neg
;
bool
right_son_neg
;
int
left_mask_output_data_sum
;
int
right_mask_output_data_sum
;
int
left_mask_output_data_sum_half
;
int
right_mask_output_data_sum_half
;
int
which_list_number
;
int
which_list_number_neg
;
...
...
@@ -459,6 +467,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
delete
[]
BDD_mask_this
;
delete
[]
BDD_mask_next
;
delete
[]
simplify_list
;
delete
[]
hash_simplify_list
;
delete
[]
mask_input_data
;
delete
[]
split_nodes_each_layer
;
...
...
@@ -620,6 +629,121 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
}
#endif
cout
<<
"Finish sampling IOs"
<<
endl
;
gettimeofday
(
&
finish_time
,
NULL
);
train_time
=
double
(
finish_time
.
tv_usec
-
start_time
.
tv_usec
+
1000000
*
(
finish_time
.
tv_sec
-
start_time
.
tv_sec
))
/
1000000
;
cout
<<
"BSD "
<<
BDD_id
<<
" train time = "
<<
train_time
<<
"s"
<<
endl
;
//#pragma omp parallel for
for
(
int
j
=
0
;
j
<
BDD_width_each_layer
[
i
];
j
++
){
int
left_zeros
=
0
;
int
left_ones
=
0
;
int
right_zeros
=
0
;
int
right_ones
=
0
;
bool
*
left_mask_output_data_tmp
=
new
bool
[
BSD_samples
];
bool
*
right_mask_output_data_tmp
=
new
bool
[
BSD_samples
];
if
((
i
==
(
parameter_early_stop_depth
-
1
))
&&
(
which_BDD
==
0
)
||
((
i
==
(
parameter_early_stop_depth
-
1
))
&&
(
which_BDD
==
1
))
||
((
total_split_nodes_recursive
)
>
parameter_early_stop_split_nodes
-
BDD_width_each_layer
[
i
])){
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
);
zi
++
){
left_mask_output_data_tmp
[
zi
]
=
left_mask_output_data_all
[
zi
+
BSD_samples
*
j
];
if
(
left_mask_output_data_tmp
[
zi
]){
left_ones
+=
1
;
}
else
{
left_zeros
+=
1
;
}
}
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
);
zi
++
){
right_mask_output_data
[
zi
]
=
right_mask_output_data_all
[
zi
+
BSD_samples
*
j
];
if
(
right_mask_output_data_tmp
[
zi
]){
right_ones
+=
1
;
}
else
{
right_zeros
+=
1
;
}
}
if
(
left_ones
>
left_zeros
){
all_one_left_list
[
j
]
=
1
;
all_zero_left_list
[
j
]
=
0
;
}
else
{
all_one_left_list
[
j
]
=
0
;
all_zero_left_list
[
j
]
=
1
;
}
if
(
right_ones
>
right_zeros
){
all_one_right_list
[
j
]
=
1
;
all_zero_right_list
[
j
]
=
0
;
}
else
{
all_one_right_list
[
j
]
=
0
;
all_zero_right_list
[
j
]
=
1
;
}
}
else
if
((
BDD_width_each_layer
[
i
]
>
parameter_max_BDD_width
/
2
)
){
cout
<<
"which node this layer: "
<<
j
<<
endl
;
cout
<<
" Finish trained weight = "
<<
setprecision
(
12
)
<<
(
total_finish_weight
)
/
pow
(
2
.
0
,
20
)
<<
endl
;
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
);
zi
++
){
if
(
left_mask_output_data_tmp
[
zi
]){
left_ones
+=
1
;
}
else
{
left_zeros
+=
1
;
}
}
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
);
zi
++
){
if
(
right_mask_output_data_tmp
[
zi
]){
right_ones
+=
1
;
}
else
{
right_zeros
+=
1
;
}
}
if
(
left_ones
>
left_zeros
){
all_one_left_list
[
j
]
=
1
;
all_zero_left_list
[
j
]
=
0
;
}
else
{
all_one_left_list
[
j
]
=
0
;
all_zero_left_list
[
j
]
=
1
;
}
if
(
right_ones
>
right_zeros
){
all_one_right_list
[
j
]
=
1
;
all_zero_right_list
[
j
]
=
0
;
}
else
{
all_one_right_list
[
j
]
=
0
;
all_zero_right_list
[
j
]
=
1
;
}
}
else
{
all_zero_left_list
[
j
]
=
1
;
all_one_left_list
[
j
]
=
1
;
all_zero_right_list
[
j
]
=
1
;
all_one_right_list
[
j
]
=
1
;
for
(
int
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
left_mask_output_data_tmp
[
zi
]
=
left_mask_output_data_all
[
zi
+
BSD_samples
*
j
];
if
(
left_mask_output_data_tmp
[
zi
]){
all_zero_left_list
[
j
]
=
0
;
}
else
{
all_one_left_list
[
j
]
=
0
;
}
if
((
!
all_zero_left_list
[
j
])
&&
(
!
all_one_left_list
[
j
])){
break
;
}
}
for
(
int
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
right_mask_output_data_tmp
[
zi
]
=
right_mask_output_data_all
[
zi
+
BSD_samples
*
j
];
if
(
right_mask_output_data_tmp
[
zi
]){
all_zero_right_list
[
j
]
=
0
;
}
else
{
all_one_right_list
[
j
]
=
0
;
}
if
((
!
all_zero_right_list
[
j
])
&&
(
!
all_one_right_list
[
j
])){
break
;
}
}
}
delete
[]
left_mask_output_data_tmp
;
delete
[]
right_mask_output_data_tmp
;
}
cout
<<
"Finish all one all zero compare "
<<
endl
;
gettimeofday
(
&
finish_time
,
NULL
);
train_time
=
double
(
finish_time
.
tv_usec
-
start_time
.
tv_usec
+
1000000
*
(
finish_time
.
tv_sec
-
start_time
.
tv_sec
))
/
1000000
;
cout
<<
"BSD "
<<
BDD_id
<<
" train time = "
<<
train_time
<<
"s"
<<
endl
;
for
(
int
j
=
0
;
j
<
BDD_width_each_layer
[
i
];
j
++
){
BDD
[
i
][
j
].
this_layer_bit_expansion
=
most_influence
[
i
];
...
...
@@ -630,7 +754,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
BDD
[
i
][
j
].
non_equal_number
=
total_non_equal_nodes
;
total_non_equal_nodes
+=
1
;
}
//cout<<"Debug 1"<<" ";
for
(
zi
=
0
;
zi
<
i
;
zi
++
){
left_son_mask
[
most_influence
[
zi
]]
=
BDD_mask_this
[
j
].
mask
[
most_influence
[
zi
]];
right_son_mask
[
most_influence
[
zi
]]
=
BDD_mask_this
[
j
].
mask
[
most_influence
[
zi
]];
...
...
@@ -638,69 +762,41 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
left_son_mask
[
most_influence
[
i
]]
=
0
;
right_son_mask
[
most_influence
[
i
]]
=
1
;
bool
all_zero_left
=
1
;
bool
all_one_left
=
1
;
bool
all_one_right
=
1
;
bool
all_zero_right
=
1
;
bool
all_zero_left
=
all_zero_left_list
[
j
]
;
bool
all_one_left
=
all_one_left_list
[
j
]
;
bool
all_one_right
=
all_one_right_list
[
j
]
;
bool
all_zero_right
=
all_zero_right_list
[
j
]
;
for
(
int
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
left_mask_output_data
[
zi
]
=
left_mask_output_data_all
[
zi
+
BSD_samples
*
j
];
right_mask_output_data
[
zi
]
=
right_mask_output_data_all
[
zi
+
BSD_samples
*
j
];
}
for
(
int
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
//cout<<"Debug 2"<<" ";
int
left_zeros
=
0
;
int
left_ones
=
0
;
int
right_zeros
=
0
;
int
right_ones
=
0
;
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
);
zi
++
){
if
(
left_mask_output_data
[
zi
]){
all_zero_left
=
0
;
left_ones
+=
1
;
}
else
{
all_one_left
=
0
;
}
if
((
!
all_zero_left
)
&&
(
!
all_one_left
)){
break
;
left_zeros
+=
1
;
}
}
for
(
int
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
)
;
zi
++
){
if
(
right_mask_output_data
[
zi
]){
all_zero_right
=
0
;
}
else
{
all_one_right
=
0
;
}
if
((
!
all_zero_right
)
&&
(
!
all_one_right
)){
break
;
}
}
if
((
i
==
(
parameter_early_stop_depth
-
1
))
&&
(
which_BDD
==
0
)
||
((
i
==
(
parameter_early_stop_depth
-
1
))
&&
(
which_BDD
==
1
))
||
((
total_split_nodes_recursive
)
>
parameter_early_stop_split_nodes
-
BDD_width_each_layer
[
i
])){
if
(
left_mask_output_data_sum
>
(
BSD_samples
/
2
)){
all_one_left
=
1
;
all_zero_left
=
0
;
}
else
{
all_one_left
=
0
;
all_zero_left
=
1
;
}
if
(
right_mask_output_data_sum
>
(
BSD_samples
/
2
)){
all_one_right
=
1
;
all_zero_right
=
0
;
}
else
{
all_one_right
=
0
;
all_zero_right
=
1
;
}
}
if
((
BDD_width_each_layer
[
i
]
>
parameter_max_BDD_width
/
2
)
){
if
(
left_mask_output_data_sum
>
(
BSD_samples
/
2
)){
all_one_left
=
1
;
all_zero_left
=
0
;
right_ones
+=
1
;
}
else
{
all_one_left
=
0
;
all_zero_left
=
1
;
}
if
(
right_mask_output_data_sum
>
(
BSD_samples
/
2
)){
all_one_right
=
1
;
all_zero_right
=
0
;
}
else
{
all_one_right
=
0
;
all_zero_right
=
1
;
right_zeros
+=
1
;
}
}
//cout<<"Debug 3"<<" ";
//cout<<"Debug 4"<<" ";
int
hash_left_number
=
hash_simplify_list_function
(
left_mask_output_data
,
0
);
int
hash_left_neg_number
=
hash_simplify_list_function
(
left_mask_output_data
,
1
);
int
hash_right_number
=
hash_simplify_list_function
(
right_mask_output_data
,
0
);
int
hash_right_neg_number
=
hash_simplify_list_function
(
right_mask_output_data
,
1
);
if
(
i
>
parameter_multi_output_index
-
1
){
if
(
all_zero_left
){
BDD
[
i
][
j
].
left_node_index
=
-
2
;
...
...
@@ -710,8 +806,8 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
total_finish_weight
+=
BDD
[
i
][
j
].
weight
/
2
;
}
else
{
if
(((
i
%
how_often_simplify
)
==
0
)){
which_list_number
=
compare_simplify_list
(
BDD_width_each_layer
[
i
+
1
],
left_mask_output_data
,
simplify_list
);
which_list_number_neg
=
compare_simplify_list_neg
(
BDD_width_each_layer
[
i
+
1
],
left_mask_output_data
,
simplify_list
);
which_list_number
=
compare_simplify_list
(
BDD_width_each_layer
[
i
+
1
],
left_mask_output_data
,
simplify_list
,
hash_simplify_list
,
hash_left_number
);
which_list_number_neg
=
compare_simplify_list_neg
(
BDD_width_each_layer
[
i
+
1
],
left_mask_output_data
,
simplify_list
,
hash_simplify_list
,
hash_left_neg_number
);
it_cannot_simplify
=
(
which_list_number
<
0
)
&&
(
which_list_number_neg
<
0
);
it_can_simplify
=
(
which_list_number
>=
0
);
it_can_simplify_neg
=
(
which_list_number_neg
>=
0
);
...
...
@@ -736,6 +832,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
for
(
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
simplify_list
[
BDD_width_each_layer
[
i
+
1
]
-
1
][
zi
]
=
left_mask_output_data
[
zi
];
}
hash_simplify_list
[
BDD_width_each_layer
[
i
+
1
]
-
1
]
=
hash_left_number
;
}
else
if
(
it_can_simplify
){
BDD
[
i
][
j
].
left_node_index
=
which_list_number
;
BDD
[
i
][
j
].
left_node_neg
=
0
;
...
...
@@ -785,6 +882,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
for
(
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
simplify_list
[
BDD_width_each_layer
[
i
+
1
]
-
1
][
zi
]
=
left_mask_output_data
[
zi
];
}
hash_simplify_list
[
BDD_width_each_layer
[
i
+
1
]
-
1
]
=
hash_left_number
;
}
if
(
i
>
parameter_multi_output_index
-
1
){
...
...
@@ -796,8 +894,8 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
total_finish_weight
+=
BDD
[
i
][
j
].
weight
/
2
;
}
else
{
if
(((
i
%
how_often_simplify
==
0
))){
which_list_number
=
compare_simplify_list
(
BDD_width_each_layer
[
i
+
1
],
right_mask_output_data
,
simplify_list
);
which_list_number_neg
=
compare_simplify_list_neg
(
BDD_width_each_layer
[
i
+
1
],
right_mask_output_data
,
simplify_list
);
which_list_number
=
compare_simplify_list
(
BDD_width_each_layer
[
i
+
1
],
right_mask_output_data
,
simplify_list
,
hash_simplify_list
,
hash_right_number
);
which_list_number_neg
=
compare_simplify_list_neg
(
BDD_width_each_layer
[
i
+
1
],
right_mask_output_data
,
simplify_list
,
hash_simplify_list
,
hash_right_neg_number
);
it_cannot_simplify
=
(
which_list_number
<
0
)
&&
(
which_list_number_neg
<
0
);
it_can_simplify
=
(
which_list_number
>=
0
);
it_can_simplify_neg
=
(
which_list_number_neg
>=
0
);
...
...
@@ -821,6 +919,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
for
(
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
simplify_list
[
BDD_width_each_layer
[
i
+
1
]
-
1
][
zi
]
=
right_mask_output_data
[
zi
];
}
hash_simplify_list
[
BDD_width_each_layer
[
i
+
1
]
-
1
]
=
hash_right_number
;
}
else
if
(
it_can_simplify
){
BDD
[
i
][
j
].
right_node_index
=
which_list_number
;
BDD
[
i
][
j
].
right_node_neg
=
0
;
...
...
@@ -853,6 +952,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
for
(
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
simplify_list
[
BDD_width_each_layer
[
i
+
1
]
-
1
][
zi
]
=
right_mask_output_data
[
zi
];
}
hash_simplify_list
[
BDD_width_each_layer
[
i
+
1
]
-
1
]
=
hash_right_number
;
}
}
}
else
{
...
...
@@ -872,8 +972,10 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
for
(
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
simplify_list
[
BDD_width_each_layer
[
i
+
1
]
-
1
][
zi
]
=
right_mask_output_data
[
zi
];
}
hash_simplify_list
[
BDD_width_each_layer
[
i
+
1
]
-
1
]
=
hash_right_number
;
}
//cout<<"Debug 5"<<" ";
if
(
BDD
[
i
][
j
].
left_node_index
!=
BDD
[
i
][
j
].
right_node_index
){
total_split_nodes
+=
1
;
BDD_split_nodes_each_layer
[
i
]
+=
1
;
...
...
@@ -886,6 +988,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
}
}
}
//cout<<"Debug 6"<<" ";
for
(
zi
=
0
;
zi
<
how_many_start_nodes
;
zi
++
){
root_nodes_leafs
[
zi
]
=
0
;
for
(
int
zj
=
0
;
zj
<
BDD_width_each_layer
[
i
+
1
];
zj
++
){
...
...
@@ -1059,7 +1162,7 @@ int BDD_class::BDD_FULL_PROCESS(){
cout
<<
"ready to train"
<<
endl
;
for
(
j
=
0
;
j
<
parameter_max_samples
;
j
++
){
mask_input_data
[
j
]
=
new
bool
[
parameter_input_bit_width
*
2
];
mask_input_data
[
j
]
=
new
bool
[
parameter_input_bit_width
+
2
];
}
// for (j=0;j<parameter_max_orders;j++){
// BSD_variable_order[j] = new int [parameter_input_bit_width];
...
...
src/next_layer_bit.h
View file @
6cce9111
...
...
@@ -275,8 +275,8 @@ int BDD_class::next_bit_layer_1(int depth){
}
else
if
(
all_one_left
){
change_nodes
[
this_bit_expansion
]
+=
1
;
}
else
{
which_list_number_l
=
compare_simplify_list
(
how_many_nodes_if_expansion
[
this_bit_expansion
],
left_mask_output_data
,
simplify_list
);
which_list_number_neg_l
=
compare_simplify_list_neg
(
how_many_nodes_if_expansion
[
this_bit_expansion
],
left_mask_output_data
,
simplify_list
);
//
which_list_number_l = compare_simplify_list (how_many_nodes_if_expansion[this_bit_expansion],left_mask_output_data,simplify_list);
//
which_list_number_neg_l = compare_simplify_list_neg(how_many_nodes_if_expansion[this_bit_expansion],left_mask_output_data,simplify_list);
bool
it_cannot_simplify
=
(
which_list_number_l
<
0
)
&&
(
which_list_number_neg_l
<
0
);
bool
it_can_simplify
=
(
which_list_number_l
>=
0
);
bool
it_can_simplify_neg
=
(
which_list_number_neg_l
>=
0
);
...
...
@@ -296,8 +296,8 @@ int BDD_class::next_bit_layer_1(int depth){
}
else
if
(
all_one_right
){
change_nodes
[
this_bit_expansion
]
+=
1
;
}
else
{
which_list_number_r
=
compare_simplify_list
(
how_many_nodes_if_expansion
[
this_bit_expansion
],
right_mask_output_data
,
simplify_list
);
which_list_number_neg_r
=
compare_simplify_list_neg
(
how_many_nodes_if_expansion
[
this_bit_expansion
],
right_mask_output_data
,
simplify_list
);
//
which_list_number_r = compare_simplify_list(how_many_nodes_if_expansion[this_bit_expansion],right_mask_output_data,simplify_list);
//
which_list_number_neg_r = compare_simplify_list_neg(how_many_nodes_if_expansion[this_bit_expansion],right_mask_output_data,simplify_list);
bool
it_cannot_simplify
=
(
which_list_number_r
<
0
)
&&
(
which_list_number_neg_r
<
0
);
bool
it_can_simplify
=
(
which_list_number_r
>=
0
);
bool
it_can_simplify_neg
=
(
which_list_number_neg_r
>=
0
);
...
...
src/tool_function.h
View file @
6cce9111
...
...
@@ -30,8 +30,37 @@ int BDD_class::mask_random_input_data(int depth,bool* mask,int amount,int* most_
return
0
;
};
int
BDD_class
::
hash_simplify_list_function
(
bool
*
list
,
bool
neg
){
int
BDD_class
::
compare_simplify_list
(
int
list_line_amount
,
bool
*
this_line
,
bool
**
simplify_list
){
int
a
=
int
(
BSD_samples
/
1
);
int
b
=
int
(
BSD_samples
/
2
);
int
c
=
int
(
BSD_samples
/
3
);
int
d
=
int
(
BSD_samples
/
4
);
int
line_sum_a
=
0
;
int
line_sum_b
=
0
;
int
line_sum_c
=
0
;
int
line_sum_d
=
0
;
for
(
int
i
=
0
;
i
<
BSD_samples
;
i
++
){
if
(
i
<
d
){
if
(
list
[
i
]
==!
neg
)
line_sum_d
+=
1
;
}
else
if
(
i
<
c
){
if
(
list
[
i
]
==!
neg
)
line_sum_c
+=
1
;
}
else
if
(
i
<
b
){
if
(
list
[
i
]
==!
neg
)
line_sum_b
+=
1
;
}
else
if
(
i
<
a
){
if
(
list
[
i
]
==!
neg
)
line_sum_a
+=
1
;
}
}
int
line_sum
=
line_sum_d
*
3
+
line_sum_c
*
5
+
line_sum_b
*
7
+
line_sum_a
;
return
line_sum
;
}
int
BDD_class
::
compare_simplify_list
(
int
list_line_amount
,
bool
*
this_line
,
bool
**
simplify_list
,
int
*
hash_simplify_list
,
int
hash_number
){
int
which_list_number
=
-
1
;
bool
it_can_simplify
=
0
;
int
i
,
j
;
...
...
@@ -40,10 +69,14 @@ int BDD_class::compare_simplify_list(int list_line_amount,bool* this_line,bool**
if
(
1
){
for
(
int
i
=
list_line_amount
-
1
;
i
>=
0
;
i
--
){
it_can_simplify_here
=
1
;
for
(
int
j
=
0
;
j
<
BSD_samples
;
j
++
){
if
(
simplify_list
[
i
][
j
]
!=
this_line
[
j
]){
it_can_simplify_here
=
0
;
break
;
if
(
hash_number
!=
hash_simplify_list
[
i
]){
it_can_simplify_here
=
0
;
}
else
{
for
(
int
j
=
0
;
j
<
BSD_samples
;
j
++
){
if
(
simplify_list
[
i
][
j
]
!=
this_line
[
j
]){
it_can_simplify_here
=
0
;
break
;
}
}
}
if
(
it_can_simplify_here
){
...
...
@@ -55,7 +88,7 @@ int BDD_class::compare_simplify_list(int list_line_amount,bool* this_line,bool**
}
return
which_list_number
;
};
int
BDD_class
::
compare_simplify_list_neg
(
int
list_line_amount
,
bool
*
this_line
,
bool
**
simplify_list
){
int
BDD_class
::
compare_simplify_list_neg
(
int
list_line_amount
,
bool
*
this_line
,
bool
**
simplify_list
,
int
*
hash_simplify_list
,
int
hash_neg_number
){
int
which_list_number
=
-
1
;
//return which_list_number;
bool
it_can_simplify
=
0
;
...
...
@@ -65,10 +98,14 @@ int BDD_class::compare_simplify_list_neg(int list_line_amount,bool* this_line,bo
if
(
1
){
for
(
i
=
list_line_amount
-
1
;
i
>=
0
;
i
--
){
it_can_simplify_here
=
1
;
for
(
int
j
=
0
;
j
<
BSD_samples
;
j
++
){
if
(
simplify_list
[
i
][
j
]
==
this_line
[
j
]){
it_can_simplify_here
=
0
;
break
;
if
(
hash_neg_number
!=
hash_simplify_list
[
i
]){
it_can_simplify_here
=
0
;
}
else
{
for
(
int
j
=
0
;
j
<
BSD_samples
;
j
++
){
if
(
simplify_list
[
i
][
j
]
==
this_line
[
j
]){
it_can_simplify_here
=
0
;
break
;
}
}
}
if
(
it_can_simplify_here
){
...
...
src/top.h
View file @
6cce9111
#define INPUT_AIG
#include
"io_generator/c1908
.h"
#include
"c1908
_vec.h"
#include
"usb1_crc16
.h"
#include
"usb1_crc16
_vec.h"
extern
const
int
parameter_input_bit_width
=
PI_WIDTH
+
5
;
extern
const
int
parameter_output_bit_width
=
PO_WIDTH
;
extern
const
int
parameter_train_output_bit_width
=
1
;
//
extern const int parameter_train_output_bit_width = 1 ;
//int parameter_input_bit_width = 80+5; //输入bit有几位,写在+6前面。+6是为了防止一些bug的冗余设计。
...
...
@@ -15,9 +15,9 @@ extern const int parameter_train_output_bit_width = 1 ;
//#include"io_generator_tmp.h"
extern
const
int
parameter_search_iterations
=
400
;
//最大设计次数
extern
const
int
parameter_search_iterations
=
1
;
//最大设计次数
extern
const
int
parameter_test_ios
=
1000
;
//测试要求多少样本
extern
const
int
parameter_max_samples
=
int
(
parameter_test_ios
*
10
/
32
)
*
32
;
//BSD每一个节点最多进行多少次采样
extern
const
int
parameter_max_samples
=
int
(
parameter_test_ios
*
10
0
/
32
)
*
32
;
//BSD每一个节点最多进行多少次采样
bool
*
io_generator_function
(
bool
*
input_data
,
bool
*
output_data
)
{
...
...
src/write_vec.sh
View file @
6cce9111
module_name
=
"
dalu
"
vim
-c
"open io_generator/
${
module_name
}
.h"
\
-c
"1d"
\
-c
"1d"
\
-c
":$"
\
-c
"d"
module_name
=
"
usb1_crc16
"
#@
vim -c "open io_generator/${module_name}.h" \
#@
-c "1d"\
#@
-c "1d"\
#@
-c ":$"\
#@
-c "d"
cp io_generator/
${
module_name
}
.h
${
module_name
}
_vec.h
vim
-c
"open
${
module_name
}
_vec.h"
\
-c
"1d"
\
-c
"1d"
\
-c
"1d"
\
-c
"1d"
\
-c
"1,
$
s/io_generator_outer/io_generator_outer_vec"
vim
-c
"open
${
module_name
}
_vec.h"
\
-c
"1,
$
s/vec_vec/vec"
\
-c
"1,
$
s/bool/
in
t/g"
\
-c
"1,
$
s/bool/
uint32_
t/g"
\
-c
"1,
$
s/!/
\~
/g"
\
-c
"1,
$
s/&&/and/g"
\
-c
"1,
$
s/and/
\&
/g"
\
-c
"1,
$
s/false/0/g"
\
-c
"1,
$
s/true/-1/g"
\
-c
"1,
$
s/true/32'hffffffff/g"
\
-c
":$"
\
-c
"d"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment