From a7c80ae858eb85b58908f9893bec1475fa92a3ee Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Dec 2016 10:22:13 +0100 Subject: [PATCH 01/13] - fixed: The message for invalid class extensions did not pass the class name to the error function. --- src/scripting/codegeneration/codegen.cpp | 9 ++++----- src/scripting/zscript/zcc_compile.cpp | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index 3895441d8..16025c0d0 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -1,10 +1,10 @@ /* -** thingdef_expression.cpp +** codegen.cpp ** -** Expression evaluation +** Compiler backend / code generation for ZScript and DECORATE ** **--------------------------------------------------------------------------- -** Copyright 2008 Christoph Oelckers +** Copyright 2008-2016 Christoph Oelckers ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without @@ -6586,8 +6586,7 @@ ExpEmit FxStructMember::Emit(VMFunctionBuilder *build) //========================================================================== // -// not really needed at the moment but may become useful with meta properties -// and some other class-specific extensions. +// // //========================================================================== diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 2b4974bda..c4c524817 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -74,7 +74,7 @@ void ZCCCompiler::ProcessClass(ZCC_Class *cnode, PSymbolTreeNode *treenode) } if (cls == nullptr) { - Error(cnode, "Class %s cannot be found in the current translation unit."); + Error(cnode, "Class %s cannot be found in the current translation unit.", FName(cnode->NodeName).GetChars()); return; } } From c4ca70101dc6721b72e778b928e45e395233c47d Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sat, 10 Dec 2016 01:09:05 +0100 Subject: [PATCH 02/13] Fix console window geometry size --- src/win32/i_main.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index 0931aff99..2a99f4364 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -680,17 +680,23 @@ void I_SetWndProc() void RestoreConView() { + HDC screenDC = GetDC(0); + int dpi = GetDeviceCaps(screenDC, LOGPIXELSX); + ReleaseDC(0, screenDC); + int width = (512 * dpi + 96 / 2) / 96; + int height = (384 * dpi + 96 / 2) / 96; + // Make sure the window has a frame in case it was fullscreened. SetWindowLongPtr (Window, GWL_STYLE, WS_VISIBLE|WS_OVERLAPPEDWINDOW); if (GetWindowLong (Window, GWL_EXSTYLE) & WS_EX_TOPMOST) { - SetWindowPos (Window, HWND_BOTTOM, 0, 0, 512, 384, + SetWindowPos (Window, HWND_BOTTOM, 0, 0, width, height, SWP_DRAWFRAME | SWP_NOCOPYBITS | SWP_NOMOVE); SetWindowPos (Window, HWND_TOP, 0, 0, 0, 0, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE); } else { - SetWindowPos (Window, NULL, 0, 0, 512, 384, + SetWindowPos (Window, NULL, 0, 0, width, height, SWP_DRAWFRAME | SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER); } @@ -935,8 +941,11 @@ void DoMain (HINSTANCE hInstance) progdir.Truncate((long)strlen(program)); progdir.UnlockBuffer(); - width = 512; - height = 384; + HDC screenDC = GetDC(0); + int dpi = GetDeviceCaps(screenDC, LOGPIXELSX); + ReleaseDC(0, screenDC); + width = (512 * dpi + 96 / 2) / 96; + height = (384 * dpi + 96 / 2) / 96; // Many Windows structures that specify their size do so with the first // element. DEVMODE is not one of those structures. From 54759782b3170c6b2d9becbc90d9d8a8691bd058 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sat, 10 Dec 2016 01:09:20 +0100 Subject: [PATCH 03/13] Fix cursor size --- src/win32/i_system.cpp | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 29ea3c4b7..93960653d 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -1375,10 +1375,16 @@ static HCURSOR CreateAlphaCursor(FTexture *cursorpic) HBITMAP color, mono; void *bits; + // Find closest integer scale factor for the monitor DPI + HDC screenDC = GetDC(0); + int dpi = GetDeviceCaps(screenDC, LOGPIXELSX); + int scale = MAX((dpi + 96 / 2 - 1) / 96, 1); + ReleaseDC(0, screenDC); + memset(&bi, 0, sizeof(bi)); bi.bV5Size = sizeof(bi); - bi.bV5Width = 32; - bi.bV5Height = 32; + bi.bV5Width = 32 * scale; + bi.bV5Height = 32 * scale; bi.bV5Planes = 1; bi.bV5BitCount = 32; bi.bV5Compression = BI_BITFIELDS; @@ -1403,7 +1409,7 @@ static HCURSOR CreateAlphaCursor(FTexture *cursorpic) } // Create an empty mask bitmap, since CreateIconIndirect requires this. - mono = CreateBitmap(32, 32, 1, 1, NULL); + mono = CreateBitmap(32 * scale, 32 * scale, 1, 1, NULL); if (mono == NULL) { DeleteObject(color); @@ -1413,10 +1419,28 @@ static HCURSOR CreateAlphaCursor(FTexture *cursorpic) // Copy cursor to the color bitmap. Note that GDI bitmaps are upside down compared // to normal conventions, so we create the FBitmap pointing at the last row and use // a negative pitch so that CopyTrueColorPixels will use GDI's orientation. - FBitmap bmp((BYTE *)bits + 31*32*4, -32*4, 32, 32); - cursorpic->CopyTrueColorPixels(&bmp, 0, 0); + if (scale == 1) + { + FBitmap bmp((BYTE *)bits + 31 * 32 * 4, -32 * 4, 32, 32); + cursorpic->CopyTrueColorPixels(&bmp, 0, 0); + } + else + { + std::vector unscaled; + unscaled.resize(32 * 32); + FBitmap bmp((BYTE *)unscaled.data() + 31 * 32 * 4, -32 * 4, 32, 32); + cursorpic->CopyTrueColorPixels(&bmp, 0, 0); + uint32_t *scaled = (uint32_t*)bits; + for (int y = 0; y < 32 * scale; y++) + { + for (int x = 0; x < 32 * scale; x++) + { + scaled[x + y * 32 * scale] = unscaled[x / scale + y / scale * 32]; + } + } + } - return CreateBitmapCursor(cursorpic->LeftOffset, cursorpic->TopOffset, mono, color); + return CreateBitmapCursor(cursorpic->LeftOffset * scale, cursorpic->TopOffset * scale, mono, color); } //========================================================================== From 0e448a64508e0028ee4aa221acf9177a92871521 Mon Sep 17 00:00:00 2001 From: WilliamFeely Date: Fri, 9 Dec 2016 20:15:59 -0500 Subject: [PATCH 04/13] Change DPI Awareness to per-monitor on Windows8.1+ --- src/win32/zdoom.exe.manifest | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/win32/zdoom.exe.manifest b/src/win32/zdoom.exe.manifest index 6265324dc..d5606ec78 100644 --- a/src/win32/zdoom.exe.manifest +++ b/src/win32/zdoom.exe.manifest @@ -14,7 +14,7 @@ - true + true/pm @@ -31,4 +31,4 @@ - \ No newline at end of file + From 6c86a33f5da70b62e0b9ae9191bcdab097478369 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Dec 2016 12:05:46 +0100 Subject: [PATCH 05/13] - fixed compilation of cursor scaling code. This reported 'std::vector' not defined, so now it just uses TArray, like the rest of ZDoom. --- src/win32/i_system.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 93960653d..9de5a2d47 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -1426,9 +1426,9 @@ static HCURSOR CreateAlphaCursor(FTexture *cursorpic) } else { - std::vector unscaled; - unscaled.resize(32 * 32); - FBitmap bmp((BYTE *)unscaled.data() + 31 * 32 * 4, -32 * 4, 32, 32); + TArray unscaled; + unscaled.Resize(32 * 32); + FBitmap bmp((BYTE *)&unscaled[0] + 31 * 32 * 4, -32 * 4, 32, 32); cursorpic->CopyTrueColorPixels(&bmp, 0, 0); uint32_t *scaled = (uint32_t*)bits; for (int y = 0; y < 32 * scale; y++) From 3563718049e304ea10c8bf92e39aafb8acf4cf78 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Dec 2016 12:12:29 +0100 Subject: [PATCH 06/13] - removed all fixed point inlines that aren't used anywhere. Note that most of the rest are only being used in one single function: R_DrawVoxel. --- src/basicinlines.h | 81 ---------------------------------------------- src/gccinlines.h | 81 ---------------------------------------------- src/mscinlines.h | 81 ---------------------------------------------- 3 files changed, 243 deletions(-) diff --git a/src/basicinlines.h b/src/basicinlines.h index 135208b81..db03232b3 100644 --- a/src/basicinlines.h +++ b/src/basicinlines.h @@ -20,102 +20,21 @@ static __forceinline SDWORD Scale (SDWORD a, SDWORD b, SDWORD c) return (SDWORD)(((SQWORD)a*b)/c); } -static __forceinline SDWORD MulScale1 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 1); } -static __forceinline SDWORD MulScale2 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 2); } -static __forceinline SDWORD MulScale3 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 3); } -static __forceinline SDWORD MulScale4 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 4); } -static __forceinline SDWORD MulScale5 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 5); } -static __forceinline SDWORD MulScale6 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 6); } -static __forceinline SDWORD MulScale7 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 7); } -static __forceinline SDWORD MulScale8 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 8); } -static __forceinline SDWORD MulScale9 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 9); } -static __forceinline SDWORD MulScale10 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 10); } -static __forceinline SDWORD MulScale11 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 11); } -static __forceinline SDWORD MulScale12 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 12); } -static __forceinline SDWORD MulScale13 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 13); } static __forceinline SDWORD MulScale14 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 14); } -static __forceinline SDWORD MulScale15 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 15); } static __forceinline SDWORD MulScale16 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 16); } -static __forceinline SDWORD MulScale17 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 17); } -static __forceinline SDWORD MulScale18 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 18); } -static __forceinline SDWORD MulScale19 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 19); } -static __forceinline SDWORD MulScale20 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 20); } -static __forceinline SDWORD MulScale21 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 21); } -static __forceinline SDWORD MulScale22 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 22); } -static __forceinline SDWORD MulScale23 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 23); } -static __forceinline SDWORD MulScale24 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 24); } -static __forceinline SDWORD MulScale25 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 25); } -static __forceinline SDWORD MulScale26 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 26); } -static __forceinline SDWORD MulScale27 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 27); } -static __forceinline SDWORD MulScale28 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 28); } -static __forceinline SDWORD MulScale29 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 29); } static __forceinline SDWORD MulScale30 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 30); } -static __forceinline SDWORD MulScale31 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 31); } static __forceinline SDWORD MulScale32 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 32); } static __forceinline DWORD UMulScale16 (DWORD a, DWORD b) { return (DWORD)(((QWORD)a * b) >> 16); } -static __forceinline SDWORD DMulScale1 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 1); } -static __forceinline SDWORD DMulScale2 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 2); } static __forceinline SDWORD DMulScale3 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 3); } -static __forceinline SDWORD DMulScale4 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 4); } -static __forceinline SDWORD DMulScale5 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 5); } static __forceinline SDWORD DMulScale6 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 6); } -static __forceinline SDWORD DMulScale7 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 7); } -static __forceinline SDWORD DMulScale8 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 8); } -static __forceinline SDWORD DMulScale9 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 9); } static __forceinline SDWORD DMulScale10 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 10); } -static __forceinline SDWORD DMulScale11 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 11); } -static __forceinline SDWORD DMulScale12 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 12); } -static __forceinline SDWORD DMulScale13 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 13); } -static __forceinline SDWORD DMulScale14 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 14); } -static __forceinline SDWORD DMulScale15 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 15); } -static __forceinline SDWORD DMulScale16 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 16); } -static __forceinline SDWORD DMulScale17 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 17); } static __forceinline SDWORD DMulScale18 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 18); } -static __forceinline SDWORD DMulScale19 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 19); } -static __forceinline SDWORD DMulScale20 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 20); } -static __forceinline SDWORD DMulScale21 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 21); } -static __forceinline SDWORD DMulScale22 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 22); } -static __forceinline SDWORD DMulScale23 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 23); } -static __forceinline SDWORD DMulScale24 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 24); } -static __forceinline SDWORD DMulScale25 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 25); } -static __forceinline SDWORD DMulScale26 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 26); } -static __forceinline SDWORD DMulScale27 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 27); } -static __forceinline SDWORD DMulScale28 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 28); } -static __forceinline SDWORD DMulScale29 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 29); } -static __forceinline SDWORD DMulScale30 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 30); } -static __forceinline SDWORD DMulScale31 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 31); } static __forceinline SDWORD DMulScale32 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 32); } -static inline SDWORD DivScale2 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 2) / b); } -static inline SDWORD DivScale3 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 3) / b); } -static inline SDWORD DivScale4 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 4) / b); } -static inline SDWORD DivScale5 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 5) / b); } static inline SDWORD DivScale6 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 6) / b); } -static inline SDWORD DivScale7 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 7) / b); } -static inline SDWORD DivScale8 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 8) / b); } -static inline SDWORD DivScale9 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 9) / b); } -static inline SDWORD DivScale10 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 10) / b); } -static inline SDWORD DivScale11 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 11) / b); } -static inline SDWORD DivScale12 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 12) / b); } -static inline SDWORD DivScale13 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 13) / b); } -static inline SDWORD DivScale14 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 14) / b); } -static inline SDWORD DivScale15 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 15) / b); } static inline SDWORD DivScale16 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 16) / b); } -static inline SDWORD DivScale17 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 17) / b); } -static inline SDWORD DivScale18 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 18) / b); } -static inline SDWORD DivScale19 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 19) / b); } -static inline SDWORD DivScale20 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 20) / b); } static inline SDWORD DivScale21 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 21) / b); } -static inline SDWORD DivScale22 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 22) / b); } -static inline SDWORD DivScale23 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 23) / b); } -static inline SDWORD DivScale24 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 24) / b); } -static inline SDWORD DivScale25 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 25) / b); } -static inline SDWORD DivScale26 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 26) / b); } -static inline SDWORD DivScale27 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 27) / b); } -static inline SDWORD DivScale28 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 28) / b); } -static inline SDWORD DivScale29 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 29) / b); } static inline SDWORD DivScale30 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 30) / b); } -static inline SDWORD DivScale31 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 31) / b); } diff --git a/src/gccinlines.h b/src/gccinlines.h index 925a0037a..20506a5a8 100644 --- a/src/gccinlines.h +++ b/src/gccinlines.h @@ -50,37 +50,9 @@ static inline SDWORD Scale (SDWORD a, SDWORD b, SDWORD c) #define MAKECONSTMulScale(s) \ static inline SDWORD MulScale##s (SDWORD a, SDWORD b) { return ((SQWORD)a * b) >> s; } -MAKECONSTMulScale(1) -MAKECONSTMulScale(2) -MAKECONSTMulScale(3) -MAKECONSTMulScale(4) -MAKECONSTMulScale(5) -MAKECONSTMulScale(6) -MAKECONSTMulScale(7) -MAKECONSTMulScale(8) -MAKECONSTMulScale(9) -MAKECONSTMulScale(10) -MAKECONSTMulScale(11) -MAKECONSTMulScale(12) -MAKECONSTMulScale(13) MAKECONSTMulScale(14) -MAKECONSTMulScale(15) MAKECONSTMulScale(16) -MAKECONSTMulScale(17) -MAKECONSTMulScale(18) -MAKECONSTMulScale(19) -MAKECONSTMulScale(20) -MAKECONSTMulScale(21) -MAKECONSTMulScale(22) -MAKECONSTMulScale(23) -MAKECONSTMulScale(24) -MAKECONSTMulScale(25) -MAKECONSTMulScale(26) -MAKECONSTMulScale(27) -MAKECONSTMulScale(28) -MAKECONSTMulScale(29) MAKECONSTMulScale(30) -MAKECONSTMulScale(31) MAKECONSTMulScale(32) #undef MAKECONSTMulScale @@ -92,37 +64,10 @@ static inline DWORD UMulScale16(DWORD a, DWORD b) { return ((QWORD)a * b) >> 16; return (((SQWORD)a * b) + ((SQWORD)c * d)) >> s; \ } -MAKECONSTDMulScale(1) -MAKECONSTDMulScale(2) MAKECONSTDMulScale(3) -MAKECONSTDMulScale(4) -MAKECONSTDMulScale(5) MAKECONSTDMulScale(6) -MAKECONSTDMulScale(7) -MAKECONSTDMulScale(8) -MAKECONSTDMulScale(9) MAKECONSTDMulScale(10) -MAKECONSTDMulScale(11) -MAKECONSTDMulScale(12) -MAKECONSTDMulScale(13) -MAKECONSTDMulScale(14) -MAKECONSTDMulScale(15) -MAKECONSTDMulScale(16) -MAKECONSTDMulScale(17) MAKECONSTDMulScale(18) -MAKECONSTDMulScale(19) -MAKECONSTDMulScale(20) -MAKECONSTDMulScale(21) -MAKECONSTDMulScale(22) -MAKECONSTDMulScale(23) -MAKECONSTDMulScale(24) -MAKECONSTDMulScale(25) -MAKECONSTDMulScale(26) -MAKECONSTDMulScale(27) -MAKECONSTDMulScale(28) -MAKECONSTDMulScale(29) -MAKECONSTDMulScale(30) -MAKECONSTDMulScale(31) MAKECONSTDMulScale(32) #undef MAKECONSTDMulScale @@ -142,35 +87,9 @@ MAKECONSTDMulScale(32) return result; \ } -MAKECONSTDivScale(2) -MAKECONSTDivScale(3) -MAKECONSTDivScale(4) -MAKECONSTDivScale(5) MAKECONSTDivScale(6) -MAKECONSTDivScale(7) -MAKECONSTDivScale(8) -MAKECONSTDivScale(9) -MAKECONSTDivScale(10) -MAKECONSTDivScale(11) -MAKECONSTDivScale(12) -MAKECONSTDivScale(13) -MAKECONSTDivScale(14) -MAKECONSTDivScale(15) MAKECONSTDivScale(16) -MAKECONSTDivScale(17) -MAKECONSTDivScale(18) -MAKECONSTDivScale(19) -MAKECONSTDivScale(20) MAKECONSTDivScale(21) -MAKECONSTDivScale(22) -MAKECONSTDivScale(23) -MAKECONSTDivScale(24) -MAKECONSTDivScale(25) -MAKECONSTDivScale(26) -MAKECONSTDivScale(27) -MAKECONSTDivScale(28) -MAKECONSTDivScale(29) MAKECONSTDivScale(30) -MAKECONSTDivScale(31) #undef MAKECONSTDivScale diff --git a/src/mscinlines.h b/src/mscinlines.h index 3d00e9cb0..cc16c319d 100644 --- a/src/mscinlines.h +++ b/src/mscinlines.h @@ -34,37 +34,9 @@ __forceinline SDWORD Scale (SDWORD a, SDWORD b, SDWORD c) __asm imul b \ __asm shrd eax,edx,s \ } -MAKECONSTMulScale(1) -MAKECONSTMulScale(2) -MAKECONSTMulScale(3) -MAKECONSTMulScale(4) -MAKECONSTMulScale(5) -MAKECONSTMulScale(6) -MAKECONSTMulScale(7) -MAKECONSTMulScale(8) -MAKECONSTMulScale(9) -MAKECONSTMulScale(10) -MAKECONSTMulScale(11) -MAKECONSTMulScale(12) -MAKECONSTMulScale(13) MAKECONSTMulScale(14) -MAKECONSTMulScale(15) MAKECONSTMulScale(16) -MAKECONSTMulScale(17) -MAKECONSTMulScale(18) -MAKECONSTMulScale(19) -MAKECONSTMulScale(20) -MAKECONSTMulScale(21) -MAKECONSTMulScale(22) -MAKECONSTMulScale(23) -MAKECONSTMulScale(24) -MAKECONSTMulScale(25) -MAKECONSTMulScale(26) -MAKECONSTMulScale(27) -MAKECONSTMulScale(28) -MAKECONSTMulScale(29) MAKECONSTMulScale(30) -MAKECONSTMulScale(31) #undef MAKECONSTMulScale __forceinline SDWORD MulScale32 (SDWORD a, SDWORD b) @@ -95,37 +67,10 @@ __forceinline DWORD UMulScale16(DWORD a, DWORD b) __asm shrd eax,edx,s \ } -MAKECONSTDMulScale(1) -MAKECONSTDMulScale(2) MAKECONSTDMulScale(3) -MAKECONSTDMulScale(4) -MAKECONSTDMulScale(5) MAKECONSTDMulScale(6) -MAKECONSTDMulScale(7) -MAKECONSTDMulScale(8) -MAKECONSTDMulScale(9) MAKECONSTDMulScale(10) -MAKECONSTDMulScale(11) -MAKECONSTDMulScale(12) -MAKECONSTDMulScale(13) -MAKECONSTDMulScale(14) -MAKECONSTDMulScale(15) -MAKECONSTDMulScale(16) -MAKECONSTDMulScale(17) MAKECONSTDMulScale(18) -MAKECONSTDMulScale(19) -MAKECONSTDMulScale(20) -MAKECONSTDMulScale(21) -MAKECONSTDMulScale(22) -MAKECONSTDMulScale(23) -MAKECONSTDMulScale(24) -MAKECONSTDMulScale(25) -MAKECONSTDMulScale(26) -MAKECONSTDMulScale(27) -MAKECONSTDMulScale(28) -MAKECONSTDMulScale(29) -MAKECONSTDMulScale(30) -MAKECONSTDMulScale(31) #undef MAKCONSTDMulScale __forceinline SDWORD DMulScale32 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) @@ -151,36 +96,10 @@ __forceinline SDWORD DMulScale32 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) __asm idiv b \ } -MAKECONSTDivScale(2) -MAKECONSTDivScale(3) -MAKECONSTDivScale(4) -MAKECONSTDivScale(5) MAKECONSTDivScale(6) -MAKECONSTDivScale(7) -MAKECONSTDivScale(8) -MAKECONSTDivScale(9) -MAKECONSTDivScale(10) -MAKECONSTDivScale(11) -MAKECONSTDivScale(12) -MAKECONSTDivScale(13) -MAKECONSTDivScale(14) -MAKECONSTDivScale(15) MAKECONSTDivScale(16) -MAKECONSTDivScale(17) -MAKECONSTDivScale(18) -MAKECONSTDivScale(19) -MAKECONSTDivScale(20) MAKECONSTDivScale(21) -MAKECONSTDivScale(22) -MAKECONSTDivScale(23) -MAKECONSTDivScale(24) -MAKECONSTDivScale(25) -MAKECONSTDivScale(26) -MAKECONSTDivScale(27) -MAKECONSTDivScale(28) -MAKECONSTDivScale(29) MAKECONSTDivScale(30) -MAKECONSTDivScale(31) #undef MAKECONSTDivScale #pragma warning (default: 4035) From 7d4a5898ac68d000e8aeaba224acd78b6a2c91ee Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Dec 2016 13:58:18 +0100 Subject: [PATCH 07/13] - removed most inline assembly. Integer multiplication gets handled fine by all current compilers and fixed point division is too infrequently used to justify this mess. That only leaves the Scale function which is still being used in a few places and which would create considerably worse code without assembly on 32 bit platforms. This is also far too primitive (2 or 3 assembly instructions) to claim any copyright on it, so I think m_fixed.h can now be considered free of Build-related issues. The deficated inline headers have been removed because that sole remaining function could be easily moved into m_fixed.h. --- src/basicinlines.h | 40 ----------------- src/gccinlines.h | 95 ---------------------------------------- src/m_fixed.h | 80 ++++++++++++++++++++++++++++++---- src/mscinlines.h | 105 --------------------------------------------- src/p_maputl.cpp | 4 +- 5 files changed, 73 insertions(+), 251 deletions(-) delete mode 100644 src/basicinlines.h delete mode 100644 src/gccinlines.h delete mode 100644 src/mscinlines.h diff --git a/src/basicinlines.h b/src/basicinlines.h deleted file mode 100644 index db03232b3..000000000 --- a/src/basicinlines.h +++ /dev/null @@ -1,40 +0,0 @@ -// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman -// Ken Silverman's official web site: "http://www.advsys.net/ken" -// See the included license file "BUILDLIC.TXT" for license info. -// -// This file is based on pragmas.h from Ken Silverman's original Build -// source code release but is meant for use with any compiler and does not -// rely on any inline assembly. -// - -#if _MSC_VER -#pragma once -#endif - -#if defined(__GNUC__) && !defined(__forceinline) -#define __forceinline __inline__ __attribute__((always_inline)) -#endif - -static __forceinline SDWORD Scale (SDWORD a, SDWORD b, SDWORD c) -{ - return (SDWORD)(((SQWORD)a*b)/c); -} - -static __forceinline SDWORD MulScale14 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 14); } -static __forceinline SDWORD MulScale16 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 16); } -static __forceinline SDWORD MulScale30 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 30); } -static __forceinline SDWORD MulScale32 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a * b) >> 32); } - -static __forceinline DWORD UMulScale16 (DWORD a, DWORD b) { return (DWORD)(((QWORD)a * b) >> 16); } - -static __forceinline SDWORD DMulScale3 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 3); } -static __forceinline SDWORD DMulScale6 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 6); } -static __forceinline SDWORD DMulScale10 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 10); } -static __forceinline SDWORD DMulScale18 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 18); } -static __forceinline SDWORD DMulScale32 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) { return (SDWORD)(((SQWORD)a*b + (SQWORD)c*d) >> 32); } - -static inline SDWORD DivScale6 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 6) / b); } -static inline SDWORD DivScale16 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 16) / b); } -static inline SDWORD DivScale21 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 21) / b); } -static inline SDWORD DivScale30 (SDWORD a, SDWORD b) { return (SDWORD)(((SQWORD)a << 30) / b); } - diff --git a/src/gccinlines.h b/src/gccinlines.h deleted file mode 100644 index 20506a5a8..000000000 --- a/src/gccinlines.h +++ /dev/null @@ -1,95 +0,0 @@ -// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman -// Ken Silverman's official web site: "http://www.advsys.net/ken" -// See the included license file "BUILDLIC.TXT" for license info. -// -// This file is based on pragmas.h from Ken Silverman's original Build -// source code release but is meant for use with GCC instead of Watcom C. -// -// Some of the inline assembly has been turned into C code, because -// modern compilers are smart enough to produce code at least as good as -// Ken's inline assembly. -// - -// I can come up with several different operand constraints for the -// following that work just fine when used all by themselves, but -// when I concatenate them together so that the compiler can choose -// between them, I get the following (but only if enough parameters -// are passed as the result of some operations instead of as -// variables/constants--e.g. DMulScale16 (a*2, b*2, c*2, d*2) instead of -// DMulScale16 (a, b, c, d)): -// -// `asm' operand requires impossible reload -// -// Why? - -#include - -#ifndef alloca -// MinGW does not seem to come with alloca defined. -#define alloca __builtin_alloca -#endif - -static inline SDWORD Scale (SDWORD a, SDWORD b, SDWORD c) -{ - SDWORD result, dummy; - - asm volatile - ("imull %3\n\t" - "idivl %4" - : "=a,a,a,a,a,a" (result), - "=&d,&d,&d,&d,d,d" (dummy) - : "a,a,a,a,a,a" (a), - "m,r,m,r,d,d" (b), - "r,r,m,m,r,m" (c) - : "cc" - ); - - return result; -} - -#define MAKECONSTMulScale(s) \ -static inline SDWORD MulScale##s (SDWORD a, SDWORD b) { return ((SQWORD)a * b) >> s; } - -MAKECONSTMulScale(14) -MAKECONSTMulScale(16) -MAKECONSTMulScale(30) -MAKECONSTMulScale(32) -#undef MAKECONSTMulScale - -static inline DWORD UMulScale16(DWORD a, DWORD b) { return ((QWORD)a * b) >> 16; } - -#define MAKECONSTDMulScale(s) \ - static inline SDWORD DMulScale##s (SDWORD a, SDWORD b, SDWORD c, SDWORD d) \ - { \ - return (((SQWORD)a * b) + ((SQWORD)c * d)) >> s; \ - } - -MAKECONSTDMulScale(3) -MAKECONSTDMulScale(6) -MAKECONSTDMulScale(10) -MAKECONSTDMulScale(18) -MAKECONSTDMulScale(32) -#undef MAKECONSTDMulScale - - -#define MAKECONSTDivScale(s) \ - static inline SDWORD DivScale##s (SDWORD a, SDWORD b) \ - { \ - SDWORD result, dummy; \ - asm volatile \ - ("idivl %4" \ - :"=a,a" (result), \ - "=d,d" (dummy) \ - : "a,a" (a<>(32-s)), \ - "r,m" (b) \ - : "cc"); \ - return result; \ - } - -MAKECONSTDivScale(6) -MAKECONSTDivScale(16) -MAKECONSTDivScale(21) -MAKECONSTDivScale(30) -#undef MAKECONSTDivScale - diff --git a/src/m_fixed.h b/src/m_fixed.h index 33d339608..dc7c3f4c9 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -4,14 +4,72 @@ #include #include "doomtype.h" +// Unfortunately, the Scale function still gets badly handled on 32 bit x86 platforms so it's the last remaining piece of inline assembly + +// GCC inlines #if defined(__GNUC__) && defined(__i386__) && !defined(__clang__) -#include "gccinlines.h" -#elif defined(_MSC_VER) && defined(_M_IX86) -#include "mscinlines.h" -#else -#include "basicinlines.h" +#ifndef alloca +// MinGW does not seem to come with alloca defined. +#define alloca __builtin_alloca #endif +static inline int32_t Scale(int32_t a, int32_t b, int32_t c) +{ + int32_t result, dummy; + + asm volatile + ("imull %3\n\t" + "idivl %4" + : "=a,a,a,a,a,a" (result), + "=&d,&d,&d,&d,d,d" (dummy) + : "a,a,a,a,a,a" (a), + "m,r,m,r,d,d" (b), + "r,r,m,m,r,m" (c) + : "cc" + ); + + return result; +} + +// MSVC inlines +#elif defined(_MSC_VER) && defined(_M_IX86) +#pragma warning (disable: 4035) + +__forceinline int32_t Scale(int32_t a, int32_t b, int32_t c) +{ + __asm mov eax, a + __asm imul b + __asm idiv c +} + +#pragma warning (default: 4035) +#else + +static __forceinline int32_t Scale(int32_t a, int32_t b, int32_t c) +{ + return (int32_t)(((int64_t)a*b) / c); +} + +#endif + +// Modern compilers are smart enough to do these multiplications intelligently. +__forceinline int32_t MulScale14(int32_t a, int32_t b) { return (int32_t)(((int64_t)a * b) >> 14); } // only used by R_DrawVoxel +__forceinline int32_t MulScale30(int32_t a, int32_t b) { return (int32_t)(((int64_t)a * b) >> 30); } // only used once in the node builder +__forceinline int32_t MulScale32(int32_t a, int32_t b) { return (int32_t)(((int64_t)a * b) >> 32); } // only used by R_DrawVoxel + +__forceinline uint32_t UMulScale16(uint32_t a, uint32_t b) { return (uint32_t)(((uint64_t)a * b) >> 16); } // used for sky drawing + +__forceinline int32_t DMulScale3(int32_t a, int32_t b, int32_t c, int32_t d) { return (int32_t)(((int64_t)a*b + (int64_t)c*d) >> 3); } // used for setting up slopes for Build maps +__forceinline int32_t DMulScale6(int32_t a, int32_t b, int32_t c, int32_t d) { return (int32_t)(((int64_t)a*b + (int64_t)c*d) >> 6); } // only used by R_DrawVoxel +__forceinline int32_t DMulScale10(int32_t a, int32_t b, int32_t c, int32_t d) { return (int32_t)(((int64_t)a*b + (int64_t)c*d) >> 10); } // only used by R_DrawVoxel +__forceinline int32_t DMulScale18(int32_t a, int32_t b, int32_t c, int32_t d) { return (int32_t)(((int64_t)a*b + (int64_t)c*d) >> 18); } // only used by R_DrawVoxel +__forceinline int32_t DMulScale32(int32_t a, int32_t b, int32_t c, int32_t d) { return (int32_t)(((int64_t)a*b + (int64_t)c*d) >> 32); } // used by R_PointOnSide. + +// Sadly, for divisions this is not true but these are so infrequently used that the C versions are just fine, despite not being fully optimal. +__forceinline int32_t DivScale6(int32_t a, int32_t b) { return (int32_t)(((int64_t)a << 6) / b); } // only used by R_DrawVoxel +__forceinline int32_t DivScale21(int32_t a, int32_t b) { return (int32_t)(((int64_t)a << 21) / b); } // only used by R_DrawVoxel +__forceinline int32_t DivScale30(int32_t a, int32_t b) { return (int32_t)(((int64_t)a << 30) / b); } // only used once in the node builder + __forceinline void fillshort(void *buff, unsigned int count, WORD clear) { SWORD *b2 = (SWORD *)buff; @@ -23,14 +81,18 @@ __forceinline void fillshort(void *buff, unsigned int count, WORD clear) #include "xs_Float.h" -inline SDWORD FixedDiv (SDWORD a, SDWORD b) +inline int32_t FixedDiv (int32_t a, int32_t b) { - if ((DWORD)abs(a) >> (31-16) >= (DWORD)abs (b)) + if ((uint32_t)abs(a) >> (31-16) >= (uint32_t)abs (b)) return (a^b)<0 ? FIXED_MIN : FIXED_MAX; - return DivScale16 (a, b); + + return (int32_t)(((int64_t)a << 16) / b); } -#define FixedMul MulScale16 +__forceinline int32_t FixedMul(int32_t a, int32_t b) +{ + return (int32_t)(((int64_t)a * b) >> 16); +} inline fixed_t FloatToFixed(double f) { diff --git a/src/mscinlines.h b/src/mscinlines.h deleted file mode 100644 index cc16c319d..000000000 --- a/src/mscinlines.h +++ /dev/null @@ -1,105 +0,0 @@ -// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman -// Ken Silverman's official web site: "http://www.advsys.net/ken" -// See the included license file "BUILDLIC.TXT" for license info. -// -// This file is based on pragmas.h from Ken Silverman's original Build -// source code release but is meant for use with Visual C++ instead of -// Watcom C. -// -// Some of the inline assembly has been turned into C code, because VC++ -// is smart enough to produce code at least as good as Ken's inlines. -// The more used functions are still inline assembly, because they do -// things that can't really be done in C. (I consider this a bad thing, -// because VC++ has considerably poorer support for inline assembly than -// Watcom, so it's better to rely on its C optimizer to produce fast code.) -// - - -#include -#include - -#pragma warning (disable: 4035) - -__forceinline SDWORD Scale (SDWORD a, SDWORD b, SDWORD c) -{ - __asm mov eax,a - __asm imul b - __asm idiv c -} - -#define MAKECONSTMulScale(s) \ - __forceinline SDWORD MulScale##s (SDWORD a, SDWORD b) \ - { \ - __asm mov eax,a \ - __asm imul b \ - __asm shrd eax,edx,s \ - } -MAKECONSTMulScale(14) -MAKECONSTMulScale(16) -MAKECONSTMulScale(30) -#undef MAKECONSTMulScale - -__forceinline SDWORD MulScale32 (SDWORD a, SDWORD b) -{ - __asm mov eax,a - __asm imul b - __asm mov eax,edx -} - -__forceinline DWORD UMulScale16(DWORD a, DWORD b) -{ - __asm mov eax,a - __asm mul b - __asm shrd eax,edx,16 -} - -#define MAKECONSTDMulScale(s) \ - __forceinline SDWORD DMulScale##s (SDWORD a, SDWORD b, SDWORD c, SDWORD d) \ - { \ - __asm mov eax,a \ - __asm imul b \ - __asm mov ebx,eax \ - __asm mov eax,c \ - __asm mov esi,edx \ - __asm imul d \ - __asm add eax,ebx \ - __asm adc edx,esi \ - __asm shrd eax,edx,s \ - } - -MAKECONSTDMulScale(3) -MAKECONSTDMulScale(6) -MAKECONSTDMulScale(10) -MAKECONSTDMulScale(18) -#undef MAKCONSTDMulScale - -__forceinline SDWORD DMulScale32 (SDWORD a, SDWORD b, SDWORD c, SDWORD d) -{ - __asm mov eax,a - __asm imul b - __asm mov ebx,eax - __asm mov eax,c - __asm mov esi,edx - __asm imul d - __asm add eax,ebx - __asm adc edx,esi - __asm mov eax,edx -} - -#define MAKECONSTDivScale(s) \ - __forceinline SDWORD DivScale##s (SDWORD a, SDWORD b) \ - { \ - __asm mov edx,a \ - __asm sar edx,32-s \ - __asm mov eax,a \ - __asm shl eax,s \ - __asm idiv b \ - } - -MAKECONSTDivScale(6) -MAKECONSTDivScale(16) -MAKECONSTDivScale(21) -MAKECONSTDivScale(30) -#undef MAKECONSTDivScale - -#pragma warning (default: 4035) diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index fdf66e969..d676e966c 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -2001,8 +2001,8 @@ int P_VanillaPointOnLineSide(double x, double y, const line_t* line) auto dx = FloatToFixed(x - line->v1->fX()); auto dy = FloatToFixed(y - line->v1->fY()); - auto left = MulScale16( int(delta.Y * 256) , dx ); - auto right = MulScale16( dy , int(delta.X * 256) ); + auto left = FixedMul( int(delta.Y * 256) , dx ); + auto right = FixedMul( dy , int(delta.X * 256) ); if (right < left) return 0; // front side From b78b8662dcba9897363e0dbce081065892cbc66a Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 10 Dec 2016 12:55:49 +0100 Subject: [PATCH 08/13] - Add missing GCCPRINTF in scanner code. This will help spotting erroneous usage of FScanner::{ScriptError,ScriptMessage} and FScriptPosition::Message. --- src/sc_man.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sc_man.h b/src/sc_man.h index fde6efbed..362d57faf 100644 --- a/src/sc_man.h +++ b/src/sc_man.h @@ -61,8 +61,8 @@ public: int MustMatchString(const char * const *strings, size_t stride = sizeof(char*)); int GetMessageLine(); - void ScriptError(const char *message, ...); - void ScriptMessage(const char *message, ...); + void ScriptError(const char *message, ...) GCCPRINTF(2,3); + void ScriptMessage(const char *message, ...) GCCPRINTF(2,3); bool isText(); @@ -155,7 +155,7 @@ struct FScriptPosition FScriptPosition(FString fname, int line); FScriptPosition(FScanner &sc); FScriptPosition &operator=(const FScriptPosition &other); - void Message(int severity, const char *message,...) const; + void Message(int severity, const char *message,...) const GCCPRINTF(3,4); static void ResetErrorCounter() { WarnCounter = 0; From d4a674740ef992da098533b4b9b94a24627f669b Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 10 Dec 2016 13:00:13 +0100 Subject: [PATCH 09/13] - Add missing GCCPRINTF to timidity cmsg function. Luckily, this has shown no problems. --- src/timidity/timidity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timidity/timidity.h b/src/timidity/timidity.h index b8b8bfc98..2ca64a59a 100644 --- a/src/timidity/timidity.h +++ b/src/timidity/timidity.h @@ -190,7 +190,7 @@ enum VERB_DEBUG }; -void cmsg(int type, int verbosity_level, const char *fmt, ...); +void cmsg(int type, int verbosity_level, const char *fmt, ...) GCCPRINTF(3,4); /* From 45e5e5c6eee953ef44296ffab19c0d458116c9c8 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 10 Dec 2016 13:01:49 +0100 Subject: [PATCH 10/13] - Add missing GCCPRINTF to FraggleScript script_error function. This will help spotting errors inside FraggleScript. --- src/fragglescript/t_script.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragglescript/t_script.h b/src/fragglescript/t_script.h index f0409a3f0..43f34acd4 100644 --- a/src/fragglescript/t_script.h +++ b/src/fragglescript/t_script.h @@ -718,7 +718,7 @@ public: #include "t_fs.h" -void script_error(const char *s, ...); +void script_error(const char *s, ...) GCCPRINTF(1,2); void FS_EmulateCmd(char * string); extern AActor *trigger_obj; From 810c632beb93cb19978cea29caecff7fabaf2b4c Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 10 Dec 2016 13:05:14 +0100 Subject: [PATCH 11/13] - Added missing GCCPRINTF to FileWriter::Printf. Luckily, this has shown no problems. --- src/files.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/files.h b/src/files.h index 4c12550c8..b78282482 100644 --- a/src/files.h +++ b/src/files.h @@ -374,7 +374,7 @@ public: static FileWriter *Open(const char *filename); virtual size_t Write(const void *buffer, size_t len); - size_t Printf(const char *fmt, ...); + size_t Printf(const char *fmt, ...) GCCPRINTF(2,3); protected: From 8036719f45ac8e72ba6ad287cae046a3001ebd41 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 10 Dec 2016 13:07:19 +0100 Subject: [PATCH 12/13] - Add GCCPRINTF to ZScript compiler code. This will help spotting errors in code using ZCCCompiler::{Warn,Error}. --- src/scripting/zscript/zcc_compile.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scripting/zscript/zcc_compile.h b/src/scripting/zscript/zcc_compile.h index 8b3a9f5f1..f9ebc62d4 100644 --- a/src/scripting/zscript/zcc_compile.h +++ b/src/scripting/zscript/zcc_compile.h @@ -135,8 +135,8 @@ private: ZCC_ExprTypeRef *NodeFromSymbolType(PSymbolType *sym, ZCC_Expression *idnode); - void Warn(ZCC_TreeNode *node, const char *msg, ...); - void Error(ZCC_TreeNode *node, const char *msg, ...); + void Warn(ZCC_TreeNode *node, const char *msg, ...) GCCPRINTF(3,4); + void Error(ZCC_TreeNode *node, const char *msg, ...) GCCPRINTF(3,4); void MessageV(ZCC_TreeNode *node, const char *txtcolor, const char *msg, va_list argptr); FxExpression *ConvertAST(PStruct *cclass, ZCC_TreeNode *ast); From d92a814e8cf92b258c7ee422f0bc14b8de8b665a Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Sat, 10 Dec 2016 13:47:19 +0100 Subject: [PATCH 13/13] - Fixed wrong argument format in voxeldef parser code. It got revealed by the GCCPRINTF format addition to FScanner::ScriptMessage. --- src/r_data/voxels.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_data/voxels.cpp b/src/r_data/voxels.cpp index 7c7876243..d81220ea8 100644 --- a/src/r_data/voxels.cpp +++ b/src/r_data/voxels.cpp @@ -456,7 +456,7 @@ static bool VOX_ReadSpriteNames(FScanner &sc, TArray &vsprites) } else if (sc.StringLen == 5 && (sc.String[4] = toupper(sc.String[4]), sc.String[4] < 'A' || sc.String[4] >= 'A' + MAX_SPRITE_FRAMES)) { - sc.ScriptMessage("Sprite frame %s is invalid.\n", sc.String[4]); + sc.ScriptMessage("Sprite frame %c is invalid.\n", sc.String[4]); } else {