News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

JWasmAVX2 source

Started by habran, November 25, 2014, 07:19:31 AM

Previous topic - Next topic

habran

jj2007 here you are:
and qword ptr [store],15
000000013F1911C9 48 83 A4 24 88 00 00 00 0F and         qword ptr [store],0Fh

Cod-Father

habran

ToutEnMasm I have tested source before I posted it here an I have tested it 1 minute before
and it runs flawlessly :biggrin:
I suspect that you built Debug version
Try to build Release version with Optimization: Maximize Speed (/O2) 
here is my last 64bit build from this source
Cod-Father

habran

I have spotted that some people downloaded sources without H folder
If you don't use this headers you will not have AVX2 built in
Do not build Debug version but Release version
Debug version of JWasm in 64bit has got a bug from original source
Cod-Father

habran

jj2007, using ebp or rbp for a stack frame is not shorter but apposite because of the overhead

00941097 55                   push        ebp 
00941098 8B EC                mov         ebp,esp
................
00941227 8B E5                mov         esp,ebp 
00941229 5D                   pop         ebp 
0094122A C2 10 00             ret         10h 


let alone that ebp is not available for use ;)
Cod-Father

jj2007

Quote from: habran on November 26, 2014, 06:19:22 AM
jj2007 here you are:
and qword ptr [store],15
000000013F1911C9 48 83 A4 24 88 00 00 00 0F and         qword ptr [store],0Fh


Oops, 9 bytes??? Intel is crazy, and dword ptr [eax+10h], 15 costs only 4 bytes :(

habran

it is 5 bytes on 64 bit sistem when running 32 bit APS
00E7109D 83 64 24 1C 0F       and         dword ptr [bAVX],0Fh
Cod-Father

TouEnMasm

Hello,
The version you have posted in #16,made the same thing.
Quote
Win64_8.asm: 376 lines, 3 passes, 0 ms, 0 warnings, 0 errors
Error A2168: General Failure
The first version you have posted in #1,work for me.She is in the JaWasm zip
with vc express 2013 i have further tests with various envirronnements (AMD64,...),aways same answer.
The compile i have made with your source codes is a release version with O2,I have made a test with your own project files also.
Quote
Intel(R) Core(TM) i3-4150 CPU @ 3.50GHz
Fa is a musical note to play with CL

habran

ToutEnMasm I don't know what to say because no one else complained
I am curious if anyone else had the same problem as you
I have rebuild and tested binaries and no problem here
Use that version which works for you until we see if other people have the same problem
It could be posible that JWasm.targets are wrong
Cod-Father

habran

here are JWasm targets

they suppose to be put here:C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations
Cod-Father

TouEnMasm

Here the better information I can have on the failure main.c line 127 (do while):

it is in isctype.c line 56
Quote
extern "C" int __cdecl _chvalidator(
        int c,
        int mask
        )
{
        _ASSERTE(c >= -1 && c <= 255);           //line 56 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        return _chvalidator_l(NULL, c, mask);
}
Fa is a musical note to play with CL

habran


/***
* __chvalidator
*
* Purpose:
*       This function is called by character testing functions in debug
*       versions. This function test for validation of c as character.
*       For improvement in performance, it is not used in non-debug
*       version.  It is available in the static single-thread non-debug
*       build, though, just in case C code that includes ctype.h is compiled
*       /D_DEBUG /ML.
*
*******************************************************************************/

It looks like you are building debug version :icon_eek:
in main.c line 124
try to use instead of:
strcpy( &fname[dirsize], finfo.name );
this:
wcscpy( &fname[dirsize], finfo.name );
Cod-Father

habran

ToutEnMasm, you are probably using your version of include files for assembling
I would strongly suggest you to use WinInc from Japhet's sight until you are sure that your version is working fine :biggrin:
Cod-Father

TouEnMasm


I have build a debug to try find the bug.
There is no include file in the sample.
Fa is a musical note to play with CL

habran

You need include when you assemble your ASM sources, that's what JWasm.exe is for
I suspect that the error is in your SDK that's why you have general failure error
because you can build JWasm from C sources but you can not build your ASM project :biggrin:
You use VC13 to COMPILE C sources and JWasm.exe to  ASSEMBLE ASM sources
As you can see no one else has problem but you ;)
Cod-Father

TouEnMasm

Quote
You need include when you assemble your ASM sources
Wrong!
It is the sample provided with the  JWasm212bw.zip
All defines are with the code

Without any source code I get this message in windbg
Quote
-- LuaPriv initialized--
failed to set heap information 00000057
VERIFIER STOP 000000000000D02F: pid 0x186C: FatalExit was called


