# Missed function Check Classic List Threaded 9 messages Open this post in threaded view
|

## Missed function Check

 Something that has been bothering me is the lack of verification of 2s Complement math. One line that would help check for this in the test and compare would be: | 0000000000000010 | 0000000000000010 | 0 | 1 | 0 | 1 | 1 | 0 | 1111111111111100 | 1 | 0 | This is x=2, y=2, nx, ny, and f are set to 1, output is -4.  None of the other tests check for this. Most versions of the ALU that I have found will fail this check, because few actually account for correctly implementing the math. Under the current test, all the checks can be made without every once using a increment, however if you add 2 negative numbers, the result with most implementations shows a failure. Am I missing something here?
Open this post in threaded view
|

## Re: Missed function Check

 Administrator Jeana wrote Something that has been bothering me is the lack of verification of 2s Complement math. One line that would help check for this in the test and compare would be: | 0000000000000010 | 0000000000000010 | 0 | 1 | 0 | 1 | 1 | 0 | 1111111111111100 | 1 | 0 | This is x=2, y=2, nx, ny, and f are set to 1, output is -4.  None of the other tests check for this. Most versions of the ALU that I have found will fail this check, because few actually account for correctly implementing the math. Under the current test, all the checks can be made without every once using a increment, however if you add 2 negative numbers, the result with most implementations shows a failure. Am I missing something here? I'm having a hard time trying to figure out what your point is -- you seem to be mixing up all kinds of different things with little rhyme or reason. For instance, you say that all the checks can be made without using an increment. Okay, let's say that's true. What does that have to do with adding 2 negative numbers? And what does that then have to do with the test you propose? If you set nx, ny, and f to 1 (and presumably all the others to 0), then you get a function that is not one of the eighteen defined functions. Why should the test file be testing an instruction that is not in the instruction set? If you work through the logic implied by the control signals, then you would get that the output for that instruction would be out = -(x+y+2) which with x=y=2 would be -6, or 1111111111111010 Let's walk it through. x = 2 = 0000 0000 0000 0010 y = 2 = 0000 0000 0000 0010 !x = 1111 1111 1111 1101 !y = 1111 1111 1111 1101 (!x) + (!y) = 1111 1111 1111 1010 = -6 If you want to test whether or not the ALU adds two negative numbers together correctly, then why not use a test that sets x and y both to negative numbers and then sets the control signals so that the function x+y is executed (namely f=1 and all other signals are 0)?
Open this post in threaded view
|

## Re: Missed function Check

 Administrator In reply to this post by Jeana Jeana wrote Something that has been bothering me is the lack of verification of 2s Complement math. I just looked at the test file and it does do some verification of 2'c complement math. There is a test of y-x with y = 3 and x = 17, with the result being -14. Then all of the math functions are tested with x = 0 and y = -1. Certainly the tests can be made far more extensive, but they also need to run in a reasonable time, particularly when a grader is running the submissions of dozens of people. The claim is not that it is impossible that a flawed implementation could coincidentally pass the 36 tests in this file, merely that it is pretty unlikely that this would happen. Given the very simple implementation of the ALU, this is almost certainly a valid position. It would be interesting to see a nontrivial implementation that passes all of these tests but that fails work properly for all input. I say nontrivial because it would be trivial to mix the input data with the control signals to accomplish this feat. For instance, since x is zero in all of the test cases, this could be OR'ed with one or more of the control signals and it would have no impact on these particular tests. But as soon as you have a value for which x is a 1, then some of the instructions would be corrupted.
Open this post in threaded view
|

## Re: Missed function Check

 So, my assumption is that negative numbers cannot be passed directly into the ALU.  Or at least the practice for the hardware drivers is to specify negative numbers using the flags, not direct entry. Second, -2 + -2 is -4.  Completing a bitwise-not on a number is not the name as getting its inverse value.  For example -2 under 2s complement would be 111..1110 not 111..11101 (as would be the case when simply doing a bitwise-not of a binary 2).  Of course getting the bitwise-not is the first step in getting the 2s complement, next would be incrementing the number by 1 (before doing further arithmetic functions not after). In order to properly complete an arithmetic addition between 2 numbers, they would need to be in 2s complement.  There are a few ways to implement 2s complement.  However due to the tests performed, the issue is not brought to light if these steps were skipped.  With only 1 negative number, there is a sort of built in work wound when using a full adder, however this breaks down when using 2 negative numbers (made negative by flags). I expanded beyond the original tests specifically because I was experimenting with trying to minimize the number of complex gates used, and since certain responses were not what I expected, I dug deeper which initiated the expanded test criteria and exposed this interesting quirk. A further test I did try was to increment a number after, as you have with the x+y+2, and as you said it gets -6, however to only user the bitwise function to add you get -2 (111..1110) which is not the correct answer either.  Only by adding the 2s complements for -2 can you get -4 (mathematically correct).
Open this post in threaded view
|

## Re: Missed function Check

Open this post in threaded view
|

## Re: Missed function Check

 Ok, when I was saying flags I meant the instruction pins.  My background includes a lot of shell coding, flags are used for instruction modifiers, so I used the term in the wrong context on accident.  I  apologize for the confusion. I know that the numbers can be processed as input if they were already in 2s complement (specifically useful if further computations would be completed on that variable).  However from the external data entry point of view, a user would (presumably) send a positive numbers with the negate (flags) instructions to produce a product of 2 negative numbers.  Maybe this kind of math would require further processing outside the ALU? I am aware of using an Xor combined with a half-adder for 2s complement, building a sub-chip for this concept is part of what set off this entire investigation for me.  The use of the full adder was the workaround (vice creating a 2s complement chip separate or other integrated methods) I was talking about.  Maybe it could be called more of a shortcut then a workaround? Since carry operations are part of an adder, this can (and does) work under most conditions.  I would assume that under extreme high and low numbers this may fail, but haven't tested this. That method does seems breaks down when both nx, ny instructions are set, at least with the testing I have done so far.  Assuming the goal is specifically arithmetic. I really do not understand how nx,ny,f=1 (rest=0) are meant to translates to -(x+y+2) aka -x-y-2.   I understand that this is the result, but it wasn't my intended operation?   I understand how this condition is created (between the bitwise not and the adder), but the why when using addition this should occur is kind of the issue to me.  Shouldn't the ALU account for the difference between bitwise instructions and math operations? I would have thought that those instructions should produce = -x + (-y) = -x-y.  Is this were I am misunderstanding the operations? I will have to try the x to -1234, y to -5678 test later.  I assume you mean using positive x and y, then using the nx and ny instructions?
Open this post in threaded view
|