<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>209289</bug_id>
          
          <creation_ts>2020-03-19 09:59:40 -0700</creation_ts>
          <short_desc>[JSC][BigEndians] JSTests/stress/dataview-jit-set-nan.js subtest misbehaves</short_desc>
          <delta_ts>2020-03-19 12:02:40 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tomas Popela">tpopela</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>mcatanzaro</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1631699</commentid>
    <comment_count>0</comment_count>
    <who name="Tomas Popela">tpopela</who>
    <bug_when>2020-03-19 09:59:40 -0700</bug_when>
    <thetext>The whole background story could be found in bug 194007.

While working on patch I found one case where the suggested solution doesn&apos;t work:

&quot;use strict&quot;;

function assert(b) {
    if (!b)
        throw new Error;
}

function getIsLittleEndian() {
    let ab = new ArrayBuffer(2);
    let ta = new Int16Array(ab);
    ta[0] = 0x0102;
    let dv = new DataView(ab);
    return dv.getInt16(0, true) === 0x0102;
}

let isLittleEndian = getIsLittleEndian();

function adjustForEndianessFloat32(value) {
    if (isLittleEndian)
        return value;

    let ab = new ArrayBuffer(4);
    let ta = new Float32Array(ab);
    ta[0] = value;
    let dv = new DataView(ab);
    return dv.getFloat32(0, true);
}

function test() {
    function storeLittleEndian(dv, index, value) {
        dv.setFloat32(index, value, true);
    }
    noInline(storeLittleEndian);

    function store(dv, index, value, littleEndian) {
        dv.setFloat32(index, value, littleEndian);
    }
    noInline(store);

    let buffer = new ArrayBuffer(4);
    let arr = new Float32Array(buffer);
    let bits = new Uint32Array(buffer);
    let dv = new DataView(buffer);

    for (let i = 0; i &lt; 10000; ++i) {
        storeLittleEndian(dv, 0, adjustForEndianessFloat32(12912.124123215122));
        assert(arr[0] === 12912.1240234375);
        assert(bits[0] === 0x4649c07f);
    }
}
test();


On big endian machine the arr[0] contains 6.905458702346266e-41 and bits[0] 0xc07f.

If I replace the storeLittleEndian() call with:

store(dv, 0, 12912.124123215122, isLittleEndian);

then it does work, but it&apos;s strange that the storeLittleEndian() doesn&apos;t.

Is the 12912.124123215122 number somehow special? If I observe what&apos;s in arr[0], when I change that number then it&apos;s:

input to adjustForEndianessFloat32() : arr[0] value
12912 : 12912
12912.1 : 12912.099609375
12912.12 : 12912.1201171875
12912.124 : 6.905458702346266e-41

Does anyone have an idea?</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>