JS_CLASS_UINT32_ARRAY, /* u.array (typed_array) */
JS_CLASS_BIG_INT64_ARRAY, /* u.array (typed_array) */
JS_CLASS_BIG_UINT64_ARRAY, /* u.array (typed_array) */
+ JS_CLASS_FLOAT16_ARRAY, /* u.array (typed_array) */
JS_CLASS_FLOAT32_ARRAY, /* u.array (typed_array) */
JS_CLASS_FLOAT64_ARRAY, /* u.array (typed_array) */
JS_CLASS_DATAVIEW, /* u.typed_array */
uint32_t *uint32_ptr; /* JS_CLASS_UINT32_ARRAY */
int64_t *int64_ptr; /* JS_CLASS_INT64_ARRAY */
uint64_t *uint64_ptr; /* JS_CLASS_UINT64_ARRAY */
+ uint16_t *fp16_ptr; /* JS_CLASS_FLOAT16_ARRAY */
float *float_ptr; /* JS_CLASS_FLOAT32_ARRAY */
double *double_ptr; /* JS_CLASS_FLOAT64_ARRAY */
} u;
{ JS_ATOM_Uint32Array, js_typed_array_finalizer, js_typed_array_mark }, /* JS_CLASS_UINT32_ARRAY */
{ JS_ATOM_BigInt64Array, js_typed_array_finalizer, js_typed_array_mark }, /* JS_CLASS_BIG_INT64_ARRAY */
{ JS_ATOM_BigUint64Array, js_typed_array_finalizer, js_typed_array_mark }, /* JS_CLASS_BIG_UINT64_ARRAY */
+ { JS_ATOM_Float16Array, js_typed_array_finalizer, js_typed_array_mark }, /* JS_CLASS_FLOAT16_ARRAY */
{ JS_ATOM_Float32Array, js_typed_array_finalizer, js_typed_array_mark }, /* JS_CLASS_FLOAT32_ARRAY */
{ JS_ATOM_Float64Array, js_typed_array_finalizer, js_typed_array_mark }, /* JS_CLASS_FLOAT64_ARRAY */
{ JS_ATOM_DataView, js_typed_array_finalizer, js_typed_array_mark }, /* JS_CLASS_DATAVIEW */
case JS_CLASS_UINT32_ARRAY:
case JS_CLASS_BIG_INT64_ARRAY:
case JS_CLASS_BIG_UINT64_ARRAY:
+ case JS_CLASS_FLOAT16_ARRAY:
case JS_CLASS_FLOAT32_ARRAY:
case JS_CLASS_FLOAT64_ARRAY:
p->is_exotic = 1;
case JS_CLASS_UINT32_ARRAY: /* u.typed_array / u.array */
case JS_CLASS_BIG_INT64_ARRAY: /* u.typed_array / u.array */
case JS_CLASS_BIG_UINT64_ARRAY: /* u.typed_array / u.array */
+ case JS_CLASS_FLOAT16_ARRAY: /* u.typed_array / u.array */
case JS_CLASS_FLOAT32_ARRAY: /* u.typed_array / u.array */
case JS_CLASS_FLOAT64_ARRAY: /* u.typed_array / u.array */
case JS_CLASS_DATAVIEW: /* u.typed_array */
case JS_CLASS_BIG_UINT64_ARRAY:
if (unlikely(idx >= p->u.array.count)) goto slow_path;
return JS_NewBigUint64(ctx, p->u.array.u.uint64_ptr[idx]);
+ case JS_CLASS_FLOAT16_ARRAY:
+ if (unlikely(idx >= p->u.array.count)) goto slow_path;
+ return __JS_NewFloat64(ctx, fromfp16(p->u.array.u.fp16_ptr[idx]));
case JS_CLASS_FLOAT32_ARRAY:
if (unlikely(idx >= p->u.array.count)) goto slow_path;
return __JS_NewFloat64(ctx, p->u.array.u.float_ptr[idx]);
p->u.array.u.uint64_ptr[idx] = v;
}
break;
+ case JS_CLASS_FLOAT16_ARRAY:
+ if (JS_ToFloat64Free(ctx, &d, val))
+ return -1;
+ if (unlikely(idx >= (uint32_t)p->u.array.count))
+ goto ta_out_of_bound;
+ p->u.array.u.fp16_ptr[idx] = tofp16(d);
+ break;
case JS_CLASS_FLOAT32_ARRAY:
if (JS_ToFloat64Free(ctx, &d, val))
return -1;
case JS_CLASS_BIG_UINT64_ARRAY:
js_printf(s, "%" PRIu64, *(uint64_t *)ptr);
break;
+ case JS_CLASS_FLOAT16_ARRAY:
+ js_print_float64(s, fromfp16(*(uint16_t *)ptr));
+ break;
case JS_CLASS_FLOAT32_ARRAY:
js_print_float64(s, *(float *)ptr);
break;
return JS_NewFloat64(ctx, r);
}
+static double js_math_f16round(double a)
+{
+ return fromfp16(tofp16(a));
+}
+
static double js_math_fround(double a)
{
return (float)a;
JS_CFUNC_SPECIAL_DEF("cbrt", 1, f_f, cbrt ),
JS_CFUNC_DEF("hypot", 2, js_math_hypot ),
JS_CFUNC_DEF("random", 0, js_math_random ),
+ JS_CFUNC_SPECIAL_DEF("f16round", 1, f_f, js_math_f16round ),
JS_CFUNC_SPECIAL_DEF("fround", 1, f_f, js_math_fround ),
JS_CFUNC_DEF("imul", 2, js_math_imul ),
JS_CFUNC_DEF("clz32", 1, js_math_clz32 ),
static uint8_t const typed_array_size_log2[JS_TYPED_ARRAY_COUNT] = {
0, 0, 0, 1, 1, 2, 2,
- 3, 3, /* BigInt64Array, BigUint64Array */
- 2, 3
+ 3, 3, // BigInt64Array, BigUint64Array
+ 1, 2, 3 // Float16Array, Float32Array, Float64Array
};
static JSValue js_array_buffer_constructor3(JSContext *ctx,
double d;
if (JS_ToFloat64(ctx, &d, argv[0]))
return JS_EXCEPTION;
- if (p->class_id == JS_CLASS_FLOAT32_ARRAY) {
+ if (p->class_id == JS_CLASS_FLOAT16_ARRAY) {
+ v64 = tofp16(d);
+ } else if (p->class_id == JS_CLASS_FLOAT32_ARRAY) {
union {
float f;
uint32_t u32;
int64_t v64;
double d;
float f;
+ uint16_t hf;
len = js_typed_array_get_length_internal(ctx, this_val);
if (len < 0)
}
}
break;
+ case JS_CLASS_FLOAT16_ARRAY:
+ if (is_bigint)
+ break;
+ if (isnan(d)) {
+ const uint16_t *pv = p->u.array.u.fp16_ptr;
+ /* special case: indexOf returns -1, includes finds NaN */
+ if (special != special_includes)
+ goto done;
+ for (; k != stop; k += inc) {
+ if (isfp16nan(pv[k])) {
+ res = k;
+ break;
+ }
+ }
+ } else if (d == 0) {
+ // special case: includes also finds negative zero
+ const uint16_t *pv = p->u.array.u.fp16_ptr;
+ for (; k != stop; k += inc) {
+ if (isfp16zero(pv[k])) {
+ res = k;
+ break;
+ }
+ }
+ } else if (hf = tofp16(d), d == fromfp16(hf)) {
+ const uint16_t *pv = p->u.array.u.fp16_ptr;
+ for (; k != stop; k += inc) {
+ if (pv[k] == hf) {
+ res = k;
+ break;
+ }
+ }
+ }
+ break;
case JS_CLASS_FLOAT32_ARRAY:
if (is_bigint)
break;
return (y < x) - (y > x);
}
+static int js_TA_cmp_float16(const void *a, const void *b, void *opaque) {
+ return js_cmp_doubles(fromfp16(*(const uint16_t *)a),
+ fromfp16(*(const uint16_t *)b));
+}
+
static int js_TA_cmp_float32(const void *a, const void *b, void *opaque) {
return js_cmp_doubles(*(const float *)a, *(const float *)b);
}
return JS_NewBigUint64(ctx, *(uint64_t *)a);
}
+static JSValue js_TA_get_float16(JSContext *ctx, const void *a) {
+ return __JS_NewFloat64(ctx, fromfp16(*(const uint16_t *)a));
+}
+
static JSValue js_TA_get_float32(JSContext *ctx, const void *a) {
return __JS_NewFloat64(ctx, *(const float *)a);
}
tsc.getfun = js_TA_get_uint64;
cmpfun = js_TA_cmp_uint64;
break;
+ case JS_CLASS_FLOAT16_ARRAY:
+ tsc.getfun = js_TA_get_float16;
+ cmpfun = js_TA_cmp_float16;
+ break;
case JS_CLASS_FLOAT32_ARRAY:
tsc.getfun = js_TA_get_float32;
cmpfun = js_TA_cmp_float32;
return JS_NewBigUint64(ctx, v);
}
break;
+ case JS_CLASS_FLOAT16_ARRAY:
+ {
+ uint16_t v;
+ v = get_u16(ptr);
+ if (is_swap)
+ v = bswap16(v);
+ return __JS_NewFloat64(ctx, fromfp16(v));
+ }
case JS_CLASS_FLOAT32_ARRAY:
{
union {
double d;
if (JS_ToFloat64(ctx, &d, val))
return JS_EXCEPTION;
- if (class_id == JS_CLASS_FLOAT32_ARRAY) {
+ if (class_id == JS_CLASS_FLOAT16_ARRAY) {
+ v = tofp16(d);
+ } else if (class_id == JS_CLASS_FLOAT32_ARRAY) {
union {
float f;
uint32_t i;
break;
case JS_CLASS_INT16_ARRAY:
case JS_CLASS_UINT16_ARRAY:
+ case JS_CLASS_FLOAT16_ARRAY:
if (is_swap)
v = bswap16(v);
put_u16(ptr, v);
JS_CFUNC_MAGIC_DEF("getUint32", 1, js_dataview_getValue, JS_CLASS_UINT32_ARRAY ),
JS_CFUNC_MAGIC_DEF("getBigInt64", 1, js_dataview_getValue, JS_CLASS_BIG_INT64_ARRAY ),
JS_CFUNC_MAGIC_DEF("getBigUint64", 1, js_dataview_getValue, JS_CLASS_BIG_UINT64_ARRAY ),
+ JS_CFUNC_MAGIC_DEF("getFloat16", 1, js_dataview_getValue, JS_CLASS_FLOAT16_ARRAY ),
JS_CFUNC_MAGIC_DEF("getFloat32", 1, js_dataview_getValue, JS_CLASS_FLOAT32_ARRAY ),
JS_CFUNC_MAGIC_DEF("getFloat64", 1, js_dataview_getValue, JS_CLASS_FLOAT64_ARRAY ),
JS_CFUNC_MAGIC_DEF("setInt8", 2, js_dataview_setValue, JS_CLASS_INT8_ARRAY ),
JS_CFUNC_MAGIC_DEF("setUint32", 2, js_dataview_setValue, JS_CLASS_UINT32_ARRAY ),
JS_CFUNC_MAGIC_DEF("setBigInt64", 2, js_dataview_setValue, JS_CLASS_BIG_INT64_ARRAY ),
JS_CFUNC_MAGIC_DEF("setBigUint64", 2, js_dataview_setValue, JS_CLASS_BIG_UINT64_ARRAY ),
+ JS_CFUNC_MAGIC_DEF("setFloat16", 2, js_dataview_setValue, JS_CLASS_FLOAT16_ARRAY ),
JS_CFUNC_MAGIC_DEF("setFloat32", 2, js_dataview_setValue, JS_CLASS_FLOAT32_ARRAY ),
JS_CFUNC_MAGIC_DEF("setFloat64", 2, js_dataview_setValue, JS_CLASS_FLOAT64_ARRAY ),
JS_PROP_STRING_DEF("[Symbol.toStringTag]", "DataView", JS_PROP_CONFIGURABLE ),