Ejemplo n.º 1
0
// And16 takes 32 inputs (a, b; a, b; a, b...) and produces 16 outputs.
func And16() gate.Chip {
	gates := make([]*gate.Gate, 16)
	for i := range gates {
		gates[i] = gate.And()
	}
	return gate.NewChip(arrayMap, 32, 16, gates...)
}
Ejemplo n.º 2
0
// Not16 takes 16 inputs and produces 16 outputs.
func Not16() gate.Chip {
	gates := make([]*gate.Gate, 16)
	for i := range gates {
		gates[i] = gate.Not()
	}
	return gate.NewChip(arrayNotMap, 16, 16, gates...)
}
Ejemplo n.º 3
0
// Demux takes 2 inputs x, sel (in that order) and produces 2 outputs a, b. a
// is selected if sel=false. b is selected if sel=true
func Dmux() gate.Chip {
	and1 := gate.And()
	and2 := gate.And()
	not := gate.Not()

	not.Out(and1.In2)

	return gate.NewChip(demuxMap, 2, 2, and1, and2, not)
}
Ejemplo n.º 4
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)
}
Ejemplo n.º 5
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)
}