# Pastebin wryKPtAn void LUT::MergeWith(LUT* other, int pin) { //Note the inputs from the 'other' LUT are put at the start of this one vector newContent; for(int i = 0; i < lutContent.size(); i++) { //only processing things when the value of the replaced pin is zero prevents the newContent array being duplicated if((i & (1 << pin)) == 0) { for(int j = 0; j < other->lutContent.size(); j++) { //evaluate all input combinations in the other LUT if(other->lutContent[j]) { //output of other LUT is high, thus pick from row in this LUT equivalent to i but where pin is high newContent.push_back(lutContent[i | (1 << pin)]); } else { //output of other LUT is low, thus pick from row i where pin is low newContent.push_back(lutContent[i]); } } } } inputPorts[pin]->Disconnect(); inputPorts.erase(inputPorts.begin() + pin); //add inputs of 'other' LUT to this one at the start but in the correct order for(int i = other->inputPorts.size() - 1; i >= 0; i--) { DeviceInputPort *port = new DeviceInputPort(); port->pin = i; port->device = this; port->connectedNet = other->inputPorts[i]->connectedNet; other->inputPorts[i]->connectedNet->connectedPorts.push_back(port); inputPorts.insert(inputPorts.begin(), port); } lutContent = newContent; }