flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Programming Language Design > On my new assembler

Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next
Author
Thread Post new topic Reply to topic
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland
I have finished the AVX macros, AVX2 and AVX-512 should be next. And then also lots of small instruction sets that need to be defined separately.

PS. I have converted this small snippet from fasm 1 that I once used to test the operation of AVX instructions:

Code:

include 'format/format.inc'
include 'avx.inc'

format PE64 NX GUI 5.0
entry start

section '.data' data readable writeable

  _title db 'AVX playground',0
  _error db 'AVX instructions are not supported.',0

  x dq 3.14159265389

  vectors_output:
    repeat 16i:0
        db 'ymm',`i,': %f,%f,%f,%f',13,10
    end repeat
    db 0

  buffer db 1000h dup ?

section '.text' code readable executable

  start:

        mov     eax,1
        cpuid
        and     ecx,18000000h
        cmp     ecx,18000000h
        jne     no_AVX
        xor     ecx,ecx
        xgetbv
        and     eax,110b
        cmp     eax,110b
        jne     no_AVX

        vbroadcastsd ymm0,[x]
        vsqrtpd ymm1,ymm0
        vsubpd ymm2,ymm0,ymm1
        vsubpd ymm3,ymm1,ymm2

        vaddpd xmm4,xmm2,xmm3
        vaddpd ymm5,ymm4,ymm0
        vperm2f128 ymm6,ymm4,ymm5,03h

        vsqrtpd ymm7,ymm6

        vshufpd ymm8,ymm6,ymm5,10010011b
        vroundpd ymm9,ymm8,0011b
        vroundpd ymm10,ymm8,0

        sub     rsp,418h

    repeat 16i:0
        vmovups [rsp+10h+i*32],ymm#i
    end repeat

        mov     r8,[rsp+10h]
        mov     r9,[rsp+18h]
        lea     rdx,[vectors_output]
        lea     rcx,[buffer]
        call    [sprintf]

        xor     ecx,ecx
        lea     rdx,[buffer]
        lea     r8,[_title]
        xor     r9d,r9d
        call    [MessageBoxA]

        xor     ecx,ecx
        call    [ExitProcess]

  no_AVX:

        sub     rsp,28h

        xor     ecx,ecx
        lea     rdx,[_error]
        lea     r8,[_title]
        mov     r9d,10h
        call    [MessageBoxA]

        mov     ecx,1
        call    [ExitProcess]

section '.idata' import data readable writeable

  dd 0,0,0,RVA kernel_name,RVA kernel_table
  dd 0,0,0,RVA user_name,RVA user_table
  dd 0,0,0,RVA msvcrt_name,RVA msvcrt_table
  dd 0,0,0,0,0

  kernel_table:
    ExitProcess dq RVA _ExitProcess
    dq 0
  user_table:
    MessageBoxA dq RVA _MessageBoxA
    dq 0
  msvcrt_table:
    sprintf dq RVA _sprintf
    dq 0

  kernel_name db 'KERNEL32.DLL',0
  user_name db 'USER32.DLL',0
  msvcrt_name db 'MSVCRT.DLL',0

  _ExitProcess dw 0
    db 'ExitProcess',0
  _MessageBoxA dw 0
    db 'MessageBoxA',0
  _sprintf dw 0
    db 'sprintf',0

This has been lying around on my drive for years, I think that I should have made it into one of the official examples at some point.
Post 02 Feb 2017, 19:35
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland
Turns out writing AVX2 macros went quickly. And AVX-512 ones are already underway.
Post 03 Feb 2017, 18:05
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland
The "hq7d2" release introduces a new variant of POSTPONE directive, invoked with "postpone ?" construction. The assembler refrains from processing such block until it has nothing else to do, so it is a good place for tasks like computing checksums or constructing and displaying summaries/listings, as it allows to avoid processing these things unnecessarily in the intermediate passes. I have modified the PE formatting macros so that they use this feature when computing PE checksum, and I made them compute checksum always, as fasm 1 did.

Note that it should not be recommended to use any values defined inside "postpone ?" block outside of it, as it may interfere with the resolving process and make things worse than when this feature was not used.

I have also prepared a copy of fasmg repository that can be browsed online, for anyone interested.
Post 06 Mar 2017, 14:29
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 323
My question how load 256 bits ?
MyVal dd 1.0,2.0,3.0,4.0,5.0,6.0,1.0,7.0
I write vmovups ymm1,[MyVal] but fasm get me error operand size do not match !
How say fasm i want load 256 bits in ymm1 from MyVal ?

Use qqword ?
vmovups ymm1,qqword [MyVal]
Post 07 Mar 2017, 06:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14929
Location: 6EQUJ5
Roman: are you asking about fasmg or fasm?
Post 07 Mar 2017, 07:29
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland

Roman wrote:
My question how load 256 bits ?
MyVal dd 1.0,2.0,3.0,4.0,5.0,6.0,1.0,7.0
I write vmovups ymm1,[MyVal] but fasm get me error operand size do not match !
How say fasm i want load 256 bits in ymm1 from MyVal ?

Use qqword ?
vmovups ymm1,qqword [MyVal]

Both fasm 1 and fasmg allow to define a label with associated size:

Code:
label MyVal:qqword
dd 1.0,2.0,3.0,4.0,5.0,6.0,1.0,7.0

You can use "yword" in place of "qqword" if you prefer. And with fasmg you can also specify a size as a plain number (counting bytes):

Code:
label MyVal:32

Post 07 Mar 2017, 07:41
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland
With another update I've added macros for COFF output format and now all formats that are supported by fasm 1 are also available with "format" macro I made for fasmg. With this being complete I may now start thinking about implementing some formats that fasm 1 does not have. Mach-O perhaps?
Post 08 Apr 2017, 23:16
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 256
OMF? Razz
Post 09 Apr 2017, 00:09
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland
Yes, that's another option, I even thought it could be combined with instruction set macros that would emulate the syntax of old DOS assemblers to assemble things like PC BIOS sources. It could be interesting, though perhaps only to a couple of people.

On the other hand Mach-O format is something that still haunts me, because I promised to implement it one day (but that was back when I thought that I would get a machine for testing) and I never even started it. And making an OS X version of fasmg and even fasm 1 might be a good idea.
Post 09 Apr 2017, 07:25
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland
There are some updates to the assembler core. In version "hroxx" I have added the -I command line switch which is a very versatile variation on theme of defining symbols from command line. I've been planning this feature for a long time, but it took me a while to figure out how to best implement it.

And release "hrp59" brings fixes to two bugs that I discovered while testing my new Windows headers. Because fasmg allows macros to be forward-referenced, it is valid to start a source like this:

Code:
format PE GUI 4.0
entry start

include 'win32w.inc'

Even though the "format" macro is defined inside FORMAT.INC which in turn is included by WIN32W.INC, it still can be called from the first line of source thanks to forward-referencing. By testing this on multiple examples from fasm's packages I managed to put enough stress of fasmg's core that a couple of bugs showed up. I'm surprised that I have not discovered them earlier - perhaps this is the first time that this level of complexity was reached with fasmg's macros?
Post 15 Apr 2017, 20:59
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1571
Location: Ukraine
thanks for the -i switch!
there are some cases which I wish to be switchable except debug/release mode: sometimes I wish to include hex.inc, sometimes I don't, etc.

_________________
UNICODE forever!
Post 16 Apr 2017, 07:46
View user's profile Send private message Visit poster's website Reply with quote
jacobly



Joined: 04 Feb 2016
Posts: 15
I'm not sure if this is supposed to work, but it would be useful:

Code:
macro a
        local b
        namespace b
        end namespace
end macro
a


Defining b doesn't seem to help, it seems to always error on any macro it encounters after opening the namespace.
Post 13 Jun 2017, 09:22
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland

jacobly wrote:
I'm not sure if this is supposed to work, but it would be useful:

Code:
macro a
        local b
        namespace b
        end namespace
end macro
a


Defining b doesn't seem to help, it seems to always error on any macro it encounters after opening the namespace.

This is a side-effect of a currently undocumented feature, described here. Even though it was initially accidental it turned out to have some interesting uses and I may decide to make it official.
Post 13 Jun 2017, 09:29
View user's profile Send private message Visit poster's website Reply with quote
jacobly



Joined: 04 Feb 2016
Posts: 15
Is there a reason for not being able to use irpv on variables defined with =? I did notice you can do:

Code:
while defined symbol
    ; use symbol
    restore symbol
end while


but that is backwards, destructive, and can't use indx. There's also a method using a repeat after every assignment:

Code:
a =: 0
repeat 1x:a
        list equ x
end repeat
a =: 1
repeat 1x:a
        list equ x
end repeat
a =: 2
repeat 1x:a
        list equ x
end repeat
irpv eltlist
        repeat 1x:elt
                display `x10
        end repeat
