From e9e912301f221713981613f6ad6f5b89736560cc Mon Sep 17 00:00:00 2001 From: coderJeff Date: Fri, 20 Apr 2018 23:06:30 -0400 Subject: [PATCH] Fix #875 for -gen gas -fpu sse where boolean variable to single/double conversion gives wrong sign --- changelog.txt | 2 +- src/compiler/emit_SSE.bas | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 68776826a1..b6e0ed7596 100644 --- a/changelog.txt +++ b/changelog.txt @@ -51,7 +51,7 @@ Version 1.06.0 - #841: The unary negation operator gave different result signedness when used on constant instead of non-constant expression. Now the result is always signed. - Incorrect C++ mangling for BYREF parameters using built-in types - #844: Fix bug in -gen gcc due to duplicated type (struct) names in the main module and global namespace -- #875: Fix bug where boolean variable to single/double conversion gives wrong sign on -gen gas x86 +- #875: Fix bug where boolean variable to single/double conversion gives wrong sign on -gen gas -fpu x87 & sse - #872: Fix broken boolean bitfield runtime assignments from unsigned values diff --git a/src/compiler/emit_SSE.bas b/src/compiler/emit_SSE.bas index e55bc8fd40..317da36293 100644 --- a/src/compiler/emit_SSE.bas +++ b/src/compiler/emit_SSE.bas @@ -13,6 +13,8 @@ #include once "symb.bi" #include once "emit-private.bi" +dim shared _emitLOADB2F_x86 as sub( byval dvreg as IRVREG ptr, byval svreg as IRVREG ptr ) + private sub hULONG2DBL _ ( _ byval svreg as IRVREG ptr _ @@ -38,6 +40,29 @@ private sub hULONG2DBL _ end sub +private sub _emitLOADB2F_SSE( byval dvreg as IRVREG ptr, byval svreg as IRVREG ptr ) + + dim as string dst + dim as integer ddsize = any + + '' load source to ST(0) + _emitLOADB2F_x86( dvreg, svreg ) + + hPrepOperand( dvreg, dst ) + ddsize = typeGetSize( dvreg->dtype ) + + '' pop from FPU STACK and load to SSE register + outp "sub esp" + COMMA + str( ddsize ) + if( ddsize > 4 ) then + outp "fstp qword ptr [esp]" + outp "movlpd " + dst + COMMA + "qword ptr [esp]" + else + outp "fstp dword ptr [esp]" + outp "movss " + dst + COMMA + "dword ptr [esp]" + end if + outp "add esp" + COMMA + str( ddsize ) + +end sub ''::::: private sub _emitSTORF2L_SSE _ @@ -2882,11 +2907,13 @@ function _init_opFnTB_SSE _ ) as integer '' load + _emitLOADB2F_x86 = _opFnTB_SSE[EMIT_OP_LOADB2F] _opFnTB_SSE[EMIT_OP_LOADF2I] = EMIT_CBENTRY(LOADF2I_SSE) _opFnTB_SSE[EMIT_OP_LOADI2F] = EMIT_CBENTRY(LOADI2F_SSE) _opFnTB_SSE[EMIT_OP_LOADF2L] = EMIT_CBENTRY(LOADF2L_SSE) _opFnTB_SSE[EMIT_OP_LOADL2F] = EMIT_CBENTRY(LOADL2F_SSE) _opFnTB_SSE[EMIT_OP_LOADF2F] = EMIT_CBENTRY(LOADF2F_SSE) + _opFnTB_SSE[EMIT_OP_LOADB2F] = EMIT_CBENTRY(LOADB2F_SSE) '' store _opFnTB_SSE[EMIT_OP_STORF2I] = EMIT_CBENTRY(STORF2I_SSE)