<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"><a href="https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html#//apple_ref/doc/uid/TP40002492-SW4" class="OWAAutoLink" id="LPlnk942661" previewremoved="true">https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html#//apple_ref/doc/uid/TP40002492-SW4</a></p>
<p style="margin-top:0;margin-bottom:0"></p>
<div id="LPBorder_GT_15171110143350.5863057682920306" style="margin-bottom: 20px; overflow: auto; width: 100%; text-indent: 0px;">
<table id="LPContainer_15171110143310.14778827017465412" style="width: 90%; background-color: rgb(255, 255, 255); position: relative; overflow: auto; padding-top: 20px; padding-bottom: 20px; margin-top: 20px; border-top: 1px dotted rgb(200, 200, 200); border-bottom: 1px dotted rgb(200, 200, 200);" role="presentation" cellspacing="0">
<tbody>
<tr style="border-spacing: 0px;" valign="top">
<td id="TextCell_15171110143340.5266193676546563" style="vertical-align: top; position: relative; padding: 0px; display: table-cell;" colspan="2">
<div id="LPRemovePreviewContainer_15171110143340.19944181633366054"></div>
<div id="LPTitle_15171110143340.22628333714430937" style="top: 0px; color: rgb(0, 120, 215); font-weight: 400; font-size: 21px; font-family: "wf_segoe-ui_light", "Segoe UI Light", "Segoe WP Light", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; line-height: 21px;">
<a id="LPUrlAnchor_15171110143350.3154603768868105" style="text-decoration: none;" href="https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html#//apple_ref/doc/uid/TP40002492-SW4" target="_blank">IA-32
Function Calling Conventions - Apple Developer</a></div>
<div id="LPMetadata_15171110143350.24586411836362254" style="margin: 10px 0px 16px; color: rgb(102, 102, 102); font-weight: 400; font-family: "wf_segoe-ui_normal", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; line-height: 14px;">
developer.apple.com</div>
<div id="LPDescription_15171110143350.4890541542601774" style="display: block; color: rgb(102, 102, 102); font-weight: 400; font-family: "wf_segoe-ui_normal", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; line-height: 20px; max-height: 100px; overflow: hidden;">
Describes the function-calling conventions used in the architectures supported by OS X.</div>
</td>
</tr>
</tbody>
</table>
</div>
If we generate portable C or C++, do it probably the way I said.
<p></p>
<p style="margin-top:0;margin-bottom:0">If we generate target-specific code, I386_DARWIN can assume 16-alignment (after adjusting by an odd multiple of 8).</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">But another way, is use the local struct, but maybe no pointer is needed.</p>
<p style="margin-top:0;margin-bottom:0">There might be a portable way to get it aligned -- like by always putting a 64bit double or longlong at its start.</p>
<p style="margin-top:0;margin-bottom:0">Or some compiler-specific attribute/declspec.<br>
</p>
<p style="margin-top:0;margin-bottom:0">We'd have to determine if double is 16-aligned (I think not guaranteed) or if there is a portable-enough way.</p>
<p style="margin-top:0;margin-bottom:0">Maybe C++11 alignas(16) or somesuch -- see generating C++ gets good exception handling, aligned stacks, etc. :)<br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"> - Jay<br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<div id="Signature"><br>
</div>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>From:</b> M3devel <m3devel-bounces@elegosoft.com> on behalf of Jay K <jayk123@hotmail.com><br>
<b>Sent:</b> Sunday, January 28, 2018 3:42 AM<br>
<b>To:</b> m3devel@elegosoft.com; rodney.m.bates@acm.org<br>
<b>Subject:</b> Re: [M3devel] 64-bit alignment on 32-bit target?</font>
<div> </div>
</div>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p style="margin-top:0; margin-bottom:0">Well, those are good points, I hadn't thought of it, however:</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"> - Sections within an image must be page aligned. That is how Windows works and it is all but necessary, to have different page attributes.</p>
<p style="margin-top:0; margin-bottom:0"> - Heap on Windows is 2x pointer aligned, so that is adequate. To layer that on top of an unaligned heap is cheap enough. Heap being expensive anyway. WIndows has this _aligned_malloc thing but it is overused, since
the builtin alignment is usually adequate.</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">- Leaving the stack. Dynamic static alignment on x86 has been a thing for a long time, like because SSE/XMM. Because you are right the typical x86 ABI stack alignment is probably 4 or maybe 1. I bet MacOSX already is
16 since it was SSE/XMM from the start (and 32bit is on the way out anyway).</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">Dynamic stack alignment should be achievable at the Modula-3 level but with higher cost than what C compilers do.</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">The C compiler can save the stack pointer, allocate extra, round it, and use the same offsets after that, with no impact to code beyond the prolog.</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">To do this portably however, we would have to..imagine generating C..put all aligned locals in a struct, pad the struct with alignment-1, get a pointer to the struct, and then align that, and use that, constant indirection
for every access. It isn't as bad as it sounds because it would only be needed for local structs that contain a LONGINT (recursively).</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"> - Jay<br>
</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<br>
<br>
<div style="color:rgb(0,0,0)">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>From:</b> Rodney M. Bates <rodney_bates@lcwb.coop><br>
<b>Sent:</b> Sunday, January 28, 2018 3:08 AM<br>
<b>To:</b> m3devel@elegosoft.com; Jay K<br>
<b>Subject:</b> Re: [M3devel] 64-bit alignment on 32-bit target?</font>
<div> </div>
</div>
<div class="x_BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="x_PlainText">This would be nice, but thinking about it more, this seems like a huge tar pit.<br>
<br>
Aligning *within* a record, array, activation record, heap object, global area, etc. can be<br>
done with existing mechanisms just by setting the alignment for LONGINT. But getting these<br>
entire areas 64-aligned on a 32-bit target is messy.<br>
<br>
For example, for stacks, you either have to make every field 64-aligned, so it is always that way<br>
or do runtime alignment, conditional on whether it's already 64-aligned, at call sites, before<br>
pushing any parameters, return address, etc. Neither is nice. And it's difficult to do it<br>
conditionally on whether the to-be-called AR contains 64-aligned fields (usually not) because<br>
you don't necessarily have anything but the signature for the callee when compiling call site code.<br>
<br>
All heap objects pretty much have to be 64-aligned. I think mixed alignments of heap objects<br>
has probably been shown to be a real mess, and in the case of opaque types, you may not know<br>
at the NEW site what the needed alignment is anyway.<br>
<br>
Also, the linker and loader would have to put sections on 64-bit boundaries as well. Maybe some<br>
do, but we can hardly depend on it universally, and these are tools we don't control.<br>
<br>
On 01/26/2018 01:09 PM, Jay K wrote:<br>
> I believe LONGINT should be 64-aligned on 32-bit x86 so for example you can use InterlockedCompareExchange64 on it.<br>
<br>
Is it feasible to implement a 64-bit atomic operation on a 32-bit machine anyway, with, often,<br>
32-bit RAM access? That would entail making a pair of accesses to a pair of words all atomic.<br>
And if that could happen, the pair probably wouldn't need to be 64-aligned anyway.<br>
<br>
><br>
> I suggest LONGINT should be 64-aligned so maybe all targets have the same layout, in general.<br>
><br>
><br>
> - Jay<br>
><br>
><br>
><br>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
> *From:* M3devel <m3devel-bounces@elegosoft.com> on behalf of Rodney M. Bates <rodney_bates@lcwb.coop><br>
> *Sent:* Friday, January 26, 2018 6:35 PM<br>
> *To:* m3devel<br>
> *Subject:* [M3devel] 64-bit alignment on 32-bit target?<br>
><br>
> Does anybody know:<br>
><br>
> Do we support, or does there even exist, a target that has 32-bit native words,<br>
> but has some instruction or other reason why some operand would need to be<br>
> 64-bit aligned?<br>
><br>
> We appear to be 64-bit aligning LONGINT and big enough subranges thereof on<br>
> 32-bit targets, which then needs to propagate through records, arrays, and objects<br>
> that contain them, as well as all heap allocated objects, stack frames, etc.<br>
><br>
> --<br>
> Rodney Bates<br>
> rodney.m.bates@acm.org<br>
> _______________________________________________<br>
> M3devel mailing list<br>
> M3devel@elegosoft.com<br>
> <a href="https://m3lists.elegosoft.com/mailman/listinfo/m3devel" id="LPlnk39758" previewremoved="true">
https://m3lists.elegosoft.com/mailman/listinfo/m3devel</a><br>
><br>
><br>
> _______________________________________________<br>
> M3devel mailing list<br>
> M3devel@elegosoft.com<br>
> <a href="https://m3lists.elegosoft.com/mailman/listinfo/m3devel" id="LPlnk321912" previewremoved="true">
https://m3lists.elegosoft.com/mailman/listinfo/m3devel</a><br>
><br>
<br>
-- <br>
Rodney Bates<br>
rodney.m.bates@acm.org<br>
</div>
</span></font></div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>