remove unneeded limit register
This commit is contained in:
parent
b7399b014b
commit
588ee8b710
@ -52,8 +52,8 @@
|
|||||||
\begin{lstlisting}
|
\begin{lstlisting}
|
||||||
typedef uint32_t u32;
|
typedef uint32_t u32;
|
||||||
void heron_sqrt(u32 *mem) {
|
void heron_sqrt(u32 *mem) {
|
||||||
int i;
|
int i = mem[0];
|
||||||
for (i = 1; i <= mem[0]; i++){
|
while (i > 0) {
|
||||||
u32 s = mem[i];
|
u32 s = mem[i];
|
||||||
if (s > 1) {
|
if (s > 1) {
|
||||||
// x_0 = (s + 1) / 2
|
// x_0 = (s + 1) / 2
|
||||||
@ -71,6 +71,7 @@ void heron_sqrt(u32 *mem) {
|
|||||||
}
|
}
|
||||||
mem[i] = x;
|
mem[i] = x;
|
||||||
}
|
}
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
53
graph.dot
53
graph.dot
@ -2,19 +2,17 @@
|
|||||||
digraph heron {
|
digraph heron {
|
||||||
//node [shape=circle,regular=1,style=filled,fillcolor=white];
|
//node [shape=circle,regular=1,style=filled,fillcolor=white];
|
||||||
edge [arrowhead=odot];
|
edge [arrowhead=odot];
|
||||||
graph [overlap=false];
|
graph [overlap=scale];
|
||||||
|
|
||||||
subgraph {
|
subgraph {
|
||||||
edge [weight=3];
|
edge [weight=3];
|
||||||
C0 -> C1 -> C2 -> C3 -> C4 -> C5 -> C6 -> C7 -> C8 -> C9
|
C0 -> C1 -> C2 -> C3 -> C4 -> C5 -> C6 -> C7 -> C8 -> C9 [minlen=3.5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// variables & constants
|
// variables & constants
|
||||||
mem_0 [label="mem[0]"];
|
mem_0 [label="mem[0]"];
|
||||||
mem_i [label="mem[i]"];
|
mem_i [label="mem[i]"];
|
||||||
mem_i2 [label="mem[i]"];
|
mem_i2 [label="mem[i]",shape="box"];
|
||||||
i [ ];
|
i [label="i"];
|
||||||
1 [ ];
|
1 [ ];
|
||||||
"1a" [label="1" ];
|
"1a" [label="1" ];
|
||||||
"1b" [label="1" ];
|
"1b" [label="1" ];
|
||||||
@ -24,29 +22,31 @@ digraph heron {
|
|||||||
|
|
||||||
// operands
|
// operands
|
||||||
s_shift_1 [label=">>",];
|
s_shift_1 [label=">>",];
|
||||||
i_lte_mem_0 [label=">=",];
|
i_lt_0 [label=">",];
|
||||||
|
|
||||||
// i <= mem[0]
|
// i <= mem[0]
|
||||||
mem_0 -> i_lte_mem_0;
|
mem_0 -> i:n [label="C0",style=dotted];
|
||||||
i -> i_lte_mem_0;
|
|
||||||
{ rank=same; C1; i_lte_mem_0; }
|
0 -> i_lt_0;
|
||||||
{ rank=same; C0; i; mem_0;}
|
i -> i_lt_0;
|
||||||
|
{ rank=same; C0; i}
|
||||||
|
{ rank=same; C1; i_lt_0; }
|
||||||
|
|
||||||
// if (i <= mem[0]) ->
|
// if (i <= mem[0]) ->
|
||||||
i_lte_mem_0 -> mem_s_gte_1 [style=dotted, arrowhead=normal,label="True",lhead=cluster_i_lte_mem_0];
|
i_lt_0 -> mem_s_gte_1 [style=dotted, arrowhead=normal,label="True"];
|
||||||
// else
|
// else
|
||||||
i_lte_mem_0 -> Finish [style=dotted, arrowhead=normal,label="False",lhead=cluster_i_lte_mem_0];
|
i_lt_0 -> Finish [style=dotted, arrowhead=normal,label="False"];
|
||||||
{ rank=same; C9; Finish;}
|
{ rank=same; C9; Finish;}
|
||||||
|
|
||||||
subgraph i_lte_mem_0 {
|
subgraph i_lt_0 {
|
||||||
mem_s_gte_1 [label=">"];
|
mem_s_gte_1 [label=">"];
|
||||||
|
|
||||||
s_div_x [label="/",];
|
s_div_x [label="/",];
|
||||||
new_x [label="+",];
|
new_x [label="+",];
|
||||||
s_div_x_shift_1 [label=">>",];
|
s_div_x_shift_1 [label=">>",];
|
||||||
x_shift_1 [label=">>",];
|
x_shift_1 [label=">>",];
|
||||||
old_x_lte_new_x [label="¹>=",];
|
old_x_lte_new_x [label=">=",];
|
||||||
inc_i [label="+",];
|
dec_i [label="-",];
|
||||||
|
|
||||||
// (s > 1)
|
// (s > 1)
|
||||||
mem_i -> mem_s_gte_1;
|
mem_i -> mem_s_gte_1;
|
||||||
@ -56,16 +56,17 @@ digraph heron {
|
|||||||
// if (s > 1)
|
// if (s > 1)
|
||||||
mem_s_gte_1 -> s_shift_1 [style=dotted,arrowhead=normal,label="True"];
|
mem_s_gte_1 -> s_shift_1 [style=dotted,arrowhead=normal,label="True"];
|
||||||
// else
|
// else
|
||||||
mem_s_gte_1 -> inc_i [style=dotted,arrowhead=normal,label="False"];
|
mem_s_gte_1 -> dec_i [style=dotted,arrowhead=normal,label="False"];
|
||||||
|
|
||||||
subgraph if_mem_i_gte_1 {
|
subgraph if_mem_i_gte_1 {
|
||||||
// x = s >> 1
|
// x = s >> 1
|
||||||
mem_i -> s_shift_1;
|
mem_i -> s_shift_1;
|
||||||
1 -> s_shift_1;
|
1 -> s_shift_1;
|
||||||
s_shift_1 -> x;
|
s_shift_1 -> x [style=dotted,arrowhead=normal,label="C2->C3"];
|
||||||
{ rank=same; C3; s_shift_1; x}
|
{ rank=same; C3; s_shift_1; x}
|
||||||
|
|
||||||
// (x >> 1)
|
// (x >> 1)
|
||||||
|
x [shape="box"];
|
||||||
x -> x_shift_1;
|
x -> x_shift_1;
|
||||||
"1a" -> x_shift_1;
|
"1a" -> x_shift_1;
|
||||||
// (s/x)
|
// (s/x)
|
||||||
@ -86,20 +87,20 @@ digraph heron {
|
|||||||
// (old_x <= X)
|
// (old_x <= X)
|
||||||
x -> old_x_lte_new_x;
|
x -> old_x_lte_new_x;
|
||||||
new_x -> old_x_lte_new_x;
|
new_x -> old_x_lte_new_x;
|
||||||
new_x -> x [style=dotted,label="if(¹)"];
|
new_x -> x [style=dotted,label="C7->C3"];
|
||||||
|
|
||||||
{ rank=same; C7; old_x_lte_new_x;}
|
{ rank=same; C7; old_x_lte_new_x;}
|
||||||
|
|
||||||
// if (old_x <= X)
|
// if (old_x <= X)
|
||||||
old_x_lte_new_x -> inc_i [style=dotted,arrowhead=normal,label="True"];
|
old_x_lte_new_x -> dec_i [style=dotted,arrowhead=normal,label="True"];
|
||||||
// else
|
// else
|
||||||
|
old_x_lte_new_x -> x [style=dotted,arrowhead=normal,label="False"];
|
||||||
|
|
||||||
|
"1c" -> dec_i;
|
||||||
"1c" -> inc_i;
|
i -> dec_i:ne;
|
||||||
i -> inc_i:ne;
|
dec_i:s -> i:s;
|
||||||
inc_i:s -> i:s;
|
new_x -> mem_i2 [label="C7->C8", style=dotted];
|
||||||
new_x -> mem_i2 [label="if(¹)", style=dotted];
|
{ rank=same; C8; dec_i; mem_i2};
|
||||||
{ rank=same; C8; inc_i; mem_i2};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
sqrt.c
5
sqrt.c
@ -7,8 +7,8 @@
|
|||||||
typedef uint32_t u32;
|
typedef uint32_t u32;
|
||||||
|
|
||||||
void heron_sqrt(u32 *mem) {
|
void heron_sqrt(u32 *mem) {
|
||||||
int i;
|
int i = mem[0];
|
||||||
for (i = 1; i <= mem[0]; i++){
|
while (i > 0) {
|
||||||
u32 s = mem[i];
|
u32 s = mem[i];
|
||||||
if (s > 1) {
|
if (s > 1) {
|
||||||
// x_0 = (s + 1) / 2
|
// x_0 = (s + 1) / 2
|
||||||
@ -26,6 +26,7 @@ void heron_sqrt(u32 *mem) {
|
|||||||
}
|
}
|
||||||
mem[i] = x;
|
mem[i] = x;
|
||||||
}
|
}
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user