64-bit asm woes

General FreeBASIC programming questions.
MrSwiss
Posts: 2811
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: 64-bit asm woes

Postby MrSwiss » Oct 03, 2018 21:29

jj2007 wrote:That's an interesting idea.
I'd just call it applied logic.
jj2007 wrote:Can you provide a test case?
If you want 64 bit inline ASM ... 64 bit ASM example rotate left/right with a 64 bit register
(FBC 64, exclusively!).
A hell of a lot simpler, than in 32 bit's ... (no FPU registers needed).
jj2007
Posts: 879
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: 64-bit asm woes

Postby jj2007 » Oct 03, 2018 22:01

No, I meant a test case for your suggestion to use 32-bit assembly inside 64-bit code. I am a curious guy, and always open for new ideas.
MrSwiss wrote:2) 32 bit code in and of itself (inside 64 bit code)
MrSwiss
Posts: 2811
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: 64-bit asm woes

Postby MrSwiss » Oct 03, 2018 22:11

jj2007 wrote:No, I meant a test case for your suggestion to use 32-bit assembly inside 64-bit code.
Seems, you've got me the wrong way around.
I meant to state, that this is a: *NO GO* (think of differing ptr sizes e.t.c.).
Ptr (32bit) = 4 Byte -- Ptr (64bit) = 8 Byte (same applies to 'Integer' = derived type).
deltarho[1859]
Posts: 1650
Joined: Jan 02, 2017 0:34
Location: UK

Re: 64-bit asm woes

Postby deltarho[1859] » Oct 03, 2018 22:14

jj2007 wrote:I am a curious guy, and always open for new ideas.

That is a sure fire way to get your fingers burnt on a regular basis but if you are tough enough it is worth it in the long haul - been there, got the t-shirt and so on. <smile>
jj2007
Posts: 879
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: 64-bit asm woes

Postby jj2007 » Oct 04, 2018 7:49

MrSwiss wrote:
jj2007 wrote:No, I meant a test case for your suggestion to use 32-bit assembly inside 64-bit code.
Seems, you've got me the wrong way around.

Sorry, you proposed to use 32-bit code inside 64-bit code:
MrSwiss wrote:2) 32 bit code in and of itself (inside 64 bit code)
Which is technically impossible, of course, at least outside Switzerland, but you are the expert ;-)
MrSwiss
Posts: 2811
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: 64-bit asm woes

Postby MrSwiss » Oct 04, 2018 11:15

jj2007 wrote:Sorry, you proposed to use 32-bit code inside 64-bit code
Equally sorry, but you are quoting 'out of context'.
As well as, freely interpreting things, the way you like.

I can't help it, if you don't read 'until the end' of a post:
MrSwiss wrote:Unless you are able to provide the same ASM routines, optimized for:
32 bit, as well as 64 bit, equally!

jj2007 wrote:Which is technically impossible, of course, at least outside Switzerland, but you are the expert ;-)
Is it, really? I can even do 16 bit ASM:

Code: Select all

Declare Function splitByte( ByVal As UByte ) As UShort

Dim As UByte    test = &h7F
Dim As UShort   result

result = splitByte(test)
Print test
Print HiByte(result), LoByte(result)
sleep

Function splitByte( ByVal sB As UByte ) As UShort
    Asm
        xor ax, ax
        mov al, byte ptr [sB]
        mov cl, 4
        rol ax, cl
        ror al, cl
        mov word ptr [Function], ax
    End Asm
End Function
There is a difference between 'using an assembler' and
'inline assembly' in case, you've not noticed ...
marcov
Posts: 2643
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: 64-bit asm woes

Postby marcov » Oct 04, 2018 17:28

jj2007 wrote:Which is technically impossible, of course, at least outside Switzerland, but you are the expert ;-)


Well, there are the string primitives like lods<x> of course. If you have a compiler that you can tell to put parameters in certain registers (like [r|e]si/di) you can do some non trivial stuff :-)
dodicat
Posts: 5221
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: 64-bit asm woes

Postby dodicat » Oct 05, 2018 17:56

jj2007
I found the problem I had with the average.
"Micronesia, Federated States of" has a comma in it.
So this comma in a comma seperated file is in an unusual place.
However because the grammar is correct (comma then space then continue) I can handle it.

Here are all the valid lines with 2000 highlighted.

Code: Select all


#include "file.bi"     'to use Fileexists()

Function loadfile(file As String) As String
   If Fileexists(file)=0 Then Print file;" not found":Sleep:End
    Dim As Long  f=Freefile
    Open file For Binary Access Read As #f
    Dim As String text
    If Lof(f) > 0 Then
        text = String(Lof(f), 0)
        Get #f, , text
    End If
    Close #f
    Return text
