Skip to content

Commit

Permalink
add flbit-field (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
mflatt authored Oct 30, 2024
1 parent 9165b1f commit 95ee804
Show file tree
Hide file tree
Showing 17 changed files with 282 additions and 27 deletions.
15 changes: 8 additions & 7 deletions boot/pb/equates.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* equates.h for Chez Scheme Version 10.1.0-pre-release.3 */
/* equates.h for Chez Scheme Version 10.1.0-pre-release.4 */

/* Do not edit this file. It is automatically generated and */
/* specifically tailored to the version of Chez Scheme named */
Expand Down Expand Up @@ -293,6 +293,7 @@ typedef uint64_t U64;
#define fld_mutablep_index 0x2
#define fld_name_index 0x1
#define fld_type_index 0x3
#define flonum_bits 0x40
#define flonum_bytes 0x8
#define flonum_data_disp 0x6
#define flvector_data_disp 0x9
Expand Down Expand Up @@ -334,7 +335,7 @@ typedef uint64_t U64;
#define int_bits 0x20
#define integer_divide_instruction 1
#define keyboard_interrupt_index 0x3
#define library_entry_vector_size 0x270
#define library_entry_vector_size 0x272
#define libspec_closure_index 0xD
#define libspec_does_not_expect_headroom_index 0x0
#define libspec_error_index 0xE
Expand Down Expand Up @@ -1014,7 +1015,7 @@ typedef uint64_t U64;
#define rtd_sealed 0x4
#define sbwp (ptr)0x4E
#define scaled_shot_1_shot_flag -0x8
#define scheme_version 0xA010003
#define scheme_version 0xA010004
#define seginfo_generation_disp 0x1
#define seginfo_list_bits_disp 0x8
#define seginfo_space_disp 0x0
Expand Down Expand Up @@ -1646,7 +1647,7 @@ typedef uint64_t U64;
#define VIRTREG(x,i) (((ptr *)TO_VOIDP((uptr)(x)+176))[i])

/* library entries we access from C code */
#define library_nonprocedure_code 160
#define library_dounderflow 162
#define library_popcount_slow 620
#define library_cpu_features 622
#define library_nonprocedure_code 162
#define library_dounderflow 164
#define library_popcount_slow 622
#define library_cpu_features 624
2 changes: 2 additions & 0 deletions boot/pb/gc-ocd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ static void sweep(thread_gc *tgc, ptr p, IGEN from_g)
}
}
}
PAR_SWEEPERS_WORKAROUND();
U(tc) = 0;
V(tc) = 0;
W(tc) = 0;
Expand Down Expand Up @@ -2373,6 +2374,7 @@ static void sweep_thread(thread_gc *tgc, ptr p)
}
}
}
PAR_SWEEPERS_WORKAROUND();
U(tc) = 0;
V(tc) = 0;
W(tc) = 0;
Expand Down
2 changes: 2 additions & 0 deletions boot/pb/gc-oce.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ static void sweep(thread_gc *tgc, ptr p, IGEN from_g)
}
}
}
PAR_SWEEPERS_WORKAROUND();
U(tc) = 0;
V(tc) = 0;
W(tc) = 0;
Expand Down Expand Up @@ -2507,6 +2508,7 @@ static void sweep_thread(thread_gc *tgc, ptr p)
}
}
}
PAR_SWEEPERS_WORKAROUND();
U(tc) = 0;
V(tc) = 0;
W(tc) = 0;
Expand Down
2 changes: 2 additions & 0 deletions boot/pb/gc-par.inc
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ static void sweep(thread_gc *tgc, ptr p, IGEN from_g)
}
}
}
PAR_SWEEPERS_WORKAROUND();
U(tc) = 0;
V(tc) = 0;
W(tc) = 0;
Expand Down Expand Up @@ -2416,6 +2417,7 @@ static void sweep_thread(thread_gc *tgc, ptr p)
}
}
}
PAR_SWEEPERS_WORKAROUND();
U(tc) = 0;
V(tc) = 0;
W(tc) = 0;
Expand Down
Binary file modified boot/pb/petite.boot
Binary file not shown.
Binary file modified boot/pb/scheme.boot
Binary file not shown.
4 changes: 2 additions & 2 deletions boot/pb/scheme.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* scheme.h for Chez Scheme Version 10.1.0-pre-release.3 (pb) */
/* scheme.h for Chez Scheme Version 10.1.0-pre-release.4 (pb) */