Quote

;--- create a 64-bit binary with -pe cmdline option
;---
;---   JWasm -pe Win64_8.asm
comment µ
    .x64                ; -pe requires to set cpu, model & language
    .model flat, fastcall

    option casemap:none
    option frame:auto   ; generate SEH-compatible prologues and epilogues
    option win64:3      ; init shadow space, reserve stack at PROC level
µ
;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\crt\src\isctype.c
;comment µ
    .x64                ; -pe requires to set cpu, model & language
    .model flat, fastcall

option casemap : none
option win64 : 7
option frame : auto
option stackbase : rsp
    .xmm


.NOLIST
includelib kernel32.lib
includelib user32.lib
includelib gdi32.lib

;--- resource IDs
IDR_MENU1   EQU 100
IDR_BITMAP1 EQU 101
IDM_EXIT    EQU 1000

NULL      equ 0
LPSTR     typedef ptr
LPVOID    typedef ptr
UINT      typedef DWORD
BOOL      typedef DWORD

;--- winbase definitions
HINSTANCE typedef ptr

;--- winuser definitions
HWND      typedef ptr
HMENU     typedef ptr
HICON     typedef ptr
HBRUSH    typedef ptr
HCURSOR   typedef ptr
HDC       typedef ptr
HBITMAP   typedef ptr
WPARAM    typedef ptr
LPARAM    typedef QWORD

WS_OVERLAPPEDWINDOW equ 0CF0000h
CW_USEDEFAULT  equ 80000000h
SW_SHOWDEFAULT equ 10
SW_SHOWNORMAL  equ 1
IDC_ARROW      equ 32512
IDI_APPLICATION equ 32512
CS_VREDRAW     equ 1
CS_HREDRAW     equ 2
COLOR_WINDOW   equ 5

WM_DESTROY     equ 2
WM_PAINT       equ 000Fh
WM_COMMAND     equ 0111h

proto_WNDPROC typedef proto :HWND,:QWORD,:WPARAM,:LPARAM
WNDPROC typedef ptr proto_WNDPROC

WNDCLASSEXA struct 8
cbSize          DWORD   ?
style           DWORD   ?
lpfnWndProc     WNDPROC ?
cbClsExtra      DWORD   ?
cbWndExtra      DWORD   ?
hInstance       HINSTANCE ?
hIcon           HICON   ?
hCursor         HCURSOR ?
hbrBackground   HBRUSH  ?
lpszMenuName    LPSTR   ?
lpszClassName   LPSTR   ?
hIconSm         HICON   ?
WNDCLASSEXA ends

POINT   struct
x   SDWORD  ?
y   SDWORD  ?
POINT   ends

MSG struct 8
hwnd    HWND    ?
message DWORD   ?
wParam  WPARAM  ?
lParam  LPARAM  ?
time    DWORD   ?
pt      POINT   <>
MSG ends

RECT struct
left    SDWORD  ?
top     SDWORD  ?
right   SDWORD  ?
bottom  SDWORD  ?
RECT ends

PAINTSTRUCT struct 8
hdc         HDC  ?
fErase      BOOL ?
rcPaint     RECT <>
fRestore    BOOL ?
fIncUpdate  BOOL ?
rgbReserved BYTE 32 dup (?)
PAINTSTRUCT ends

;--- wingdi definitions

DIB_RGB_COLORS  EQU 0
SRCCOPY         EQU 00CC0020h

HGDIOBJ  typedef ptr

BITMAPINFOHEADER struct
biSize          DWORD   ?
biWidth         SDWORD  ?
biHeight        SDWORD  ?
biPlanes        WORD    ?
biBitCount      WORD    ?
biCompression   DWORD   ?
biSizeImage     DWORD   ?
biXPelsPerMeter SDWORD  ?
biYPelsPerMeter SDWORD  ?
biClrUsed       DWORD   ?
biClrImportant  DWORD   ?
BITMAPINFOHEADER ends

    option dllimport:<kernel32.dll>
GetModuleHandleA proto :LPSTR
GetCommandLineA  proto
ExitProcess      proto :UINT

    option dllimport:<user32.dll>
