-
Notifications
You must be signed in to change notification settings - Fork 11
/
Inc16.js
60 lines (48 loc) · 1.22 KB
/
Inc16.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* The MIT License (MIT)
* Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*/
'use strict';
const BuiltInGate = require('../BuiltInGate');
const {int16Table} = require('../../../util/numbers');
/**
* Canonical truth table for the `Inc16` gate.
*/
const TRUTH_TABLE = int16Table([
{in: 0b0000000000000000, out: 0b0000000000000001},
{in: 0b1111111111111111, out: 0b0000000000000000},
{in: 0b0000000000000101, out: 0b0000000000000110},
{in: 0b1111111111111011, out: 0b1111111111111100},
]);
/**
* Adds the constant 1 to the input.
*/
class Inc16 extends BuiltInGate {
/**
* IN in[16];
* OUT out[16];
*
* Abstract:
*
* HalfAdder(a=in[0], b=1, sum=out[0], carry=c1);
* HalfAdder(a=in[1], b=c1, sum=out[1], carry=c2);
* ...
*
* Technically use JS + operator on 16-bit values.
*/
eval() {
const _in = this.getInputPins()[0].getValue();
this.getOutputPins()[0].setValue(_in + 1);
}
}
/**
* Specification of the `Inc16` gate.
*/
Inc16.Spec = {
name: 'Inc16',
description: 'Adds the constant 1 to the input.',
inputPins: [{name: 'in', size: 16}],
outputPins: [{name: 'out', size: 16}],
truthTable: TRUTH_TABLE,
};
module.exports = Inc16;