/* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed or intended for use * in the design, construction, operation or maintenance of any nuclear * facility. * * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ package com.jogamp.common.os; import jogamp.common.os.PlatformPropsImpl; /** * Machine data description for alignment and size onle, see {@link com.jogamp.gluegen}. *
* {@code little-endian} / {@code big/endian} description is left, * allowing re-using instances in {@link MachineDataInfo.StaticConfig StaticConfig}. * Use {@link {@link PlatformPropsImpl#LITTLE_ENDIAN}. *
** Further more, the value {@ MachineDataInfo#pageSizeInBytes} shall be ignored * in {@link MachineDataInfo.StaticConfig StaticConfig}, see {@link MachineDataInfo#compatible(MachineDataInfo)}. *
*/ public class MachineDataInfo { /* arch os int, long, float, doubl, ldoubl, ptr, page */ private final static int[] size_arm_mips_32 = { 4, 4, 4, 8, 8, 4, 4096 }; private final static int[] size_x86_32_unix = { 4, 4, 4, 8, 12, 4, 4096 }; private final static int[] size_x86_32_macos = { 4, 4, 4, 8, 16, 4, 4096 }; private final static int[] size_ppc_32_unix = { 4, 4, 4, 8, 16, 4, 4096 }; private final static int[] size_sparc_32_sunos = { 4, 4, 4, 8, 16, 4, 8192 }; private final static int[] size_x86_32_windows = { 4, 4, 4, 8, 12, 4, 4096 }; private final static int[] size_lp64_unix = { 4, 8, 4, 8, 16, 8, 4096 }; private final static int[] size_x86_64_windows = { 4, 4, 4, 8, 16, 8, 4096 }; private final static int[] size_arm64_ios = { 4, 8, 4, 8, 8, 8, 8192 }; /* arch os i8, i16, i32, i64, int, long, float, doubl, ldoubl, ptr */ private final static int[] align_arm_mips_32 = { 1, 2, 4, 8, 4, 4, 4, 8, 8, 4 }; private final static int[] align_x86_32_unix = { 1, 2, 4, 4, 4, 4, 4, 4, 4, 4 }; private final static int[] align_x86_32_macos = { 1, 2, 4, 4, 4, 4, 4, 4, 16, 4 }; private final static int[] align_ppc_32_unix = { 1, 2, 4, 8, 4, 4, 4, 8, 16, 4 }; private final static int[] align_sparc_32_sunos = { 1, 2, 4, 8, 4, 4, 4, 8, 8, 4 }; private final static int[] align_x86_32_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 4, 4 }; private final static int[] align_lp64_unix = { 1, 2, 4, 8, 4, 8, 4, 8, 16, 8 }; private final static int[] align_x86_64_windows = { 1, 2, 4, 8, 4, 4, 4, 8, 16, 8 }; private final static int[] align_arm64_ios = { 1, 2, 4, 8, 4, 8, 4, 8, 8, 8 }; /** * Static enumeration of {@link MachineDataInfo} instances * used for high performance data size and alignment lookups, * e.g. for generated structures using the {@link MachineDataInfo.StaticConfig} index. ** The value {@link MachineDataInfo#pageSizeInBytes} shall be ignored * for static instances! *
** If changing this table, you need to: *
MachineDataInfo
are considered equal if all components
* match but {@link #runtimeValidated}, {@link #isRuntimeValidated()}.
* @return true
if the two MachineDataInfo are equal;
* otherwise false
.
*/
@Override
public final boolean equals(final Object obj) {
if (this == obj) { return true; }
if ( !(obj instanceof MachineDataInfo) ) { return false; }
final MachineDataInfo md = (MachineDataInfo) obj;
return pageSizeInBytes == md.pageSizeInBytes &&
compatible(md);
}
/**
* Checks whether two {@link MachineDataInfo} objects are equal.
* * Two {@link MachineDataInfo} instances are considered equal if all components * match but {@link #isRuntimeValidated()} and {@link #pageSizeInBytes()}. *
* @returntrue
if the two {@link MachineDataInfo} are equal;
* otherwise false
.
*/
public final boolean compatible(final MachineDataInfo md) {
return intSizeInBytes == md.intSizeInBytes &&
longSizeInBytes == md.longSizeInBytes &&
floatSizeInBytes == md.floatSizeInBytes &&
doubleSizeInBytes == md.doubleSizeInBytes &&
ldoubleSizeInBytes == md.ldoubleSizeInBytes &&
pointerSizeInBytes == md.pointerSizeInBytes &&
int8AlignmentInBytes == md.int8AlignmentInBytes &&
int16AlignmentInBytes == md.int16AlignmentInBytes &&
int32AlignmentInBytes == md.int32AlignmentInBytes &&
int64AlignmentInBytes == md.int64AlignmentInBytes &&
intAlignmentInBytes == md.intAlignmentInBytes &&
longAlignmentInBytes == md.longAlignmentInBytes &&
floatAlignmentInBytes == md.floatAlignmentInBytes &&
doubleAlignmentInBytes == md.doubleAlignmentInBytes &&
ldoubleAlignmentInBytes == md.ldoubleAlignmentInBytes &&
pointerAlignmentInBytes == md.pointerAlignmentInBytes ;
}
public StringBuilder toString(StringBuilder sb) {
if(null==sb) {
sb = new StringBuilder();
}
sb.append("MachineDataInfo: runtimeValidated ").append(isRuntimeValidated()).append(", 32Bit ").append(4 == pointerAlignmentInBytes).append(", primitive size / alignment:").append(PlatformPropsImpl.NEWLINE);
sb.append(" int8 ").append(int8SizeInBytes) .append(" / ").append(int8AlignmentInBytes);
sb.append(", int16 ").append(int16SizeInBytes) .append(" / ").append(int16AlignmentInBytes).append(Platform.getNewline());
sb.append(" int ").append(intSizeInBytes) .append(" / ").append(intAlignmentInBytes);
sb.append(", long ").append(longSizeInBytes) .append(" / ").append(longAlignmentInBytes).append(Platform.getNewline());
sb.append(" int32 ").append(int32SizeInBytes) .append(" / ").append(int32AlignmentInBytes);
sb.append(", int64 ").append(int64SizeInBytes) .append(" / ").append(int64AlignmentInBytes).append(Platform.getNewline());
sb.append(" float ").append(floatSizeInBytes) .append(" / ").append(floatAlignmentInBytes);
sb.append(", double ").append(doubleSizeInBytes) .append(" / ").append(doubleAlignmentInBytes);
sb.append(", ldouble ").append(ldoubleSizeInBytes).append(" / ").append(ldoubleAlignmentInBytes).append(Platform.getNewline());
sb.append(" pointer ").append(pointerSizeInBytes).append(" / ").append(pointerAlignmentInBytes);
sb.append(", page ").append(pageSizeInBytes);
return sb;
}
@Override
public String toString() {
return toString(null).toString();
}
}