Gas64 (no more use of gcc, only gas) WDS / LNX

User projects written in or related to FreeBASIC.
Post Reply
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by SARG »

@hhr
There is not any problem on my side.
Is it a compile time error ? in this case what error ?
Or a runtime problem ?

That issue could be already fixed after your report viewtopic.php?p=292633#p292633
Unfortunately daily builds are off since june 6th however I can put a link to my own version.

Try by declaring impulsex/impulsey double instead single.
hhr
Posts: 205
Joined: Nov 29, 2019 10:41

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by hhr »

@SARG
Declaring impulsex/impulsey double instead single solved the problem. Now I will wait for the next daily build. Thank you for the answer and for gas64.

PS: I tested with FB-1.09.0 and forgot to test with the latest available daily build. There is no error, please excuse my mistake.
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by SARG »

hhr wrote: Jun 20, 2022 8:38 There is no error, please excuse my mistake.
No problem.
In fact the issue was reported by dodicat and fixed at the beginning of january.
hhr
Posts: 205
Joined: Nov 29, 2019 10:41

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by hhr »

We can download a new daily build and I tested Everlift with it. https://users.freebasic-portal.de/stw/builds/.
For gas64 I changed Double to Single in Line 79.
Is this a bug in gas64? We should help to make gas64 better and better, but I do not want to be hasty.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by dodicat »

You are correct hhr.
The angle has to be single
using double compiles OK but doesn't run.
I'll try and isolate the problem.
Thanks.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by dodicat »

The bug in -gen gas64 seems to be around the sin function.
If the crt sin is used then it is OK.

Code: Select all

#cmdline "-gen gas64"

#define usecrt '<<------------------- comment out the whole line

declare function sin_ cdecl lib "msvcrt" alias "sin"(as double) as double
Type V2
    As Single x,y
End Type

Function drawline(x As Long,y As Long,angle As double,length As double,flag As Long=0) As v2
    angle=angle*.0174532925199433
    Dim As Single x2=x+length*Cos(angle)
#ifdef usecrt
    Dim As Single y2=y-length*Sin_(angle)
#else
 Dim As Single y2=y-length*Sin(angle)
#endif
    Return Type(x2,y2)
End Function


screen 19,32
dim as single a
dim as double l=200
for a=0 to 360 step 1
dim as v2 p=drawline(400,300,a,l)
line(400,300)-(p.x,p.y),rgb(200,0,0)
if abs(sqr((400-p.x)^2+(300-p.y)^2)-l)>.1 then print a,abs(sqr((400-p.x)^2+(300-p.y)^2)-l)
next a
print "OK"
sleep


 
(using build fbc_win64_mingw_0794_2022-06-20)
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by SARG »

Sorry guys, no problem on my side with both codes.

What should I get/see ?

edit : no problem with my own version but there is an issue with the daily build version.

edit bis : there is a problem of compatibily with libs.
Compiling with lastest fbc.exe (daily build) and the libs from 1.09 --> no problem

I'll try to find with what version the problem begins.
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by SARG »

it took more than 2 hours for finding an explanation. Thanks asm debugger.
Daily builds don't use the same libs as provided by fbc 1.09 :
- daily build, cos/sin functions are called in the OS (Windows)
- regular 1.09, it's the lib from gcc AFAIK

Now the real problem, when calling cos and sin these functions, of OS, write into the area of reserved stack for drawline and unfortunately crush x2 value stored in this area.

First instructions of the functions :

Code: Select all

push rbx 
sub rsp,70
mov rax,7FFFFFFFFFFFFFFF 
movaps xmmword ptr ss:[rsp+60],xmm6 
movsd qword ptr ss:[rsp+88],xmm0    <------ rsp is decremented by 70 but adding 88 it's beyond its reserved stack.
It seems weird ..... Any opinion/help is welcome.

@dodicat
Using sin from crt avoid the call to the other 'problematic' function so the value is not crushed.
adeyblue
Posts: 299
Joined: Nov 07, 2019 20:08

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by adeyblue »

It's spilling the parameter into the home area/shadow store.
https://docs.microsoft.com/en-us/cpp/bu ... w=msvc-170
The caller is responsible for allocating space for the callee's parameters. The caller must always allocate sufficient space to store four register parameters, even if the callee doesn't take that many parameters
There's a diagram here
https://docs.microsoft.com/en-us/cpp/bu ... w=msvc-170
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by dodicat »

Why just the bare 7FFFFFFFFFFFFFFF
(mov rax,7FFFFFFFFFFFFFFF )
Shouldn't there be 0x prefixed?
mov rax, 0x7FFFFFFFFFFFFFFF
Or is this the correct result of your own debug program.
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by SARG »

@adeyblue
I know all that (I printed these pages some years ago) otherwise how gas64 could work. However you put me on the track, thanks.

In gas64 Cos, Sin and few other functions are called in a different way and no space is reserved for parameters on the stack (bad forgetting) if there is no other calls. Then 'obviously' the area used by sin/cos functions to save xmm0 is wrong.
By chance until now that did not cause any problem.
I'll fixed that quickly.

@dodicat
That's just a copy of what is displayed by the debugger (x64dbg, very powerful).
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by dodicat »

Thanks for fixing that SARG, and hhr for finding the bug in the first place.
SARG
Posts: 1755
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by SARG »

@dodicat
Easy fix (3 lines added including a test....) yesterday night, will be pushed this afternoon. After it'll depend of Jeff.

@dodicat, hhr, adeyblue
Thanks for your help.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Ever lift.

Post by D.J.Peters »

@dodicat from my raytracer stuff NanoMeter2RGB() with gamma corecture.
The calculation of gamma factor isn't from me (but can't remember the source) it comes from the visible spectrum of 380-780 nm !

