Debian Codegraph @

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

raw
1 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +pclmul -emit-llvm -o - | FileCheck %s
2 // RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +pclmul -emit-llvm -o - -std=c++11 | FileCheck %s
3 // RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +pclmul -emit-llvm -o - -std=c++11 -fexperimental-new-constant-interpreter | FileCheck %s
4
5 #include <wmmintrin.h>
6 #include "builtin_test_helpers.h"
7
8 __m128i test_mm_clmulepi64_si128(__m128i a, __m128i b) {
9 // CHECK: @llvm.x86.pclmulqdq
10 return _mm_clmulepi64_si128(a, b, 0);
11 }
12
13 // Test constexpr evaluation for _mm_clmulepi64_si128
14 // imm8=0x00: lower 64 bits of both operands
15 // Test case: 0x1 * 0x3 = 0x3 (carry-less multiplication)
16 TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x1ULL, 0x0ULL}), ((__m128i){0x3ULL, 0x0ULL}), 0x00), 0x3ULL, 0x0ULL));
17
18 // imm8=0x01: upper 64 bits of first operand, lower 64 bits of second
19 TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x0ULL, 0x1ULL}), ((__m128i){0x3ULL, 0x0ULL}), 0x01), 0x3ULL, 0x0ULL));
20
21 // imm8=0x10: lower 64 bits of first operand, upper 64 bits of second
22 TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x1ULL, 0x0ULL}), ((__m128i){0x0ULL, 0x3ULL}), 0x10), 0x3ULL, 0x0ULL));
23
24 // imm8=0x11: upper 64 bits of both operands
25 TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x0ULL, 0x1ULL}), ((__m128i){0x0ULL, 0x3ULL}), 0x11), 0x3ULL, 0x0ULL));
26
27 // Test cases with non-zero upper 64-bit results
28 // imm8=0x00: lower 64 bits of both operands
29 // 0x8000000000000000 * 0x2 = result with upper bits set
30 TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){(long long)0x8000000000000000ULL, 0x0ULL}), ((__m128i){0x2ULL, 0x0ULL}), 0x00), 0x0ULL, 0x1ULL));
31
32 // imm8=0x01: upper 64 bits of first operand, lower 64 bits of second
33 // 0xFFFFFFFFFFFFFFFF * 0x2 = result with upper bits set
34 TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x0ULL, (long long)0xFFFFFFFFFFFFFFFFULL}), ((__m128i){0x2ULL, 0x0ULL}), 0x01), 0xFFFFFFFFFFFFFFFEULL, 0x1ULL));
35
36 // imm8=0x10: lower 64 bits of first operand, upper 64 bits of second
37 // 0x1000000000000000 * 0x10 = result with upper bits set
38 TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){(long long)0x1000000000000000ULL, 0x0ULL}), ((__m128i){0x0ULL, 0x10ULL}), 0x10), 0x0ULL, 0x1ULL));
39
40 // imm8=0x11: upper 64 bits of both operands
41 // 0x8000000000000001 * 0x8000000000000001 = result with upper bits set
42 TEST_CONSTEXPR(match_m128i(_mm_clmulepi64_si128(((__m128i){0x0ULL, (long long)0x8000000000000001ULL}), ((__m128i){0x0ULL, (long long)0x8000000000000001ULL}), 0x11), 0x1ULL, 0x4000000000000000ULL));