<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jul 26, 2014, at 7:02 AM, Erik Schnetter <<a href="mailto:schnetter@gmail.com">schnetter@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Jul 26, 2014, at 0:22 , Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:<br><br><blockquote type="cite">On Fri, Jul 25, 2014 at 06:15:52PM -0500, Aaron Watry wrote:<br><blockquote type="cite">This generates bitcode which is indistinguishable from what was<br>hand-written for int32 types in v[load|store]_impl.ll<br><br></blockquote><br>The LLVM IR produce by these implementations is incorrect.  The<br>alignment on the loads and stores needs to be the size of the base type.<br>So, the load produced by an int2 vload should have an alignment of 4<br>bytes.<br><br>You may already have something like this, but here is the command I used to<br>compile vload.cl to LLVM IR to verify the alignment.<br><br>clang -S -emit-llvm -o $1.ll -include /usr/local/include/clc/clc.h<br>-I/usr/local//include/ -Dcl_clang_storage_class_specifiers -target r600<br>-mcpu=verde -c $1<br><br>To get the correct alignment you'll want to something like:<br><br>int2 vload2(size_t offset, local int *ptr) {<br>      ptr += offset * 2;<br>      return (int2)(ptr[0], ptr[1]);<br>}<br></blockquote><br>We are using this in pocl:<br><br>TYPE##2 _CL_OVERLOADABLE<br>vload2(size_t offset, const MOD TYPE *p)<br>{<br> return (TYPE##2)(p[offset*2], p[offset*2+1]);<br>}<br><br>which is essentially the same as you suggest.<br><br>-erik<br><br></div></blockquote><div><br></div><div>I think this will result in IR with 2 loads in it. The IR from these functions should be a single instruction with the alignment specified to be the element type’s alignment, and I don’t think anything will optimize that into it. The current implementation results in extractelement + store for each. </div><div><br></div><div><br></div><div>Something like this:</div><div><div>typedef float2 less_aligned_float2 __attribute__ ((aligned (4)));</div><div>void test_vstore2(local float* ptr, float2 val)</div><div>{</div><div>    *((local less_aligned_float2*) ptr) = val;</div><div>}</div><div><br></div><div>Gives the expected IR of a single vector store with the right alignment:</div><div><br></div><div><div>define void @test_vstore2(float addrspace(3)* nocapture %ptr, <2 x float> %val) #0 {</div><div>entry:</div><div>  %0 = bitcast float addrspace(3)* %ptr to <2 x float> addrspace(3)*</div><div>  store <2 x float> %val, <2 x float> addrspace(3)* %0, align 4, !tbaa !1</div><div>  ret void</div><div>}</div></div></div><div><br></div><div><br></div><div><br></div><br><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite"><blockquote type="cite">Signed-off-by: Aaron Watry <<a href="mailto:awatry@gmail.com">awatry@gmail.com</a>><br>---<br>generic/lib/shared/vload.cl  | 10 +++++-----<br>generic/lib/shared/vstore.cl | 16 +++++-----------<br>2 files changed, 10 insertions(+), 16 deletions(-)<br><br>diff --git a/generic/lib/shared/vload.cl b/generic/lib/shared/vload.cl<br>index 6793072..c6ea683 100644<br>--- a/generic/lib/shared/vload.cl<br>+++ b/generic/lib/shared/vload.cl<br>@@ -2,23 +2,23 @@<br><br>#define VLOAD_VECTORIZE(PRIM_TYPE, ADDR_SPACE) \<br> _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##2 vload2(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \<br>-    return (PRIM_TYPE##2)(x[2*offset] , x[2*offset+1]); \<br>+    return *((const ADDR_SPACE PRIM_TYPE##2*)(&x[2*offset])); \<br> } \<br>\<br> _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##3 vload3(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \<br>-    return (PRIM_TYPE##3)(x[3*offset] , x[3*offset+1], x[3*offset+2]); \<br>+    return *((const ADDR_SPACE PRIM_TYPE##3*)(&x[3*offset])); \<br> } \<br>\<br> _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##4 vload4(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \<br>-    return (PRIM_TYPE##4)(x[4*offset], x[4*offset+1], x[4*offset+2], x[4*offset+3]); \<br>+    return *((const ADDR_SPACE PRIM_TYPE##4*)(&x[4*offset])); \<br> } \<br>\<br> _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##8 vload8(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \<br>-    return (PRIM_TYPE##8)(vload4(0, &x[8*offset]), vload4(1, &x[8*offset])); \<br>+    return *((const ADDR_SPACE PRIM_TYPE##8*)(&x[8*offset])); \<br> } \<br>\<br> _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##16 vload16(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \<br>-    return (PRIM_TYPE##16)(vload8(0, &x[16*offset]), vload8(1, &x[16*offset])); \<br>+    return *((const ADDR_SPACE PRIM_TYPE##16*)(&x[16*offset])); \<br> } \<br><br>#define VLOAD_ADDR_SPACES(__CLC_SCALAR_GENTYPE) \<br>diff --git a/generic/lib/shared/vstore.cl b/generic/lib/shared/vstore.cl<br>index f6d360e..9cb35ad 100644<br>--- a/generic/lib/shared/vstore.cl<br>+++ b/generic/lib/shared/vstore.cl<br>@@ -4,29 +4,23 @@<br><br>#define VSTORE_VECTORIZE(PRIM_TYPE, ADDR_SPACE) \<br> _CLC_OVERLOAD _CLC_DEF void vstore2(PRIM_TYPE##2 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \<br>-    mem[2*offset] = vec.s0; \<br>-    mem[2*offset+1] = vec.s1; \<br>+    *((ADDR_SPACE PRIM_TYPE##2*)(&mem[2*offset])) = vec; \<br> } \<br>\<br> _CLC_OVERLOAD _CLC_DEF void vstore3(PRIM_TYPE##3 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \<br>-    mem[3*offset] = vec.s0; \<br>-    mem[3*offset+1] = vec.s1; \<br>-    mem[3*offset+2] = vec.s2; \<br>+    *((ADDR_SPACE PRIM_TYPE##3*)(&mem[3*offset])) = vec; \<br> } \<br>\<br> _CLC_OVERLOAD _CLC_DEF void vstore4(PRIM_TYPE##4 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \<br>-    vstore2(vec.lo, 0, &mem[offset*4]); \<br>-    vstore2(vec.hi, 1, &mem[offset*4]); \<br>+    *((ADDR_SPACE PRIM_TYPE##4*)(&mem[4*offset])) = vec; \<br> } \<br>\<br> _CLC_OVERLOAD _CLC_DEF void vstore8(PRIM_TYPE##8 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \<br>-    vstore4(vec.lo, 0, &mem[offset*8]); \<br>-    vstore4(vec.hi, 1, &mem[offset*8]); \<br>+    *((ADDR_SPACE PRIM_TYPE##8*)(&mem[8*offset])) = vec; \<br> } \<br>\<br> _CLC_OVERLOAD _CLC_DEF void vstore16(PRIM_TYPE##16 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \<br>-    vstore8(vec.lo, 0, &mem[offset*16]); \<br>-    vstore8(vec.hi, 1, &mem[offset*16]); \<br>+    *((ADDR_SPACE PRIM_TYPE##16*)(&mem[16*offset])) = vec; \<br> } \<br><br>#define VSTORE_ADDR_SPACES(__CLC_SCALAR___CLC_GENTYPE) \<br>--<span class="Apple-converted-space"> </span><br>1.9.1<br><br><br>_______________________________________________<br>Libclc-dev mailing list<br><a href="mailto:Libclc-dev@pcc.me.uk">Libclc-dev@pcc.me.uk</a><br><a href="http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev">http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev</a><br></blockquote><br>_______________________________________________<br>Libclc-dev mailing list<br><a href="mailto:Libclc-dev@pcc.me.uk">Libclc-dev@pcc.me.uk</a><br><a href="http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev">http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev</a><br></blockquote><br>--<span class="Apple-converted-space"> </span><br>Erik Schnetter <<a href="mailto:schnetter@gmail.com">schnetter@gmail.com</a>><br><a href="http://www.perimeterinstitute.ca/personal/eschnetter/">http://www.perimeterinstitute.ca/personal/eschnetter/</a><br><br>My email is as private as my paper mail. I therefore support encrypting<br>and signing email messages. Get my PGP key from<span class="Apple-converted-space"> </span><a href="http://pgp.mit.edu/">http://pgp.mit.edu/</a>.<br><br>_______________________________________________<br>Libclc-dev mailing list<br><a href="mailto:Libclc-dev@pcc.me.uk">Libclc-dev@pcc.me.uk</a><br><a href="http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev">http://www.pcc.me.uk/cgi-bin/mailman/listinfo/libclc-dev</a></div></blockquote></div><br></body></html>