initial commit: a mess of assembly code
[fmap.git] / x86_64_sse2_x87 / fasm / examples / x86 / win64avx.asm
blobb7d4637869b32d48f469986dfba0ab86c5769781
2 include 'format/format.inc'
4 format PE64 NX GUI 5.0
5 entry start
7 include 'ext/avx.inc'
9 section '.data' data readable writeable
11 _title db 'AVX playground',0
12 _error db 'AVX instructions are not supported.',0
14 x dq 3.14159265389
16 vector_output:
17 repeat 16, i:0
18 db 'ymm',`i,': %f,%f,%f,%f',13,10
19 end repeat
20 db 0
22 buffer db 1000h dup ?
24 section '.text' code readable executable
26 start:
28 mov eax,1
29 cpuid
30 and ecx,18000000h
31 cmp ecx,18000000h
32 jne no_AVX
33 xor ecx,ecx
34 xgetbv
35 and eax,110b
36 cmp eax,110b
37 jne no_AVX
39 vbroadcastsd ymm0, [x]
40 vsqrtpd ymm1, ymm0
42 vsubpd ymm2, ymm0, ymm1
43 vsubpd ymm3, ymm1, ymm2
45 vaddpd xmm4, xmm2, xmm3
46 vaddpd ymm5, ymm4, ymm0
48 vperm2f128 ymm6, ymm4, ymm5, 03h
49 vshufpd ymm7, ymm6, ymm5, 10010011b
51 vroundpd ymm8, ymm7, 0011b
52 vroundpd ymm9, ymm7, 0
54 sub rsp,418h
56 repeat 16, i:0
57 vmovups [rsp+10h+i*32],ymm#i
58 end repeat
60 mov r8,[rsp+10h]
61 mov r9,[rsp+18h]
62 lea rdx,[vector_output]
63 lea rcx,[buffer]
64 call [sprintf]
66 xor ecx,ecx
67 lea rdx,[buffer]
68 lea r8,[_title]
69 xor r9d,r9d
70 call [MessageBoxA]
72 xor ecx,ecx
73 call [ExitProcess]
75 no_AVX:
77 sub rsp,28h
79 xor ecx,ecx
80 lea rdx,[_error]
81 lea r8,[_title]
82 mov r9d,10h
83 call [MessageBoxA]
85 mov ecx,1
86 call [ExitProcess]
88 section '.idata' import data readable writeable
90 dd 0,0,0,RVA kernel_name,RVA kernel_table
91 dd 0,0,0,RVA user_name,RVA user_table
92 dd 0,0,0,RVA msvcrt_name,RVA msvcrt_table
93 dd 0,0,0,0,0
95 kernel_table:
96 ExitProcess dq RVA _ExitProcess
97 dq 0
98 user_table:
99 MessageBoxA dq RVA _MessageBoxA
100 dq 0
101 msvcrt_table:
102 sprintf dq RVA _sprintf
103 dq 0
105 kernel_name db 'KERNEL32.DLL',0
106 user_name db 'USER32.DLL',0
107 msvcrt_name db 'MSVCRT.DLL',0
109 _ExitProcess dw 0
110 db 'ExitProcess',0
111 _MessageBoxA dw 0
112 db 'MessageBoxA',0
113 _sprintf dw 0
114 db 'sprintf',0