End Function

Sub FindAndReplace(s As String,Find As String,Relpace As String)
    Var position=Instr(s,Find)
    While position>0
        s=Mid(s,1,position-1) & Relpace & Mid(s,position+Len(Find))
        position=Instr(position+Len(Relpace),s,Find)
    Wend
End Sub

Function isnumber(Byval s As String) As boolean
    Static As String * 13 number="-+.0123456789"
    Dim As Long ctr,dot,lnum=13
    For m As Long=0 To Len(s)-1
        If m>0 And s[m]=45 Or s[m]=43 Then Return 0
        If s[m]=46 Then dot+=1
        For n As Long=0 To lnum-1
            If s[m]=number[n] Then ctr+=1:Exit For
        Next n
    Next
    Return ctr<>0 Andalso ctr=Len(s) And dot<2 
End Function

Function StringSplit(s_in As String,chars As String,result() As String) As Long
    Dim As Long ctr,ctr2,k,n,LC=Len(chars)
    Dim As boolean tally(Len(s_in))
    #macro check_instring()
    n=0
    While n<Lc
        If chars[n]=s_in[k] Then
            tally(k)=true
            If (ctr2-1) Then ctr+=1
            ctr2=0
            Exit While
        End If
        n+=1
    Wend
    #endmacro
   
    #macro split()
    If tally(k) Then
        If (ctr2-1) Then ctr+=1:result(ctr)=Mid(s_in,k+2-ctr2,ctr2-1)
        ctr2=0
    End If
    #endmacro
    '==================  LOOP TWICE =======================
    For k  =0 To Len(s_in)-1
        ctr2+=1:check_instring()
    Next k
    If ctr Then Redim result(1 To ctr): ctr=0:ctr2=0 Else  Return 0
    For k  =0 To Len(s_in)-1
        ctr2+=1:split()
    Next k
    '===================== Last one ========================
    If ctr2>0 Then
        Redim Preserve result(1 To ctr+1)
        result(ctr+1)=Mid(s_in,k+1-ctr2,ctr2)
    End If
    Return Ubound(result)
End Function


Dim As Double t=Timer
Dim As String text=LoadFile("MDG_Export_20181003_012728491.csv")
'Dim As String text=Loadfile("MDG_Export_20181002_120726411.csv")

Redim As String s(),s2(),y()
Dim As Long column
Dim As Long i,i2
Dim As Double d
StringSplit(text,Chr(10),s()) 'split on new line
StringSplit(s(1),",",y())    'get the header strings

For z As Long=1991 To 2015
    If z=2000 Then Color 15,8 Else Color 15,0
    i=0:i2=0:d=0
    Dim As String yr=Str(z)
    For n As Long=Lbound(y) To Ubound(y)
        If y(n)=yr Then column=n:Exit For 'get column from header titles
    Next
    For n As Long=Lbound(s) To Ubound(s)
        If Instr(s(n),"Population undernourished, percentage") Then
            i2+=1      'total readings
            Var cpy=s(n)
            FindAndReplace(cpy,", ",Chr(0))
            stringsplit(cpy,",",s2())
            s2(column)=Trim(s2(column),Chr(34))
            If isnumber(s2(column)) Then  d+=Val(s2(column)):i+=1 'valid readings
        End If
    Next n
    If z=1991 Then Print "total readings = ";i2;" for Population undernourished, percentage":print
    Print "For Year ";yr;tab(20);"average = ";d/i;tab(60);"(";i;"  valid readings)"
   
    Print
Next z
Print "Time taken for all runs ";Timer-t

Print "done"
'Micronesia, Federated States of

Sleep 

The number of undernourished seems to be falling.
caseih
Posts: 1300
Joined: Feb 26, 2007 5:32

Re: 64-bit asm woes

Postby caseih » Oct 05, 2018 18:55

I'm not completely clear in my remembrance of significant figures, but I'm pretty sure the correct average of that field should be 16.0%. I'm not sure if the significant figures should be 3 digits or 4 digits. Not that it matters for our case! But doing real data analysis, it might.
jj2007
Posts: 879
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: 64-bit asm woes

Postby jj2007 » Oct 05, 2018 19:04

dodicat wrote:jj2007
I found the problem I had with the average.
"Micronesia, Federated States of" has a comma in it.
So this comma in a comma seperated file is in an unusual place.
Yes indeed, as noted earlier:
jj2007 wrote:Check e.g. the Korea value in line 18822, it should be 37.9. The problem here is that column 2 is Korea, Democratic People's Republic of - csv is a tricky format ;-)

However, the format allows commas inside strings:

