Debian Codegraph @

clang/test/CodeGen/RISCV/riscv-inline-asm-fixed-length-vector.c

raw
1 // REQUIRES: riscv-registered-target
2
3 // RUN: %clang_cc1 -triple riscv32 -target-feature +v \
4 // RUN: -mvscale-min=2 -mvscale-max=2 -O2 -emit-llvm %s -o - \
5 // RUN: | FileCheck %s
6 // RUN: %clang_cc1 -triple riscv64 -target-feature +v \
7 // RUN: -mvscale-min=2 -mvscale-max=2 -O2 -emit-llvm %s -o - \
8 // RUN: | FileCheck %s
9
10 // Test RISC-V V-extension fixed-length vector inline assembly constraints.
11 #include <riscv_vector.h>
12 #include <stdbool.h>
13
14 typedef vbool1_t fixed_bool1_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen)));
15 typedef vint32m1_t fixed_i32m1_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen)));
16 typedef vint8mf2_t fixed_i8mf2_t __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen / 2)));
17
18 typedef bool bx2 __attribute__((ext_vector_type(16)));
19 typedef int i32x2 __attribute__((ext_vector_type(2)));
20 typedef char i8x4 __attribute__((ext_vector_type(4)));
21
22 fixed_i32m1_t test_vr(fixed_i32m1_t a) {
23 // CHECK-LABEL: define{{.*}} @test_vr
24 // CHECK: %0 = tail call <4 x i32> asm sideeffect "vadd.vv $0, $1, $2", "=^vr,^vr,^vr"(<4 x i32> %a, <4 x i32> %a)
25 fixed_i32m1_t ret;
26 asm volatile ("vadd.vv %0, %1, %2" : "=vr"(ret) : "vr"(a), "vr"(a));
27 return ret;
28 }
29
30 i32x2 test_vr2(i32x2 a) {
31 // CHECK-LABEL: define{{.*}} @test_vr2
32 // CHECK: %1 = tail call <2 x i32> asm sideeffect "vadd.vv $0, $1, $2", "=^vr,^vr,^vr"(<2 x i32> %0, <2 x i32> %0)
33 i32x2 ret;
34 asm volatile ("vadd.vv %0, %1, %2" : "=vr"(ret) : "vr"(a), "vr"(a));
35 return ret;
36 }
37
38 fixed_i8mf2_t test_vd(fixed_i8mf2_t a) {
39 // CHECK-LABEL: define{{.*}} @test_vd
40 // CHECK: %0 = tail call <8 x i8> asm sideeffect "vadd.vv $0, $1, $2", "=^vd,^vr,^vr"(<8 x i8> %a, <8 x i8> %a)
41 fixed_i8mf2_t ret;
42 asm volatile ("vadd.vv %0, %1, %2" : "=vd"(ret) : "vr"(a), "vr"(a));
43 return ret;
44 }
45
46 i8x4 test_vd2(i8x4 a) {
47 // CHECK-LABEL: define{{.*}} @test_vd2
48 // CHECK: %1 = tail call <4 x i8> asm sideeffect "vadd.vv $0, $1, $2", "=^vd,^vr,^vr"(<4 x i8> %0, <4 x i8> %0)
49 i8x4 ret;
50 asm volatile ("vadd.vv %0, %1, %2" : "=vd"(ret) : "vr"(a), "vr"(a));
51 return ret;
52 }
53
54 fixed_bool1_t test_vm(fixed_bool1_t a) {
55 // CHECK-LABEL: define{{.*}} @test_vm
56 // CHECK: %1 = tail call <16 x i8> asm sideeffect "vmand.mm $0, $1, $2", "=^vm,^vm,^vm"(<16 x i8> %a, <16 x i8> %a)
57 fixed_bool1_t ret;
58 asm volatile ("vmand.mm %0, %1, %2" : "=vm"(ret) : "vm"(a), "vm"(a));
59 return ret;
60 }
61
62 void test_vm2(bx2 a) {
63 // CHECK-LABEL: define{{.*}} @test_vm2
64 // CHECK: tail call void asm sideeffect "dummy $0", "^vm"(<16 x i1> %a1)
65 asm volatile ("dummy %0" :: "vm"(a));
66 }