[PATCH 3/4] msvcrt: Check for ERMS support and use __stosb for large memset calls.

Piotr Caban piotr.caban at gmail.com
Mon Sep 13 09:51:02 CDT 2021


On 9/13/21 2:23 PM, Rémi Bernon wrote:
>   void msvcrt_init_math( void *module )
>   {
> +#if defined(__i386__) || defined(__x86_64__)
> +    int regs[4];
> +
> +    __cpuid(regs, 0);
> +    if (regs[0] < 7) erms_supported = FALSE;
> +    else
> +    {
> +        __cpuidex(regs, 7, 0);
> +        erms_supported = ((regs[1] >> 9) & 1);
> +    }
> +#else
> +    erms_supported = FALSE;
> +#endif
erms_supported is zeroed (and memset is even called before 
msvcrt_init_math function call). It can be changed to:
#if defined(__i386__) || defined(__x86_64__)
     int regs[4];

     __cpuid(regs, 0);
     if (regs[0] >= 7)
     {
         __cpuid(regs, 7);
         erms_supported = ((regs[1] >> 9) & 1);
     }
#endif

There's one more thing that is worth mentioning. In ntdll we're checking 
if cpuid is available. On the other hand it's used without the check in 
wineboot. I guess it's OK to use cpuid without the check.

>   static void memset_aligned_32(unsigned char *d, uint64_t v, size_t n)
>   {
> +#if defined(__i386__) || defined(__x86_64__)
> +    if (n >= 2048 && erms_supported) __stosb(d, v, n);
> +    else
How about changing the code in a way that no weird indentation is 
introduced:
if (n >= 2048 && erms_supported)
{
     __stosb(d, v, n);
     return d;
}

Thanks,
Piotr



More information about the wine-devel mailing list