[commit: ghc] master: Implement new `compareByteArrays#` primop (e3ba26f)
git at git.haskell.org
git at git.haskell.org
Mon Oct 16 19:09:34 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/e3ba26f8b49700b41ff4672f3f7f6a4e453acdcc/ghc
>---------------------------------------------------------------
commit e3ba26f8b49700b41ff4672f3f7f6a4e453acdcc
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Mon Oct 16 21:01:57 2017 +0200
Implement new `compareByteArrays#` primop
The new primop
compareByteArrays# :: ByteArray# -> Int# {- offset -}
-> ByteArray# -> Int# {- offset -}
-> Int# {- length -}
-> Int#
allows to compare the subrange of the first `ByteArray#` to
the (same-length) subrange of the second `ByteArray#` and returns a
value less than, equal to, or greater than zero if the range is found,
respectively, to be byte-wise lexicographically less than, to match,
or be greater than the second range.
Under the hood, the new primop is implemented in terms of the standard
ISO C `memcmp(3)` function. It is currently an out-of-line primop but
work is underway to optimise this into an inline primop for a future
follow-up Differential (see D4091).
This primop has applications in packages like `text`, `text-short`,
`bytestring`, `text-containers`, `primitive`, etc. which currently
have to incur the overhead of an ordinary FFI call to directly or
indirectly invoke `memcmp(3)` as well has having to deal with some
`unsafePerformIO`-variant.
While at it, this also improves the documentation for the existing
`copyByteArray#` primitive which has a non-trivial type-signature
that significantly benefits from a more explicit description of its
arguments.
Reviewed By: bgamari
Differential Revision: https://phabricator.haskell.org/D4090
>---------------------------------------------------------------
e3ba26f8b49700b41ff4672f3f7f6a4e453acdcc
compiler/prelude/primops.txt.pp | 25 ++-
includes/stg/MiscClosures.h | 1 +
rts/PrimOps.cmm | 14 ++
rts/RtsSymbols.c | 1 +
testsuite/tests/codeGen/should_run/all.T | 1 +
.../tests/codeGen/should_run/compareByteArrays.hs | 167 +++++++++++++++++++++
.../codeGen/should_run/compareByteArrays.stdout | 12 ++
7 files changed, 218 insertions(+), 3 deletions(-)
Diff suppressed because of size. To see it, use:
git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc e3ba26f8b49700b41ff4672f3f7f6a4e453acdcc
More information about the ghc-commits
mailing list