10 messages in net.java.dev.jna.usersRe: [jna-users] setting structure ali...
FromSent OnAttachments
Rui CaridadeDec 8, 2008 6:07 pm 
Timothy WallDec 8, 2008 7:18 pm 
Rui CaridadeDec 8, 2008 8:26 pm 
Timothy WallDec 8, 2008 8:54 pm 
Rui CaridadeDec 8, 2008 9:05 pm 
Rui CaridadeDec 10, 2008 5:11 pm.log
Timothy WallDec 10, 2008 6:05 pm 
Rui CaridadeDec 10, 2008 6:13 pm 
Rui CaridadeDec 11, 2008 2:50 am 
Timothy WallDec 11, 2008 5:24 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] setting structure alignmentActions...
From:Rui Caridade (waih@yahoo.com)
Date:Dec 10, 2008 6:13:28 pm
List:net.java.dev.jna.users

Thank you :) I did not relate it to a padding issue because i had something like this on
vector

public float x, y, z; float __SIMD_pad__; /* Padding to 16th byte for SIMD operations (3DNow!/SSE) */

I had thought i didn't need to declare __SIMD_pad__ as public because i don't
want the user to be able to see it. By declaring it public fixes the problem :) Thank you again

________________________________ From: Timothy Wall <twal@dev.java.net> To: use@jna.dev.java.net Sent: Thursday, December 11, 2008 2:05:37 AM Subject: Re: [jna-users] setting structure alignment

On Dec 10, 2008, at 8:12 PM, Rui Caridade wrote:

Hello. I've been testing the bindings and sometimes it crashes the vm :| The err log goes at attachment. The crash is more frequent ,read happens most of the time if i call the lib for
example as follows

SIMDx86Vector vector = null; vector = SIMDx86Vector.allocate(); vector.x = 2.0f; vector.y = 2.0f; vector.z = 2.0f; System.out.println("X " + vector.x + " Y " + vector.y + " Z " +
vector.z); simd.SIMDx86Vector_Scale(vector,scale); //System.out.println(vector.toString()); System.out.println("X " + vector.x + " Y " + vector.y + " Z " +
vector.z);

If i don't comment vector.toString() i get

X 2.0 Y 2.0 Z 2.0 SIMDx86Vector(allocated@0x9a53bc8 (12 bytes)) {

This address is aligned to 8 bytes, not 16 ----^

In addition, your original C structure had 4 bytes padding to ensure a block
size of 16 bytes; your Java structure is only 12 bytes, which means a likely
read or write outside of allocated memory.

Your structure will need to allocate 15 bytes extra if there's any chance the
pointer allocated might need alignment. Memory.align() does not allocate more
memory, it just changes the base pointer and reduces the size of the allocated
block.

float x@0=4.0 float y@4=4.0 float z@8=4.0 } memory dump [00008040] [00008040] [00008040] X 4.0 Y 4.0 Z 4.0

Can anyone please point me to what i'm doing wrong? Thank you in advance

From: Rui Caridade <waih@yahoo.com> To: use@jna.dev.java.net Sent: Tuesday, December 9, 2008 5:05:55 AM Subject: Re: [jna-users] setting structure alignment

Well i could have couldn't i :| It would have been simpler....

From: Timothy Wall <twal@dev.java.net> To: use@jna.dev.java.net Sent: Tuesday, December 9, 2008 4:55:08 AM Subject: Re: [jna-users] setting structure alignment

Maybe I'm missing something, but why not just put the "align" call into the
SIMDx86Vector ctor?

Thank you :) I've tested a bit more and it all seems to work :) Jna is great :) For correctness sake, this was what i did:

protected static void setAlignment(Structure c ){ ((Memory)(c.getPointer())).align(4); }

and then for instance on Vector

SIMDx86Vector v =(SIMDx86Vector) Structure.newInstance(SIMDx86Vector.class); SIMDx86Factory.setAlignment(v); return v;

Is this correct way to do it ? :) Thank you again for your fast and unvaluable help From: Timothy Wall <twal@dev.java.net> To: use@jna.dev.java.net Sent: Tuesday, December 9, 2008 3:18:39 AM Subject: Re: [jna-users] setting structure alignment

You'll need to explicitly ensure that the memory allocated for the structure is
aligned, using Memory.align(4).

Hello. I'm currently working on creating bindings for libSIMDx86
(http://simdx86.sourceforge.net/). Some structures are aligned to the 16th byte for instance

typedef struct SIMDx86Vector { float x, y, z; float __SIMD_pad__; /* Padding to 16th byte for SIMD operations (3DNow!/SSE)
*/ } SIMDx86Vector ALIGNED;

Where aligned is

#if defined(__GNUC__) #define ALIGNED __attribute__(( aligned(16) )) #elif defined(_MSC_VER) #define ALIGNED __declspec(align(16)) #endif

My implementation is as follows

public class SIMDx86Vector extends Structure {

float x, y, z; float __SIMD_pad__; /* Padding to 16th byte for SIMD operations (3DNow!/SSE)
*/

public SIMDx86Vector allocate(){ return (SIMDx86Vector) Structure.newInstance(this.getClass()); } }

My question is do i need to do anything more on the Java side? All the best and thanks in advance

<hs_err_pid4412.log>--------------------------------------------------------------------- To unsubscribe, e-mail: user@jna.dev.java.net For additional commands, e-mail: user@jna.dev.java.net