agorararmard | 1a1e89a | 2020-11-05 22:36:46 +0200 | [diff] [blame] | 1 | # A general XOR script |
| 2 | # (https://www.klayout.de/forum/discussion/100/xor-vs-diff-tool) |
| 3 | # This script uses KLayout's DRC language to implement a generic |
| 4 | # XOR between two layouts. The name of the layouts is given |
| 5 | # in $a and $b. |
| 6 | |
| 7 | # For layout-to-layout XOR with multiple cores, run this script with |
| 8 | # ./klayout -r xor.drc -rd thr=NUM_CORES -rd top_cell=TOP_CELL_NAME -rd a=a.gds -rd b=b.gds -rd ol=xor.gds -zz |
| 9 | # (replace NUM_CORES by the desired number of cores to utilize |
| 10 | |
| 11 | # enable timing output |
| 12 | verbose |
| 13 | |
| 14 | # set up input a |
| 15 | a = source($a, $top_cell) |
| 16 | |
| 17 | # set up input b |
| 18 | b = source($b, $top_cell) |
| 19 | |
| 20 | $o && report("XOR #{$a} vs. #{$b}", $o) |
| 21 | $ol && target($ol, $co || "XOR") |
| 22 | |
| 23 | $thr && threads($thr) || threads(2) |
| 24 | |
| 25 | # collect all common layers |
| 26 | layers = {} |
| 27 | [ a.layout, b.layout ].each do |ly| |
| 28 | ly.layer_indices.each do |li| |
| 29 | i = ly.get_info(li) |
| 30 | layers[i.to_s] = i |
| 31 | end |
| 32 | end |
| 33 | |
| 34 | # perform the XOR's |
| 35 | layers.keys.sort.each do |l| |
| 36 | i = layers[l] |
| 37 | info("--- Running XOR for #{l} ---") |
| 38 | x = a.input(l) ^ b.input(l) |
| 39 | info("XOR differences: #{x.data.size}") |
| 40 | $o && x.output(l, "XOR results for layer #{l}") |
| 41 | $ol && x.output(i.layer, i.datatype, i.name) |
| 42 | end |