Unexpected behavior from Hardware Simulator [SPOILERS]

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Unexpected behavior from Hardware Simulator [SPOILERS]

Andrew Gacek
I was implementing Inc16 and I stumbled into some very strange behavior (bug?) from the hardware simulator. My code is attached below. What happens is that Inc16.tst fails on the very first test. But if I swap the first two tests (and update the cmp file accordingly), then all tests pass. Am I doing something wrong? I know my implementation is messy. I've since cleaned it up and it works while avoiding the bug. I'm posting this now just to see if there really is a bug or if I'm doing something explicitly wrong.


Here's my code:

CHIP Inc16 {
    IN in[16];
    OUT out[16];

    PARTS:
    One16(out=one);
    Add16(a=in, b=one, out=out);
}

CHIP One16 {
     IN;
     OUT out[16];

     PARTS:
     Not(in=false, out=out[0]);
     Id(in=false, out=out[1]);
     Id(in=false, out=out[2]);
     Id(in=false, out=out[3]);
     Id(in=false, out=out[4]);
     Id(in=false, out=out[5]);
     Id(in=false, out=out[6]);
     Id(in=false, out=out[7]);
     Id(in=false, out=out[8]);
     Id(in=false, out=out[9]);
     Id(in=false, out=out[10]);
     Id(in=false, out=out[11]);
     Id(in=false, out=out[12]);
     Id(in=false, out=out[13]);
     Id(in=false, out=out[14]);
     Id(in=false, out=out[15]);
}

CHIP Id {
     IN in;
     OUT out;

     PARTS:
     Or(a=in, b=false, out=out);
}

(Using built-ins for all the rest)
Reply | Threaded
Open this post in threaded view
|

Re: Unexpected behavior from Hardware Simulator [SPOILERS]

cadet1620
Administrator
Andrew Gacek wrote
I was implementing Inc16 and I stumbled into some very strange behavior (bug?) from the hardware simulator. My code is attached below. What happens is that Inc16.tst fails on the very first test. But if I swap the first two tests (and update the cmp file accordingly), then all tests pass. Am I doing something wrong? I know my implementation is messy. I've since cleaned it up and it works while avoiding the bug. I'm posting this now just to see if there really is a bug or if I'm doing something explicitly wrong.


Here's my code:

CHIP Inc16 {
    IN in[16];
    OUT out[16];

    PARTS:
    One16(out=one);
    Add16(a=in, b=one, out=out);
}
Yes, it's a strange simulator bug, probably related to the output-only One16 chip.

Some things I found playing around with it:
If you replace the One16() with Add16(a=false, b[0]=true, b[1..15]=false, out=one) the test passes.
If you replace the guts of the One16 chip with the above Add16 the test still fails.
If you change the test to begin
    set in %B0000000000001000, // must be != 0
    set in %B0000000000000000,
    eval,
    output;
the test will pass.

--Mark