BeginPaint       proto :HWND, :ptr PAINTSTRUCT
CreateWindowExA  proto :DWORD, :LPSTR, :LPSTR, :DWORD, :SDWORD, :SDWORD, :SDWORD, :SDWORD, :HWND, :HMENU, :HINSTANCE, :LPVOID
DefWindowProcA   proto :HWND, :UINT, :WPARAM, :LPARAM
DestroyWindow    proto :HWND
DispatchMessageA proto :ptr MSG
EndPaint         proto :HWND, :ptr PAINTSTRUCT
GetClientRect    proto :HWND, :ptr RECT
GetMessageA      proto :ptr MSG, :HWND, :SDWORD, :SDWORD
LoadBitmapA      proto :HINSTANCE, :LPSTR
LoadCursorA      proto :HINSTANCE, :LPSTR
LoadIconA        proto :HINSTANCE, :LPSTR
PostQuitMessage  proto :SDWORD
RegisterClassExA proto :ptr WNDCLASSEXA
ShowWindow       proto :HWND, :SDWORD
TranslateMessage proto :ptr MSG
UpdateWindow     proto :HWND

    option DLLIMPORT:<gdi32.dll>
BitBlt             proto :HDC, :DWORD, :DWORD, :DWORD, :DWORD, :HDC, :DWORD, :DWORD, :DWORD
CreateCompatibleDC proto :HDC
DeleteDC           proto :HDC
GetDIBits          proto :HDC, :HBITMAP, :DWORD, :DWORD, :ptr, :ptr BITMAPINFO, :DWORD
SelectObject       proto :HDC, :HGDIOBJ
    option dllimport:none

WinMain proto :HINSTANCE, :HINSTANCE, :LPSTR, :UINT

    .data

ClassName db "SimpleWinClass",0
AppName  db "Bitmap rendering",0

    .data?

hInstance HINSTANCE ?
hBitmap   HBITMAP ?
CommandLine LPSTR ?

    .code

;WinMainCRTStartup proc FRAME
start:
   .LISTALL
   mov eax,sizeof HWND
   .NOLIST
    invoke GetModuleHandleA, NULL
    mov    hInstance, rax
    invoke GetCommandLineA
    mov    CommandLine, rax
    invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
    invoke ExitProcess, eax

;WinMainCRTStartup endp

WinMain proc FRAME hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:UINT

    LOCAL wc:WNDCLASSEXA
    LOCAL msg:MSG
    LOCAL hwnd:HWND

    invoke LoadBitmapA, hInst, IDR_BITMAP1
    mov   hBitmap, rax

    mov   wc.cbSize, SIZEOF WNDCLASSEXA
    mov   wc.style, CS_HREDRAW or CS_VREDRAW
    lea   rax, [WndProc]
    mov   wc.lpfnWndProc, rax
    mov   wc.cbClsExtra, 0
    mov   wc.cbWndExtra, 0
    mov   rcx, hInst
    mov   wc.hInstance, rcx
    mov   wc.hbrBackground, COLOR_WINDOW+1
    mov   wc.lpszMenuName, IDR_MENU1
    lea   rax, [ClassName]
    mov   wc.lpszClassName, rax
    invoke LoadIconA, NULL, IDI_APPLICATION
    mov   wc.hIcon, rax
    mov   wc.hIconSm, rax
    invoke LoadCursorA, NULL, IDC_ARROW
    mov   wc.hCursor,rax
    invoke RegisterClassExA, addr wc
    invoke CreateWindowExA, NULL, ADDR ClassName, ADDR AppName,
           WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
           CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL, NULL,
           hInst, NULL
    mov   hwnd,rax
    invoke ShowWindow, hwnd, SW_SHOWNORMAL
    invoke UpdateWindow, hwnd
    .while (1)
        invoke GetMessageA, ADDR msg, NULL, 0, 0
        .break .if (!eax)
        invoke TranslateMessage, ADDR msg
        invoke DispatchMessageA, ADDR msg
    .endw
    mov   rax, msg.wParam
    ret
WinMain endp

WndProc proc FRAME hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

local hdc2:HDC
local ps:PAINTSTRUCT
local rect:RECT
local bmi:BITMAPINFOHEADER

    .if edx == WM_DESTROY
        invoke PostQuitMessage, NULL
        xor rax,rax
    .elseif edx == WM_COMMAND
        .if wParam == IDM_EXIT
            invoke DestroyWindow, hWnd
        .endif
        xor eax, eax
    .elseif edx == WM_PAINT
        invoke BeginPaint, hWnd, addr ps
        invoke CreateCompatibleDC, ps.hdc
        mov hdc2, rax
        invoke SelectObject, hdc2, hBitmap
        mov bmi.biSize, sizeof BITMAPINFOHEADER
        mov bmi.biBitCount, 0
        invoke GetDIBits, hdc2, hBitmap, 0, 0, 0, addr bmi, DIB_RGB_COLORS
        invoke GetClientRect, hWnd, addr rect
        mov r8d, rect.right
        sub r8d, bmi.biWidth
        jnc @F
        xor r8d, r8d
