[Mesa-dev] [PATCH 08/16 v2] st/nine: Change x86 FPU Control word on device creation

Roland Scheidegger sroland at vmware.com
Sun Apr 26 11:14:49 PDT 2015


Am 26.04.2015 um 18:36 schrieb Ilia Mirkin:
> On Sun, Apr 26, 2015 at 12:27 PM, Axel Davy <axel.davy at ens.fr> wrote:
>> From: Tiziano Bacocco <tizbac2 at gmail.com>
>>
>> As on wined3d and windows, when D3DCREATE_FPU_PRESERVE is not
>> specified, change the fpu control word to all exceptions masked,
>> single precision, round to nearest.
>>
>> Signed-off-by: Axel Davy <axel.davy at ens.fr>
>> Signed-off-by: Tiziano Bacocco <tizbac2 at gmail.com>
>> ---
>>  src/gallium/state_trackers/nine/device9.c | 31 +++++++++++++++++++++++++++++++
>>  1 file changed, 31 insertions(+)
>>
>> diff --git a/src/gallium/state_trackers/nine/device9.c b/src/gallium/state_trackers/nine/device9.c
>> index 1a776a7..0bd1717 100644
>> --- a/src/gallium/state_trackers/nine/device9.c
>> +++ b/src/gallium/state_trackers/nine/device9.c
>> @@ -41,6 +41,7 @@
>>
>>  #include "pipe/p_screen.h"
>>  #include "pipe/p_context.h"
>> +#include "pipe/p_config.h"
>>  #include "util/u_math.h"
>>  #include "util/u_inlines.h"
>>  #include "util/u_hash_table.h"
>> @@ -53,6 +54,33 @@
>>
>>  #define DBG_CHANNEL DBG_DEVICE
>>
>> +#if defined(PIPE_CC_GCC) && (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64))
>> +
>> +#include <fpu_control.h>
>> +
>> +static void nine_setup_fpu()
>> +{
>> +    fpu_control_t c;
>> +
>> +    _FPU_GETCW(c);
>> +    /* clear the control word */
>> +    c &= _FPU_RESERVED;
>> +    /* d3d9 doc/wine tests: mask all exceptions, use single-precision
>> +     * and round to nearest */
>> +    c |= _FPU_MASK_IM | _FPU_MASK_DM | _FPU_MASK_ZM | _FPU_MASK_OM |
>> +         _FPU_MASK_UM | _FPU_MASK_PM | _FPU_SINGLE | _FPU_RC_NEAREST;
>> +    _FPU_SETCW(c);
> 
> Again... why not use the fe* functions which are in C99 and you don't
> have to do these checks?
> 
> fenv_t env;
> feholdexcept(&env);
> fesetenv(&env);
> fesetround(FE_TONEAREST);
> 
> Hmmm... not sure about the _FPU_SINGLE thing -- what does that do?

That's for specifying precision. Don't forget x87 fpu regs are always 80
bit (extended double precision) and there are no explicit instructions
for floats, doubles, extended doubles. I don't know what the abi default
precision actually is (either double or extended double), but being able
to specify this is what really matters, the rest is all default anyway.
(I have no idea if you can do that with fenv.)

Roland



> 
>> +}
>> +
>> +#else
>> +
>> +static void nine_setup_fpu(void)
>> +{
>> +    WARN_ONCE("FPU setup not supported on non-x86 platforms\n");
>> +}
>> +
>> +#endif
>> +
>>  static void
>>  NineDevice9_SetDefaultState( struct NineDevice9 *This, boolean is_reset )
>>  {
>> @@ -168,6 +196,9 @@ NineDevice9_ctor( struct NineDevice9 *This,
>>      IDirect3D9_AddRef(This->d3d9);
>>      ID3DPresentGroup_AddRef(This->present);
>>
>> +    if (!(This->params.BehaviorFlags & D3DCREATE_FPU_PRESERVE))
>> +        nine_setup_fpu();
>> +
>>      This->pipe = This->screen->context_create(This->screen, NULL);
>>      if (!This->pipe) { return E_OUTOFMEMORY; } /* guess */
>>
>> --
>> 2.1.0
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.freedesktop.org_mailman_listinfo_mesa-2Ddev&d=AwIGaQ&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=Vjtt0vs_iqoI31UfJxBl7yv9I2FeiaeAYgMTLKRBc_I&m=2toYeNPVRrm_uZA1WPLTUtcomtJeOKhWX4t40XQe3Hw&s=9zLC7rqLe0S6IxvaQU8epMrOSWw-vXvZPxV0_o6yJSU&e= 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.freedesktop.org_mailman_listinfo_mesa-2Ddev&d=AwIGaQ&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=Vjtt0vs_iqoI31UfJxBl7yv9I2FeiaeAYgMTLKRBc_I&m=2toYeNPVRrm_uZA1WPLTUtcomtJeOKhWX4t40XQe3Hw&s=9zLC7rqLe0S6IxvaQU8epMrOSWw-vXvZPxV0_o6yJSU&e= 
> 



More information about the mesa-dev mailing list