From ffd686cc6387676cfac3d86275fc82b1a29a4ed1 Mon Sep 17 00:00:00 2001 From: Zhijin Zeng Date: Thu, 28 Nov 2024 11:15:54 +0800 Subject: [PATCH 1/2] Specify the Name Mangling Rule for Vector Function Introduce how to name vector function associated to the scalar function decorated with the OpenMP `declare simd` pragma. These vector functions can be used to process multiple instances in a single invocation to improve performance. Both library vendors and compilers must obey this rule to interface with each other. --- riscv-cc.adoc | 4 ++ riscv-elf.adoc | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/riscv-cc.adoc b/riscv-cc.adoc index f6ab1882..0bf6cd32 100644 --- a/riscv-cc.adoc +++ b/riscv-cc.adoc @@ -428,6 +428,10 @@ NOTE: `setjmp`/`longjmp` follow the standard calling convention, which clobbers all vector registers. Hence, the standard vector calling convention variant won't disrupt the `jmp_buf` ABI. +NOTE: Vector functions corresponding to scalar functions which are decorated with +the OpenMP `declare simd` pragma need to obey an additional name mangling rule. +For more details, see <>. + === ILP32E Calling Convention IMPORTANT: RV32E is not a ratified base ISA and so we cannot guarantee the diff --git a/riscv-elf.adoc b/riscv-elf.adoc index 9d4ea27f..b20351e4 100644 --- a/riscv-elf.adoc +++ b/riscv-elf.adoc @@ -234,6 +234,116 @@ type-name = identifier-nondigit *identifier-char identifier-nondigit = ALPHA / "_" identifier-char = identifier-nondigit / "_" ---- + +== Name Mangling for Vector Function + +This section describes how to name vector functions corresponding to scalar +functions which are decorated with `#pragma omp declare simd`. The order of the +vector function parameters should be the same as that of the original scalar +function. + +Name mangling rule for vector functions. + +[source,abnf] +---- +mangled-vector-name := "_ZGV" "_" + + := "1" | "2" | "4" | "8" (LMUL in turn is 1, 2, 4, 8) + | "h" | "q" | "e" (LMUL in turn is 1/2, 1/4, 1/8) + + := "N" (No mask, default for no inbranch clause) + | "M" (Mask, for inbranch clause) + + := SIMDLEN (VLS Mode, the number of elements processed at a time) + | "x" (VLA Mode) + + := { } + + := [ ] + + := "v" + | "l" | "l" + | "R" | "R" + | "L" | "L" + | "U" | "U" + | "ls" + | "Rs" + | "Ls" + | "Us" + | "u" + + := "n" // if linear step is negative + | + + := + + := integral number greater than or equal to 1 + + := integral number greater than or equal to 2 + + := [ "a" ] // specified by aligned clause + + := the orignal name of the scalar function +---- + +=== Description of the parameter_type token + +"v":: Vector parameter, default value for no linear or uniform clause. + +"l" | "l" :: This parameter is specified by the linear clause with a +compile-time constant, and its type must be either an integral type or a pointer +type. `number` is the value of the compile-time constant step, or it is an empty +string if the constant step is 1. Additionally, the base type of this parameter +must be an integral type. + +"R" | "R" :: This parameter is specified by the linear clause with a +compile-time constant. It has a ref modifier and its type must be reference type. +`number` is the value of the compile-time constant step, or it is an empty +string if the constant step is 1. Additionally, the base type of this parameter +must be an integral type. + +"L" | "L" :: This parameter is specified by the linear clause with a +compile-time constant. It has either a val modifier or no modifier and its type +must be reference type. `number` is the value of the compile-time constant step, +or it is an empty string if the constant step is 1. Additionally, the base type +of this parameter must be an integral type. + +"U" | "U" :: This parameter is specified by the linear clause with a +compile-time constant. It has a uval modifier and its type must be reference type. +`number` is the value of the compile-time constant step, or it is an empty +string if the constant step is 1. Additionally, the base type of this parameter +must be an integral type. + +"ls" :: This parameter is specified by the linear clause with a +loop-independent, runtime-invariant step parameter specified in the uniform clause. +Its type must be either an integral type or a pointer type. `pos' is the position +(starting from 0) of the step parameter in the function parameter list. +Additionally, both the base type of this parameter and the step parameter must be +integral types. + +"Rs" :: This parameter is specified by the linear clause with a +loop-independent, runtime-invariant step parameter specified in the uniform clause. +It has a ref modifier and its type must be reference type. `pos' is the position +(starting from 0) of the step parameter in the function parameter list. +Additionally, both the base type of this parameter and the step parameter must be +integral types. + +"Ls" :: This parameter is specified by the linear clause with a +loop-independent, runtime-invariant step parameter specified in the uniform clause. +It has either a val modifier or no modifier and its type must be reference type. +`pos' is the position (starting from 0) of the step parameter in the function +parameter list. Additionally, both the base type of this parameter and the step +parameter must be integral types. + +"Us" :: This parameter is specified by the linear clause with a +loop-independent, runtime-invariant step parameter specified in the uniform clause. +It has a uval modifier and its type must be reference type. `pos' is the position +(starting from 0) of the step parameter in the function parameter list. +Additionally, both the base type of this parameter and the step parameter must be +integral types. + +"u":: Uniform parameter, specified by uniform clause. + == ELF Object Files The ELF object file format for RISC-V follows the From 8276b3f696eef51a8aaa14015fa853054db01b7a Mon Sep 17 00:00:00 2001 From: Zhijin Zeng Date: Sat, 14 Dec 2024 13:37:26 +0800 Subject: [PATCH 2/2] fixup: add r in isa field --- riscv-elf.adoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/riscv-elf.adoc b/riscv-elf.adoc index b20351e4..e2abf4c3 100644 --- a/riscv-elf.adoc +++ b/riscv-elf.adoc @@ -246,7 +246,9 @@ Name mangling rule for vector functions. [source,abnf] ---- -mangled-vector-name := "_ZGV" "_" +mangled-vector-name := "_ZGV" "_" + + := "r" := "1" | "2" | "4" | "8" (LMUL in turn is 1, 2, 4, 8) | "h" | "q" | "e" (LMUL in turn is 1/2, 1/4, 1/8)