[Git][ghc/ghc][wip/js-staging] 3 commits: Fix isFloatDenormalized function
Sylvain Henry (@hsyl20)
gitlab at gitlab.haskell.org
Mon Sep 26 14:54:16 UTC 2022
Sylvain Henry pushed to branch wip/js-staging at Glasgow Haskell Compiler / GHC
Commits:
651959f8 by Sylvain Henry at 2022-09-26T16:41:37+02:00
Fix isFloatDenormalized function
- - - - -
93f450a7 by Sylvain Henry at 2022-09-26T16:56:39+02:00
Reuse convert buffer
- - - - -
711ddddf by Sylvain Henry at 2022-09-26T16:57:28+02:00
Reuse convert buffer bis
- - - - -
2 changed files:
- libraries/base/jsbits/base.js
- rts/js/arith.js
Changes:
=====================================
libraries/base/jsbits/base.js
=====================================
@@ -781,32 +781,6 @@ function h$stg_sig_install(sigNo, actionCode, sigSet_d, sigSet_o) {
return 0;
}
-const h$word_float_conv_buf = new DataView(new ArrayBuffer(8));
-
-function h$stg_word32ToFloatzh(v) {
- h$word_float_conv_buf.setUint32(0, v);
- return h$word_float_conv_buf.getFloat32(0);
-}
-
-function h$stg_floatToWord32zh(v) {
- h$word_float_conv_buf.setFloat32(0, v);
- return h$word_float_conv_buf.getUint32(0);
-}
-
-function h$stg_word64ToDoublezh(h,l) {
- h$word_float_conv_buf.setUint32(0, h);
- h$word_float_conv_buf.setUint32(4, l);
- return h$word_float_conv_buf.getFloat64(0);
-}
-
-function h$stg_doubleToWord64zh(v) {
- h$word_float_conv_buf.setFloat64(0, v);
- var l = h$word_float_conv_buf.getUint32(4);
- var h = h$word_float_conv_buf.getUint32(0);
- RETURN_UBX_TUP2(h,l);
-}
-
-
const h$putchar_buf = h$newByteArray(1);
function h$putchar(c) {
=====================================
rts/js/arith.js
=====================================
@@ -324,13 +324,18 @@ function h$isDoubleDenormalized(d) {
}
function h$isFloatDenormalized(d) {
- return (d !== 0 && Math.abs(d) < 2.2250738585072014e-308) ? 1 : 0;
+ h$convertFloat[0] = d;
+ var i = h$convertInt[0];
+ var exp = (i >> 23) & 0xff;
+ var s = i&8388607;
+ return ((s !== 0 && exp === 0) ? 1 : 0);
}
var h$convertBuffer = new ArrayBuffer(8);
var h$convertDouble = new Float64Array(h$convertBuffer);
var h$convertFloat = new Float32Array(h$convertBuffer);
var h$convertInt = new Int32Array(h$convertBuffer);
+var h$convertWord = new Uint32Array(h$convertBuffer);
// use direct inspection through typed array for decoding floating point numbers if this test gives
// the expected answer. fixme: does this test catch all non-ieee or weird endianness situations?
@@ -524,7 +529,6 @@ function h$ctz64(x1,x2) {
}
var h$fround = null;
-var h$truncateFloat_buf = null;
if(typeof Math.fround === 'function') {
h$fround = function(f) {
TRACE_ARITH("fround (native): " + f);
@@ -533,9 +537,8 @@ if(typeof Math.fround === 'function') {
} else {
h$fround = function(f) {
TRACE_ARITH("fround (buffer): " + f);
- if(!h$truncateFloat_buf) h$truncateFloat_buf = new Float32Array(1);
- h$truncateFloat_buf[0] = f;
- return h$truncateFloat_buf[0];
+ h$convertFloat[0] = f;
+ return h$convertFloat[0];
}
}
@@ -596,3 +599,26 @@ function h$__word_encodeFloat(j,e) {
if (!j) return 0;
return h$fround((j>>>0) * (2 ** (e|0)));
}
+
+function h$stg_word32ToFloatzh(v) {
+ h$convertWord[0] = v;
+ return h$convertFloat[0];
+}
+
+function h$stg_floatToWord32zh(v) {
+ h$convertFloat[0] = v;
+ return h$convertWord[0];
+}
+
+function h$stg_word64ToDoublezh(h,l) {
+ h$convertWord[0] = l;
+ h$convertWord[1] = h;
+ return h$convertDouble[0];
+}
+
+function h$stg_doubleToWord64zh(v) {
+ h$convertDouble[0] = v;
+ var l = h$convertWord[0];
+ var h = h$convertWord[1];
+ RETURN_UBX_TUP2(h,l);
+}
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/abf77718cf5df1d10062bcc15de0d867175e8515...711ddddfa9ddc88643a73ff91d9151b9920f8077
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/abf77718cf5df1d10062bcc15de0d867175e8515...711ddddfa9ddc88643a73ff91d9151b9920f8077
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20220926/99a27752/attachment-0001.html>
More information about the ghc-commits
mailing list