Exemplo n.º 1
0
// Or16 takes 32 inputs (a, b; a, b; a, b...) and produces 16 outputs.
func Or16() gate.Chip {
	gates := make([]*gate.Gate, 16)
	for i := range gates {
		gates[i] = gate.Or()
	}
	return gate.NewChip(arrayMap, 32, 16, gates...)
}
Exemplo n.º 2
0
// Mux takes 3 inputs a, b, and sel (in that order) and produces 1 output. a is
// selected when sel=false. b is selected when sel=true.
func Mux() gate.Chip {
	and1 := gate.And()
	and2 := gate.And()
	or := gate.Or()
	not := gate.Not()

	not.Out(and1.In2)
	and1.Out(or.In1)
	and2.Out(or.In2)

	return gate.NewChip(muxMap, 3, 1, or, and1, and2, not)
}
Exemplo n.º 3
0
// Xor takes 2 inputs and produces 1 output.
func Xor() gate.Chip {
	and1 := gate.And()
	and2 := gate.And()
	not := gate.Not()
	or := gate.Or()

	and1.Out(not.In1)
	not.Out(and2.In1)
	or.Out(and2.In2)

	return gate.NewChip(xorMap, 2, 1, and2, and1, not, or)
}