end irpv


but that seems overly verbose when it seems like irpv could just do the same thing as repeat.

After some more tests I realized that repeat is already reasonably restricted to constant polys, but "Error: value of type not allowed in this context." does indeed seem reasonable for non-constant polys encountered during irpv, just not for constant ones.
Post 12 Jul 2017, 13:59
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland

jacobly wrote:
Is there a reason for not being able to use irpv on variables defined with =?

The iterator defined by IRPV is a parameter, so it can only have symbolic value (text substitution). To let it iterate through other kinds of values, some kind of intermediate variable would need to be defined, so for example "irpv elt, list" in an iteration where value of "list" is numeric would need to set the value of "elt" parameter to a symbol "xxx" and the value of "xxx" would need to be set to the value taken from the "list" stack. This might be possible with come recognition context tricks, but I see no elegant solution at the moment.
Post 12 Jul 2017, 19:37
View user's profile Send private message Visit poster's website Reply with quote
jacobly



Joined: 04 Feb 2016
Posts: 15
That makes sense, I was just hoping that it could be done in the same way that repeat 1, x:1 manages to create a parameter x that substitutes to `x = "1".

On an unrelated note, I was having problems understanding and debugging multiple pass issues, so I ended up creating a debug version of fasmg that outputs the display buffer every pass (usually with a small pass limit < 10 or so). This was so invaluable that I was thinking maybe it could be added as a command line argument.
Post 13 Jul 2017, 01:46
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland

jacobly wrote:
That makes sense, I was just hoping that it could be done in the same way that repeat 1, x:1 manages to create a parameter x that substitutes to `x = "1".

