dexcz / libyuv

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

Illegal instruction using AVX2 on i5-3450 #343

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The AVX2 instruction set isn't available on the i5-3450, but is still reported 
as available in the CPU detection code.

Steps:
1. Run YUV conversion using the ARGBToUVRow_AVX2 codepath
2. Crash with illegal instruction on vpavgb

Here is a patch that fixes the problem:
--- old/libyuv/source/cpu_id.cc   2014-03-11 16:45:46.000000000 -0700
+++ new\libyuv\source\cpu_id.cc      2014-03-11 16:45:46.000000000 -0700
@@ -180,10 +180,13 @@
 LIBYUV_API SAFEBUFFERS
 int InitCpuFlags(void) {
 #if !defined(__CLR_VER) && defined(CPU_X86)
+  uint32 cpu_info0[4] = { 0, 0, 0, 0 };
   uint32 cpu_info1[4] = { 0, 0, 0, 0 };
   uint32 cpu_info7[4] = { 0, 0, 0, 0 };
+  CpuId(0, 0, cpu_info0);
   CpuId(1, 0, cpu_info1);
-  CpuId(7, 0, cpu_info7);
+  if (cpu_info0[0] >= 7)
+    CpuId(7, 0, cpu_info7);
   cpu_info_ = ((cpu_info1[3] & 0x04000000) ? kCpuHasSSE2 : 0) |
               ((cpu_info1[2] & 0x00000200) ? kCpuHasSSSE3 : 0) |
               ((cpu_info1[2] & 0x00080000) ? kCpuHasSSE41 : 0) |

Original issue reported on code.google.com by slou...@gmail.com on 12 Jul 2014 at 12:14

GoogleCodeExporter commented 9 years ago
Thanks for the report and code.
Your change seems fine, except possible risk that AMD 'extended' codes set the 
high bit

Original comment by fbarch...@chromium.org on 12 Jul 2014 at 1:33

GoogleCodeExporter commented 9 years ago
Code up for review
https://webrtc-codereview.appspot.com/12969004/

Are you using the code directly or will you need to rolled into chrome or 
something?

Original comment by fbarch...@chromium.org on 12 Jul 2014 at 2:11

GoogleCodeExporter commented 9 years ago
I'm using the code directly.

Thanks!

Original comment by slou...@gmail.com on 12 Jul 2014 at 4:04

GoogleCodeExporter commented 9 years ago

Original comment by fbarch...@chromium.org on 12 Jul 2014 at 5:11

GoogleCodeExporter commented 9 years ago
r1035 checked in.  Give it a try if you can

Original comment by fbarch...@chromium.org on 14 Jul 2014 at 5:53

GoogleCodeExporter commented 9 years ago
Looks good, thanks!

Original comment by slou...@gmail.com on 14 Jul 2014 at 9:52

GoogleCodeExporter commented 9 years ago

Original comment by fbarch...@chromium.org on 15 Jul 2014 at 12:09