Skip to content

Commit bece3db

Browse files
committed
[clang] add sqrt{pd|ps}256
Signed-off-by: Shreeyash Pandey <[email protected]>
1 parent 83c0718 commit bece3db

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,13 @@ let Features = "avx", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWid
504504
def vinsertf128_pd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Vector<2, double>, _Constant int)">;
505505
def vinsertf128_ps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<4, float>, _Constant int)">;
506506
def vinsertf128_si256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<4, int>, _Constant int)">;
507+
def sqrtpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>)">;
508+
def sqrtps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>)">;
507509
}
508510

509511
let Features = "avx", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {
510512
def vpermilpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Constant int)">;
511513
def vpermilps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Constant int)">;
512-
def sqrtpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>)">;
513-
def sqrtps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>)">;
514514
def rsqrtps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>)">;
515515
def rcpps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>)">;
516516
def roundpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Constant int)">;

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,6 +3829,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
38293829
return interp__builtin_x86_insert_subvector(S, OpPC, Call, BuiltinID);
38303830
case X86::BI__builtin_ia32_sqrtpd:
38313831
case X86::BI__builtin_ia32_sqrtps:
3832+
case X86::BI__builtin_ia32_sqrtpd256:
3833+
case X86::BI__builtin_ia32_sqrtps256:
38323834
return interp__builtin_x86_sqrt(S, OpPC, Call, BuiltinID);
38333835

38343836
default:

clang/lib/AST/ExprConstant.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12237,7 +12237,9 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1223712237
return Success(APValue(ResultElements.data(), ResultElements.size()), E);
1223812238
}
1223912239
case X86::BI__builtin_ia32_sqrtpd:
12240-
case X86::BI__builtin_ia32_sqrtps: {
12240+
case X86::BI__builtin_ia32_sqrtps:
12241+
case X86::BI__builtin_ia32_sqrtpd256:
12242+
case X86::BI__builtin_ia32_sqrtps256: {
1224112243
llvm::errs() << "We are inside sqrtpd/sqrtps\n";
1224212244
APValue Source;
1224312245
if (!EvaluateAsRValue(Info, E->getArg(0), Source))

clang/lib/Headers/avxintrin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static __inline __m256 __DEFAULT_FN_ATTRS_CONSTEXPR _mm256_mul_ps(__m256 __a,
335335
/// A 256-bit vector of [4 x double].
336336
/// \returns A 256-bit vector of [4 x double] containing the square roots of the
337337
/// values in the operand.
338-
static __inline __m256d __DEFAULT_FN_ATTRS
338+
static __inline __m256d __DEFAULT_FN_ATTRS_CONSTEXPR
339339
_mm256_sqrt_pd(__m256d __a)
340340
{
341341
return (__m256d)__builtin_ia32_sqrtpd256((__v4df)__a);
@@ -352,7 +352,7 @@ _mm256_sqrt_pd(__m256d __a)
352352
/// A 256-bit vector of [8 x float].
353353
/// \returns A 256-bit vector of [8 x float] containing the square roots of the
354354
/// values in the operand.
355-
static __inline __m256 __DEFAULT_FN_ATTRS
355+
static __inline __m256 __DEFAULT_FN_ATTRS_CONSTEXPR
356356
_mm256_sqrt_ps(__m256 __a)
357357
{
358358
return (__m256)__builtin_ia32_sqrtps256((__v8sf)__a);

clang/test/CodeGen/X86/avx-builtins.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,12 +1871,16 @@ __m256d test_mm256_sqrt_pd(__m256d A) {
18711871
return _mm256_sqrt_pd(A);
18721872
}
18731873

1874+
TEST_CONSTEXPR(match_m256d(_mm256_sqrt_pd(_mm256_set_pd(16.0, 9.0, 4.0, 1.0)), 1.0, 2.0, 3.0, 4.0));
1875+
18741876
__m256 test_mm256_sqrt_ps(__m256 A) {
18751877
// CHECK-LABEL: test_mm256_sqrt_ps
18761878
// CHECK: call {{.*}}<8 x float> @llvm.sqrt.v8f32(<8 x float> %{{.*}})
18771879
return _mm256_sqrt_ps(A);
18781880
}
18791881

1882+
TEST_CONSTEXPR(match_m256(_mm256_sqrt_ps(_mm256_set_ps(64.0f, 49.0f, 36.0f, 25.0f, 16.0f, 9.0f, 4.0f, 1.0f)), 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f));
1883+
18801884
void test_mm256_store_pd(double* A, __m256d B) {
18811885
// CHECK-LABEL: test_mm256_store_pd
18821886
// CHECK: store <4 x double> %{{.*}}, ptr %{{.*}}, align 32

0 commit comments

Comments
 (0)