Showing preview only (296K chars total). Download the full file or copy to clipboard to get everything.
Repository: powturbo/Turbo-Base64
Branch: master
Commit: 83b2a8d1555c
Files: 32
Total size: 284.5 KB
Directory structure:
gitextract_0jc76c4i/
├── .github/
│ └── workflows/
│ └── build.yaml
├── CMakeLists.txt
├── LICENSE
├── README.md
├── cmake/
│ └── turbobase64-config.cmake.in
├── conf.h
├── makefile
├── rust/
│ ├── .gitignore
│ ├── Cargo.toml
│ ├── README.md
│ ├── build.rs
│ ├── src/
│ │ ├── bindings.rs
│ │ ├── lib.rs
│ │ └── tests.rs
│ └── wrapper.h
├── tb64app.c
├── time_.h
├── turbob64.h
├── turbob64_.h
├── turbob64c.c
├── turbob64d.c
├── turbob64v128.c
├── turbob64v256.c
├── turbob64v512.c
└── vs/
├── getopt.c
├── getopt.h
├── inttypes.h
├── stdint.h
├── turbob64avx.c
└── vs2022/
├── TB64App.vcxproj
├── TurboBase64.sln
└── TurboBase64.vcxproj
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/workflows/build.yaml
================================================
name: build
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
linux:
runs-on: '${{ matrix.os }}'
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
compiler: ["gcc", "clang"]
env:
CC: ${{ matrix.compiler }}
steps:
- uses: actions/checkout@v3
- run: make
- run: lscpu
- run: ./tb64app -v1
macos:
runs-on: '${{ matrix.os }}'
strategy:
fail-fast: false
matrix:
os: [macos-latest]
compiler: ["clang"]
env:
CC: ${{ matrix.compiler }}
steps:
- uses: actions/checkout@v3
- run: make
- run: sysctl -n machdep.cpu.brand_string
- run: ./tb64app -v1
# - run: ./tb64app -T -f3
windows:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v3
- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
install: make mingw-w64-x86_64-gcc
update: true
- run: make
- run: ./tb64app -v1
# - run: ./tb64app -T -f3
================================================
FILE: CMakeLists.txt
================================================
cmake_minimum_required(VERSION 3.15)
project(turbobase64 C)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Run cmake -D<OPTION>=ON|OFF to turn on/off options.
# Usage example:
# cmake -B build -S . -DNCHECK=ON
# cmake --build build
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(NCHECK "Dinsable for checking for more fast decoding" OFF)
# default=partial checking, detect allmost all errors
option(FULLCHECK "Enable full base64 checking" OFF)
option(NAVX512 "Disable AVX512" OFF)
option(BUILD_APP "Build executables" OFF)
message(STATUS "Configuring with CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}")
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(ARCH_AMD64 ON)
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
set(ARCH_AARCH64 ON)
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
set(ARCH_PPC64LE ON)
endif()
set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_DEBUG "-O0 -ggdb")
# Set compiler options.
if(NCHECK)
add_compile_definitions(NB64CHECK)
endif()
if(FULLCHECK)
add_compile_definitions(DB64CHECK)
endif()
if(NAVX512)
add_compile_definitions(NAVX512)
endif()
if(ARCH_PPC64LE)
set(MARCH "-march=power9 -mtune=power9")
set(MSSE "-D__SSSE3__")
elseif(ARCH_AARCH64)
set(MARCH "-march=armv8-a")
else()
set(MARCH "-march=native")
set(MSSE "-mssse3")
endif()
# Object library is just a bunch of object files.
add_library(_b64_scalar OBJECT turbob64c.c turbob64d.c)
target_compile_options(_b64_scalar PRIVATE ${MARCH} -falign-loops)
# turbob64v128.c contains code for SSE, AVX, NEON, Power9.
# It's compiled twice with different flags.
add_library(_b64_v128 OBJECT turbob64v128.c)
target_compile_options(_b64_v128 PRIVATE ${MSSE} -falign-loops)
# Use a list to collect all object libraries.
set(_b64_objs _b64_scalar _b64_v128)
if(ARCH_AMD64)
# Compile turbob64v128.c for the second time.
add_library(_b64_avx OBJECT turbob64v128.c)
target_compile_options(_b64_avx PRIVATE -march=corei7-avx -mtune=corei7-avx -mno-aes -fstrict-aliasing)
list(APPEND _b64_objs _b64_avx)
add_library(_b64_v256 OBJECT turbob64v256.c)
target_compile_options(_b64_v256 PRIVATE -march=haswell -fstrict-aliasing -falign-loops)
list(APPEND _b64_objs _b64_v256)
add_library(_b64_v512 OBJECT turbob64v512.c)
target_compile_options(_b64_v512 PRIVATE -march=skylake-avx512 -mavx512vbmi -fstrict-aliasing -falign-loops)
list(APPEND _b64_objs _b64_v512)
endif()
if(BUILD_SHARED_LIBS)
add_library(base64 SHARED)
else()
add_library(base64 STATIC)
endif()
foreach(_obj ${_b64_objs})
set_target_properties(${_obj} PROPERTIES POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS})
target_sources(base64 PRIVATE $<TARGET_OBJECTS:${_obj}>)
endforeach()
# The XCODE fix is from https://github.com/ClickHouse/ClickHouse/blob/cf7d354a693f15fc5941edbf39e295d0bf8de21c/contrib%2Fbase64-cmake%2FCMakeLists.txt#L46-L54
if(XCODE OR XCODE_VERSION)
# https://gitlab.kitware.com/cmake/cmake/issues/17457
# Some native build systems may not like targets that have only object files, so consider adding at least one real source file
# This applies to Xcode.
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/dummy.c")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.c" "")
endif()
target_sources(base64 PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/dummy.c")
endif()
if(BUILD_APP)
add_executable(tb64app tb64app.c)
target_link_libraries(tb64app base64)
endif()
# Set package information.
set(PACKAGE_NAME ${PROJECT_NAME})
set(PACKAGE_NAMESPACE "turbo::")
# For CMAKE_INSTALL_{INCLUDEDIR,LIBDIR} etc.
include(GNUInstallDirs)
set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}")
# Please refer "Modern CMake" on how to install a library.
# https://cliutils.gitlab.io/modern-cmake/chapters/install/installing.html
# Also refer to cmake documentation
# https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html
# Set PUBLIC_HEADER property for install(TARGETS) to install header file.
set_target_properties(base64 PROPERTIES PUBLIC_HEADER "${CMAKE_SOURCE_DIR}/turbob64.h")
# Set includes destination for install(TARGETS), which will be added
# to INTERFACE_INCLUDE_DIRECTORIES target property.
# So user only need to call "target_link_libraries(turbo::base64)", without
# needing to set include directories.
target_include_directories(
base64 SYSTEM PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> # For being used from add_subdirectory.
$<INSTALL_INTERFACE:include> # When being used from an installation.
)
# Installs library along with header files.
# Also associates the installed target files with an export.
install(
TARGETS base64
EXPORT ${PACKAGE_NAME}-targets
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME}"
)
# Generates and installs cmake config files containing exported targets.
install(
EXPORT ${PACKAGE_NAME}-targets
DESTINATION "${CONFIG_INSTALL_DIR}"
NAMESPACE ${PACKAGE_NAMESPACE}
)
# Generate cmake config-files from template.
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PACKAGE_NAME}-config.cmake.in"
${PACKAGE_NAME}-config.cmake
INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}"
#NO_CHECK_REQUIRED_COMPONENTS_MACRO
# PATH_VARS can be referenced in config template file with PACKAGE_<var>.
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake"
DESTINATION "${CONFIG_INSTALL_DIR}"
)
================================================
FILE: LICENSE
================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
================================================
FILE: README.md
================================================
## Turbo Base64:Fastest Base64 SSE/AVX2/AVX512/Neon/Altivec
[](https://github.com/powturbo/Turbo-Base64/actions/workflows/build.yaml)
##### **Fastest Base64 SIMD** Encoding library
* 100% C (C++ headers), as simple as memcpy
* No other base64 library encode or decode faster
* :sparkles: **Scalar** can be faster than other SSE or ARM Neon based base64 libraries
* **SSE** faster than other SSE/AVX/AVX2! base64 library
* Fastest **AVX2** implementation
* TurboBase64 AVX2 decoding up to ~2x faster than other AVX2 libs.
* TurboBase64 is 3,5-4 times faster than other libs for short strings
* Fastest **ARM Neon** base64
* :new:(2023.04) avx512 - 2x faster than avx2, faster than any other implementation
* :+1: Dynamic CPU detection and **JIT scalar/sse/avx/avx2/avx512** switching
* Base64 robust **error checking**, optimized for **long+short** strings
* Portable library, 32/64 bits, **SSE/AVX/AVX2/AVX512**, **ARM Neon**, **Power9 Altivec**
* OS:Linux amd64, arm64, Power9, MacOs+Apple M1, s390x. Windows: Mingw, visual c++
* Big endian + Little endian
* Ready and simple to use library, no armada of files, no hassles dependencies
* **LICENSE GPL 3** . Commercial license available. Contact us at powturbo [_AT_] gmail [_DOT_] com
<p>
------------------------------------------------------------------------
Download Turbo-Base64 executable benchmark tb64app from
[releases](https://github.com/powturbo/Turbo-Base64/releases/tag/2023.04),
extract the files and type "tb64app"</br>
## Benchmark incl. the best SIMD Base64 libs:
- Single thread
- Including base64 error checking
- Small file + realistic and practical (no PURE cache) benchmark
- Unlike other benchmarks, the best of the best scalar+simd libraries are included
- all libraries with the latest version
#### Benchmark AMD CPU: AMD Ryzen 9 7950X @ 4,50 GHz, DDR5 6000 CL30 - gcc-12.2
|E Size|ratio%|E MB/s|D MB/s|1,000,000 bytes - 2023.07 |
|--------:|-----:|--------:|--------:|----------------|
|1333336|133.33%|**77619**|**76716**|**8:tb64v512vbmi**|
|1333336|133.33%|41325| 48783| 7:_tb64v256 avx2|
|1333336|133.33%|45292| 46665| 5:tb64v256 avx2|
|1000000|100.00%|37047| 31694|10:memcpy |
|1333336|133.33%|25077| 28537| 4:tb64v128a avx |
|1333336|133.33%|24375| 27880| 3:tb64v128 |
|1333336|133.33%| 9513| 6908| 2:tb64x |
|1333336|133.33%| 9513| 5975| 9:_tb64x |
|1333336|133.33%| 4914| 5182| 1:tb64s |
|E Size|ratio%|E MB/s|D MB/s|10,000 bytes - 2023.07 |
|--------:|-----:|--------:|--------:|----------------|
|13336|133.36%|**89079**|**92006**|**8:tb64v512vbmi**|
|10000|100.00%|84418| 85703|10:memcpy |
|13336|133.36%|34963| 46216| 7:_tb64v256 avx2 |
|13336|133.36%|40722| 44552| 5:tb64v256 avx2 |
|13336|133.36%|22601| 27298| 4:tb64v128a avx |
|13336|133.36%|21113| 26930| 3:tb64v128 |
|13336|133.36%| 9648| 6809| 2:tb64x |
|13336|133.36%| 9626| 5599| 9:_tb64x |
|13336|133.36%| 4937| 5184| 1:tb64s |
#### Benchmark Intel CPU: i7-9700k 3.6GHz gcc 11.2
|E Size|ratio%|E MB/s|D MB/s|Name|50,000 bytes - 2022.02 |
|--------:|-----:|--------:|--------:|----------------|----------------|
|66668|133.3|**32794**|**37837**|[**tb64v256**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|
|66668|133.3|27789|22264|[b64avx2](https://github.com/aklomp/base64)|aklomp Base64 avx2|
|66668|133.3|25305|21980|[fb64avx2](https://github.com/lemire/fastbase64)|lemire Fastbase64 avx2|
|||||||
|66668|133.3|**17348**|**20686**|[**tb64v128a**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx**|
|66668|133.3|**16035**|**18865**|[**tb64v128**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 sse**|
|66668|133.3|15820|13078|[b64avx](https://github.com/aklomp/base64)|aklomp Base64 avx|
|66668|133.3|15322|11302|[b64sse](https://github.com/aklomp/base64)|aklomp Base64 sse41|
|50000|100.0|47593|47623|memcpy||
|E Size|ratio%|E MB/s|D MB/s|Name| 1 MB - 2022.02|
|--------:|-----:|--------:|--------:|----------------|----------------|
|1333336|133.3|**29086**|**29748**|[**tb64v256**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|
|1333336|133.3|26153|22515|[b64avx2](https://github.com/aklomp/base64)|Base64 avx2|
|1333336|133.3|23686|21231|[fb64avx2](https://github.com/lemire/fastbase64)|Fastbase64 avx2|
|||||||
|1333336|133.3|**16897**|**20215**|[**tb64v128a**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx**|
|1333336|133.3|**15932**|**18749**|[**tb64v128**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 sse**|
|1333336|133.3|15537|12959|[b64avx](https://github.com/aklomp/base64)|Base64 avx|
|1333336|133.3|15135|11304|[b64sse](https://github.com/aklomp/base64)|Base64 sse41|
|||||||
|1333336|133.3|**6546**|**5473**|[**TB64x**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 scalar**|
|1333336|133.3|6495|4454|[b64plain](https://github.com/aklomp/base64)|Base64 plain|
|1333336|133.3|1908|2752|[TB64s](https://github.com/powturbo/TurboBase64)|**Turbo Base64 scalar**|
|1333336|133.3|2541|4289|[chrome](https://github.com/lemire/fastbase64)|Google Chrome base64|
|1333336|133.3|2670|2299|[fb64plain](https://github.com/lemire/fastbase64)|FastBase64 plain|
|1333334|135.4|1754|219|[linux](https://github.com/lemire/fastbase64)|Linux base64|
|1000000|100.0|28688|28656|memcpy||
<a name="short"></a> TurboBase64 vs. Base64 for short strings (incl. checking)
|String length|E MB/s|D MB/s|Name|50,000 bytes - short strings 2022.02 |
|------------:|--------:|--------:|----------------|----------------|
| 4 - 16 |**2330**|**2161**|[**TB64avx2**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|
| |891|734|[b64avx2](https://github.com/aklomp/base64)|Base64 avx2|
| 8 - 32 |**3963**|**3570**|[**TB64avx2**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|
| |1348|943|[b64avx2](https://github.com/aklomp/base64)|Base64 avx2|
| 16 - 64 |**6881**|**5937**|[**TB64avx2**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|
| |2509|1488|[b64avx2](https://github.com/aklomp/base64)|Base64 avx2|
| 32 - 128 |**10946**|**8880**|[**TB64avx2**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|
| |4902|2777|[b64avx2](https://github.com/aklomp/base64)|Base64 avx2|
###### Benchmark ARM Neon: Apple M1 3,5GHz (clang 12.0)
|E MB/s|size|ratio| D MB/s| 50,000 bytes (2023.08) |
|--------|-----------:|------:|----------:|-----------------------------|
|24012.43|66668|133.34%|15352.09|tb64v128 (turbo-base64)|
|19087.55|66668|133.34%|12515.17|b64neon64 (aklomp/base64)|
|5611.48|66668|133.34%|5092.64|tb64s|
|9782.45|66668|133.34%|6798.98|tb64x|
|6181.37|66668|133.34%|3108.54|b64plain|
|45566.16|50000|100.00%|45484.13|memcpy|
###### Benchmark ARM Neon: ARMv8 A73-ODROID-N2 1.8GHz (clang 6.0)
|E Size|ratio%|E MB/s|D MB/s|Name|30MB binary 2019.12|
|--------:|-----:|--------:|--------:|----------------|----------------|
|40000000|133.3|**2026**|**1650**|[**TB64neon**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 Neon**|
|40000000|133.3|1795|1285|[b64neon64](https://github.com/aklomp/base64)|Base64 Neon|
|40000000|133.3|**1270**|**1095**|[**TB64x**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 scalar**|
|40000000|133.3|695|965|[TB64s](https://github.com/powturbo/TurboBase64)|**Turbo Base64 scalar**|
|40000000|133.3|512|782|[fb64neon](https://github.com/lemire/fastbase64)|Fastbase64 SIMD Neon|
|40000000|133.3|565|460|[Chrome](https://github.com/lemire/fastbase64)|Google Chrome base64|
|40000000|133.3|642|614|[b64plain](https://github.com/aklomp/base64)|Base64 plain|
|40000000|133.3|506|548|[fb64plain](https://github.com/lemire/fastbase64)|Fastbase64 plain|
|40500000|135.4|314|91|[Linux](https://github.com/lemire/fastbase64)|Linux base64|
|30000000|100.0|3820|3834|memcpy||
- (**bold** = pareto in category) MB=1.000.000<br />
- (E/D) : Encode/Decode
- Timmings are respectively relative to the base64 output/input in encode/decode.
<p>
## Compile: (Download or clone Turbo Base64 SIMD)
git clone https://github.com/powturbo/Turbo-Base64.git
make
## Usage: (Benchmark App)
./tb64app file
or
./tb64app
## Function usage:
>**static inline unsigned turbob64len(unsigned n)**<br />
Base64 output length after encoding
>**unsigned tb64enc(const unsigned char *in, unsigned inlen, unsigned char *out)**<br />
Encode binary input 'in' buffer into base64 string 'out'<br />
with automatic cpu detection for simd and switch (sse/avx2/scalar<br />
**in** : Input buffer to encode<br />
**inlen** : Length in bytes of input buffer<br />
**out** : Output buffer<br />
**return value**: Length of output buffer<br />
**Remark** : byte 'zero' is not written to end of output stream<br />
Caller must add 0 (out[outlen] = 0) for a null terminated string<br />
>**unsigned tb64dec(const unsigned char *in, unsigned inlen, unsigned char *out)**<br />
Decode base64 input 'in' buffer into binary buffer 'out' <br />
**in** : input buffer to decode<br />
**inlen** : length in bytes of input buffer <br />
**out** : output buffer<br />
**return value**: >0 output buffer length<br />
0 Error (invalid base64 input or input length = 0)<br />
### Environment:
###### OS/Compiler (32 + 64 bits):
- Windows: Visual C++ (2017)
- Windows: MinGW-w64 makefile
- Linux amd/intel: GNU GCC (>=4.6)
- Linux amd/intel: Clang (>=3.2)
- Linux arm: aarch64 ARMv8 Neon: gcc (>=6.3)
- Linux arm: aarch64 ARMv8 Neon: clang (>=6.0)
- MaxOS: XCode (>=9), apple M1
- PowerPC ppc64le: gcc (>=8.0) incl. SIMD Altivec
###### References:
- [fastbase v2022.02](https://github.com/lemire/fastbase64)
- [base64 v2022.02](https://github.com/aklomp/base64)
- [base64simd](https://github.com/WojciechMula/base64simd)
###### * **SIMD Base64 publications:**
* :green_book:[Faster Base64 Encoding and Decoding Using AVX2 Instructions](https://arxiv.org/abs/1704.00605)
* :green_book:[RFC 4648:The Base16, Base32, and Base64 Data Encodings](https://tools.ietf.org/html/rfc4648)
Last update: 06 AUG 2023
================================================
FILE: cmake/turbobase64-config.cmake.in
================================================
@PACKAGE_INIT@
# Usage:
#
# find_pacakge(@PACKAGE_NAME@)
#
# add_executable(foo)
# target_link_libraries(foo @PACKAGE_NAMESPACE@base64)
set_and_check(@PACKAGE_NAME@_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(@PACKAGE_NAME@_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_LIBDIR@")
set(@PACKAGE_NAME@_LIBRARIES @PACKAGE_NAMESPACE@base64)
include(${CMAKE_CURRENT_LIST_DIR}/@PACKAGE_NAME@-targets.cmake)
check_required_components(@PACKAGE_NAME@)
================================================
FILE: conf.h
================================================
/**
Copyright (C) powturbo 2016-2023
GPL v3 License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- homepage : https://sites.google.com/site/powturbo/
- github : https://github.com/powturbo
- twitter : https://twitter.com/powturbo
- email : powturbo [_AT_] gmail [_DOT_] com
**/
// conf.h - config & common
#ifndef CONF_H_
#define CONF_H_
#if defined(_MSC_VER) && (_MSC_VER < 1600)
#if !defined(_STDINT) && !defined(_MSC_STDINT_H_)
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
#endif
#else
#include <stdint.h>
#endif
#include <stddef.h>
#define __STDC_WANT_IEC_60559_TYPES_EXT__
#include <float.h>
#if defined(__clang__) && defined(__is_identifier)
#if !__is_identifier(_Float16)
#undef FLT16_BUILTIN
#endif
#elif defined(FLT16_MAX)
#define FLT16_BUILTIN
#endif
//------------------------- Compiler ------------------------------------------
#if defined(__GNUC__)
#include <stdint.h>
#define ALIGNED(t,v,n) t v __attribute__ ((aligned (n)))
#define ALWAYS_INLINE inline __attribute__((always_inline))
#define NOINLINE __attribute__((noinline))
#define _PACKED __attribute__ ((packed))
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
//#define bswap8(x) (x)
#if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 8
#define bswap16(x) __builtin_bswap16(x)
#else
static ALWAYS_INLINE unsigned short bswap16(unsigned short x) { return __builtin_bswap32(x << 16); }
#endif
#define bswap32(x) __builtin_bswap32(x)
#define bswap64(x) __builtin_bswap64(x)
#define popcnt32(_x_) __builtin_popcount(_x_)
#define popcnt64(_x_) __builtin_popcountll(_x_)
#if defined(__i386__) || defined(__x86_64__)
//x,__bsr32: 1:0,2:1,3:1,4:2,5:2,6:2,7:2,8:3,9:3,10:3,11:3,12:3,13:3,14:3,15:3,16:4,17:4,18:4,19:4,20:4,21:4,22:4,23:4,24:4,25:4,26:4,27:4,28:4,29:4,30:4,31:4,32:5,...
//x, bsr32: 0:0,1:1,2:2,3:2,4:3,5:3,6:3,7:3,8:4,9:4,10:4,11:4,12:4,13:4,14:4,15:4,16:5,17:5,18:5,19:5,20:5,21:5,22:5,23:5,24:5,25:5,26:5,27:5,28:5,29:5,30:5,31:5,32:6,...
static ALWAYS_INLINE int __bsr32( int x) { asm("bsr %1,%0" : "=r" (x) : "rm" (x) ); return x; }
static ALWAYS_INLINE int bsr32( int x) { int b = -1; asm("bsrl %1,%0" : "+r" (b) : "rm" (x) ); return b + 1; }
static ALWAYS_INLINE int bsr64(uint64_t x ) { return x?64 - __builtin_clzll(x):0; }
static ALWAYS_INLINE int __bsr64(uint64_t x ) { return 63 - __builtin_clzll(x); }
static ALWAYS_INLINE unsigned rol32(unsigned x, int s) { asm ("roll %%cl,%0" :"=r" (x) :"0" (x),"c" (s)); return x; }
static ALWAYS_INLINE unsigned ror32(unsigned x, int s) { asm ("rorl %%cl,%0" :"=r" (x) :"0" (x),"c" (s)); return x; }
static ALWAYS_INLINE uint64_t rol64(uint64_t x, int s) { asm ("rolq %%cl,%0" :"=r" (x) :"0" (x),"c" (s)); return x; }
static ALWAYS_INLINE uint64_t ror64(uint64_t x, int s) { asm ("rorq %%cl,%0" :"=r" (x) :"0" (x),"c" (s)); return x; }
#else
static ALWAYS_INLINE int __bsr32(unsigned x ) { return 31 - __builtin_clz( x); }
static ALWAYS_INLINE int bsr32(int x ) { return x?32 - __builtin_clz( x):0; }
static ALWAYS_INLINE int bsr64(uint64_t x) { return x?64 - __builtin_clzll(x):0; }
static ALWAYS_INLINE int __bsr64(uint64_t x ) { return 63 - __builtin_clzll(x); }
static ALWAYS_INLINE unsigned rol32(unsigned x, int s) { return x << s | x >> (32 - s); }
static ALWAYS_INLINE unsigned ror32(unsigned x, int s) { return x >> s | x << (32 - s); }
static ALWAYS_INLINE unsigned rol64(unsigned x, int s) { return x << s | x >> (64 - s); }
static ALWAYS_INLINE unsigned ror64(unsigned x, int s) { return x >> s | x << (64 - s); }
#endif
#define ctz64(_x_) __builtin_ctzll(_x_)
#define ctz32(_x_) __builtin_ctz(_x_) // 0:32 ctz32(1<<a) = a (a=1..31)
#define clz64(_x_) __builtin_clzll(_x_)
#define clz32(_x_) __builtin_clz(_x_) // 00000000 00000000 00000000 01000000 = 25
#elif _MSC_VER //----------------------------------------------------
#include <windows.h>
#include <intrin.h>
#if _MSC_VER < 1600
#include "vs/stdint.h"
#define __builtin_prefetch(x,a)
#define inline __inline
#else
#include <stdint.h>
#define __builtin_prefetch(x,a) _mm_prefetch(x, _MM_HINT_NTA)
#endif
#define ALIGNED(t,v,n) __declspec(align(n)) t v
#define ALWAYS_INLINE __forceinline
#define NOINLINE __declspec(noinline)
#define _PACKED //__attribute__ ((packed))
#define THREADLOCAL __declspec(thread)
#define likely(x) (x)
#define unlikely(x) (x)
static ALWAYS_INLINE int __bsr32(unsigned x) { unsigned long z=0; _BitScanReverse(&z, x); return z; }
static ALWAYS_INLINE int bsr32( unsigned x) { unsigned long z; _BitScanReverse(&z, x); return x?z+1:0; }
static ALWAYS_INLINE int ctz32( unsigned x) { unsigned long z; _BitScanForward(&z, x); return x?z:32; }
static ALWAYS_INLINE int clz32( unsigned x) { unsigned long z; _BitScanReverse(&z, x); return x?31-z:32; }
#if !defined(_M_ARM64) && !defined(_M_X64)
static ALWAYS_INLINE unsigned char _BitScanForward64(unsigned long* ret, uint64_t x) {
unsigned long x0 = (unsigned long)x, top, bottom; _BitScanForward(&top, (unsigned long)(x >> 32)); _BitScanForward(&bottom, x0);
*ret = x0 ? bottom : 32 + top; return x != 0;
}
static unsigned char _BitScanReverse64(unsigned long* ret, uint64_t x) {
unsigned long x1 = (unsigned long)(x >> 32), top, bottom; _BitScanReverse(&top, x1); _BitScanReverse(&bottom, (unsigned long)x);
*ret = x1 ? top + 32 : bottom; return x != 0;
}
#endif
static ALWAYS_INLINE int __bsr64(uint64_t x) { unsigned long z = 0; _BitScanReverse64(&z, x); return z; }
static ALWAYS_INLINE int bsr64(uint64_t x) { unsigned long z=0; _BitScanReverse64(&z, x); return x?z+1:0; }
static ALWAYS_INLINE int ctz64(uint64_t x) { unsigned long z; _BitScanForward64(&z, x); return x?z:64; }
static ALWAYS_INLINE int clz64(uint64_t x) { unsigned long z; _BitScanReverse64(&z, x); return x?63-z:64; }
#define rol32(x,s) _lrotl(x, s)
#define ror32(x,s) _lrotr(x, s)
#define bswap16(x) _byteswap_ushort(x)
#define bswap32(x) _byteswap_ulong(x)
#define bswap64(x) _byteswap_uint64(x)
#define popcnt32(x) __popcnt(x)
#ifdef _WIN64
#define popcnt64(x) __popcnt64(x)
#else
#define popcnt64(x) (popcnt32(x) + popcnt32(x>>32))
#endif
#define sleep(x) Sleep(x/1000)
#define fseeko _fseeki64
#define ftello _ftelli64
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define strtoull _strtoui64
static ALWAYS_INLINE double round(double num) { return (num > 0.0) ? floor(num + 0.5) : ceil(num - 0.5); }
#endif
#define __bsr8(_x_) __bsr32(_x_)
#define __bsr16(_x_) __bsr32(_x_)
#define bsr8(_x_) bsr32(_x_)
#define bsr16(_x_) bsr32(_x_)
#define ctz8(_x_) ctz32((_x_)+(1<< 8))
#define ctz16(_x_) ctz32((_x_)+(1<<16))
#define clz8(_x_) (clz32(_x_)-24)
#define clz16(_x_) (clz32(_x_)-16)
#define popcnt8(x) popcnt32(x)
#define popcnt16(x) popcnt32(x)
//--------------- Unaligned memory access -------------------------------------
#ifdef UA_MEMCPY
#include <string.h>
static ALWAYS_INLINE unsigned short ctou16(const void *cp) { unsigned short x; memcpy(&x, cp, sizeof(x)); return x; } // ua read
static ALWAYS_INLINE unsigned ctou32(const void *cp) { unsigned x; memcpy(&x, cp, sizeof(x)); return x; }
static ALWAYS_INLINE unsigned long long ctou64(const void *cp) { unsigned long long x; memcpy(&x, cp, sizeof(x)); return x; }
static ALWAYS_INLINE size_t ctousz(const void *cp) { size_t x; memcpy(&x, cp, sizeof(x)); return x; }
#ifdef FLT16_BUILTIN
static ALWAYS_INLINE _Float16 ctof16(const void *cp) { _Float16 x; memcpy(&x, cp, sizeof(x)); return x; }
#endif
static ALWAYS_INLINE float ctof32(const void *cp) { float x; memcpy(&x, cp, sizeof(x)); return x; }
static ALWAYS_INLINE double ctof64(const void *cp) { double x; memcpy(&x, cp, sizeof(x)); return x; }
static ALWAYS_INLINE void stou16( void *cp, unsigned short x) { memcpy(cp, &x, sizeof(x)); } // ua write
static ALWAYS_INLINE void stou32( void *cp, unsigned x) { memcpy(cp, &x, sizeof(x)); }
static ALWAYS_INLINE void stou64( void *cp, unsigned long long x) { memcpy(cp, &x, sizeof(x)); }
static ALWAYS_INLINE void stousz( void *cp, size_t x) { memcpy(cp, &x, sizeof(x)); }
#ifdef FLT16_BUILTIN
static ALWAYS_INLINE void stof16( void *cp, _Float16 x) { memcpy(cp, &x, sizeof(x)); }
#endif
static ALWAYS_INLINE void stof32( void *cp, float x) { memcpy(cp, &x, sizeof(x)); }
static ALWAYS_INLINE void stof64( void *cp, double x) { memcpy(cp, &x, sizeof(x)); }
static ALWAYS_INLINE void ltou32(unsigned *x, const void *cp) { memcpy(x, cp, sizeof(*x)); } // ua read into ptr
static ALWAYS_INLINE void ltou64(unsigned long long *x, const void *cp) { memcpy(x, cp, sizeof(*x)); }
#elif defined(__i386__) || defined(__x86_64__) || \
defined(_M_IX86) || defined(_M_AMD64) || _MSC_VER ||\
defined(__powerpc__) || defined(__s390__) ||\
defined(__ARM_FEATURE_UNALIGNED) || defined(__aarch64__) || defined(__arm__) ||\
defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__) || \
defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__)
#define ctou16(_cp_) (*(unsigned short *)(_cp_))
#define ctou32(_cp_) (*(unsigned *)(_cp_))
#define ctof16(_cp_) (*(_Float16 *)(_cp_))
#define ctof32(_cp_) (*(float *)(_cp_))
#define stou16(_cp_, _x_) (*(unsigned short *)(_cp_) = _x_)
#define stou32(_cp_, _x_) (*(unsigned *)(_cp_) = _x_)
#define stof16(_cp_, _x_) (*(_Float16 *)(_cp_) = _x_)
#define stof32(_cp_, _x_) (*(float *)(_cp_) = _x_)
#define ltou32(_px_, _cp_) *(_px_) = *(unsigned *)(_cp_)
#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || defined(__s390__) || defined(_MSC_VER)
#define ctou64(_cp_) (*(uint64_t *)(_cp_))
#define ctof64(_cp_) (*(double *)(_cp_))
#define stou64(_cp_, _x_) (*(uint64_t *)(_cp_) = _x_)
#define stof64(_cp_, _x_) (*(double *)(_cp_) = _x_)
#define ltou64(_px_, _cp_) *(_px_) = *(uint64_t *)(_cp_)
#elif defined(__ARM_FEATURE_UNALIGNED)
struct _PACKED longu { uint64_t l; };
struct _PACKED doubleu { double d; };
#define ctou64(_cp_) ((struct longu *)(_cp_))->l
#define ctof64(_cp_) ((struct doubleu *)(_cp_))->d
#define stou64(_cp_) ((struct longu *)(_cp_))->l = _x_
#define stof64(_cp_) ((struct doubleu *)(_cp_))->d = _x_
#define ltou64(_px_, _cp_) *(_px_) = ((struct longu *)(_cp_))->l
#endif
#elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7S__)
struct _PACKED shortu { unsigned short s; };
struct _PACKED unsignedu { unsigned u; };
struct _PACKED longu { uint64_t l; };
#ifdef FLT16_BUILTIN
struct _PACKED float16u { _Float16 g; };
#endif
struct _PACKED floatu { float f; };
struct _PACKED doubleu { double d; };
#define ctou16(_cp_) ((struct shortu *)(_cp_))->s
#define ctou32(_cp_) ((struct unsignedu *)(_cp_))->u
#define ctou64(_cp_) ((struct longu *)(_cp_))->l
#define ctof16(_cp_) ((struct float16u *)(_cp_))->g
#define ctof32(_cp_) ((struct floatu *)(_cp_))->f
#define ctof64(_cp_) ((struct doubleu *)(_cp_))->d
#define stou16(_cp_, _x_) ((struct shortu *)(_cp_))->s = _x_
#define stou32(_cp_, _x_) ((struct unsignedu *)(_cp_))->u = _x_
#define stou64(_cp_, _x_) ((struct longu *)(_cp_))->l = _x_
#define stof16(_cp_, _x_) ((struct float16u *)(_cp_))->g = _x_
#define stof32(_cp_, _x_) ((struct floatu *)(_cp_))->f = _x_
#define stof64(_cp_, _x_) ((struct doubleu *)(_cp_))->d = _x_
#define ltou32(_cp_) *(_px_) = ((struct unsignedu *)(_cp_))->u
#define ltou64(_cp_) *(_px_) = ((struct longu *)(_cp_))->l
#else
#error "unknown cpu"
#endif
#define ctou24(_cp_) (ctou32(_cp_) & 0xffffff)
#define ctou48(_cp_) (ctou64(_cp_) & 0xffffffffffffull)
#define ctou8(_cp_) (*(_cp_))
//--------------------- wordsize ----------------------------------------------
#if defined(__64BIT__) || defined(_LP64) || defined(__LP64__) || defined(_WIN64) ||\
defined(__x86_64__) || defined(_M_X64) ||\
defined(__ia64) || defined(_M_IA64) ||\
defined(__aarch64__) ||\
defined(__mips64) ||\
defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) ||\
defined(__s390x__)
#define __WORDSIZE 64
#else
#define __WORDSIZE 32
#endif
#endif
//---------------------misc ---------------------------------------------------
#define BZMASK64(_b_) (~(~0ull << (_b_)))
#define BZMASK32(_b_) (~(~0u << (_b_)))
#define BZMASK16(_b_) BZMASK32(_b_)
#define BZMASK8( _b_) BZMASK32(_b_)
#define BZHI64(_u_, _b_) ((_u_) & BZMASK64(_b_)) // b Constant
#define BZHI32(_u_, _b_) ((_u_) & BZMASK32(_b_))
#define BZHI16(_u_, _b_) BZHI32(_u_, _b_)
#define BZHI8( _u_, _b_) BZHI32(_u_, _b_)
#define BEXTR32(x,start,len) (((x) >> (start)) & ((1u << (len)) - 1)) //Bit field extract (with register)
#ifdef __AVX2__
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
#include <intrin.h>
#else
#include <x86intrin.h>
#endif
#define bzhi32(_u_, _b_) _bzhi_u32(_u_, _b_) // b variable
#define bextr32(x,start,len) _bextr_u32(x,start,len)
#if !(defined(_M_X64) || defined(__amd64__)) && (defined(__i386__) || defined(_M_IX86))
#define bzhi64(_u_, _b_) BZHI64(_u_, _b_)
#else
#define bzhi64(_u_, _b_) _bzhi_u64(_u_, _b_)
#endif
#else
#define bzhi64(_u_, _b_) BZHI64(_u_, _b_)
#define bzhi32(_u_, _b_) BZHI32(_u_, _b_)
#define bextr32(x,start,len) (((x) >> (start)) & ((1u << (len)) - 1)) //Bit field extract (with register)
#endif
#define bzhi16(_u_, _b_) bzhi32(_u_, _b_)
#define bzhi8( _u_, _b_) bzhi32(_u_, _b_)
#define SIZE_ROUNDUP(_n_, _a_) (((size_t)(_n_) + (size_t)((_a_) - 1)) & ~(size_t)((_a_) - 1))
#define ALIGN_DOWN(__ptr, __a) ((void *)((uintptr_t)(__ptr) & ~(uintptr_t)((__a) - 1)))
#define T2_(_x_, _y_) _x_##_y_
#define T2(_x_, _y_) T2_(_x_,_y_)
#define T3_(_x_,_y_,_z_) _x_##_y_##_z_
#define T3(_x_,_y_,_z_) T3_(_x_, _y_, _z_)
#define CACHE_LINE_SIZE 64
#define PREFETCH_DISTANCE (CACHE_LINE_SIZE*4)
#define CLAMP(_x_, _low_, _high_) (((_x_) > (_high_)) ? (_high_) : (((_x_) < (_low_)) ? (_low_) : (_x_)))
//--- NDEBUG -------
#include <stdio.h>
#ifdef _MSC_VER
#ifdef NDEBUG
#define AS(expr, fmt, ...)
#define AC(expr, fmt, ...) do { if(!(expr)) { fprintf(stderr, fmt, ##__VA_ARGS__ ); fflush(stderr); exit(-1); } } while(0)
#define die(fmt, ...) do { fprintf(stderr, fmt, ##__VA_ARGS__ ); fflush(stderr); exit(-1); } while(0)
#else
#define AS(expr, fmt, ...) do { if(!(expr)) { fflush(stdout);fprintf(stderr, "%s:%s:%d:", __FILE__, __FUNCTION__, __LINE__); fprintf(stderr, fmt, ##__VA_ARGS__ ); fflush(stderr); exit(-1); } } while(0)
#define AC(expr, fmt, ...) do { if(!(expr)) { fflush(stdout);fprintf(stderr, "%s:%s:%d:", __FILE__, __FUNCTION__, __LINE__); fprintf(stderr, fmt, ##__VA_ARGS__ ); fflush(stderr); exit(-1); } } while(0)
#define die(fmt, ...) do { fprintf(stderr, "%s:%s:%d:", __FILE__, __FUNCTION__, __LINE__); fprintf(stderr, fmt, ##__VA_ARGS__ ); fflush(stderr); exit(-1); } while(0)
#endif
#else
#ifdef NDEBUG
#define AS(expr, fmt,args...)
#define AC(expr, fmt,args...) do { if(!(expr)) { fprintf(stderr, fmt, ## args ); fflush(stderr); exit(-1); } } while(0)
#define die(fmt,args...) do { fprintf(stderr, fmt, ## args ); fflush(stderr); exit(-1); } while(0)
#else
#define AS(expr, fmt,args...) do { if(!(expr)) { fflush(stdout);fprintf(stderr, "%s:%s:%d:", __FILE__, __FUNCTION__, __LINE__); fprintf(stderr, fmt, ## args ); fflush(stderr); exit(-1); } } while(0)
#define AC(expr, fmt,args...) do { if(!(expr)) { fflush(stdout);fprintf(stderr, "%s:%s:%d:", __FILE__, __FUNCTION__, __LINE__); fprintf(stderr, fmt, ## args ); fflush(stderr); exit(-1); } } while(0)
#define die(fmt,args...) do { fprintf(stderr, "%s:%s:%d:", __FILE__, __FUNCTION__, __LINE__); fprintf(stderr, fmt, ## args ); fflush(stderr); exit(-1); } while(0)
#endif
#endif
================================================
FILE: makefile
================================================
# powturbo (c) Copyright 2016-2023
# Linux: "export CC=clang" "export CXX=clang". windows mingw: "set CC=gcc" "set CXX=g++" or uncomment the CC,CXX lines
CC ?= gcc
CXX ?= g++
#CC=aarch64-linux-gnu-gcc
#CC=powerpc64le-linux-gnu-gcc
# uncomment to disable checking for more faster decoding
#NCHECK=1
#uncomment for full base64 checking (default=partial checking, detect allmost all errors)
#FULLCHECK=1
#uncomment for use memcpy instead of unaligned loads
#UAMEMCPY=1
#NAVX512=1
#NAVX2=1
#NSSE=1
#NAVX=1
#RDTSC=1
#XBASE64=1
#CFLAGS+=-DDEBUG -g
CFLAGS+=-DNDEBUG
#------- OS/ARCH -------------------
ifneq (,$(filter Windows%,$(OS)))
OS := Windows
ARCH=x86_64
else
OS := $(shell uname -s)
ARCH := $(shell uname -m)
ifneq (,$(findstring aarch64,$(CC)))
ARCH = aarch64
else ifneq (,$(findstring arm64,$(ARCH)))
ARCH = aarch64
else ifneq (,$(findstring powerpc64le,$(CC)))
ARCH = ppc64le
endif
endif
ifeq ($(ARCH),ppc64le)
CFLAGS=-mcpu=power9 -mtune=power9
MSSE=-D__SSSE3__
else ifeq ($(ARCH),aarch64)
CFLAGS+=-march=armv8-a
ifneq (,$(findstring clang, $(CC)))
CFLAGS+=-fomit-frame-pointer
endif
MSSE=-march=armv8-a
else ifeq ($(ARCH),$(filter $(ARCH),x86_64 ppc64le))
MSSE=-mssse3
endif
ifeq (,$(findstring clang, $(CC)))
CFLAGS+=-falign-loops
endif
#---------------------------------------------------
ifeq ($(OS),$(filter $(OS),Linux GNU/kFreeBSD GNU OpenBSD FreeBSD DragonFly NetBSD MSYS_NT Haiku))
LDFLAGS+=-lrt
endif
ifeq ($(STATIC),1)
LDFLAGS+=-static
endif
FPIC=-fPIC
ifeq ($(NCHECK),1)
DEFS+=-DNB64CHECK
else
ifeq ($(FULLCHECK),1)
DEFS+=-DB64CHECK
endif
endif
ifeq ($(RDTSC),1)
DEFS+=-D_RDTSC
endif
ifeq ($(UAMEMCPY),1)
DEFS+=-DUA_MEMCPY
endif
ifeq ($(XBASE64),1)
include xtb64.mak
endif
all: tb64app libtb64.so libtb64.a
tb64app.o: CFLAGS+=$(XDEFS) $(MARCH)
turbob64c.o: CFLAGS+=$(DEFS) $(FPIC) -fstrict-aliasing $(MARCH)
turbob64d.o: CFLAGS+=$(DEFS) $(FPIC) -fstrict-aliasing $(MARCH)
turbob64v128.o: CFLAGS+=$(DEFS) $(FPIC) -fstrict-aliasing $(MSSE)
turbob64v256.o: CFLAGS+=$(DEFS) $(FPIC) -fstrict-aliasing -march=haswell
turbob64v512.o: CFLAGS+=$(DEFS) $(FPIC) -fstrict-aliasing -march=skylake-avx512 -mavx512vbmi
turbob64v128a.o: turbob64v128.c
$(CC) -O3 $(CFLAGS) $(DEFS) $(FPIC) -fstrict-aliasing -march=corei7-avx -mtune=corei7-avx -mno-aes $< -c -o turbob64v128a.o
#_tb64.o: _tb64.c
# $(CC) -O3 $(FPIC) -I/usr/include/python2.7 $< -c -o $@
LIB=turbob64c.o turbob64d.o turbob64v128.o
ifeq ($(ARCH),x86_64)
LIB+=turbob64v128a.o turbob64v256.o
ifneq ($(NAVX512),1)
LIB+=turbob64v512.o
else
DEFS+=-DNAVX512
endif
endif
#_tb64.so: _tb64.o
# $(CC) -shared $^ -o $@
libtb64.a: $(LIB)
ar cr $@ $+
libtb64.so: $(LIB)
$(CC) -shared $^ -o $@
install:
cp libtb64.so ~/.local/lib/
cp libtb64.a ~/.local/lib/
# FIXME: how does one build _tb64.so?
# ./python/tb64/build.py
# cp _tb64.so ~/.local/lib/
tb64app: $(LIB) $(XLIB) tb64app.o
$(CC) -O3 $(LIB) $(XLIB) $(XDEFS) tb64app.o $(LDFLAGS) -o tb64app
tb64bench: $(LIB) tb64bench.o
$(CC) -O3 $(LIB) tb64bench.o $(LDFLAGS) -o tb64bench
tb64test: $(LIB) tb64test.o
$(CC) -O3 $(LIB) tb64test.o $(LDFLAGS) -o tb64test
.c.o:
$(CC) -O3 $(CFLAGS) $< -c -o $@
.cc.o:
$(CXX) -O3 $(CXXFLAGS) $< -c -o $@
ifeq ($(OS),Windows)
clean:
del /S *.o
del *.a
del *.so
else
clean:
@find . -type f -name "*\.o" -delete -or -name "*\~" -delete -or -name "core" -delete -or -name "tb64app" -delete -or -name "_tb64.so" \
-delete -or -name "_tb64.c" -delete -or -name "xlibtb64.so" -delete -or -name "libtb64.a" -delete -or -name "libtb64.so"
endif
================================================
FILE: rust/.gitignore
================================================
target
Cargo.lock
================================================
FILE: rust/Cargo.toml
================================================
[package]
authors = ["powturbo <powturbo [AT] gmail [DOT] com>"]
build = "build.rs"
name = "Turbo-Base64"
version = "0.60.0"
[dependencies]
rand = "0.8"
[build-dependencies]
bindgen = "*"
================================================
FILE: rust/README.md
================================================
# Rust bindings for Turbo-Base64
This is a wrapper for [Turbo-Base64](https://github.com/powturbo/Turbo-Base64).
## Installation
1- Prerequistes: build and install the Turbo-Base64 library libtb64.a into /usr/local/lib
2 - Use the provided src/bindings.rs file or generate a new rust bindings.rs file.
```shell
cargo build
```
3 - Test
```shell
cargo test
```
## Examples
- see the tests.rs file in the src folder
- a list of public functions are available in the bindings.rs file
## Reference
- [bindgen automatically generates Rust FFI bindings to C and C++ libraries.](https://rust-lang.github.io/rust-bindgen/)
================================================
FILE: rust/build.rs
================================================
// build bindings.rs
extern crate bindgen;
use std::env;
use std::path::PathBuf;
fn main() {
println!("cargo:rustc-link-lib=tb64");
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
================================================
FILE: rust/src/bindings.rs
================================================
/* automatically generated by rust-bindgen 0.64.0 */
pub const TB64_VERSION : u32 = 100 ;
pub type wchar_t = :: std :: os :: raw :: c_int ; # [repr (C)] # [repr (align (16))] # [derive (Debug , Copy , Clone)]
pub struct max_align_t {
pub __clang_max_align_nonce1 : :: std :: os :: raw :: c_longlong ,
pub __bindgen_padding_0 : u64 ,
pub __clang_max_align_nonce2 : u128 , } # [test] fn bindgen_test_layout_max_align_t () { const UNINIT : :: std :: mem :: MaybeUninit < max_align_t > = :: std :: mem :: MaybeUninit :: uninit () ; let ptr = UNINIT . as_ptr () ;
assert_eq ! (:: std :: mem :: size_of :: < max_align_t > () , 32usize , concat ! ("Size of: " , stringify ! (max_align_t))) ;
assert_eq ! (:: std :: mem :: align_of :: < max_align_t > () , 16usize , concat ! ("Alignment of " , stringify ! (max_align_t))) ;
assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __clang_max_align_nonce1) as usize - ptr as usize } , 0usize , concat ! ("Offset of field: " , stringify ! (max_align_t) , "::" , stringify ! (__clang_max_align_nonce1))) ;
assert_eq ! (unsafe { :: std :: ptr :: addr_of ! ((* ptr) . __clang_max_align_nonce2) as usize - ptr as usize } , 16usize , concat ! ("Offset of field: " , stringify ! (max_align_t) , "::" , stringify ! (__clang_max_align_nonce2))) ; }
extern "C" { pub fn tb64enclen (inlen : usize) -> usize ; }
extern "C" { pub fn tb64declen (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize) -> usize ; }
extern "C" { pub fn tb64enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; } pub type TB64FUNC = :: std :: option :: Option < unsafe extern "C" fn (in_ : * const :: std :: os :: raw :: c_uchar , n : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize > ; extern "C" { pub static mut _tb64e : TB64FUNC ; } extern "C" { pub static mut _tb64d : TB64FUNC ; }
extern "C" { pub fn tb64senc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64sdec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64xenc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64xdec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64v128enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64v128dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64v128aenc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64v128adec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64v256enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64v256dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64v512enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64v512dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn tb64ini (id : :: std :: os :: raw :: c_uint , isshort : :: std :: os :: raw :: c_uint) ; }
extern "C" { pub fn _tb64v256enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn _tb64v256dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }
extern "C" { pub fn cpuini (cpuisa : :: std :: os :: raw :: c_uint) -> :: std :: os :: raw :: c_uint ; }
extern "C" { pub fn cpustr (cpuisa : :: std :: os :: raw :: c_uint) -> * mut :: std :: os :: raw :: c_char ; }
================================================
FILE: rust/src/lib.rs
================================================
// prerequisites: Install Turbo-Base64 library tb64lib under /usr/lib or /usr/local/lib
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
//include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
include!("bindings.rs");
#[cfg(test)]
mod tests;
================================================
FILE: rust/src/tests.rs
================================================
extern crate rand;
use std::convert::TryFrom;
use std::convert::TryInto;
use std::vec;
use super::*;
fn decode_block(indata: &[u8]) -> Vec<u8> {
println!("dec size = {}", indata.len());
if indata.len() == 0 {
return vec![];
}
unsafe {
let inlen = tb64declen(indata.as_ptr() as *mut ::std::os::raw::c_uchar, indata.len() );
let mut decoded_data = vec![0u8; inlen ];
let _ = tb64sdec(indata.as_ptr() as *mut ::std::os::raw::c_uchar, indata.len(), decoded_data.as_mut_ptr() as *mut u8);
return decoded_data;
}
}
fn encode_block(indata: &[u8]) -> Vec<u8> {
println!("enc size = {}", indata.len());
unsafe {
let outlen = tb64enclen( indata.len() );
let mut encoded_indata = vec![0u8; outlen];
let _size = tb64senc(indata.as_ptr() as *mut u8, indata.len(), encoded_indata.as_mut_ptr() as *mut ::std::os::raw::c_uchar);
return encoded_indata;
}
}
fn test_block(inlen: usize) {
let mut source = Vec::with_capacity(inlen);
for i in 0..inlen {
if rand::random() {
source.push(u8::try_from(i+1).unwrap());
}
}
if source.is_empty() {
source = vec![1u8, 2]
}
let encoded = encode_block(&source[..]);
let decoded = decode_block(&encoded[..]);
assert_eq!(&source[..], &decoded[..]);
}
#[test]
fn sample_tb64() {
let block_sizes = vec![1u32, 100, 3, 4, 8, 10, 16, 8, 32, 5, 64, 3, 128, 255];
for _ in 1..10 {
for size in &block_sizes[..] {
println!("testing with cap = {}", size+0);
test_block((size+0).try_into().unwrap());
}
}
}
================================================
FILE: rust/wrapper.h
================================================
// Include TurboPFor public c/c++ header
#include "../turbob64.h"
================================================
FILE: tb64app.c
================================================
/**
Copyright (C) powturbo 2016-2023
SPDX-License-Identifier: GPL v3 License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- homepage : https://sites.google.com/site/powturbo/
- github : https://github.com/powturbo
- twitter : https://twitter.com/powturbo
- email : powturbo [_AT_] gmail [_DOT_] com
**/
// Turbo-Base64: TB64app.c - Benchmark app
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#if !defined(_WIN32)
#include <sys/mman.h>
#include <sys/resource.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#else
#include <io.h>
#include <fcntl.h>
#endif
#ifdef __APPLE__
#include <sys/malloc.h>
#else
#include <malloc.h>
#endif
#ifdef _MSC_VER
#include "vs/getopt.h"
#else
#include <getopt.h>
#endif
#include "conf.h"
#include "turbob64.h"
#include "time_.h"
#ifdef _WIN32
int getpagesize_() {
static int pagesize = 0;
if (pagesize == 0) {
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
pagesize = max(system_info.dwPageSize,
system_info.dwAllocationGranularity);
}
return pagesize;
}
#endif
#include "turbob64_.h"
#ifdef XBASE64
#define FAC 2
#include "xb64test.h"
#else
#define FAC 1
#endif
#ifdef CRZY
#include "crzy64/crzy64.h"
#endif
//------------------------------- malloc ------------------------------------------------
#define USE_MMAP
#if __WORDSIZE == 64
#define MAP_BITS 30
#else
#define MAP_BITS 28
#endif
void *_valloc(size_t size, unsigned a) {
if(!size) return NULL;
#ifdef _WIN32
return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
#elif defined(USE_MMAP) && !defined(__APPLE__)
void *ptr = mmap(NULL/*0(size_t)a<<MAP_BITS*/, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if(ptr == MAP_FAILED) return NULL;
return ptr;
#else
return malloc(size);
#endif
}
void _vfree(void *p, size_t size) {
if(!p) return;
#ifdef _WIN32
VirtualFree(p, 0, MEM_RELEASE);
#elif defined(USE_MMAP) && !defined(__APPLE__)
munmap(p, size);
#else
free(p);
#endif
}
int memcheck(unsigned char *in, unsigned n, unsigned char *cpy) {
int i;
for(i = 0; i < n; i++)
if(in[i] != cpy[i]) {
printf("ERROR in[%d]=%x, dec[%d]=%x\n", i, in[i], i, cpy[i]);
return i+1;
}
return 0;
}
#define ID_MEMCPY 10
unsigned bench(unsigned char *in, unsigned n, unsigned char *out, unsigned char *cpy, int id) {
unsigned l = 0,m=tb64enclen(n);
#ifndef _MSC_VER
memrcpy(cpy,in,n);
#endif
switch(id) {
case 1: TMBENCH("",l=tb64senc( in, n, out),m); pr(l,n); TMBENCH2(" 1:tb64s ", tb64sdec( out, l, cpy), l); break;
case 2: TMBENCH("",l=tb64xenc( in, n, out),m); pr(l,n); TMBENCH2(" 2:tb64x ", tb64xdec( out, l, cpy), l); break;
#if defined(__i386__) || defined(__x86_64__) || defined(__ARM_NEON) || defined(__powerpc64__)
case 3:if(cpuini(0)>=0x33) { TMBENCH("",l=tb64v128enc( in, n, out),m); pr(l,n); TMBENCH2(" 3:tb64v128 ", tb64v128dec( out, l, cpy), l); } break;
case 6: TMBENCH("",l=tb64enc( in, n, out),m); pr(l,n); TMBENCH2(" 6:tb64auto ", tb64dec( out, l, cpy), l); break;
#endif
#if defined(__i386__) || defined(__x86_64__)
case 4:if(cpuini(0)>=0x50) { TMBENCH("",l=tb64v128aenc(in, n, out),m); pr(l,n); TMBENCH2(" 4:tb64v128a avx ", tb64v128adec(out, l, cpy), l); } break;
case 5:if(cpuini(0)>=0x60) { TMBENCH("",l=tb64v256enc( in, n, out),m); pr(l,n); TMBENCH2(" 5:tb64v256 avx2 ", tb64v256dec( out, l, cpy), l); } break;
case 7:if(cpuini(0)>=0x60) { TMBENCH("",l=_tb64v256enc(in, n, out),m); pr(l,n); TMBENCH2(" 7:_tb64v256 avx2 ", _tb64v256dec(out, l, cpy), l); } break;
#ifndef NAVX512 // +VBMI
case 8:{ unsigned c = cpuini(0);
if(c>=(0x800|0x200)) { TMBENCH("", l=tb64v512enc(in, n, out),m); pr(l,n); TMBENCH2(" 8:tb64v512vbmi ", tb64v512dec( out,l,cpy),l); }
//else if(c>=0x800) { TMBENCH("", l=tb64v256enc(in, n, out),m); pr(l,n); TMBENCH2(" 8:tb64v512 ", tb64v512dec0(out, l, cpy),l); }
} break;
#endif
#endif
case 9: TMBENCH("",l=tb64xenc( in, n, out),m); pr(l,n); TMBENCH2(" 9:_tb64x ", _tb64xd( out, l, cpy), l); break;
case ID_MEMCPY: TMBENCH( "", memcpy(out,in,m) ,m); pr(n,n); TMBENCH2("10:memcpy ", memcpy(cpy,out,n), n); l = n; break;
#ifdef XBASE64
#include "xtb64test_.c"
#endif
default: return 0;
}
if(l) { printf(" %10d\n", n); memcheck(in,n,cpy); }
return l;
}
void usage(char *pgm) {
fprintf(stderr, "\nTurboBase64 Copyright (c) 2016-2023 Powturbo %s\n", __DATE__);
fprintf(stderr, "Usage: %s [options] [file]\n", pgm);
fprintf(stderr, " -e# # = function ids separated by ',' or ranges '#-#' (default='1-%d')\n", ID_MEMCPY);
fprintf(stderr, " -B#s # = max. benchmark filesize (default 120Mb)\n");
fprintf(stderr, " s = modifier s:B,K,M,G=(1, 1000, 1.000.000, 1.000.000.000) s:k,m,h=(1024,1Mb,1Gb). (default m) ex. 64k or 64K\n");
fprintf(stderr, "Benchmark:\n");
fprintf(stderr, " -I#/-J# # = Number of de/compression runs (default=3)\n");
fprintf(stderr, " -e# # = function id\n");
fprintf(stderr, " -q# # = cpuid (33=ssse, 50:avx, 60=avx2 (default:auto detect)\n");
fprintf(stderr, " -k# random test with predefined sizes (0=1K-20MB function id\n");
fprintf(stderr, " #: 0=1K-20MB, 1=short input\n");
fprintf(stderr, " -T Test all input sizes 0-10000\n");
fprintf(stderr, "Ex. turbob64 file\n");
fprintf(stderr, " turbob64 -e3 file\n");
fprintf(stderr, " turbob64 -e1-6 file\n");
fprintf(stderr, " turbob64 -q33 file -I15 -J15\n");
fprintf(stderr, " turbob64 -e1-6 -k1\n");
exit(0);
}
void fuzzcheck(unsigned char *_in, unsigned insize, unsigned char *_out, unsigned outsize, unsigned char *_cpy, unsigned fuzz) {
unsigned char *in = _in, *out = _out, *cpy = _cpy; printf(" Fuzz OK. Waiting seg. fault\n");fflush(stdout);
unsigned n;
for(n = 0; n <= 10099; n++) {
unsigned m = tb64enclen(n);
if(fuzz & 2) { cpy = (_cpy+insize) - n, out = (_out+outsize) - m; printf("O%x ", out[m]);fflush(stdout);
printf("C%x ", cpy[n]);fflush(stdout);
}
if(fuzz & 1) { in = (_in +insize) - n; printf("I%x ", in[n]); fflush(stdout); }
} printf("Fuzztest not reliable. Reapeat until seg. fault\n");fflush(stdout);
}
void fuzztest(unsigned id, unsigned char *_in, unsigned insize, unsigned char *_out, unsigned outsize, unsigned char *_cpy, unsigned fuzz) {
unsigned char *in = _in, *out = _out, *cpy = _cpy;
unsigned s,n,i,l = 0;
printf("[id=%u", id);fflush(stdout);
for(n = 0; n <= 10099; n++) {
unsigned m = tb64enclen(n);
if(fuzz & 1) in = (_in +insize) - n; // move the i/o buffers to the end, this will normally (but not always) cause a seg fault
if(fuzz & 2) cpy = (_cpy+insize) - n, out = (_out+outsize) - m; // by reading/writing beyond the buffer end
srand(time(0));
for(i = 0; i < n; i++) // Generate a random string
in[i] = rand()&0xff;
memrcpy(cpy, in, n); // copy input reversed
switch(id) {
case 1: l = tb64senc( in, n, out); if(l != m) die("Error n=%u\n", n); tb64sdec( out, l, cpy); break;
case 2: l = tb64xenc( in, n, out); if(l != m) die("Error n=%u\n", n); tb64xdec( out, l, cpy); break;
case 3: if(cpuini(0)>=0x33) { l = tb64v128enc( in, n, out); if(l != m) die("Error n=%u\n", n); tb64v128dec( out, l, cpy); } break;
#if defined(__i386__) || defined(__x86_64__)
case 4: if(cpuini(0)>=0x50) { l = tb64v128aenc(in, n, out); if(l != m) die("Error n=%u\n", n); tb64v128adec(out, l, cpy); } break;
case 5: if(cpuini(0)>=0x60) { l = tb64v256enc( in, n, out); if(l != m) die("Error n=%u\n", n); tb64v256dec( out, l, cpy); } break;
case 8: if(cpuini(0)>=(0x800|0x200)) { l = tb64v512enc( in, n, out); if(l != m) die("Error n=%u\n", n); tb64v512dec( out, l, cpy); } break;
case 11: if(cpuini(0)>=0x60) { l = _tb64v256enc(in, n, out); if(l != m) die("Error n=%u\n", n);_tb64v256dec(out, l, cpy); } break; //unsafe when OVHD=0
#endif
#ifdef XBASE64F // fastbase is unsafe, can reads/writes beyound i/o buffers
#include "xtb64fuzz_.c"
#endif
default: printf("]");fflush(stdout);
return;
}
if(l && memcheck(in,n,cpy)) exit(-1);
} printf(" OK]");fflush(stdout);
}
int verbose=3;
int main(int argc, char* argv[]) {
unsigned cmp = 1, bsize = (120*Mb), esize = 4, fno, id=0, fuzz = 0, bid = 0, tst = 0,
n = bsize, outsize = tb64enclen(n), insize = outsize;
char *scmd = NULL, _scmd[33];
unsigned char *in, *_in=NULL, *cpy, *_cpy=NULL, *out, *_out=NULL;
int c, digit_optind = 0, this_option_optind = optind ? optind : 1, option_index = 0;
static struct option long_options[] = { {"blocsize", 0, 0, 'b'}, {0, 0, 0} };
for(;;) {
if((c = getopt_long(argc, argv, "B:e:f:I:J:k:m:M:q:Tv:", long_options, &option_index)) == -1) break;
switch(c) {
case 0 : printf("Option %s", long_options[option_index].name); if(optarg) printf (" with arg %s", optarg); printf ("\n"); break;
case 'B': bsize = argtoi(optarg,1); break;
case 'k': bid = atoi(optarg); break;
case 'f': fuzz = atoi(optarg); break;
case 'e': scmd = optarg; break;
case 'I': if((tm_Rep = atoi(optarg))<=0) tm_rep = tm_Rep = 1; break;
case 'J': if((tm_Rep2 = atoi(optarg))<=0) tm_rep = tm_Rep2 = 1; break;
#ifdef XBASE64
case 'm': if(!(smin = atoi(optarg))) smin = 1; break;
case 'M': smask = atoi(optarg); if(smask&(smask-1)) die("Range must be power of 2"); smask--; break;
#endif
case 'q': if(!strcasecmp(optarg,"sse")) cpuini(0x33);
else if(!strcasecmp(optarg,"avx")) cpuini(0x50);
else if(!strcasecmp(optarg,"avx2")) cpuini(0x60);
else if(!strcasecmp(optarg,"avx512")) cpuini(0x78); break;
case 'T': tst++; break;
case 'v': verbose = atoi(optarg); break;
default:
usage(argv[0]);
exit(0);
}
}
tm_init(tm_Rep, verbose);
sprintf(_scmd, "1-%d", ID_MEMCPY);
tb64ini(0,0); printf("detected simd (id=%x->'%s')\n\n", cpuini(0), cpustr(cpuini(0)));
unsigned char *tmp1,*tmp2;
if(!(_in = (unsigned char*)_valloc(insize, 0))) die("malloc error in size=%u\n", insize); in = _in;
if(!(tmp1 = (unsigned char*)_valloc(insize, 0))) die("malloc error cpy size=%u\n", insize);
if(!(_cpy = (unsigned char*)_valloc(insize, 0))) die("malloc error cpy size=%u\n", insize); cpy = _cpy;
if(!(tmp2 = (unsigned char*)_valloc(outsize,0))) die("malloc error cpy size=%u\n", insize);
if(!(_out = (unsigned char*)_valloc(outsize,0))) die("malloc error out size=%u\n", outsize); out = _out;
_vfree(tmp1, insize);
_vfree(tmp2, outsize);
if(tst) { //------------------------ test + fuzzer (option -T) ----------------------------------------------------------------------------
char *p = scmd?scmd:_scmd;
do {
unsigned id = strtoul(p, &p, 10), idx = id, i;
while(isspace(*p)) p++;
if(*p == '-' && (idx = strtoul(p+1, &p, 10)) < id)
idx = id;
for(i = id; i <= idx; i++)
fuzztest(i,_in,insize,_out,outsize,_cpy, fuzz);
fuzzcheck(_in,insize,_out,outsize,_cpy, fuzz);
} while(*p++); printf("fuzz OK\n");
} else if(argc - optind < 1) { //------------------ bechmark with predefined sizes (option -k#) -------------------------------------------
unsigned _size0[] = { 1*KB, 10*KB, 50*KB, 100*KB, 200*KB, 500*KB, 1*MB, 10*MB, 20*MB, 0 },
_size1[] = { 1, 3, 7, 15, 31, 67, 127, 255, 511, 1*KB, 0 },
_size2[] = { 12, 15,16,17, 31,32,33, 47,48,50, 63,64,65, 95,96,97, 120, 180, 250, 500, 1*KB, 10*KB, 50*KB, 100*KB, 500*KB, 1*MB, 0 },
_size3[] = { 100, 200, 1*KB, 100*KB, 1*MB, 0 },
_size4[] = { 15, 63, 127, 159, 191, 255, 511, 1023, 0 },
_size5[] = { 1,2, 3,4,5,6, 63,64,65,66, 0 },
*_sizea[] = { _size0, _size1, _size2, _size3, _size4, _size5 },
*sizes = _sizea[bid>5?5:bid];
if(bid > 5) { _size5[0] = bid; _size5[1] = 0; }
printf(" E MB/s size ratio%% D MB/s function (random)\n");
for(int s = 0; sizes[s]; s++) {
n = sizes[s]; if(n > bsize) continue;
if(fuzz & 1) in = (_in +insize) - n;
if(fuzz & 2) out = (_out+outsize) - tb64enclen(n), cpy = (_cpy+insize)-n;
srand(0); for(int i = 0; i < n; i++) in[i] = rand()&0xff;
char *p = scmd?scmd:_scmd;
do {
unsigned id = strtoul(p, &p, 10),idx = id, i;
while(isspace(*p)) p++;
if(*p == '-' && (idx = strtoul(p+1, &p, 10)) < id)
idx = id;
for(i = id; i <= idx; i++)
bench(in, n, out,cpy,i);
} while(*p++);
}
} else { //------------------------------------ file benchmark -----------------------------------------------------------------------------
for(fno = optind; fno < argc; fno++) {
unsigned flen,m,n=bsize,i;
char *inname = argv[fno];
if(strcmp(inname, "NULL")) {
FILE *fi = fopen(inname, "rb"); if(!fi ) { perror(inname); continue; }
fseek(fi, 0, SEEK_END);
flen = ftell(fi);
fseek(fi, 0, SEEK_SET);
if(flen > bsize) flen = bsize;
n = flen;
n = fread(in, 1, n, fi); printf("File='%s' Length=%u\n", inname, n);
fclose(fi);
}
m = tb64enclen(n);
if(!n) exit(0);
printf(" E MB/s size ratio D MB/s function\n");
char *p = scmd?scmd:_scmd;
do {
unsigned id = strtoul(p, &p, 10),idx = id, i;
while(isspace(*p)) p++;
if(*p == '-' && (idx = strtoul(p+1, &p, 10)) < id)
idx = id;
for(i = id; i <= idx; i++)
bench(in,n,out,cpy,i);
} while(*p++);
}
}
_vfree(_in, insize);
_vfree(_out, outsize);
_vfree(_cpy, insize);
}
================================================
FILE: time_.h
================================================
/**
Copyright (C) powturbo 2013-2023
GPL v2 License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- homepage : https://sites.google.com/site/powturbo/
- github : https://github.com/powturbo
- twitter : https://twitter.com/powturbo
- email : powturbo [_AT_] gmail [_DOT_] com
**/
// time_.h : parameter free high precision time/benchmark functions
#include <time.h>
#include <float.h>
#ifdef _WIN32
#include <windows.h>
#ifndef sleep
#define sleep(n) Sleep((n) * 1000)
#endif
#define uint64_t unsigned __int64
#else
#include <stdint.h>
#include <unistd.h>
#define Sleep(ms) usleep((ms) * 1000)
#endif
#if defined (__i386__) || defined( __x86_64__ ) // ------------------ rdtsc --------------------------
#ifdef _MSC_VER
#include <intrin.h> // __rdtsc
#else
#include <x86intrin.h>
#endif
#ifdef __corei7__
#define RDTSC_INI(_c_) do { unsigned _cl, _ch; \
__asm volatile ("cpuid\n\t" \
"rdtsc\n\t" \
"mov %%edx, %0\n" \
"mov %%eax, %1\n": "=r" (_ch), "=r" (_cl):: \
"%rax", "%rbx", "%rcx", "%rdx"); \
_c_ = (uint64_t)_ch << 32 | _cl; \
} while(0)
#define RDTSC(_c_) do { unsigned _cl, _ch; \
__asm volatile("rdtscp\n" \
"mov %%edx, %0\n" \
"mov %%eax, %1\n" \
"cpuid\n\t": "=r" (_ch), "=r" (_cl):: "%rax",\
"%rbx", "%rcx", "%rdx");\
_c_ = (uint64_t)_ch << 32 | _cl;\
} while(0)
#else
/*#define RDTSC(_c_) do { unsigned _cl, _ch;\
__asm volatile ("cpuid \n"\
"rdtsc"\
: "=a"(_cl), "=d"(_ch)\
: "a"(0)\
: "%ebx", "%ecx");\
_c_ = (uint64_t)_ch << 32 | _cl;\
} while(0)*/
#define RDTSC(_c_) do { unsigned _cl, _ch;\
__asm volatile("rdtsc" : "=a"(_cl), "=d"(_ch) );\
_c_ = (uint64_t)_ch << 32 | _cl;\
} while(0)
#endif
#define RDTSC_INI(_c_) RDTSC(_c_)
#else // ------------------ time --------------------------
#define RDTSC_INI(_c_)
#define RDTSC(_c_)
#endif
#ifndef TM_F
#define TM_F 1.0 // TM_F=4 -> MI/s
#endif
#ifdef _RDTSC //---------------------- rdtsc --------------------------------
#define TM_M (CLOCKS_PER_SEC*1000000ull)
#define TM_PRE 4
#define TM_MBS "cycle/byte"
static double TMBS(unsigned l, double t) { return (double)t/(double)l; }
typedef uint64_t tm_t;
static tm_t tmtime() { uint64_t c; RDTSC(c); return c; }
static tm_t tminit() { uint64_t c; __asm volatile("" ::: "memory"); RDTSC_INI(c); return c; }
static double tmdiff(tm_t start, tm_t stop) { return (double)(stop - start); }
static int tmiszero(tm_t t) { return !t; }
#else //---------------------- time -----------------------------------
#define TM_M 1
#define TM_PRE 2
#define TM_MBS "MB/s"
static double TMBS(unsigned l, double t) { return (l/t)/1000000.0; }
#ifdef _WIN32 //-------- windows
static LARGE_INTEGER tps;
typedef unsigned __int64 tm_t;
static tm_t tmtime() { LARGE_INTEGER tm; tm_t t; QueryPerformanceCounter(&tm); return tm.QuadPart; }
static tm_t tminit() { tm_t t0,ts; QueryPerformanceFrequency(&tps); t0 = tmtime(); while((ts = tmtime())==t0) {}; return ts; }
static double tmdiff(tm_t start, tm_t stop) { return (double)(stop - start)/tps.QuadPart; }
static int tmiszero(tm_t t) { return !t; }
#else // Linux & compatible / MacOS
#ifdef __APPLE__
#include <AvailabilityMacros.h>
#ifndef MAC_OS_X_VERSION_10_12
#define MAC_OS_X_VERSION_10_12 101200
#endif
#define CIVETWEB_APPLE_HAVE_CLOCK_GETTIME (defined(__APPLE__) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12)
#if !(CIVETWEB_APPLE_HAVE_CLOCK_GETTIME)
#include <sys/time.h>
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 0
int clock_gettime(int /*clk_id*/, struct timespec* t) {
struct timeval now;
int rv = gettimeofday(&now, NULL);
if (rv) return rv;
t->tv_sec = now.tv_sec;
t->tv_nsec = now.tv_usec * 1000;
return 0;
}
#endif
#endif
typedef struct timespec tm_t;
static tm_t tmtime() { struct timespec tm; clock_gettime(CLOCK_MONOTONIC, &tm); return tm; }
static double tmdiff(tm_t start, tm_t stop) { return (stop.tv_sec - start.tv_sec) + (double)(stop.tv_nsec - start.tv_nsec)/1e9f; }
static tm_t tminit() { tm_t t0 = tmtime(),t; while(!tmdiff(t = tmtime(),t0)) {}; return t; }
static int tmiszero(tm_t t) { return !(t.tv_sec|t.tv_nsec); }
#endif
#endif
//---------------------------------------- bench ----------------------------------------------------------------------
// for each a function call is repeated until exceeding tm_tx seconds.
// A run duration is always tm_tx seconds
// The number of runs can be set with the program options -I and -J (specify -I15 -J15 for more precision)
// sleep after each 8 runs to avoid cpu throttling.
#define TMSLEEP do { tm_T = tmtime(); if(tmiszero(tm_0)) tm_0 = tm_T; else if(tmdiff(tm_0, tm_T) > tm_TX) { if(tm_verbose>2) { printf("S \b\b");fflush(stdout); } sleep(tm_slp); tm_0=tmtime();} } while(0)
// benchmark loop
#define TMBEG(_tm_Reps_) { unsigned _tm_r,_tm_c = 0,_tm_R,_tm_Rx = _tm_Reps_,_tm_Rn = _tm_Reps_; double _tm_t;\
for(tm_rm = tm_rep, tm_tm = DBL_MAX, _tm_R = 0; _tm_R < _tm_Rn; _tm_R++) { tm_t _tm_t0 = tminit(); /*for each run*/\
for(_tm_r = 0;_tm_r < tm_rm;) { /*repeat tm_rm times */
#define TMEND(_len_) \
_tm_r++; if(tm_tm == DBL_MAX && (_tm_t = tmdiff(_tm_t0, tmtime())) > tm_tx) break;\
}\
/*1st run: break the loop after tm_tx=1 sec, calculate a new repeats 'tm_rm' to avoid calling time() after each function call*/\
/*other runs: break the loop only after 'tm_rm' repeats */ \
_tm_t = tmdiff(_tm_t0, tmtime());\
/*set min time, recalculate repeats tm_rm based on tm_tx, recalculate number of runs based on tm_TX*/\
if(_tm_t < tm_tm) { if(tm_tm == DBL_MAX) { tm_rm = _tm_r; _tm_Rn = tm_TX/_tm_t; _tm_Rn = _tm_Rn<_tm_Rx?_tm_Rn:_tm_Rx; /*printf("repeats=%u,%u,%.4f ", _tm_Rn, _tm_Rx, _tm_t);*/ } \
tm_tm = _tm_t; _tm_c++;\
} else if(_tm_t > tm_tm*1.15) TMSLEEP;/*force sleep at 15% divergence*/\
if(tm_verbose>2) { printf("%8.*f %2d_%.2d\b\b\b\b\b\b\b\b\b\b\b\b\b\b",TM_PRE, TMBS(_len_, tm_tm/tm_rm),_tm_R+1,_tm_c),fflush(stdout); }\
if((_tm_R & 7)==7) sleep(tm_slp); /*pause 20 secs after each 8 runs to avoid cpu throttling*/\
}\
}
static unsigned tm_rep = 1u<<30, tm_Rep = 3, tm_Rep2 = 3, tm_rm, tm_RepMin = 1, tm_slp = 20, tm_verbose = 3;
static tm_t tm_0, tm_T;
static double tm_tm, tm_tx = 1.0*TM_M, tm_TX = 60.0*TM_M;
static void tm_init(int _tm_Rep, int _tm_verbose) { tm_verbose = _tm_verbose; if(_tm_Rep) tm_Rep = _tm_Rep; }
#define TMBENCH(_name_, _func_, _len_) do { if(tm_verbose>=1) printf("%s ", _name_?_name_:#_func_);\
TMBEG(tm_Rep) _func_; TMEND(_len_); \
double dm = tm_tm, dr = tm_rm; \
if(tm_verbose>2) printf("%8.*f \b\b\b\b\b", TM_PRE, TMBS(_len_, dm/dr) );\
else if(tm_verbose) printf("%8.*f ", TM_PRE, TMBS(_len_, dm/dr) );\
} while(0)
// second TMBENCH. Example: use TMBENCH for encoding and TMBENCH2 for decoding
#define TMBENCH2(_name_, _func_, _len_) do { \
TMBEG(tm_Rep2) _func_; TMEND(_len_);\
double dm = tm_tm, dr = tm_rm; if(tm_verbose>2) printf("%8.*f \b\b\b\b\b", TM_PRE,TMBS(_len_, dm/dr) );else if(tm_verbose) printf("%8.*f ", TM_PRE,TMBS(_len_, dm/dr) );\
if(tm_verbose>=1) printf("%s ", _name_?_name_:#_func_);\
} while(0)
// Check
#define TMBENCHT(_name_,_func_, _len_, _res_) do { \
TMBEG(tm_Rep) \
if(_func_ != _res_) { printf("ERROR: %lld != %lld", (long long)_func_, (long long)_res_ ); exit(0); };\
TMEND(_len_);\
if(tm_verbose>2) printf("%8.*f \b\b\b\b\b", TM_PRE, TMBS(_len_,(double)tm_tm/(double)tm_rm) );\
if(tm_verbose>1) printf("%s ", _name_?_name_:#_func_ );\
} while(0)
static void pr(unsigned l, unsigned n) {
double r = (double)l*100.0/n;
if(r>0.1) printf("%10u %6.2f%% ", l, r);
else if(r>0.01) printf("%10u %7.3f%% ", l, r);
else printf("%10u %8.4f%% ", l, r); fflush(stdout);
}
//----------------------------------------------------------------------------------------------------------------------------------
#define Kb (1u<<10)
#define Mb (1u<<20)
#define Gb (1u<<30)
#define KB 1000
#define MB 1000000
#define GB 1000000000
static unsigned argtoi(char *s, unsigned def) {
char *p;
unsigned n = strtol(s, &p, 10),f = 1;
switch(*p) {
case 'K': f = KB; break;
case 'M': f = MB; break;
case 'G': f = GB; break;
case 'k': f = Kb; break;
case 'm': f = Mb; break;
case 'g': f = Gb; break;
case 'B': return n; break;
case 'b': def = 0;
default: if(!def) return n>=32?0xffffffffu:(1u << n); f = def;
}
return n*f;
}
static uint64_t argtol(char *s) {
char *p;
uint64_t n = strtol(s, &p, 10),f=1;
switch(*p) {
case 'K': f = KB; break;
case 'M': f = MB; break;
case 'G': f = GB; break;
case 'k': f = Kb; break;
case 'm': f = Mb; break;
case 'g': f = Gb; break;
case 'B': return n; break;
case 'b': return 1u << n;
default: f = MB;
}
return n*f;
}
static uint64_t argtot(char *s) {
char *p;
uint64_t n = strtol(s, &p, 10),f=1;
switch(*p) {
case 'h': f = 3600000; break;
case 'm': f = 60000; break;
case 's': f = 1000; break;
case 'M': f = 1; break;
default: f = 1000;
}
return n*f;
}
static void memrcpy(unsigned char *out, unsigned char *in, unsigned n) { int i; for(i = 0; i < n; i++) out[i] = ~in[i]; }
================================================
FILE: turbob64.h
================================================
/**
Copyright (C) powturbo 2016-2023
SPDX-License-Identifier: GPL v3 License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- homepage : https://sites.google.com/site/powturbo/
- github : https://github.com/powturbo
- twitter : https://twitter.com/powturbo
- email : powturbo [_AT_] gmail [_DOT_] com
**/
// Turbo-Base64 - C/C++ include header
#ifndef _TURBOB64_H_
#define _TURBOB64_H_
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TB64_VERSION 100
//---------------------- Turbo-Base64 API functions ----------------------------------
// return the base64 buffer length after encoding
size_t tb64enclen(size_t inlen);
// return the original (after decoding) length for a given base64 encoded buffer
size_t tb64declen(const unsigned char *in, size_t inlen);
// Encode binary input 'in' buffer into base64 string 'out'
// with automatic cpu detection for avx2/sse4.1/scalar
// in : Input buffer to encode
// inlen : Length in bytes of input buffer
// out : Output buffer
// return value: Length of output buffer
// Remark : byte 'zero' is not written to end of output stream
// Caller must add 0 (out[outlen] = 0) for a null terminated string
size_t tb64enc(const unsigned char *in, size_t inlen, unsigned char *out);
// Decode base64 input 'in' buffer into binary buffer 'out'
// in : input buffer to decode
// inlen : length in bytes of input buffer
// out : output buffer
// return value: >0 output buffer length
// 0 Error (invalid base64 input or input length = 0)
size_t tb64dec(const unsigned char *in, size_t inlen, unsigned char *out);
//------ Direct call to tb64enc + tb64dec ---------------------------------------
// Direct call to tb64enc + tb64dec saving a function call + a check instruction
// call tb64ini, then call _tb64e(in, inlen, out) or _tb64d(in, inlen, out)
typedef size_t (*TB64FUNC)(const unsigned char *__restrict in, size_t n, unsigned char *__restrict out);
extern TB64FUNC _tb64e;
extern TB64FUNC _tb64d;
//---------------------- base64 Internal functions ------------------------------
// Base64 output length after encoding
#define TB64ENCLEN(_n_) ((_n_ + 2)/3 * 4)
// Memory efficient (small lookup tables) scalar but (slower) version
size_t tb64senc( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
size_t tb64sdec( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
// Fast scalar
size_t tb64xenc( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
size_t tb64xdec( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
// ssse3
size_t tb64v128enc( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
size_t tb64v128dec( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
// avx
size_t tb64v128aenc( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
size_t tb64v128adec( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
// avx2
size_t tb64v256enc( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
size_t tb64v256dec( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
// avx512_vbmi
size_t tb64v512enc( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
size_t tb64v512dec( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);
// detect cpu && set the default run time functions for tb64enc/tb64dec
// isshort = 0 : default
// isshort > 0 : set optimized short strings version (actually only avx2)
void tb64ini(unsigned id, unsigned isshort);
//------- optimized functions for short strings only --------------------------
// - decoding without checking
// - can read beyond the input buffer end,
// therefore input buffer size must be 32 bytes larger than input length
size_t _tb64v256enc(const unsigned char *in, size_t inlen, unsigned char *out);
size_t _tb64v256dec(const unsigned char *in, size_t inlen, unsigned char *out);
//------- CPU instruction set ----------------------
// cpuisa = 0: return current simd set,
// cpuisa != 0: set simd set 0:scalar, 0x33:sse2, 0x60:avx2
unsigned cpuini(unsigned cpuisa);
// convert simd set to string "sse3", "ssse3", "sse4.1", "avx", "avx2", "neon",...
// Ex.: printf("current cpu set=%s\n", cpustr(cpuini(0)) );
char *cpustr(unsigned cpuisa);
#ifdef __cplusplus
}
#endif
#endif
================================================
FILE: turbob64_.h
================================================
/**
Copyright (C) powturbo 2016-2023
SPDX-License-Identifier: GPL v3 License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- homepage : https://sites.google.com/site/powturbo/
- github : https://github.com/powturbo
- twitter : https://twitter.com/powturbo
- email : powturbo [_AT_] gmail [_DOT_] com
**/
// Turbo-Base64: internal include
//#define UA_MEMCPY // Force replace unaligned stores with memcpy (see "conf.h")
#include "conf.h"
size_t _tb64xdec( const unsigned char *in, size_t inlen, unsigned char *out);
size_t tb64memcpy(const unsigned char *in, size_t inlen, unsigned char *out); // testing only
#define PREFETCH(_ip_,_i_,_rw_) __builtin_prefetch(_ip_+(_i_),_rw_)
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define BSWAP32(a) a
#define BSWAP64(a) a
#else
#define BSWAP32(a) bswap32(a)
#define BSWAP64(a) bswap64(a)
#endif
#ifdef NB64CHECK // decoding without checking
#define CHECK0(a)
#define CHECK1(a)
#else // decoding incl. checking
#define CHECK0(a) a
#ifdef B64CHECK // Full check
#define CHECK1(a) a
#else
#define CHECK1(a)
#endif
#endif
//------- Encode: scalar helper macros & functions ----------------------------------------------------------
extern unsigned char tb64lutse[];
#define SU32(_u_) (tb64lutse[(_u_>> 8) & 0x3f] << 24 |\
tb64lutse[(_u_>>14) & 0x3f] << 16 |\
tb64lutse[(_u_>>20) & 0x3f] << 8 |\
tb64lutse[(_u_>>26) & 0x3f])
#define ETAIL()\
unsigned _l = (in+inlen) - ip; AS(ip <= in+inlen, "ETAIL:Fatal %d\n", (unsigned)(ip - (in+inlen)));\
if(_l == 3) { unsigned _u = ip[0]<<24 | ip[1]<<16 | ip[2]<<8; stou32(op, SU32(_u)); op+=4; }\
else if(_l == 2) { op[0] = tb64lutse[(ip[0]>>2)&0x3f]; op[1] = tb64lutse[(ip[0] & 0x3) << 4 | (ip[1] & 0xf0) >> 4]; op[2] = tb64lutse[(ip[1] & 0xf) << 2]; op[3] = '='; op+=4; }\
else if(_l) { op[0] = tb64lutse[(ip[0]>>2)&0x3f]; op[1] = tb64lutse[(ip[0] & 0x3) << 4], op[2] = '='; op[3] = '='; op+=4; }
extern const unsigned short tb64lute[];
#define XU32(_u_) (tb64lute[(_u_ >> 8) & 0xfff] << 16 |\
tb64lute[ _u_ >> 20])
#define EXTAIL(_n_) for(; op < out_-4; op += 4, ip += 3) { unsigned _u = BSWAP32(ctou32(ip)); stou32(op, XU32(_u)); } ETAIL()
//------- Decode: scalar helper macros & functions ----------------------------------------------------------
extern const unsigned tb64lutd0[];
extern const unsigned tb64lutd1[];
extern const unsigned tb64lutd2[];
extern const unsigned tb64lutd3[];
#define DU32(_u_) (tb64lutd0[(unsigned char)(_u_ )] |\
tb64lutd1[(unsigned char)(_u_>> 8)] |\
tb64lutd2[(unsigned char)(_u_>> 16)] |\
tb64lutd3[ _u_>> 24 ] )
#define DXTAILC(ip,out,op,_check_) {\
if(ip[3] != '=') { unsigned u = ctou32(ip); u = DU32(u); op[0] = u; op[1] = u>>8; op[2] = u>>16; op+=3; _check_; } /*4->3*/\
else if(ip[2] != '=') { unsigned u = tb64lutd0[ip[0]] | tb64lutd1[ip[1]] | tb64lutd2[ip[2]]; op[0] = u; op[1] = u>>8; op+=2; _check_; } /*3->2*/\
else if(ip[1] != '=') { unsigned u = tb64lutd0[ip[0]] | tb64lutd1[ip[1]]; *op++ = u; _check_; } /*2->1*/\
else { unsigned u = tb64lutd0[ip[0]]; *op++ = u; _check_; } /*1->1*/\
}
#define DXTAIL(ip,out,op) {\
if(ip[3] != '=') { unsigned u = ctou32(ip); u = DU32(u); op[0] = u; op[1] = u>>8; op[2] = u>>16; op+=3;} /*4->3*/\
else if(ip[2] != '=') { uint16_t u = tb64lutd0[ip[0]] | tb64lutd1[ip[1]] | tb64lutd2[ip[2]]; op[0] = u; op[1] = u>>8; op+=2; } /*3->2*/\
else if(ip[1] != '=') { *op++ = tb64lutd0[ip[0]] | tb64lutd1[ip[1]]; } /*2->1*/\
else { *op++ = tb64lutd0[ip[0]]; } /*1->1*/\
}
static ALWAYS_INLINE size_t _tb64xd(const unsigned char *in, size_t inlen, unsigned char *out) {
const unsigned char *ip = in, *in_ = in+inlen;
unsigned char *op = out;
#ifdef B64CHECK
unsigned cu = 0;
for(; ip < in_-4; ip += 4, op += 3) { unsigned u = ctou32(ip); u = DU32(u); stou32(op, u); cu |= u; }
DXTAILC(ip,out,op, cu |= u);
return (cu == -1)?0:(op-out);
#else
for(; ip < in_-4; ip += 4, op += 3) { unsigned u = ctou32(ip); u = DU32(u); stou32(op, u); }
DXTAIL(ip,out,op)
return op - out;
#endif
}
//------- SSE helper macros & functions ----------------------------------------------------------
#if defined(__SSSE3__)
#include <tmmintrin.h>
#define BITPACK128V8_6(v, cpv) {\
const __m128i merge_ab_bc = _mm_maddubs_epi16(v, _mm_set1_epi32(0x01400140)); /*dec_reshuffle: https://arxiv.org/abs/1704.00605 P.17*/\
v = _mm_madd_epi16(merge_ab_bc, _mm_set1_epi32(0x00011000));\
v = _mm_shuffle_epi8(v, cpv);\
}
#define BITMAP128V8_6(iv, shifted, delta_asso, delta_values, ov) { /*map 8-bits ascii to 6-bits binary*/\
shifted = _mm_srli_epi32(iv, 3);\
const __m128i delta_hash = _mm_avg_epu8(_mm_shuffle_epi8(delta_asso, iv), shifted);\
ov = _mm_add_epi8(_mm_shuffle_epi8(delta_values, delta_hash), iv);\
}
#define B64CHK128(iv, shifted, check_asso, check_values, vx) {\
const __m128i check_hash = _mm_avg_epu8( _mm_shuffle_epi8(check_asso, iv), shifted);\
const __m128i chk = _mm_adds_epi8(_mm_shuffle_epi8(check_values, check_hash), iv);\
vx = _mm_or_si128(vx, chk);\
}
static ALWAYS_INLINE __m128i bitmap128v8_6(const __m128i v) { /*map 8-bits ascii to 6-bits binary*/
const __m128i offsets = _mm_set_epi8( 0, 0,-16,-19, -4,-4,-4,-4, -4,-4,-4,-4, -4,-4,71,65);
__m128i vidx = _mm_subs_epu8(v, _mm_set1_epi8(51));
vidx = _mm_sub_epi8(vidx, _mm_cmpgt_epi8(v, _mm_set1_epi8(25)));
return _mm_add_epi8(v, _mm_shuffle_epi8(offsets, vidx));
}
static ALWAYS_INLINE __m128i bitunpack128v8_6(__m128i v) { /* unpack 6 -> 8 */
__m128i va = _mm_mulhi_epu16(_mm_and_si128(v, _mm_set1_epi32(0x0fc0fc00)), _mm_set1_epi32(0x04000040));
__m128i vb = _mm_mullo_epi16(_mm_and_si128(v, _mm_set1_epi32(0x003f03f0)), _mm_set1_epi32(0x01000010));
return _mm_or_si128(va, vb);
}
#endif
//------- avx2 helper macros & functions ----------------------------------------------------------
#ifdef __AVX2__
static ALWAYS_INLINE __m256i bitmap256v8_6(const __m256i v) { //map 8-bits ascii to 6-bits binary (https://arxiv.org/abs/1704.00605)
__m256i vidx = _mm256_subs_epu8(v, _mm256_set1_epi8(51));
vidx = _mm256_sub_epi8(vidx, _mm256_cmpgt_epi8(v, _mm256_set1_epi8(25)));
const __m256i offsets = _mm256_set_epi8(0, 0, -16, -19, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, 71, 65,
0, 0, -16, -19, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, 71, 65);
return _mm256_add_epi8(v, _mm256_shuffle_epi8(offsets, vidx));
}
static ALWAYS_INLINE __m256i bitunpack256v8_6(__m256i v) { //https://arxiv.org/abs/1704.00605 p.12
__m256i va = _mm256_mulhi_epu16(_mm256_and_si256(v, _mm256_set1_epi32(0x0fc0fc00)), _mm256_set1_epi32(0x04000040));
__m256i vb = _mm256_mullo_epi16(_mm256_and_si256(v, _mm256_set1_epi32(0x003f03f0)), _mm256_set1_epi32(0x01000010));
return _mm256_or_si256(va, vb);
}
#endif
================================================
FILE: turbob64c.c
================================================
/**
Copyright (C) powturbo 2016-2023
SPDX-License-Identifier: GPL v3 License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- homepage : https://sites.google.com/site/powturbo/
- github : https://github.com/powturbo
- twitter : https://twitter.com/powturbo
- email : powturbo [_AT_] gmail [_DOT_] com
**/
// Turbo-Base64: Scalar encode
#include "turbob64_.h"
#include "turbob64.h"
size_t tb64enclen(size_t n) { return TB64ENCLEN(n); }
//----------------------- small 64 bytes lut encoding ---------------------------------------------------------------------------------------------
unsigned char tb64lutse[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
#define ES(_i_) { \
unsigned v = ctou32(ip+3+_i_*6 ); u = BSWAP32(u); stou32(op+_i_*8, SU32(u));\
u = ctou32(ip+3+_i_*6+3); v = BSWAP32(v); stou32(op+_i_*8+4, SU32(v));\
}
size_t tb64senc(const unsigned char *in, size_t inlen, unsigned char *out) {
const unsigned char *ip = in;
unsigned char *op = out;
size_t outlen = TB64ENCLEN(inlen);
if(outlen > 4+8) {
unsigned u = ctou32(ip);
for(; op < (out+outlen)-(4+64); op += 64, ip += (64/4)*3) { ES(0); ES(1); ES( 2); ES( 3); ES( 4); ES( 5); ES( 6); ES( 7); PREFETCH(ip,128, 0); }
for(; op < (out+outlen)-(4+ 8); op += 8, ip += ( 8/4)*3) ES(0);
}
for(; op < (out+outlen)-4; op += 4, ip += 3) { unsigned _u = BSWAP32(ctou32(ip)); stou32(op, SU32(_u)); }
ETAIL();
return outlen;
}
//---------------------- Fast encoding with 4k LUT --------------------------------------------------------------------------------------------------
const unsigned short tb64lute[1<<12] = {
0x4141,0x4241,0x4341,0x4441,0x4541,0x4641,0x4741,0x4841,0x4941,0x4a41,0x4b41,0x4c41,0x4d41,0x4e41,0x4f41,0x5041,
0x5141,0x5241,0x5341,0x5441,0x5541,0x5641,0x5741,0x5841,0x5941,0x5a41,0x6141,0x6241,0x6341,0x6441,0x6541,0x6641,
0x6741,0x6841,0x6941,0x6a41,0x6b41,0x6c41,0x6d41,0x6e41,0x6f41,0x7041,0x7141,0x7241,0x7341,0x7441,0x7541,0x7641,
0x7741,0x7841,0x7941,0x7a41,0x3041,0x3141,0x3241,0x3341,0x3441,0x3541,0x3641,0x3741,0x3841,0x3941,0x2b41,0x2f41,
0x4142,0x4242,0x4342,0x4442,0x4542,0x4642,0x4742,0x4842,0x4942,0x4a42,0x4b42,0x4c42,0x4d42,0x4e42,0x4f42,0x5042,
0x5142,0x5242,0x5342,0x5442,0x5542,0x5642,0x5742,0x5842,0x5942,0x5a42,0x6142,0x6242,0x6342,0x6442,0x6542,0x6642,
0x6742,0x6842,0x6942,0x6a42,0x6b42,0x6c42,0x6d42,0x6e42,0x6f42,0x7042,0x7142,0x7242,0x7342,0x7442,0x7542,0x7642,
0x7742,0x7842,0x7942,0x7a42,0x3042,0x3142,0x3242,0x3342,0x3442,0x3542,0x3642,0x3742,0x3842,0x3942,0x2b42,0x2f42,
0x4143,0x4243,0x4343,0x4443,0x4543,0x4643,0x4743,0x4843,0x4943,0x4a43,0x4b43,0x4c43,0x4d43,0x4e43,0x4f43,0x5043,
0x5143,0x5243,0x5343,0x5443,0x5543,0x5643,0x5743,0x5843,0x5943,0x5a43,0x6143,0x6243,0x6343,0x6443,0x6543,0x6643,
0x6743,0x6843,0x6943,0x6a43,0x6b43,0x6c43,0x6d43,0x6e43,0x6f43,0x7043,0x7143,0x7243,0x7343,0x7443,0x7543,0x7643,
0x7743,0x7843,0x7943,0x7a43,0x3043,0x3143,0x3243,0x3343,0x3443,0x3543,0x3643,0x3743,0x3843,0x3943,0x2b43,0x2f43,
0x4144,0x4244,0x4344,0x4444,0x4544,0x4644,0x4744,0x4844,0x4944,0x4a44,0x4b44,0x4c44,0x4d44,0x4e44,0x4f44,0x5044,
0x5144,0x5244,0x5344,0x5444,0x5544,0x5644,0x5744,0x5844,0x5944,0x5a44,0x6144,0x6244,0x6344,0x6444,0x6544,0x6644,
0x6744,0x6844,0x6944,0x6a44,0x6b44,0x6c44,0x6d44,0x6e44,0x6f44,0x7044,0x7144,0x7244,0x7344,0x7444,0x7544,0x7644,
0x7744,0x7844,0x7944,0x7a44,0x3044,0x3144,0x3244,0x3344,0x3444,0x3544,0x3644,0x3744,0x3844,0x3944,0x2b44,0x2f44,
0x4145,0x4245,0x4345,0x4445,0x4545,0x4645,0x4745,0x4845,0x4945,0x4a45,0x4b45,0x4c45,0x4d45,0x4e45,0x4f45,0x5045,
0x5145,0x5245,0x5345,0x5445,0x5545,0x5645,0x5745,0x5845,0x5945,0x5a45,0x6145,0x6245,0x6345,0x6445,0x6545,0x6645,
0x6745,0x6845,0x6945,0x6a45,0x6b45,0x6c45,0x6d45,0x6e45,0x6f45,0x7045,0x7145,0x7245,0x7345,0x7445,0x7545,0x7645,
0x7745,0x7845,0x7945,0x7a45,0x3045,0x3145,0x3245,0x3345,0x3445,0x3545,0x3645,0x3745,0x3845,0x3945,0x2b45,0x2f45,
0x4146,0x4246,0x4346,0x4446,0x4546,0x4646,0x4746,0x4846,0x4946,0x4a46,0x4b46,0x4c46,0x4d46,0x4e46,0x4f46,0x5046,
0x5146,0x5246,0x5346,0x5446,0x5546,0x5646,0x5746,0x5846,0x5946,0x5a46,0x6146,0x6246,0x6346,0x6446,0x6546,0x6646,
0x6746,0x6846,0x6946,0x6a46,0x6b46,0x6c46,0x6d46,0x6e46,0x6f46,0x7046,0x7146,0x7246,0x7346,0x7446,0x7546,0x7646,
0x7746,0x7846,0x7946,0x7a46,0x3046,0x3146,0x3246,0x3346,0x3446,0x3546,0x3646,0x3746,0x3846,0x3946,0x2b46,0x2f46,
0x4147,0x4247,0x4347,0x4447,0x4547,0x4647,0x4747,0x4847,0x4947,0x4a47,0x4b47,0x4c47,0x4d47,0x4e47,0x4f47,0x5047,
0x5147,0x5247,0x5347,0x5447,0x5547,0x5647,0x5747,0x5847,0x5947,0x5a47,0x6147,0x6247,0x6347,0x6447,0x6547,0x6647,
0x6747,0x6847,0x6947,0x6a47,0x6b47,0x6c47,0x6d47,0x6e47,0x6f47,0x7047,0x7147,0x7247,0x7347,0x7447,0x7547,0x7647,
0x7747,0x7847,0x7947,0x7a47,0x3047,0x3147,0x3247,0x3347,0x3447,0x3547,0x3647,0x3747,0x3847,0x3947,0x2b47,0x2f47,
0x4148,0x4248,0x4348,0x4448,0x4548,0x4648,0x4748,0x4848,0x4948,0x4a48,0x4b48,0x4c48,0x4d48,0x4e48,0x4f48,0x5048,
0x5148,0x5248,0x5348,0x5448,0x5548,0x5648,0x5748,0x5848,0x5948,0x5a48,0x6148,0x6248,0x6348,0x6448,0x6548,0x6648,
0x6748,0x6848,0x6948,0x6a48,0x6b48,0x6c48,0x6d48,0x6e48,0x6f48,0x7048,0x7148,0x7248,0x7348,0x7448,0x7548,0x7648,
0x7748,0x7848,0x7948,0x7a48,0x3048,0x3148,0x3248,0x3348,0x3448,0x3548,0x3648,0x3748,0x3848,0x3948,0x2b48,0x2f48,
0x4149,0x4249,0x4349,0x4449,0x4549,0x4649,0x4749,0x4849,0x4949,0x4a49,0x4b49,0x4c49,0x4d49,0x4e49,0x4f49,0x5049,
0x5149,0x5249,0x5349,0x5449,0x5549,0x5649,0x5749,0x5849,0x5949,0x5a49,0x6149,0x6249,0x6349,0x6449,0x6549,0x6649,
0x6749,0x6849,0x6949,0x6a49,0x6b49,0x6c49,0x6d49,0x6e49,0x6f49,0x7049,0x7149,0x7249,0x7349,0x7449,0x7549,0x7649,
0x7749,0x7849,0x7949,0x7a49,0x3049,0x3149,0x3249,0x3349,0x3449,0x3549,0x3649,0x3749,0x3849,0x3949,0x2b49,0x2f49,
0x414a,0x424a,0x434a,0x444a,0x454a,0x464a,0x474a,0x484a,0x494a,0x4a4a,0x4b4a,0x4c4a,0x4d4a,0x4e4a,0x4f4a,0x504a,
0x514a,0x524a,0x534a,0x544a,0x554a,0x564a,0x574a,0x584a,0x594a,0x5a4a,0x614a,0x624a,0x634a,0x644a,0x654a,0x664a,
0x674a,0x684a,0x694a,0x6a4a,0x6b4a,0x6c4a,0x6d4a,0x6e4a,0x6f4a,0x704a,0x714a,0x724a,0x734a,0x744a,0x754a,0x764a,
0x774a,0x784a,0x794a,0x7a4a,0x304a,0x314a,0x324a,0x334a,0x344a,0x354a,0x364a,0x374a,0x384a,0x394a,0x2b4a,0x2f4a,
0x414b,0x424b,0x434b,0x444b,0x454b,0x464b,0x474b,0x484b,0x494b,0x4a4b,0x4b4b,0x4c4b,0x4d4b,0x4e4b,0x4f4b,0x504b,
0x514b,0x524b,0x534b,0x544b,0x554b,0x564b,0x574b,0x584b,0x594b,0x5a4b,0x614b,0x624b,0x634b,0x644b,0x654b,0x664b,
0x674b,0x684b,0x694b,0x6a4b,0x6b4b,0x6c4b,0x6d4b,0x6e4b,0x6f4b,0x704b,0x714b,0x724b,0x734b,0x744b,0x754b,0x764b,
0x774b,0x784b,0x794b,0x7a4b,0x304b,0x314b,0x324b,0x334b,0x344b,0x354b,0x364b,0x374b,0x384b,0x394b,0x2b4b,0x2f4b,
0x414c,0x424c,0x434c,0x444c,0x454c,0x464c,0x474c,0x484c,0x494c,0x4a4c,0x4b4c,0x4c4c,0x4d4c,0x4e4c,0x4f4c,0x504c,
0x514c,0x524c,0x534c,0x544c,0x554c,0x564c,0x574c,0x584c,0x594c,0x5a4c,0x614c,0x624c,0x634c,0x644c,0x654c,0x664c,
0x674c,0x684c,0x694c,0x6a4c,0x6b4c,0x6c4c,0x6d4c,0x6e4c,0x6f4c,0x704c,0x714c,0x724c,0x734c,0x744c,0x754c,0x764c,
0x774c,0x784c,0x794c,0x7a4c,0x304c,0x314c,0x324c,0x334c,0x344c,0x354c,0x364c,0x374c,0x384c,0x394c,0x2b4c,0x2f4c,
0x414d,0x424d,0x434d,0x444d,0x454d,0x464d,0x474d,0x484d,0x494d,0x4a4d,0x4b4d,0x4c4d,0x4d4d,0x4e4d,0x4f4d,0x504d,
0x514d,0x524d,0x534d,0x544d,0x554d,0x564d,0x574d,0x584d,0x594d,0x5a4d,0x614d,0x624d,0x634d,0x644d,0x654d,0x664d,
0x674d,0x684d,0x694d,0x6a4d,0x6b4d,0x6c4d,0x6d4d,0x6e4d,0x6f4d,0x704d,0x714d,0x724d,0x734d,0x744d,0x754d,0x764d,
0x774d,0x784d,0x794d,0x7a4d,0x304d,0x314d,0x324d,0x334d,0x344d,0x354d,0x364d,0x374d,0x384d,0x394d,0x2b4d,0x2f4d,
0x414e,0x424e,0x434e,0x444e,0x454e,0x464e,0x474e,0x484e,0x494e,0x4a4e,0x4b4e,0x4c4e,0x4d4e,0x4e4e,0x4f4e,0x504e,
0x514e,0x524e,0x534e,0x544e,0x554e,0x564e,0x574e,0x584e,0x594e,0x5a4e,0x614e,0x624e,0x634e,0x644e,0x654e,0x664e,
0x674e,0x684e,0x694e,0x6a4e,0x6b4e,0x6c4e,0x6d4e,0x6e4e,0x6f4e,0x704e,0x714e,0x724e,0x734e,0x744e,0x754e,0x764e,
0x774e,0x784e,0x794e,0x7a4e,0x304e,0x314e,0x324e,0x334e,0x344e,0x354e,0x364e,0x374e,0x384e,0x394e,0x2b4e,0x2f4e,
0x414f,0x424f,0x434f,0x444f,0x454f,0x464f,0x474f,0x484f,0x494f,0x4a4f,0x4b4f,0x4c4f,0x4d4f,0x4e4f,0x4f4f,0x504f,
0x514f,0x524f,0x534f,0x544f,0x554f,0x564f,0x574f,0x584f,0x594f,0x5a4f,0x614f,0x624f,0x634f,0x644f,0x654f,0x664f,
0x674f,0x684f,0x694f,0x6a4f,0x6b4f,0x6c4f,0x6d4f,0x6e4f,0x6f4f,0x704f,0x714f,0x724f,0x734f,0x744f,0x754f,0x764f,
0x774f,0x784f,0x794f,0x7a4f,0x304f,0x314f,0x324f,0x334f,0x344f,0x354f,0x364f,0x374f,0x384f,0x394f,0x2b4f,0x2f4f,
0x4150,0x4250,0x4350,0x4450,0x4550,0x4650,0x4750,0x4850,0x4950,0x4a50,0x4b50,0x4c50,0x4d50,0x4e50,0x4f50,0x5050,
0x5150,0x5250,0x5350,0x5450,0x5550,0x5650,0x5750,0x5850,0x5950,0x5a50,0x6150,0x6250,0x6350,0x6450,0x6550,0x6650,
0x6750,0x6850,0x6950,0x6a50,0x6b50,0x6c50,0x6d50,0x6e50,0x6f50,0x7050,0x7150,0x7250,0x7350,0x7450,0x7550,0x7650,
0x7750,0x7850,0x7950,0x7a50,0x3050,0x3150,0x3250,0x3350,0x3450,0x3550,0x3650,0x3750,0x3850,0x3950,0x2b50,0x2f50,
0x4151,0x4251,0x4351,0x4451,0x4551,0x4651,0x4751,0x4851,0x4951,0x4a51,0x4b51,0x4c51,0x4d51,0x4e51,0x4f51,0x5051,
0x5151,0x5251,0x5351,0x5451,0x5551,0x5651,0x5751,0x5851,0x5951,0x5a51,0x6151,0x6251,0x6351,0x6451,0x6551,0x6651,
0x6751,0x6851,0x6951,0x6a51,0x6b51,0x6c51,0x6d51,0x6e51,0x6f51,0x7051,0x7151,0x7251,0x7351,0x7451,0x7551,0x7651,
0x7751,0x7851,0x7951,0x7a51,0x3051,0x3151,0x3251,0x3351,0x3451,0x3551,0x3651,0x3751,0x3851,0x3951,0x2b51,0x2f51,
0x4152,0x4252,0x4352,0x4452,0x4552,0x4652,0x4752,0x4852,0x4952,0x4a52,0x4b52,0x4c52,0x4d52,0x4e52,0x4f52,0x5052,
0x5152,0x5252,0x5352,0x5452,0x5552,0x5652,0x5752,0x5852,0x5952,0x5a52,0x6152,0x6252,0x6352,0x6452,0x6552,0x6652,
0x6752,0x6852,0x6952,0x6a52,0x6b52,0x6c52,0x6d52,0x6e52,0x6f52,0x7052,0x7152,0x7252,0x7352,0x7452,0x7552,0x7652,
0x7752,0x7852,0x7952,0x7a52,0x3052,0x3152,0x3252,0x3352,0x3452,0x3552,0x3652,0x3752,0x3852,0x3952,0x2b52,0x2f52,
0x4153,0x4253,0x4353,0x4453,0x4553,0x4653,0x4753,0x4853,0x4953,0x4a53,0x4b53,0x4c53,0x4d53,0x4e53,0x4f53,0x5053,
0x5153,0x5253,0x5353,0x5453,0x5553,0x5653,0x5753,0x5853,0x5953,0x5a53,0x6153,0x6253,0x6353,0x6453,0x6553,0x6653,
0x6753,0x6853,0x6953,0x6a53,0x6b53,0x6c53,0x6d53,0x6e53,0x6f53,0x7053,0x7153,0x7253,0x7353,0x7453,0x7553,0x7653,
0x7753,0x7853,0x7953,0x7a53,0x3053,0x3153,0x3253,0x3353,0x3453,0x3553,0x3653,0x3753,0x3853,0x3953,0x2b53,0x2f53,
0x4154,0x4254,0x4354,0x4454,0x4554,0x4654,0x4754,0x4854,0x4954,0x4a54,0x4b54,0x4c54,0x4d54,0x4e54,0x4f54,0x5054,
0x5154,0x5254,0x5354,0x5454,0x5554,0x5654,0x5754,0x5854,0x5954,0x5a54,0x6154,0x6254,0x6354,0x6454,0x6554,0x6654,
0x6754,0x6854,0x6954,0x6a54,0x6b54,0x6c54,0x6d54,0x6e54,0x6f54,0x7054,0x7154,0x7254,0x7354,0x7454,0x7554,0x7654,
0x7754,0x7854,0x7954,0x7a54,0x3054,0x3154,0x3254,0x3354,0x3454,0x3554,0x3654,0x3754,0x3854,0x3954,0x2b54,0x2f54,
0x4155,0x4255,0x4355,0x4455,0x4555,0x4655,0x4755,0x4855,0x4955,0x4a55,0x4b55,0x4c55,0x4d55,0x4e55,0x4f55,0x5055,
0x5155,0x5255,0x5355,0x5455,0x5555,0x5655,0x5755,0x5855,0x5955,0x5a55,0x6155,0x6255,0x6355,0x6455,0x6555,0x6655,
0x6755,0x6855,0x6955,0x6a55,0x6b55,0x6c55,0x6d55,0x6e55,0x6f55,0x7055,0x7155,0x7255,0x7355,0x7455,0x7555,0x7655,
0x7755,0x7855,0x7955,0x7a55,0x3055,0x3155,0x3255,0x3355,0x3455,0x3555,0x3655,0x3755,0x3855,0x3955,0x2b55,0x2f55,
0x4156,0x4256,0x4356,0x4456,0x4556,0x4656,0x4756,0x4856,0x4956,0x4a56,0x4b56,0x4c56,0x4d56,0x4e56,0x4f56,0x5056,
0x5156,0x5256,0x5356,0x5456,0x5556,0x5656,0x5756,0x5856,0x5956,0x5a56,0x6156,0x6256,0x6356,0x6456,0x6556,0x6656,
0x6756,0x6856,0x6956,0x6a56,0x6b56,0x6c56,0x6d56,0x6e56,0x6f56,0x7056,0x7156,0x7256,0x7356,0x7456,0x7556,0x7656,
0x7756,0x7856,0x7956,0x7a56,0x3056,0x3156,0x3256,0x3356,0x3456,0x3556,0x3656,0x3756,0x3856,0x3956,0x2b56,0x2f56,
0x4157,0x4257,0x4357,0x4457,0x4557,0x4657,0x4757,0x4857,0x4957,0x4a57,0x4b57,0x4c57,0x4d57,0x4e57,0x4f57,0x5057,
0x5157,0x5257,0x5357,0x5457,0x5557,0x5657,0x5757,0x5857,0x5957,0x5a57,0x6157,0x6257,0x6357,0x6457,0x6557,0x6657,
0x6757,0x6857,0x6957,0x6a57,0x6b57,0x6c57,0x6d57,0x6e57,0x6f57,0x7057,0x7157,0x7257,0x7357,0x7457,0x7557,0x7657,
0x7757,0x7857,0x7957,0x7a57,0x3057,0x3157,0x3257,0x3357,0x3457,0x3557,0x3657,0x3757,0x3857,0x3957,0x2b57,0x2f57,
0x4158,0x4258,0x4358,0x4458,0x4558,0x4658,0x4758,0x4858,0x4958,0x4a58,0x4b58,0x4c58,0x4d58,0x4e58,0x4f58,0x5058,
0x5158,0x5258,0x5358,0x5458,0x5558,0x5658,0x5758,0x5858,0x5958,0x5a58,0x6158,0x6258,0x6358,0x6458,0x6558,0x6658,
0x6758,0x6858,0x6958,0x6a58,0x6b58,0x6c58,0x6d58,0x6e58,0x6f58,0x7058,0x7158,0x7258,0x7358,0x7458,0x7558,0x7658,
0x7758,0x7858,0x7958,0x7a58,0x3058,0x3158,0x3258,0x3358,0x3458,0x3558,0x3658,0x3758,0x3858,0x3958,0x2b58,0x2f58,
0x4159,0x4259,0x4359,0x4459,0x4559,0x4659,0x4759,0x4859,0x4959,0x4a59,0x4b59,0x4c59,0x4d59,0x4e59,0x4f59,0x5059,
0x5159,0x5259,0x5359,0x5459,0x5559,0x5659,0x5759,0x5859,0x5959,0x5a59,0x6159,0x6259,0x6359,0x6459,0x6559,0x6659,
0x6759,0x6859,0x6959,0x6a59,0x6b59,0x6c59,0x6d59,0x6e59,0x6f59,0x7059,0x7159,0x7259,0x7359,0x7459,0x7559,0x7659,
0x7759,0x7859,0x7959,0x7a59,0x3059,0x3159,0x3259,0x3359,0x3459,0x3559,0x3659,0x3759,0x3859,0x3959,0x2b59,0x2f59,
0x415a,0x425a,0x435a,0x445a,0x455a,0x465a,0x475a,0x485a,0x495a,0x4a5a,0x4b5a,0x4c5a,0x4d5a,0x4e5a,0x4f5a,0x505a,
0x515a,0x525a,0x535a,0x545a,0x555a,0x565a,0x575a,0x585a,0x595a,0x5a5a,0x615a,0x625a,0x635a,0x645a,0x655a,0x665a,
0x675a,0x685a,0x695a,0x6a5a,0x6b5a,0x6c5a,0x6d5a,0x6e5a,0x6f5a,0x705a,0x715a,0x725a,0x735a,0x745a,0x755a,0x765a,
0x775a,0x785a,0x795a,0x7a5a,0x305a,0x315a,0x325a,0x335a,0x345a,0x355a,0x365a,0x375a,0x385a,0x395a,0x2b5a,0x2f5a,
0x4161,0x4261,0x4361,0x4461,0x4561,0x4661,0x4761,0x4861,0x4961,0x4a61,0x4b61,0x4c61,0x4d61,0x4e61,0x4f61,0x5061,
0x5161,0x5261,0x5361,0x5461,0x5561,0x5661,0x5761,0x5861,0x5961,0x5a61,0x6161,0x6261,0x6361,0x6461,0x6561,0x6661,
0x6761,0x6861,0x6961,0x6a61,0x6b61,0x6c61,0x6d61,0x6e61,0x6f61,0x7061,0x7161,0x7261,0x7361,0x7461,0x7561,0x7661,
0x7761,0x7861,0x7961,0x7a61,0x3061,0x3161,0x3261,0x3361,0x3461,0x3561,0x3661,0x3761,0x3861,0x3961,0x2b61,0x2f61,
0x4162,0x4262,0x4362,0x4462,0x4562,0x4662,0x4762,0x4862,0x4962,0x4a62,0x4b62,0x4c62,0x4d62,0x4e62,0x4f62,0x5062,
0x5162,0x5262,0x5362,0x5462,0x5562,0x5662,0x5762,0x5862,0x5962,0x5a62,0x6162,0x6262,0x6362,0x6462,0x6562,0x6662,
0x6762,0x6862,0x6962,0x6a62,0x6b62,0x6c62,0x6d62,0x6e62,0x6f62,0x7062,0x7162,0x7262,0x7362,0x7462,0x7562,0x7662,
0x7762,0x7862,0x7962,0x7a62,0x3062,0x3162,0x3262,0x3362,0x3462,0x3562,0x3662,0x3762,0x3862,0x3962,0x2b62,0x2f62,
0x4163,0x4263,0x4363,0x4463,0x4563,0x4663,0x4763,0x4863,0x4963,0x4a63,0x4b63,0x4c63,0x4d63,0x4e63,0x4f63,0x5063,
0x5163,0x5263,0x5363,0x5463,0x5563,0x5663,0x5763,0x5863,0x5963,0x5a63,0x6163,0x6263,0x6363,0x6463,0x6563,0x6663,
0x6763,0x6863,0x6963,0x6a63,0x6b63,0x6c63,0x6d63,0x6e63,0x6f63,0x7063,0x7163,0x7263,0x7363,0x7463,0x7563,0x7663,
0x7763,0x7863,0x7963,0x7a63,0x3063,0x3163,0x3263,0x3363,0x3463,0x3563,0x3663,0x3763,0x3863,0x3963,0x2b63,0x2f63,
0x4164,0x4264,0x4364,0x4464,0x4564,0x4664,0x4764,0x4864,0x4964,0x4a64,0x4b64,0x4c64,0x4d64,0x4e64,0x4f64,0x5064,
0x5164,0x5264,0x5364,0x5464,0x5564,0x5664,0x5764,0x5864,0x5964,0x5a64,0x6164,0x6264,0x6364,0x6464,0x6564,0x6664,
0x6764,0x6864,0x6964,0x6a64,0x6b64,0x6c64,0x6d64,0x6e64,0x6f64,0x7064,0x7164,0x7264,0x7364,0x7464,0x7564,0x7664,
0x7764,0x7864,0x7964,0x7a64,0x3064,0x3164,0x3264,0x3364,0x3464,0x3564,0x3664,0x3764,0x3864,0x3964,0x2b64,0x2f64,
0x4165,0x4265,0x4365,0x4465,0x4565,0x4665,0x4765,0x4865,0x4965,0x4a65,0x4b65,0x4c65,0x4d65,0x4e65,0x4f65,0x5065,
0x5165,0x5265,0x5365,0x5465,0x5565,0x5665,0x5765,0x5865,0x5965,0x5a65,0x6165,0x6265,0x6365,0x6465,0x6565,0x6665,
0x6765,0x6865,0x6965,0x6a65,0x6b65,0x6c65,0x6d65,0x6e65,0x6f65,0x7065,0x7165,0x7265,0x7365,0x7465,0x7565,0x7665,
0x7765,0x7865,0x7965,0x7a65,0x3065,0x3165,0x3265,0x3365,0x3465,0x3565,0x3665,0x3765,0x3865,0x3965,0x2b65,0x2f65,
0x4166,0x4266,0x4366,0x4466,0x4566,0x4666,0x4766,0x4866,0x4966,0x4a66,0x4b66,0x4c66,0x4d66,0x4e66,0x4f66,0x5066,
0x5166,0x5266,0x5366,0x5466,0x5566,0x5666,0x5766,0x5866,0x5966,0x5a66,0x6166,0x6266,0x6366,0x6466,0x6566,0x6666,
0x6766,0x6866,0x6966,0x6a66,0x6b66,0x6c66,0x6d66,0x6e66,0x6f66,0x7066,0x7166,0x7266,0x7366,0x7466,0x7566,0x7666,
0x7766,0x7866,0x7966,0x7a66,0x3066,0x3166,0x3266,0x3366,0x3466,0x3566,0x3666,0x3766,0x3866,0x3966,0x2b66,0x2f66,
0x4167,0x4267,0x4367,0x4467,0x4567,0x4667,0x4767,0x4867,0x4967,0x4a67,0x4b67,0x4c67,0x4d67,0x4e67,0x4f67,0x5067,
0x5167,0x5267,0x5367,0x5467,0x5567,0x5667,0x5767,0x5867,0x5967,0x5a67,0x6167,0x6267,0x6367,0x6467,0x6567,0x6667,
0x6767,0x6867,0x6967,0x6a67,0x6b67,0x6c67,0x6d67,0x6e67,0x6f67,0x7067,0x7167,0x7267,0x7367,0x7467,0x7567,0x7667,
0x7767,0x7867,0x7967,0x7a67,0x3067,0x3167,0x3267,0x3367,0x3467,0x3567,0x3667,0x3767,0x3867,0x3967,0x2b67,0x2f67,
0x4168,0x4268,0x4368,0x4468,0x4568,0x4668,0x4768,0x4868,0x4968,0x4a68,0x4b68,0x4c68,0x4d68,0x4e68,0x4f68,0x5068,
0x5168,0x5268,0x5368,0x5468,0x5568,0x5668,0x5768,0x5868,0x5968,0x5a68,0x6168,0x6268,0x6368,0x6468,0x6568,0x6668,
0x6768,0x6868,0x6968,0x6a68,0x6b68,0x6c68,0x6d68,0x6e68,0x6f68,0x7068,0x7168,0x7268,0x7368,0x7468,0x7568,0x7668,
0x7768,0x7868,0x7968,0x7a68,0x3068,0x3168,0x3268,0x3368,0x3468,0x3568,0x3668,0x3768,0x3868,0x3968,0x2b68,0x2f68,
0x4169,0x4269,0x4369,0x4469,0x4569,0x4669,0x4769,0x4869,0x4969,0x4a69,0x4b69,0x4c69,0x4d69,0x4e69,0x4f69,0x5069,
0x5169,0x5269,0x5369,0x5469,0x5569,0x5669,0x5769,0x5869,0x5969,0x5a69,0x6169,0x6269,0x6369,0x6469,0x6569,0x6669,
0x6769,0x6869,0x6969,0x6a69,0x6b69,0x6c69,0x6d69,0x6e69,0x6f69,0x7069,0x7169,0x7269,0x7369,0x7469,0x7569,0x7669,
0x7769,0x7869,0x7969,0x7a69,0x3069,0x3169,0x3269,0x3369,0x3469,0x3569,0x3669,0x3769,0x3869,0x3969,0x2b69,0x2f69,
0x416a,0x426a,0x436a,0x446a,0x456a,0x466a,0x476a,0x486a,0x496a,0x4a6a,0x4b6a,0x4c6a,0x4d6a,0x4e6a,0x4f6a,0x506a,
0x516a,0x526a,0x536a,0x546a,0x556a,0x566a,0x576a,0x586a,0x596a,0x5a6a,0x616a,0x626a,0x636a,0x646a,0x656a,0x666a,
0x676a,0x686a,0x696a,0x6a6a,0x6b6a,0x6c6a,0x6d6a,0x6e6a,0x6f6a,0x706a,0x716a,0x726a,0x736a,0x746a,0x756a,0x766a,
0x776a,0x786a,0x796a,0x7a6a,0x306a,0x316a,0x326a,0x336a,0x346a,0x356a,0x366a,0x376a,0x386a,0x396a,0x2b6a,0x2f6a,
0x416b,0x426b,0x436b,0x446b,0x456b,0x466b,0x476b,0x486b,0x496b,0x4a6b,0x4b6b,0x4c6b,0x4d6b,0x4e6b,0x4f6b,0x506b,
0x516b,0x526b,0x536b,0x546b,0x556b,0x566b,0x576b,0x586b,0x596b,0x5a6b,0x616b,0x626b,0x636b,0x646b,0x656b,0x666b,
0x676b,0x686b,0x696b,0x6a6b,0x6b6b,0x6c6b,0x6d6b,0x6e6b,0x6f6b,0x706b,0x716b,0x726b,0x736b,0x746b,0x756b,0x766b,
0x776b,0x786b,0x796b,0x7a6b,0x306b,0x316b,0x326b,0x336b,0x346b,0x356b,0x366b,0x376b,0x386b,0x396b,0x2b6b,0x2f6b,
0x416c,0x426c,0x436c,0x446c,0x456c,0x466c,0x476c,0x486c,0x496c,0x4a6c,0x4b6c,0x4c6c,0x4d6c,0x4e6c,0x4f6c,0x506c,
0x516c,0x526c,0x536c,0x546c,0x556c,0x566c,0x576c,0x586c,0x596c,0x5a6c,0x616c,0x626c,0x636c,0x646c,0x656c,0x666c,
0x676c,0x686c,0x696c,0x6a6c,0x6b6c,0x6c6c,0x6d6c,0x6e6c,0x6f6c,0x706c,0x716c,0x726c,0x736c,0x746c,0x756c,0x766c,
0x776c,0x786c,0x796c,0x7a6c,0x306c,0x316c,0x326c,0x336c,0x346c,0x356c,0x366c,0x376c,0x386c,0x396c,0x2b6c,0x2f6c,
0x416d,0x426d,0x436d,0x446d,0x456d,0x466d,0x476d,0x486d,0x496d,0x4a6d,0x4b6d,0x4c6d,0x4d6d,0x4e6d,0x4f6d,0x506d,
0x516d,0x526d,0x536d,0x546d,0x556d,0x566d,0x576d,0x586d,0x596d,0x5a6d,0x616d,0x626d,0x636d,0x646d,0x656d,0x666d,
0x676d,0x686d,0x696d,0x6a6d,0x6b6d,0x6c6d,0x6d6d,0x6e6d,0x6f6d,0x706d,0x716d,0x726d,0x736d,0x746d,0x756d,0x766d,
0x776d,0x786d,0x796d,0x7a6d,0x306d,0x316d,0x326d,0x336d,0x346d,0x356d,0x366d,0x376d,0x386d,0x396d,0x2b6d,0x2f6d,
0x416e,0x426e,0x436e,0x446e,0x456e,0x466e,0x476e,0x486e,0x496e,0x4a6e,0x4b6e,0x4c6e,0x4d6e,0x4e6e,0x4f6e,0x506e,
0x516e,0x526e,0x536e,0x546e,0x556e,0x566e,0x576e,0x586e,0x596e,0x5a6e,0x616e,0x626e,0x636e,0x646e,0x656e,0x666e,
0x676e,0x686e,0x696e,0x6a6e,0x6b6e,0x6c6e,0x6d6e,0x6e6e,0x6f6e,0x706e,0x716e,0x726e,0x736e,0x746e,0x756e,0x766e,
0x776e,0x786e,0x796e,0x7a6e,0x306e,0x316e,0x326e,0x336e,0x346e,0x356e,0x366e,0x376e,0x386e,0x396e,0x2b6e,0x2f6e,
0x416f,0x426f,0x436f,0x446f,0x456f,0x466f,0x476f,0x486f,0x496f,0x4a6f,0x4b6f,0x4c6f,0x4d6f,0x4e6f,0x4f6f,0x506f,
0x516f,0x526f,0x536f,0x546f,0x556f,0x566f,0x576f,0x586f,0x596f,0x5a6f,0x616f,0x626f,0x636f,0x646f,0x656f,0x666f,
0x676f,0x686f,0x696f,0x6a6f,0x6b6f,0x6c6f,0x6d6f,0x6e6f,0x6f6f,0x706f,0x716f,0x726f,0x736f,0x746f,0x756f,0x766f,
0x776f,0x786f,0x796f,0x7a6f,0x306f,0x316f,0x326f,0x336f,0x346f,0x356f,0x366f,0x376f,0x386f,0x396f,0x2b6f,0x2f6f,
0x4170,0x4270,0x4370,0x4470,0x4570,0x4670,0x4770,0x4870,0x4970,0x4a70,0x4b70,0x4c70,0x4d70,0x4e70,0x4f70,0x5070,
0x5170,0x5270,0x5370,0x5470,0x5570,0x5670,0x5770,0x5870,0x5970,0x5a70,0x6170,0x6270,0x6370,0x6470,0x6570,0x6670,
0x6770,0x6870,0x6970,0x6a70,0x6b70,0x6c70,0x6d70,0x6e70,0x6f70,0x7070,0x7170,0x7270,0x7370,0x7470,0x7570,0x7670,
0x7770,0x7870,0x7970,0x7a70,0x3070,0x3170,0x3270,0x3370,0x3470,0x3570,0x3670,0x3770,0x3870,0x3970,0x2b70,0x2f70,
0x4171,0x4271,0x4371,0x4471,0x4571,0x4671,0x4771,0x4871,0x4971,0x4a71,0x4b71,0x4c71,0x4d71,0x4e71,0x4f71,0x5071,
0x5171,0x5271,0x5371,0x5471,0x5571,0x5671,0x5771,0x5871,0x5971,0x5a71,0x6171,0x6271,0x6371,0x6471,0x6571,0x6671,
0x6771,0x6871,0x6971,0x6a71,0x6b71,0x6c71,0x6d71,0x6e71,0x6f71,0x7071,0x7171,0x7271,0x7371,0x7471,0x7571,0x7671,
0x7771,0x7871,0x7971,0x7a71,0x3071,0x3171,0x3271,0x3371,0x3471,0x3571,0x3671,0x3771,0x3871,0x3971,0x2b71,0x2f71,
0x4172,0x4272,0x4372,0x4472,0x4572,0x4672,0x4772,0x4872,0x4972,0x4a72,0x4b72,0x4c72,0x4d72,0x4e72,0x4f72,0x5072,
0x5172,0x5272,0x5372,0x5472,0x5572,0x5672,0x5772,0x5872,0x5972,0x5a72,0x6172,0x6272,0x6372,0x6472,0x6572,0x6672,
0x6772,0x6872,0x6972,0x6a72,0x6b72,0x6c72,0x6d72,0x6e72,0x6f72,0x7072,0x7172,0x7272,0x7372,0x7472,0x7572,0x7672,
0x7772,0x7872,0x7972,0x7a72,0x3072,0x3172,0x3272,0x3372,0x3472,0x3572,0x3672,0x3772,0x3872,0x3972,0x2b72,0x2f72,
0x4173,0x4273,0x4373,0x4473,0x4573,0x4673,0x4773,0x4873,0x4973,0x4a73,0x4b73,0x4c73,0x4d73,0x4e73,0x4f73,0x5073,
0x5173,0x5273,0x5373,0x5473,0x5573,0x5673,0x5773,0x5873,0x5973,0x5a73,0x6173,0x6273,0x6373,0x6473,0x6573,0x6673,
0x6773,0x6873,0x6973,0x6a73,0x6b73,0x6c73,0x6d73,0x6e73,0x6f73,0x7073,0x7173,0x7273,0x7373,0x7473,0x7573,0x7673,
0x7773,0x7873,0x7973,0x7a73,0x3073,0x3173,0x3273,0x3373,0x3473,0x3573,0x3673,0x3773,0x3873,0x3973,0x2b73,0x2f73,
0x4174,0x4274,0x4374,0x4474,0x4574,0x4674,0x4774,0x4874,0x4974,0x4a74,0x4b74,0x4c74,0x4d74,0x4e74,0x4f74,0x5074,
0x5174,0x5274,0x5374,0x5474,0x5574,0x5674,0x5774,0x5874,0x5974,0x5a74,0x6174,0x6274,0x6374,0x6474,0x6574,0x6674,
0x6774,0x6874,0x6974,0x6a74,0x6b74,0x6c74,0x6d74,0x6e74,0x6f74,0x7074,0x7174,0x7274,0x7374,0x7474,0x7574,0x7674,
0x7774,0x7874,0x7974,0x7a74,0x3074,0x3174,0x3274,0x3374,0x3474,0x3574,0x3674,0x3774,0x3874,0x3974,0x2b74,0x2f74,
0x4175,0x4275,0x4375,0x4475,0x4575,0x4675,0x4775,0x4875,0x4975,0x4a75,0x4b75,0x4c75,0x4d75,0x4e75,0x4f75,0x5075,
0x5175,0x5275,0x5375,0x5475,0x5575,0x5675,0x5775,0x5875,0x5975,0x5a75,0x6175,0x6275,0x6375,0x6475,0x6575,0x6675,
0x6775,0x6875,0x6975,0x6a75,0x6b75,0x6c75,0x6d75,0x6e75,0x6f75,0x7075,0x7175,0x7275,0x7375,0x7475,0x7575,0x7675,
0x7775,0x7875,0x7975,0x7a75,0x3075,0x3175,0x3275,0x3375,0x3475,0x3575,0x3675,0x3775,0x3875,0x3975,0x2b75,0x2f75,
0x4176,0x4276,0x4376,0x4476,0x4576,0x4676,0x4776,0x4876,0x4976,0x4a76,0x4b76,0x4c76,0x4d76,0x4e76,0x4f76,0x5076,
0x5176,0x5276,0x5376,0x5476,0x5576,0x5676,0x5776,0x5876,0x5976,0x5a76,0x6176,0x6276,0x6376,0x6476,0x6576,0x6676,
0x6776,0x6876,0x6976,0x6a76,0x6b76,0x6c76,0x6d76,0x6e76,0x6f76,0x7076,0x7176,0x7276,0x7376,0x7476,0x7576,0x7676,
0x7776,0x7876,0x7976,0x7a76,0x3076,0x3176,0x3276,0x3376,0x3476,0x3576,0x3676,0x3776,0x3876,0x3976,0x2b76,0x2f76,
0x4177,0x4277,0x4377,0x4477,0x4577,0x4677,0x4777,0x4877,0x4977,0x4a77,0x4b77,0x4c77,0x4d77,0x4e77,0x4f77,0x5077,
0x5177,0x5277,0x5377,0x5477,0x5577,0x5677,0x5777,0x5877,0x5977,0x5a77,0x6177,0x6277,0x6377,0x6477,0x6577,0x6677,
0x6777,0x6877,0x6977,0x6a77,0x6b77,0x6c77,0x6d77,0x6e77,0x6f77,0x7077,0x7177,0x7277,0x7377,0x7477,0x7577,0x7677,
0x7777,0x7877,0x7977,0x7a77,0x3077,0x3177,0x3277,0x3377,0x3477,0x3577,0x3677,0x3777,0x3877,0x3977,0x2b77,0x2f77,
0x4178,0x4278,0x4378,0x4478,0x4578,0x4678,0x4778,0x4878,0x4978,0x4a78,0x4b78,0x4c78,0x4d78,0x4e78,0x4f78,0x5078,
0x5178,0x5278,0x5378,0x5478,0x5578,0x5678,0x5778,0x5878,0x5978,0x5a78,0x6178,0x6278,0x6378,0x6478,0x6578,0x6678,
0x6778,0x6878,0x6978,0x6a78,0x6b78,0x6c78,0x6d78,0x6e78,0x6f78,0x7078,0x7178,0x7278,0x7378,0x7478,0x7578,0x7678,
0x7778,0x7878,0x7978,0x7a78,0x3078,0x3178,0x3278,0x3378,0x3478,0x3578,0x3678,0x3778,0x3878,0x3978,0x2b78,0x2f78,
0x4179,0x4279,0x4379,0x4479,0x4579,0x4679,0x4779,0x4879,0x4979,0x4a79,0x4b79,0x4c79,0x4d79,0x4e79,0x4f79,0x5079,
0x5179,0x5279,0x5379,0x5479,0x5579,0x5679,0x5779,0x5879,0x5979,0x5a79,0x6179,0x6279,0x6379,0x6479,0x6579,0x6679,
0x6779,0x6879,0x6979,0x6a79,0x6b79,0x6c79,0x6d79,0x6e79,0x6f79,0x7079,0x7179,0x7279,0x7379,0x7479,0x7579,0x7679,
0x7779,0x7879,0x7979,0x7a79,0x3079,0x3179,0x3279,0x3379,0x3479,0x3579,0x3679,0x3779,0x3879,0x3979,0x2b79,0x2f79,
0x417a,0x427a,0x437a,0x447a,0x457a,0x467a,0x477a,0x487a,0x497a,0x4a7a,0x4b7a,0x4c7a,0x4d7a,0x4e7a,0x4f7a,0x507a,
0x517a,0x527a,0x537a,0x547a,0x557a,0x567a,0x577a,0x587a,0x597a,0x5a7a,0x617a,0x627a,0x637a,0x647a,0x657a,0x667a,
0x677a,0x687a,0x697a,0x6a7a,0x6b7a,0x6c7a,0x6d7a,0x6e7a,0x6f7a,0x707a,0x717a,0x727a,0x737a,0x747a,0x757a,0x767a,
0x777a,0x787a,0x797a,0x7a7a,0x307a,0x317a,0x327a,0x337a,0x347a,0x357a,0x367a,0x377a,0x387a,0x397a,0x2b7a,0x2f7a,
0x4130,0x4230,0x4330,0x4430,0x4530,0x4630,0x4730,0x4830,0x4930,0x4a30,0x4b30,0x4c30,0x4d30,0x4e30,0x4f30,0x5030,
0x5130,0x5230,0x5330,0x5430,0x5530,0x5630,0x5730,0x5830,0x5930,0x5a30,0x6130,0x6230,0x6330,0x6430,0x6530,0x6630,
0x6730,0x6830,0x6930,0x6a30,0x6b30,0x6c30,0x6d30,0x6e30,0x6f30,0x7030,0x7130,0x7230,0x7330,0x7430,0x7530,0x7630,
0x7730,0x7830,0x7930,0x7a30,0x3030,0x3130,0x3230,0x3330,0x3430,0x3530,0x3630,0x3730,0x3830,0x3930,0x2b30,0x2f30,
0x4131,0x4231,0x4331,0x4431,0x4531,0x4631,0x4731,0x4831,0x4931,0x4a31,0x4b31,0x4c31,0x4d31,0x4e31,0x4f31,0x5031,
0x5131,0x5231,0x5331,0x5431,0x5531,0x5631,0x5731,0x5831,0x5931,0x5a31,0x6131,0x6231,0x6331,0x6431,0x6531,0x6631,
0x6731,0x6831,0x6931,0x6a31,0x6b31,0x6c31,0x6d31,0x6e31,0x6f31,0x7031,0x7131,0x7231,0x7331,0x7431,0x7531,0x7631,
0x7731,0x7831,0x7931,0x7a31,0x3031,0x3131,0x3231,0x3331,0x3431,0x3531,0x3631,0x3731,0x3831,0x3931,0x2b31,0x2f31,
0x4132,0x4232,0x4332,0x4432,0x4532,0x4632,0x4732,0x4832,0x4932,0x4a32,0x4b32,0x4c32,0x4d32,0x4e32,0x4f32,0x5032,
0x5132,0x5232,0x5332,0x5432,0x5532,0x5632,0x5732,0x5832,0x5932,0x5a32,0x6132,0x6232,0x6332,0x6432,0x6532,0x6632,
0x6732,0x6832,0x6932,0x6a32,0x6b32,0x6c32,0x6d32,0x6e32,0x6f32,0x7032,0x7132,0x7232,0x7332,0x7432,0x7532,0x7632,
0x7732,0x7832,0x7932,0x7a32,0x3032,0x3132,0x3232,0x3332,0x3432,0x3532,0x3632,0x3732,0x3832,0x3932,0x2b32,0x2f32,
0x4133,0x4233,0x4333,0x4433,0x4533,0x4633,0x4733,0x4833,0x4933,0x4a33,0x4b33,0x4c33,0x4d33,0x4e33,0x4f33,0x5033,
0x5133,0x5233,0x5333,0x5433,0x5533,0x5633,0x5733,0x5833,0x5933,0x5a33,0x6133,0x6233,0x6333,0x6433,0x6533,0x6633,
0x6733,0x6833,0x6933,0x6a33,0x6b33,0x6c33,0x6d33,0x6e33,0x6f33,0x7033,0x7133,0x7233,0x7333,0x7433,0x7533,0x7633,
0x7733,0x7833,0x7933,0x7a33,0x3033,0x3133,0x3233,0x3333,0x3433,0x3533,0x3633,0x3733,0x3833,0x3933,0x2b33,0x2f33,
0x4134,0x4234,0x4334,0x4434,0x4534,0x4634,0x4734,0x4834,0x4934,0x4a34,0x4b34,0x4c34,0x4d34,0x4e34,0x4f34,0x5034,
0x5134,0x5234,0x5334,0x5434,0x5534,0x5634,0x5734,0x5834,0x5934,0x5a34,0x6134,0x6234,0x6334,0x6434,0x6534,0x6634,
0x6734,0x6834,0x6934,0x6a34,0x6b34,0x6c34,0x6d34,0x6e34,0x6f34,0x7034,0x7134,0x7234,0x7334,0x7434,0x7534,0x7634,
0x7734,0x7834,0x7934,0x7a34,0x3034,0x3134,0x3234,0x3334,0x3434,0x3534,0x3634,0x3734,0x3834,0x3934,0x2b34,0x2f34,
0x4135,0x4235,0x4335,0x4435,0x4535,0x4635,0x4735,0x4835,0x4935,0x4a35,0x4b35,0x4c35,0x4d35,0x4e35,0x4f35,0x5035,
0x5135,0x5235,0x5335,0x5435,0x5535,0x5635,0x5735,0x5835,0x5935,0x5a35,0x6135,0x6235,0x6335,0x6435,0x6535,0x6635,
0x6735,0x6835,0x6935,0x6a35,0x6b35,0x6c35,0x6d35,0x6e35,0x6f35,0x7035,0x7135,0x7235,0x7335,0x7435,0x7535,0x7635,
0x7735,0x7835,0x7935,0x7a35,0x3035,0x3135,0x3235,0x3335,0x3435,0x3535,0x3635,0x3735,0x3835,0x3935,0x2b35,0x2f35,
0x4136,0x4236,0x4336,0x4436,0x4536,0x4636,0x4736,0x4836,0x4936,0x4a36,0x4b36,0x4c36,0x4d36,0x4e36,0x4f36,0x5036,
0x5136,0x5236,0x5336,0x5436,0x5536,0x5636,0x5736,0x5836,0x5936,0x5a36,0x6136,0x6236,0x6336,0x6436,0x6536,0x6636,
0x6736,0x6836,0x6936,0x6a36,0x6b36,0x6c36,0x6d36,0x6e36,0x6f36,0x7036,0x7136,0x7236,0x7336,0x7436,0x7536,0x7636,
0x7736,0x7836,0x7936,0x7a36,0x3036,0x3136,0x3236,0x3336,0x3436,0x3536,0x3636,0x3736,0x3836,0x3936,0x2b36,0x2f36,
0x4137,0x4237,0x4337,0x4437,0x4537,0x4637,0x4737,0x4837,0x4937,0x4a37,0x4b37,0x4c37,0x4d37,0x4e37,0x4f37,0x5037,
0x5137,0x5237,0x5337,0x5437,0x5537,0x5637,0x5737,0x5837,0x5937,0x5a37,0x6137,0x6237,0x6337,0x6437,0x6537,0x6637,
0x6737,0x6837,0x6937,0x6a37,0x6b37,0x6c37,0x6d37,0x6e37,0x6f37,0x7037,0x7137,0x7237,0x7337,0x7437,0x7537,0x7637,
0x7737,0x7837,0x7937,0x7a37,0x3037,0x3137,0x3237,0x3337,0x3437,0x3537,0x3637,0x3737,0x3837,0x3937,0x2b37,0x2f37,
0x4138,0x4238,0x4338,0x4438,0x4538,0x4638,0x4738,0x4838,0x4938,0x4a38,0x4b38,0x4c38,0x4d38,0x4e38,0x4f38,0x5038,
0x5138,0x5238,0x5338,0x5438,0x5538,0x5638,0x5738,0x5838,0x5938,0x5a38,0x6138,0x6238,0x6338,0x6438,0x6538,0x6638,
0x6738,0x6838,0x6938,0x6a38,0x6b38,0x6c38,0x6d38,0x6e38,0x6f38,0x7038,0x7138,0x7238,0x7338,0x7438,0x7538,0x7638,
0x7738,0x7838,0x7938,0x7a38,0x3038,0x3138,0x3238,0x3338,0x3438,0x3538,0x3638,0x3738,0x3838,0x3938,0x2b38,0x2f38,
0x4139,0x4239,0x4339,0x4439,0x4539,0x4639,0x4739,0x4839,0x4939,0x4a39,0x4b39,0x4c39,0x4d39,0x4e39,0x4f39,0x5039,
0x5139,0x5239,0x5339,0x5439,0x5539,0x5639,0x5739,0x5839,0x5939,0x5a39,0x6139,0x6239,0x6339,0x6439,0x6539,0x6639,
0x6739,0x6839,0x6939,0x6a39,0x6b39,0x6c39,0x6d39,0x6e39,0x6f39,0x7039,0x7139,0x7239,0x7339,0x7439,0x7539,0x7639,
0x7739,0x7839,0x7939,0x7a39,0x3039,0x3139,0x3239,0x3339,0x3439,0x3539,0x3639,0x3739,0x3839,0x3939,0x2b39,0x2f39,
0x412b,0x422b,0x432b,0x442b,0x452b,0x462b,0x472b,0x482b,0x492b,0x4a2b,0x4b2b,0x4c2b,0x4d2b,0x4e2b,0x4f2b,0x502b,
0x512b,0x522b,0x532b,0x542b,0x552b,0x562b,0x572b,0x582b,0x592b,0x5a2b,0x612b,0x622b,0x632b,0x642b,0x652b,0x662b,
0x672b,0x682b,0x692b,0x6a2b,0x6b2b,0x6c2b,0x6d2b,0x6e2b,0x6f2b,0x702b,0x712b,0x722b,0x732b,0x742b,0x752b,0x762b,
0x772b,0x782b,0x792b,0x7a2b,0x302b,0x312b,0x322b,0x332b,0x342b,0x352b,0x362b,0x372b,0x382b,0x392b,0x2b2b,0x2f2b,
0x412f,0x422f,0x432f,0x442f,0x452f,0x462f,0x472f,0x482f,0x492f,0x4a2f,0x4b2f,0x4c2f,0x4d2f,0x4e2f,0x4f2f,0x502f,
0x512f,0x522f,0x532f,0x542f,0x552f,0x562f,0x572f,0x582f,0x592f,0x5a2f,0x612f,0x622f,0x632f,0x642f,0x652f,0x662f,
0x672f,0x682f,0x692f,0x6a2f,0x6b2f,0x6c2f,0x6d2f,0x6e2f,0x6f2f,0x702f,0x712f,0x722f,0x732f,0x742f,0x752f,0x762f,
0x772f,0x782f,0x792f,0x7a2f,0x302f,0x312f,0x322f,0x332f,0x342f,0x352f,0x362f,0x372f,0x382f,0x392f,0x2b2f,0x2f2f };
#define EX(_i_) {\
unsigned v = ctou32(ip+3+_i_*6 ); u = BSWAP32(u); stou32(op+_i_*8, XU32(u));\
u = ctou32(ip+3+_i_*6+3); v = BSWAP32(v); stou32(op+_i_*8+4, XU32(v));\
}
size_t tb64xenc(const unsigned char *in, size_t inlen, unsigned char *out) {
size_t outlen = TB64ENCLEN(inlen);
const unsigned char *ip = in, *out_ = out + outlen;
unsigned char *op = out;
if(outlen > 4+8) {
unsigned u = ctou32(ip);
for(; op < out_-(4+64); op += 64, ip += (64/4)*3) { EX(0); EX(1); EX( 2); EX( 3); EX( 4); EX( 5); EX( 6); EX( 7); PREFETCH(ip,384, 0); }
for(; op < out_-(4+ 8); op += 8, ip += ( 8/4)*3) EX(0);
}
EXTAIL(1);
return outlen;
}
================================================
FILE: turbob64d.c
================================================
/**
Copyright (C) powturbo 2016-2023
SPDX-License-Identifier: GPL v3 License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- homepage : https://sites.google.com/site/powturbo/
- github : https://github.com/powturbo
- twitter : https://twitter.com/powturbo
- email : powturbo [_AT_] gmail [_DOT_] com
**/
// Turbo-Base64: Scalar decode
//------------- TurboBase64 : Base64 decoding -------------------
#include "turbob64.h"
#include "turbob64_.h"
//--------------------- Decoding with small lut (only 64 bytes used)------------------------------------
#define _ 0xff // invald entry
static const unsigned char lut[] = {
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _,62, _, _, _,63,
52,53,54,55,56,57,58,59,60,61, _, _, _, _, _, _,
_, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
15,16,17,18,19,20,21,22,23,24,25, _, _, _, _, _,
_,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,51, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _
};
#undef _
#ifdef NCHECK // no checking
#define DSC(a) DS(a)
#else
#ifdef B64CHECK // Full check
#undef DS
#define DS(a) DSC(a)
#endif
#endif
#define DS32(_u_) BSWAP32(lut[(unsigned char)(_u_ )] << 26 |\
lut[(unsigned char)(_u_>> 8)] << 20 |\
lut[(unsigned char)(_u_>> 16)] << 14 |\
lut[ _u_>> 24 ] << 8)
#define DS32C(_u_) (lut[(unsigned char)(_u_ )] |\
lut[(unsigned char)(_u_>> 8)] |\
lut[(unsigned char)(_u_>> 16)] |\
lut[ _u_>> 24 ])
#define DS_(_i_,_check0_,_check1_) { unsigned _o0,_o1, _q0,_q1;\
ltou32(&u0, ip+8+_i_*16 ); ltou32(&u1, ip+8+_i_*16+4 ); _o0 = DS32(v0); _o1 = DS32(v1); _check0_; \
ltou32(&v0, ip+8+_i_*16+8); ltou32(&v1, ip+8+_i_*16+8+4); _q0 = DS32(u0); _q1 = DS32(u1); _check1_; \
stou32(op+_i_*12, _o0); stou32(op+_i_*12+3, _o1);\
stou32(op+_i_*12+6, _q0); stou32(op+_i_*12+9, _q1);\
}
#define DS(_i_) DS_(_i_,;,;)
#define DSC64(_i_) DS_(_i_,CHECK0(cu |= _o0),CHECK1(cu |= _q0))
size_t tb64sdec(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {
const unsigned char *ip = in;
unsigned char *op = out;
CHECK0(unsigned cu = 0);
if(inlen > 16+4) {
if(inlen&3) return 0;
unsigned v0 = ctou32(ip), v1 = ctou32(ip+4), u0,u1;
for(; ip < in+inlen-4-128; ip += 128, op += 128*3/4) { DSC64(0); DS(1); DS( 2); DS( 3); DS( 4); DS( 5); DS( 6); DS( 7); PREFETCH(ip, 384, 0); }
for(; ip < in+inlen-4-16; ip += 16, op += 16*3/4) DS( 0);
} else if(!inlen) return 0;
for(; ip < (in+inlen)-4; ip += 4, op += 3) { unsigned u = ctou32(ip); u = DS32(u); stou32(op, u); CHECK0(cu |= u); }
if(ip[3] != '=') { unsigned u = ctou32(ip); cu |= DS32C(u); u = DS32(u); op[0] = u; op[1] = u>>8; op[2] = u>>16; op+=3; } // 4->3 bytes
else if(ip[2] != '=') { unsigned u = BSWAP32(lut[ip[0]]<<26 | lut[ip[1]]<<20 | lut[ip[2]]<<14); op[0] = u; op[1] = u>>8; op+=2; cu |= lut[ip[0]] | lut[ip[1]] | lut[ip[2]];} // 3->2 bytes
else if(ip[1] != '=') { *op++ = BSWAP32(lut[ip[0]]<<26 | lut[ip[1]]<<20); cu |= lut[ip[0]] | lut[ip[1]]; } // 2->1 byte
else { *op++ = BSWAP32(lut[ip[0]]); cu |= lut[ip[0]]; };// 1->1 byte
return (cu == 0xff)?0:(op - out);
}
//------ Fast decoding with pre shifted lookup table: 4k=4*4*256, (but only 4*4*64 = 1024 bytes used) for fast decoding --------------------------------------------------------------------
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define _ -1 // invalid entry
const unsigned tb64lutd0[] = {
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _,0xf8000000, _, _, _,0xfc000000,
0xd0000000,0xd4000000,0xd8000000,0xdc000000,0xe0000000,0xe4000000,0xe8000000,0xec000000,0xf0000000,0xf4000000, _, _, _, _, _, _,
_,0x00000000,0x04000000,0x08000000,0x0c000000,0x10000000,0x14000000,0x18000000,0x1c000000,0x20000000,0x24000000,0x28000000,0x2c000000,0x30000000,0x34000000,0x38000000,
0x3c000000,0x40000000,0x44000000,0x48000000,0x4c000000,0x50000000,0x54000000,0x58000000,0x5c000000,0x60000000,0x64000000, _, _, _, _, _,
_,0x68000000,0x6c000000,0x70000000,0x74000000,0x78000000,0x7c000000,0x80000000,0x84000000,0x88000000,0x8c000000,0x90000000,0x94000000,0x98000000,0x9c000000,0xa0000000,
0xa4000000,0xa8000000,0xac000000,0xb0000000,0xb4000000,0xb8000000,0xbc000000,0xc0000000,0xc4000000,0xc8000000,0xcc000000, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _
};
const unsigned tb64lutd1[] = {
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _,0x3e00000, _, _, _,0x3f00000,
0x3400000,0x3500000,0x3600000,0x3700000,0x3800000,0x3900000,0x3a00000,0x3b00000,0x3c00000,0x3d00000, _, _, _, _, _, _,
_,0x0000000,0x0100000,0x0200000,0x0300000,0x0400000,0x0500000,0x0600000,0x0700000,0x0800000,0x0900000,0x0a00000,0x0b00000,0x0c00000,0x0d00000,0x0e00000,
0x0f00000,0x1000000,0x1100000,0x1200000,0x1300000,0x1400000,0x1500000,0x1600000,0x1700000,0x1800000,0x1900000, _, _, _, _, _,
_,0x1a00000,0x1b00000,0x1c00000,0x1d00000,0x1e00000,0x1f00000,0x2000000,0x2100000,0x2200000,0x2300000,0x2400000,0x2500000,0x2600000,0x2700000,0x2800000,
0x2900000,0x2a00000,0x2b00000,0x2c00000,0x2d00000,0x2e00000,0x2f00000,0x3000000,0x3100000,0x3200000,0x3300000, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _
};
const unsigned tb64lutd2[] = {
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _,0xf8000, _, _, _,0xfc000,
0xd0000,0xd4000,0xd8000,0xdc000,0xe0000,0xe4000,0xe8000,0xec000,0xf0000,0xf4000, _, _, _, _, _, _,
_,0x00000,0x04000,0x08000,0x0c000,0x10000,0x14000,0x18000,0x1c000,0x20000,0x24000,0x28000,0x2c000,0x30000,0x34000,0x38000,
0x3c000,0x40000,0x44000,0x48000,0x4c000,0x50000,0x54000,0x58000,0x5c000,0x60000,0x64000, _, _, _, _, _,
_,0x68000,0x6c000,0x70000,0x74000,0x78000,0x7c000,0x80000,0x84000,0x88000,0x8c000,0x90000,0x94000,0x98000,0x9c000,0xa0000,
0xa4000,0xa8000,0xac000,0xb0000,0xb4000,0xb8000,0xbc000,0xc0000,0xc4000,0xc8000,0xcc000, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _
};
const unsigned tb64lutd3[] = {
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _,0x3e00, _, _, _,0x3f00,
0x3400,0x3500,0x3600,0x3700,0x3800,0x3900,0x3a00,0x3b00,0x3c00,0x3d00, _, _, _, _, _, _,
_,0x0000,0x0100,0x0200,0x0300,0x0400,0x0500,0x0600,0x0700,0x0800,0x0900,0x0a00,0x0b00,0x0c00,0x0d00,0x0e00,
0x0f00,0x1000,0x1100,0x1200,0x1300,0x1400,0x1500,0x1600,0x1700,0x1800,0x1900, _, _, _, _, _,
_,0x1a00,0x1b00,0x1c00,0x1d00,0x1e00,0x1f00,0x2000,0x2100,0x2200,0x2300,0x2400,0x2500,0x2600,0x2700,0x2800,
0x2900,0x2a00,0x2b00,0x2c00,0x2d00,0x2e00,0x2f00,0x3000,0x3100,0x3200,0x3300, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _
};
#undef _
#else
#define _ -1 // invalid entry
const unsigned tb64lutd0[] = {
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _,0xf8, _, _, _,0xfc,
0xd0,0xd4,0xd8,0xdc,0xe0,0xe4,0xe8,0xec,0xf0,0xf4, _, _, _, _, _, _,
_,0x00,0x04,0x08,0x0c,0x10,0x14,0x18,0x1c,0x20,0x24,0x28,0x2c,0x30,0x34,0x38,
0x3c,0x40,0x44,0x48,0x4c,0x50,0x54,0x58,0x5c,0x60,0x64, _, _, _, _, _,
_,0x68,0x6c,0x70,0x74,0x78,0x7c,0x80,0x84,0x88,0x8c,0x90,0x94,0x98,0x9c,0xa0,
0xa4,0xa8,0xac,0xb0,0xb4,0xb8,0xbc,0xc0,0xc4,0xc8,0xcc, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _
};
const unsigned tb64lutd1[] = {
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _,0xe003, _, _, _,0xf003,
0x4003,0x5003,0x6003,0x7003,0x8003,0x9003,0xa003,0xb003,0xc003,0xd003, _, _, _, _, _, _,
_,0x0000,0x1000,0x2000,0x3000,0x4000,0x5000,0x6000,0x7000,0x8000,0x9000,0xa000,0xb000,0xc000,0xd000,0xe000,
0xf000,0x0001,0x1001,0x2001,0x3001,0x4001,0x5001,0x6001,0x7001,0x8001,0x9001, _, _, _, _, _,
_,0xa001,0xb001,0xc001,0xd001,0xe001,0xf001,0x0002,0x1002,0x2002,0x3002,0x4002,0x5002,0x6002,0x7002,0x8002,
0x9002,0xa002,0xb002,0xc002,0xd002,0xe002,0xf002,0x0003,0x1003,0x2003,0x3003, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _
};
const unsigned tb64lutd2[] = {
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _,0x800f00, _, _, _,0xc00f00,
0x000d00,0x400d00,0x800d00,0xc00d00,0x000e00,0x400e00,0x800e00,0xc00e00,0x000f00,0x400f00, _, _, _, _, _, _,
_,0x000000,0x400000,0x800000,0xc00000,0x000100,0x400100,0x800100,0xc00100,0x000200,0x400200,0x800200,0xc00200,0x000300,0x400300,0x800300,
0xc00300,0x000400,0x400400,0x800400,0xc00400,0x000500,0x400500,0x800500,0xc00500,0x000600,0x400600, _, _, _, _, _,
_,0x800600,0xc00600,0x000700,0x400700,0x800700,0xc00700,0x000800,0x400800,0x800800,0xc00800,0x000900,0x400900,0x800900,0xc00900,0x000a00,
0x400a00,0x800a00,0xc00a00,0x000b00,0x400b00,0x800b00,0xc00b00,0x000c00,0x400c00,0x800c00,0xc00c00, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _
};
const unsigned tb64lutd3[] = {
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _,0x3e0000, _, _, _,0x3f0000,
0x340000,0x350000,0x360000,0x370000,0x380000,0x390000,0x3a0000,0x3b0000,0x3c0000,0x3d0000, _, _, _, _, _, _,
_,0x000000,0x010000,0x020000,0x030000,0x040000,0x050000,0x060000,0x070000,0x080000,0x090000,0x0a0000,0x0b0000,0x0c0000,0x0d0000,0x0e0000,
0x0f0000,0x100000,0x110000,0x120000,0x130000,0x140000,0x150000,0x160000,0x170000,0x180000,0x190000, _, _, _, _, _,
_,0x1a0000,0x1b0000,0x1c0000,0x1d0000,0x1e0000,0x1f0000,0x200000,0x210000,0x220000,0x230000,0x240000,0x250000,0x260000,0x270000,0x280000,
0x290000,0x2a0000,0x2b0000,0x2c0000,0x2d0000,0x2e0000,0x2f0000,0x300000,0x310000,0x320000,0x330000, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _
};
#undef _
#endif
size_t tb64declen(const unsigned char *__restrict in, size_t inlen) {
if(!inlen || (inlen&3)) return 0;
size_t outlen = (inlen/4)*3;
const unsigned char *ip = in+inlen;
if(ip[-1] != '=');
else if(ip[-2] != '=') outlen -= 1;
else if(ip[-3] != '=') outlen -= 2;
else outlen -= 3;
return outlen;
}
#ifdef NCHECK
#define DXC(a) DX(a)
#else
#ifdef B64CHECK
#undef DX
#define DX(a) DXC(a)
#endif
#endif
#ifdef _TB64X_32
#define DX_(_i_,_check0_,_check1_) { unsigned _o0,_o1, _q0,_q1;\
ltou32(&u0, ip+8+_i_*16 ); ltou32(&u1, ip+8+_i_*16+4 ); _o0 = DU32(v0); _o1 = DU32(v1); _check0_; \
ltou32(&v0, ip+8+_i_*16+8); ltou32(&v1, ip+8+_i_*16+8+4); _q0 = DU32(u0); _q1 = DU32(u1); _check1_; \
stou32(op+_i_*12, _o0); stou32(op+_i_*12+3, _o1);\
stou32(op+_i_*12+6, _q0); stou32(op+_i_*12+9, _q1);\
}
#else
#define DX_(_i_,_check0_,_check1_) { unsigned _o0,_o1, _q0,_q1; unsigned long long u;\
ltou64(&u, ip+8+_i_*16 );\
_o0 = DU32((unsigned)v); \
v >>= 32; _o1 = DU32((unsigned)v); _check0_;\
ltou64(&v, ip+8+_i_*16+8);\
_q0 = DU32((unsigned)u);\
u >>= 32; _q1 = DU32((unsigned)u); _check1_;\
stou32(op+_i_*12, _o0); stou32(op+_i_*12+3, _o1);\
stou32(op+_i_*12+6, _q0); stou32(op+_i_*12+9, _q1);\
}
#endif
#define DX(_i_) DX_(_i_,;,;)
#define DXC64(_i_) DX_(_i_,CHECK0(cu |= _o0),CHECK1(cu |= _q0))
size_t tb64xdec(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {
const unsigned char *ip = in;
unsigned char *op = out;
CHECK0(unsigned cu = 0);
if(inlen > 16+4) {
if(inlen&3) return 0;
#ifdef _TB64X_32
unsigned v0 = ctou32(ip), v1 = ctou32(ip+4), u0,u1;
#else
unsigned long long v = ctou64(ip),u;
#endif
for(; ip < in+inlen-4-128; ip += 128, op += 128*3/4) { DXC64(0); DX(1); DX( 2); DX( 3); DX( 4); DX( 5); DX( 6); DX( 7); PREFETCH(ip, 384, 0); }
for(; ip < in+inlen-4-16; ip += 16, op += 16*3/4) DX( 0);
} else if(!inlen) return 0;
for(; ip < (in+inlen)-4; ip += 4, op += 3) { unsigned u = ctou32(ip); u = DU32(u); stou32(op, u); CHECK0(cu |= u); }
DXTAILC(ip,out,op,CHECK0(cu |= u));
return CHECK0((cu == (unsigned)-1)?(size_t)0:)op - out;
}
================================================
FILE: turbob64v128.c
================================================
/**
Copyright (C) powturbo 2016-2023
SPDX-License-Identifier: GPL v3 License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- homepage : https://sites.google.com/site/powturbo/
- github : https://github.com/powturbo
- twitter : https://twitter.com/powturbo
- email : powturbo [_AT_] gmail [_DOT_] com
**/
// Turbo-Base64: ssse3 + arm neon functions (see also turbob64v256)
#include <string.h>
#if defined(__AVX__)
#include <immintrin.h>
#define FUNPREF tb64v128a
#elif defined(__SSE4_1__)
#include <smmintrin.h>
#define FUNPREF tb64v128
#elif defined(__SSSE3__)
#ifdef __powerpc64__
#define __SSE__ 1
#define __SSE2__ 1
#define __SSE3__ 1
#define NO_WARN_X86_INTRINSICS 1
#endif
#define FUNPREF tb64v128
#include <tmmintrin.h>
#elif defined(__SSE2__)
#include <emmintrin.h>
#elif defined(__ARM_NEON)
#include <arm_neon.h>
#endif
#include "turbob64_.h"
#include "turbob64.h"
#ifdef __ARM_NEON //----------------------------------- arm neon --------------------------------
#define _ 0xff // invald entry
static const unsigned char lut[] = {
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _,62, _, _, _,63,
52,53,54,55,56,57,58,59,60,61, _, _, _, _, _, _,
_, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
15,16,17,18,19,20,21,22,23,24,25, _, _, _, _, _,
_,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,51, _, _, _, _, _,
};
#undef _
#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ == 10 && __GNUC_MINOR__ <= 2 || \
__GNUC__ == 9 && __GNUC_MINOR__ <= 3 || \
__GNUC__ == 8 && __GNUC_MINOR__ <= 4 || \
__GNUC__ <= 7)
static inline uint8x16x4_t vld1q_u8_x4(const uint8_t *lut) {
uint8x16x4_t v;
v.val[0] = vld1q_u8(lut);
v.val[1] = vld1q_u8(lut+16);
v.val[2] = vld1q_u8(lut+32);
v.val[3] = vld1q_u8(lut+48);
return v;
}
#endif
#define B64D(iv, ov) {\
iv.val[0] = vqtbx4q_u8(vqtbl4q_u8(vlut1, veorq_u8(iv.val[0], cv40)), vlut0, iv.val[0]);\
iv.val[1] = vqtbx4q_u8(vqtbl4q_u8(vlut1, veorq_u8(iv.val[1], cv40)), vlut0, iv.val[1]);\
iv.val[2] = vqtbx4q_u8(vqtbl4q_u8(vlut1, veorq_u8(iv.val[2], cv40)), vlut0, iv.val[2]);\
iv.val[3] = vqtbx4q_u8(vqtbl4q_u8(vlut1, veorq_u8(iv.val[3], cv40)), vlut0, iv.val[3]);\
\
ov.val[0] = vorrq_u8(vshlq_n_u8(iv.val[0], 2), vshrq_n_u8(iv.val[1], 4));\
ov.val[1] = vorrq_u8(vshlq_n_u8(iv.val[1], 4), vshrq_n_u8(iv.val[2], 2));\
ov.val[2] = vorrq_u8(vshlq_n_u8(iv.val[2], 6), iv.val[3] );\
}
#define _B64CHK128(iv, xv) xv = vorrq_u8(xv, vorrq_u8(vorrq_u8(iv.val[0], iv.val[1]), vorrq_u8(iv.val[2], iv.val[3])))
size_t tb64v128dec(const unsigned char *in, size_t inlen, unsigned char *out) {
const unsigned char *ip;
unsigned char *op;
const uint8x16x4_t vlut0 = vld1q_u8_x4( lut),
vlut1 = vld1q_u8_x4(&lut[64]);
const uint8x16_t cv40 = vdupq_n_u8(0x40);
uint8x16_t xv = vdupq_n_u8(0);
#define DN 256
for(ip = in, op = out; ip != in+(inlen&~(DN-1)); ip += DN, op += (DN/4)*3) { PREFETCH(ip,256,0);
uint8x16x4_t iv0 = vld4q_u8(ip),
iv1 = vld4q_u8(ip+64);
uint8x16x3_t ov0,ov1;
B64D(iv0, ov0);
#if DN > 128
CHECK1(_B64CHK128(iv0,xv));
#else
CHECK0(_B64CHK128(iv0,xv));
#endif
B64D(iv1, ov1); CHECK1(_B64CHK128(iv1,xv));
#if DN > 128
iv0 = vld4q_u8(ip+128);
iv1 = vld4q_u8(ip+192);
#endif
vst3q_u8(op, ov0);
vst3q_u8(op+48, ov1);
#if DN > 128
B64D(iv0,ov0); CHECK1(_B64CHK128(iv0,xv));
B64D(iv1,ov1);
vst3q_u8(op+ 96, ov0);
vst3q_u8(op+144, ov1);
CHECK0(_B64CHK128(iv1,xv));
#endif
}
for( ; ip != in+(inlen&~(64-1)); ip += 64, op += (64/4)*3) {
uint8x16x4_t iv = vld4q_u8(ip);
uint8x16x3_t ov; B64D(iv,ov);
vst3q_u8(op, ov);
CHECK0(xv = vorrq_u8(xv, vorrq_u8(vorrq_u8(iv.val[0], iv.val[1]), vorrq_u8(iv.val[2], iv.val[3]))));
}
size_t rc = 0, r = inlen&(64-1);
if(r && !(rc=tb64xdec(ip, r, op)) || vaddvq_u8(vshrq_n_u8(xv,7))) { return 0; }//decode all
return (op - out) + rc;
}
//--------------------------------------------------------------------------------------------------
#define B64E(iv, ov) {\
ov.val[0] = vshrq_n_u8(iv.val[0], 2);\
ov.val[1] = vandq_u8(vorrq_u8(vshlq_n_u8(iv.val[0], 4), vshrq_n_u8(iv.val[1], 4)), cv3f);\
ov.val[2] = vandq_u8(vorrq_u8(vshlq_n_u8(iv.val[1], 2), vshrq_n_u8(iv.val[2], 6)), cv3f);\
ov.val[3] = vandq_u8( iv.val[2], cv3f);\
\
ov.val[0] = vqtbl4q_u8(vlut, ov.val[0]);\
ov.val[1] = vqtbl4q_u8(vlut, ov.val[1]);\
ov.val[2] = vqtbl4q_u8(vlut, ov.val[2]);\
ov.val[3] = vqtbl4q_u8(vlut, ov.val[3]);\
}
size_t tb64v128enc(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {
static unsigned char lut[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const size_t outlen = TB64ENCLEN(inlen);
const unsigned char *ip, *out_ = out+outlen;
unsigned char *op;
const uint8x16x4_t vlut = vld1q_u8_x4(lut);
const uint8x16_t cv3f = vdupq_n_u8(0x3f);
#define EN 128 // 256//
for(ip = in, op = out; op != out+(outlen&~(EN-1)); op += EN, ip += (EN/4)*3) {
uint8x16x3_t iv0 = vld3q_u8(ip),
iv1 = vld3q_u8(ip+48);
uint8x16x4_t ov0,ov1; B64E(iv0, ov0); B64E(iv1, ov1);
#if EN > 128
iv0 = vld3q_u8(ip+ 96);
iv1 = vld3q_u8(ip+144);
#endif
vst4q_u8(op, ov0);
vst4q_u8(op+64, ov1); //PREFETCH(ip,256,0);
#if EN > 128
B64E(iv0, ov0); B64E(iv1, ov1);
vst4q_u8(op+128, ov0);
vst4q_u8(op+192, ov1);
#endif
}
for( ; op != out+(outlen&~(64-1)); op += 64, ip += (64/4)*3) {
const uint8x16x3_t iv = vld3q_u8(ip);
uint8x16x4_t ov;
B64E(iv, ov);
vst4q_u8(op,ov);
}
EXTAIL();
return outlen;
}
#elif defined(__SSSE3__) //----------------- SSSE3 / SSE4.1 / AVX (derived from the AVX2 functions ) -----------------------------------------------------------------
//--------------- decode -------------------
#define DS64(_i_) {\
__m128i iv0 = _mm_loadu_si128((__m128i *)(ip+32+_i_*64 )),\
iv1 = _mm_loadu_si128((__m128i *)(ip+32+_i_*64+16));\
\
__m128i ou0,shifted0; BITMAP128V8_6(iu0, shifted0,delta_asso, delta_values, ou0); BITPACK128V8_6(ou0, cpv);\
__m128i ou1,shifted1; BITMAP128V8_6(iu1, shifted1,delta_asso, delta_values, ou1); BITPACK128V8_6(ou1, cpv);\
_mm_storeu_si128((__m128i*)(op+_i_*48) , ou0);\
_mm_storeu_si128((__m128i*)(op+_i_*48+12), ou1);\
CHECK0(B64CHK128(iu0, shifted0, check_asso, check_values, vx));\
CHECK1(B64CHK128(iu1, shifted1, check_asso, check_values, vx));\
\
iu0 = _mm_loadu_si128((__m128i *)(ip+32+_i_*64+32));\
iu1 = _mm_loadu_si128((__m128i *)(ip+32+_i_*64+48));\
\
__m128i ov2,shifted2; BITMAP128V8_6(iv0, shifted2,delta_asso, delta_values, ov2); BITPACK128V8_6(ov2, cpv);\
__m128i ov3,shifted3; BITMAP128V8_6(iv1, shifted3,delta_asso, delta_values, ov3); BITPACK128V8_6(ov3, cpv);\
_mm_storeu_si128((__m128i*)(op+_i_*48+24), ov2);\
_mm_storeu_si128((__m128i*)(op+_i_*48+36), ov3);\
CHECK1(B64CHK128(iv0, shifted2, check_asso, check_values, vx));\
CHECK1(B64CHK128(iv1, shifted3, check_asso, check_values, vx));\
}
size_t T2(FUNPREF, dec)(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {
if(inlen&3) return 0;
const unsigned char *ip = in, *in_ = in+inlen;
unsigned char *op = out;
__m128i vx = _mm_setzero_si128();
const __m128i delta_asso = _mm_setr_epi8(0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0f);
const __m128i delta_values = _mm_setr_epi8(0x00, 0x00, 0x00, 0x13, 0x04, 0xbf, 0xbf, 0xb9, 0xb9, 0x00, 0x10, 0xc3, 0xbf, 0xbf, 0xb9, 0xb9);
#ifndef NB64CHECK
const __m128i check_asso = _mm_setr_epi8(0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, 0x07, 0x0b, 0x0b, 0x0b, 0x0f);
const __m128i check_values = _mm_setr_epi8(0x80, 0x80, 0x80, 0x80, 0xcf, 0xbf, 0xd5, 0xa6, 0xb5, 0x86, 0xd1, 0x80, 0xb1, 0x80, 0x91, 0x80);
#endif
const __m128i cpv = _mm_set_epi8( -1, -1, -1, -1, 12, 13, 14, 8, 9, 10, 4, 5, 6, 0, 1, 2);
if(inlen >= 32+64+4) {
__m128i iu0 = _mm_loadu_si128((__m128i *) ip ),
iu1 = _mm_loadu_si128((__m128i *)(ip+16));
for(; ip < in_-(32+2*64+4); ip += 128, op += 128*3/4) { DS64(0); DS64(1); }
if( ip < in_-(32+ 64+4)) { DS64(0); ip += 64, op += 64*3/4; }
} else if(!inlen) return 0;
for(; ip < in_-(16+4); ip += 16, op += 16*3/4) {
__m128i iv = _mm_loadu_si128((__m128i *)ip), ov, shifted0;
BITMAP128V8_6(iv, shifted0, delta_asso, delta_values, ov);
BITPACK128V8_6(ov, cpv);
_mm_storeu_si128((__m128i*) op, ov);
CHECK0(B64CHK128(iv, shifted0, check_asso, check_values, vx));
}
unsigned cx = _mm_movemask_epi8(vx);
size_t rc = 0, r = in_ - ip;
if(r && !(rc = _tb64xd(ip, r, op)) || cx)
return 0;
return (op - out)+rc;
}
//---------------------- encode ------------------
#define ES64(_i_) {\
__m128i v0 = _mm_loadu_si128((__m128i*)(ip+24+_i_*48+ 0)),\
v1 = _mm_loadu_si128((__m128i*)(ip+24+_i_*48+12));\
\
u0 = _mm_shuffle_epi8(u0, shuf);\
u1 = _mm_shuffle_epi8(u1, shuf);\
u0 = bitunpack128v8_6(u0);\
u1 = bitunpack128v8_6(u1);\
u0 = bitmap128v8_6(u0);\
u1 = bitmap128v8_6(u1);\
_mm_storeu_si128((__m128i*)(op+_i_*64+ 0), u0);\
_mm_storeu_si128((__m128i*)(op+_i_*64+16), u1);\
\
u0 = _mm_loadu_si128((__m128i*)(ip+24+_i_*48+24));\
u1 = _mm_loadu_si128((__m128i*)(ip+24+_i_*48+36));\
\
v0 = _mm_shuffle_epi8(v0, shuf);\
v1 = _mm_shuffle_epi8(v1, shuf);\
v0 = bitunpack128v8_6(v0);\
v1 = bitunpack128v8_6(v1); \
v0 = bitmap128v8_6(v0);\
v1 = bitmap128v8_6(v1);\
_mm_storeu_si128((__m128i*)(op+_i_*64+32), v0);\
_mm_storeu_si128((__m128i*)(op+_i_*64+48), v1);\
}
size_t T2(FUNPREF, enc)(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {
const size_t outlen = TB64ENCLEN(inlen);
const unsigned char *ip = in, *out_ = out+outlen;
unsigned char *op = out;
const __m128i shuf = _mm_set_epi8(10,11, 9,10, 7, 8, 6, 7, 4, 5, 3, 4, 1, 2, 0, 1);
if(outlen >= (24+48+4)*4/3) {
__m128i u0 = _mm_loadu_si128((__m128i*) ip),
u1 = _mm_loadu_si128((__m128i*)(ip+12));
for(; op < out_-(24+2*48+4)*4/3; op += 128, ip += 128*3/4) { ES64(0); ES64(1); }
if( op < out_-(24+ 48+4)*4/3) { ES64(0); op += 64; ip += 64*3/4; }
}
for(; op < out_- (12+4)*4/3; op += 16, ip += 16*3/4) {
__m128i v = _mm_loadu_si128((__m128i*)ip);
v = _mm_shuffle_epi8(v, shuf);
v = bitunpack128v8_6(v);
v = bitmap128v8_6(v);
_mm_storeu_si128((__m128i*)op, v);
}
EXTAIL(3);
return outlen;
}
#endif
//-------------------------------------------------------------------------------------------------------------------
#ifndef __AVX__ //include only 1 time
size_t tb64memcpy(const unsigned char* in, size_t inlen, unsigned char *out) {
memcpy(out, in, inlen);
return inlen;
}
static unsigned _cpuisa;
//--------------------- CPU detection -------------------------------------------
#if defined(__i386__) || defined(__x86_64__)
#if _MSC_VER >=1300
#include <intrin.h>
#elif defined (__INTEL_COMPILER)
#include <x86intrin.h>
#endif
static inline void cpuid(int reg[4], int id) {
#if defined (_MSC_VER) //|| defined (__INTEL_COMPILER)
__cpuidex(reg, id, 0);
#elif defined(__i386__) || defined(__x86_64__)
__asm("cpuid" : "=a"(reg[0]),"=b"(reg[1]),"=c"(reg[2]),"=d"(reg[3]) : "a"(id),"c"(0) : );
#endif
}
static inline uint64_t xgetbv (int ctr) {
#if(defined _MSC_VER && (_MSC_FULL_VER >= 160040219) || defined __INTEL_COMPILER)
return _xgetbv(ctr);
#elif defined(__i386__) || defined(__x86_64__)
unsigned a, d;
__asm("xgetbv" : "=a"(a),"=d"(d) : "c"(ctr) : );
return (uint64_t)d << 32 | a;
#else
unsigned a=0, d=0;
return (uint64_t)d << 32 | a;
#endif
}
#endif
#define AVX512F 0x001
#define AVX512DQ 0x002
#define AVX512IFMA 0x004
#define AVX512PF 0x008
#define AVX512ER 0x010
#define AVX512CD 0x020
#define AVX512BW 0x040
#define AVX512VL 0x080
#define AVX512VNNI 0x100
#define AVX512VBMI 0x200
#define AVX512VBMI2 0x400
#define IS_SSE 0x10
#define IS_SSE2 0x20
#define IS_SSE3 0x30
#define IS_SSSE3 0x32
#define IS_POWER9 0x34 // powerpc
#define IS_NEON 0x38 // arm neon
#define IS_SSE41 0x40
#define IS_SSE41x 0x41 //+popcount
#define IS_SSE42 0x42
#define IS_AVX 0x50
#define IS_AVX2 0x60
#define IS_AVX512 0x800
unsigned cpuisa(void) {
int c[4] = {0};
if(_cpuisa) return _cpuisa;
_cpuisa++;
#if defined(__i386__) || defined(__x86_64__)
cpuid(c, 0);
if(c[0]) {
cpuid(c, 1);
//family = ((c >> 8) & 0xf) + ((c >> 20) & 0xff)
//model = ((c >> 4) & 0xf) + ((c >> 12) & 0xf0)
if( c[3] & (1 << 25)) { _cpuisa = IS_SSE;
if( c[3] & (1 << 26)) { _cpuisa = IS_SSE2;
if( c[2] & (1 << 0)) { _cpuisa = IS_SSE3;
// _cpuisa = IS_SSE3SLOW; // Atom SSSE3 slow
if( c[2] & (1 << 9)) { _cpuisa = IS_SSSE3;
if( c[2] & (1 << 19)) { _cpuisa = IS_SSE41;
if( c[2] & (1 << 23)) { _cpuisa = IS_SSE41x; // +popcount
if( c[2] & (1 << 20)) { _cpuisa = IS_SSE42; // SSE4.2
if((c[2] & (1 << 28)) &&
(c[2] & (1 << 27)) && // OSXSAVE
(c[2] & (1 << 26)) && // XSAVE
(xgetbv(0) & 6)==6) { _cpuisa = IS_AVX; // AVX
if(c[2]& (1 << 3)) _cpuisa |= 1; // +FMA3
if(c[2]& (1 << 16)) _cpuisa |= 2; // +FMA4
if(c[2]& (1 << 25)) _cpuisa |= 4; // +AES
cpuid(c, 7);
if(c[1] & (1 << 5)) { _cpuisa = IS_AVX2;
if(c[1] & (1 << 16)) {
cpuid(c, 0xd);
if((c[0] & 0x60)==0x60) { _cpuisa = IS_AVX512;
cpuid(c, 7);
if(c[1] & (1<<16)) _cpuisa |= AVX512F;
if(c[1] & (1<<17)) _cpuisa |= AVX512DQ;
if(c[1] & (1<<21)) _cpuisa |= AVX512IFMA;
if(c[1] & (1<<26)) _cpuisa |= AVX512PF;
if(c[1] & (1<<27)) _cpuisa |= AVX512ER;
if(c[1] & (1<<28)) _cpuisa |= AVX512CD;
if(c[1] & (1<<30)) _cpuisa |= AVX512BW;
if(c[1] & (1u<<31)) _cpuisa |= AVX512VL;
if(c[2] & (1<< 1)) _cpuisa |= AVX512VBMI;
if(c[2] & (1<<11)) _cpuisa |= AVX512VNNI;
if(c[2] & (1<< 6)) _cpuisa |= AVX512VBMI2;
}}}
}}}}}}}}}
#elif defined(__powerpc64__)
_cpuisa = IS_POWER9; // power9
#elif defined(__ARM_NEON)
_cpuisa = IS_NEON; // ARM_NEON
#endif
return _cpuisa;
}
unsigned cpuini(unsigned cpuisa) { if(cpuisa) _cpuisa = cpuisa; return _cpuisa; }
char *cpustr(unsigned cpuisa) {
if(!cpuisa) cpuisa = _cpuisa;
#if defined(__i386__) || defined(__x86_64__)
if(cpuisa >= IS_AVX512) {
if(cpuisa & AVX512VBMI2) return "avx512vbmi2";
if(cpuisa & AVX512VBMI) return "avx512vbmi";
if(cpuisa & AVX512VNNI) return "avx512vnni";
if(cpuisa & AVX512VL) return "avx512vl";
if(cpuisa & AVX512BW) return "avx512bw";
if(cpuisa & AVX512CD) return "avx512cd";
if(cpuisa & AVX512ER)
gitextract_0jc76c4i/
├── .github/
│ └── workflows/
│ └── build.yaml
├── CMakeLists.txt
├── LICENSE
├── README.md
├── cmake/
│ └── turbobase64-config.cmake.in
├── conf.h
├── makefile
├── rust/
│ ├── .gitignore
│ ├── Cargo.toml
│ ├── README.md
│ ├── build.rs
│ ├── src/
│ │ ├── bindings.rs
│ │ ├── lib.rs
│ │ └── tests.rs
│ └── wrapper.h
├── tb64app.c
├── time_.h
├── turbob64.h
├── turbob64_.h
├── turbob64c.c
├── turbob64d.c
├── turbob64v128.c
├── turbob64v256.c
├── turbob64v512.c
└── vs/
├── getopt.c
├── getopt.h
├── inttypes.h
├── stdint.h
├── turbob64avx.c
└── vs2022/
├── TB64App.vcxproj
├── TurboBase64.sln
└── TurboBase64.vcxproj
SYMBOL INDEX (177 symbols across 16 files)
FILE: conf.h
function bswap16 (line 63) | static ALWAYS_INLINE unsigned short bswap16(unsigned short x) { return _...
function ALWAYS_INLINE (line 74) | static ALWAYS_INLINE int __bsr32( int x) { ...
function ALWAYS_INLINE (line 75) | static ALWAYS_INLINE int bsr32( int x) { int b = -1; ...
function ALWAYS_INLINE (line 76) | static ALWAYS_INLINE int bsr64(uint64_t x ) { return x?64 ...
function ALWAYS_INLINE (line 77) | static ALWAYS_INLINE int __bsr64(uint64_t x ) { return 63 ...
function rol32 (line 79) | static ALWAYS_INLINE unsigned rol32(unsigned x, int s) { asm ("roll %%cl...
function ror32 (line 80) | static ALWAYS_INLINE unsigned ror32(unsigned x, int s) { asm ("rorl %%cl...
function ALWAYS_INLINE (line 81) | static ALWAYS_INLINE uint64_t rol64(uint64_t x, int s) { asm ("rolq %%cl...
function ALWAYS_INLINE (line 82) | static ALWAYS_INLINE uint64_t ror64(uint64_t x, int s) { asm ("rorq %%cl...
function ALWAYS_INLINE (line 84) | static ALWAYS_INLINE int __bsr32(unsigned x ) { return 31 ...
function ALWAYS_INLINE (line 85) | static ALWAYS_INLINE int bsr32(int x ) { return x?32 ...
function ALWAYS_INLINE (line 86) | static ALWAYS_INLINE int bsr64(uint64_t x) { return x?64 - __builti...
function ALWAYS_INLINE (line 87) | static ALWAYS_INLINE int __bsr64(uint64_t x ) { return 63 ...
function rol32 (line 89) | static ALWAYS_INLINE unsigned rol32(unsigned x, int s) { return x << s |...
function ror32 (line 90) | static ALWAYS_INLINE unsigned ror32(unsigned x, int s) { return x >> s |...
function rol64 (line 91) | static ALWAYS_INLINE unsigned rol64(unsigned x, int s) { return x << s |...
function ror64 (line 92) | static ALWAYS_INLINE unsigned ror64(unsigned x, int s) { return x >> s |...
function ALWAYS_INLINE (line 120) | static ALWAYS_INLINE int __bsr32(unsigned x) { unsigned long z=0; _BitSc...
function ALWAYS_INLINE (line 121) | static ALWAYS_INLINE int bsr32( unsigned x) { unsigned long z; _BitSc...
function ALWAYS_INLINE (line 122) | static ALWAYS_INLINE int ctz32( unsigned x) { unsigned long z; _BitSc...
function ALWAYS_INLINE (line 123) | static ALWAYS_INLINE int clz32( unsigned x) { unsigned long z; _BitSc...
function _BitScanForward64 (line 125) | static ALWAYS_INLINE unsigned char _BitScanForward64(unsigned long* ret,...
function _BitScanReverse64 (line 129) | static unsigned char _BitScanReverse64(unsigned long* ret, uint64_t x) {
function ALWAYS_INLINE (line 134) | static ALWAYS_INLINE int __bsr64(uint64_t x) { unsigned long z = 0; _Bit...
function ALWAYS_INLINE (line 135) | static ALWAYS_INLINE int bsr64(uint64_t x) { unsigned long z=0; _BitScan...
function ALWAYS_INLINE (line 136) | static ALWAYS_INLINE int ctz64(uint64_t x) { unsigned long z; _BitScan...
function ALWAYS_INLINE (line 137) | static ALWAYS_INLINE int clz64(uint64_t x) { unsigned long z; _BitScan...
function ALWAYS_INLINE (line 159) | static ALWAYS_INLINE double round(double num) { return (num > 0.0) ? flo...
function ctou16 (line 177) | static ALWAYS_INLINE unsigned short ctou16(const void *cp) { unsigne...
function ctou32 (line 178) | static ALWAYS_INLINE unsigned ctou32(const void *cp) { unsigne...
function ctou64 (line 179) | static ALWAYS_INLINE unsigned long long ctou64(const void *cp) { unsigne...
function ALWAYS_INLINE (line 180) | static ALWAYS_INLINE size_t ctousz(const void *cp) { size_t ...
function ALWAYS_INLINE (line 182) | static ALWAYS_INLINE _Float16 ctof16(const void *cp) { _Float1...
function ALWAYS_INLINE (line 184) | static ALWAYS_INLINE float ctof32(const void *cp) { float ...
function ALWAYS_INLINE (line 185) | static ALWAYS_INLINE double ctof64(const void *cp) { double ...
function ALWAYS_INLINE (line 187) | static ALWAYS_INLINE void stou16( void *cp, unsigned ...
function ALWAYS_INLINE (line 188) | static ALWAYS_INLINE void stou32( void *cp, unsigned ...
function ALWAYS_INLINE (line 189) | static ALWAYS_INLINE void stou64( void *cp, unsigned ...
function ALWAYS_INLINE (line 190) | static ALWAYS_INLINE void stousz( void *cp, size_t ...
function ALWAYS_INLINE (line 192) | static ALWAYS_INLINE void stof16( void *cp, _Float16 ...
function ALWAYS_INLINE (line 194) | static ALWAYS_INLINE void stof32( void *cp, float ...
function ALWAYS_INLINE (line 195) | static ALWAYS_INLINE void stof64( void *cp, double ...
function ALWAYS_INLINE (line 197) | static ALWAYS_INLINE void ltou32(unsigned *x, co...
function ALWAYS_INLINE (line 198) | static ALWAYS_INLINE void ltou64(unsigned long long *x, co...
function longu (line 229) | struct _PACKED longu { uint64_t l; }
function doubleu (line 230) | struct _PACKED doubleu { double d; }
function shortu (line 240) | struct _PACKED shortu { unsigned short s; }
function unsignedu (line 241) | struct _PACKED unsignedu { unsigned u; }
function longu (line 242) | struct _PACKED longu { uint64_t l; }
function float16u (line 244) | struct _PACKED float16u { _Float16 g; }
function floatu (line 246) | struct _PACKED floatu { float f; }
function doubleu (line 247) | struct _PACKED doubleu { double d; }
FILE: rust/build.rs
function main (line 7) | fn main() {
FILE: rust/src/bindings.rs
constant TB64_VERSION (line 3) | pub const TB64_VERSION : u32 = 100 ;
type wchar_t (line 4) | pub type wchar_t = :: std :: os :: raw :: c_int ;
type max_align_t (line 5) | pub struct max_align_t {
function bindgen_test_layout_max_align_t (line 8) | fn bindgen_test_layout_max_align_t () { const UNINIT : :: std :: mem :: ...
function tb64enclen (line 13) | pub fn tb64enclen (inlen : usize) -> usize ;
function tb64declen (line 14) | pub fn tb64declen (in_ : * const :: std :: os :: raw :: c_uchar , inlen ...
function tb64enc (line 15) | pub fn tb64enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : u...
function tb64dec (line 16) | pub fn tb64dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : u...
type TB64FUNC (line 16) | pub type TB64FUNC = :: std :: option :: Option < unsafe extern "C" fn (i...
function tb64senc (line 17) | pub fn tb64senc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : ...
function tb64sdec (line 18) | pub fn tb64sdec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : ...
function tb64xenc (line 19) | pub fn tb64xenc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : ...
function tb64xdec (line 20) | pub fn tb64xdec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : ...
function tb64v128enc (line 21) | pub fn tb64v128enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen...
function tb64v128dec (line 22) | pub fn tb64v128dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen...
function tb64v128aenc (line 23) | pub fn tb64v128aenc (in_ : * const :: std :: os :: raw :: c_uchar , inle...
function tb64v128adec (line 24) | pub fn tb64v128adec (in_ : * const :: std :: os :: raw :: c_uchar , inle...
function tb64v256enc (line 25) | pub fn tb64v256enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen...
function tb64v256dec (line 26) | pub fn tb64v256dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen...
function tb64v512enc (line 27) | pub fn tb64v512enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen...
function tb64v512dec (line 28) | pub fn tb64v512dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen...
function tb64ini (line 29) | pub fn tb64ini (id : :: std :: os :: raw :: c_uint , isshort : :: std ::...
function _tb64v256enc (line 30) | pub fn _tb64v256enc (in_ : * const :: std :: os :: raw :: c_uchar , inle...
function _tb64v256dec (line 31) | pub fn _tb64v256dec (in_ : * const :: std :: os :: raw :: c_uchar , inle...
function cpuini (line 32) | pub fn cpuini (cpuisa : :: std :: os :: raw :: c_uint) -> :: std :: os :...
function cpustr (line 33) | pub fn cpustr (cpuisa : :: std :: os :: raw :: c_uint) -> * mut :: std :...
FILE: rust/src/tests.rs
function decode_block (line 9) | fn decode_block(indata: &[u8]) -> Vec<u8> {
function encode_block (line 23) | fn encode_block(indata: &[u8]) -> Vec<u8> {
function test_block (line 34) | fn test_block(inlen: usize) {
function sample_tb64 (line 52) | fn sample_tb64() {
FILE: tb64app.c
function getpagesize_ (line 56) | int getpagesize_() {
function _vfree (line 101) | void _vfree(void *p, size_t size) {
function memcheck (line 112) | int memcheck(unsigned char *in, unsigned n, unsigned char *cpy) {
function bench (line 123) | unsigned bench(unsigned char *in, unsigned n, unsigned char *out, unsign...
function usage (line 157) | void usage(char *pgm) {
function fuzzcheck (line 179) | void fuzzcheck(unsigned char *_in, unsigned insize, unsigned char *_out,...
function fuzztest (line 191) | void fuzztest(unsigned id, unsigned char *_in, unsigned insize, unsigned...
function main (line 227) | int main(int argc, char* argv[]) {
FILE: time_.h
function TMBS (line 94) | static double TMBS(unsigned l, double t) { return (double)t/(double)l; }
type tm_t (line 96) | typedef uint64_t tm_t;
function tm_t (line 97) | static tm_t tmtime() { uint64_t c; RDTSC(c); retu...
function tm_t (line 98) | static tm_t tminit() { uint64_t c; __asm volatile...
function tmdiff (line 99) | static double tmdiff(tm_t start, tm_t stop) { return (double)(stop - sta...
function tmiszero (line 100) | static int tmiszero(tm_t t) { return !t; }
function TMBS (line 105) | static double TMBS(unsigned l, double t) { return (l/t)/1000000.0; }
type tm_t (line 110) | typedef unsigned __int64 tm_t;
function tm_t (line 111) | static tm_t tmtime() { LARGE_INTEGER tm; tm_t t; ...
function tm_t (line 112) | static tm_t tminit() { tm_t t0,ts; QueryPerforman...
function tmdiff (line 113) | static double tmdiff(tm_t start, tm_t stop) { return (double)(stop - sta...
function tmiszero (line 114) | static int tmiszero(tm_t t) { return !t; }
function clock_gettime (line 126) | int clock_gettime(int /*clk_id*/, struct timespec* t) {
type tm_t (line 137) | typedef struct timespec tm_t;
function tm_t (line 138) | static tm_t tmtime() { struct timespec tm; clock_...
function tmdiff (line 139) | static double tmdiff(tm_t start, tm_t stop) { return (stop.tv_sec - star...
function tm_t (line 140) | static tm_t tminit() { tm_t t0 = tmtime(),t; whil...
function tmiszero (line 141) | static int tmiszero(tm_t t) { return !(t.tv_sec|t.tv_nse...
function tm_init (line 177) | static void tm_init(int _tm_Rep, int _tm_verbose) { tm_verbose = _tm_ver...
function pr (line 202) | static void pr(unsigned l, unsigned n) {
function argtoi (line 217) | static unsigned argtoi(char *s, unsigned def) {
function argtol (line 233) | static uint64_t argtol(char *s) {
function argtot (line 250) | static uint64_t argtot(char *s) {
function memrcpy (line 263) | static void memrcpy(unsigned char *out, unsigned char *in, unsigned n) {...
FILE: turbob64_.h
function ALWAYS_INLINE (line 134) | static ALWAYS_INLINE __m128i bitmap128v8_6(const __m128i v) { /*map 8-bi...
function ALWAYS_INLINE (line 142) | static ALWAYS_INLINE __m128i bitunpack128v8_6(__m128i v) { /* unpack 6 -...
function ALWAYS_INLINE (line 150) | static ALWAYS_INLINE __m256i bitmap256v8_6(const __m256i v) { //map...
function ALWAYS_INLINE (line 159) | static ALWAYS_INLINE __m256i bitunpack256v8_6(__m256i v) { //https...
FILE: turbob64c.c
function tb64enclen (line 28) | size_t tb64enclen(size_t n) { return TB64ENCLEN(n); }
function tb64senc (line 37) | size_t tb64senc(const unsigned char *in, size_t inlen, unsigned char *ou...
function tb64xenc (line 316) | size_t tb64xenc(const unsigned char *in, size_t inlen, unsigned char *ou...
FILE: turbob64d.c
function tb64sdec (line 81) | size_t tb64sdec(const unsigned char *__restrict in, size_t inlen, unsign...
function tb64declen (line 262) | size_t tb64declen(const unsigned char *__restrict in, size_t inlen) {
function tb64xdec (line 306) | size_t tb64xdec(const unsigned char *__restrict in, size_t inlen, unsign...
FILE: turbob64v128.c
function uint8x16x4_t (line 71) | static inline uint8x16x4_t vld1q_u8_x4(const uint8_t *lut) {
function tb64v128dec (line 94) | size_t tb64v128dec(const unsigned char *in, size_t inlen, unsigned char ...
function tb64v128enc (line 151) | size_t tb64v128enc(const unsigned char *__restrict in, size_t inlen, uns...
function tb64memcpy (line 302) | size_t tb64memcpy(const unsigned char* in, size_t inlen, unsigned char *...
function cpuid (line 316) | static inline void cpuid(int reg[4], int id) {
function xgetbv (line 324) | static inline uint64_t xgetbv (int ctr) {
function cpuisa (line 363) | unsigned cpuisa(void) {
function cpuini (line 415) | unsigned cpuini(unsigned cpuisa) { if(cpuisa) _cpuisa = cpuisa; return _...
function tb64ini (line 464) | void tb64ini(unsigned id, unsigned isshort) {
function tb64enc (line 499) | size_t tb64enc(const unsigned char *in, size_t inlen, unsigned char *out) {
function tb64dec (line 503) | size_t tb64dec(const unsigned char *in, size_t inlen, unsigned char *out) {
FILE: turbob64v256.c
function tb64v256dec (line 106) | size_t tb64v256dec(const unsigned char *__restrict in, size_t inlen, uns...
function tb64v256enc (line 176) | size_t tb64v256enc(const unsigned char *__restrict in, size_t inlen, uns...
function _tb64v256dec (line 211) | size_t _tb64v256dec(const unsigned char *__restrict in, size_t inlen, un...
function _tb64v256enc (line 264) | size_t _tb64v256enc(const unsigned char *__restrict in, size_t inlen, un...
FILE: turbob64v512.c
function tb64v512enc (line 44) | size_t tb64v512enc(const unsigned char *__restrict in, size_t inlen, uns...
function tb64v512dec (line 112) | size_t tb64v512dec(const unsigned char *in, size_t inlen, unsigned char ...
function tb64v512dec0 (line 170) | size_t tb64v512dec0(const unsigned char *in, size_t inlen, unsigned char...
FILE: vs/getopt.c
type option (line 96) | struct option
type option (line 98) | struct option
function _vwarnx (line 116) | static void
function warnx (line 125) | static void
function gcd (line 137) | static int
function permute_args (line 157) | static void
function parse_long_options (line 194) | static int
function getopt_internal (line 322) | static int
function getopt (line 522) | int
function getopt_long (line 542) | int
function getopt_long_only (line 555) | int
FILE: vs/getopt.h
type option (line 64) | struct option /* specification for a long form option... */
type option (line 80) | struct option
type option (line 82) | struct option
FILE: vs/inttypes.h
type imaxdiv_t (line 48) | typedef struct {
function _inline (line 277) | static
FILE: vs/stdint.h
type int_least8_t (line 99) | typedef int8_t int_least8_t;
type int_least16_t (line 100) | typedef int16_t int_least16_t;
type int_least32_t (line 101) | typedef int32_t int_least32_t;
type int_least64_t (line 102) | typedef int64_t int_least64_t;
type uint_least8_t (line 103) | typedef uint8_t uint_least8_t;
type uint_least16_t (line 104) | typedef uint16_t uint_least16_t;
type uint_least32_t (line 105) | typedef uint32_t uint_least32_t;
type uint_least64_t (line 106) | typedef uint64_t uint_least64_t;
type int_fast8_t (line 109) | typedef int8_t int_fast8_t;
type int_fast16_t (line 110) | typedef int16_t int_fast16_t;
type int_fast32_t (line 111) | typedef int32_t int_fast32_t;
type int_fast64_t (line 112) | typedef int64_t int_fast64_t;
type uint_fast8_t (line 113) | typedef uint8_t uint_fast8_t;
type uint_fast16_t (line 114) | typedef uint16_t uint_fast16_t;
type uint_fast32_t (line 115) | typedef uint32_t uint_fast32_t;
type uint_fast64_t (line 116) | typedef uint64_t uint_fast64_t;
type intmax_t (line 128) | typedef int64_t intmax_t;
type uintmax_t (line 129) | typedef uint64_t uintmax_t;
Condensed preview — 32 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (303K chars).
[
{
"path": ".github/workflows/build.yaml",
"chars": 1122,
"preview": "name: build\non:\n push:\n branches:\n - master\n pull_request:\n branches:\n - master\njobs:\n linux:\n run"
},
{
"path": "CMakeLists.txt",
"chars": 5670,
"preview": "cmake_minimum_required(VERSION 3.15)\n\nproject(turbobase64 C)\n\nif(NOT CMAKE_BUILD_TYPE)\n set(CMAKE_BUILD_TYPE Release)"
},
{
"path": "LICENSE",
"chars": 35149,
"preview": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
},
{
"path": "README.md",
"chars": 10360,
"preview": "## Turbo Base64:Fastest Base64 SSE/AVX2/AVX512/Neon/Altivec\n[\n#\n# add_executable(foo)\n# target_link_libraries(fo"
},
{
"path": "conf.h",
"chars": 17786,
"preview": "/**\n Copyright (C) powturbo 2016-2023\n GPL v3 License\n\n This program is free software; you can redistribute it "
},
{
"path": "makefile",
"chars": 3572,
"preview": "# powturbo (c) Copyright 2016-2023\n# Linux: \"export CC=clang\" \"export CXX=clang\". windows mingw: \"set CC=gcc\" \"set CXX="
},
{
"path": "rust/.gitignore",
"chars": 18,
"preview": "target\nCargo.lock\n"
},
{
"path": "rust/Cargo.toml",
"chars": 190,
"preview": "[package]\nauthors = [\"powturbo <powturbo [AT] gmail [DOT] com>\"]\nbuild = \"build.rs\"\nname = \"Turbo-Base64\"\nversion = \"0.6"
},
{
"path": "rust/README.md",
"chars": 625,
"preview": "# Rust bindings for Turbo-Base64\n\nThis is a wrapper for [Turbo-Base64](https://github.com/powturbo/Turbo-Base64).\n\n## In"
},
{
"path": "rust/build.rs",
"chars": 461,
"preview": "// build bindings.rs\nextern crate bindgen;\n\nuse std::env;\nuse std::path::PathBuf;\n\nfn main() {\n println!(\"cargo:rustc"
},
{
"path": "rust/src/bindings.rs",
"chars": 4504,
"preview": "/* automatically generated by rust-bindgen 0.64.0 */\n\npub const TB64_VERSION : u32 = 100 ;\npub type wchar_t = :: std ::"
},
{
"path": "rust/src/lib.rs",
"chars": 286,
"preview": "// prerequisites: Install Turbo-Base64 library tb64lib under /usr/lib or /usr/local/lib \n#![allow(non_upper_case_global"
},
{
"path": "rust/src/tests.rs",
"chars": 1634,
"preview": "extern crate rand;\n\nuse std::convert::TryFrom;\nuse std::convert::TryInto;\nuse std::vec;\n\nuse super::*;\n\nfn decode_block("
},
{
"path": "rust/wrapper.h",
"chars": 66,
"preview": "// Include TurboPFor public c/c++ header\n#include \"../turbob64.h\"\n"
},
{
"path": "tb64app.c",
"chars": 16418,
"preview": "/**\n Copyright (C) powturbo 2016-2023\n SPDX-License-Identifier: GPL v3 License\n\n This program is free software;"
},
{
"path": "time_.h",
"chars": 10603,
"preview": "/**\n Copyright (C) powturbo 2013-2023\n GPL v2 License\n\n This program is free software; you can redistribute it "
},
{
"path": "turbob64.h",
"chars": 5309,
"preview": "/**\n Copyright (C) powturbo 2016-2023\n SPDX-License-Identifier: GPL v3 License\n\n This program is free software;"
},
{
"path": "turbob64_.h",
"chars": 8384,
"preview": "/**\n Copyright (C) powturbo 2016-2023\n SPDX-License-Identifier: GPL v3 License\n\n This program is free software;"
},
{
"path": "turbob64c.c",
"chars": 32029,
"preview": "/**\n Copyright (C) powturbo 2016-2023\n SPDX-License-Identifier: GPL v3 License\n\n This program is free software;"
},
{
"path": "turbob64d.c",
"chars": 24764,
"preview": "/**\n Copyright (C) powturbo 2016-2023\n SPDX-License-Identifier: GPL v3 License\n\n This program is free software;"
},
{
"path": "turbob64v128.c",
"chars": 20304,
"preview": "/**\n Copyright (C) powturbo 2016-2023\n SPDX-License-Identifier: GPL v3 License\n\n This program is free software;"
},
{
"path": "turbob64v256.c",
"chars": 17204,
"preview": "/**\n Copyright (C) powturbo 2016-2023\n SPDX-License-Identifier: GPL v3 License\n\n This program is free software;"
},
{
"path": "turbob64v512.c",
"chars": 14546,
"preview": "/**\n Copyright (C) powturbo 2016-2023\n SPDX-License-Identifier: GPL v3 License\n This program is free software; "
},
{
"path": "vs/getopt.c",
"chars": 15590,
"preview": "/*\t$OpenBSD: getopt_long.c,v 1.23 2007/10/31 12:34:57 chl Exp $\t*/\n/*\t$NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 "
},
{
"path": "vs/getopt.h",
"chars": 3106,
"preview": "#ifndef __GETOPT_H__\n/**\n * DISCLAIMER\n * This file has no copyright assigned and is placed in the Public Domain.\n * Thi"
},
{
"path": "vs/inttypes.h",
"chars": 8060,
"preview": "// ISO C9x compliant inttypes.h for Microsoft Visual Studio\n// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) "
},
{
"path": "vs/stdint.h",
"chars": 8101,
"preview": "// ISO C9x compliant stdint.h for Microsoft Visual Studio\n// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG"
},
{
"path": "vs/turbob64avx.c",
"chars": 28,
"preview": "#include \"turbob64v128.c\"\r\n"
},
{
"path": "vs/vs2022/TB64App.vcxproj",
"chars": 9220,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project DefaultTargets=\"Build\" ToolsVersion=\"15.0\" xmlns=\"http://schemas.micros"
},
{
"path": "vs/vs2022/TurboBase64.sln",
"chars": 2176,
"preview": "\r\nMicrosoft Visual Studio Solution File, Format Version 12.00\r\n# Visual Studio 15\r\nVisualStudioVersion = 15.0.28307.757"
},
{
"path": "vs/vs2022/TurboBase64.vcxproj",
"chars": 13601,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project DefaultTargets=\"Build\" ToolsVersion=\"15.0\" xmlns=\"http://schemas.micros"
}
]
About this extraction
This page contains the full source code of the powturbo/Turbo-Base64 GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 32 files (284.5 KB), approximately 105.6k tokens, and a symbol index with 177 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.