chibi-scheme/lib/srfi
Alexei Lozovsky 6f35aa75f4
Fix usage of signbit() in SRFI 144
C standard defines signbit() as a macro returning "non-zero value" for
negative arguments (see 7.12.3.6 of C11 standard). SRFI 144's flsign-bit
is defined to return exactly 1.

Make sure to convert the result of signbit() call into "boolean int"
which is either 0 or 1.

This is not a theoretical issue. This causes SRFI 144 test suite to fail
on many architectures that are not x86_64.

GCC on x86_64 compiles signbit() as

        movmskpd %xmm0, %eax
        andl     $1, %eax

which indeed returns either 0 or 1. movmskpd extracts 2-bit sign mask
from the FP value in src register and stores that in low-order bits of
the dst register. Then the unneded extra bit is masked out, leaving only
the lowest bit set or unset.

However, other architectures don't have such conveniences and go with
more direct approach. For example, GCC on ARMv7 produces this:

        sub     sp, sp, #8
        vstr.64 d0, [sp]
        ldr     r0, [sp, #4]
        and     r0, r0, #0x80000000
        add     sp, sp, #8
        bx      lr

which effectively returns either 0 or -1. Generated code masks out
everything but the sign bit and returns the result as is. The value
0x80000000 is the representation of -1.

Even on i386 signbit() is compiled as

        fldl    4(%esp)
        fxam
        fnstsw  %ax
        fstp    %st(0)
        andl    $512, %eax
        ret

which effectively returns either 0 or 512: fxam sets C1 bit FPU status
word to the sign of FP value, then the status word is extracted, the
"sign bit" is masked out, and left as is.
2021-06-06 13:49:44 +09:00
..
1 fix order of arguments in lset= 2020-05-27 14:27:31 +09:00
2 Fix and-let* so that it allows bodies according to SRFI 2. 2020-10-22 15:13:04 +02:00
14 fix iset-intersection on large trees in the first argument (issue #606) 2020-01-27 21:52:17 +08:00
16 move definitions to start of body 2016-02-28 18:05:02 +09:00
18 better inexact computation for ratios which overflow double (issue #671) 2020-07-15 16:38:56 +09:00
26 Converting tests to modules instead of separate programs. 2015-04-05 23:38:51 +09:00
27 fixing distribution of random bignums, adding uniformity tests on the results (issue #675) 2020-08-07 12:40:07 +09:00
33 adding (srfi 142), using that in place of (srfi 33) 2017-04-16 22:06:56 +09:00
38 better fix for #618 2020-06-16 10:05:26 +09:00
39 Added full support for packed images, both for static and dynamic libraries. 2016-02-15 21:12:58 -05:00
41 adding (srfi 41) 2018-01-14 00:22:14 +09:00
69 hash raw bytes of bignums 2020-08-11 11:12:04 +09:00
95 remove more tabs 2020-07-28 20:10:31 +09:00
98 SRFI-98: Do not decl. environ as extern on Win32 2017-12-13 17:30:36 +09:00
99 death to tabs 2020-07-28 15:26:42 +09:00
101 adding (srfi 101) 2018-01-15 23:51:16 +09:00
113 don't include-shared hash multiple times 2018-01-24 23:58:30 +09:00
116 cleaning up test names 2020-06-19 17:37:55 +09:00
117 adding new srfi tests to lib-tests 2017-04-16 22:15:58 +09:00
121 adding (srfi 121) 2017-04-16 22:07:51 +09:00
125 Implement SRFI 162. 2020-05-02 21:05:19 +02:00
127 adding (srfi 127) 2018-01-15 23:15:14 +09:00
128 death to tabs 2020-07-28 15:26:42 +09:00
129 distinguishing lowercase and foldcase (fixes issue #420) 2017-08-27 14:10:05 +09:00
130 add proper grammar support to srfi 130 string-split 2021-04-02 13:51:02 +09:00
132 typo in vector-select! 2018-02-01 15:43:46 +09:00
133 Fix SRFI 133 vector-every crash on empty vector 2020-05-09 11:46:10 -04:00
134 cleaning up test names 2020-06-19 17:37:55 +09:00
135 adding (srfi 135) 2018-01-16 01:14:40 +09:00
139 removing tabs 2017-08-26 23:29:02 +09:00
143 adding (srfi 143) 2017-05-27 22:50:35 +09:00
144 Fix usage of signbit() in SRFI 144 2021-06-06 13:49:44 +09:00
146 tabs in srfi 146 2020-07-28 15:29:49 +09:00
151 death to tabs 2020-07-28 15:26:42 +09:00
158 cleaning up test names 2020-06-19 17:37:55 +09:00
159 fixing (srfi 159) after refactoring 2020-07-06 15:09:49 +09:00
160 Fix upper bounds checks in u64vectors. 2021-04-30 14:02:29 +09:00
166 text attribute resetting fix 2020-08-24 13:52:29 +02:00
179 exporting array-coeffs 2021-05-10 22:56:36 +09:00
219 Add SRFI 219: Define higher-order lambda 2021-04-18 12:21:32 +03:00
1.sld Making libraries portable where possible. 2015-04-26 16:17:38 +09:00
2.sld save a char and a beta reduction 2020-11-25 14:39:49 +09:00
6.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
8.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
9.scm compare record field names with eq? 2016-06-25 22:53:37 +09:00
9.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
11.sld death to tabs 2020-07-28 15:26:42 +09:00
14.sld adding (srfi 14) 2017-08-26 20:34:56 +09:00
16.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
18.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
23.sld adding explicit (srfi 23) 2017-04-01 21:47:34 +09:00
26.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
27.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
33.sld adding (srfi 142), using that in place of (srfi 33) 2017-04-16 22:06:56 +09:00
38.scm better fix for #618 2020-06-16 10:05:26 +09:00
38.sld adding initial support for SRFI 160 uniform vectors 2019-01-15 23:43:50 +08:00
39.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
41.scm Correct record-type names in srfi 41 2020-06-09 19:50:13 +02:00
41.sld Add (scheme lazy) to imports for srfi 41 2020-06-09 15:05:41 +02:00
46.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
55.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
69.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
95.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
98.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
99.sld Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00
101.scm adding (srfi 101) 2018-01-15 23:51:16 +09:00
101.sld adding (srfi 101) 2018-01-15 23:51:16 +09:00
111.sld adding (srfi 111) 2017-03-26 22:02:43 +09:00
113.sld don't include-shared hash multiple times 2018-01-24 23:58:30 +09:00
115.sld adding missing export regexp-match->list (issue #419) 2017-06-26 10:36:38 +09:00
116.sld adding (srfi 116) 2017-08-24 21:29:33 +09:00
117.sld adding (srfi 117) 2017-04-01 22:15:08 +09:00
121.sld adding (srfi 121) 2017-04-16 22:07:51 +09:00
124.sld remove tab 2017-04-01 20:43:43 +09:00
125.sld adding (srfi 125) 2017-04-18 23:24:56 +09:00
127.scm adding (srfi 127) 2018-01-15 23:15:14 +09:00
127.sld adding (srfi 127) 2018-01-15 23:15:14 +09:00
128.sld Implement SRFI 162. 2020-05-02 21:05:19 +02:00
129.sld updating to Unicode 9 and adding SRFI 129 2017-03-28 23:42:47 +09:00
130.scm add proper grammar support to srfi 130 string-split 2021-04-02 13:51:02 +09:00
130.sld even string-cursor->index/index->cursor are polymorphic 2020-07-03 09:43:26 +09:00
132.sld adding (srfi 132) 2017-03-30 01:17:30 +09:00
133.sld adding (srfi 133) 2017-03-31 00:48:35 +09:00
134.scm adding (srfi 134) 2018-01-16 00:00:48 +09:00
134.sld adding (srfi 134) 2018-01-16 00:00:48 +09:00
135.scm adding (srfi 135) 2018-01-16 01:14:40 +09:00
135.sld adding (srfi 135) 2018-01-16 01:14:40 +09:00
139.scm fixing whitespace 2020-06-16 11:43:47 +09:00
139.sld removing tabs 2017-08-26 23:29:02 +09:00
141.sld adding (srfi 141) 2017-04-01 20:42:32 +09:00
142.sld replacing (srfi 142) with (srfi 151) 2017-08-21 22:32:57 +09:00
143.sld replacing (srfi 142) with (srfi 151) 2017-08-21 22:32:57 +09:00
144.sld add fl-epsilon to srfi 144 2020-08-11 21:26:42 +03:00
145.sld add docs and tests for assert, unify with SRFI 145 2021-05-06 20:34:03 +09:00
146.sld adding srfi 146 2020-05-26 13:57:06 +09:00
147.sld adding (srfi 147) 2017-04-01 20:33:13 +09:00
151.sld replacing (srfi 142) with (srfi 151) 2017-08-21 22:32:57 +09:00
154.scm adding (srfi 154) 2017-10-06 22:54:32 +09:00
154.sld adding (srfi 154) 2017-10-06 22:54:32 +09:00
158.scm Fix generator-find 2020-08-29 10:25:23 +02:00
158.sld Implement SRFI 158. 2020-05-05 22:28:10 +02:00
159.sld fixing (srfi 159) after refactoring 2020-07-06 15:09:49 +09:00
165.scm cleanup whitespace 2020-05-25 18:52:33 +09:00
165.sld cleanup whitespace 2020-05-25 18:52:33 +09:00
166.sld forgot to export make-state-variable from composite library 2020-08-17 22:02:15 +09:00
179.sld package SRFI 179 2021-05-10 17:49:02 +09:00
188.sld adding srfi 188 2020-05-26 10:12:27 +09:00
193.sld Add SRFI 193 Scheme library 2021-02-05 14:08:31 +02:00
219.sld Add SRFI 219: Define higher-order lambda 2021-04-18 12:21:32 +03:00