adds a new barrel shifter example

This commit is contained in:
hneemann 2021-01-07 19:35:48 +01:00
parent eb71b37077
commit 0ff4e7a7b8
4 changed files with 682 additions and 2 deletions

View File

@ -0,0 +1,530 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D^32</string>
</entry>
<entry>
<string>Bits</string>
<int>32</int>
</entry>
<entry>
<string>intFormat</string>
<intFormat>bin</intFormat>
</entry>
</elementAttributes>
<pos x="740" y="160"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D^32_in</string>
</entry>
<entry>
<string>Bits</string>
<int>32</int>
</entry>
<entry>
<string>intFormat</string>
<intFormat>bin</intFormat>
</entry>
<entry>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="160" y="140"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>sh^32</string>
</entry>
<entry>
<string>Bits</string>
<int>5</int>
</entry>
</elementAttributes>
<pos x="380" y="180"/>
</visualElement>
<visualElement>
<elementName>barrelShifter2.dig</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>32 bit, left</string>
</entry>
<entry>
<string>generic</string>
<string>dataBits := 32;
direction := &quot;left&quot;;</string>
</entry>
</elementAttributes>
<pos x="420" y="140"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D^8</string>
</entry>
<entry>
<string>Bits</string>
<int>8</int>
</entry>
<entry>
<string>intFormat</string>
<intFormat>bin</intFormat>
</entry>
</elementAttributes>
<pos x="740" y="420"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D^8_in</string>
</entry>
<entry>
<string>Bits</string>
<int>8</int>
</entry>
<entry>
<string>intFormat</string>
<intFormat>bin</intFormat>
</entry>
<entry>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="160" y="400"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>sh^8</string>
</entry>
<entry>
<string>Bits</string>
<int>3</int>
</entry>
</elementAttributes>
<pos x="380" y="440"/>
</visualElement>
<visualElement>
<elementName>barrelShifter2.dig</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>8 bit, left</string>
</entry>
<entry>
<string>generic</string>
<string>dataBits := 8;
direction := &quot;left&quot;;</string>
</entry>
</elementAttributes>
<pos x="420" y="400"/>
</visualElement>
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>32 bit, left</string>
</entry>
<entry>
<string>Testdata</string>
<testData>
<dataString>D^32_in sh^32 D^32
loop(n,32)
1 (n) (1&lt;&lt;n)
end loop
loop(n,32)
7 (n) (7&lt;&lt;n)
end loop</dataString>
</testData>
</entry>
</elementAttributes>
<pos x="580" y="220"/>
</visualElement>
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>8 bit, left</string>
</entry>
<entry>
<string>Testdata</string>
<testData>
<dataString>D^8_in sh^8 D^8
loop(n,8)
1 (n) (1&lt;&lt;n)
end loop
loop(n,8)
7 (n) (7&lt;&lt;n)
end loop</dataString>
</testData>
</entry>
</elementAttributes>
<pos x="580" y="480"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D^8_R</string>
</entry>
<entry>
<string>Bits</string>
<int>8</int>
</entry>
<entry>
<string>intFormat</string>
<intFormat>bin</intFormat>
</entry>
</elementAttributes>
<pos x="740" y="680"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D^8_inR</string>
</entry>
<entry>
<string>Bits</string>
<int>8</int>
</entry>
<entry>
<string>intFormat</string>
<intFormat>bin</intFormat>
</entry>
<entry>
<string>InDefault</string>
<value v="128" z="false"/>
</entry>
</elementAttributes>
<pos x="160" y="660"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>sh^8_R</string>
</entry>
<entry>
<string>Bits</string>
<int>3</int>
</entry>
</elementAttributes>
<pos x="380" y="700"/>
</visualElement>
<visualElement>
<elementName>barrelShifter2.dig</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>8 bit, right</string>
</entry>
<entry>
<string>generic</string>
<string>dataBits := 8;
direction := &quot;right&quot;;</string>
</entry>
</elementAttributes>
<pos x="420" y="660"/>
</visualElement>
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>8 bit, right</string>
</entry>
<entry>
<string>Testdata</string>
<testData>
<dataString>D^8_inR sh^8_R D^8_R
loop(n,8)
128 (n) (128&gt;&gt;n)
end loop
loop(n,8)
192 (n) (192&gt;&gt;n)
end loop</dataString>
</testData>
</entry>
</elementAttributes>
<pos x="580" y="740"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D^16</string>
</entry>
<entry>
<string>Bits</string>
<int>16</int>
</entry>
<entry>
<string>intFormat</string>
<intFormat>bin</intFormat>
</entry>
</elementAttributes>
<pos x="740" y="960"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D^16_in</string>
</entry>
<entry>
<string>Bits</string>
<int>16</int>
</entry>
<entry>
<string>intFormat</string>
<intFormat>bin</intFormat>
</entry>
<entry>
<string>InDefault</string>
<value v="32768" z="false"/>
</entry>
</elementAttributes>
<pos x="160" y="940"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>sh^16</string>
</entry>
<entry>
<string>Bits</string>
<int>4</int>
</entry>
</elementAttributes>
<pos x="380" y="980"/>
</visualElement>
<visualElement>
<elementName>barrelShifter2.dig</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>16 bit, right, arith</string>
</entry>
<entry>
<string>generic</string>
<string>dataBits := 16;
direction := &quot;arith&quot;;</string>
</entry>
</elementAttributes>
<pos x="420" y="940"/>
</visualElement>
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>16 bit, right arith</string>
</entry>
<entry>
<string>Testdata</string>
<testData>
<dataString>D^16_in sh^16 D^16
loop(n,16)
(1&lt;&lt;14) (n) ((1&lt;&lt;14)&gt;&gt;n)
end loop
loop(n,16)
(1&lt;&lt;15) (n) (-1&lt;&lt;(15-n))
end loop</dataString>
</testData>
</entry>
</elementAttributes>
<pos x="580" y="1020"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D^64</string>
</entry>
<entry>
<string>Bits</string>
<int>64</int>
</entry>
<entry>
<string>intFormat</string>
<intFormat>bin</intFormat>
</entry>
</elementAttributes>
<pos x="740" y="-120"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D^64_in</string>
</entry>
<entry>
<string>Bits</string>
<int>64</int>
</entry>
<entry>
<string>intFormat</string>
<intFormat>bin</intFormat>
</entry>
<entry>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="160" y="-140"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>sh^64</string>
</entry>
<entry>
<string>Bits</string>
<int>6</int>
</entry>
</elementAttributes>
<pos x="380" y="-100"/>
</visualElement>
<visualElement>
<elementName>barrelShifter2.dig</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>64 bit, left</string>
</entry>
<entry>
<string>generic</string>
<string>dataBits := 64;
direction := &quot;left&quot;;</string>
</entry>
</elementAttributes>
<pos x="420" y="-140"/>
</visualElement>
<visualElement>
<elementName>Testcase</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>64 bit, left</string>
</entry>
<entry>
<string>Testdata</string>
<testData>
<dataString>D^64_in sh^64 D^64
loop(n,64)
1 (n) (1&lt;&lt;n)
end loop
loop(n,64)
7 (n) (7&lt;&lt;n)
end loop</dataString>
</testData>
</entry>
</elementAttributes>
<pos x="580" y="-60"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="480" y="960"/>
<p2 x="740" y="960"/>
</wire>
<wire>
<p1 x="480" y="160"/>
<p2 x="740" y="160"/>
</wire>
<wire>
<p1 x="380" y="-100"/>
<p2 x="420" y="-100"/>
</wire>
<wire>
<p1 x="480" y="420"/>
<p2 x="740" y="420"/>
</wire>
<wire>
<p1 x="480" y="680"/>
<p2 x="740" y="680"/>
</wire>
<wire>
<p1 x="160" y="-140"/>
<p2 x="420" y="-140"/>
</wire>
<wire>
<p1 x="160" y="140"/>
<p2 x="420" y="140"/>
</wire>
<wire>
<p1 x="160" y="940"/>
<p2 x="420" y="940"/>
</wire>
<wire>
<p1 x="160" y="400"/>
<p2 x="420" y="400"/>
</wire>
<wire>
<p1 x="380" y="180"/>
<p2 x="420" y="180"/>
</wire>
<wire>
<p1 x="160" y="660"/>
<p2 x="420" y="660"/>
</wire>
<wire>
<p1 x="380" y="980"/>
<p2 x="420" y="980"/>
</wire>
<wire>
<p1 x="480" y="-120"/>
<p2 x="740" y="-120"/>
</wire>
<wire>
<p1 x="380" y="440"/>
<p2 x="420" y="440"/>
</wire>
<wire>
<p1 x="380" y="700"/>
<p2 x="420" y="700"/>
</wire>
</wires>
<measurementOrdering/>
</circuit>

