Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions boot/pb/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ typedef unsigned char octet;
#define Sstring_length(x) ((iptr)((uptr)(*((iptr *)TO_VOIDP((uptr)(x)+1)))>>4))
#define Sstring_ref(x,i) Schar_value(((string_char *)TO_VOIDP((uptr)(x)+9))[i])
#define Sunbox(x) (*((ptr *)TO_VOIDP((uptr)(x)+9)))
static inline int Spopcount(uptr x) {
#if defined(__clang__) || defined(__GNUC__)
return __builtin_popcountll((unsigned long)x);
#else
/* count bits of each 2-bit chunk */
x = x - ((x >> 1) & 0x5555555555555555ULL);
/* count bits of each 4-bit chunk */
x = (x & 0x3333333333333333ULL) + ((x >> 2) & 0x3333333333333333ULL);
/* count bits of each 8-bit chunk */
x = x + (x >> 4);
/* mask out junk */
x &= 0x0F0F0F0F0F0F0F0FULL;
/* add all 8-bit chunks */
return (x * 0x0101010101010101ULL) >> 56;
#endif
}
#define Sstencil_vector_length(x) Spopcount(((uptr)(*((iptr *)TO_VOIDP((uptr)(x)+1))))>>6)
#define Sstencil_vector_ref(x,i) (((ptr *)TO_VOIDP((uptr)(x)+9))[i])
EXPORT iptr Sinteger_value(ptr);
Expand Down
1 change: 0 additions & 1 deletion c/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#include "system.h"
#include "popcount.h"

/* locally defined functions */
static void maybe_queue_fire_collector(thread_gc *tgc);
Expand Down
2 changes: 1 addition & 1 deletion c/build.zuo
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
(map at-source
(list "system.h" "types.h" "version.h" "globals.h" "externs.h" "segment.h"
"atomic.h" "thread.h" "sort.h" "compress-io.h"
"nocurses.h" "popcount.h"))
"nocurses.h"))
(list c-config-file)
(map at-mach
(list "equates.h"
Expand Down
1 change: 0 additions & 1 deletion c/fasl.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@

#include "system.h"
#include "zlib.h"
#include "popcount.h"

#ifdef WIN32
#include <io.h>
Expand Down
1 change: 0 additions & 1 deletion c/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#ifndef WIN32
#include <sys/wait.h>
#endif /* WIN32 */
#include "popcount.h"
#include <assert.h>

/*
Expand Down
1 change: 0 additions & 1 deletion c/gcwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#include "system.h"
#include "popcount.h"

/* locally defined functions */
static void segment_tell(uptr seg);
Expand Down
35 changes: 0 additions & 35 deletions c/popcount.h

This file was deleted.

6 changes: 6 additions & 0 deletions release_notes/release_notes.stex
Original file line number Diff line number Diff line change
Expand Up @@ -2987,6 +2987,12 @@ in fasl files does not generally make sense.
%-----------------------------------------------------------------------------
\section{Bug Fixes}\label{section:bugfixes}


\subsection{Declare \scheme{Spopcount} in scheme.h (10.4.0)}

A bug where the header file scheme.h refers to an undeclared \scheme{Spopcount} function
has been fixed.

\subsection{Eager port closing on error in \scheme{open-source-file} (10.4.0)}

When \scheme{open-source-file} fails on a non-seekable device, the file descriptor port
Expand Down
25 changes: 24 additions & 1 deletion s/mkheader.ss
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,30 @@
(format "Schar_value~a" (access "x" "i" string data)))

(defref Sunbox box ref)


(let-values
([(suffix fives threes junk-mask ones shift)
(constant-case ptr-bits
[(32) (values "l" "0x55555555" "0x33333333" "0xF0F0F0F" "0x01010101" 24)]
[(64) (values "ll" "0x5555555555555555ULL" "0x3333333333333333ULL"
"0x0F0F0F0F0F0F0F0FULL" "0x0101010101010101ULL" 56)])])
(pr "static inline int Spopcount(uptr x) {\n")
(pr "#if defined(__clang__) || defined(__GNUC__)\n")
(pr " return __builtin_popcount~a((unsigned long)x);\n" suffix)
(pr "#else\n")
(pr " /* count bits of each 2-bit chunk */\n")
(pr " x = x - ((x >> 1) & ~a);\n" fives)
(pr " /* count bits of each 4-bit chunk */\n")
(pr " x = (x & ~a) + ((x >> 2) & ~a);\n" threes threes)
(pr " /* count bits of each 8-bit chunk */\n")
(pr " x = x + (x >> 4);\n")
(pr " /* mask out junk */\n")
(pr " x &= ~a;\n" junk-mask)
(pr " /* add all 8-bit chunks */\n")
(pr " return (x * ~a) >> ~d;\n" ones shift)
(pr "#endif\n")
(pr "}\n"))

(def "Sstencil_vector_length(x)"
(format "Spopcount(((uptr)~a)>>~d)"
(access "x" stencil-vector type)
Expand Down
Loading