Skip to content

Commit

Permalink
gfxlib2: Control selection of x86 MMX blitters
Browse files Browse the repository at this point in the history
- added fb.GFX_NO_X86_MMX = &h00000100 constant to fbgfx.bi,
  when passed as flag to SCREEN[RES] disable MMX blitters on x86 32-bit
- added fb.GET_X86_MMX_ENABLED = 18 constant to fbgfx.bi,
  used with ScreenControl to determine if MMX blitters are selected
  If returned value is non-zero, then MMX is enabled.  If zero, then
  MMX is disabled.  All other platforms return zero.
- added fb.SET_X86_MMX_ENABLED = 118 constant to fbgfx.bi,
  used with ScreenControl to specific if MMX blitters should be used.
  Pass non-zero value to enable, and zero value to disable.
  All other platforms ignore this setting
- internal: query the cpu type for MMX capability only when setting the
  graphics mode with SCREEN[RES] or when setting x86 MMX feature with
  ScreenControl fb.SET_X86_MMX_ENABLED function
  • Loading branch information
jayrm committed Dec 17, 2023
1 parent b7154ff commit dace83c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Expand Up @@ -8,6 +8,7 @@ Version 1.20.0
- emscripten/fbc: don't cast to integer for array indexing (possible regression of behaviour when fixing github #217)
- github #421: fbc: win32/win64: pass '-fno-ident' to gcc to help prevent identification strings from accumulating in the final binary
- fbc: internal: rtlMathLongintDIV() decide on signed or unsigned division based on sign instead of exact data type
- gfxlib2: on x86 32-bit, query the cpu type for MMX capability only when setting the graphics mode with SCREEN[RES] or when setting x86 MMX feature with ScreenControl fb.SET_X86_MMX_ENABLED function

[added]
- x86_64: optimize SHL MOD INTDIV to use 32-bit operation when result will be converted to long/ulong
Expand All @@ -21,6 +22,9 @@ Version 1.20.0
- gas64: optimizations: enable IR_OPT_ADDRCISC optimizations to use complex addressing (base + offset*multiplier) optimization for indexes (SARG)
- fbc headers: add ./inc/fberror.bi for runtime library error constants
- rtlib: ./inc/fbc-int/string.bi - for string descriptor and low level string functions
- gfxlib2: added fb.GFX_NO_X86_MMX = &h00000100 constant to fbgfx.bi - when passed as flag to SCREEN[RES] disable MMX blitters on x86 32-bit
- gfxlib2: added fb.GET_X86_MMX_ENABLED = 18 constant to fbgfx.bi - used with ScreenControl to determine if MMX blitters are selected on x86 32 bit. If returned value is non-zero, then MMX is enabled. If zero, then MMX is disabled. All other platforms return zero.
- gfxlib2: added fb.SET_X86_MMX_ENABLED = 118 constant to fbgfx.bi - used with ScreenControl to specific if MMX blitters should be used on x86 32-bit. Pass non-zero value to enable, and zero value to disable. All other platforms ignore this setting

[fixed]
- github #410: give consistent floating point comparisons results involving NaNs.
Expand Down
5 changes: 4 additions & 1 deletion inc/fbgfx.bi
Expand Up @@ -48,7 +48,8 @@ namespace FB
GFX_SHAPED_WINDOW = &h00000010, _
GFX_ALWAYS_ON_TOP = &h00000020, _
GFX_ALPHA_PRIMITIVES = &h00000040, _
GFX_HIGH_PRIORITY = &h00000080,_
GFX_HIGH_PRIORITY = &h00000080, _
GFX_NO_X86_MMX = &h00000100, _
GFX_SCREEN_EXIT = &h80000000l

'' OpenGL options
Expand Down Expand Up @@ -85,6 +86,7 @@ namespace FB
GET_GL_EXTENSIONS = 15, _
GET_HIGH_PRIORITY = 16, _
GET_SCANLINE_SIZE = 17, _
GET_X86_MMX_ENABLED = 18, _
_
GET_GL_COLOR_BITS = 37, _
GET_GL_COLOR_RED_BITS = 38, _
Expand Down Expand Up @@ -124,6 +126,7 @@ namespace FB
SET_GL_ACCUM_BLUE_BITS = 115, _
SET_GL_ACCUM_ALPHA_BITS = 116, _
SET_GL_NUM_SAMPLES = 117, _
SET_X86_MMX_ENABLED = 118, _
_
SET_GL_2D_MODE = 150, _
SET_GL_SCALE = 151
Expand Down
4 changes: 4 additions & 0 deletions src/gfxlib2/fb_gfx.h
Expand Up @@ -47,6 +47,7 @@ DRIVER_SHAPED_WINDOW 0x00000010 yes no yes no no
DRIVER_ALWAYS_ON_TOP 0x00000020 no no yes no no
DRIVER_ALPHA_PRIMITIVES 0x00000040 yes no no no no
DRIVER_HIGH_PRIORITY 0x00000080 yes no yes no no
DRIVER_NO_X86_MMX 0x00000100 yes no yes no no
DRIVER_OPENGL_OPTIONS 0x000F0000 no no yes no no
HAS_STENCIL_BUFFER 0x00010000 no no yes no no
HAS_ACCUMULATION_BUFFER 0x00020000 no no yes no no
Expand Down Expand Up @@ -78,6 +79,7 @@ OPENGL_SUPPORT 0x20000000 no yes no yes yes
#define DRIVER_ALWAYS_ON_TOP 0x00000020
#define DRIVER_ALPHA_PRIMITIVES 0x00000040
#define DRIVER_HIGH_PRIORITY 0x00000080
#define DRIVER_NO_X86_MMX 0x00000100
#define DRIVER_OPENGL_OPTIONS 0x000F0000
#define HAS_STENCIL_BUFFER 0x00010000
#define HAS_ACCUMULATION_BUFFER 0x00020000
Expand Down Expand Up @@ -156,6 +158,7 @@ OPENGL_SUPPORT 0x20000000 no yes no yes yes
#define GET_GL_EXTENSIONS 15
#define GET_HIGH_PRIORITY 16
#define GET_SCANLINE_SIZE 17
#define GET_X86_MMX_ENABLED 18

