# Optimization question (somewhat ALU-related)

5 messages
Open this post in threaded view
|

## Optimization question (somewhat ALU-related)

 This came up while building my ALU, but I'll try to use non-specific examples in order to avoid spoilers. So, suppose I have an ALU-like chip with the following interface: CHIP ALU {     IN         x[16], y[16],  // 16-bit Inputs         f;                 // Operation: Or16 if 0, And16 if 1     OUT         out[16];  // 16-bit ouput } So, the f input is just a selector that decides which operation (AND/OR) to perform on the inputs. My usual strategy has been to perform both operations first, then use a Mux to decide which one to actually output: Or16(a=x, b=y, out=xory); And16(a=x, b=y, out=xandy); Mux16(a=xory, b=xandy, sel=f, out=out); This seems wasteful, though, because I'm always performing an operation I don't need and then throwing it away. Is there any way around this? I thought of using DMux's in order to make the decision before doing the operation, but then it occurred to me that both operations would be done anyway (one operation would just be operating on 0's). Plus, I'd still have to Mux at the end in order to avoid connecting multiple internal pins to the same output pin. Even more wasteful. Now that I think about it, I'm not sure it's even possible to have a part in a chip that doesn't "run". I'll have to think about that some more. Thanks, Frank
Open this post in threaded view
|

## Re: Optimization question (somewhat ALU-related)

 knarf_navillus wrote This seems wasteful, though, because I'm always performing an operation I don't need and then throwing it away. I think I understand your thinking. The short answer is "hardware is not like software," and you really can't view an unused portion of a circuit as "wasteful." (Unless, of course, it really is never used.) In my own TECS class, I have a mix of CS and EE students. And the CS students (software-oriented) tend to raise the same question you have, while the EE students (hardware-oriented) always stress the fundamental point that hardware "operations" are not like software operations.
Open this post in threaded view
|

## Re: Optimization question (somewhat ALU-related)

 ybakos wrote In my own TECS class, I have a mix of CS and EE students. And the CS students (software-oriented) tend to raise the same question you have... That's hilarious! I definitely am thinking about this with a software mindset. I'm used to checking first, and performing the operation after (e.g., if f==true, then do And, else do Or). Instead, it feels like I'm saying, "Go ahead and do both operations and I'll decide afterwards (via Mux) which result I want to use and which I want to throw away." Thank you for clarifying for me. Cheers. Frank