View File

@ -214,6 +214,17 @@ direction := &quot;arith&quot;;</string>
</elementAttributes> </elementAttributes>
<pos x="540" y="0"/> <pos x="540" y="0"/>
</visualElement> </visualElement>
<visualElement>
<elementName>Text</elementName>
<elementAttributes>
<entry>
<string>Description</string>
<string>A BarrelShifter implemented using recursion.
{{de Ein rekursiv implementierter BarrelShifter.}}</string>
</entry>
</elementAttributes>
<pos x="180" y="-100"/>
</visualElement>
</visualElements> </visualElements>
<wires> <wires>
<wire> <wire>

View File

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes>
<entry>
<string>isGeneric</string>
<boolean>true</boolean>
</entry>
</attributes>
<visualElements>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>D</string>
</entry>
<entry>
<string>Bits</string>
<int>2</int>
</entry>
<entry>
<string>generic</string>
<string>this.Bits=args.dataBits;</string>
</entry>
</elementAttributes>
<pos x="-60" y="0"/>
</visualElement>
<visualElement>
<elementName>GenericInitCode</elementName>
<elementAttributes>
<entry>
<string>generic</string>
<string>dataBits:=16;
direction:=&quot;left&quot;;</string>
</entry>
</elementAttributes>
<pos x="-120" y="-160"/>
</visualElement>
<visualElement>
<elementName>GenericCode</elementName>
<elementAttributes>
<entry>
<string>generic</string>
<string>sh:=bitsNeededFor(args.dataBits)-1;
circuit:=&quot;&quot;;
if (args.direction=&quot;right&quot;) {
circuit=&quot;shift-fixed-right-inc.dig&quot;;
} else {
if (args.direction=&quot;arith&quot;) {
circuit=&quot;shift-fixed-arith-right-inc.dig&quot;;
} else {
if (args.direction=&quot;left&quot;) {
circuit=&quot;shift-fixed-left-inc.dig&quot;;
} else {
panic(&quot;only \&quot;left\&quot;, \&quot;right\&quot; or \&quot;arith\&quot; is allowed as direction, not \&quot;&quot;+args.direction+&quot;\&quot;!&quot;);
}
}
}
for (i:=0;i&lt;sh;i++) {
x:= i*5+2;
s:=addComponent(circuit,x,0);
s.shift:=1&lt;&lt;i;
addWire(x+3,1,x+5,0);
addWire(0,i+5,x-1,i+5);
addWire(x-1,i+5,x-1,2);
addWire(x-1,2,x,2);
}
o:=addComponent(&quot;Out&quot;,sh*5+2,0);
o.Bits=args.dataBits;
o.Label=&quot;Out&quot;;</string>
</entry>
</elementAttributes>
<pos x="-780" y="-40"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Label</string>
<string>sh</string>
</entry>
<entry>
<string>generic</string>
<string>this.Bits=bitsNeededFor(args.dataBits)-1;</string>
</entry>
</elementAttributes>
<pos x="-60" y="100"/>
</visualElement>
<visualElement>
<elementName>Splitter</elementName>
<elementAttributes>
<entry>
<string>Input Splitting</string>
<string>2</string>
</entry>
<entry>
<string>generic</string>
<string>sh:=bitsNeededFor(args.dataBits)-1;
this.&apos;Input Splitting&apos;=&quot;&quot;+sh;
this.&apos;Output Splitting&apos;=&quot;1*&quot;+sh;</string>
</entry>
<entry>
<string>Output Splitting</string>
<string>1,1</string>
</entry>
</elementAttributes>
<pos x="-20" y="100"/>
</visualElement>
<visualElement>
<elementName>Text</elementName>
<elementAttributes>
<entry>
<string>Description</string>
<string>A BarrelShifter implemented using component creation.
{{de Ein BarrelShifter implementiert durch Bauteilerzeugung.}}</string>
</entry>
</elementAttributes>
<pos x="-780" y="-280"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="-60" y="0"/>
<p2 x="40" y="0"/>
</wire>
<wire>
<p1 x="-60" y="100"/>
<p2 x="-20" y="100"/>
</wire>
</wires>
<measurementOrdering/>
</circuit>

View File

@ -40,8 +40,8 @@ public class TestExamples extends TestCase {
*/ */
public void testDistExamples() throws Exception { public void testDistExamples() throws Exception {
File examples = new File(Resources.getRoot().getParentFile().getParentFile(), "/main/dig"); File examples = new File(Resources.getRoot().getParentFile().getParentFile(), "/main/dig");
assertEquals(309, new FileScanner(this::check).scan(examples)); assertEquals(311, new FileScanner(this::check).scan(examples));
assertEquals(495, testCasesInFiles); assertEquals(500, testCasesInFiles);
} }
/** /**