Such parameter has a value which is actually equivalent to a text containing decimal digits (you may see it when you concatenate the counter with a name of a label). But this would not work with more complex values.


jacobly wrote:
On an unrelated note, I was having problems understanding and debugging multiple pass issues, so I ended up creating a debug version of fasmg that outputs the display buffer every pass (usually with a small pass limit < 10 or so). This was so invaluable that I was thinking maybe it could be added as a command line argument.

It would be an interesting option to have. Perhaps I could add it as another level to "-v" switch ("-v2"?).
Post 13 Jul 2017, 14:22
View user's profile Send private message Visit poster's website Reply with quote
jacobly



Joined: 04 Feb 2016
Posts: 15
The libc version of fasmg crashes due to a corrupted heap because "ccall getenv,esi" can clobber ecx.
Post 26 Jul 2017, 07:42
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland
Thank you. I have not tested this version much.
Post 26 Jul 2017, 09:42
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6437
Location: Kraków, Poland

jacobly wrote:
That makes sense, I was just hoping that it could be done in the same way that repeat 1, x:1 manages to create a parameter x that substitutes to `x = "1".

I gave it a more thought and I realized that all the tools required to make it work were already present in the engine. While this makes IRPV more complex in both definition and implementation, I think that it is worth it to make the directive behave more intuitively.

Now you can use IRPV to iterate through all kinds of values (it is never going to give an error). When a given value is not symbolic, there are two cases. When the value is a plain positive number, the parameter works similarly to the counter of REPEAT and it contains a text with decimal digits. For any other kind of value a proxy variable is created, and the parameter contains the identifier of this variable - which is simply the "." identifier equipped with appropriate recognition context.

You may try it out with the hvic8 version.
Post 27 Jul 2017, 18:15
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next

< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.