I'm evaluating MIPS SIMD Architecture (MSA) programming using the Codescape GCC Toolchain. There's not much information out there about MSA and builtins. (As far as I can tell there's only two MSA cpu's, the P5600 and Warrior I6400, and they first became available several years ago).
My test program is below.
#include <msa.h>
#include <stdint.h>
#define ALIGN16 __attribute__((aligned(16)))
int main(int argc, char* argv[])
{
ALIGN16 uint32_t a[] = {64, 128, 256, 512};
ALIGN16 uint32_t b[] = {1024, 2048, 4096, 8192};
ALIGN16 uint32_t c[4];
v4u32 va = __builtin_msa_ld_w (a, 0);
v4u32 vb = __builtin_msa_ld_w (b, 0);
v4u32 vc = __builtin_msa_adds_u_w (va, vb);
__builtin_msa_st_w (vc, c, 0);
return 0;
}
Compiling the program results in the errors shown below. The problem is, the vector loads return a signed vector but my vectors are unsigned. I have a similar problem with the vector stores.
// The 4 vector loads provided through builtins
v16i8 __builtin_msa_ld_b (void *, imm_n512_511); // byte
v8i16 __builtin_msa_ld_h (void *, imm_n1024_1022); // half word
v4i32 __builtin_msa_ld_w (void *, imm_n2048_2044); // word
v2i64 __builtin_msa_ld_d (void *, imm_n4096_4088); // double word
(The imm_n512_511
and friends is discussed in the GCC manual at 6.59.16 MIPS SIMD Architecture (MSA) Support).
I read MIPS paper(?) at MIPS SIMD Architecture but it does not discuss how to convert between integral vector types. There are lots of floating-point conversion instructions, but nothing for integral types.
Is a simple cast the preferred way to convert between integral vector types? Or is there something else I should be doing?
MSA$ mips-img-linux-gnu-gcc.exe -mmsa test.c -c
test.c: In function 'main':
test.c:12:2: note: use -flax-vector-conversions to permit conversions between ve
ctors with differing element types or numbers of subparts
v4u32 va = __builtin_msa_ld_w (a, 0);
^~~~~
test.c:12:13: error: incompatible types when initializing type 'v4u32 {aka __vec
tor(4) unsigned int}' using type '__vector(4) int'
v4u32 va = __builtin_msa_ld_w (a, 0);
^~~~~~~~~~~~~~~~~~
test.c:13:13: error: incompatible types when initializing type 'v4u32 {aka __vec
tor(4) unsigned int}' using type '__vector(4) int'
v4u32 vb = __builtin_msa_ld_w (b, 0);
^~~~~~~~~~~~~~~~~~
test.c:16:22: error: incompatible type for argument 1 of '__builtin_msa_st_w'
__builtin_msa_st_w (vc, c, 0);
^~
test.c:16:22: note: expected '__vector(4) int' but argument is of type 'v4u32 {a
ka __vector(4) unsigned int}'