[Sablevm-user] Re: 64 bit alignment
Brought to you by:
egagnon
From: Etienne M. G. <eg...@j-...> - 2000-11-30 20:28:22
|
xli wrote: > > Thank you for your reply. > > > On a 64 bit platform, sizeof(void *) will be 64 bits. All we have to > > do, now, is make sure the remaining of the stack is aligned (which I > > have to double check). > > I think you are right for a 64 bit platform. However, I tried your idea > on a SPARC architecture which is a 32 bit platform but requires 64 bit > allignment for doubles (longs). For example, the following code: > > #define allignment() {if ((int)(p)&0x00000007) p++;} > > main(){ > int *p; > double d1, d2, d3; > > d1 = 123.5; > d2 = 45.7892; > > p = (int*) malloc(20*sizeof(void*)); > > p++; > > // allignment(); > > *((double*) p) = d1; > > p += 2; > > *((double*) p) = d2; > > d3 = *(double*) p + *(double*) (p-2); > > printf(" %f + %f = %f \n", d1, d2, d3); > } > > will cause a bus error if the allignment macro is ommitted. > I didn't know about that. In this case, there's an ugly solution (maybe not that ugly): union _svmt_stack_frame_entry_union { jint jint; jfloat jfloat; void *addr; #ifdef DOUBLE_ALIGNMENT jdouble dummy_jdouble; #endif }; > I also tried the above code on my PC, it works because ix86 architecture > does not require such kind of allignment (I guess). > > >This is an important point to check. I will need a lot of feedback from > >people like you to make sure SableVM is easily portable to various > >systems with a minimal effort. > > This is also an important point for me, as I am now working on a > Prolog virtual machine which should be portable to various platforms. > > Cheers. > > Li -- ---------------------------------------------------------------------- Etienne M. Gagnon, M.Sc. e-mail: eg...@j-... Author of SableCC: http://www.sable.mcgill.ca/sablecc/ and SableVM: http://www.sablevm.org/ ---------------------------------------------------------------------- |