Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDS shifts limit count to 48; sds_cpu.c doesn't for cycle/rotate shifts #315

Open
at7heb opened this issue Oct 28, 2023 · 4 comments
Open

Comments

@at7heb
Copy link

at7heb commented Oct 28, 2023

The SDS Technical Reference manuals say that if the shift count is > 48, it is set to 48. The LSH and RSH implementations in sds_cpu.c do that for logical, arithmetic shifts, and normalize. For circular shifts, the shift count is incorrectly reduced modulo 48.

I corresponded with Mark Emmer, a colleague from NOAA/DOCB. He verified this with the logic equations in the 900097A-Volume 2 Examiner Diagnostic Manual, volume 2, e.g. 10/1964 edition page 176, left cycle, phase 1, T2, where x48 is set to = not(not(s6) * not(s7) * not(s8)) + s9 * s10 (meaning if count has the 32 and 16 bits set, or any of the 64, 128, or 256 bits set.

Here's the code for left cycle/rotate

        case 04:                                        /* left cycle */
            sc = sc % 48;                               /* mod 48 */
            if (sc)                                     /* rotate */
                RotR48 (48 - sc);
            break;

IMO, the shift count should be adjusted at the beginning of the LSH and RSH functions, as the 930/940 do.

PS: curiously, sds_cpu.c also has code for a rotate left normalize. The documented normalize shifts zeros into the LSB of the B register as it normalizes. The code in sds_cpu.c shifts sign bits of A into the LSB of B in the undocumented variant. Any insights?

@markpizz
Copy link
Contributor

markpizz commented Nov 6, 2023

@rms47 and @kenrector thoughts on this?

@rms47
Copy link
Member

rms47 commented Nov 8, 2023

Yes, he's right. It's a bug. Shift counts should be limited to 48 at the top of LSH and RSH. Further, rotates of 48 are effectively NOPs and should be detected before calling RRot48.

The rotate left normalize falls out of the logic equations for left shift. The 940 doesn't explicitly test for unspecified shift combinations; the Tech Manual says they can be ignored because they are illegal. The combination of normalize and cycle is at least predictable, based on the logic equations. I can't figure out what the undefined right shift combinations would do.

I've posted the updated source to my web site.

@at7heb
Copy link
Author

at7heb commented Jul 15, 2024

Yes, he's right. It's a bug. Shift counts should be limited to 48 at the top of LSH and RSH. Further, rotates of 48 are effectively NOPs and should be detected before calling RRot48.

The rotate left normalize falls out of the logic equations for left shift. The 940 doesn't explicitly test for unspecified shift combinations; the Tech Manual says they can be ignored because they are illegal. The combination of normalize and cycle is at least predictable, based on the logic equations. I can't figure out what the undefined right shift combinations would do.

I've posted the updated source to my web site.

Assign me if you wish; I'll be submitting a pull request presently. Mark Emmer pointed out that this repository was (the only one) missing the fix.

@rms47
Copy link
Member

rms47 commented Jul 16, 2024

Sigh... This has been fixed, along with numerous other bugs, in the current version of 3.X for months. See simh.trailing-edge.com/sources/current. The entire directory needs to be merged into "Supnik Current" and then forward merged into mainline. To make this easier, I've zipped it up and released it as SimH v3.12-5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants