diff --git a/examples/Introduction.ipynb b/examples/Introduction.ipynb index cdbbcab..fa72d0d 100644 --- a/examples/Introduction.ipynb +++ b/examples/Introduction.ipynb @@ -6,36 +6,28 @@ "source": [ "# KyuPy Introduction\n", "\n", - "Working with KyuPy's basic data structures.\n", + "This notebook introduces KyuPy's basic data structures and built-in functions step-by-step.\n", "\n", - "## Gate-Level Circuits\n", + "## Working With Gate-Level Circuit Structures\n", "\n", - "KyuPy has parsers for:\n", + "KyuPy has two parser modules:\n", "\n", - "* The [ISCAS'89 Benchmark Format](https://www.researchgate.net/profile/Franc-Brglez/publication/224723140_Combination_profiles_of_sequential_benchmark_circuits) \".bench\"\n", - "* Non-hierarchical gate-level verilog\n", + "* `kyupy.bench`: The [ISCAS'89 Benchmark Format](https://www.researchgate.net/profile/Franc-Brglez/publication/224723140_Combination_profiles_of_sequential_benchmark_circuits) \".bench\"\n", + "* `kyupy.verilog`: Non-hierarchical gate-level verilog\n", "\n", - "Files can be loaded using `load(file)`, strings can be parsed using `parse(text)`." + "Files can be loaded using `.load(file)`, strings can be parsed using `.parse(text)`." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "# 0000000.000 W Numba unavailable. Falling back to pure Python.\n" - ] - } - ], + "outputs": [], "source": [ "from kyupy import bench, verilog\n", "\n", "# load a file\n", - "b14 = verilog.load('../tests/b14.v.gz')\n", + "b15 = verilog.load('../tests/b15_2ig.v.gz')\n", "\n", "# ... or specify the circuit as string \n", "adder = bench.parse('''\n", @@ -54,7 +46,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "They return KyuPy's intermediate prepresentation of the circuit graph (objects of class `Circuit`):" + "They return KyuPy's intermediate prepresentation of the circuit graph (objects of class `kyupy.circuit.Circuit`):" ] }, { @@ -65,7 +57,7 @@ { "data": { "text/plain": [ - "{name: \"b14\", cells: 15873, forks: 15842, lines: 46891, io_nodes: 91}" + "kyupy.circuit.Circuit" ] }, "execution_count": 2, @@ -74,7 +66,7 @@ } ], "source": [ - "b14" + "type(b15)" ] }, { @@ -85,7 +77,7 @@ { "data": { "text/plain": [ - "{name: \"adder\", cells: 6, forks: 8, lines: 17, io_nodes: 3}" + "{name: \"b15\", cells: 10789, forks: 10749, lines: 32032, io_nodes: 111}" ] }, "execution_count": 3, @@ -93,6 +85,26 @@ "output_type": "execute_result" } ], + "source": [ + "b15" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{name: \"adder\", cells: 6, forks: 8, lines: 17, io_nodes: 3}" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "adder" ] @@ -101,18 +113,111 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Apparently, circuits contain `cells`, `forks`, `lines`, and `io_nodes`.\n", + "The `.stats` property returns a dictionary with more detailed statistics on the elements in the circuit." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'__node__': 21538,\n", + " '__cell__': 10789,\n", + " '__fork__': 10749,\n", + " '__io__': 111,\n", + " '__line__': 32032,\n", + " 'TIEH_RVT': 1,\n", + " '__comb__': 10261,\n", + " 'NBUFFX4_RVT': 114,\n", + " 'NBUFFX2_RVT': 371,\n", + " 'INVX2_RVT': 27,\n", + " 'NBUFFX8_RVT': 40,\n", + " 'INVX0_RVT': 769,\n", + " 'AND2X1_RVT': 996,\n", + " 'OR2X1_RVT': 1087,\n", + " 'OR2X2_RVT': 8,\n", + " 'INVX8_RVT': 30,\n", + " 'NOR2X2_RVT': 20,\n", + " 'INVX4_RVT': 36,\n", + " 'AND2X2_RVT': 50,\n", + " 'SDFFARX1_RVT': 412,\n", + " '__dff__': 417,\n", + " 'NAND2X0_RVT': 6596,\n", + " 'NOR2X0_RVT': 74,\n", + " 'NOR2X1_RVT': 15,\n", + " 'NAND2X1_RVT': 3,\n", + " 'NOR2X4_RVT': 5,\n", + " 'NAND2X2_RVT': 9,\n", + " 'SDFFARX2_RVT': 5,\n", + " 'NAND2X4_RVT': 3,\n", + " 'AND2X4_RVT': 1,\n", + " 'INVX32_RVT': 4,\n", + " 'INVX16_RVT': 1,\n", + " 'NBUFFX32_RVT': 1,\n", + " 'output': 71,\n", + " 'input': 40,\n", + " '__latch__': 0,\n", + " '__seq__': 417}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b15.stats" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'__node__': 14,\n", + " '__cell__': 6,\n", + " '__fork__': 8,\n", + " '__io__': 3,\n", + " '__line__': 17,\n", + " 'DFF': 1,\n", + " '__dff__': 1,\n", + " 'XOR': 2,\n", + " '__comb__': 5,\n", + " 'AND': 2,\n", + " 'OR': 1,\n", + " '__latch__': 0,\n", + " '__seq__': 1}" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "adder.stats" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Circuits contain `cells`, `forks`, `lines`, and `io_nodes`. Let's explore these...\n", "\n", "### Cells and Forks\n", "\n", - "Let's explore cells and forks for the adder circuit.\n", - "\n", - "There are dictionary-mappings from names to these objects:" + "`cells` and `forks` are dictionaries that map names to `Node`-objects." ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -126,7 +231,7 @@ " 'cout': 13:OR\"cout\" <15 <16 >14}" ] }, - "execution_count": 4, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -137,7 +242,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -153,7 +258,7 @@ " 'axbacin': 12:__fork__\"axbacin\" <11 >16}" ] }, - "execution_count": 5, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -166,12 +271,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "(For bench-files, the names of gates equal the names of the signals they produce. In verilog files, the names can be different.)" + "Access any cell or fork by name using a simple dictionary lookup:" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -180,7 +285,7 @@ "6:XOR\"axb\" <3 <4 >2" ] }, - "execution_count": 6, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -191,7 +296,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -200,7 +305,7 @@ "7:__fork__\"axb\" <2 >6 >12" ] }, - "execution_count": 7, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -223,7 +328,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -232,7 +337,7 @@ "(6, 'XOR', 'axb')" ] }, - "execution_count": 8, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -247,7 +352,7 @@ "source": [ "*Forks* are `Node`-objects of the special kind `__fork__`.\n", "\n", - "*Cells* are `Node`-objects of any other kind. A kind is just a string and can be anything.\n", + "*Cells* are `Node`-objects of any other kind. A *kind* is just a string and can be anything.\n", "\n", "The namespaces of *forks* and *cells* are separate:\n", "* A *cell* and a *fork* **can** have the same name.\n", @@ -256,7 +361,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -265,7 +370,7 @@ "(7, '__fork__', 'axb')" ] }, - "execution_count": 9, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -278,16 +383,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The `index` of a *node* in a circuit is unique and consecutive.\n", + "The `index` of a *node* in a circuit is a unique and consecutive integer.\n", "\n", - "Also *forks* and *cells* have all separate indices.\n", + "Although *Forks* and *cells* can have the same name, they all have separate indices.\n", "\n", "Nodes can be accessed by their index using the `nodes` list:" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -309,7 +414,7 @@ " 13:OR\"cout\" <15 <16 >14]" ] }, - "execution_count": 10, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -320,7 +425,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -329,7 +434,7 @@ "(6:XOR\"axb\" <3 <4 >2, 7:__fork__\"axb\" <2 >6 >12)" ] }, - "execution_count": 11, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -338,6 +443,62 @@ "adder.nodes[6], adder.nodes[7]" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A common use for the index is to store additional data for nodes. Since the index is positive, unique, and consecutive, it can be easily used with external arrays or lists.\n", + "\n", + "This is how you store an additional \"weight\" for each node in the circuit:" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "weights = [0] * len(adder.nodes)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Use the node instance to index into the external list. This also works with numpy arrays, of course." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "weights[adder.cells['axb']] = 5" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "weights" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -355,7 +516,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -364,7 +525,7 @@ "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]" ] }, - "execution_count": 12, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -382,7 +543,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -391,7 +552,7 @@ "(6:XOR\"axb\" <3 <4 >2, 7:__fork__\"axb\" <2 >6 >12)" ] }, - "execution_count": 13, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -413,7 +574,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -422,7 +583,7 @@ "([3, 4], [2])" ] }, - "execution_count": 14, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -440,7 +601,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -449,7 +610,7 @@ "(0, 0, 1)" ] }, - "execution_count": 15, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -469,7 +630,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -478,7 +639,7 @@ "[0:__fork__\"a\" >3 >9, 1:__fork__\"b\" >4 >10, 2:__fork__\"s\" <5 ]" ] }, - "execution_count": 16, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -500,7 +661,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -512,7 +673,7 @@ " 4:DFF\"cin\" <1 >0]" ] }, - "execution_count": 17, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -532,7 +693,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -541,7 +702,7 @@ "6:XOR\"axb\" <3 <4 >2" ] }, - "execution_count": 18, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -552,7 +713,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -571,7 +732,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -580,7 +741,7 @@ "'cout'" ] }, - "execution_count": 20, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -593,47 +754,47 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Let's continue with `b14` loaded before. It has 91 io_nodes:" + "Let's continue with `b15` loaded before. It has 111 io_nodes:" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "({name: \"b14\", cells: 15873, forks: 15842, lines: 46891, io_nodes: 91},\n", - " [31587:input\"clock\" >15805,\n", - " 31589:input\"reset\" >15806,\n", - " 31591:output\"addr[19]\" <46836 ,\n", - " 31592:output\"addr[18]\" <46837 ,\n", - " 31593:output\"addr[17]\" <46838 ,\n", - " 31594:output\"addr[16]\" <46839 ,\n", - " 31595:output\"addr[15]\" <46840 ,\n", - " 31596:output\"addr[14]\" <46841 ,\n", - " 31597:output\"addr[13]\" <46842 ,\n", - " 31598:output\"addr[12]\" <46843 ,\n", - " 31599:output\"addr[11]\" <46844 ,\n", - " 31600:output\"addr[10]\" <46845 ,\n", - " 31601:output\"addr[9]\" <46846 ,\n", - " 31602:output\"addr[8]\" <46847 ,\n", - " 31603:output\"addr[7]\" <46848 ,\n", - " 31604:output\"addr[6]\" <46849 ,\n", - " 31605:output\"addr[5]\" <46850 ,\n", - " 31606:output\"addr[4]\" <46851 ,\n", - " 31607:output\"addr[3]\" <46852 ,\n", - " 31608:output\"addr[2]\" <46853 ])" + "({name: \"b15\", cells: 10789, forks: 10749, lines: 32032, io_nodes: 111},\n", + " [21386:output\"BE_n[3]\" <31961 ,\n", + " 21387:output\"BE_n[2]\" <31962 ,\n", + " 21388:output\"BE_n[1]\" <31963 ,\n", + " 21389:output\"BE_n[0]\" <31964 ,\n", + " 21390:output\"Address[29]\" <31965 ,\n", + " 21391:output\"Address[28]\" <31966 ,\n", + " 21392:output\"Address[27]\" <31967 ,\n", + " 21393:output\"Address[26]\" <31968 ,\n", + " 21394:output\"Address[25]\" <31969 ,\n", + " 21395:output\"Address[24]\" <31970 ,\n", + " 21396:output\"Address[23]\" <31971 ,\n", + " 21397:output\"Address[22]\" <31972 ,\n", + " 21398:output\"Address[21]\" <31973 ,\n", + " 21399:output\"Address[20]\" <31974 ,\n", + " 21400:output\"Address[19]\" <31975 ,\n", + " 21401:output\"Address[18]\" <31976 ,\n", + " 21402:output\"Address[17]\" <31977 ,\n", + " 21403:output\"Address[16]\" <31978 ,\n", + " 21404:output\"Address[15]\" <31979 ,\n", + " 21405:output\"Address[14]\" <31980 ])" ] }, - "execution_count": 21, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "b14, b14.io_nodes[:20]" + "b15, b15.io_nodes[:20]" ] }, { @@ -645,127 +806,310 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "306" + "528" ] }, - "execution_count": 22, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "len(b14.s_nodes)" + "len(b15.s_nodes)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The `io_locs(prefix)` and `s_locs(prefix)` methods return the locations of signals, busses and registers in `io_nodes` and `s_nodes`:" + "The `.io_locs(prefix)` and `.s_locs(prefix)` methods return the locations of signals, busses and registers in `io_nodes` and `s_nodes`. :" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "1" + "107" ] }, - "execution_count": 23, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "b14.io_locs('reset')" + "b15.io_locs('RESET')" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]" + "[33,\n", + " 32,\n", + " 31,\n", + " 30,\n", + " 29,\n", + " 28,\n", + " 27,\n", + " 26,\n", + " 25,\n", + " 24,\n", + " 23,\n", + " 22,\n", + " 21,\n", + " 20,\n", + " 19,\n", + " 18,\n", + " 17,\n", + " 16,\n", + " 15,\n", + " 14,\n", + " 13,\n", + " 12,\n", + " 11,\n", + " 10,\n", + " 9,\n", + " 8,\n", + " 7,\n", + " 6,\n", + " 5,\n", + " 4]" ] }, - "execution_count": 24, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "b14.io_locs('addr')" + "b15.io_locs('Address')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Example of a two-dimensional register file (16 8-bit registers):" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[1130:SDFFARX1_RVT\"IR_reg_0_\" <16917 <16919 <16918 <16920 <16921 >566 >567,\n", - " 1202:SDFFARX1_RVT\"IR_reg_1_\" <17052 <17054 <17053 <17055 <17056 >611 >612,\n", - " 1124:SDFFARX1_RVT\"IR_reg_2_\" <16907 <16909 <16908 <16910 <16911 >562 >563,\n", - " 1127:SDFFARX1_RVT\"IR_reg_3_\" <16912 <16914 <16913 <16915 <16916 >564 >565,\n", - " 1199:SDFFARX1_RVT\"IR_reg_4_\" <17047 <17049 <17048 <17050 <17051 >609 >610,\n", - " 1196:SDFFARX1_RVT\"IR_reg_5_\" <17042 <17044 <17043 <17045 <17046 >607 >608,\n", - " 1193:SDFFARX1_RVT\"IR_reg_6_\" <17037 <17039 <17038 <17040 <17041 >605 >606,\n", - " 1190:SDFFARX1_RVT\"IR_reg_7_\" <17032 <17034 <17033 <17035 <17036 >603 >604,\n", - " 1187:SDFFARX1_RVT\"IR_reg_8_\" <17027 <17029 <17028 <17030 <17031 >601 >602,\n", - " 1184:SDFFARX1_RVT\"IR_reg_9_\" <17022 <17024 <17023 <17025 <17026 >599 >600,\n", - " 1181:SDFFARX1_RVT\"IR_reg_10_\" <17017 <17019 <17018 <17020 <17021 >597 >598,\n", - " 1178:SDFFARX1_RVT\"IR_reg_11_\" <17012 <17014 <17013 <17015 <17016 >595 >596,\n", - " 1175:SDFFARX1_RVT\"IR_reg_12_\" <17007 <17009 <17008 <17010 <17011 >593 >594,\n", - " 1172:SDFFARX1_RVT\"IR_reg_13_\" <17002 <17004 <17003 <17005 <17006 >591 >592,\n", - " 1169:SDFFARX1_RVT\"IR_reg_14_\" <16997 <16999 <16998 <17000 <17001 >589 >590,\n", - " 1166:SDFFARX1_RVT\"IR_reg_15_\" <16992 <16994 <16993 <16995 <16996 >587 >588,\n", - " 1163:SDFFARX1_RVT\"IR_reg_16_\" <16987 <16989 <16988 <16990 <16991 >585 >586,\n", - " 1133:SDFFARX1_RVT\"IR_reg_17_\" <16922 <16924 <16923 <16925 <16926 >568 >569,\n", - " 1136:SDFFARX1_RVT\"IR_reg_18_\" <16927 <16929 <16928 <16930 <16931 >570,\n", - " 1138:SDFFARX1_RVT\"IR_reg_19_\" <16932 <16934 <16933 <16935 <16936 >571 >572,\n", - " 1141:SDFFARX1_RVT\"IR_reg_20_\" <16937 <16939 <16938 <16940 <16941 >573,\n", - " 1143:SDFFARX1_RVT\"IR_reg_21_\" <16942 <16944 <16943 <16945 <16946 >574 >575,\n", - " 1146:SDFFARX1_RVT\"IR_reg_22_\" <16947 <16949 <16948 <16950 <16951 >576 >577,\n", - " 1149:SDFFARX1_RVT\"IR_reg_23_\" <16952 <16954 <16953 <16955 <16956 >578,\n", - " 1151:SDFFARX1_RVT\"IR_reg_24_\" <16957 <16959 <16958 <16960 <16961 >579,\n", - " 1153:SDFFARX1_RVT\"IR_reg_25_\" <16962 <16964 <16963 <16965 <16966 >580,\n", - " 1155:SDFFARX1_RVT\"IR_reg_26_\" <16967 <16969 <16968 <16970 <16971 >581,\n", - " 1157:SDFFARX1_RVT\"IR_reg_27_\" <16972 <16974 <16973 <16975 <16976 >582,\n", - " 1159:SDFFARX1_RVT\"IR_reg_28_\" <16977 <16979 <16978 <16980 <16981 >583,\n", - " 1161:SDFFARX1_RVT\"IR_reg_29_\" <16982 <16984 <16983 <16985 <16986 >584,\n", - " 1122:SDFFARX1_RVT\"IR_reg_30_\" <16902 <16904 <16903 <16905 <16906 >561,\n", - " 1120:SDFFARX1_RVT\"IR_reg_31_\" <16897 <16899 <16898 <16900 <16901 >560]" + "[[349, 348, 350, 347, 351, 346, 352, 345],\n", + " [357, 356, 358, 355, 359, 354, 360, 353],\n", + " [365, 364, 366, 363, 367, 362, 368, 361],\n", + " [373, 372, 374, 371, 375, 370, 376, 369],\n", + " [381, 380, 382, 379, 383, 378, 384, 377],\n", + " [389, 388, 390, 387, 391, 386, 392, 385],\n", + " [397, 396, 398, 395, 399, 394, 400, 393],\n", + " [405, 404, 406, 403, 407, 402, 408, 401],\n", + " [413, 412, 414, 411, 415, 410, 416, 409],\n", + " [421, 420, 422, 419, 423, 418, 424, 417],\n", + " [429, 428, 430, 427, 431, 426, 432, 425],\n", + " [437, 436, 438, 435, 439, 434, 440, 433],\n", + " [445, 444, 446, 443, 447, 442, 448, 441],\n", + " [453, 452, 454, 451, 455, 450, 456, 449],\n", + " [461, 460, 462, 459, 463, 458, 464, 457],\n", + " [469, 468, 470, 467, 471, 466, 472, 465]]" ] }, - "execution_count": 25, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "[b14.s_nodes[i] for i in b14.s_locs('IR_reg')]" + "b15.s_locs('InstQueue_reg')" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "---------------\n", + "1385:SDFFARX1_RVT\"InstQueue_reg_0__0_\" <12704 <12706 <12705 <12707 <12708 >702\n", + "1383:SDFFARX1_RVT\"InstQueue_reg_0__1_\" <12699 <12701 <12700 <12702 <12703 >701\n", + "1387:SDFFARX1_RVT\"InstQueue_reg_0__2_\" <12709 <12711 <12710 <12712 <12713 >703\n", + "1381:SDFFARX1_RVT\"InstQueue_reg_0__3_\" <12694 <12696 <12695 <12697 <12698 >700\n", + "1389:SDFFARX1_RVT\"InstQueue_reg_0__4_\" <12714 <12716 <12715 <12717 <12718 >704\n", + "1379:SDFFARX1_RVT\"InstQueue_reg_0__5_\" <12689 <12691 <12690 <12692 <12693 >699\n", + "1391:SDFFARX1_RVT\"InstQueue_reg_0__6_\" <12719 <12721 <12720 <12722 <12723 >705\n", + "1377:SDFFARX1_RVT\"InstQueue_reg_0__7_\" <12684 <12686 <12685 <12687 <12688 >698\n", + "---------------\n", + "1401:SDFFARX1_RVT\"InstQueue_reg_1__0_\" <12744 <12746 <12745 <12747 <12748 >710\n", + "1399:SDFFARX1_RVT\"InstQueue_reg_1__1_\" <12739 <12741 <12740 <12742 <12743 >709\n", + "1403:SDFFARX1_RVT\"InstQueue_reg_1__2_\" <12749 <12751 <12750 <12752 <12753 >711\n", + "1397:SDFFARX1_RVT\"InstQueue_reg_1__3_\" <12734 <12736 <12735 <12737 <12738 >708\n", + "1405:SDFFARX1_RVT\"InstQueue_reg_1__4_\" <12754 <12756 <12755 <12757 <12758 >712\n", + "1395:SDFFARX1_RVT\"InstQueue_reg_1__5_\" <12729 <12731 <12730 <12732 <12733 >707\n", + "1407:SDFFARX1_RVT\"InstQueue_reg_1__6_\" <12759 <12761 <12760 <12762 <12763 >713\n", + "1393:SDFFARX1_RVT\"InstQueue_reg_1__7_\" <12724 <12726 <12725 <12727 <12728 >706\n", + "---------------\n", + "1417:SDFFARX1_RVT\"InstQueue_reg_2__0_\" <12784 <12786 <12785 <12787 <12788 >718\n", + "1415:SDFFARX1_RVT\"InstQueue_reg_2__1_\" <12779 <12781 <12780 <12782 <12783 >717\n", + "1419:SDFFARX1_RVT\"InstQueue_reg_2__2_\" <12789 <12791 <12790 <12792 <12793 >719\n", + "1413:SDFFARX1_RVT\"InstQueue_reg_2__3_\" <12774 <12776 <12775 <12777 <12778 >716\n", + "1421:SDFFARX1_RVT\"InstQueue_reg_2__4_\" <12794 <12796 <12795 <12797 <12798 >720\n", + "1411:SDFFARX1_RVT\"InstQueue_reg_2__5_\" <12769 <12771 <12770 <12772 <12773 >715\n", + "1423:SDFFARX1_RVT\"InstQueue_reg_2__6_\" <12799 <12801 <12800 <12802 <12803 >721\n", + "1409:SDFFARX1_RVT\"InstQueue_reg_2__7_\" <12764 <12766 <12765 <12767 <12768 >714\n", + "---------------\n", + "1433:SDFFARX1_RVT\"InstQueue_reg_3__0_\" <12824 <12826 <12825 <12827 <12828 >726\n", + "1431:SDFFARX1_RVT\"InstQueue_reg_3__1_\" <12819 <12821 <12820 <12822 <12823 >725\n", + "1435:SDFFARX1_RVT\"InstQueue_reg_3__2_\" <12829 <12831 <12830 <12832 <12833 >727\n", + "1429:SDFFARX1_RVT\"InstQueue_reg_3__3_\" <12814 <12816 <12815 <12817 <12818 >724\n", + "1437:SDFFARX1_RVT\"InstQueue_reg_3__4_\" <12834 <12836 <12835 <12837 <12838 >728\n", + "1427:SDFFARX1_RVT\"InstQueue_reg_3__5_\" <12809 <12811 <12810 <12812 <12813 >723\n", + "1439:SDFFARX1_RVT\"InstQueue_reg_3__6_\" <12839 <12841 <12840 <12842 <12843 >729\n", + "1425:SDFFARX1_RVT\"InstQueue_reg_3__7_\" <12804 <12806 <12805 <12807 <12808 >722\n", + "---------------\n", + "1449:SDFFARX1_RVT\"InstQueue_reg_4__0_\" <12864 <12866 <12865 <12867 <12868 >734\n", + "1447:SDFFARX1_RVT\"InstQueue_reg_4__1_\" <12859 <12861 <12860 <12862 <12863 >733\n", + "1451:SDFFARX1_RVT\"InstQueue_reg_4__2_\" <12869 <12871 <12870 <12872 <12873 >735\n", + "1445:SDFFARX1_RVT\"InstQueue_reg_4__3_\" <12854 <12856 <12855 <12857 <12858 >732\n", + "1453:SDFFARX1_RVT\"InstQueue_reg_4__4_\" <12874 <12876 <12875 <12877 <12878 >736\n", + "1443:SDFFARX1_RVT\"InstQueue_reg_4__5_\" <12849 <12851 <12850 <12852 <12853 >731\n", + "1455:SDFFARX1_RVT\"InstQueue_reg_4__6_\" <12879 <12881 <12880 <12882 <12883 >737\n", + "1441:SDFFARX1_RVT\"InstQueue_reg_4__7_\" <12844 <12846 <12845 <12847 <12848 >730\n", + "---------------\n", + "1465:SDFFARX1_RVT\"InstQueue_reg_5__0_\" <12904 <12906 <12905 <12907 <12908 >742\n", + "1463:SDFFARX1_RVT\"InstQueue_reg_5__1_\" <12899 <12901 <12900 <12902 <12903 >741\n", + "1467:SDFFARX1_RVT\"InstQueue_reg_5__2_\" <12909 <12911 <12910 <12912 <12913 >743\n", + "1461:SDFFARX1_RVT\"InstQueue_reg_5__3_\" <12894 <12896 <12895 <12897 <12898 >740\n", + "1469:SDFFARX1_RVT\"InstQueue_reg_5__4_\" <12914 <12916 <12915 <12917 <12918 >744\n", + "1459:SDFFARX1_RVT\"InstQueue_reg_5__5_\" <12889 <12891 <12890 <12892 <12893 >739\n", + "1471:SDFFARX1_RVT\"InstQueue_reg_5__6_\" <12919 <12921 <12920 <12922 <12923 >745\n", + "1457:SDFFARX1_RVT\"InstQueue_reg_5__7_\" <12884 <12886 <12885 <12887 <12888 >738\n", + "---------------\n", + "1481:SDFFARX1_RVT\"InstQueue_reg_6__0_\" <12944 <12946 <12945 <12947 <12948 >750\n", + "1479:SDFFARX1_RVT\"InstQueue_reg_6__1_\" <12939 <12941 <12940 <12942 <12943 >749\n", + "1483:SDFFARX1_RVT\"InstQueue_reg_6__2_\" <12949 <12951 <12950 <12952 <12953 >751\n", + "1477:SDFFARX1_RVT\"InstQueue_reg_6__3_\" <12934 <12936 <12935 <12937 <12938 >748\n", + "1485:SDFFARX1_RVT\"InstQueue_reg_6__4_\" <12954 <12956 <12955 <12957 <12958 >752\n", + "1475:SDFFARX1_RVT\"InstQueue_reg_6__5_\" <12929 <12931 <12930 <12932 <12933 >747\n", + "1487:SDFFARX1_RVT\"InstQueue_reg_6__6_\" <12959 <12961 <12960 <12962 <12963 >753\n", + "1473:SDFFARX1_RVT\"InstQueue_reg_6__7_\" <12924 <12926 <12925 <12927 <12928 >746\n", + "---------------\n", + "1497:SDFFARX1_RVT\"InstQueue_reg_7__0_\" <12984 <12986 <12985 <12987 <12988 >758\n", + "1495:SDFFARX1_RVT\"InstQueue_reg_7__1_\" <12979 <12981 <12980 <12982 <12983 >757\n", + "1499:SDFFARX1_RVT\"InstQueue_reg_7__2_\" <12989 <12991 <12990 <12992 <12993 >759\n", + "1493:SDFFARX1_RVT\"InstQueue_reg_7__3_\" <12974 <12976 <12975 <12977 <12978 >756\n", + "1501:SDFFARX1_RVT\"InstQueue_reg_7__4_\" <12994 <12996 <12995 <12997 <12998 >760\n", + "1491:SDFFARX1_RVT\"InstQueue_reg_7__5_\" <12969 <12971 <12970 <12972 <12973 >755\n", + "1503:SDFFARX1_RVT\"InstQueue_reg_7__6_\" <12999 <13001 <13000 <13002 <13003 >761\n", + "1489:SDFFARX1_RVT\"InstQueue_reg_7__7_\" <12964 <12966 <12965 <12967 <12968 >754\n", + "---------------\n", + "1513:SDFFARX1_RVT\"InstQueue_reg_8__0_\" <13024 <13026 <13025 <13027 <13028 >766\n", + "1511:SDFFARX1_RVT\"InstQueue_reg_8__1_\" <13019 <13021 <13020 <13022 <13023 >765\n", + "1515:SDFFARX1_RVT\"InstQueue_reg_8__2_\" <13029 <13031 <13030 <13032 <13033 >767 >768\n", + "1509:SDFFARX1_RVT\"InstQueue_reg_8__3_\" <13014 <13016 <13015 <13017 <13018 >764\n", + "1518:SDFFARX1_RVT\"InstQueue_reg_8__4_\" <13034 <13036 <13035 <13037 <13038 >769\n", + "1507:SDFFARX1_RVT\"InstQueue_reg_8__5_\" <13009 <13011 <13010 <13012 <13013 >763\n", + "1520:SDFFARX1_RVT\"InstQueue_reg_8__6_\" <13039 <13041 <13040 <13042 <13043 >770\n", + "1505:SDFFARX1_RVT\"InstQueue_reg_8__7_\" <13004 <13006 <13005 <13007 <13008 >762\n", + "---------------\n", + "1530:SDFFARX1_RVT\"InstQueue_reg_9__0_\" <13064 <13066 <13065 <13067 <13068 >775\n", + "1528:SDFFARX1_RVT\"InstQueue_reg_9__1_\" <13059 <13061 <13060 <13062 <13063 >774\n", + "1532:SDFFARX1_RVT\"InstQueue_reg_9__2_\" <13069 <13071 <13070 <13072 <13073 >776\n", + "1526:SDFFARX1_RVT\"InstQueue_reg_9__3_\" <13054 <13056 <13055 <13057 <13058 >773\n", + "1534:SDFFARX1_RVT\"InstQueue_reg_9__4_\" <13074 <13076 <13075 <13077 <13078 >777\n", + "1524:SDFFARX1_RVT\"InstQueue_reg_9__5_\" <13049 <13051 <13050 <13052 <13053 >772\n", + "1536:SDFFARX1_RVT\"InstQueue_reg_9__6_\" <13079 <13081 <13080 <13082 <13083 >778\n", + "1522:SDFFARX1_RVT\"InstQueue_reg_9__7_\" <13044 <13046 <13045 <13047 <13048 >771\n", + "---------------\n", + "1546:SDFFARX1_RVT\"InstQueue_reg_10__0_\" <13104 <13106 <13105 <13107 <13108 >783\n", + "1544:SDFFARX1_RVT\"InstQueue_reg_10__1_\" <13099 <13101 <13100 <13102 <13103 >782\n", + "1548:SDFFARX1_RVT\"InstQueue_reg_10__2_\" <13109 <13111 <13110 <13112 <13113 >784\n", + "1542:SDFFARX1_RVT\"InstQueue_reg_10__3_\" <13094 <13096 <13095 <13097 <13098 >781\n", + "1550:SDFFARX1_RVT\"InstQueue_reg_10__4_\" <13114 <13116 <13115 <13117 <13118 >785 >786\n", + "1540:SDFFARX1_RVT\"InstQueue_reg_10__5_\" <13089 <13091 <13090 <13092 <13093 >780\n", + "1553:SDFFARX1_RVT\"InstQueue_reg_10__6_\" <13119 <13121 <13120 <13122 <13123 >787\n", + "1538:SDFFARX1_RVT\"InstQueue_reg_10__7_\" <13084 <13086 <13085 <13087 <13088 >779\n", + "---------------\n", + "1563:SDFFARX1_RVT\"InstQueue_reg_11__0_\" <13144 <13146 <13145 <13147 <13148 >792\n", + "1561:SDFFARX1_RVT\"InstQueue_reg_11__1_\" <13139 <13141 <13140 <13142 <13143 >791\n", + "1565:SDFFARX1_RVT\"InstQueue_reg_11__2_\" <13149 <13151 <13150 <13152 <13153 >793\n", + "1559:SDFFARX1_RVT\"InstQueue_reg_11__3_\" <13134 <13136 <13135 <13137 <13138 >790\n", + "1567:SDFFARX1_RVT\"InstQueue_reg_11__4_\" <13154 <13156 <13155 <13157 <13158 >794\n", + "1557:SDFFARX1_RVT\"InstQueue_reg_11__5_\" <13129 <13131 <13130 <13132 <13133 >789\n", + "1569:SDFFARX1_RVT\"InstQueue_reg_11__6_\" <13159 <13161 <13160 <13162 <13163 >795\n", + "1555:SDFFARX1_RVT\"InstQueue_reg_11__7_\" <13124 <13126 <13125 <13127 <13128 >788\n", + "---------------\n", + "1579:SDFFARX1_RVT\"InstQueue_reg_12__0_\" <13184 <13186 <13185 <13187 <13188 >800\n", + "1577:SDFFARX1_RVT\"InstQueue_reg_12__1_\" <13179 <13181 <13180 <13182 <13183 >799\n", + "1581:SDFFARX1_RVT\"InstQueue_reg_12__2_\" <13189 <13191 <13190 <13192 <13193 >801\n", + "1575:SDFFARX1_RVT\"InstQueue_reg_12__3_\" <13174 <13176 <13175 <13177 <13178 >798\n", + "1583:SDFFARX1_RVT\"InstQueue_reg_12__4_\" <13194 <13196 <13195 <13197 <13198 >802\n", + "1573:SDFFARX1_RVT\"InstQueue_reg_12__5_\" <13169 <13171 <13170 <13172 <13173 >797\n", + "1585:SDFFARX1_RVT\"InstQueue_reg_12__6_\" <13199 <13201 <13200 <13202 <13203 >803\n", + "1571:SDFFARX1_RVT\"InstQueue_reg_12__7_\" <13164 <13166 <13165 <13167 <13168 >796\n", + "---------------\n", + "1595:SDFFARX1_RVT\"InstQueue_reg_13__0_\" <13224 <13226 <13225 <13227 <13228 >808\n", + "1593:SDFFARX1_RVT\"InstQueue_reg_13__1_\" <13219 <13221 <13220 <13222 <13223 >807\n", + "1597:SDFFARX1_RVT\"InstQueue_reg_13__2_\" <13229 <13231 <13230 <13232 <13233 >809\n", + "1591:SDFFARX1_RVT\"InstQueue_reg_13__3_\" <13214 <13216 <13215 <13217 <13218 >806\n", + "1599:SDFFARX1_RVT\"InstQueue_reg_13__4_\" <13234 <13236 <13235 <13237 <13238 >810\n", + "1589:SDFFARX1_RVT\"InstQueue_reg_13__5_\" <13209 <13211 <13210 <13212 <13213 >805\n", + "1601:SDFFARX1_RVT\"InstQueue_reg_13__6_\" <13239 <13241 <13240 <13242 <13243 >811\n", + "1587:SDFFARX1_RVT\"InstQueue_reg_13__7_\" <13204 <13206 <13205 <13207 <13208 >804\n", + "---------------\n", + "1611:SDFFARX1_RVT\"InstQueue_reg_14__0_\" <13264 <13266 <13265 <13267 <13268 >816\n", + "1609:SDFFARX1_RVT\"InstQueue_reg_14__1_\" <13259 <13261 <13260 <13262 <13263 >815\n", + "1613:SDFFARX1_RVT\"InstQueue_reg_14__2_\" <13269 <13271 <13270 <13272 <13273 >817\n", + "1607:SDFFARX1_RVT\"InstQueue_reg_14__3_\" <13254 <13256 <13255 <13257 <13258 >814\n", + "1615:SDFFARX1_RVT\"InstQueue_reg_14__4_\" <13274 <13276 <13275 <13277 <13278 >818\n", + "1605:SDFFARX1_RVT\"InstQueue_reg_14__5_\" <13249 <13251 <13250 <13252 <13253 >813\n", + "1617:SDFFARX1_RVT\"InstQueue_reg_14__6_\" <13279 <13281 <13280 <13282 <13283 >819\n", + "1603:SDFFARX1_RVT\"InstQueue_reg_14__7_\" <13244 <13246 <13245 <13247 <13248 >812\n", + "---------------\n", + "1627:SDFFARX1_RVT\"InstQueue_reg_15__0_\" <13304 <13306 <13305 <13307 <13308 >824\n", + "1625:SDFFARX1_RVT\"InstQueue_reg_15__1_\" <13299 <13301 <13300 <13302 <13303 >823\n", + "1629:SDFFARX1_RVT\"InstQueue_reg_15__2_\" <13309 <13311 <13310 <13312 <13313 >825\n", + "1623:SDFFARX1_RVT\"InstQueue_reg_15__3_\" <13294 <13296 <13295 <13297 <13298 >822\n", + "1631:SDFFARX1_RVT\"InstQueue_reg_15__4_\" <13314 <13316 <13315 <13317 <13318 >826\n", + "1621:SDFFARX1_RVT\"InstQueue_reg_15__5_\" <13289 <13291 <13290 <13292 <13293 >821\n", + "1633:SDFFARX1_RVT\"InstQueue_reg_15__6_\" <13319 <13321 <13320 <13322 <13323 >827\n", + "1619:SDFFARX1_RVT\"InstQueue_reg_15__7_\" <13284 <13286 <13285 <13287 <13288 >820\n" + ] + } + ], + "source": [ + "for l in b15.s_locs('InstQueue_reg'):\n", + " print('---------------')\n", + " for i in l:\n", + " print(b15.s_nodes[i])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "**Example: Tracing out a scan chain.**\n", + "### Example: Tracing A Scan Chain\n", "\n", "We start at the output of the scan chain \"test_so000\", then go backwards through the circuit.\n", "\n", @@ -774,22 +1118,22 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "length (with forks): 573\n", - "length (without forks): 287\n", - "length only SDFF: 215\n", - "output\"test_so000\" __fork__\"test_so000\" NBUFFX8_RVT\"HFSBUF_36_76\" __fork__\"aps_rename_215_\" SDFFARX1_RVT\"wr_reg\" __fork__\"HFSNET_169\" INVX4_RVT\"HFSINV_691_254\" __fork__\"HFSNET_170\" INVX0_RVT\"HFSINV_2682_255\" __fork__\"state\" ... __fork__\"IR[0]\" SDFFARX1_RVT\"IR_reg_0_\" __fork__\"ZBUF_17_16\" NBUFFX2_RVT\"ZBUF_17_inst_905\" __fork__\"ZBUF_275_16\" NBUFFX4_RVT\"ZBUF_275_inst_906\" __fork__\"B\" SDFFARX1_RVT\"B_reg\" __fork__\"test_si000\" input\"test_si000\"\n" + "length (with forks): 1123\n", + "length (without forks): 562\n", + "length only SDFF: 417\n", + "output\"test_so000\" __fork__\"test_so000\" NBUFFX8_RVT\"ZBUF_15_inst_543\" __fork__\"aps_rename_15_\" SDFFARX1_RVT\"W_R_n_reg\" __fork__\"ZBUF_17_48\" NBUFFX2_RVT\"ZBUF_17_inst_981\" __fork__\"N3897\" SDFFARX1_RVT\"uWord_reg_14_\" __fork__\"N3896\" ... __fork__\"Address[0]\" NBUFFX2_RVT\"ZBUF_19_inst_438\" __fork__\"aps_rename_14_\" SDFFARX1_RVT\"Address_reg_0_\" __fork__\"ADS_n\" NBUFFX2_RVT\"ZBUF_34_inst_547\" __fork__\"aps_rename_18_\" SDFFARX1_RVT\"ADS_n_reg\" __fork__\"test_si000\" input\"test_si000\"\n" ] } ], "source": [ - "chain = [cell := b14.cells['test_so000']]\n", + "chain = [cell := b15.cells['test_so000']]\n", "while len(cell.ins) > 0:\n", " chain.append(cell := cell.ins[2 if cell.kind.startswith('SDFF') else 0].driver)\n", " \n", @@ -805,7 +1149,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "There is a generator for **traversing the circuit in topological order**.\n", + "### Traversing a Circuit in Topological Order\n", + "\n", + "There are several generators to traverse the circuit in various topological orderings.\n", "\n", "The following loop prints all nodes:\n", "* starting with primary inputs (nodes that don't have any input connections) and sequential elements,\n", @@ -814,7 +1160,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 34, "metadata": {}, "outputs": [ { @@ -847,7 +1193,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Example: Determining logic level (distance from inputs or sequential elements) of nodes.**\n", + "### Example: Determine Topological Level\n", + "\n", + "The topological (or logic level) of a node is its distance from inputs or sequential elements.\n", "\n", "Inputs and flip-flops themselves are level 0, *cells* driven by just inputs and flip-flops are level 1, and so on.\n", "*Fork* nodes have the same level as their driver, because they do not increase the logic depth." @@ -855,25 +1203,25 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Maximum logic depth: 112\n" + "Maximum logic depth: 44\n" ] } ], "source": [ "import numpy as np\n", "\n", - "levels = np.zeros(len(b14.nodes), dtype=np.uint32) # store level for each node.\n", + "levels = np.zeros(len(b15.nodes), dtype=np.uint32) # array to store level for each node.\n", "\n", - "for n in b14.topological_order():\n", + "for n in b15.topological_order():\n", " if 'DFF' in n.kind or len(n.ins) == 0:\n", - " levels[n] = 0\n", + " levels[n] = 0 # use the node n directly to index into the array.\n", " elif n.kind == '__fork__':\n", " levels[n] = levels[n.ins[0].driver] # forks only have exactly one driver\n", " else:\n", @@ -891,33 +1239,33 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "depth: 112 node: __fork__ n2692 driving: SDFFARX1_RVT reg1_reg_29_ \n", - "depth: 112 node: NAND2X0_RVT U465 driving: __fork__ n2692 \n", - "depth: 112 node: NAND2X0_RVT U562 driving: __fork__ n2724 \n", - "depth: 112 node: __fork__ n2724 driving: SDFFARX1_RVT reg0_reg_29_ \n", - "depth: 112 node: __fork__ n2608 driving: SDFFARX1_RVT B_reg \n", - "depth: 112 node: NAND2X0_RVT U170 driving: __fork__ n2608 \n", - "depth: 111 node: NAND2X0_RVT U5550 driving: __fork__ n2693 \n", - "depth: 111 node: __fork__ n2660 driving: SDFFARX1_RVT reg2_reg_29_ \n", - "depth: 111 node: AND2X2_RVT U5560 driving: __fork__ n2660 \n", - "depth: 111 node: __fork__ n2725 driving: SDFFARX1_RVT reg0_reg_28_ \n", - "depth: 111 node: __fork__ n2693 driving: SDFFARX1_RVT reg1_reg_28_ \n", - "depth: 111 node: __fork__ n362 driving: NAND2X0_RVT U170 \n", - "depth: 111 node: NAND2X0_RVT U173 driving: __fork__ n362 \n", - "depth: 111 node: __fork__ n600 driving: NAND2X0_RVT U562 \n", - "depth: 111 node: NAND2X0_RVT U563 driving: __fork__ n600 \n", - "depth: 111 node: NAND2X0_RVT U565 driving: __fork__ n2725 \n", - "depth: 111 node: NAND2X0_RVT U466 driving: __fork__ n535 \n", - "depth: 111 node: __fork__ n535 driving: NAND2X0_RVT U465 \n", - "depth: 110 node: __fork__ n4691 driving: AND2X2_RVT U5560 \n", - "depth: 110 node: NAND2X0_RVT U5736 driving: __fork__ n790 \n" + "depth: 44 node: __fork__ n4587 driving: SDFFARX1_RVT EAX_reg_31_ \n", + "depth: 44 node: NAND2X0_RVT U737 driving: __fork__ n4587 \n", + "depth: 43 node: __fork__ n4478 driving: SDFFARX1_RVT Address_reg_29_\n", + "depth: 43 node: NAND2X0_RVT U738 driving: __fork__ n684 \n", + "depth: 43 node: __fork__ n4416 driving: SDFFARX1_RVT PhyAddrPointer_reg_29_\n", + "depth: 43 node: NAND2X0_RVT U220 driving: __fork__ n4416 \n", + "depth: 43 node: NAND2X0_RVT U214 driving: __fork__ n4414 \n", + "depth: 43 node: __fork__ n4414 driving: SDFFARX1_RVT PhyAddrPointer_reg_31_\n", + "depth: 43 node: __fork__ n684 driving: NAND2X0_RVT U737 \n", + "depth: 43 node: NAND2X0_RVT U408 driving: __fork__ n4478 \n", + "depth: 42 node: NAND2X0_RVT U216 driving: __fork__ n332 \n", + "depth: 42 node: __fork__ n4510 driving: SDFFARX1_RVT rEIP_reg_29_ \n", + "depth: 42 node: NAND2X0_RVT U595 driving: __fork__ n4540 \n", + "depth: 42 node: __fork__ n4540 driving: SDFFARX1_RVT EBX_reg_31_ \n", + "depth: 42 node: __fork__ n4588 driving: SDFFARX1_RVT EAX_reg_30_ \n", + "depth: 42 node: __fork__ n332 driving: NAND2X0_RVT U214 \n", + "depth: 42 node: NAND2X0_RVT U222 driving: __fork__ n337 \n", + "depth: 42 node: __fork__ n463 driving: NAND2X0_RVT U408 \n", + "depth: 42 node: __fork__ n4446 driving: SDFFARX1_RVT InstAddrPointer_reg_31_\n", + "depth: 42 node: NAND2X0_RVT U311 driving: __fork__ n4446 \n" ] } ], @@ -925,7 +1273,7 @@ "nodes_by_depth = np.argsort(levels)[::-1]\n", "\n", "for n_idx in nodes_by_depth[:20]:\n", - " n = b14.nodes[n_idx]\n", + " n = b15.nodes[n_idx] # get the node itself by its index\n", " readers = ', '.join([f'{l.reader.kind:12s} {l.reader.name:14s}' for l in n.outs])\n", " print(f'depth: {levels[n_idx]} node: {n.kind:12s} {n.name:6s} driving: {readers}')" ] @@ -958,7 +1306,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -970,7 +1318,7 @@ " 4:DFF\"cin\" <1 >0]" ] }, - "execution_count": 30, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -985,14 +1333,14 @@ "source": [ "We can construct a set of vectors using the `mvarray` helper function.\n", "\n", - "Each vector has 2 elements, one for each io_node and sequential element.\n", + "Each vector has 4 elements, one for each io_node and sequential element.\n", "\n", "This would be an exhaustive vector set (the output in `s_nodes` remains unassigned (\"-\")):" ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 38, "metadata": {}, "outputs": [ { @@ -1004,15 +1352,15 @@ " [0, 0, 0, 0, 3, 3, 3, 3]], dtype=uint8)" ] }, - "execution_count": 31, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "from kyupy.logic import mvarray\n", + "from kyupy import logic\n", "\n", - "inputs = mvarray('00-0', '10-0', '01-0', '11-0', '00-1', '10-1', '01-1', '11-1')\n", + "inputs = logic.mvarray('00-0', '10-0', '01-0', '11-0', '00-1', '10-1', '01-1', '11-1')\n", "inputs" ] }, @@ -1021,6 +1369,7 @@ "metadata": {}, "source": [ "The numeric values in this array are defined in `kyupy.logic`.\n", + "A logic-0 is stored as `0`, a logic-1 is stored as `3`, and 'unassigned' is stored as `2`.\n", "\n", "The **last** axis is always the number of vectors. It may be unintuitive at first, but it is more convenient for data-parallel simulations.\n", "\n", @@ -1029,7 +1378,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -1038,7 +1387,7 @@ "(4, 8)" ] }, - "execution_count": 32, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -1056,7 +1405,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -1075,63 +1424,61 @@ } ], "source": [ - "from kyupy.logic import mv_str\n", - "\n", - "print(mv_str(inputs))" + "print(logic.mv_str(inputs))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Load a stuck-at fault test pattern set and expected fault-free responses from a STIL file. It contains 1081 test vectors." + "Load a stuck-at fault test pattern set and expected fault-free responses from a STIL file. It contains 678 test vectors." ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "from kyupy import stil\n", "\n", - "s = stil.load('../tests/b14.stuck.stil.gz')\n", - "stuck_tests = s.tests(b14)\n", - "stuck_responses = s.responses(b14)" + "s = stil.load('../tests/b15_2ig.sa_nf.stil.gz')\n", + "stuck_tests = s.tests(b15)\n", + "stuck_responses = s.responses(b15)" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "306" + "528" ] }, - "execution_count": 35, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "len(b14.s_nodes)" + "len(b15.s_nodes)" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(306, 1081)" + "(528, 678)" ] }, - "execution_count": 36, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -1142,16 +1489,16 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(306, 1081)" + "(528, 678)" ] }, - "execution_count": 37, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -1162,44 +1509,44 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 45, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "00--------------------00101011101101111011100010101100----------------------------------00-11110011001100110001100110011000100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110110011001100110011001100110011001001100110011001100111000\n", - "P0--------------------11011111011001100111010101011101----------------------------------00-10111011010110011101110010111010111011101100010000110101111111011010101001010101010101010101001010110101001010101010101010110100000111111111111111011010100100101010010010101101010101001010100111010001010010000011100\n", - "P0--------------------00001101000101011100111111111111----------------------------------00-10000001000000010100000000000000110110110111111010101000101100101110001111101001110110100000110101001000100101000101010101001000011110110111111111000001111000010000101100010000100010100100011111101010001101000100011\n", - "P0--------------------11011111111110101011001111101111----------------------------------01-10000000000000000000000000000000001010011100110011010111011100010001110110011100101000011010101011111111111111111111111111111111011000011101010110111110010101100101010011100010001000010101010011010111100010100110111\n", - "P0--------------------00011111111110101001011001011111----------------------------------01-10000000001001010000000000000000111101001010000110000000010011010001100000010110001101100011010111000011011011010001000000000011111111111101000101011111111110000100101010000001010101011100000101001011010101010110001\n" + "------------------------------------------------------------------------------------------------------0----00--000110110011010011101101001011010010110100101101001001100110011001100110011001100011001100110011001100110011001110011001100110011001100110011001011101001011010010110100101101001011010010110100101101001011101100110011001101100110000010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011100110011001100110011001100110011111100001001011000100\n", + "--------------------------------------1100011011011111--------10111110--------------------------------P-00000--0101111000011010-01----110---110-110---110-11001100110-11101010011010-10-1010-1010101010-10-10-1010-10-10-10-101-10101010101010-10-10100-01010101011-01-11101110111011101-101-111011101-111011101-111010101000-10-1010-101010010-10011--0100-100110000111100001-111111-000011100000-101-01000011110-11-001000011111111-0001010100010001000----1----1-----1---11-----------00-101010101010-1010-1010101010101--10-1101010111111111\n", + "---------------------------------------1-1--1--1---1--1000100000000011--------------------------------P-10-00--11000001101111011---0--01-1111111111111111--1111110-111011111-111---11--11-1--1--------------------------------000000001---1----1--010-1-1---10010110011111110101001-0-0-0-1-0-1-0-011-0-1-000-1-001-1000101111111111111111111101111001101----1----------1-----------------------------------------------------1-11011100011111111-----111-----1-111-0-1-1----------------01------1------1-1-------------1--011-01011110011101111\n", + "------------------------------------------------------------------------------------------------------P111100--11011-0110000-10--0-----0--0-0-1-0-1-0-0-1---1-0-1-------0-01-11---0-0--00-0-00--------------------------------001100110000011000111110011000100--0011-------------1---------------------0-1-----1---1-1-1-1111111111111111101000100--001000011001-----1--111111--1--11--111--011---------------------------------0-------0-0---------------------------------------------00--------------------------------10-110-10010010-01010\n", + "--------------------------------------1011011111010000--------00101101--------------------------------P001100--10001010001111100-1-10101-1-1-1-1-1-1-1-1-101-1-1-100-000----0--00--1-0---------------------------------------------1--------------------------110-0--00001-0011001-001-0011001-0-0-010-001-1-0110101-1-1-0-100000000000011--1-11-1110-1----1--------------0--00---00-01---00-0----00-00---11-00--00000001011-0001-00-01---001001--11100---00-00---00-00---------1100-----01-------------0---------------0--11------0101000-10---\n" ] } ], "source": [ - "print(mv_str(stuck_tests[:,:5]))" + "print(logic.mv_str(stuck_tests[:,:5]))" ] }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 46, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "--11001100110011001100--------------------------------0011001100110011001100110011001110--011110011001100110001100110011000100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110110011001100110011001100110011001001100110011001100111000\n", - "--10000010010100010111--------------------------------0101010010101010110101001001010100--011111110011011111000111010101010111011101100010000110101111111011010101001010101010101010101001010110101001010101010101010110100000111111111111111011010100100101010010010101101010101001010101000111111111111111011101\n", - "--01000101100010101111--------------------------------1000100101000100001000110100001010--001000001111111101000000000000000110110110111111010101000101100101110001111101001110110100000110101001000100101000101010101001000011001110111111111000001111000010000101100010000100010100100011111000111110100111000010\n", - "--11001010001111010110--------------------------------1010101000010001000111001010100101--110000000000000000000000000000000001010011100110011010111011100010001110110011100101000011010101000000000000000000000000000000000011100011101010110111110010100100101010011100010001000010101010011010111100010100110000\n", - "--11010101010110100101--------------------------------0000111010101010000001010100100000--001000000001110101100000000000000111101001010000110000000010011010001100000010110001101100011010111000011011011010001000000000011111000000011000101011111111110000100101010000001010101011100001000110000001011000111000\n" + "11001100110011001100110011001100110000--------------------------------01001100110011001100110011001100--------0000110110011010011101101001011010010110100101101001001100110011001100110011001100011001100110011001100110011001110011001100110011001100110011001011101001011010010110100101101001011010010110100101101001011101100110011001101100110000010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011100110011001100110011001100110011111100001001011000100\n", + "X0101010101010101X0101X01010101010XX11--------------------------------001X01X01X01X0101X01X01X01010101--------X0001010110000010X01XXXX110XXX110X110XXX110X11001100110X11101010011010X10X1010X1010101010X10X10X1010X10X10X10X101X10101010101010X10X10100X01010101110X00X01000100010001000X000X010001000X010001000X010000000000X10X1010X101010010X10001XX0100X100110000111100001X111111X000011100000X101X01000011110X11X001000011111111X00010101000100010001111011011110110110000011001110101X101010101010X1010X10101010101011X1001101010111111111\n", + "1X11XX1XXXXXXXXXXXXX1X1XXXXXX1XXXX1X1X--------------------------------0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--------101010001101110010011111100000000000000000011000000110000000001000110000000001000XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX000000001XXX1XXXX1XX010X1X1XXX10110110011111110101001X0X0X0X1X0X1X0X011X0X1X000X1X001X1000101000000000000000000011111001010XXXX1XXXXXXXXXX1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1X11011100011111111XXXXX111XXXXX1X111X0X1X1XXXXXXXXXXXXXXXX0110000100100010100101001011011001100100101100001110101\n", + "0101XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0X0X--------------------------------0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--------011011X11100000000X0XXXXX0XX0X0X1X0X1X0X0X1XXX1X0X1XXXXXXX0X01X11XXX0X0XX00X0X00XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX011100110000011000111110011000100XX0011XXXXXXXXXXXXX1XXXXXXXXXXXXXXXXXXXXX0X1XXXXX1XXX1X1X1X1111111111111111101000100XX001000011001XXXXX1XX111111XX1XX11XX111XX011XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XXXXXXX0X0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX10X1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX101110010110110X01010\n", + "1XXXXX0XXXXXXXXXXXXXXX0XXXXXXXXXXX1XXX--------------------------------0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--------100011001101001100X1X10101X1X1X1X1X1X1X1X1X101X1X1X100X000XXXX0XX00XX1X0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXXXXXXXXXXXXXXXXXXXXXXXX110X0XX00101X0011001X001X0011001X0X0X010X001X1X0110101X1X1X0X100000000000011XX1X11X1110X1XX1000101111100010X0XX00XXX00X01XXX00X0XXXX00X00XXX11X00XX00000001011X0001X00X01XXX001001XX11100XXX00X00XXX00X00XX01101100011011001011XXXXXXXXXXX0XXXXXXXXXXXXXXX0XX010X1X1X0101000X10XXX\n" ] } ], "source": [ - "print(mv_str(stuck_responses[:,:5]))" + "print(logic.mv_str(stuck_responses[:,:5]))" ] }, { @@ -1211,62 +1558,110 @@ "\n", "`stuck_tests` has values for all primary inputs and scan flip-flops, `stuck_responses` contains the expected values for all primary outputs and scan flip-flops.\n", "\n", - "Since this is a static test, only '0' and '1' are used with the exception of the clock input, which has a positive pulse 'P'.\n", + "Since this is a static test, only '0', '1' and 'X' are used with the exception of the clock input, which has a positive pulse 'P'.\n", "\n", "A transition fault test is a dynamic test that also contains 'R' for rising transition and 'F' for falling transition:" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ - "s = stil.load('../tests/b14.transition.stil.gz')\n", - "transition_tests = s.tests_loc(b14)\n", - "transition_responses = s.responses(b14)" + "s = stil.load('../tests/b15_2ig.tf_nf.stil.gz')\n", + "transition_tests = s.tests_loc(b15)\n", + "transition_responses = s.responses(b15)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "STIL files for delay tests usually only contain the initialization patterns.\n", + "When loading launch-on-capture transition fault tests, use `.tests_loc()`. This function performs a logic simulation of the launch cycle to calculate the transitions for the delay test itself." ] }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 48, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "XX--------------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX----------------------------------XX-11110011001100110001100110011000100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110110011001100110011001100110011001001100110011001100111000\n", - "00--------------------RRRRRRFRRRRRRRRRRRFFRFRRRRRRRRRR----------------------------------00-00000001110100011111011010000000000000000011001001100101111110101110110001000100010100110111111101101000000111110011100010111000111R1111111111111111111111110001100100000110100000111010101110RFF00F000F0F00F00000FF01F\n", - "00--------------------11R111110R0RR0R1110R01R1R001FRRR----------------------------------0F-RR0R00000000RR11R0RRR000R0R000R0010100010001011000111001000010001010111010101010100000000100001011100100001100011110110100000010011000011111100010111100010010111110100011100100011010000010111F11F0F01RRR110F0R01R011R\n", - "00--------------------RRFRRFR100FR10R010F10FR1111F111R----------------------------------0R-F01R0F01F100R01FF1F10R101FR1RR1R01001110010101110110000000100101111101001110100010011111111110100010001000100110100001111110011001001011011010111111111111111F10110101001010001001000001011001R0RF0R0R1FRR0RFR1RRRR101R\n", - "00--------------------FFR1RRF11FFRRR1R0FR100FF1R0FRFFF----------------------------------01-111FRRFF0RRRRRF01FFFRFRFFRRRFFRR11110100111100111000011001000111111000100011010000010000011111011111111110110111100100110001001111111000111111111000011101111000010010101000000101010101110000R1R1RRF001R1R1R1R10FF001R\n" + "------------------------------------------------------------------------------------------------------X----XX--000110110011010011101101001011010010110100101101001001100110011001100110011001100011001100110011001100110011001110011001100110011001100110011001011101001011010010110100101101001011010010110100101101001011101100110011001101100110000010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011100110011001100110011001100110011111100001001011000100\n", + "--------------------------------------RFRRRRFRRFRRRR1R--------RXXRXRRR--------------------------------00F0F00--RR1RRXRF00011010XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX011X00XXX101X1X1X1X1X1X1X1X1X1X1X1X1X1X1X1X1X1X1X1X1X0XXXXXXX1XXXXXXXXXXXXXXXXXXXXXXXXRRXRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX00000000000000000111111000001001RFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX11XXXXX\n", + "--------------------------------------1X111XX11X1XX1X11XX11XX111X11X11--------------------------------0-XXR00--F1FF1X0110011X01XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXFXX1XFFX1XFXFXFXFXFXFXFXFXFXFXFXFXFXFXFXFXFXFXFXFXFX0XFXFXFXF11110XX1XX1XXXXXXX1XXXX1XFR1F1XXXXXXXXXXXXXXXXX011101111000101101110111110001001000100010101011011001110111000X1XX11XXXXXXXX11XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX000X011111111111111111111111111111R0F1R0R001RR100FF1XXX\n", + "--------------------------------------------------------------XXXXXXXX--------------------------------0--FX00--F11F1XFRR00R01111XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX1XXXXXRX1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX111111111111111111111110X0XX10XXXXXXXXXRXXXRXRF1FFFRFRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXXXXXXXXXXX0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX11X1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX011001010010111111111\n", + "--------------------------------------------------------------FFXFFFFF--------------------------------0XXRR00--RF01FXRF00001XX1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX010X010111111111X111111111111111X11100XX0101XXXXXX01XXXX01XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1X1111X110111111XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0RXRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXXXX\n" ] } ], "source": [ - "print(mv_str(transition_tests[:,:5]))" + "print(logic.mv_str(transition_tests[:,:5]))" ] }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "11001100110011001100110011001100110000--------------------------------01001100110011001100110011001100--------0000110110011010011101101001011010010110100101101001001100110011001100110011001100011001100110011001100110011001110011001100110011001100110011001011101001011010010110100101101001011010010110100101101001011101100110011001101100110000010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011100110011001100110011001100110011111100001001011000100\n", + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1--------------------------------0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--------X01001X0110000010XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX011X00XXX000X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X1XXXXXXX1XXXXXXXXXXXXXXXXXXXXXXXX11X1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1111111111111111100000011111011010X1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0X0X0X1XXXXXXX11XXXXX\n", + "0100111111111111111111111111111110101X--------------------------------0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--------101011X0110011001000X0X0X1X0X0X1X0X0X0X1X1X0X0X1X1X010110100110001XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX1X00X1X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X000001XX1XX1XXXXXXX1XXXX1X01000XXXXXXXXXXXXXXXXX011101111000101101110111110001001000100010101011011001110111000X1XX11XXXXXXXX11XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0010100000000000000000000000000000111011011000000010XXX\n", + "1011XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX01--------------------------------0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--------X00101X01100100010XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX1XXXXX1X1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX000000000000000000000001X0XX11XXXXXXXX0100010101000101XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXXXXXXXXXXX0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX11101XXXXXXXXXXXXXXXXXXXXXXXXXXXXX001100000100001110100\n", + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1--------------------------------0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--------X01000X1100101XX1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX000X0011000000000000000000000000000011XX1111XXXXXX11XXXX11XXXXXXXXXXXXXXXXXXXXXXXXXXXX11X1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0100000001000000XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX01X1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1X0X0X1XXXXXXXX0XXXXX\n" + ] + } + ], + "source": [ + "print(logic.mv_str(transition_responses[:,:5]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Initialization patterns and launch patterns can be filtered by providing a call-back function. This can be used to fill in unassigned values." + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [], + "source": [ + "def zero_fill(mva):\n", + " return np.choose(mva, logic.mvarray('0X01PRFN')) # maps '0X-1PRFN' -> '0X01PRFN'\n", + "\n", + "transition_tests_zf = s.tests_loc(b15, init_filter=zero_fill, launch_filter=zero_fill)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "--11001100110011001100--------------------------------0011001100110011001100110011001110--011110011001100110001100110011000100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110110011001100110011001100110011001001100110011001100111000\n", - "--00000000000000000000--------------------------------0111010101110000010110000010011010--011111111111110111111100101111111000000000011001001100101111110101110110001000100010100110111111101101000000111110011100010111000111111111111111111111111111100011001000001101000001110101011101111111111111111111110011\n", - "--11010001111110000110--------------------------------1101000001011000100111000101111110--000010111111100000100011101011100010100010001011000111001000010001010111010101010100000000100001011100100001100011110110100000010011100011111100010111100010010111110100011100100011010000010110011000011111100010111110\n", - "--11111101011011010010--------------------------------1001101000001001000101001010110110--000110001010010100101011010111111101101001011001110000000000001001111010011101000100111111111101000100010001001101000011111100110010110110110101111111111111110101101010010100010010000010110010010010110110101111111010\n", - "--00011111111100011111--------------------------------0000111010101010000001010100100010--000011011100000110111010110001100000100110000110011111001101111001110001000110100000100000111110111111111101101111001001100010011111001001111111110000111011110000100101010000001010101011100001100101100011010110110010\n" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110110011010011101101001011010010110100101101001001100110011001100110011001100011001100110011001100110011001110011001100110011001100110011001011101001011010010110100101101001011010010110100101101001011101100110011001101100110000010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011100110011001100110011001100110011111100001001011000100\n", + "00000000000000000000000000000000000000RFRRRRFRRFRRRR1R00000000RRRRRRRR0000000000000000000000000000000000F0F0000RR1RR0RF00011010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001100000010101010101010101010101010101010101010101010000000001000000000000000000000000RR0R000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111000001001RF0R000000000000000000000000000000R00000R00000001100000\n", + "00000000000000000000000000000000000000101110011010010110011001110110110000000000000000000000000000000000R0R0000F1FF1001100110010RR0R0R000R0R000R0R0R00000R0R00000R0R00R0RR00RRR0000000000000000000000000000000000000000000000000000000000000000000000000000000F0010FF010F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F000F0F0F0F1111000100100000001000010FR1F1000000000000000000111011110001011011101111100010010001000101010110110011101110000100110000000011000000000000000000000000000000000000011111111111111111111111111111R0F1R0R001RR100FF1000\n", + "000000000000000000000000000000000000000000000000000000000000000FF00F0000000000000000000000000000000000000F00000F11F10FRR00R01111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000R010000000000000000000000000000000000000000000000000111111111111111111111110000010000000000R000R0RF1FFFRFR000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001101000000000000000000000000000000011001010010111111111\n", + "00000000000000000000000000000000000000000000000000000000000000FFRFFFFF00000000000000000000000000000000000RR0000RF01F0RF00001001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000101111111110111111111111111011100000101000000010000010000000000000000000000000000RR0R0000000000000000000000000000000000000000000000000000000000000000000000000101111011011111100000000000000000000000000000000000000000R0R000000000000000000000000000000R0R000R00000001000000\n" ] } ], "source": [ - "print(mv_str(transition_responses[:,:5]))" + "print(logic.mv_str(transition_tests_zf[:,:5]))" ] }, { @@ -1283,27 +1678,25 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 52, "metadata": {}, "outputs": [], "source": [ - "from kyupy.logic import mv_to_bp, bp_to_mv\n", - "\n", - "stuck_tests_bp = mv_to_bp(stuck_tests)" + "stuck_tests_bp = logic.mv_to_bp(stuck_tests)" ] }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 53, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(306, 3, 136)" + "(528, 3, 85)" ] }, - "execution_count": 44, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -1316,29 +1709,29 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Instead of 1081 bytes per s_node, bit-parallel storage only uses 3*136=408 bytes.\n", + "Instead of 678 bytes per s_node, bit-parallel storage only uses 3*85=255 bytes.\n", "\n", "The reverse operation is `bp_to_mv`. Note that the number of vectors may be rounded up to the next multiple of 8:" ] }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 54, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(306, 1088)" + "(528, 680)" ] }, - "execution_count": 45, + "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "bp_to_mv(stuck_tests_bp).shape" + "logic.bp_to_mv(stuck_tests_bp).shape" ] }, { @@ -1347,44 +1740,44 @@ "source": [ "## Logic Simulation\n", "\n", - "The following code performs a 8-valued logic simulation on all 1081 vectors for one clock cycle." + "The following code performs a 8-valued logic simulation on all 678 vectors for one clock cycle." ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 55, "metadata": {}, "outputs": [], "source": [ "from kyupy.logic_sim import LogicSim\n", "\n", - "sim = LogicSim(b14, sims=stuck_tests.shape[-1]) # 1081 simulations in parallel\n", + "sim = LogicSim(b15, sims=stuck_tests.shape[-1]) # 678 simulations in parallel\n", "sim.s[0] = stuck_tests_bp\n", "sim.s_to_c()\n", "sim.c_prop()\n", "sim.c_to_s()\n", - "sim_responses = bp_to_mv(sim.s[1])[...,:stuck_tests.shape[-1]] # trim from 1088 -> 1081" + "sim_responses = logic.bp_to_mv(sim.s[1])[...,:stuck_tests.shape[-1]] # trim from 680 -> 678" ] }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 56, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "--11001100110011001100--------------------------------0011001100110011001100110011001110--000110110110111010111011100010100100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110110011001100110011001100110011001100110011001100110011001\n", - "--10000010010100010111--------------------------------0101010010101010110101001001010100--011111110011011111000111010101010111011101100010000110101111111011010101001010101010101010101001010110101001010101010101010110100000111111111111111011010100100101010010010101101010101001010101000111111111111111011101\n", - "--01000101100010101111--------------------------------1000100101000100001000110100001010--001000001111111101000000000000000110110110111111010101000101100101110001111101001110110100000110101001000100101000101010101001000011001110111111111000001111000010000101100010000100010100100011111000111110100111000010\n", - "--11001010001111010110--------------------------------1010101000010001000111001010100101--110000000000000000000000000000000001010011100110011010111011100010001110110011100101000011010101000000000000000000000000000000000011100011101010110111110010100100101010011100010001000010101010011010111100010100110000\n", - "--11010101010110100101--------------------------------0000111010101010000001010100100000--001000000001110101100000000000000111101001010000110000000010011010001100000010110001101100011010111000011011011010001000000000011111000000011000101011111111110000100101010000001010101011100001000110000001011000111000\n" + "11001100110011001100110011001100110000--------------------------------01001100110011001100110011001100--------010X110XXX011010011101101001011010010110100101101001001100110011001100110011001100011001100110011001100110011001110011001100110011001100110011001011101001011010010110100101101001011010010110100101101001011101100110011001101100110000010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011100110011001100110011001100110011111100001001011000100\n", + "-0101010101010101-0101-01010101010--11--------------------------------001-01-01X01-0101-01-01-01010101---------0001010110000010X01XXXX110XXX110X110XXX110X11001100110X11101010011010X10X1010X1010101010X10X10X1010X10X10X10X101X10101010101010X10X10100X01010101110X00X01000100010001000X000X010001000X010001000X010000000000X10X1010X101010010X10001XX0100X100110000111100001X111111X000011100000X101X01000011110X11X001000011111111X00010101000100010001111011011110110110000011001110101X101010101010X1010X10101010101011X1001101010111111111\n", + "1-11--1-------------1-1------1----1-1---------------------------------0--------X------------------------------101010001101110010011111100000000000000000011000000110000000001000110000000001000XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX000000001XXX1XXXX1XX010X1X1XXX10110110011111110101001X0X0X0X1X0X1X0X011X0X1X000X1X001X1000101000000000000000000011111001010XXXX1XXXXXXXXXX1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1X11011100011111111XXXXX111XXXXX1X111X0X1X1XXXXXXXXXXXXXXXX0110000100100010100101001011011001100100101100001110101\n", + "0101------------------------------0-0---------------------------------0--------X------------------------------011011X11100000000X0XXXXX0XX0X0X1X0X1X0X0X1XXX1X0X1XXXXXXX0X01X11XXX0X0XX00X0X00XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX011100110000011000111110011000100XX0011XXXXXXXXXXXXX1XXXXXXXXXXXXXXXXXXXXX0X1XXXXX1XXX1X1X1X1111111111111111101000100XX001000011001XXXXX1XX111111XX1XX11XX111XX011XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XXXXXXX0X0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX10X1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX101110010110110X01010\n", + "1-----0---------------0-----------1-----------------------------------0--------X------------------------------100011001101001100X1X10101X1X1X1X1X1X1X1X1X101X1X1X100X000XXXX0XX00XX1X0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXXXXXXXXXXXXXXXXXXXXXXXX110X0XX00101X0011001X001X0011001X0X0X010X001X1X0110101X1X1X0X100000000000011XX1X11X1110X1XX1000101111100010X0XX00XXX00X01XXX00X0XXXX00X00XXX11X00XX00000001011X0001X00X01XXX001001XX11100XXX00X00XXX00X00XX01101100011011001011XXXXXXXXXXX0XXXXXXXXXXXXXXX0XX010X1X1X0101000X10XXX\n" ] } ], "source": [ - "print(mv_str(sim_responses[:,:5]))" + "print(logic.mv_str(sim_responses[:,:5]))" ] }, { @@ -1395,27 +1788,31 @@ "\n", "The first test fails, because it is a flush test while simulation implicitly assumes a standard test with a capture clock.\n", "\n", - "The remaining 1080 responses are identical." + "The remaining 677 responses should be compatible.\n", + "\n", + "The following checks for compatibility (unknown/unassigned values in STIL always match)." ] }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 57, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "1080" + "677" ] }, - "execution_count": 48, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "np.sum(np.min(sim_responses == stuck_responses, axis=0))" + "np.sum(np.min((sim_responses == stuck_responses) | \n", + " (stuck_responses == logic.UNASSIGNED) | \n", + " (stuck_responses == logic.UNKNOWN), axis=0))" ] }, { @@ -1427,37 +1824,37 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 58, "metadata": {}, "outputs": [], "source": [ - "sim = LogicSim(b14, sims=transition_tests.shape[-1]) # 1392 simulations in parallel\n", - "sim.s[0] = mv_to_bp(transition_tests)\n", + "sim = LogicSim(b15, sims=transition_tests_zf.shape[-1]) # 1147 simulations in parallel\n", + "sim.s[0] = logic.mv_to_bp(transition_tests_zf)\n", "sim.s_to_c()\n", "sim.c_prop()\n", "sim.c_to_s()\n", - "sim_responses = bp_to_mv(sim.s[1])[...,:transition_tests.shape[-1]] # trim to 1392" + "sim_responses = logic.bp_to_mv(sim.s[1])[...,:transition_tests_zf.shape[-1]] # trim to 1147" ] }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 59, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "--11001100110011001100--------------------------------0011001100110011001100110011001110--0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110110011001100110011001100110011001100110011001100110011001\n", - "--F00000F00F0F000F00FF--------------------------------01110101011100000101100000100110R0--0RRRRRRRNNNRNRPRNNNNNRFFRFRRRRRRR000000000011001001100101111110101110110001000100010100110111111101101000000111110011100010111000NNNNNNNNNNNNNNNNNNNNNNNNNNNNP0011001000001101000001110101011101RRRRRRRRRRRRRRRRRRRRP01R\n", - "--R10R0F011RRR10F0F11F--------------------------------1101000001011000100111000101111110--0FFPNPRRRRRRRFFFFFRFFFRRRFRFRRRFPPNPNPPPNPPPNPNNPPPNNNPPNPPPPNPPPNPNPNNNPNPNPNPNPNPPPPPPPPNPPPPNPNNNPPNPPPPNNPPPNNNNPNNPNPPPPPPNPPNNRPPPNNNNNNPPPNPNNNNPPPNPPNPNNNNNPNPPPNNNPPNPPPNNPNP0P00N0NNFPNNPPPPNNNNNNPPPNPNNRNNF\n", - "--RRRR1RFR0RRF1R0R0FR0--------------------------------10011010000010010001010010101101RF--FPPNNPPPNPNPPNPNPPNPNPNNPNPNNNNNNRFRRFNFPRFRNPFNNRFFPPPPPPPFPPNPFNNNNPNPPNNNPNPPPNPPNNNNNNNNNNPNPPPNPPPNPPPNPPNNPNPPPPNNNNNNPPNNPPNPRNPNNPNNPNPNNNNNNNNNNNNNNNPNPNNPNPNPPNPNPPPNPPNPPPPPNPNNPPNFPNPPNPNNPNNPNPNNNNNNNPNF\n", - "--FF01R1R1R1R100FRR1R1--------------------------------00001110101010100000010101001000R0--0FFFRNFRRRFFFFFRRFRRRFRFRRFFFRRFFFFFNPFRRFFFFRRFFNRRRRFFRRFRRRNFFNNNPPPNPPPNNPNPPPPPNPPPPPNNNNNPNNNNNNNNNNPNNPNNNNPPNPPNNPPPNPPNNNNNFFRPPNNNNNNNNNPPPPNNNPNNNNPPPPNPPNPN0NP0PPPPN0N0NPN0NNNPPPPNNFFNFRRPFFNNFNFNNPRRPPNF\n" + "11001100110011001100110011001100110000--------------------------------01001100110011001100110011001100--------0100110001011010011101101001011010010110100101101001001100110011001100110011001100011001100110011001100110011001110011001100110011001100110011001011101001011010010110100101101001011010010110100101101001011101100110011001101100110000010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011100110011001100110011001100110011111100001001011000100\n", + "0000000000000000000000000000000000000R--------------------------------00000000000000000000000000000000--------0FNFFNPFRR0PFF01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000NNP0PP00F0FPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPF0F0F0F0FPRP0P0P0PN000000000000000000000000NNPNP000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000RRRRRRRRRRRRRRRRRFFFFFFRRRRRFRRFNPPNP00000000000000000000000000000FPP000NP0000P0NN00000\n", + "01001111111111111111111111111111101010--------------------------------00000000000000000000000000000000--------1PNPRN0PNN0011001PFF0F0F0R0F0F0R0F0F0F0R0R0F0F0R0R0FRFRRFRFFRRFFFR000000000000000PP0PP0PPP00PP00P00000000000000000000000000000000000000000000000P00N0PP0N0P0P0P0P0P0P0P0P0P0P0P0P0P0P0P0P0P0P0P0P0P000P0P0P0PFFFFR00N00N0000000N0000N0PNFPF00000000000000000011101111000101101110111110001001000100010101011011001110111000010011000000001100000000000000000000000000000000PPRPRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFNRRFNRFRRFFFFP0PRF000\n", + "10110000000000000000000000000000000001--------------------------------00000000000000000000000000000000--------0PFNP1PPNNPPNPFFNF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000PPPNP00PPNPNPPP0P0P0P0P0P0P0P0P0P0P0P0P0P0P000000000000000000FFFFFFFFFFFFFFFFFFFFFFFR0PPRNR000000000N000N0NPNPPPNPN0P000P0P0P000P0P0P000P0P0P000P0P0P000P0P0PN00P0P0000000000000000000000000000000000000000000000000000000011RFR000000000000000000000000000000F1R0F0F0RFPFFNNNFNFF\n", + "0000000000000000000000000000000000000R--------------------------------00000000000000000000000000000000--------0FRPFPPNRP0RPN00N00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F00PFRNFFFFFFFFPFFFFFFFFFFFFFFFPFFFRRP0RNRN000000RN0000RN000PP0PPPPPPP0P0000000000000NN0N0000000000000000000000000000000000000000000000000000000000000000000000000FRFFFFPFFRFFFFFFPPPPPPPPPPPPPPPP0000000000000000000000000N0N000000000000000000000000000000N0F000N00000PPF00PP00\n" ] } ], "source": [ - "print(mv_str(sim_responses[:,:5]))" + "print(logic.mv_str(sim_responses[:,:5]))" ] }, { @@ -1471,51 +1868,57 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 60, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "--11001100110011001100--------------------------------0011001100110011001100110011001110--0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110110011001100110011001100110011001100110011001100110011001\n", - "--00000000000000000000--------------------------------0111010101110000010110000010011010--011111111111110111111100101111111000000000011001001100101111110101110110001000100010100110111111101101000000111110011100010111000111111111111111111111111111100011001000001101000001110101011101111111111111111111110011\n", - "--11010001111110000110--------------------------------1101000001011000100111000101111110--000010111111100000100011101011100010100010001011000111001000010001010111010101010100000000100001011100100001100011110110100000010011100011111100010111100010010111110100011100100011010000010110011000011111100010111110\n", - "--11111101011011010010--------------------------------1001101000001001000101001010110110--000110001010010100101011010111111101101001011001110000000000001001111010011101000100111111111101000100010001001101000011111100110010110110110101111111111111110101101010010100010010000010110010010010110110101111111010\n", - "--00011111111100011111--------------------------------0000111010101010000001010100100010--000011011100000110111010110001100000100110000110011111001101111001110001000110100000100000111110111111111101101111001001100010011111001001111111110000111011110000100101010000001010101011100001100101100011010110110010\n" + "11001100110011001100110011001100110000--------------------------------01001100110011001100110011001100--------0100110001011010011101101001011010010110100101101001001100110011001100110011001100011001100110011001100110011001110011001100110011001100110011001011101001011010010110100101101001011010010110100101101001011101100110011001101100110000010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011100110011001100110011001100110011111100001001011000100\n", + "00000000000000000000000000000000000001--------------------------------00000000000000000000000000000000--------0010010011000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000010000000100000000000000000000000011010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111110000001111101101001000000000000000000000000000000000000100000001100000\n", + "01001111111111111111111111111111101010--------------------------------00000000000000000000000000000000--------1010110011001100100000000100000100000001010000010100101101001100010000000000000000000000000000000000000000000000000000000000000000000000000000000001000010000000000000000000000000000000000000000000000000000000010010010000000100001001000000000000000000000111011110001011011101111100010010001000101010110110011101110000100110000000011000000000000000000000000000000000010100000000000000000000000000000111011011000000010000\n", + "10110000000000000000000000000000000001--------------------------------00000000000000000000000000000000--------0001010011001000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000001010000000000000000000000000000000000000000000000000000000000000000000000001000111000000000100010101000101000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001110100000000000000000000000000000001100000100001110100\n", + "00000000000000000000000000000000000001--------------------------------00000000000000000000000000000000--------0010000110010100100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001100000000000000000000000000001100111100000011000011000000000000000000000000000011010000000000000000000000000000000000000000000000000000000000000000000000000010000000100000000000000000000000000000000000000000000000101000000000000000000000000000000100000100000000000000\n" ] } ], "source": [ - "sim_responses_final = np.choose(sim_responses, mvarray('0X-10101')) # '0X-1PRFN'\n", - "print(mv_str(sim_responses_final[:,:5]))" + "sim_responses_final = np.choose(sim_responses, logic.mvarray('0X-10101')) # maps '0X-1PRFN' -> '0X-10101'\n", + "print(logic.mv_str(sim_responses_final[:,:5]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Again, first test is a flush test, so we expect 1391 matches." + "Again, first test is a flush test, so we expect 1146 matches.\n", + "\n", + "We simulated zero-filled patterns and therefore have more specified output bits.\n", + "\n", + "The following checks for compatability (unknown/unassigned values in STIL always match)." ] }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "1391" + "1146" ] }, - "execution_count": 52, + "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "np.sum(np.min(sim_responses_final == transition_responses, axis=0))" + "np.sum(np.min((sim_responses_final == transition_responses) | \n", + " (transition_responses == logic.UNASSIGNED) | \n", + " (transition_responses == logic.UNKNOWN), axis=0))" ] }, { @@ -1534,14 +1937,14 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 62, "metadata": {}, "outputs": [], "source": [ "from kyupy import sdf\n", "\n", - "df = sdf.load('../tests/b14.sdf.gz')\n", - "lt = df.annotation(b14, dataset=0, interconnect=False)" + "df = sdf.load('../tests/b15_2ig.sdf.gz')\n", + "delays = df.annotation(b15, dataset=0, interconnect=False)" ] }, { @@ -1553,22 +1956,22 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(46891, 2, 2)" + "(32032, 2, 2)" ] }, - "execution_count": 54, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "lt.shape" + "delays.shape" ] }, { @@ -1580,22 +1983,22 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "120628" + "78296" ] }, - "execution_count": 55, + "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "(lt != 0).sum()" + "(delays != 0).sum()" ] }, { @@ -1617,14 +2020,13 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 65, "metadata": {}, "outputs": [], "source": [ "from kyupy.wave_sim import WaveSimCuda, TMAX\n", - "import numpy as np\n", "\n", - "wsim = WaveSimCuda(b14, lt, sims=32, c_caps=16)" + "wsim = WaveSimCuda(b15, delays, sims=32, c_caps=16)" ] }, { @@ -1636,18 +2038,18 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 66, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Waveforms : 93908.5 kiB\n", - "State Allocation Table : 1113.4 kiB\n", - "Circuit Timing : 1484.5 kiB\n", - "Circuit Netlist : 1099.0 kiB\n", - "Sequential State : 420.8 kiB\n" + "Waveforms : 64293.5 kiB\n", + "State Allocation Table : 129.3 kiB\n", + "Circuit Timing : 1034.1 kiB\n", + "Circuit Netlist : 750.8 kiB\n", + "Sequential State : 726.0 kiB\n" ] } ], @@ -1656,8 +2058,8 @@ " print(f'{name}: {arr.nbytes / 1024:.1f} kiB')\n", " \n", "print_mem('Waveforms ', wsim.c)\n", - "print_mem('State Allocation Table ', wsim.vat)\n", - "print_mem('Circuit Timing ', wsim.timing)\n", + "print_mem('State Allocation Table ', wsim.c_locs)\n", + "print_mem('Circuit Timing ', wsim.delays)\n", "print_mem('Circuit Netlist ', wsim.ops)\n", "print_mem('Sequential State ', wsim.s)" ] @@ -1667,158 +2069,168 @@ "metadata": {}, "source": [ "This is a typical simulation loop where the number of patterns is larger than the number of simulators available.\n", - "We simulate `trans_tests_bp`.\n", - "The timing simulator accepts 8-valued `BPArray`s, but it will return response (capture) data in a different format." + "We simulate `transition_tests_zf`.\n", + "The initial values, transition times and final values are loaded into `wsim.s` and the following three calls will update this array with simulation results. We collect all results in `wsim_results`." ] }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 67, "metadata": {}, "outputs": [], "source": [ - "sims = 128 # trans_tests.shape[-1] # Feel free to simulate all tests if CUDA is set up correctly.\n", + "from kyupy import batchrange\n", + "import numpy as np\n", "\n", - "cdata = np.zeros((len(wsim.interface), sims, 7)) # space to store all capture data\n", + "sims = 128 # transition_tests_zf.shape[-1] # Feel free to simulate all tests if CUDA is set up correctly.\n", "\n", - "for offset in range(0, sims, wsim.sims):\n", - " wsim.assign(trans_tests_bp, offset=offset)\n", - " wsim.propagate(sims=sims-offset)\n", - " wsim.capture(time=2.5, cdata=cdata, offset=offset) # capture at time 2.5" + "wsim_results = np.zeros((11, wsim.s_len, sims)) # space to store all simulation results\n", + "\n", + "for offset, size in batchrange(sims, wsim.sims):\n", + " wsim.s[0] = (transition_tests_zf[:,offset:offset+size] >> 1) & 1 # initial value\n", + " wsim.s[1] = 0.0 # transition time\n", + " wsim.s[2] = transition_tests_zf[:,offset:offset+size] & 1 # final value\n", + " wsim.s_to_c()\n", + " wsim.c_prop(sims=size)\n", + " wsim.c_to_s(time=1.5) # capture at time 1.5\n", + " wsim_results[:,:,offset:offset+size] = wsim.s[:,:,:size]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The capture data contains for each PI, PO, and scan flip-flop (axis 0), and each test (axis 1) seven values:\n", - "\n", - "0. Probability of capturing a 1 at the given capture time (same as next value, if no standard deviation given).\n", - "1. A capture value decided by random sampling according to above probability.\n", - "2. The final value (assume a very late capture time).\n", - "3. True, if there was a premature capture (capture error), i.e. final value is different from captured value.\n", - "4. Earliest arrival time. The time at which the output transitioned from its initial value.\n", - "5. Latest stabilization time. The time at which the output transitioned to its final value.\n", - "6. Overflow indicator. If non-zero, some signals in the input cone of this output had more transitions than specified in `wavecaps`. Some transitions have been discarded, the final values in the waveforms are still valid." + "The arrays `wsim.s` and `wsim_results` contain various information for each PI, PO, and scan flip-flop (axis 1), and each test (axis 2):\n", + "* ``s[0]`` (P)PI initial value\n", + "* ``s[1]`` (P)PI transition time\n", + "* ``s[2]`` (P)PI final value\n", + "* ``s[3]`` (P)PO initial value\n", + "* ``s[4]`` (P)PO earliest arrival time (EAT): The time at which the output transitioned from its initial value.\n", + "* ``s[5]`` (P)PO latest stabilization time (LST): The time at which the output settled to its final value.\n", + "* ``s[6]`` (P)PO final value\n", + "* ``s[7]`` (P)PO capture value: probability of capturing a 1 at a given capture time\n", + "* ``s[8]`` (P)PO sampled capture value: decided by random sampling according to a given seed.\n", + "* ``s[9]`` (P)PO sampled capture slack: (capture time - LST) - decided by random sampling according to a given seed.\n", + "* ``s[10]`` Overflow indicator: If non-zero, some signals in the input cone of this output had more\n", + " transitions than specified in ``c_caps``. Some transitions have been discarded, the\n", + " final values in the waveforms are still valid." ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 68, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(306, 128, 7)" + "(11, 528, 128)" ] }, - "execution_count": 40, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "cdata.shape" + "wsim_results.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "For validating against known logic values, take `cdata[...,1]`." + "For validating against known logic values, convert the samples capture values `wsim_results[8]` into an mvarray like this:" ] }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 69, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "mismatch for test pattern 0\n", - "127 of 128 responses matched with simulator\n" + "110011001100110011001100110011001100000000000000000000000000000000000001001100110011001100110011001100000000000100110001011010011101101001011010010110100101101001001100110011001100110011001100011001100110011001100110011001110011001100110011001100110011001011101001011010010110100101101001011010010110100101101001011101100110011001101100110000010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101011100110011001100110011001100110011111100001001011000100\n", + "000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000010010011000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000010000000100000000000000000000000011010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111110000001111101101001000000000000000000000000000000000000100000001100000\n", + "010011111111111111111111111111111010100000000000000000000000000000000000000000000000000000000000000000000000001010110011001100100000000100000100000001010000010100101101001100010000000000000000000000000000000000000000000000000000000000000000000000000000000001000010000000000000000000000000000000000000000000000000000000010010010000000100001001000000000000000000000111011110001011011101111100010010001000101010110110011101110000100110000000011000000000000000000000000000000000010100000000000000000000000000000111011011000000010000\n", + "101100000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000001010011001000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000001010000000000000000000000000000000000000000000000000000000000000000000000001000111000000000100010101000101000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001110100000000000000000000000000000001100000100001110100\n", + "000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000010000110010100100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001100000000000000000000000000001100111100000011000011000000000000000000000000000011010000000000000000000000000000000000000000000000000000000000000000000000000010000000100000000000000000000000000000000000000000000000101000000000000000000000000000000100000100000000000000\n" ] } ], "source": [ - "matches = 0\n", - "\n", - "for i in range(cdata.shape[1]):\n", - " response = ''.join('1' if x > 0.5 else '0' for x in cdata[..., i, 1])\n", - " if trans_responses[i].replace('-','0') == response:\n", - " matches += 1\n", - " else:\n", - " print(f'mismatch for test pattern {i}')\n", - "print(f'{matches} of {cdata.shape[1]} responses matched with simulator')" + "wsim_responses_final = ((wsim_results[8] > 0.5) * logic.ONE).astype(np.uint8)\n", + "print(logic.mv_str(wsim_responses_final[:,:5]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The circuit delay is the maximum among all latest stabilization times:" + "We expect 127 matches here." ] }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 70, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2.17240047454834" + "127" ] }, - "execution_count": 42, + "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "cdata[...,5].max()" + "np.sum(np.min((wsim_responses_final == transition_responses[:,:sims]) | \n", + " (transition_responses[:,:sims] == logic.UNASSIGNED) | \n", + " (transition_responses[:,:sims] == logic.UNKNOWN), axis=0))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Check for overflows. If too many of them occur, increase `wavecaps` during engine instanciation:" + "The circuit delay is the maximum among all latest stabilization times:" ] }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2.0" + "1.1518999338150024" ] }, - "execution_count": 43, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "cdata[...,6].sum()" + "wsim_results[5].max()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Check for capture failures:" + "Check for overflows. If too many of them occur, increase `c_caps` during engine instanciation:" ] }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 72, "metadata": {}, "outputs": [ { @@ -1827,13 +2239,40 @@ "0.0" ] }, - "execution_count": 44, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "wsim_results[10].sum()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Check for capture failures by comparing the samples PPO capture value with the final PPO value:" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "cdata[...,3].sum()" + "(wsim_results[6] != wsim_results[8]).sum()" ] }, { diff --git a/tests/b15_2ig.sa_nf.stil.gz b/tests/b15_2ig.sa_nf.stil.gz new file mode 100644 index 0000000..b0159f3 Binary files /dev/null and b/tests/b15_2ig.sa_nf.stil.gz differ diff --git a/tests/b15_2ig.sdf.gz b/tests/b15_2ig.sdf.gz new file mode 100644 index 0000000..52da6cf Binary files /dev/null and b/tests/b15_2ig.sdf.gz differ diff --git a/tests/b15_2ig.tf_nf.stil.gz b/tests/b15_2ig.tf_nf.stil.gz new file mode 100644 index 0000000..bc3eced Binary files /dev/null and b/tests/b15_2ig.tf_nf.stil.gz differ