-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathks.lua
More file actions
executable file
·71 lines (65 loc) · 2.57 KB
/
ks.lua
File metadata and controls
executable file
·71 lines (65 loc) · 2.57 KB
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
61
62
63
64
65
66
67
68
69
70
71
local strict = require("spaghetti.strict")
strict.wrap_env()
local spaghetti = require("spaghetti")
local bitx = require("spaghetti.bitx")
local band = spaghetti.band
local bxor = spaghetti.bxor
local bor = spaghetti.bor
local constant = spaghetti.constant
local function lshiftk(node, k)
return node:lshift(bitx.lshift(1, k))
end
local function ks(lhs, rhs)
lhs:assert(0x10000000, 0x0001FFFF)
local carry_in = lhs:band(0x00010000):zeroable()
rhs:assert(0x10000000, 0x0000FFFF)
local lhs_ka = lhs:bor(0x00010000)
local rhs_ka = rhs:bor(0x3FFF0000)
local generate = band(lhs_ka, rhs_ka):assert(0x10010000, 0x0000FFFF)
local propagate = bxor(lhs_ka, rhs_ka):assert(0x2FFE0000, 0x0000FFFF)
local onebit_sums = propagate
for i = 1, 4 do
local bit_i = bitx.lshift(1, i)
local bit_i_m1 = bitx.lshift(1, i - 1)
local generate_keepalive = bitx.band(bitx.bor(0x30000000, bitx.lshift(bitx.lshift(1, bit_i) - 1, 16)), 0x3FFFFFFF)
local propagate_fill = constant(0x3FFF0000, bitx.lshift(1, bit_i_m1) - 1)
generate = bor(generate, band(propagate, lshiftk(generate, bit_i_m1))):assert(generate_keepalive, 0x0000FFFF)
propagate = band(propagate, bor(lshiftk(propagate, bit_i_m1), propagate_fill)):assert(0x2FFE0000, 0x0000FFFF)
end
generate:assert(0x3FFF0000, 0x0000FFFF)
propagate:assert(0x2FFE0000, 0x0000FFFF)
local generate_shifted = lshiftk(generate, 1):assert(0x3FFE0000, 0x0001FFFE)
local propagate_shifted = bor(lshiftk(propagate, 1), constant(0, 1)):assert(0x1FFC0000, 0x0001FFFF)
local propagate_conditional = carry_in:select(propagate_shifted, 0x1FFC0000):assert(0x1FFC0000, 0x0001FFFF)
local carries = bor(generate_shifted, propagate_conditional):assert(0x3FFE0000, 0x0001FFFF)
local sum = bxor(onebit_sums, carries):assert(0x10000000, 0x0001FFFF)
return sum
end
local lhs = spaghetti.input(0x10000000, 0x0001FFFF)
local rhs = spaghetti.input(0x10000000, 0x0000FFFF)
local sum = ks(lhs, rhs)
sum:assert(0x10000000, 0x0001FFFF)
return {
design = spaghetti.build({
inputs = {
[ 1 ] = lhs,
[ 3 ] = rhs,
},
outputs = {
[ 1 ] = sum,
},
stacks = 1,
storage_slots = 21,
work_slots = 8,
}),
extra_parts = {
{ type = elem.DEFAULT_PT_FILT, x = 3, y = -4, ctype = 0x1001DEAD },
{ type = elem.DEFAULT_PT_LDTC, x = 3, y = -2 },
{ type = elem.DEFAULT_PT_FILT, x = 3, y = -1 },
{ type = elem.DEFAULT_PT_FILT, x = 5, y = -4, ctype = 0x1000BEEF },
{ type = elem.DEFAULT_PT_LDTC, x = 5, y = -2 },
{ type = elem.DEFAULT_PT_FILT, x = 5, y = -1 },
{ type = elem.DEFAULT_PT_LDTC, x = 3, y = 2 },
{ type = elem.DEFAULT_PT_FILT, x = 3, y = 3 },
},
}