r193187 - _mm_extract_epi16: use "& 7" when index is out of bound.

Manman Ren manman.ren at gmail.com
Tue Oct 22 12:24:43 PDT 2013


Author: mren
Date: Tue Oct 22 14:24:42 2013
New Revision: 193187

URL: http://llvm.org/viewvc/llvm-project?rev=193187&view=rev
Log:
_mm_extract_epi16: use "& 7" when index is out of bound.

This is in line with implementation of _mm_extract_pi16.
rdar://15250497

Modified:
    cfe/trunk/lib/Headers/emmintrin.h
    cfe/trunk/test/CodeGen/sse-builtins.c

Modified: cfe/trunk/lib/Headers/emmintrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/emmintrin.h?rev=193187&r1=193186&r2=193187&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/emmintrin.h (original)
+++ cfe/trunk/lib/Headers/emmintrin.h Tue Oct 22 14:24:42 2013
@@ -1266,7 +1266,7 @@ static __inline__ int __attribute__((__a
 _mm_extract_epi16(__m128i __a, int __imm)
 {
   __v8hi __b = (__v8hi)__a;
-  return (unsigned short)__b[__imm];
+  return (unsigned short)__b[__imm & 7];
 }
 
 static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))

Modified: cfe/trunk/test/CodeGen/sse-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/sse-builtins.c?rev=193187&r1=193186&r2=193187&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/sse-builtins.c (original)
+++ cfe/trunk/test/CodeGen/sse-builtins.c Tue Oct 22 14:24:42 2013
@@ -206,3 +206,10 @@ void test_stream_si128(__m128i x, void *
   // CHECK: store {{.*}} <2 x i64>* {{.*}}, align 16, !nontemporal
   _mm_stream_si128(y, x);
 }
+
+void test_extract_epi16(__m128i __a) {
+  // CHECK-LABEL: define void @test_extract_epi16
+  // CHECK: [[x:%.*]] = and i32 %{{.*}}, 7
+  // CHECK: extractelement <8 x i16> %{{.*}}, i32 [[x]]
+  _mm_extract_epi16(__a, 8);
+}





More information about the cfe-commits mailing list