BigMing001 / libyuv

Automatically exported from code.google.com/p/libyuv
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

xgetbv(0) fails on Visual C 2013 release builds #529

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
compile/run on 32 bit VC2013 release

d:\src\libyuv\libyuv>out\release\libyuv_unittest.exe --gtest_catch_exceptions=0 
--gtest_filter=*Cpu*
Note: Google Test filter = *Cpu*
[==========] Running 3 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 3 tests from LibYUVBaseTest
[ RUN      ] LibYUVBaseTest.TestCpuHas
xgetbv xcr0 0
Cpu Flags 1f1
Has ARM 0
Has NEON 0
Has X86 10
Has SSE2 20
Has SSSE3 40
Has SSE4.1 80
Has SSE4.2 100
Has AVX 0
Has AVX2 0
Has ERMS 0
Has FMA3 0
Has AVX3 0
Has MIPS 0
Has MIPS DSPR2 0
[       OK ] LibYUVBaseTest.TestCpuHas (10 ms)

debug works.  clangcl works.
with printf, this is bad code (esi return value)

  00000000: 56                 push        esi
  00000001: 33 C9              xor         ecx,ecx
  00000003: 0F 01 D0           xgetbv
  00000006: 56                 push        esi
  00000007: 68 00 00 00 00     push        offset ??_C@_0BF@NJCNKKJK@intrin?5xgetbv?$CI0?$CJ?5?$CFx?6?$AA@
  0000000C: E8 00 00 00 00     call        _printf
  00000011: 59                 pop         ecx
  00000012: 59                 pop         ecx
  00000013: 8B C6              mov         eax,esi
  00000015: 5E                 pop         esi
  00000016: C3                 ret

with #pragma optimize("g", off) this is correct code (eax return value)
  00000000: 55                 push        ebp
  00000001: 8B EC              mov         ebp,esp
  00000003: 51                 push        ecx
  00000004: 83 65 FC 00        and         dword ptr [ebp-4],0
  00000008: 33 C9              xor         ecx,ecx
  0000000A: 0F 01 D0           xgetbv
  0000000D: 89 45 FC           mov         dword ptr [ebp-4],eax
  00000010: FF 75 FC           push        dword ptr [ebp-4]
  00000013: 68 00 00 00 00     push        offset ??_C@_0BF@NJCNKKJK@intrin?5xgetbv?$CI0?$CJ?5?$CFx?6?$AA@
  00000018: E8 00 00 00 00     call        _printf
  0000001D: 59                 pop         ecx
  0000001E: 59                 pop         ecx
  0000001F: 8B 45 FC           mov         eax,dword ptr [ebp-4]
  00000022: 8B E5              mov         esp,ebp
  00000024: 5D                 pop         ebp
  00000025: C3                 ret

_GetXCR0:
  00000000: 55                 push        ebp
  00000001: 89 E5              mov         ebp,esp
  00000003: 83 EC 10           sub         esp,10h
  00000006: C7 45 F0 00 00 00  mov         dword ptr [ebp-10h],0
            00
  0000000D: C7 45 FC 00 00 00  mov         dword ptr [ebp-4],0
            00
  00000014: 31 C9              xor         ecx,ecx
  00000016: 0F 01 D0           xgetbv
  00000019: 89 45 F8           mov         dword ptr [ebp-8],eax
  0000001C: 89 55 F4           mov         dword ptr [ebp-0Ch],edx
  0000001F: 8B 45 F8           mov         eax,dword ptr [ebp-8]
  00000022: 89 45 F0           mov         dword ptr [ebp-10h],eax
  00000025: 8B 45 F0           mov         eax,dword ptr [ebp-10h]
  00000028: 83 C4 10           add         esp,10h
  0000002B: 5D                 pop         ebp
  0000002C: C3                 ret

Original issue reported on code.google.com by fbarch...@chromium.org on 8 Dec 2015 at 4:59

GoogleCodeExporter commented 8 years ago
The following revision refers to this bug:
  https://chromium.googlesource.com/libyuv/libyuv.git/+/fae1a105458a23d42c3e30f4d9ca321d08934e80

commit fae1a105458a23d42c3e30f4d9ca321d08934e80
Author: Frank Barchard <fbarchard@google.com>
Date: Wed Dec 09 02:13:32 2015

Work around bug in xgetbv for Visual Studio.

xgetbv is generating bad code, falsely disabling AVX2 and AVX512.
disable optimization for the function affected on older versions of Visual C 32 
bit.

R=brucedawson@chromium.org, dhrosa@google.com, harryjin@google.com
BUG=libyuv:529

Review URL: https://codereview.chromium.org/1503393004 .

[modify] 
http://crrev.com/fae1a105458a23d42c3e30f4d9ca321d08934e80/README.chromium
[modify] 
http://crrev.com/fae1a105458a23d42c3e30f4d9ca321d08934e80/include/libyuv/version
.h
[modify] 
http://crrev.com/fae1a105458a23d42c3e30f4d9ca321d08934e80/source/cpu_id.cc

Original comment by bugdroid1@chromium.org on 9 Dec 2015 at 2:14

GoogleCodeExporter commented 8 years ago
Fixed in r1550

Original comment by fbarch...@chromium.org on 9 Dec 2015 at 2:14

GoogleCodeExporter commented 8 years ago
The following revision refers to this bug:
  https://chromium.googlesource.com/libyuv/libyuv.git/+/353ffbab8055432a7383eac6c05c1b3cbd5f2679

commit 353ffbab8055432a7383eac6c05c1b3cbd5f2679
Author: Frank Barchard <fbarchard@google.com>
Date: Wed Dec 09 03:03:43 2015

fix for gcc compile error: variable duplicate define

TBR=harryjin@google.com
BUG=libyuv:529

Review URL: https://codereview.chromium.org/1512793002 .

[modify] 
http://crrev.com/353ffbab8055432a7383eac6c05c1b3cbd5f2679/source/cpu_id.cc

Original comment by bugdroid1@chromium.org on 9 Dec 2015 at 3:04

GoogleCodeExporter commented 8 years ago
vs2013 update 5 is reported to resolve this issue as well.

Original comment by fbarch...@google.com on 10 Dec 2015 at 11:30

GoogleCodeExporter commented 8 years ago

Original comment by fbarch...@google.com on 10 Dec 2015 at 11:42