<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Aptos;
        panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:12.0pt;
        font-family:"Aptos",sans-serif;
        mso-ligatures:standardcontextual;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Aptos",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#467886" vlink="#96607D" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">Is there way to control the alignment of `float[]` so that it loads nicely into a FloatVector?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">`jdk.incubator.vector.FloatVector.fromArray(VectorSpecies<Float>, float[], int)` creates a `FloatVector` from some elements of a `float[]`.  On a machine with 4 float vector lanes, that call reads 4 float
 values from the `float[]`.  If the 4 values from the array are properly aligned relative to a cache line boundary -- and if the cache line width is a multiple of the number of lanes -- then everything goes smoothly because every `FloatVector.fromArray` call
 will read from only one cache line.  If the values in the array are not aligned relative to a cache line boundary, then some of the `FloatVector.fromArray` calls will have to read from 2 cache lines.  On some processors, reads from 2 cache lines will take
 longer than reads from a single cache line.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">The JVM promises to align objects on 8-byte boundaries (and a user can ask for coarser alignment with `-XX:ObjectAlignmentInBytes=` in powers of 2, at the expense of wasting memory and cache space to "dark
 matter" between objects).  But the JVM makes no promises about the alignment of elements within an array, other than that they will be "naturally aligned" for the type of the element.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I can discover the alignment of the elements of a `float[]` by noting the time taken to read them into `FloatVector` instances.  And I can make use of that alignment information to pad the array to get advantageous
 alignment for the elements.  But any garbage collection could move the array to a different alignment (maintaining `ObjectAlignmentInBytes`) which would negate any padding I might have added.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Is there a way (for example, an annotation) that will align the elements of an array such that vector reads will not cross cache line boundaries?  The alignment mechanism will have to take into account the
 size of the object header (with and without compressed class pointers), the length field for the array, and any padding added to naturally align the elements of the array.  A Java programmer will have no idea about those details.  But they might be willing
 to annotate an array that they were going to use with `FloatVector`.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                                                ... peter<o:p></o:p></span></p>
</div>
</body>
</html>