[M3devel] LONGINT/LONGREAL alignment on 32bit targets?
Jay K
jay.krell at cornell.edu
Mon Sep 21 09:21:47 CEST 2015
er, ok, I partly did this.
https://modula3.elegosoft.com/cgi-bin/cvsweb.cgi/cm3/m3-sys/m3middle/src/Target.m3.diff?r1=1.95;r2=1.96;f=u
Revision 1.96: download - view: text, markup, annotated - select for diffsThu Apr 1 17:56:37 2010 (5 years, 5 months ago) by jkrellBranches: MAINDiff to: previous 1.95: preferred, unifiedChanges since revision 1.95: +1 -9 lines
leave max_align = 64 for all platformsthis effects: I386_FREEBSD / FreeBSD4 I386_LINUX / LINUXLIBC6 NetBSD2_i386
It does not affect any others -- not PPC, not Darwin, not 64bit, not Solaris, not NT.
but it wasn't consistent across 32bit platforms or x86.Nor should it necessarily -- I recall Cygwin wants to alignmore than cm3, implying NT does.
- Jay
From: jay.krell at cornell.edu
To: m3devel at elegosoft.com
Date: Mon, 21 Sep 2015 07:07:21 +0000
Subject: Re: [M3devel] LONGINT/LONGREAL alignment on 32bit targets?
Hm. Same thing with double/LONGREAL.Do we need to fix this??Or just use it as evidence that our interop isn't perfect but adequate?
jair:1 jay$ cat 1.c src/Main.m3#include <stdio.h>
int main(){printf("%d\n", (int)sizeof(struct {int a; double b;}));return 0;}
MODULE Main;IMPORT IO, Fmt, Ctypes;
BEGINIO.Put(Fmt.Int(BYTESIZE(RECORD a:Ctypes.int; b:LONGREAL; END)));IO.Put("\n");END Main.
jair:1 jay$ rm -rf I386_DARWIN/jair:1 jay$ cm3 -DTARGET=I386_DARWIN --- building in I386_DARWIN ---
new source -> compiling Main.m3 -> linking ajair:1 jay$ ./I386_DARWIN/a16jair:1 jay$ cc -m32 1.cjair:1 jay$ ./a.out12jair:1 jay$
- Jay
From: jay.krell at cornell.edu
To: m3devel at elegosoft.com
Date: Mon, 21 Sep 2015 07:04:49 +0000
Subject: [M3devel] LONGINT alignment on 32bit targets?
For the record, I didn't do this, way back even in:
https://modula3.elegosoft.com/cgi-bin/cvsweb.cgi/cm3/m3-sys/m3middle/src/Target.m3?rev=1.1;content-type=text%2Fplain
we had:
(* build a generic 32-bit/IEEE system description *)
Int64.cg_type := CGType.Int64; Int64.size := 64; Int64.align := 64; Int64.min.x := IChunks { 00, 00, 00, 16_8000 }; Int64.max.x := IChunks { FF, FF, FF, 16_7fff };
This is likely wrong on many/most/all 32bit targets.
Int64 is likely to be loaded/stored with two 32bit operations, therefore align probably should be 32.
At the time, I don't think there was any way to use this type, i.e.there was no LONGINT.
Once LONGINT came into being, if you wrote:
foo.m3RECORD a: Ctypes.int; b: LONGINTEND;
and foo.c:struct { int a; long long b;};
you would probably get different layout.
Let's see:
jair:src jay$ cat 1.cint a = sizeof(struct { int a; long long b;});jair:src jay$ cc -c -S -m32 1.cjair:src jay$ cat 1.s .section __TEXT,__text,regular,pure_instructions .macosx_version_min 10, 10 .section __DATA,__data .globl _a ## @a .align 2_a: .long 12 ## 0xc
jair:1 jay$ cat 1.c src/Main.m3 src/m3makefile #include <stdio.h>
int main(){printf("%d\n", (int)sizeof(struct {int a; long long b;}));return 0;}
MODULE Main;IMPORT IO, Fmt, Ctypes;
BEGINIO.Put(Fmt.Int(BYTESIZE(RECORD a:Ctypes.int; b:LONGINT; END)));IO.Put("\n");END Main.
import("m3core")import("libm3")implementation("Main")build_standalone()program("a")
jair:1 jay$ cc -m32 1.cjair:1 jay$ ./a.out12
jair:1 jay$ cm3 -DTARGET=I386_DARWIN --- building in I386_DARWIN ---
new source -> compiling Main.m3 -> linking ajair:1 jay$ ./I386_DARWIN/a
16
Now, if you are going to use x86 interlocked instructions on this,you might need higher alignment anyway. Might.
(Which all goes to my point -- while layout rules can't actually be removed,they have to exist, it does behoove one to try to layout data that hasobvious portable layout, if you need interop. i.e. you just would not everhave a record like this. You would make the likely padding explicit.Or sort by size. Though once you put records within records, it becomesdifficult/impossible.)
- Jay
_______________________________________________
M3devel mailing list
M3devel at elegosoft.com
https://mail.elegosoft.com/cgi-bin/mailman/listinfo/m3devel
_______________________________________________
M3devel mailing list
M3devel at elegosoft.com
https://mail.elegosoft.com/cgi-bin/mailman/listinfo/m3devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20150921/64152667/attachment-0002.html>
More information about the M3devel
mailing list