-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathcircuits13.si
45 lines (41 loc) · 1.07 KB
/
circuits13.si
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
// a rather extreme pipelined multiplier going down to single bits
// defined by a recursive circuitry instantiation producing a pipeline
circuitry mul(output result,input a,input b)
{
$$if widthof('a') ~= widthof('b') then
$$ error('mul expects both inputs to have the same width')
$$end
$$local l = widthof('a')>>1
$$local h = widthof('a')-l
$$print('l = ' .. l .. ' h = ' .. h)
$$if l < 1 then
result = a[0,1] && b[0,1];
$$else
sameas(a) albh(0); sameas(a) ahbl(0); sameas(a) albl(0); sameas(a) ahbh(0);
->
(ahbl) = mul( a[$l$,$h$] , b[ 0,$l$] );
(albh) = mul( a[ 0,$h$] , b[$l$,$h$] );
(albl) = mul( a[ 0,$h$] , b[ 0,$h$] );
(ahbh) = mul( a[$l$,$h$] , b[$l$,$h$] );
->
result = { {ahbh,$l$b0} + ahbl+albh+albl[$l$,$h$] , albl[0,$l$] };
$$end
}
unit main(output uint8 leds)
{
uint16 t(0);
uint8 a(11); //$(1<<8)-1$);
uint8 b(22); //$(1<<8)-1$);
uint32 cycle(0);
algorithm {
__display("[%d] start",cycle);
(t) = mul(a,b);
->
uint32 m = a*b;
__display("[%d] %d %d",cycle,t,m);
leds = t;
}
always_after {
cycle = cycle + 1;
}
}