/* Do not edit this file. It is automatically generated and */
/* specifically tailored to the version of Chez Scheme named */
Expand Down Expand Up @@ -40,7 +40,7 @@
#endif

/* Chez Scheme Version and machine type */
#define VERSION "10.1.0-pre-release.3"
#define VERSION "10.1.0-pre-release.4"
#define MACHINE_TYPE "pb"

/* Integer typedefs */
Expand Down
27 changes: 26 additions & 1 deletion csug/numeric.stex
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ It is useful primarily in the printing of floating-point numbers.

\noindent
\scheme{fllp} returns the 12-bit integer consisting of the exponent
plus highest order represented bit of a flonum (ieee 64-bit
plus highest order represented bit of a flonum (IEEE 64-bit
floating-point number).
It can be used to compute a fast approximation of the logarithm of
the number.
Expand All @@ -636,6 +636,31 @@ the number.
(fllp #b1.0e-10000000000) ;=> 0
\endschemedisplay

%----------------------------------------------------------------------------
\entryheader
\formdef{flbit-field}{\categoryprocedure}{(flbit-field \var{flonum} \var{exint_1} \var{exint_2})}
\returns a nonnegative exact integer
\listlibraries
\endentryheader

\var{flonum} must be a flonum, \var{exint_1} and \var{exint_2} must be
exact integers in the range \scheme{0} to \scheme{64} (inclusive), and
\var{exint_2} must be no less than \var{exint_1}.

\noindent
Analogous to \scheme{bitwise-bit-field} on exact integers,
\scheme{flbit-field} extracts bits within an IEEE 64-bit
floating-point representation from \var{exint_1} (inclusive) to
\var{exint_2} (exclusive). Bit \scheme{0} is the low bit and bit
\scheme{63} is the high (sign) bit. The extracted bit field is
reported as a nonnegative exact integer.

\schemedisplay
(flbit-field 0.0 0 64) ; => 0
(flbit-field -0.0 63 64) ; => 1
(flbit-field +inf.0 48 64) ; => #x7FF0
(flbit-field 3.14e132 52 63) ; => 1463
\endschemedisplay

\section{Inexact Complex Operations\label{SECTNUMERICCOMPLEXNUM}}

Expand Down
80 changes: 80 additions & 0 deletions mats/fl.ms
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,81 @@
(0.0 . 4.0) (0.0 . -4.0) (-0.0 . 4.0) (0.0 . -4.0)))
)

