@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
30 lines (24 loc) • 752 B
JavaScript
import { assert } from "../assert.js";
/**
*
* @param {number} a_offset
* @param {number} b_offset
* @param {number} byte_length
* @returns {number}
*/
export function largest_common_alignment_uint32(a_offset, b_offset, byte_length) {
assert.isNonNegativeInteger(a_offset, 'a_offset');
assert.isNonNegativeInteger(b_offset, 'b_offset');
assert.isNonNegativeInteger(byte_length, 'length');
const mask = a_offset | b_offset | byte_length;
if ((mask & 3) === 0) {
// aligned on 4-byte boundary
return 4
} else if ((mask & 1) === 0) {
// aligned on 2-byte boundary
return 2;
} else {
// worst-case, assume 1-byte boundary
return 1;
}
}