@@:
        shr r8d, 1
        mov r9d, rect.bottom
        sub r9d, bmi.biHeight
        jnc @F
        xor r9d, r9d
@@:
        shr r9d, 1
        invoke BitBlt, ps.hdc, r8d, r9d, bmi.biWidth, bmi.biHeight, hdc2, 0, 0, SRCCOPY
        invoke DeleteDC, hdc2
        invoke EndPaint, hWnd, addr ps

        xor eax,eax
    .else
        invoke DefWindowProcA, rcx, edx, r8, r9
    .endif
    ret
WndProc endp

if 1 ;for -pe

RT_BITMAP EQU 2
RT_MENU   EQU 4

;--- menu resource flags
MF_POPUP   EQU 10h
MF_END     EQU 80h

IMAGE_RESOURCE_DIRECTORY struct
Characteristics      DWORD ?
TimeDateStamp        DWORD ?
MajorVersion         WORD  ?
MinorVersion         WORD  ?
NumberOfNamedEntries WORD  ?
NumberOfIdEntries    WORD  ?
IMAGE_RESOURCE_DIRECTORY ends

IMAGE_RESOURCE_DIRECTORY_ENTRY struct
union
r0      RECORD NameIsString:1, NameOffset:31
Name_   DWORD   ?
Id      WORD    ?
ends
union
OffsetToData DWORD   ?
r1           RECORD   DataIsDirectory:1, OffsetToDirectory:31
ends
IMAGE_RESOURCE_DIRECTORY_ENTRY ends

IMAGE_RESOURCE_DATA_ENTRY struct
OffsetToData DWORD ?
Size_        DWORD ?
CodePage     DWORD ?
Reserved     DWORD ?
IMAGE_RESOURCE_DATA_ENTRY ends

    option dotname

.rsrc segment dword read FLAT public 'RSRC'

;--- define menu IDR_MENU1 and bitmap IDR_BITMAP1

;--- root level: enum the resource types
      IMAGE_RESOURCE_DIRECTORY <0,0,0,0,0,2>
      IMAGE_RESOURCE_DIRECTORY_ENTRY < <RT_BITMAP>, <SECTIONREL bms   + 80000000h> >
      IMAGE_RESOURCE_DIRECTORY_ENTRY < <RT_MENU>,   <SECTIONREL menus + 80000000h> >

;--- second level: enum the IDs of resource type X
bms   IMAGE_RESOURCE_DIRECTORY <0,0,0,0,0,1>
      IMAGE_RESOURCE_DIRECTORY_ENTRY < <IDR_BITMAP1>, <SECTIONREL bm1   + 80000000h> >
menus IMAGE_RESOURCE_DIRECTORY <0,0,0,0,0,1>
      IMAGE_RESOURCE_DIRECTORY_ENTRY < <IDR_MENU1>,   <SECTIONREL menu1 + 80000000h> >

;--- third level: enum the languages of ID X
bm1   IMAGE_RESOURCE_DIRECTORY <0,0,0,0,0,1>
      IMAGE_RESOURCE_DIRECTORY_ENTRY < <409h>, <SECTIONREL bm1_l1> >
menu1 IMAGE_RESOURCE_DIRECTORY <0,0,0,0,0,1>
      IMAGE_RESOURCE_DIRECTORY_ENTRY < <409h>, <SECTIONREL m1_l1> >

;--- last level: define the resource data
;--- data for menu IDR_MENU1, language 409h
m1_l1 IMAGE_RESOURCE_DATA_ENTRY <IMAGEREL m1_l1_data, size_m1_l1, 0, 0>
m1_l1_data dw 0,0   ;menu header
    dw MF_POPUP or MF_END, '&','F','i','l','e',0
    dw MF_END, IDM_EXIT,   'E','&','x','i','t',0
size_m1_l1 equ $ - m1_l1_data
    align 4

;--- data for bitmap IDR_BITMAP1
bm1_l1 IMAGE_RESOURCE_DATA_ENTRY <IMAGEREL bm1_l1_data, size_bm1_l1, 0, 0>
bm1_l1_data label word
    incbin <Win32_8.bmp>,14   ;skip bitmap file header
size_bm1_l1 equ $ - ( bm1_l1_data )

.rsrc ends

;--- set /subsystem:windows
;--- the PE header is stored in section .hdr$2
    option dotname
.hdr$2 segment DWORD FLAT public 'HDR'
    org 5Ch ;position to IMAGE_NT_HEADER64.OptionalHeader.Subsystem
    dw 2    ;2=subsystem windows
.hdr$2 ends

endif

end start ;WinMainCRTStartup

Fa is a musical note to play with CL