Code: Select all

"408","Korea, Democratic People's Republic of","580","Y","Population ...
"583","Micronesia, Federated States of","580","Y","Population ...

But I see you managed to handle it correctly. With some more compiler optimisations, one might even find a solution that beats assembly...

Code: Select all

Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz

14 ms for loading 44553 rows
17 ms for processing 234 matches (of which 171 valid) with an average of 15.996

FB:
Time taken for the 2000 run  0.05290798947464737 (loading and splitting not included)

With -gen gcc -Wc -Ofast (version 8.1.0), it's only a factor 3 ;-)

@caseih: Perfectly right, but we took the M$ Excel value as a reference and wanted to make sure that our results are identical.
dodicat
Posts: 5221
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: 64-bit asm woes

Postby dodicat » Oct 05, 2018 20:24

8.2 is out.
8.1 is now obsolete< out of date, outdated, outmoded, old-fashioned;,no longer in use, disused, fallen into disuse, superannuated, outworn, antiquated, antediluvian, anachronistic, discarded, discontinued, old, dated, antique, archaic, ancient, fossilized, extinct, defunct, dead, bygone, out of fashion, out, behind the times; démodé, passé, old hat, out of the ark, geriatric,past its sell-by date>
marcov
Posts: 2643
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: 64-bit asm woes

Postby marcov » Oct 05, 2018 20:56

dodicat wrote:8.2 is out.
8.1 is now obsolete< out of date, outdated, outmoded, old-fashioned;,no longer in use, disused, fallen into disuse, superannuated, outworn, antiquated, antediluvian, anachronistic, discarded, discontinued, old, dated, antique, archaic, ancient, fossilized, extinct, defunct, dead, bygone, out of fashion, out, behind the times; démodé, passé, old hat, out of the ark, geriatric,past its sell-by date>


Or, in short: legacy.
deltarho[1859]
Posts: 1650
Joined: Jan 02, 2017 0:34
Location: UK

Re: 64-bit asm woes

Postby deltarho[1859] » Oct 06, 2018 0:19

According to St_W: "There doesn't seem to be a gcc 8.2 build from the mingw-w64 project as of now"

One: Are you still using Internet Explorer?
Two: Yes.
One: Have you not heard of Chrome or Firefox?
Two: Yes, but my bulletproof vest is at the cleaners.
One: Bulletproof vest?
Two: Oh, yes. I wouldn't wander too far from Microsoft without one.
One: So, you are still using Windows Explorer, Task Manager and NotePad?
Two: What else?
One: Blimey, is that the time - must dash.
jj2007
Posts: 879
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: 64-bit asm woes

Postby jj2007 » Oct 06, 2018 1:06

dodicat wrote:8.2 is out.
Where did you get the binary? Google finds all kinds of sites, but, for example, ftp://ftp.fu-berlin.de/unix/languages/g ... gcc-8.2.0/ says the date is 26/07/18, i.e. more than two months ago. And your post sounds as if that was breaking news...

https://gcc.gnu.org/install/binaries.html
We are often asked about pre-compiled versions of GCC. While we cannot provide these for all platforms, below you’ll find links to binaries for various platforms where creating them by yourself is not easy due to various reasons.
...
Microsoft Windows:
The Cygwin project;
The MinGW and mingw-w64 projects.
Gcc is an ugly mess. I am just opening the 113MB gcc-8.2.0.tar.gz from ftp://ftp.fu-berlin.de/unix/languages/g ... gcc-8.2.0/ hoping to find inside that bloatware packet the tiny gcc.exe that, maybe, is a tick better or faster than version 8.1.0... it takes ages to find the binaries, it takes ages to download them, it takes ages to extract them, and in the end it will take ages to configure them, because this bunch of gcc developers do not like the idea of one central download site where you could find the *.msi file that has been the standard for decades. Disgusting.
Last edited by jj2007 on Oct 06, 2018 1:26, edited 1 time in total.
deltarho[1859]
Posts: 1650
Joined: Jan 02, 2017 0:34
Location: UK

Re: 64-bit asm woes

Postby deltarho[1859] » Oct 06, 2018 1:26

@jj2007

I downloaded that a little while back and it extracts to a 321MB folder. It is no good to us - we want the "gcc 8.2 build from the mingw-w64 project" (w64 as in Windows 64-bit OS).

When I say we I mean those of us who are desirous of cutting edge because not all of us are, of course. We need 'stick in the muds' as much as those who indulge in flights of fancy. Raise your glass to polar opposition.<smile>
Last edited by deltarho[1859] on Oct 06, 2018 1:33, edited 1 time in total.

Return to “General”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 6 guests