diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /dom/webgpu/tests/cts/checkout/src/external | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/webgpu/tests/cts/checkout/src/external')
4 files changed, 168 insertions, 44 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/external/README.md b/dom/webgpu/tests/cts/checkout/src/external/README.md index 84fbf9c732..29c5f41f3a 100644 --- a/dom/webgpu/tests/cts/checkout/src/external/README.md +++ b/dom/webgpu/tests/cts/checkout/src/external/README.md @@ -28,4 +28,4 @@ should be listed below. | **Name** | **Origin** | **License** | **Version** | **Purpose** | |----------------------|--------------------------------------------------|-------------|-------------|------------------------------------------------| -| petamoriken/float16 | [github](https://github.com/petamoriken/float16) | MIT | 3.6.6 | Fluent support for f16 numbers via TypedArrays | +| petamoriken/float16 | [github](https://github.com/petamoriken/float16) | MIT | 3.8.6 | Fluent support for f16 numbers via TypedArrays | diff --git a/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/LICENSE.txt b/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/LICENSE.txt index e8eacf4e7f..e3d7962fe8 100644 --- a/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/LICENSE.txt +++ b/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2021 Kenta Moriuchi +Copyright (c) 2017-2024 Kenta Moriuchi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/float16.d.ts b/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/float16.d.ts index c9d66ab7ca..7e79bc177c 100644 --- a/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/float16.d.ts +++ b/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/float16.d.ts @@ -331,6 +331,26 @@ export interface Float16Array { subarray(begin?: number, end?: number): Float16Array; /** + * Copies the array and returns the copy with the elements in reverse order. + */ + toReversed(): Float16Array; + + /** + * Copies and sorts the array. + * @param compareFn Function used to determine the order of the elements. It is expected to return + * a negative value if first argument is less than second argument, zero if they're equal and a positive + * value otherwise. If omitted, the elements are sorted in ascending. + */ + toSorted(compareFn?: (a: number, b: number) => number): Float16Array; + + /** + * Copies the array and replaces the element at the given index with the provided value. + * @param index The zero-based location in the array for which to replace an element. + * @param value Element to insert into the array in place of the replaced element. + */ + with(index: number, value: number): Float16Array; + + /** * Converts a number to a string by using the current locale. */ toLocaleString(): string; @@ -468,4 +488,11 @@ export declare function setFloat16( * Returns the nearest half-precision float representation of a number. * @param x A numeric expression. */ +export declare function f16round(x: number): number; + +/** + * Returns the nearest half-precision float representation of a number. + * @alias f16round + * @param x A numeric expression. + */ export declare function hfround(x: number): number; diff --git a/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/float16.js b/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/float16.js index 54843a4842..1031e2bcda 100644 --- a/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/float16.js +++ b/dom/webgpu/tests/cts/checkout/src/external/petamoriken/float16/float16.js @@ -1,4 +1,4 @@ -/*! @petamoriken/float16 v3.6.6 | MIT License - https://github.com/petamoriken/float16 */ +/*! @petamoriken/float16 v3.8.6 | MIT License - https://github.com/petamoriken/float16 */ const THIS_IS_NOT_AN_OBJECT = "This is not an object"; const THIS_IS_NOT_A_FLOAT16ARRAY_OBJECT = "This is not a Float16Array object"; @@ -19,6 +19,8 @@ const CANNOT_MIX_BIGINT_AND_OTHER_TYPES = const ITERATOR_PROPERTY_IS_NOT_CALLABLE = "@@iterator property is not callable"; const REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE = "Reduce of empty array with no initial value"; +const THE_COMPARISON_FUNCTION_MUST_BE_EITHER_A_FUNCTION_OR_UNDEFINED = + "The comparison function must be either a function or undefined"; const OFFSET_IS_OUT_OF_BOUNDS = "Offset is out of bounds"; function uncurryThis(target) { @@ -48,7 +50,8 @@ const { } = Reflect; const NativeProxy = Proxy; const { - MAX_SAFE_INTEGER: MAX_SAFE_INTEGER, + EPSILON, + MAX_SAFE_INTEGER, isFinite: NumberIsFinite, isNaN: NumberIsNaN, } = Number; @@ -97,7 +100,10 @@ const ArrayPrototypeToLocaleString = uncurryThis( ); const NativeArrayPrototypeSymbolIterator = ArrayPrototype[SymbolIterator]; const ArrayPrototypeSymbolIterator = uncurryThis(NativeArrayPrototypeSymbolIterator); -const MathTrunc = Math.trunc; +const { + abs: MathAbs, + trunc: MathTrunc, +} = Math; const NativeArrayBuffer = ArrayBuffer; const ArrayBufferIsView = NativeArrayBuffer.isView; const ArrayBufferPrototype = NativeArrayBuffer.prototype; @@ -146,6 +152,7 @@ const TypedArrayPrototypeGetSymbolToStringTag = uncurryThisGetter( TypedArrayPrototype, SymbolToStringTag ); +const NativeUint8Array = Uint8Array; const NativeUint16Array = Uint16Array; const Uint16ArrayFrom = (...args) => { return ReflectApply(TypedArrayFrom, NativeUint16Array, args); @@ -190,7 +197,10 @@ const SafeIteratorPrototype = ObjectCreate(null, { }, }); function safeIfNeeded(array) { - if (array[SymbolIterator] === NativeArrayPrototypeSymbolIterator) { + if ( + array[SymbolIterator] === NativeArrayPrototypeSymbolIterator && + ArrayIteratorPrototype.next === ArrayIteratorPrototypeNext + ) { return array; } const safe = ObjectCreate(SafeIteratorPrototype); @@ -221,8 +231,10 @@ function wrap(generator) { } function isObject(value) { - return (value !== null && typeof value === "object") || - typeof value === "function"; + return ( + (value !== null && typeof value === "object") || + typeof value === "function" + ); } function isObjectLike(value) { return value !== null && typeof value === "object"; @@ -232,11 +244,16 @@ function isNativeTypedArray(value) { } function isNativeBigIntTypedArray(value) { const typedArrayName = TypedArrayPrototypeGetSymbolToStringTag(value); - return typedArrayName === "BigInt64Array" || - typedArrayName === "BigUint64Array"; + return ( + typedArrayName === "BigInt64Array" || + typedArrayName === "BigUint64Array" + ); } function isArrayBuffer(value) { try { + if (ArrayIsArray(value)) { + return false; + } ArrayBufferPrototypeGetByteLength( (value)); return true; } catch (e) { @@ -254,25 +271,26 @@ function isSharedArrayBuffer(value) { return false; } } +function isAnyArrayBuffer(value) { + return isArrayBuffer(value) || isSharedArrayBuffer(value); +} function isOrdinaryArray(value) { if (!ArrayIsArray(value)) { return false; } - if (value[SymbolIterator] === NativeArrayPrototypeSymbolIterator) { - return true; - } - const iterator = value[SymbolIterator](); - return iterator[SymbolToStringTag] === "Array Iterator"; + return ( + value[SymbolIterator] === NativeArrayPrototypeSymbolIterator && + ArrayIteratorPrototype.next === ArrayIteratorPrototypeNext + ); } function isOrdinaryNativeTypedArray(value) { if (!isNativeTypedArray(value)) { return false; } - if (value[SymbolIterator] === NativeTypedArrayPrototypeSymbolIterator) { - return true; - } - const iterator = value[SymbolIterator](); - return iterator[SymbolToStringTag] === "Array Iterator"; + return ( + value[SymbolIterator] === NativeTypedArrayPrototypeSymbolIterator && + ArrayIteratorPrototype.next === ArrayIteratorPrototypeNext + ); } function isCanonicalIntegerIndexString(value) { if (typeof value !== "string") { @@ -307,11 +325,37 @@ function hasFloat16ArrayBrand(target) { return ReflectHas(constructor, brand); } +const INVERSE_OF_EPSILON = 1 / EPSILON; +function roundTiesToEven(num) { + return (num + INVERSE_OF_EPSILON) - INVERSE_OF_EPSILON; +} +const FLOAT16_MIN_VALUE = 6.103515625e-05; +const FLOAT16_MAX_VALUE = 65504; +const FLOAT16_EPSILON = 0.0009765625; +const FLOAT16_EPSILON_MULTIPLIED_BY_FLOAT16_MIN_VALUE = FLOAT16_EPSILON * FLOAT16_MIN_VALUE; +const FLOAT16_EPSILON_DEVIDED_BY_EPSILON = FLOAT16_EPSILON * INVERSE_OF_EPSILON; +function roundToFloat16(num) { + const number = +num; + if (!NumberIsFinite(number) || number === 0) { + return number; + } + const sign = number > 0 ? 1 : -1; + const absolute = MathAbs(number); + if (absolute < FLOAT16_MIN_VALUE) { + return sign * roundTiesToEven(absolute / FLOAT16_EPSILON_MULTIPLIED_BY_FLOAT16_MIN_VALUE) * FLOAT16_EPSILON_MULTIPLIED_BY_FLOAT16_MIN_VALUE; + } + const temp = (1 + FLOAT16_EPSILON_DEVIDED_BY_EPSILON) * absolute; + const result = temp - (temp - absolute); + if (result > FLOAT16_MAX_VALUE || NumberIsNaN(result)) { + return sign * Infinity; + } + return sign * result; +} const buffer = new NativeArrayBuffer(4); const floatView = new NativeFloat32Array(buffer); const uint32View = new NativeUint32Array(buffer); -const baseTable = new NativeUint32Array(512); -const shiftTable = new NativeUint32Array(512); +const baseTable = new NativeUint16Array(512); +const shiftTable = new NativeUint8Array(512); for (let i = 0; i < 256; ++i) { const e = i - 127; if (e < -27) { @@ -342,18 +386,16 @@ for (let i = 0; i < 256; ++i) { } } function roundToFloat16Bits(num) { - floatView[0] = (num); + floatView[0] = roundToFloat16(num); const f = uint32View[0]; const e = (f >> 23) & 0x1ff; return baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]); } const mantissaTable = new NativeUint32Array(2048); -const exponentTable = new NativeUint32Array(64); -const offsetTable = new NativeUint32Array(64); for (let i = 1; i < 1024; ++i) { let m = i << 13; let e = 0; - while((m & 0x00800000) === 0) { + while ((m & 0x00800000) === 0) { m <<= 1; e -= 0x00800000; } @@ -364,6 +406,7 @@ for (let i = 1; i < 1024; ++i) { for (let i = 1024; i < 2048; ++i) { mantissaTable[i] = 0x38000000 + ((i - 1024) << 13); } +const exponentTable = new NativeUint32Array(64); for (let i = 1; i < 31; ++i) { exponentTable[i] = i << 23; } @@ -373,14 +416,15 @@ for (let i = 33; i < 63; ++i) { exponentTable[i] = 0x80000000 + ((i - 32) << 23); } exponentTable[63] = 0xc7800000; +const offsetTable = new NativeUint16Array(64); for (let i = 1; i < 64; ++i) { if (i !== 32) { offsetTable[i] = 1024; } } function convertToNumber(float16bits) { - const m = float16bits >> 10; - uint32View[0] = mantissaTable[offsetTable[m] + (float16bits & 0x3ff)] + exponentTable[m]; + const i = float16bits >> 10; + uint32View[0] = mantissaTable[offsetTable[i] + (float16bits & 0x3ff)] + exponentTable[i]; return floatView[0]; } @@ -572,26 +616,20 @@ class Float16Array { let float16bitsArray; if (isFloat16Array(input)) { float16bitsArray = ReflectConstruct(NativeUint16Array, [getFloat16BitsArray(input)], new.target); - } else if (isObject(input) && !isArrayBuffer(input)) { + } else if (isObject(input) && !isAnyArrayBuffer(input)) { let list; let length; if (isNativeTypedArray(input)) { list = input; length = TypedArrayPrototypeGetLength(input); const buffer = TypedArrayPrototypeGetBuffer(input); - const BufferConstructor = !isSharedArrayBuffer(buffer) - ? (SpeciesConstructor( - buffer, - NativeArrayBuffer - )) - : NativeArrayBuffer; if (IsDetachedBuffer(buffer)) { throw NativeTypeError(ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER); } if (isNativeBigIntTypedArray(input)) { throw NativeTypeError(CANNOT_MIX_BIGINT_AND_OTHER_TYPES); } - const data = new BufferConstructor( + const data = new NativeArrayBuffer( length * BYTES_PER_ELEMENT ); float16bitsArray = ReflectConstruct(NativeUint16Array, [data], new.target); @@ -758,6 +796,30 @@ class Float16Array { } return convertToNumber(float16bitsArray[k]); } + with(index, value) { + assertFloat16Array(this); + const float16bitsArray = getFloat16BitsArray(this); + const length = TypedArrayPrototypeGetLength(float16bitsArray); + const relativeIndex = ToIntegerOrInfinity(index); + const k = relativeIndex >= 0 ? relativeIndex : length + relativeIndex; + const number = +value; + if (k < 0 || k >= length) { + throw NativeRangeError(OFFSET_IS_OUT_OF_BOUNDS); + } + const uint16 = new NativeUint16Array( + TypedArrayPrototypeGetBuffer(float16bitsArray), + TypedArrayPrototypeGetByteOffset(float16bitsArray), + TypedArrayPrototypeGetLength(float16bitsArray) + ); + const cloned = new Float16Array( + TypedArrayPrototypeGetBuffer( + TypedArrayPrototypeSlice(uint16) + ) + ); + const array = getFloat16BitsArray(cloned); + array[k] = roundToFloat16Bits(number); + return cloned; + } map(callback, ...opts) { assertFloat16Array(this); const float16bitsArray = getFloat16BitsArray(this); @@ -995,6 +1057,23 @@ class Float16Array { TypedArrayPrototypeReverse(float16bitsArray); return this; } + toReversed() { + assertFloat16Array(this); + const float16bitsArray = getFloat16BitsArray(this); + const uint16 = new NativeUint16Array( + TypedArrayPrototypeGetBuffer(float16bitsArray), + TypedArrayPrototypeGetByteOffset(float16bitsArray), + TypedArrayPrototypeGetLength(float16bitsArray) + ); + const cloned = new Float16Array( + TypedArrayPrototypeGetBuffer( + TypedArrayPrototypeSlice(uint16) + ) + ); + const clonedFloat16bitsArray = getFloat16BitsArray(cloned); + TypedArrayPrototypeReverse(clonedFloat16bitsArray); + return cloned; + } fill(value, ...opts) { assertFloat16Array(this); const float16bitsArray = getFloat16BitsArray(this); @@ -1020,6 +1099,29 @@ class Float16Array { }); return this; } + toSorted(compareFn) { + assertFloat16Array(this); + const float16bitsArray = getFloat16BitsArray(this); + if (compareFn !== undefined && typeof compareFn !== "function") { + throw new NativeTypeError(THE_COMPARISON_FUNCTION_MUST_BE_EITHER_A_FUNCTION_OR_UNDEFINED); + } + const sortCompare = compareFn !== undefined ? compareFn : defaultCompare; + const uint16 = new NativeUint16Array( + TypedArrayPrototypeGetBuffer(float16bitsArray), + TypedArrayPrototypeGetByteOffset(float16bitsArray), + TypedArrayPrototypeGetLength(float16bitsArray) + ); + const cloned = new Float16Array( + TypedArrayPrototypeGetBuffer( + TypedArrayPrototypeSlice(uint16) + ) + ); + const clonedFloat16bitsArray = getFloat16BitsArray(cloned); + TypedArrayPrototypeSort(clonedFloat16bitsArray, (x, y) => { + return sortCompare(convertToNumber(x), convertToNumber(y)); + }); + return cloned; + } slice(start, end) { assertFloat16Array(this); const float16bitsArray = getFloat16BitsArray(this); @@ -1216,13 +1318,8 @@ function setFloat16(dataView, byteOffset, value, ...opts) { ); } -function hfround(x) { - const number = +x; - if (!NumberIsFinite(number) || number === 0) { - return number; - } - const x16 = roundToFloat16Bits(number); - return convertToNumber(x16); +function f16round(x) { + return roundToFloat16(x); } -export { Float16Array, getFloat16, hfround, isFloat16Array, isTypedArray, setFloat16 }; +export { Float16Array, f16round, getFloat16, f16round as hfround, isFloat16Array, isTypedArray, setFloat16 };
\ No newline at end of file |