#define GET_GL_COLOR_BITS 37
#define GET_GL_COLOR_RED_BITS 38
Expand Down Expand Up @@ -195,6 +198,7 @@ OPENGL_SUPPORT 0x20000000 no yes no yes yes
#define SET_GL_ACCUM_BLUE_BITS 115
#define SET_GL_ACCUM_ALPHA_BITS 116
#define SET_GL_NUM_SAMPLES 117
#define SET_X86_MMX_ENABLED 118

#define SET_GL_2D_MODE 150
#define SET_GL_SCALE 151
Expand Down
22 changes: 22 additions & 0 deletions src/gfxlib2/gfx_control.c
Expand Up @@ -165,6 +165,11 @@ FBCALL void fb_GfxControl_i( int what, ssize_t *param1, ssize_t *param2, ssize_t
res1 = __fb_gfx->scanline_size;
break;

case GET_X86_MMX_ENABLED:
if (__fb_gfx)
res1 = (__fb_gfx->flags & X86_MMX_ENABLED) ? FB_TRUE : FB_FALSE;
break;

case SET_WINDOW_POS:
if ((__fb_gfx) && (__fb_gfx->driver->set_window_pos))
__fb_gfx->driver->set_window_pos(*param1, *param2);
Expand Down Expand Up @@ -303,6 +308,23 @@ FBCALL void fb_GfxControl_i( int what, ssize_t *param1, ssize_t *param2, ssize_t
__fb_gl_params.num_samples = *param1;
break;

case SET_X86_MMX_ENABLED:
#ifdef HOST_X86
if (__fb_gfx) {
if (fb_CpuDetect() & 0x800000) {
if (*param1) {
__fb_gfx->flags |= X86_MMX_ENABLED;
} else {
__fb_gfx->flags &= ~X86_MMX_ENABLED;
}
} else {
__fb_gfx->flags &= ~X86_MMX_ENABLED;
}
}
#endif
context->last_target = NULL;
break;

case SET_GL_2D_MODE:
/* set the initial 2d mode only; we don't want to
change the active mode in use. The activie mode
Expand Down
3 changes: 1 addition & 2 deletions src/gfxlib2/gfx_core.c
Expand Up @@ -290,8 +290,7 @@ static void *fb_hPixelCpy4(void *dest, const void *src, size_t size)
void fb_hSetupFuncs(int bpp)
{
#ifdef HOST_X86
if (fb_CpuDetect() & 0x800000) {
__fb_gfx->flags |= X86_MMX_ENABLED;
if (__fb_gfx->flags & X86_MMX_ENABLED) {
fb_hMemCpy = fb_hMemCpyMMX;
fb_hMemSet = fb_hMemSetMMX;
} else {
Expand Down
28 changes: 20 additions & 8 deletions src/gfxlib2/gfx_screen.c
Expand Up @@ -285,14 +285,26 @@ static int set_mode
__fb_gfx->event_queue = (EVENT *)malloc(sizeof(EVENT) * MAX_EVENTS);
__fb_gfx->event_mutex = fb_MutexCreate();
__fb_color_conv_16to32 = (unsigned int *)malloc(sizeof(int) * 512);
if (flags != DRIVER_NULL) {
if (flags & DRIVER_ALPHA_PRIMITIVES)
__fb_gfx->flags |= ALPHA_PRIMITIVES;
if (flags & DRIVER_OPENGL)
__fb_gfx->flags |= OPENGL_SUPPORT;
if (flags & DRIVER_HIGH_PRIORITY)
__fb_gfx->flags |= HIGH_PRIORITY;
}

if (flags != DRIVER_NULL) {
if (flags & DRIVER_ALPHA_PRIMITIVES) {
__fb_gfx->flags |= ALPHA_PRIMITIVES;
}
if (flags & DRIVER_OPENGL) {
__fb_gfx->flags |= OPENGL_SUPPORT;
}
if (flags & DRIVER_HIGH_PRIORITY) {
__fb_gfx->flags |= HIGH_PRIORITY;
}
}

#ifdef HOST_X86
if (fb_CpuDetect() & 0x800000) {
if (!(flags & DRIVER_NO_X86_MMX)) {
__fb_gfx->flags |= X86_MMX_ENABLED;
}
}
#endif

fb_hSetupFuncs(__fb_gfx->bpp);
fb_hSetupData();
Expand Down

0 comments on commit dace83c

Please sign in to comment.