EDIT: found the javascript source code at: https://www.johndcook.com/wavelength_to_RGB.html is inside the HTML code.

one more: https://codepen.io/pen?&editors=011 look in the right pane at: nmToRGB:

Joshy

Code: Select all

function NanoMeter2RGB(byval nm as single) as ulong
  dim as single r,g,b,factor
  if nm<380.0f then
    nm=380.0f
  elseif nm>780.0f then
    nm=780.0f
  endif  
  if nm < 440.0f then ' 380-440
    r =-(nm - 440.0f) / 60.0f : b = 1.0f
  elseif nm >= 440.0f andalso nm < 490.0f then
    g = (nm - 440.0f) / 50.0f : b = 1.0f
  elseif nm >= 490.0f andalso nm < 510.0f then
    b = -(nm - 510.0f) / 20.0f : g = 1.0f 
  elseif nm >= 510.0f andalso nm < 580.0f then
    r = (nm - 510.0f) / 70.0f : g = 1.0f
  elseif nm >= 580.0f andalso nm < 645.0f then
    g = -(nm - 645.0f) / 65.0f : r = 1.0f 
  elseif nm >= 645.0f then ' 645-780
    r = 1.0f
  endif
  if nm < 420.0f then
    factor = 0.3f + 0.7f*(nm - 380.0f) / 40.0f
  elseif nm >= 420.0f andalso nm < 701.0f then
    factor = 1.0f
  elseif nm >= 701.0f then
    factor = 0.3f + 0.7f*(780.0f - nm) / 80.0f
  endif
  const GAMMA as single = 0.8f
  r = iif(r > 0.0f,255.0f*((r*factor)^GAMMA),0.0f)
  g = iif(g > 0.0f,255.0f*((g*factor)^GAMMA),0.0f)
  b = iif(b > 0.0f,255.0f*((b*factor)^GAMMA),0.0f) 

  return RGB(r,g,b)
end function
screenres 400,64,32
for x as single=0 to 400
  ' 380-780 nanometer
  var colour=NanoMeter2RGB(380.0f+x)
  line (x,0)-step(0,63),colour
next
sleep
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Gas64 (no more use of gcc, only gas) WDS / LNX

Post by dodicat »

Thanks D.j.Peters.
Bluatigro posted a rainbow colour function a while back.
Here I compare yours and his.
Although the colours in both blend nicely, the ulong values are not linear, so I created a false linearity with a spline for red, green and blue in my ever lift.

Code: Select all

'#cmdline "-gen gas64"
function NanoMeter2RGB(byval nm as single) as ulong
  dim as single r,g,b,factor
  if nm<380.0f then
    nm=380.0f
  elseif nm>780.0f then
    nm=780.0f
  endif  
  if nm < 440.0f then ' 380-440
    r =-(nm - 440.0f) / 60.0f : b = 1.0f
  elseif nm >= 440.0f andalso nm < 490.0f then
    g = (nm - 440.0f) / 50.0f : b = 1.0f
  elseif nm >= 490.0f andalso nm < 510.0f then
    b = -(nm - 510.0f) / 20.0f : g = 1.0f 
  elseif nm >= 510.0f andalso nm < 580.0f then
    r = (nm - 510.0f) / 70.0f : g = 1.0f
  elseif nm >= 580.0f andalso nm < 645.0f then
    g = -(nm - 645.0f) / 65.0f : r = 1.0f 
  elseif nm >= 645.0f then ' 645-780
    r = 1.0f
  endif
  if nm < 420.0f then
    factor = 0.3f + 0.7f*(nm - 380.0f) / 40.0f
  elseif nm >= 420.0f andalso nm < 701.0f then
    factor = 1.0f
  elseif nm >= 701.0f then
    factor = 0.3f + 0.7f*(780.0f - nm) / 80.0f
  endif
  const GAMMA as single = 0.8f
  r = iif(r > 0.0f,255.0f*((r*factor)^GAMMA),0.0f)
  g = iif(g > 0.0f,255.0f*((g*factor)^GAMMA),0.0f)
  b = iif(b > 0.0f,255.0f*((b*factor)^GAMMA),0.0f) 

  return RGB(r,g,b)
end function

function rainbow( x as single ) as ulong 'idea from bluatigro
    static as double pi=4*atn(1)
    #define rad(n) (pi/180)*(n)
  dim as ulong r , g , b
  r = sin( rad( x ) ) * 127 + 128
  g = sin( rad( x - 120 ) ) * 127 + 128
  b = sin( rad( x + 120 ) ) * 127 + 128
  return rgb( r and 255 , g and 255 , b and 255 )
end function


function map(a as double,b as double,x as double,c as double,d as double) as double
      return ((d)-(c))*((x)-(a))/((b)-(a))+(c)
      end function

screen 20,32
dim as ulong min=4294967294,max=0
dim as ulong colour
dim as double xpos,ypos
for k as long=1 to 2
for x as single=0 to 400 step .25
  if k=1 then colour=NanoMeter2RGB(380.0+x) else colour=rainbow(380-x)
   xpos=map(0,400,x,0,1024)
  if k=1 then ypos=map(4278190335.0,4294967040.0,colour,50,500) else _
              ypos=map(4278302408.0,4294920760.0,colour,50,500)
  line(xpos,768)-(xpos,ypos),colour
  if min>colour then min=colour
  if max<colour then max=colour
next
if k=1 then print "D.J.Peters" else print "Bluatigro"
print "colours "; min;" to ";max
print "Press a key"
min=4294967294:max=0
sleep
cls
next

sleep 
This should work with -gen gas64 after SARG's mose recent update.(The map function to test)
Post Reply