(mat flbit-field
(error? (flbit-field))
(error? (flbit-field 0.0))
(error? (flbit-field 0.0 1))
(error? (flbit-field 0 1 2))
(error? (flbit-field 0.0 -1 2))
(error? (flbit-field 0.0 2 1))
(error? (flbit-field 0.0 2 -1))
(error? (flbit-field 0.0 65 65))
(error? (flbit-field 0.0 32 65))
(error? (flbit-field 0.0 (expt 2 100) (add1 (expt 2 100))))
(error? (flbit-field 0.0 0 (expt 2 100)))

(let loop ([i 0])
(or (= i 65)
(and (eqv? 0 (flbit-field 3.14 i i))
(loop (add1 i)))))

;; all 0 bits
(let loop ([i 0])
(or (= i 64)
(and (eqv? 0 (flbit-field 0.0 i (add1 i)))
(loop (add1 i)))))

;; all 0 bits except high bit for sign
(let loop ([i 0])
(if (= i 63)
(eqv? 1 (flbit-field -0.0 i (add1 i)))
(and (eqv? 0 (flbit-field -0.0 i (add1 i)))
(loop (add1 i)))))

;; all 0-bit ranges
(let loop ([i 0])
(or (= i 64)
(and (eqv? 0 (flbit-field 0.0 0 (add1 i)))
(loop (add1 i)))))

(eqv? (flbit-field 3.141579e132 0 64)
#x5B71B43544F260A6)
(eqv? (flbit-field 3.141579e132 0 63)
#x5B71B43544F260A6)
(eqv? (flbit-field 3.141579e132 1 64)
#x2db8da1aa2793053)
(eqv? (flbit-field 3.141579e132 4 60)
#xB71B43544F260A)
(eqv? (flbit-field 3.141579e132 8 56)
#x71B43544F260)
(eqv? (flbit-field 3.141579e132 32 64)
#x5B71B435)
(eqv? (flbit-field 3.141579e132 0 32)
#x44F260A6)
(eqv? (flbit-field 3.141579e132 16 48)
#xB43544F2)
(let iloop ([i 0])
(or (= i 64)
(let jloop ([j i])
(if (= j 64)
(iloop (add1 i))
(and
(eqv? (flbit-field 3.141579e132 i j)
(bitwise-bit-field #x5B71B43544F260A6 i j))
(jloop (add1 j)))))))

(let iloop ([i 0])
(or (= i 64)
(let jloop ([j i])
(if (= j 64)
(iloop (add1 i))
(and
(eqv? ((eval `(lambda (x) (flbit-field x ,i ,j))) 3.141579e132)
(bitwise-bit-field #x5B71B43544F260A6 i j))
(jloop (add1 j)))))))

)

(mat fp-unboxing
(begin
(define-syntax check-loop-allocation
Expand Down Expand Up @@ -1131,6 +1206,11 @@
(check-loop-allocation (lambda (v) (fllog v v)))
(check-loop-allocation (lambda (v) (flexpt v v)))

(check-loop-allocation (lambda (v) (exact->inexact (flbit-field v 1 23))))
(check-loop-allocation (lambda (v) (exact->inexact (flbit-field (fl+ v 2.0) 1 23))))
(check-loop-allocation (lambda (v) (exact->inexact (flbit-field v 40 63))))
(check-loop-allocation (lambda (v) (exact->inexact (flbit-field (fl+ v 2.0) 40 63))))

(let ([i 0])
(check-loop-allocation (lambda (v) (begin
(set! i (add1 i))
Expand Down
53 changes: 37 additions & 16 deletions mats/patch-compile-0-t-f-f
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*** output-compile-0-f-f-f-experr/errors-compile-0-f-f-f Fri Sep 20 10:53:07 2024
--- output-compile-0-t-f-f-experr/errors-compile-0-t-f-f Fri Sep 20 10:58:11 2024
*** output-compile-0-f-f-f-experr/errors-compile-0-f-f-f Sat Oct 26 11:30:13 2024
--- output-compile-0-t-f-f-experr/errors-compile-0-t-f-f Sat Oct 26 11:34:11 2024
***************
*** 180,186 ****
3.mo:Expected error in mat case-lambda: "incorrect number of arguments 2 to #<procedure foo>".
Expand Down Expand Up @@ -6261,15 +6261,36 @@
fl.mo:Expected error in mat fldenominator: "fldenominator: 3 is not a flonum".
fl.mo:Expected error in mat fldenominator: "fldenominator: 0+1i is not a flonum".
***************
*** 10247,10253 ****
*** 10230,10238 ****
fl.mo:Expected error in mat fldiv0-and-mod0: "flmod0: 17 is not a flonum".
fl.mo:Expected error in mat fldiv0-and-mod0: "flmod0: a is not a flonum".
fl.mo:Expected error in mat fldiv0-and-mod0: "flmod0: (a) is not a flonum".
! fl.mo:Expected error in mat flbit-field: "incorrect argument count in call (flbit-field)".
! fl.mo:Expected error in mat flbit-field: "incorrect argument count in call (flbit-field 0.0)".
! fl.mo:Expected error in mat flbit-field: "incorrect argument count in call (flbit-field 0.0 1)".
fl.mo:Expected error in mat flbit-field: "flbit-field: 0 is not a flonum".
fl.mo:Expected error in mat flbit-field: "flbit-field: invalid start index -1".
fl.mo:Expected error in mat flbit-field: "flbit-field: invalid end index 1".
--- 10230,10238 ----
fl.mo:Expected error in mat fldiv0-and-mod0: "flmod0: 17 is not a flonum".
fl.mo:Expected error in mat fldiv0-and-mod0: "flmod0: a is not a flonum".
fl.mo:Expected error in mat fldiv0-and-mod0: "flmod0: (a) is not a flonum".
! fl.mo:Expected error in mat flbit-field: "incorrect number of arguments 0 to #<procedure flbit-field>".
! fl.mo:Expected error in mat flbit-field: "incorrect number of arguments 1 to #<procedure flbit-field>".
! fl.mo:Expected error in mat flbit-field: "incorrect number of arguments 2 to #<procedure flbit-field>".
fl.mo:Expected error in mat flbit-field: "flbit-field: 0 is not a flonum".
fl.mo:Expected error in mat flbit-field: "flbit-field: invalid start index -1".
fl.mo:Expected error in mat flbit-field: "flbit-field: invalid end index 1".
***************
*** 10258,10264 ****
cfl.mo:Expected error in mat cfl-: "cfl-: a is not a cflonum".
cfl.mo:Expected error in mat cfl-: "cfl-: a is not a cflonum".
cfl.mo:Expected error in mat cfl-: "cfl-: a is not a cflonum".
! cfl.mo:Expected error in mat cfl-: "incorrect argument count in call (cfl-)".
cfl.mo:Expected error in mat cfl-: "cfl-: a is not a cflonum".
cfl.mo:Expected error in mat cfl-: "cfl-: a is not a cflonum".
cfl.mo:Expected error in mat cfl-: "cfl-: a is not a cflonum".
--- 10247,10253 ----
--- 10258,10264 ----
cfl.mo:Expected error in mat cfl-: "cfl-: a is not a cflonum".
cfl.mo:Expected error in mat cfl-: "cfl-: a is not a cflonum".
cfl.mo:Expected error in mat cfl-: "cfl-: a is not a cflonum".
Expand All @@ -6278,7 +6299,7 @@
cfl.mo:Expected error in mat cfl-: "cfl-: a is not a cflonum".
cfl.mo:Expected error in mat cfl-: "cfl-: a is not a cflonum".
***************
*** 10257,10270 ****
*** 10268,10281 ****
cfl.mo:Expected error in mat cfl/: "cfl/: a is not a cflonum".
cfl.mo:Expected error in mat cfl/: "cfl/: a is not a cflonum".
cfl.mo:Expected error in mat cfl/: "cfl/: a is not a cflonum".
Expand All @@ -6293,7 +6314,7 @@
foreign.mo:Expected error in mat load-shared-object: "load-shared-object: invalid path 3".
foreign.mo:Expected error in mat foreign-procedure: "foreign-procedure: no entry for "i do not exist"".
foreign.mo:Expected error in mat foreign-procedure: "foreign-procedure: no entry for "i do not exist"".
--- 10257,10270 ----
--- 10268,10281 ----
cfl.mo:Expected error in mat cfl/: "cfl/: a is not a cflonum".
cfl.mo:Expected error in mat cfl/: "cfl/: a is not a cflonum".
cfl.mo:Expected error in mat cfl/: "cfl/: a is not a cflonum".
Expand All @@ -6309,7 +6330,7 @@
foreign.mo:Expected error in mat foreign-procedure: "foreign-procedure: no entry for "i do not exist"".
foreign.mo:Expected error in mat foreign-procedure: "foreign-procedure: no entry for "i do not exist"".
***************
*** 10299,10306 ****
*** 10310,10317 ****
foreign.mo:Expected error in mat foreign-procedure: "id: invalid foreign-procedure argument foo".
foreign.mo:Expected error in mat foreign-procedure: "foreign-procedure: invalid foreign procedure handle abcde".
foreign.mo:Expected error in mat foreign-procedure: "float_id: invalid foreign-procedure argument 0".
Expand All @@ -6318,7 +6339,7 @@
foreign.mo:Expected error in mat foreign-sizeof: "foreign-sizeof: invalid foreign type specifier i-am-not-a-type".
foreign.mo:Expected error in mat foreign-sizeof: "foreign-sizeof: invalid foreign type specifier 1".
foreign.mo:Expected error in mat foreign-bytevectors: "u8*->u8*: invalid foreign-procedure argument "hello"".
--- 10299,10306 ----
--- 10310,10317 ----
foreign.mo:Expected error in mat foreign-procedure: "id: invalid foreign-procedure argument foo".
foreign.mo:Expected error in mat foreign-procedure: "foreign-procedure: invalid foreign procedure handle abcde".
foreign.mo:Expected error in mat foreign-procedure: "float_id: invalid foreign-procedure argument 0".
Expand All @@ -6328,7 +6349,7 @@
foreign.mo:Expected error in mat foreign-sizeof: "foreign-sizeof: invalid foreign type specifier 1".
foreign.mo:Expected error in mat foreign-bytevectors: "u8*->u8*: invalid foreign-procedure argument "hello"".
***************
*** 10820,10832 ****
*** 10831,10843 ****
unix.mo:Expected error in mat file-operations: "file-access-time: failed for "testlink": no such file or directory".
unix.mo:Expected error in mat file-operations: "file-change-time: failed for "testlink": no such file or directory".
unix.mo:Expected error in mat file-operations: "file-modification-time: failed for "testlink": no such file or directory".
Expand All @@ -6342,7 +6363,7 @@
windows.mo:Expected error in mat registry: "get-registry: pooh is not a string".
windows.mo:Expected error in mat registry: "put-registry!: 3 is not a string".
windows.mo:Expected error in mat registry: "put-registry!: 3 is not a string".
--- 10820,10832 ----
--- 10831,10843 ----
unix.mo:Expected error in mat file-operations: "file-access-time: failed for "testlink": no such file or directory".
unix.mo:Expected error in mat file-operations: "file-change-time: failed for "testlink": no such file or directory".
unix.mo:Expected error in mat file-operations: "file-modification-time: failed for "testlink": no such file or directory".
Expand All @@ -6357,7 +6378,7 @@
windows.mo:Expected error in mat registry: "put-registry!: 3 is not a string".
windows.mo:Expected error in mat registry: "put-registry!: 3 is not a string".
***************
*** 10854,10925 ****
*** 10865,10936 ****
ieee.mo:Expected error in mat flonum->fixnum: "flonum->fixnum: result for -inf.0 would be outside of fixnum range".
ieee.mo:Expected error in mat flonum->fixnum: "flonum->fixnum: result for +nan.0 would be outside of fixnum range".
ieee.mo:Expected error in mat fllp: "fllp: 3 is not a flonum".
Expand Down Expand Up @@ -6430,7 +6451,7 @@
date.mo:Expected error in mat time: "time>=?: 3 is not a time record".
date.mo:Expected error in mat time: "time>=?: #<procedure car> is not a time record".
date.mo:Expected error in mat time: "time>=?: types of <time> and <time> differ".
--- 10854,10925 ----
--- 10865,10936 ----
ieee.mo:Expected error in mat flonum->fixnum: "flonum->fixnum: result for -inf.0 would be outside of fixnum range".
ieee.mo:Expected error in mat flonum->fixnum: "flonum->fixnum: result for +nan.0 would be outside of fixnum range".
ieee.mo:Expected error in mat fllp: "fllp: 3 is not a flonum".
Expand Down Expand Up @@ -6504,7 +6525,7 @@
date.mo:Expected error in mat time: "time>=?: #<procedure car> is not a time record".
date.mo:Expected error in mat time: "time>=?: types of <time> and <time> differ".
***************
*** 10927,10940 ****
*** 10938,10951 ****
date.mo:Expected error in mat time: "add-duration: <time> does not have type time-duration".
date.mo:Expected error in mat time: "subtract-duration: <time> does not have type time-duration".
date.mo:Expected error in mat time: "copy-time: <date> is not a time record".
Expand All @@ -6519,7 +6540,7 @@
date.mo:Expected error in mat date: "make-date: invalid nanosecond -1".
date.mo:Expected error in mat date: "make-date: invalid nanosecond <int>".
date.mo:Expected error in mat date: "make-date: invalid nanosecond zero".
--- 10927,10940 ----
--- 10938,10951 ----
date.mo:Expected error in mat time: "add-duration: <time> does not have type time-duration".
date.mo:Expected error in mat time: "subtract-duration: <time> does not have type time-duration".
date.mo:Expected error in mat time: "copy-time: <date> is not a time record".
Expand All @@ -6535,7 +6556,7 @@
date.mo:Expected error in mat date: "make-date: invalid nanosecond <int>".
date.mo:Expected error in mat date: "make-date: invalid nanosecond zero".
***************
*** 10960,11020 ****
*** 10971,11031 ****
date.mo:Expected error in mat date: "make-date: invalid time-zone offset 90000".
date.mo:Expected error in mat date: "make-date: invalid time-zone offset est".
date.mo:Expected error in mat date: "make-date: invalid time-zone offset "est"".
Expand Down Expand Up @@ -6597,7 +6618,7 @@
date.mo:Expected error in mat date: "current-date: invalid time-zone offset -90000".
date.mo:Expected error in mat date: "current-date: invalid time-zone offset 90000".
date.mo:Expected error in mat conversions/sleep: "date->time-utc: <time> is not a date record".
--- 10960,11020 ----
--- 10971,11031 ----
date.mo:Expected error in mat date: "make-date: invalid time-zone offset 90000".
date.mo:Expected error in mat date: "make-date: invalid time-zone offset est".
date.mo:Expected error in mat date: "make-date: invalid time-zone offset "est"".
Expand Down
Loading

0 comments on commit 95ee804

Please sign in to comment.