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

Ubuntu 18.04 problem with running float.sbl causing overflow or underflow #14

Closed
osmanfb opened this issue Dec 23, 2021 · 18 comments
Closed

Comments

@osmanfb
Copy link

osmanfb commented Dec 23, 2021

I built the x64 spitbol on my ubuntu 18.04 laptop. Building and running sanitychecjk went ok and I installed it. But trying it on the files in the test subdirectory, I am having a problem with float.sbl file.
../sbl float.sbl
5. expect 5.0

test/float_orig.sbl(9) : error 264 -- subtraction caused real overflow

in file test/float_orig.sbl
in line 9
in statement 9
stmts executed 9
execution time msec 0
in line 0
memory used (bytes) 12792
memory left (bytes) 249344

same thing happens with the spitbol executable from the bin subdir.. But if build the 32 bit version from github/x32 then that spitbol runs the float.sbl without any problems. Also if switch floats to integers, it also works.
What could be the problem/where to look ???
TIA

@CheyenneWills
Copy link
Contributor

I'm also running into a similar problem, but am getting a segfault around label gts26 with just a simple:

x = 2.0 'a'
end

@CheyenneWills
Copy link
Contributor

I think I might know what is going on and I'm investigating a solution (possible misplacement of a read-write area into a read only segment)

@CheyenneWills
Copy link
Contributor

Found the problem and have a fix. It wasn't what I had thought above.

Some of the internal calls to C functions from the assembly code need to preserve some registers that get clobbered (I believe that this might be a Linux vs Windows difference).

Adding a couple of pushes prior to the calls and pops afterwards appears to fix the problem.

CheyenneWills added a commit to CheyenneWills/x64 that referenced this issue Dec 29, 2021
On Linux, the C calling convention clobbers the following registers that
are used internally:

    RDI, RSI, RDX, RCX

Ensure that these registers are preserved when calling the internal C
runtime functions.

Fixes issue spitbol#14
CheyenneWills added a commit to CheyenneWills/x64 that referenced this issue Dec 29, 2021
On Linux, the C calling convention clobbers the following registers that
are used internally:

    RDI, RSI, RDX, RCX

Ensure that these registers are preserved when calling the internal C
runtime functions.

Fixes issue spitbol#14
@CheyenneWills
Copy link
Contributor

Pull Request #15 I believe fixes the problem. The branch contains some of the other patches that I've worked on and includes some general (and minor) build cleanup.

@osmanfb
Copy link
Author

osmanfb commented Dec 29, 2021

Thanks for looking into and fixing but how long does it take github to update the master branch? I just cloned the master into a new folder and float.sbl still causing the underflow.

@CheyenneWills
Copy link
Contributor

Thanks for looking into and fixing but how long does it take github to update the master branch? I just cloned the master into a new folder and float.sbl still causing the underflow.

I'm waiting to hear back from Dave Shields who has commit authority. In the meantime you can use what's in the above pull request.

@osmanfb
Copy link
Author

osmanfb commented Dec 29, 2021

I did. I changed sbl.asm, int.asm, int.dcl as the diffs showed. same problem. looks like clobbering happens on the output = statements, Variable calculations of any complexity that I tried worked ok as long as the output statement did not contain any float ops. I also cloned bootstrap and it did not work either. Looks like the above asm and dcl files are created each time make is executed. So the changes are overwritten. Since I don't know what I'm doing, I'll wait until master is updated.

@daveshields
Copy link
Collaborator

daveshields commented Dec 29, 2021 via email

@CheyenneWills
Copy link
Contributor

Cheyenne, Thanks for all your work. I reviewed your prior emails and noted that I invited to to become a committer on November 4, so please feel free to pull your patches into the master. thanks, dave

Thanks Dave. It appears that I don't have write access to the spitbol/x64 repository, just read access so I can't complete the pull request.

@daveshields
Copy link
Collaborator

daveshields commented Jan 3, 2022 via email

@CheyenneWills
Copy link
Contributor

The fix is now in master.

@CheyenneWills
Copy link
Contributor

::sigh:: still a minor problem (probably a missed call).

@daveshields
Copy link
Collaborator

daveshields commented Jan 3, 2022 via email

@CheyenneWills
Copy link
Contributor

I found the problem with the floating point. There needed to be some checks for floating point "problems" with some of the operations (+-/*). I have a "fix" for that as well..

New PR coming in for that..

@CheyenneWills
Copy link
Contributor

PR #16 should better handle the problem with some floating point operations.

I was getting the error: "test/float.sbl(9) : error 264 -- subtraction caused real overflow". The above PR should fix that.

@osmanfb
Copy link
Author

osmanfb commented Jan 4, 2022

as of Jan 04, 2 pm the master branch still causing the floating point exception. I checked that having bunch of lines of float operations does not cause the exception. But multiple "output = " with floats does. x = 2.0
y = 5.0
z = x + y * ( y - 1.0)
w = x * y * z
output = w
output = x
output = x + y
end
the last output cause an exception. If taken out runs ok.

@CheyenneWills
Copy link
Contributor

as of Jan 04, 2 pm the master branch still causing the floating point exception. I checked that having bunch of lines of float operations does not cause the exception. But multiple "output = " with floats does. x = 2.0 y = 5.0 z = x + y * ( y - 1.0) w = x * y * z output = w output = x output = x + y end the last output cause an exception. If taken out runs ok.

I've merged the latest changes (PR #16) into master.

@osmanfb
Copy link
Author

osmanfb commented Jan 6, 2022

thanks Cheyenne. master is working ok now (Jan 6, 00:28). The only thing is the pre-built bin/sbl is causing "illegal instruction" and maybe should not be included. Also a few lines could be added to the README to do a make bootsbl first and then follow with make BASEBOL=./bootsbl and finally make bininst to copy the sbl to the bin directory.

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