]> granicus.if.org Git - clang/commitdiff
_mm_extract_epi16: use "& 7" when index is out of bound.
authorManman Ren <manman.ren@gmail.com>
Tue, 22 Oct 2013 19:24:42 +0000 (19:24 +0000)
committerManman Ren <manman.ren@gmail.com>
Tue, 22 Oct 2013 19:24:42 +0000 (19:24 +0000)
This is in line with implementation of _mm_extract_pi16.
rdar://15250497

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193187 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Headers/emmintrin.h
test/CodeGen/sse-builtins.c

index 9ab0a73aad6c50923e17b2c85914abf0fd945a7c..a78eb54c45a97b2929843f3976d44d3980e2b12b 100644 (file)
@@ -1266,7 +1266,7 @@ static __inline__ int __attribute__((__always_inline__, __nodebug__))
 _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__))
index 559d855547b0605580d5c53a09d8c614992fd146..cee9b3c2a5dfccd094d926c903aff89ae763a887 100644 (file)
@@ -206,3 +206,10 @@ void test_stream_si128(__m128i x, void *y) {
   // 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);
+}