[
  {
    "path": ".github/workflows/build.yaml",
    "content": "name: build\non:\n  push:\n    branches:\n      - master\n  pull_request:\n    branches:\n      - master\njobs:\n  linux:\n    runs-on: '${{ matrix.os }}'\n    strategy:\n      fail-fast: false\n      matrix:\n        os: [ubuntu-latest]\n        compiler: [\"gcc\", \"clang\"]\n    env:      \n      CC: ${{ matrix.compiler }}\n    steps:\n      - uses: actions/checkout@v3\n      - run: make \n      - run: lscpu\n      - run: ./tb64app -v1\n\n  macos:\n    runs-on: '${{ matrix.os }}'\n    strategy:\n      fail-fast: false\n      matrix:\n        os: [macos-latest]\n        compiler: [\"clang\"]\n    env:      \n      CC: ${{ matrix.compiler }}\n    steps:\n      - uses: actions/checkout@v3\n      - run: make\n      - run: sysctl -n machdep.cpu.brand_string\n      - run: ./tb64app -v1\n#      - run: ./tb64app -T -f3\n\n  windows:\n    runs-on: windows-latest\n    defaults:\n      run:\n        shell: msys2 {0}\n    steps:\n    - uses: actions/checkout@v3\n    - uses: msys2/setup-msys2@v2\n      with:\n        msystem: MINGW64\n        install: make mingw-w64-x86_64-gcc\n        update: true\n    - run: make\n    - run: ./tb64app -v1\n#    - run: ./tb64app -T -f3\n\n \n"
  },
  {
    "path": "CMakeLists.txt",
    "content": "cmake_minimum_required(VERSION 3.15)\n\nproject(turbobase64 C)\n\nif(NOT CMAKE_BUILD_TYPE)\n    set(CMAKE_BUILD_TYPE Release)\nendif()\n\n# Run cmake -D<OPTION>=ON|OFF to turn on/off options.\n# Usage example:\n#     cmake -B build -S . -DNCHECK=ON\n#     cmake --build build\noption(BUILD_SHARED_LIBS \"Build shared libraries\" OFF)\noption(NCHECK \"Dinsable for checking for more fast decoding\" OFF)\n# default=partial checking, detect allmost all errors\noption(FULLCHECK \"Enable full base64 checking\" OFF)\noption(NAVX512 \"Disable AVX512\" OFF)\noption(BUILD_APP \"Build executables\" OFF)\n\nmessage(STATUS \"Configuring with CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}\")\nif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL \"x86_64\")\n    set(ARCH_AMD64 ON)\nelseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL \"aarch64\" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL \"arm64\")\n    set(ARCH_AARCH64 ON)\nelseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL \"ppc64le\")\n    set(ARCH_PPC64LE ON)\nendif()\n\nset(CMAKE_C_FLAGS_RELEASE \"-O3\")\nset(CMAKE_C_FLAGS_DEBUG \"-O0 -ggdb\")\n\n# Set compiler options.\nif(NCHECK)\n    add_compile_definitions(NB64CHECK)\nendif()\nif(FULLCHECK)\n    add_compile_definitions(DB64CHECK)\nendif()\nif(NAVX512)\n    add_compile_definitions(NAVX512)\nendif()\n\nif(ARCH_PPC64LE)\n    set(MARCH \"-march=power9 -mtune=power9\")\n    set(MSSE \"-D__SSSE3__\")\nelseif(ARCH_AARCH64)\n    set(MARCH \"-march=armv8-a\")\nelse()\n    set(MARCH \"-march=native\")\n    set(MSSE \"-mssse3\")\nendif()\n\n# Object library is just a bunch of object files.\nadd_library(_b64_scalar OBJECT turbob64c.c turbob64d.c)\ntarget_compile_options(_b64_scalar PRIVATE ${MARCH} -falign-loops)\n\n# turbob64v128.c contains code for SSE, AVX, NEON, Power9.\n# It's compiled twice with different flags.\nadd_library(_b64_v128 OBJECT turbob64v128.c)\ntarget_compile_options(_b64_v128 PRIVATE ${MSSE} -falign-loops)\n\n# Use a list to collect all object libraries.\nset(_b64_objs _b64_scalar _b64_v128)\n\nif(ARCH_AMD64)\n    # Compile turbob64v128.c for the second time.\n    add_library(_b64_avx OBJECT turbob64v128.c)\n    target_compile_options(_b64_avx PRIVATE -march=corei7-avx -mtune=corei7-avx -mno-aes -fstrict-aliasing)\n    list(APPEND _b64_objs _b64_avx)\n\n    add_library(_b64_v256 OBJECT turbob64v256.c)\n    target_compile_options(_b64_v256 PRIVATE -march=haswell -fstrict-aliasing -falign-loops)\n    list(APPEND _b64_objs _b64_v256)\n\n    add_library(_b64_v512 OBJECT turbob64v512.c)\n    target_compile_options(_b64_v512 PRIVATE -march=skylake-avx512 -mavx512vbmi -fstrict-aliasing -falign-loops)\n    list(APPEND _b64_objs _b64_v512)\nendif()\n\nif(BUILD_SHARED_LIBS)\n    add_library(base64 SHARED)\nelse()\n    add_library(base64 STATIC)\nendif()\n\nforeach(_obj ${_b64_objs})\n    set_target_properties(${_obj} PROPERTIES POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS})\n    target_sources(base64 PRIVATE $<TARGET_OBJECTS:${_obj}>)\nendforeach()\n\n# The XCODE fix is from https://github.com/ClickHouse/ClickHouse/blob/cf7d354a693f15fc5941edbf39e295d0bf8de21c/contrib%2Fbase64-cmake%2FCMakeLists.txt#L46-L54\nif(XCODE OR XCODE_VERSION)\n    # https://gitlab.kitware.com/cmake/cmake/issues/17457\n    # Some native build systems may not like targets that have only object files, so consider adding at least one real source file\n    # This applies to Xcode.\n    if(NOT EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/dummy.c\")\n        file(WRITE \"${CMAKE_CURRENT_BINARY_DIR}/dummy.c\" \"\")\n    endif()\n    target_sources(base64 PRIVATE \"${CMAKE_CURRENT_BINARY_DIR}/dummy.c\")\nendif()\n\nif(BUILD_APP)\n    add_executable(tb64app tb64app.c)\n    target_link_libraries(tb64app base64)\nendif()\n\n# Set package information.\nset(PACKAGE_NAME ${PROJECT_NAME})\nset(PACKAGE_NAMESPACE \"turbo::\")\n\n# For CMAKE_INSTALL_{INCLUDEDIR,LIBDIR} etc.\ninclude(GNUInstallDirs)\nset(CONFIG_INSTALL_DIR \"${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}\")\n\n# Please refer \"Modern CMake\" on how to install a library.\n# https://cliutils.gitlab.io/modern-cmake/chapters/install/installing.html\n# Also refer to cmake documentation\n# https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html\n\n# Set PUBLIC_HEADER property for install(TARGETS) to install header file.\nset_target_properties(base64 PROPERTIES PUBLIC_HEADER \"${CMAKE_SOURCE_DIR}/turbob64.h\")\n# Set includes destination for install(TARGETS), which will be added\n# to INTERFACE_INCLUDE_DIRECTORIES target property.\n# So user only need to call \"target_link_libraries(turbo::base64)\", without\n# needing to set include directories.\ntarget_include_directories(\n    base64 SYSTEM PUBLIC\n    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> # For being used from add_subdirectory.\n    $<INSTALL_INTERFACE:include> # When being used from an installation.\n)\n\n# Installs library along with header files.\n# Also associates the installed target files with an export.\ninstall(\n    TARGETS base64\n    EXPORT ${PACKAGE_NAME}-targets\n    PUBLIC_HEADER DESTINATION \"${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME}\"\n)\n\n# Generates and installs cmake config files containing exported targets.\ninstall(\n    EXPORT ${PACKAGE_NAME}-targets\n    DESTINATION \"${CONFIG_INSTALL_DIR}\"\n    NAMESPACE ${PACKAGE_NAMESPACE}\n)\n\n# Generate cmake config-files from template.\ninclude(CMakePackageConfigHelpers)\nconfigure_package_config_file(\n    \"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PACKAGE_NAME}-config.cmake.in\"\n    ${PACKAGE_NAME}-config.cmake\n    INSTALL_DESTINATION \"${CONFIG_INSTALL_DIR}\"\n    #NO_CHECK_REQUIRED_COMPONENTS_MACRO\n    # PATH_VARS can be referenced in config template file with PACKAGE_<var>.\n    PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR\n    )\ninstall(\n    FILES\n    \"${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake\"\n    DESTINATION \"${CONFIG_INSTALL_DIR}\"\n)\n\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "## Turbo Base64:Fastest Base64 SSE/AVX2/AVX512/Neon/Altivec\n[![Build ubuntu](https://github.com/powturbo/Turbo-Base64/actions/workflows/build.yaml/badge.svg)](https://github.com/powturbo/Turbo-Base64/actions/workflows/build.yaml)\n\n##### **Fastest Base64 SIMD** Encoding library\n * 100% C (C++ headers), as simple as memcpy\n * No other base64 library encode or decode faster\n * :sparkles: **Scalar** can be faster than other SSE or ARM Neon based base64 libraries\n * **SSE** faster than other SSE/AVX/AVX2! base64 library\n * Fastest **AVX2** implementation \n * TurboBase64 AVX2 decoding up to ~2x faster than other AVX2 libs.\n * TurboBase64 is 3,5-4 times faster than other libs for short strings\n * Fastest **ARM Neon** base64\n * :new:(2023.04) avx512 - 2x faster than avx2, faster than any other implementation\n * :+1: Dynamic CPU detection and **JIT scalar/sse/avx/avx2/avx512** switching\n * Base64 robust **error checking**, optimized for **long+short** strings\n * Portable library, 32/64 bits, **SSE/AVX/AVX2/AVX512**, **ARM Neon**, **Power9 Altivec**\n * OS:Linux amd64, arm64, Power9, MacOs+Apple M1, s390x. Windows: Mingw, visual c++\n * Big endian + Little endian\n * Ready and simple to use library, no armada of files, no hassles dependencies\n * **LICENSE GPL 3** . Commercial license available. Contact us at powturbo [_AT_] gmail [_DOT_] com\n<p>\n\t\n------------------------------------------------------------------------\n\t\nDownload Turbo-Base64 executable benchmark tb64app from \n[releases](https://github.com/powturbo/Turbo-Base64/releases/tag/2023.04),\nextract the files and type \"tb64app\"</br>\n\n## Benchmark incl. the best SIMD Base64 libs:\n- Single thread\n- Including base64 error checking\n- Small file + realistic and practical (no PURE cache) benchmark \n- Unlike other benchmarks, the best of the best scalar+simd libraries are included\n- all libraries with the latest version\n\n#### Benchmark AMD CPU: AMD Ryzen 9 7950X @ 4,50 GHz, DDR5 6000 CL30 - gcc-12.2\n|E Size|ratio%|E MB/s|D MB/s|1,000,000 bytes - 2023.07 |\n|--------:|-----:|--------:|--------:|----------------|\n|1333336|133.33%|**77619**|**76716**|**8:tb64v512vbmi**|\n|1333336|133.33%|41325| 48783| 7:_tb64v256 avx2| \n|1333336|133.33%|45292| 46665| 5:tb64v256  avx2|\n|1000000|100.00%|37047| 31694|10:memcpy        | \n|1333336|133.33%|25077| 28537| 4:tb64v128a avx | \n|1333336|133.33%|24375| 27880| 3:tb64v128      | \n|1333336|133.33%| 9513|  6908| 2:tb64x         | \n|1333336|133.33%| 9513|  5975| 9:_tb64x        | \n|1333336|133.33%| 4914|  5182| 1:tb64s         | \n\n\n|E Size|ratio%|E MB/s|D MB/s|10,000 bytes - 2023.07 |\n|--------:|-----:|--------:|--------:|----------------|\n|13336|133.36%|**89079**|**92006**|**8:tb64v512vbmi**|\n|10000|100.00%|84418|  85703|10:memcpy            |\n|13336|133.36%|34963|  46216| 7:_tb64v256 avx2    |\n|13336|133.36%|40722|  44552| 5:tb64v256  avx2    |\n|13336|133.36%|22601|  27298| 4:tb64v128a avx     |\n|13336|133.36%|21113|  26930| 3:tb64v128          |\n|13336|133.36%| 9648|   6809| 2:tb64x             |\n|13336|133.36%| 9626|   5599| 9:_tb64x            |\n|13336|133.36%| 4937|   5184| 1:tb64s             |\n\n#### Benchmark Intel CPU: i7-9700k 3.6GHz gcc 11.2\n|E Size|ratio%|E MB/s|D MB/s|Name|50,000 bytes - 2022.02 |\n|--------:|-----:|--------:|--------:|----------------|----------------|\n|66668|133.3|**32794**|**37837**|[**tb64v256**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|\n|66668|133.3|27789|22264|[b64avx2](https://github.com/aklomp/base64)|aklomp Base64 avx2|\n|66668|133.3|25305|21980|[fb64avx2](https://github.com/lemire/fastbase64)|lemire Fastbase64 avx2|\n|||||||\n|66668|133.3|**17348**|**20686**|[**tb64v128a**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx**|\n|66668|133.3|**16035**|**18865**|[**tb64v128**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 sse**|\n|66668|133.3|15820|13078|[b64avx](https://github.com/aklomp/base64)|aklomp Base64 avx|\n|66668|133.3|15322|11302|[b64sse](https://github.com/aklomp/base64)|aklomp Base64 sse41|\n|50000|100.0|47593|47623|memcpy||\n\n|E Size|ratio%|E MB/s|D MB/s|Name| 1 MB - 2022.02|\n|--------:|-----:|--------:|--------:|----------------|----------------|\n|1333336|133.3|**29086**|**29748**|[**tb64v256**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|\n|1333336|133.3|26153|22515|[b64avx2](https://github.com/aklomp/base64)|Base64 avx2|\n|1333336|133.3|23686|21231|[fb64avx2](https://github.com/lemire/fastbase64)|Fastbase64 avx2|\n|||||||\n|1333336|133.3|**16897**|**20215**|[**tb64v128a**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx**|\n|1333336|133.3|**15932**|**18749**|[**tb64v128**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 sse**|\n|1333336|133.3|15537|12959|[b64avx](https://github.com/aklomp/base64)|Base64 avx|\n|1333336|133.3|15135|11304|[b64sse](https://github.com/aklomp/base64)|Base64 sse41|\n|||||||\n|1333336|133.3|**6546**|**5473**|[**TB64x**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 scalar**|\n|1333336|133.3|6495|4454|[b64plain](https://github.com/aklomp/base64)|Base64 plain|\n|1333336|133.3|1908|2752|[TB64s](https://github.com/powturbo/TurboBase64)|**Turbo Base64 scalar**|\n|1333336|133.3|2541|4289|[chrome](https://github.com/lemire/fastbase64)|Google Chrome base64|\n|1333336|133.3|2670|2299|[fb64plain](https://github.com/lemire/fastbase64)|FastBase64 plain|\n|1333334|135.4|1754|219|[linux](https://github.com/lemire/fastbase64)|Linux base64|\n|1000000|100.0|28688|28656|memcpy||\n\n<a name=\"short\"></a> TurboBase64 vs. Base64 for short strings (incl. checking)\n|String length|E MB/s|D MB/s|Name|50,000 bytes - short strings 2022.02 |\n|------------:|--------:|--------:|----------------|----------------|\n| 4 - 16      |**2330**|**2161**|[**TB64avx2**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|\n|             |891|734|[b64avx2](https://github.com/aklomp/base64)|Base64 avx2|\n| 8 - 32      |**3963**|**3570**|[**TB64avx2**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|\n|             |1348|943|[b64avx2](https://github.com/aklomp/base64)|Base64 avx2|\n| 16 - 64     |**6881**|**5937**|[**TB64avx2**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|\n|             |2509|1488|[b64avx2](https://github.com/aklomp/base64)|Base64 avx2|\n| 32 - 128    |**10946**|**8880**|[**TB64avx2**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 avx2**|\n|             |4902|2777|[b64avx2](https://github.com/aklomp/base64)|Base64 avx2|\n\n###### Benchmark ARM Neon: Apple M1 3,5GHz (clang 12.0)\n|E MB/s|size|ratio| D MB/s| 50,000 bytes (2023.08) |\n|--------|-----------:|------:|----------:|-----------------------------|\n|24012.43|66668|133.34%|15352.09|tb64v128 (turbo-base64)|\n|19087.55|66668|133.34%|12515.17|b64neon64 (aklomp/base64)|\n|5611.48|66668|133.34%|5092.64|tb64s|\n|9782.45|66668|133.34%|6798.98|tb64x|\n|6181.37|66668|133.34%|3108.54|b64plain|\n|45566.16|50000|100.00%|45484.13|memcpy|\n\n###### Benchmark ARM Neon: ARMv8 A73-ODROID-N2 1.8GHz (clang 6.0)\n|E Size|ratio%|E MB/s|D MB/s|Name|30MB binary 2019.12|\n|--------:|-----:|--------:|--------:|----------------|----------------|\n|40000000|133.3|**2026**|**1650**|[**TB64neon**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 Neon**|\n|40000000|133.3|1795|1285|[b64neon64](https://github.com/aklomp/base64)|Base64 Neon|\n|40000000|133.3|**1270**|**1095**|[**TB64x**](https://github.com/powturbo/TurboBase64)|**Turbo Base64 scalar**|\n|40000000|133.3|695|965|[TB64s](https://github.com/powturbo/TurboBase64)|**Turbo Base64 scalar**|\n|40000000|133.3|512|782|[fb64neon](https://github.com/lemire/fastbase64)|Fastbase64 SIMD Neon|\n|40000000|133.3|565|460|[Chrome](https://github.com/lemire/fastbase64)|Google Chrome base64|\n|40000000|133.3|642|614|[b64plain](https://github.com/aklomp/base64)|Base64 plain|\n|40000000|133.3|506|548|[fb64plain](https://github.com/lemire/fastbase64)|Fastbase64 plain|\n|40500000|135.4|314|91|[Linux](https://github.com/lemire/fastbase64)|Linux base64|\n|30000000|100.0|3820|3834|memcpy||\n\n- (**bold** = pareto in category)  MB=1.000.000<br />\n- (E/D) : Encode/Decode\n- Timmings are respectively relative to the base64 output/input in encode/decode.\n\n\n<p>\n\n## Compile: (Download or clone Turbo Base64 SIMD)\n        git clone https://github.com/powturbo/Turbo-Base64.git\n        make\n\n## Usage: (Benchmark App)\n\n        ./tb64app file \n        or  \n        ./tb64app\n\n## Function usage:\n\n>**static inline unsigned turbob64len(unsigned n)**<br />\n\tBase64 output length after encoding\n\n>**unsigned tb64enc(const unsigned char *in, unsigned inlen, unsigned char *out)**<br />\n\tEncode binary input 'in' buffer into base64 string 'out'<br />\n\twith automatic cpu detection for simd and switch (sse/avx2/scalar<br />\n\t**in**          : Input buffer to encode<br />\n\t**inlen**       : Length in bytes of input buffer<br />\n\t**out**         : Output buffer<br />\n\t**return value**: Length of output buffer<br />\n\t**Remark**      : byte 'zero' is not written to end of output stream<br />\n    \t         \t  Caller must add 0 (out[outlen] = 0) for a null terminated string<br />\n\n\n>**unsigned tb64dec(const unsigned char *in, unsigned inlen, unsigned char *out)**<br />\n\tDecode base64 input 'in' buffer into binary buffer 'out' <br />\n\t**in**          : input buffer to decode<br />\n\t**inlen**       : length in bytes of input buffer <br />\n\t**out**         : output buffer<br />\n\t**return value**: >0 output buffer length<br />\n                      0 Error (invalid base64 input or input length = 0)<br />\n\n### Environment:\n\n###### OS/Compiler (32 + 64 bits):\n- Windows: Visual C++ (2017)\n- Windows: MinGW-w64 makefile\n- Linux amd/intel: GNU GCC (>=4.6)\n- Linux amd/intel: Clang (>=3.2) \n- Linux arm: aarch64 ARMv8 Neon: gcc (>=6.3) \n- Linux arm: aarch64 ARMv8 Neon: clang (>=6.0) \n- MaxOS: XCode (>=9), apple M1\n- PowerPC ppc64le: gcc (>=8.0) incl. SIMD Altivec\n\n###### References:\n- [fastbase v2022.02](https://github.com/lemire/fastbase64)\n- [base64 v2022.02](https://github.com/aklomp/base64)\n- [base64simd](https://github.com/WojciechMula/base64simd)\n\n###### * **SIMD Base64 publications:**\n  * :green_book:[Faster Base64 Encoding and Decoding Using AVX2 Instructions](https://arxiv.org/abs/1704.00605)\n  * :green_book:[RFC 4648:The Base16, Base32, and Base64 Data Encodings](https://tools.ietf.org/html/rfc4648)\n\nLast update: 06 AUG 2023\n"
  },
  {
    "path": "cmake/turbobase64-config.cmake.in",
    "content": "@PACKAGE_INIT@\n\n# Usage:\n#\n#     find_pacakge(@PACKAGE_NAME@)\n#\n#     add_executable(foo)\n#     target_link_libraries(foo @PACKAGE_NAMESPACE@base64)\n\nset_and_check(@PACKAGE_NAME@_INCLUDE_DIRS \"@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@\")\nset_and_check(@PACKAGE_NAME@_LIBRARY_DIRS \"@PACKAGE_CMAKE_INSTALL_LIBDIR@\")\n\nset(@PACKAGE_NAME@_LIBRARIES @PACKAGE_NAMESPACE@base64)\n\ninclude(${CMAKE_CURRENT_LIST_DIR}/@PACKAGE_NAME@-targets.cmake)\n\ncheck_required_components(@PACKAGE_NAME@)\n"
  },
  {
    "path": "conf.h",
    "content": "/**\n    Copyright (C) powturbo 2016-2023\n    GPL v3 License\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\n    - homepage : https://sites.google.com/site/powturbo/\n    - github   : https://github.com/powturbo\n    - twitter  : https://twitter.com/powturbo\n    - email    : powturbo [_AT_] gmail [_DOT_] com\n**/\n\n// conf.h - config & common\n#ifndef CONF_H_\n#define CONF_H_\n#if defined(_MSC_VER) && (_MSC_VER < 1600)\n  #if !defined(_STDINT) && !defined(_MSC_STDINT_H_)\ntypedef unsigned char      uint8_t;\ntypedef unsigned short     uint16_t;\ntypedef unsigned int       uint32_t;\ntypedef unsigned long long uint64_t;\n  #endif\n#else\n#include <stdint.h>\n#endif\n#include <stddef.h>\n#define __STDC_WANT_IEC_60559_TYPES_EXT__\n#include <float.h>\n#if defined(__clang__) && defined(__is_identifier)\n  #if !__is_identifier(_Float16)\n    #undef FLT16_BUILTIN\n  #endif\n#elif defined(FLT16_MAX)\n#define FLT16_BUILTIN\n#endif\n\n//------------------------- Compiler ------------------------------------------\n  #if defined(__GNUC__)\n#include <stdint.h>\n#define ALIGNED(t,v,n)  t v __attribute__ ((aligned (n)))\n#define ALWAYS_INLINE   inline __attribute__((always_inline))\n#define NOINLINE        __attribute__((noinline))\n#define _PACKED         __attribute__ ((packed))\n#define likely(x)       __builtin_expect((x),1)\n#define unlikely(x)     __builtin_expect((x),0)\n\n//#define bswap8(x)    (x)\n    #if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 8\n#define bswap16(x) __builtin_bswap16(x)\n    #else\nstatic ALWAYS_INLINE unsigned short bswap16(unsigned short x) { return __builtin_bswap32(x << 16); }\n    #endif\n#define bswap32(x) __builtin_bswap32(x)\n#define bswap64(x) __builtin_bswap64(x)\n\n#define popcnt32(_x_)   __builtin_popcount(_x_)\n#define popcnt64(_x_)   __builtin_popcountll(_x_)\n\n    #if defined(__i386__) || defined(__x86_64__)\n//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,...\n//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,...\nstatic ALWAYS_INLINE int    __bsr32(               int x) {             asm(\"bsr  %1,%0\" : \"=r\" (x) : \"rm\" (x) ); return x; }\nstatic ALWAYS_INLINE int      bsr32(               int x) { int b = -1; asm(\"bsrl %1,%0\" : \"+r\" (b) : \"rm\" (x) ); return b + 1; }\nstatic ALWAYS_INLINE int      bsr64(uint64_t x          ) { return x?64 - __builtin_clzll(x):0; }\nstatic ALWAYS_INLINE int    __bsr64(uint64_t x          ) { return   63 - __builtin_clzll(x);   }\n\nstatic ALWAYS_INLINE unsigned rol32(unsigned x, int s) { asm (\"roll %%cl,%0\" :\"=r\" (x) :\"0\" (x),\"c\" (s)); return x; }\nstatic ALWAYS_INLINE unsigned ror32(unsigned x, int s) { asm (\"rorl %%cl,%0\" :\"=r\" (x) :\"0\" (x),\"c\" (s)); return x; }\nstatic ALWAYS_INLINE uint64_t rol64(uint64_t x, int s) { asm (\"rolq %%cl,%0\" :\"=r\" (x) :\"0\" (x),\"c\" (s)); return x; }\nstatic ALWAYS_INLINE uint64_t ror64(uint64_t x, int s) { asm (\"rorq %%cl,%0\" :\"=r\" (x) :\"0\" (x),\"c\" (s)); return x; }\n    #else\nstatic ALWAYS_INLINE int    __bsr32(unsigned x          ) { return   31 - __builtin_clz(  x); }\nstatic ALWAYS_INLINE int      bsr32(int x               ) { return x?32 - __builtin_clz(  x):0; }\nstatic ALWAYS_INLINE int      bsr64(uint64_t x) { return x?64 - __builtin_clzll(x):0; }\nstatic ALWAYS_INLINE int    __bsr64(uint64_t x          ) { return   63 - __builtin_clzll(x);   }\n\nstatic ALWAYS_INLINE unsigned rol32(unsigned x, int s) { return x << s | x >> (32 - s); }\nstatic ALWAYS_INLINE unsigned ror32(unsigned x, int s) { return x >> s | x << (32 - s); }\nstatic ALWAYS_INLINE unsigned rol64(unsigned x, int s) { return x << s | x >> (64 - s); }\nstatic ALWAYS_INLINE unsigned ror64(unsigned x, int s) { return x >> s | x << (64 - s); }\n    #endif\n\n#define ctz64(_x_) __builtin_ctzll(_x_)\n#define ctz32(_x_) __builtin_ctz(_x_)    // 0:32  ctz32(1<<a) = a (a=1..31)\n#define clz64(_x_) __builtin_clzll(_x_)\n#define clz32(_x_) __builtin_clz(_x_)    // 00000000 00000000 00000000 01000000 = 25\n\n  #elif _MSC_VER //----------------------------------------------------\n#include <windows.h>\n#include <intrin.h>\n    #if _MSC_VER < 1600\n#include \"vs/stdint.h\"\n#define __builtin_prefetch(x,a)\n#define inline          __inline\n    #else\n#include <stdint.h>\n#define __builtin_prefetch(x,a) _mm_prefetch(x, _MM_HINT_NTA)\n    #endif\n\n#define ALIGNED(t,v,n)  __declspec(align(n)) t v\n#define ALWAYS_INLINE   __forceinline\n#define NOINLINE        __declspec(noinline)\n#define _PACKED         //__attribute__ ((packed))\n#define THREADLOCAL     __declspec(thread)\n#define likely(x)       (x)\n#define unlikely(x)     (x)\n\nstatic ALWAYS_INLINE int __bsr32(unsigned x) { unsigned long z=0; _BitScanReverse(&z, x); return z; }\nstatic ALWAYS_INLINE int bsr32(  unsigned x) { unsigned long z;   _BitScanReverse(&z, x); return x?z+1:0; }\nstatic ALWAYS_INLINE int ctz32(  unsigned x) { unsigned long z;   _BitScanForward(&z, x); return x?z:32; }\nstatic ALWAYS_INLINE int clz32(  unsigned x) { unsigned long z;   _BitScanReverse(&z, x); return x?31-z:32; }\n  #if !defined(_M_ARM64) && !defined(_M_X64)\nstatic ALWAYS_INLINE unsigned char _BitScanForward64(unsigned long* ret, uint64_t x) {\n  unsigned long x0 = (unsigned long)x, top, bottom;         _BitScanForward(&top, (unsigned long)(x >> 32)); _BitScanForward(&bottom, x0);\n  *ret = x0 ? bottom : 32 + top;  return x != 0;\n}\nstatic unsigned char _BitScanReverse64(unsigned long* ret, uint64_t x) {\n  unsigned long x1 = (unsigned long)(x >> 32), top, bottom; _BitScanReverse(&top, x1);                       _BitScanReverse(&bottom, (unsigned long)x);\n  *ret = x1 ? top + 32 : bottom;  return x != 0;\n}\n  #endif\nstatic ALWAYS_INLINE int __bsr64(uint64_t x) { unsigned long z = 0; _BitScanReverse64(&z, x); return z; }\nstatic ALWAYS_INLINE int bsr64(uint64_t x) { unsigned long z=0; _BitScanReverse64(&z, x); return x?z+1:0; }\nstatic ALWAYS_INLINE int ctz64(uint64_t x) { unsigned long z;   _BitScanForward64(&z, x); return x?z:64; }\nstatic ALWAYS_INLINE int clz64(uint64_t x) { unsigned long z;   _BitScanReverse64(&z, x); return x?63-z:64; }\n\n#define rol32(x,s) _lrotl(x, s)\n#define ror32(x,s) _lrotr(x, s)\n\n#define bswap16(x) _byteswap_ushort(x)\n#define bswap32(x) _byteswap_ulong(x)\n#define bswap64(x) _byteswap_uint64(x)\n\n#define popcnt32(x) __popcnt(x)\n  #ifdef _WIN64\n#define popcnt64(x) __popcnt64(x)\n  #else\n#define popcnt64(x) (popcnt32(x) + popcnt32(x>>32))\n  #endif\n\n#define sleep(x)     Sleep(x/1000)\n#define fseeko       _fseeki64\n#define ftello       _ftelli64\n#define strcasecmp   _stricmp\n#define strncasecmp  _strnicmp\n#define strtoull     _strtoui64\nstatic ALWAYS_INLINE double round(double num) { return (num > 0.0) ? floor(num + 0.5) : ceil(num - 0.5); }\n  #endif\n\n#define __bsr8(_x_)  __bsr32(_x_)\n#define __bsr16(_x_) __bsr32(_x_)\n#define bsr8(_x_)    bsr32(_x_)\n#define bsr16(_x_)   bsr32(_x_)\n#define ctz8(_x_)    ctz32((_x_)+(1<< 8))\n#define ctz16(_x_)   ctz32((_x_)+(1<<16))\n#define clz8(_x_)    (clz32(_x_)-24)\n#define clz16(_x_)   (clz32(_x_)-16)\n\n#define popcnt8(x)   popcnt32(x)\n#define popcnt16(x)  popcnt32(x)\n\n//--------------- Unaligned memory access -------------------------------------\n  #ifdef UA_MEMCPY\n#include <string.h>\nstatic ALWAYS_INLINE unsigned short     ctou16(const void *cp) { unsigned short     x; memcpy(&x, cp, sizeof(x)); return x; } // ua read\nstatic ALWAYS_INLINE unsigned           ctou32(const void *cp) { unsigned           x; memcpy(&x, cp, sizeof(x)); return x; }\nstatic ALWAYS_INLINE unsigned long long ctou64(const void *cp) { unsigned long long x; memcpy(&x, cp, sizeof(x)); return x; }\nstatic ALWAYS_INLINE size_t             ctousz(const void *cp) { size_t             x; memcpy(&x, cp, sizeof(x)); return x; }\n#ifdef FLT16_BUILTIN\nstatic ALWAYS_INLINE _Float16           ctof16(const void *cp) { _Float16           x; memcpy(&x, cp, sizeof(x)); return x; }\n#endif\nstatic ALWAYS_INLINE float              ctof32(const void *cp) { float              x; memcpy(&x, cp, sizeof(x)); return x; }\nstatic ALWAYS_INLINE double             ctof64(const void *cp) { double             x; memcpy(&x, cp, sizeof(x)); return x; }\n\nstatic ALWAYS_INLINE void               stou16(      void *cp, unsigned short     x) { memcpy(cp, &x, sizeof(x)); } // ua write\nstatic ALWAYS_INLINE void               stou32(      void *cp, unsigned           x) { memcpy(cp, &x, sizeof(x)); }\nstatic ALWAYS_INLINE void               stou64(      void *cp, unsigned long long x) { memcpy(cp, &x, sizeof(x)); }\nstatic ALWAYS_INLINE void               stousz(      void *cp, size_t             x) { memcpy(cp, &x, sizeof(x)); }\n#ifdef FLT16_BUILTIN\nstatic ALWAYS_INLINE void               stof16(      void *cp, _Float16           x) { memcpy(cp, &x, sizeof(x)); }\n#endif\nstatic ALWAYS_INLINE void               stof32(      void *cp, float              x) { memcpy(cp, &x, sizeof(x)); }\nstatic ALWAYS_INLINE void               stof64(      void *cp, double             x) { memcpy(cp, &x, sizeof(x)); }\n\nstatic ALWAYS_INLINE void               ltou32(unsigned           *x, const void *cp) { memcpy(x, cp, sizeof(*x)); } // ua read into ptr \nstatic ALWAYS_INLINE void               ltou64(unsigned long long *x, const void *cp) { memcpy(x, cp, sizeof(*x)); }\n\n  #elif defined(__i386__) || defined(__x86_64__) || \\\n    defined(_M_IX86) || defined(_M_AMD64) || _MSC_VER ||\\\n    defined(__powerpc__) || defined(__s390__) ||\\\n    defined(__ARM_FEATURE_UNALIGNED) || defined(__aarch64__) || defined(__arm__) ||\\\n    defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \\\n    defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__) || \\\n    defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__)  || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6Z__)   || defined(__ARM_ARCH_6ZK__)\n#define ctou16(_cp_) (*(unsigned short *)(_cp_))\n#define ctou32(_cp_) (*(unsigned       *)(_cp_))\n#define ctof16(_cp_) (*(_Float16       *)(_cp_))\n#define ctof32(_cp_) (*(float          *)(_cp_))\n\n#define stou16(_cp_, _x_)  (*(unsigned short *)(_cp_) = _x_)\n#define stou32(_cp_, _x_)  (*(unsigned       *)(_cp_) = _x_)\n#define stof16(_cp_, _x_)  (*(_Float16       *)(_cp_) = _x_)\n#define stof32(_cp_, _x_)  (*(float          *)(_cp_) = _x_)\n\n#define ltou32(_px_, _cp_) *(_px_) = *(unsigned *)(_cp_)\n\n    #if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || defined(__s390__) || defined(_MSC_VER)\n#define ctou64(_cp_)       (*(uint64_t *)(_cp_))\n#define ctof64(_cp_)       (*(double   *)(_cp_))\n\n#define stou64(_cp_, _x_)  (*(uint64_t *)(_cp_) = _x_)\n#define stof64(_cp_, _x_)  (*(double   *)(_cp_) = _x_)\n\n#define ltou64(_px_, _cp_) *(_px_) = *(uint64_t *)(_cp_)\n\n    #elif defined(__ARM_FEATURE_UNALIGNED)\nstruct _PACKED longu     { uint64_t l; };\nstruct _PACKED doubleu   { double   d; };\n#define ctou64(_cp_) ((struct longu     *)(_cp_))->l\n#define ctof64(_cp_) ((struct doubleu   *)(_cp_))->d\n\n#define stou64(_cp_) ((struct longu     *)(_cp_))->l = _x_\n#define stof64(_cp_) ((struct doubleu   *)(_cp_))->d = _x_\n#define ltou64(_px_, _cp_) *(_px_) = ((struct longu *)(_cp_))->l\n    #endif\n\n  #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7S__)\nstruct _PACKED shortu    { unsigned short     s; };\nstruct _PACKED unsignedu { unsigned           u; };\nstruct _PACKED longu     { uint64_t           l; };\n#ifdef FLT16_BUILTIN\nstruct _PACKED float16u  { _Float16           g; };\n#endif\nstruct _PACKED floatu    { float              f; };\nstruct _PACKED doubleu   { double             d; };\n\n#define ctou16(_cp_) ((struct shortu    *)(_cp_))->s\n#define ctou32(_cp_) ((struct unsignedu *)(_cp_))->u\n#define ctou64(_cp_) ((struct longu     *)(_cp_))->l\n#define ctof16(_cp_) ((struct float16u  *)(_cp_))->g\n#define ctof32(_cp_) ((struct floatu    *)(_cp_))->f\n#define ctof64(_cp_) ((struct doubleu   *)(_cp_))->d\n\n#define stou16(_cp_, _x_) ((struct shortu    *)(_cp_))->s = _x_\n#define stou32(_cp_, _x_) ((struct unsignedu *)(_cp_))->u = _x_\n#define stou64(_cp_, _x_) ((struct longu     *)(_cp_))->l = _x_\n#define stof16(_cp_, _x_) ((struct float16u  *)(_cp_))->g = _x_\n#define stof32(_cp_, _x_) ((struct floatu    *)(_cp_))->f = _x_\n#define stof64(_cp_, _x_) ((struct doubleu   *)(_cp_))->d = _x_\n\n#define ltou32(_cp_) *(_px_) = ((struct unsignedu *)(_cp_))->u\n#define ltou64(_cp_) *(_px_) = ((struct longu *)(_cp_))->l\n  #else\n#error \"unknown cpu\"\n  #endif\n\n#define ctou24(_cp_) (ctou32(_cp_) & 0xffffff)\n#define ctou48(_cp_) (ctou64(_cp_) & 0xffffffffffffull)\n#define ctou8(_cp_) (*(_cp_))\n//--------------------- wordsize ----------------------------------------------\n  #if defined(__64BIT__) || defined(_LP64) || defined(__LP64__) || defined(_WIN64) ||\\\n    defined(__x86_64__) || defined(_M_X64) ||\\\n    defined(__ia64) || defined(_M_IA64) ||\\\n    defined(__aarch64__) ||\\\n    defined(__mips64) ||\\\n    defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) ||\\\n    defined(__s390x__)\n#define __WORDSIZE 64\n  #else\n#define __WORDSIZE 32\n  #endif\n#endif\n\n//---------------------misc ---------------------------------------------------\n#define BZMASK64(_b_)                    (~(~0ull << (_b_)))\n#define BZMASK32(_b_)                    (~(~0u   << (_b_)))\n#define BZMASK16(_b_)                    BZMASK32(_b_)\n#define BZMASK8( _b_)                    BZMASK32(_b_)\n\n#define BZHI64(_u_, _b_)                 ((_u_) & BZMASK64(_b_))  // b Constant\n#define BZHI32(_u_, _b_)                 ((_u_) & BZMASK32(_b_)) \n#define BZHI16(_u_, _b_)                 BZHI32(_u_, _b_)\n#define BZHI8( _u_, _b_)                 BZHI32(_u_, _b_)\n#define BEXTR32(x,start,len)             (((x) >> (start)) & ((1u << (len)) - 1)) //Bit field extract (with register)\n\n    #ifdef __AVX2__\n      #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)\n#include <intrin.h>\n      #else\n#include <x86intrin.h>\n      #endif\n#define bzhi32(_u_, _b_)                 _bzhi_u32(_u_, _b_)  // b variable\n#define bextr32(x,start,len)             _bextr_u32(x,start,len)  \n\n      #if !(defined(_M_X64) || defined(__amd64__)) && (defined(__i386__) || defined(_M_IX86))\n#define bzhi64(_u_, _b_)                 BZHI64(_u_, _b_)\n      #else\n#define bzhi64(_u_, _b_)                 _bzhi_u64(_u_, _b_)\n      #endif\n    #else\n#define bzhi64(_u_, _b_)                 BZHI64(_u_, _b_) \n#define bzhi32(_u_, _b_)                 BZHI32(_u_, _b_)\n#define bextr32(x,start,len)             (((x) >> (start)) & ((1u << (len)) - 1)) //Bit field extract (with register)\n    #endif\n\n#define bzhi16(_u_, _b_)                 bzhi32(_u_, _b_)\n#define bzhi8( _u_, _b_)                 bzhi32(_u_, _b_)\n\n#define SIZE_ROUNDUP(_n_, _a_) (((size_t)(_n_) + (size_t)((_a_) - 1)) & ~(size_t)((_a_) - 1))\n#define ALIGN_DOWN(__ptr, __a) ((void *)((uintptr_t)(__ptr) & ~(uintptr_t)((__a) - 1)))\n\n#define T2_(_x_, _y_) _x_##_y_\n#define T2(_x_, _y_) T2_(_x_,_y_)\n\n#define T3_(_x_,_y_,_z_) _x_##_y_##_z_\n#define T3(_x_,_y_,_z_) T3_(_x_, _y_, _z_)\n\n#define CACHE_LINE_SIZE     64\n#define PREFETCH_DISTANCE   (CACHE_LINE_SIZE*4)\n\n#define CLAMP(_x_, _low_, _high_)  (((_x_) > (_high_)) ? (_high_) : (((_x_) < (_low_)) ? (_low_) : (_x_)))\n\n//--- NDEBUG -------\n#include <stdio.h>\n  #ifdef _MSC_VER\n    #ifdef NDEBUG\n#define AS(expr, fmt, ...)\n#define AC(expr, fmt, ...) do { if(!(expr)) { fprintf(stderr, fmt, ##__VA_ARGS__ ); fflush(stderr); exit(-1); } } while(0)\n#define die(fmt, ...) do { fprintf(stderr, fmt, ##__VA_ARGS__ ); fflush(stderr); exit(-1); } while(0)\n    #else\n#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)\n#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)\n#define die(fmt, ...) do { fprintf(stderr, \"%s:%s:%d:\", __FILE__, __FUNCTION__, __LINE__); fprintf(stderr, fmt, ##__VA_ARGS__ ); fflush(stderr); exit(-1); } while(0)\n    #endif\n  #else\n    #ifdef NDEBUG\n#define AS(expr, fmt,args...)\n#define AC(expr, fmt,args...) do { if(!(expr)) { fprintf(stderr, fmt, ## args ); fflush(stderr); exit(-1); } } while(0)\n#define die(fmt,args...) do { fprintf(stderr, fmt, ## args ); fflush(stderr); exit(-1); } while(0)\n    #else\n#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)\n#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)\n#define die(fmt,args...) do { fprintf(stderr, \"%s:%s:%d:\", __FILE__, __FUNCTION__, __LINE__); fprintf(stderr, fmt, ## args ); fflush(stderr); exit(-1); } while(0)\n    #endif\n  #endif\n"
  },
  {
    "path": "makefile",
    "content": "# powturbo  (c) Copyright 2016-2023\n# Linux: \"export CC=clang\" \"export CXX=clang\". windows mingw: \"set CC=gcc\" \"set CXX=g++\" or uncomment the CC,CXX lines\nCC ?= gcc\nCXX ?= g++\n#CC=aarch64-linux-gnu-gcc\n#CC=powerpc64le-linux-gnu-gcc\n\n# uncomment to disable checking for more faster decoding\n#NCHECK=1\n#uncomment for full base64 checking (default=partial checking, detect allmost all errors)\n#FULLCHECK=1\n#uncomment for use memcpy instead of unaligned loads\n#UAMEMCPY=1\n\n#NAVX512=1\n#NAVX2=1\n#NSSE=1\n#NAVX=1\n\n#RDTSC=1\n#XBASE64=1\n\n#CFLAGS+=-DDEBUG -g\nCFLAGS+=-DNDEBUG\n\n#------- OS/ARCH -------------------\nifneq (,$(filter Windows%,$(OS)))\n  OS := Windows\n  ARCH=x86_64\nelse\n  OS := $(shell uname -s)\n  ARCH := $(shell uname -m)\n\nifneq (,$(findstring aarch64,$(CC)))\n  ARCH = aarch64\nelse ifneq (,$(findstring arm64,$(ARCH)))\n  ARCH = aarch64\nelse ifneq (,$(findstring powerpc64le,$(CC)))\n  ARCH = ppc64le\nendif\nendif\n\nifeq ($(ARCH),ppc64le)\n  CFLAGS=-mcpu=power9 -mtune=power9\n  MSSE=-D__SSSE3__\nelse ifeq ($(ARCH),aarch64)\n  CFLAGS+=-march=armv8-a \nifneq (,$(findstring clang, $(CC)))\n  CFLAGS+=-fomit-frame-pointer\nendif\n  MSSE=-march=armv8-a\nelse ifeq ($(ARCH),$(filter $(ARCH),x86_64 ppc64le))\n  MSSE=-mssse3\nendif\nifeq (,$(findstring clang, $(CC)))\n  CFLAGS+=-falign-loops\nendif\n#---------------------------------------------------\nifeq ($(OS),$(filter $(OS),Linux GNU/kFreeBSD GNU OpenBSD FreeBSD DragonFly NetBSD MSYS_NT Haiku))\nLDFLAGS+=-lrt\nendif\n\nifeq ($(STATIC),1)\nLDFLAGS+=-static\nendif\n\nFPIC=-fPIC\n\nifeq ($(NCHECK),1)\nDEFS+=-DNB64CHECK\nelse\nifeq ($(FULLCHECK),1)\nDEFS+=-DB64CHECK\nendif\nendif\n\nifeq ($(RDTSC),1)\nDEFS+=-D_RDTSC\nendif\n\nifeq ($(UAMEMCPY),1)\nDEFS+=-DUA_MEMCPY\nendif\n\nifeq ($(XBASE64),1)\ninclude xtb64.mak\nendif\n\nall: tb64app libtb64.so libtb64.a\n\ntb64app.o:       CFLAGS+=$(XDEFS) $(MARCH) \nturbob64c.o:     CFLAGS+=$(DEFS) $(FPIC) -fstrict-aliasing $(MARCH)\nturbob64d.o:     CFLAGS+=$(DEFS) $(FPIC) -fstrict-aliasing $(MARCH)\nturbob64v128.o:  CFLAGS+=$(DEFS) $(FPIC) -fstrict-aliasing $(MSSE)\nturbob64v256.o:  CFLAGS+=$(DEFS) $(FPIC) -fstrict-aliasing -march=haswell\nturbob64v512.o:  CFLAGS+=$(DEFS) $(FPIC) -fstrict-aliasing -march=skylake-avx512 -mavx512vbmi\nturbob64v128a.o: turbob64v128.c\n\t$(CC) -O3 $(CFLAGS) $(DEFS) $(FPIC) -fstrict-aliasing -march=corei7-avx -mtune=corei7-avx -mno-aes $< -c -o turbob64v128a.o \n\n#_tb64.o: _tb64.c\n#\t$(CC) -O3 $(FPIC) -I/usr/include/python2.7 $< -c -o $@ \n\nLIB=turbob64c.o turbob64d.o turbob64v128.o\nifeq ($(ARCH),x86_64)\nLIB+=turbob64v128a.o turbob64v256.o\nifneq ($(NAVX512),1)\nLIB+=turbob64v512.o\nelse\nDEFS+=-DNAVX512\nendif\nendif\n\n#_tb64.so: _tb64.o\n#\t$(CC) -shared $^ -o $@\n\nlibtb64.a: $(LIB)\n\tar cr $@ $+\n\nlibtb64.so: $(LIB)\n\t$(CC) -shared $^ -o $@\n\t\ninstall:\n\tcp libtb64.so ~/.local/lib/\n\tcp libtb64.a ~/.local/lib/\n\t# FIXME: how does one build _tb64.so?\n\t# ./python/tb64/build.py\n\t# cp _tb64.so ~/.local/lib/\n\ntb64app: $(LIB) $(XLIB) tb64app.o \n\t$(CC) -O3 $(LIB) $(XLIB) $(XDEFS) tb64app.o $(LDFLAGS) -o tb64app\n\ntb64bench: $(LIB) tb64bench.o \n\t$(CC) -O3 $(LIB) tb64bench.o $(LDFLAGS) -o tb64bench\n\ntb64test: $(LIB) tb64test.o \n\t$(CC) -O3 $(LIB) tb64test.o $(LDFLAGS) -o tb64test\n\t\n.c.o:\n\t$(CC) -O3 $(CFLAGS) $< -c -o $@\n\n.cc.o:\n\t$(CXX) -O3 $(CXXFLAGS) $< -c -o $@\n\nifeq ($(OS),Windows)\nclean:\n\tdel /S *.o\n\tdel *.a\n\tdel *.so\nelse\nclean:\n\t@find . -type f -name \"*\\.o\" -delete -or -name \"*\\~\" -delete -or -name \"core\" -delete -or -name \"tb64app\" -delete -or -name \"_tb64.so\" \\\n\t-delete -or -name \"_tb64.c\" -delete -or -name \"xlibtb64.so\" -delete -or -name \"libtb64.a\" -delete -or -name \"libtb64.so\"\nendif\n"
  },
  {
    "path": "rust/.gitignore",
    "content": "target\nCargo.lock\n"
  },
  {
    "path": "rust/Cargo.toml",
    "content": "[package]\nauthors = [\"powturbo <powturbo [AT] gmail [DOT] com>\"]\nbuild = \"build.rs\"\nname = \"Turbo-Base64\"\nversion = \"0.60.0\"\n\n[dependencies]\nrand = \"0.8\"\n\n[build-dependencies]\nbindgen = \"*\"\n"
  },
  {
    "path": "rust/README.md",
    "content": "# Rust bindings for Turbo-Base64\n\nThis is a wrapper for [Turbo-Base64](https://github.com/powturbo/Turbo-Base64).\n\n## Installation\n1- Prerequistes: build and install the Turbo-Base64 library libtb64.a into /usr/local/lib  \n\n2 - Use the provided src/bindings.rs file or generate a new rust bindings.rs file.\n```shell\ncargo build\n```\n3 - Test \n```shell\ncargo test\n```\n## Examples\n - see the tests.rs file in the src folder\n - a list of public functions are available in the bindings.rs file\n \n## Reference\n- [bindgen automatically generates Rust FFI bindings to C and C++ libraries.](https://rust-lang.github.io/rust-bindgen/)\n"
  },
  {
    "path": "rust/build.rs",
    "content": "// build bindings.rs\nextern crate bindgen;\n\nuse std::env;\nuse std::path::PathBuf;\n\nfn main() {\n    println!(\"cargo:rustc-link-lib=tb64\");\n\n    let bindings = bindgen::Builder::default()\n        .header(\"wrapper.h\")\n        .generate()\n        .expect(\"Unable to generate bindings\");\n\n    let out_path = PathBuf::from(env::var(\"OUT_DIR\").unwrap());\n    bindings\n        .write_to_file(out_path.join(\"bindings.rs\"))\n        .expect(\"Couldn't write bindings!\");\n}\n"
  },
  {
    "path": "rust/src/bindings.rs",
    "content": "/* automatically generated by rust-bindgen 0.64.0  */\n\npub const TB64_VERSION : u32 = 100 ;\npub type wchar_t = :: std :: os :: raw :: c_int ; # [repr (C)] # [repr (align (16))] # [derive (Debug , Copy , Clone)]\npub struct max_align_t {\npub __clang_max_align_nonce1 : :: std :: os :: raw :: c_longlong ,\npub __bindgen_padding_0 : u64 ,\npub __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 () ;\n assert_eq ! (:: std :: mem :: size_of :: < max_align_t > () , 32usize , concat ! (\"Size of: \" , stringify ! (max_align_t))) ;\n assert_eq ! (:: std :: mem :: align_of :: < max_align_t > () , 16usize , concat ! (\"Alignment of \" , stringify ! (max_align_t))) ;\n 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))) ;\n 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))) ; }\nextern \"C\" { pub fn tb64enclen (inlen : usize) -> usize ; }\nextern \"C\" { pub fn tb64declen (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize) -> usize ; }\nextern \"C\" { pub fn tb64enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"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 ; }\nextern \"C\" { pub fn tb64senc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64sdec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64xenc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64xdec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64v128enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64v128dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64v128aenc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64v128adec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64v256enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64v256dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64v512enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64v512dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn tb64ini (id : :: std :: os :: raw :: c_uint , isshort : :: std :: os :: raw :: c_uint) ; }\nextern \"C\" { pub fn _tb64v256enc (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn _tb64v256dec (in_ : * const :: std :: os :: raw :: c_uchar , inlen : usize , out : * mut :: std :: os :: raw :: c_uchar) -> usize ; }\nextern \"C\" { pub fn cpuini (cpuisa : :: std :: os :: raw :: c_uint) -> :: std :: os :: raw :: c_uint ; }\nextern \"C\" { pub fn cpustr (cpuisa : :: std :: os :: raw :: c_uint) -> * mut :: std :: os :: raw :: c_char ; }\n"
  },
  {
    "path": "rust/src/lib.rs",
    "content": "// prerequisites: Install Turbo-Base64 library tb64lib under /usr/lib or /usr/local/lib  \n#![allow(non_upper_case_globals)]\n#![allow(non_camel_case_types)]\n#![allow(non_snake_case)]\n//include!(concat!(env!(\"OUT_DIR\"), \"/bindings.rs\"));\ninclude!(\"bindings.rs\");\n\n#[cfg(test)]\nmod tests;\n"
  },
  {
    "path": "rust/src/tests.rs",
    "content": "extern crate rand;\n\nuse std::convert::TryFrom;\nuse std::convert::TryInto;\nuse std::vec;\n\nuse super::*;\n\nfn decode_block(indata: &[u8]) -> Vec<u8> {\n    println!(\"dec size = {}\", indata.len());\n\n    if indata.len() == 0 {\n        return vec![];\n    }\n    unsafe {\n      let inlen = tb64declen(indata.as_ptr() as *mut ::std::os::raw::c_uchar, indata.len() );\n      let mut decoded_data = vec![0u8; inlen ];\n      let _ = tb64sdec(indata.as_ptr() as *mut ::std::os::raw::c_uchar, indata.len(), decoded_data.as_mut_ptr() as *mut u8);\n      return decoded_data;\n    }\n}\n\nfn encode_block(indata: &[u8]) -> Vec<u8> {\n    println!(\"enc size = {}\", indata.len());\n\n    unsafe {\n      let outlen = tb64enclen( indata.len() );\n      let mut encoded_indata = vec![0u8; outlen];\n      let _size = tb64senc(indata.as_ptr() as *mut u8, indata.len(), encoded_indata.as_mut_ptr() as *mut ::std::os::raw::c_uchar);\n      return encoded_indata;\n    }\n}\n\nfn test_block(inlen: usize) {\n    let mut source = Vec::with_capacity(inlen);\n    for i in 0..inlen {\n        if rand::random() {\n            source.push(u8::try_from(i+1).unwrap());\n        }\n    }\n\n    if source.is_empty() {\n        source = vec![1u8, 2]\n    }\n\n    let encoded = encode_block(&source[..]);\n    let decoded = decode_block(&encoded[..]);\n    assert_eq!(&source[..], &decoded[..]);\n}\n\n#[test]\nfn sample_tb64() {\n    let block_sizes = vec![1u32, 100, 3, 4, 8, 10, 16, 8, 32, 5, 64, 3, 128, 255];\n\n    for _ in 1..10 {\n        for size in &block_sizes[..] {\n            println!(\"testing with cap = {}\", size+0);\n            test_block((size+0).try_into().unwrap());\n        }\n    }\n}\n"
  },
  {
    "path": "rust/wrapper.h",
    "content": "// Include TurboPFor public c/c++ header\n#include \"../turbob64.h\"\n"
  },
  {
    "path": "tb64app.c",
    "content": "/**\n    Copyright (C) powturbo 2016-2023\n    SPDX-License-Identifier: GPL v3 License\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\n    - homepage : https://sites.google.com/site/powturbo/\n    - github   : https://github.com/powturbo\n    - twitter  : https://twitter.com/powturbo\n    - email    : powturbo [_AT_] gmail [_DOT_] com\n**/\n// Turbo-Base64: TB64app.c - Benchmark app\n\n#include <string.h> \n#include <stdio.h>\n#include <stdlib.h>\n#include <ctype.h>\n  #if !defined(_WIN32)  \n#include <sys/mman.h>\n#include <sys/resource.h>\n#include <unistd.h>\n#include <sys/types.h>\n#include <sys/param.h>\n  #else\n#include <io.h> \n#include <fcntl.h>\n  #endif\n\n#ifdef __APPLE__\n#include <sys/malloc.h>\n#else\n#include <malloc.h>\n#endif\n  #ifdef _MSC_VER\n#include \"vs/getopt.h\"\n  #else\n#include <getopt.h> \n#endif \n\n#include \"conf.h\"\n#include \"turbob64.h\"\n#include \"time_.h\"\n    #ifdef _WIN32 \nint getpagesize_() {\n  static int pagesize = 0;\n  if (pagesize == 0) {\n    SYSTEM_INFO system_info;\n    GetSystemInfo(&system_info);\n    pagesize = max(system_info.dwPageSize,\n                        system_info.dwAllocationGranularity);\n  }\n  return pagesize;\n} \n  #endif\n\n#include \"turbob64_.h\"\n\n  #ifdef XBASE64\n#define FAC 2\n#include \"xb64test.h\"\n  #else\n#define FAC 1\n  #endif\n  \n  #ifdef CRZY\n#include \"crzy64/crzy64.h\"\n  #endif\n//------------------------------- malloc ------------------------------------------------\n#define USE_MMAP\n  #if __WORDSIZE == 64\n#define MAP_BITS 30\n  #else\n#define MAP_BITS 28\n  #endif\n\nvoid *_valloc(size_t size, unsigned a) {\n  if(!size) return NULL;\n    #ifdef _WIN32\n  return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);\n    #elif defined(USE_MMAP) && !defined(__APPLE__)\n  void *ptr = mmap(NULL/*0(size_t)a<<MAP_BITS*/, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);\n  if(ptr == MAP_FAILED) return NULL;                                                        \n  return ptr;\n    #else\n  return malloc(size); \n    #endif\n}\n\nvoid _vfree(void *p, size_t size) {\n  if(!p) return;\n    #ifdef _WIN32\n  VirtualFree(p, 0, MEM_RELEASE);\n    #elif defined(USE_MMAP) && !defined(__APPLE__)\n  munmap(p, size);\n    #else\n  free(p);\n    #endif\n} \n\nint memcheck(unsigned char *in, unsigned n, unsigned char *cpy) { \n  int i;\n  for(i = 0; i < n; i++)\n    if(in[i] != cpy[i]) {\n      printf(\"ERROR in[%d]=%x, dec[%d]=%x\\n\", i, in[i], i, cpy[i]);\n      return i+1; \n    }\n  return 0;\n}\n \n#define ID_MEMCPY 10\nunsigned bench(unsigned char *in, unsigned n, unsigned char *out, unsigned char *cpy, int id) { \n  unsigned l = 0,m=tb64enclen(n);\n    #ifndef _MSC_VER\n  memrcpy(cpy,in,n); \n    #endif\n  switch(id) {\n    case 1:                      TMBENCH(\"\",l=tb64senc(    in, n, out),m); pr(l,n); TMBENCH2(\" 1:tb64s          \", tb64sdec(    out, l, cpy), l);   break;\n    case 2:                      TMBENCH(\"\",l=tb64xenc(    in, n, out),m); pr(l,n); TMBENCH2(\" 2:tb64x          \", tb64xdec(    out, l, cpy), l);   break;\n      #if defined(__i386__) || defined(__x86_64__) || defined(__ARM_NEON) || defined(__powerpc64__)\n    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;\n    case 6:                      TMBENCH(\"\",l=tb64enc(     in, n, out),m); pr(l,n); TMBENCH2(\" 6:tb64auto       \", tb64dec(     out, l, cpy), l);   break;\n      #endif\n      #if defined(__i386__) || defined(__x86_64__)\n    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;\n    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;\n    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;\n        #ifndef NAVX512                                                            // +VBMI\n    case 8:{ unsigned c = cpuini(0); \n      if(c>=(0x800|0x200)) { TMBENCH(\"\",  l=tb64v512enc(in, n, out),m); pr(l,n); TMBENCH2(\" 8:tb64v512vbmi   \", tb64v512dec( out,l,cpy),l); } \n      //else if(c>=0x800)    { TMBENCH(\"\",  l=tb64v256enc(in, n, out),m); pr(l,n); TMBENCH2(\" 8:tb64v512       \", tb64v512dec0(out, l, cpy),l); } \n    } break;\n        #endif \n\t  #endif\n    case 9:                      TMBENCH(\"\",l=tb64xenc(    in, n, out),m); pr(l,n); TMBENCH2(\" 9:_tb64x         \", _tb64xd(     out, l, cpy), l);   break;\n    case ID_MEMCPY:              TMBENCH( \"\", memcpy(out,in,m) ,m);        pr(n,n); TMBENCH2(\"10:memcpy         \", memcpy(cpy,out,n), n);  l = n;   break;\n      #ifdef XBASE64\n    #include \"xtb64test_.c\"\n      #endif\n    default: return 0;\n  }\n  if(l) { printf(\" %10d\\n\", n); memcheck(in,n,cpy); }\n  return l;\n}\n\nvoid usage(char *pgm) {\n  fprintf(stderr, \"\\nTurboBase64 Copyright (c) 2016-2023 Powturbo %s\\n\", __DATE__);\n  fprintf(stderr, \"Usage: %s [options] [file]\\n\", pgm);\n  fprintf(stderr, \" -e#      # = function ids separated by ',' or ranges '#-#' (default='1-%d')\\n\", ID_MEMCPY);\n  fprintf(stderr, \" -B#s     # = max. benchmark filesize (default 120Mb)\\n\");\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\");\n  fprintf(stderr, \"Benchmark:\\n\");\n  fprintf(stderr, \" -I#/-J#  # = Number of de/compression runs (default=3)\\n\");\n  fprintf(stderr, \" -e#      # = function id\\n\");\n  fprintf(stderr, \" -q#      # = cpuid (33=ssse, 50:avx, 60=avx2 (default:auto detect)\\n\");\n  fprintf(stderr, \" -k#      random test with predefined sizes (0=1K-20MB function id\\n\");\n  fprintf(stderr, \"          #: 0=1K-20MB, 1=short input\\n\");\n  fprintf(stderr, \" -T       Test all input sizes 0-10000\\n\");\n  fprintf(stderr, \"Ex. turbob64 file\\n\");\n  fprintf(stderr, \"    turbob64 -e3 file\\n\");\n  fprintf(stderr, \"    turbob64 -e1-6 file\\n\");\n  fprintf(stderr, \"    turbob64 -q33 file -I15 -J15\\n\");\n  fprintf(stderr, \"    turbob64 -e1-6 -k1\\n\");\n  exit(0);\n} \n\n\nvoid fuzzcheck(unsigned char *_in, unsigned insize, unsigned char *_out, unsigned outsize, unsigned char *_cpy, unsigned fuzz) {\n  unsigned char *in = _in, *out = _out, *cpy = _cpy;                            printf(\" Fuzz OK. Waiting seg. fault\\n\");fflush(stdout);\n  unsigned      n;\n  for(n = 0; n <= 10099; n++) {  \t\t\t\t\t\t\t\t\t\t\t\t\n    unsigned m = tb64enclen(n); \n    if(fuzz & 2) { cpy = (_cpy+insize) - n, out = (_out+outsize) - m;           printf(\"O%x \", out[m]);fflush(stdout); \n                                                                                printf(\"C%x \", cpy[n]);fflush(stdout); \n    }\n    if(fuzz & 1) { in  = (_in +insize) - n;                                     printf(\"I%x \", in[n]); fflush(stdout); }\n  }                      \t\t\t\t\t\t\t\t\t\t\t\t\t\tprintf(\"Fuzztest not reliable. Reapeat until seg. fault\\n\");fflush(stdout);\n}\n\nvoid fuzztest(unsigned id, unsigned char *_in, unsigned insize, unsigned char *_out, unsigned outsize, unsigned char *_cpy, unsigned fuzz) {\n  unsigned char *in = _in, *out = _out, *cpy = _cpy;\n  unsigned      s,n,i,l = 0;\n                                                                                printf(\"[id=%u\", id);fflush(stdout);\n  for(n = 0; n <= 10099; n++) {  \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n    unsigned m = tb64enclen(n); \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\n    if(fuzz & 2) cpy = (_cpy+insize) - n, out = (_out+outsize) - m;             // by reading/writing beyond the buffer end\n    \t\t\t\n    srand(time(0));                                                             \n\tfor(i = 0; i < n; i++)                                                      // Generate a random string \n\t  in[i] = rand()&0xff;  \n    memrcpy(cpy, in, n);   \t\t\t\t\t\t\t\t\t\t\t\t\t\t// copy input reversed \n    \n    switch(id) {\n      case  1:                       l = tb64senc(    in, n, out); if(l != m) die(\"Error n=%u\\n\", n); tb64sdec(    out, l, cpy);   break;\n      case  2:                       l = tb64xenc(    in, n, out); if(l != m) die(\"Error n=%u\\n\", n); tb64xdec(    out, l, cpy);   break;\n      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;\n        #if defined(__i386__) || defined(__x86_64__)\n      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;\n      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;\n      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;\n      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\n        #endif\n        #ifdef XBASE64F // fastbase is unsafe, can reads/writes beyound i/o buffers\n      #include \"xtb64fuzz_.c\"  \n\t#endif\n      default:                                                                  printf(\"]\");fflush(stdout);\n\treturn;\n    }                                                                           \n    if(l && memcheck(in,n,cpy)) exit(-1); \t                                    \t\t\t\t\t\t\t\t\t\n  }                                                                             printf(\" OK]\");fflush(stdout);\n}\n\nint verbose=3;\n\nint main(int argc, char* argv[]) {                              \n  unsigned      cmp = 1, bsize = (120*Mb), esize = 4, fno, id=0, fuzz = 0, bid = 0, tst = 0,\n                n = bsize, outsize = tb64enclen(n), insize = outsize;\n  char          *scmd = NULL, _scmd[33];\n  unsigned char *in, *_in=NULL, *cpy, *_cpy=NULL, *out, *_out=NULL;\n\n  int           c, digit_optind = 0, this_option_optind = optind ? optind : 1, option_index = 0;\n  static struct option long_options[] = { {\"blocsize\",  0, 0, 'b'}, {0, 0, 0}  };\n  for(;;) {\n    if((c = getopt_long(argc, argv, \"B:e:f:I:J:k:m:M:q:Tv:\", long_options, &option_index)) == -1) break;\n    switch(c) {\n      case  0 : printf(\"Option %s\", long_options[option_index].name); if(optarg) printf (\" with arg %s\", optarg);  printf (\"\\n\"); break;                                \n      case 'B': bsize = argtoi(optarg,1);                             break;\n      case 'k': bid = atoi(optarg);                                   break;\n      case 'f': fuzz = atoi(optarg);                                  break;\n      case 'e': scmd = optarg;                                        break;\n      case 'I': if((tm_Rep  = atoi(optarg))<=0) tm_rep = tm_Rep  = 1; break;\n      case 'J': if((tm_Rep2 = atoi(optarg))<=0) tm_rep = tm_Rep2 = 1; break;\n        #ifdef XBASE64\n      case 'm': if(!(smin = atoi(optarg))) smin = 1;                  break;\n      case 'M': smask = atoi(optarg); if(smask&(smask-1)) die(\"Range must be power of 2\"); smask--; break;\n        #endif\t  \n      case 'q':      if(!strcasecmp(optarg,\"sse\"))    cpuini(0x33);  \n                else if(!strcasecmp(optarg,\"avx\"))    cpuini(0x50); \n                else if(!strcasecmp(optarg,\"avx2\"))   cpuini(0x60); \n                else if(!strcasecmp(optarg,\"avx512\")) cpuini(0x78);   break;\n      case 'T': tst++;                                                break;\n\t  case 'v': verbose = atoi(optarg); break;\n      default: \n        usage(argv[0]);\n        exit(0); \n    }\n  }\n  \n  tm_init(tm_Rep, verbose);  \n  sprintf(_scmd, \"1-%d\", ID_MEMCPY);\n  tb64ini(0,0); \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tprintf(\"detected simd (id=%x->'%s')\\n\\n\", cpuini(0), cpustr(cpuini(0))); \n  unsigned char *tmp1,*tmp2;\n  if(!(_in  = (unsigned char*)_valloc(insize, 0))) die(\"malloc error in size=%u\\n\",  insize);  in  = _in;\n  if(!(tmp1 = (unsigned char*)_valloc(insize, 0))) die(\"malloc error cpy size=%u\\n\", insize);  \n  if(!(_cpy = (unsigned char*)_valloc(insize, 0))) die(\"malloc error cpy size=%u\\n\", insize);  cpy = _cpy;\n  if(!(tmp2 = (unsigned char*)_valloc(outsize,0))) die(\"malloc error cpy size=%u\\n\", insize);  \n  if(!(_out = (unsigned char*)_valloc(outsize,0))) die(\"malloc error out size=%u\\n\", outsize); out = _out;\n  _vfree(tmp1, insize); \n  _vfree(tmp2, outsize);\n                                                                                \n  if(tst) {\t//------------------------ test + fuzzer (option -T) ----------------------------------------------------------------------------\n    char *p = scmd?scmd:_scmd;\n    do { \n      unsigned id = strtoul(p, &p, 10), idx = id, i;    \n      while(isspace(*p)) p++; \n\t  if(*p == '-' && (idx = strtoul(p+1, &p, 10)) < id)\n\t    idx = id;  \n      for(i = id; i <= idx; i++) \n\t    fuzztest(i,_in,insize,_out,outsize,_cpy, fuzz);\n\t  fuzzcheck(_in,insize,_out,outsize,_cpy, fuzz);\n\t\n    } while(*p++);\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t    printf(\"fuzz OK\\n\");\n  } else if(argc - optind < 1) { //------------------ bechmark with predefined sizes (option -k#) -------------------------------------------\n    unsigned _size0[] = { 1*KB, 10*KB, 50*KB, 100*KB, 200*KB, 500*KB, 1*MB, 10*MB, 20*MB, 0 }, \n\t         _size1[] = { 1, 3, 7, 15, 31, 67, 127, 255, 511, 1*KB, 0 },\n             _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 }, \n             _size3[] = { 100, 200, 1*KB, 100*KB, 1*MB, 0 }, \n\t         _size4[] = { 15, 63, 127, 159, 191, 255, 511, 1023, 0 },\n\t         _size5[] = { 1,2, 3,4,5,6, 63,64,65,66, 0 },\n\t\t    *_sizea[] = { _size0, _size1, _size2, _size3, _size4, _size5 },\n\t\t\t *sizes   = _sizea[bid>5?5:bid];\n\tif(bid > 5) { _size5[0] = bid; _size5[1] = 0; }\n                                                                                printf(\"  E MB/s    size     ratio%%   D MB/s   function (random)\\n\");   \n    for(int s = 0; sizes[s]; s++) {\n      n = sizes[s];  if(n > bsize) continue;\n      \n      if(fuzz & 1) in  = (_in +insize) - n; \n      if(fuzz & 2) out = (_out+outsize) - tb64enclen(n), cpy = (_cpy+insize)-n;\n\t  \n      srand(0); for(int i = 0; i < n; i++) in[i] = rand()&0xff;\n      char *p = scmd?scmd:_scmd;\n      do { \n        unsigned id = strtoul(p, &p, 10),idx = id, i;    \n        while(isspace(*p)) p++; \n\t    if(*p == '-' &&  (idx = strtoul(p+1, &p, 10)) < id)\n\t\t  idx = id;  \n        for(i = id; i <= idx; i++) \n          bench(in, n, out,cpy,i);\n      } while(*p++);\n    } \n  } else { //------------------------------------ file benchmark -----------------------------------------------------------------------------\n    for(fno = optind; fno < argc; fno++) {\n      unsigned flen,m,n=bsize,i;    \n      char *inname = argv[fno];\n\t  if(strcmp(inname, \"NULL\")) {\n        FILE *fi = fopen(inname, \"rb\");                                           if(!fi ) { perror(inname); continue; }  \n        fseek(fi, 0, SEEK_END); \n        flen = ftell(fi); \t\t\t\t\t\t\t\t\t\t\t\t\t \t\n        fseek(fi, 0, SEEK_SET);\n    \n        if(flen > bsize) flen = bsize;                                           \n        n = flen;\n        n = fread(in, 1, n, fi);                                                  printf(\"File='%s' Length=%u\\n\", inname, n);            \n        fclose(fi);\n\t  }\n\t  m = tb64enclen(n);\n      if(!n) exit(0);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tprintf(\"  E MB/s    size     ratio    D MB/s   function\\n\");  \n      char *p = scmd?scmd:_scmd;\n      do { \n        unsigned id = strtoul(p, &p, 10),idx = id, i;    \n        while(isspace(*p)) p++; \n\t\tif(*p == '-' && (idx = strtoul(p+1, &p, 10)) < id) \n\t\t  idx = id; \n        for(i = id; i <= idx; i++)\n          bench(in,n,out,cpy,i);    \n      } while(*p++);\n    }\n  }\n  _vfree(_in,  insize);\n  _vfree(_out, outsize);\n  _vfree(_cpy, insize);\n}\n"
  },
  {
    "path": "time_.h",
    "content": "/**\n    Copyright (C) powturbo 2013-2023\n    GPL v2 License\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\n    - homepage : https://sites.google.com/site/powturbo/\n    - github   : https://github.com/powturbo\n    - twitter  : https://twitter.com/powturbo\n    - email    : powturbo [_AT_] gmail [_DOT_] com\n**/\n//      time_.h : parameter free high precision time/benchmark functions\n#include <time.h>\n#include <float.h>\n  #ifdef _WIN32\n#include <windows.h>\n    #ifndef sleep\n#define sleep(n) Sleep((n) * 1000)\n    #endif\n#define uint64_t unsigned __int64\n\n  #else\n#include <stdint.h>\n#include <unistd.h>\n#define Sleep(ms) usleep((ms) * 1000)\n  #endif\n\n#if defined (__i386__) || defined( __x86_64__ )  // ------------------ rdtsc --------------------------\n  #ifdef _MSC_VER\n#include <intrin.h> // __rdtsc\n  #else\n#include <x86intrin.h>\n  #endif\n\n  #ifdef __corei7__\n#define RDTSC_INI(_c_) do { unsigned _cl, _ch;              \\\n  __asm volatile (\"cpuid\\n\\t\"                               \\\n                \"rdtsc\\n\\t\"                                 \\\n                \"mov %%edx, %0\\n\"                           \\\n                \"mov %%eax, %1\\n\": \"=r\" (_ch), \"=r\" (_cl):: \\\n                \"%rax\", \"%rbx\", \"%rcx\", \"%rdx\");            \\\n  _c_ = (uint64_t)_ch << 32 | _cl;              \\\n} while(0)\n\n#define RDTSC(_c_) do { unsigned _cl, _ch;                  \\\n  __asm volatile(\"rdtscp\\n\"                                 \\\n               \"mov %%edx, %0\\n\"                            \\\n               \"mov %%eax, %1\\n\"                            \\\n               \"cpuid\\n\\t\": \"=r\" (_ch), \"=r\" (_cl):: \"%rax\",\\\n               \"%rbx\", \"%rcx\", \"%rdx\");\\\n  _c_ = (uint64_t)_ch << 32 | _cl;\\\n} while(0)\n  #else\n/*#define RDTSC(_c_) do { unsigned _cl, _ch;\\\n  __asm volatile (\"cpuid \\n\"\\\n                \"rdtsc\"\\\n                : \"=a\"(_cl), \"=d\"(_ch)\\\n                : \"a\"(0)\\\n                : \"%ebx\", \"%ecx\");\\\n  _c_ = (uint64_t)_ch << 32 | _cl;\\\n} while(0)*/\n#define RDTSC(_c_) do { unsigned _cl, _ch;\\\n   __asm volatile(\"rdtsc\" : \"=a\"(_cl), \"=d\"(_ch) );\\\n  _c_ = (uint64_t)_ch << 32 | _cl;\\\n} while(0)\n  #endif\n\n#define RDTSC_INI(_c_) RDTSC(_c_)\n#else                                          // ------------------ time --------------------------\n#define RDTSC_INI(_c_)\n#define RDTSC(_c_)\n#endif\n\n#ifndef TM_F\n#define TM_F 1.0  // TM_F=4 -> MI/s\n#endif\n\n#ifdef _RDTSC //---------------------- rdtsc --------------------------------\n#define TM_M   (CLOCKS_PER_SEC*1000000ull)\n#define TM_PRE 4\n#define TM_MBS \"cycle/byte\"\nstatic double TMBS(unsigned l, double t) { return (double)t/(double)l; }\n\ntypedef uint64_t tm_t;\nstatic tm_t   tmtime()                      { uint64_t c; RDTSC(c); return c; }\nstatic tm_t   tminit()                      { uint64_t c; __asm volatile(\"\" ::: \"memory\"); RDTSC_INI(c); return c; }\nstatic double tmdiff(tm_t start, tm_t stop) { return (double)(stop - start); }\nstatic int    tmiszero(tm_t t)              { return !t; }\n#else          //---------------------- time -----------------------------------\n#define TM_M   1\n#define TM_PRE 2\n#define TM_MBS \"MB/s\"\nstatic double TMBS(unsigned l, double t) { return (l/t)/1000000.0; }\n\n  #ifdef _WIN32 //-------- windows \nstatic LARGE_INTEGER tps;\n\ntypedef unsigned __int64 tm_t;\nstatic tm_t   tmtime()                      { LARGE_INTEGER tm; tm_t t; QueryPerformanceCounter(&tm); return tm.QuadPart; }\nstatic tm_t   tminit()                      { tm_t t0,ts; QueryPerformanceFrequency(&tps); t0 = tmtime(); while((ts = tmtime())==t0) {}; return ts; }\nstatic double tmdiff(tm_t start, tm_t stop) { return (double)(stop - start)/tps.QuadPart; }\nstatic int    tmiszero(tm_t t)              { return !t; }\n  #else        // Linux & compatible / MacOS\n    #ifdef __APPLE__\n#include <AvailabilityMacros.h>\n      #ifndef MAC_OS_X_VERSION_10_12\n#define MAC_OS_X_VERSION_10_12 101200\n      #endif\n#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)\n      #if !(CIVETWEB_APPLE_HAVE_CLOCK_GETTIME)\n#include <sys/time.h>\n#define CLOCK_REALTIME 0\n#define CLOCK_MONOTONIC 0\nint clock_gettime(int /*clk_id*/, struct timespec* t) {\n  struct timeval now;\n  int rv = gettimeofday(&now, NULL);\n  if (rv) return rv;\n  t->tv_sec  = now.tv_sec;\n  t->tv_nsec = now.tv_usec * 1000;\n  return 0;\n}\n      #endif\n    #endif\n    \ntypedef struct timespec tm_t;   \nstatic tm_t   tmtime()                      { struct timespec tm; clock_gettime(CLOCK_MONOTONIC, &tm); return tm; }\nstatic double tmdiff(tm_t start, tm_t stop) { return (stop.tv_sec - start.tv_sec) + (double)(stop.tv_nsec - start.tv_nsec)/1e9f; }\nstatic tm_t   tminit()                      { tm_t t0 = tmtime(),t; while(!tmdiff(t = tmtime(),t0)) {}; return t; }\nstatic int    tmiszero(tm_t t)              { return !(t.tv_sec|t.tv_nsec); }\n  #endif\n#endif \n\n//---------------------------------------- bench ----------------------------------------------------------------------\n// for each a function call is repeated until exceeding tm_tx seconds.\n// A run duration is always tm_tx seconds\n// The number of runs can be set with the program options  -I and -J (specify -I15 -J15 for more precision)\n\n// sleep after each 8 runs to avoid cpu throttling.\n#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)\n\n// benchmark loop\n#define TMBEG(_tm_Reps_) { unsigned _tm_r,_tm_c = 0,_tm_R,_tm_Rx = _tm_Reps_,_tm_Rn = _tm_Reps_; double _tm_t;\\\n  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*/\\\n    for(_tm_r = 0;_tm_r < tm_rm;) { /*repeat tm_rm times */\n\n#define TMEND(_len_) \\\n      _tm_r++; if(tm_tm == DBL_MAX && (_tm_t = tmdiff(_tm_t0, tmtime())) > tm_tx) break;\\\n    }\\\n    /*1st run: break the loop after tm_tx=1 sec, calculate a new repeats 'tm_rm' to avoid calling time() after each function call*/\\\n    /*other runs: break the loop only after 'tm_rm' repeats */ \\\n    _tm_t = tmdiff(_tm_t0, tmtime());\\\n    /*set min time, recalculate repeats tm_rm based on tm_tx, recalculate number of runs based on tm_TX*/\\\n    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);*/ } \\\n\t  tm_tm = _tm_t; _tm_c++;\\\n    } else if(_tm_t > tm_tm*1.15) TMSLEEP;/*force sleep at 15% divergence*/\\\n    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); }\\\n    if((_tm_R & 7)==7) sleep(tm_slp); /*pause 20 secs after each 8 runs to avoid cpu throttling*/\\\n  }\\\n}\n\nstatic unsigned tm_rep = 1u<<30, tm_Rep = 3, tm_Rep2 = 3, tm_rm, tm_RepMin = 1, tm_slp = 20, tm_verbose = 3;\nstatic tm_t tm_0, tm_T;\nstatic double tm_tm, tm_tx = 1.0*TM_M, tm_TX = 60.0*TM_M;\n\nstatic void tm_init(int _tm_Rep, int _tm_verbose) { tm_verbose = _tm_verbose; if(_tm_Rep) tm_Rep = _tm_Rep; }\n\n#define TMBENCH(_name_, _func_, _len_)  do { if(tm_verbose>=1) printf(\"%s \", _name_?_name_:#_func_);\\\n  TMBEG(tm_Rep) _func_; TMEND(_len_); \\\n  double dm = tm_tm, dr = tm_rm; \\\n  if(tm_verbose>2) printf(\"%8.*f      \\b\\b\\b\\b\\b\", TM_PRE, TMBS(_len_, dm/dr) );\\\n  else if(tm_verbose) printf(\"%8.*f      \", TM_PRE, TMBS(_len_, dm/dr) );\\\n} while(0)\n\n// second TMBENCH. Example: use TMBENCH for encoding and TMBENCH2 for decoding\n#define TMBENCH2(_name_, _func_, _len_)  do { \\\n  TMBEG(tm_Rep2) _func_; TMEND(_len_);\\\n  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) );\\\n  if(tm_verbose>=1) printf(\"%s \", _name_?_name_:#_func_);\\\n} while(0)\n\n// Check\n#define TMBENCHT(_name_,_func_, _len_, _res_)  do { \\\n  TMBEG(tm_Rep) \\\n  if(_func_ != _res_) { printf(\"ERROR: %lld != %lld\", (long long)_func_, (long long)_res_ ); exit(0); };\\\n  TMEND(_len_);\\\n  if(tm_verbose>2) printf(\"%8.*f      \\b\\b\\b\\b\\b\", TM_PRE, TMBS(_len_,(double)tm_tm/(double)tm_rm) );\\\n  if(tm_verbose>1) printf(\"%s \", _name_?_name_:#_func_ );\\\n} while(0)\n\nstatic void pr(unsigned l, unsigned n) {\n  double r = (double)l*100.0/n;\n  if(r>0.1)  printf(\"%10u %6.2f%%   \", l, r);\n  else if(r>0.01) printf(\"%10u %7.3f%%  \", l, r);\n  else printf(\"%10u %8.4f%% \", l, r); fflush(stdout); \n}\n\n//----------------------------------------------------------------------------------------------------------------------------------\n#define Kb (1u<<10)\n#define Mb (1u<<20)\n#define Gb (1u<<30)\n#define KB 1000\n#define MB 1000000\n#define GB 1000000000\n\nstatic unsigned argtoi(char *s, unsigned def) {\n  char *p;\n  unsigned n = strtol(s, &p, 10),f = 1;\n  switch(*p) {\n    case 'K': f = KB; break;\n    case 'M': f = MB; break;\n    case 'G': f = GB; break;\n    case 'k': f = Kb; break;\n    case 'm': f = Mb; break;\n    case 'g': f = Gb; break;\n    case 'B': return n; break;\n    case 'b': def = 0;\n    default: if(!def) return n>=32?0xffffffffu:(1u << n); f = def;\n  }\n  return n*f;\n}\nstatic uint64_t argtol(char *s) {\n  char *p;\n  uint64_t n = strtol(s, &p, 10),f=1;\n  switch(*p) {\n    case 'K': f = KB; break;\n    case 'M': f = MB; break;\n    case 'G': f = GB; break;\n    case 'k': f = Kb; break;\n    case 'm': f = Mb; break;\n    case 'g': f = Gb; break;\n    case 'B': return n; break;\n    case 'b': return 1u << n;\n    default:  f = MB;\n  }\n  return n*f;\n}\n\nstatic uint64_t argtot(char *s) {\n  char *p;\n  uint64_t n = strtol(s, &p, 10),f=1;\n  switch(*p) {\n    case 'h': f = 3600000; break;\n    case 'm': f = 60000;   break;\n    case 's': f = 1000;    break;\n    case 'M': f = 1;       break;\n    default:  f = 1000;\n  }\n  return n*f;\n}\n\nstatic void memrcpy(unsigned char *out, unsigned char *in, unsigned n) { int i; for(i = 0; i < n; i++) out[i] = ~in[i]; }\n\n"
  },
  {
    "path": "turbob64.h",
    "content": "/**\n    Copyright (C) powturbo 2016-2023\n    SPDX-License-Identifier: GPL v3 License\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\n    - homepage : https://sites.google.com/site/powturbo/\n    - github   : https://github.com/powturbo\n    - twitter  : https://twitter.com/powturbo\n    - email    : powturbo [_AT_] gmail [_DOT_] com\n**/\n// Turbo-Base64 - C/C++ include header\n#ifndef _TURBOB64_H_\n#define _TURBOB64_H_\n\n#include <stddef.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define TB64_VERSION 100\n//---------------------- Turbo-Base64 API functions ----------------------------------\n// return the base64 buffer length after encoding\nsize_t tb64enclen(size_t inlen);\n\n// return the original (after decoding) length for a given base64 encoded buffer\nsize_t tb64declen(const unsigned char *in, size_t inlen);\n\n// Encode binary input 'in' buffer into base64 string 'out' \n// with automatic cpu detection for avx2/sse4.1/scalar \n// in          : Input buffer to encode\n// inlen       : Length in bytes of input buffer\n// out         : Output buffer\n// return value: Length of output buffer\n// Remark      : byte 'zero' is not written to end of output stream\n//               Caller must add 0 (out[outlen] = 0) for a null terminated string\nsize_t tb64enc(const unsigned char *in, size_t inlen, unsigned char *out);\n\n// Decode base64 input 'in' buffer into binary buffer 'out' \n// in          : input buffer to decode\n// inlen       : length in bytes of input buffer \n// out         : output buffer\n// return value: >0 output buffer length\n//                0 Error (invalid base64 input or input length = 0)\nsize_t tb64dec(const unsigned char *in, size_t inlen, unsigned char *out);\n\n//------ Direct call to tb64enc + tb64dec ---------------------------------------\n// Direct call to tb64enc + tb64dec saving a function call + a check instruction\n// call tb64ini, then call _tb64e(in, inlen, out) or _tb64d(in, inlen, out)\ntypedef size_t (*TB64FUNC)(const unsigned char *__restrict in, size_t n, unsigned char *__restrict out);\n\nextern TB64FUNC _tb64e;\nextern TB64FUNC _tb64d;\n\n//---------------------- base64 Internal functions ------------------------------\n// Base64 output length after encoding \n#define TB64ENCLEN(_n_) ((_n_ + 2)/3 * 4)\n\n// Memory efficient (small lookup tables) scalar but (slower) version\nsize_t tb64senc(     const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\nsize_t tb64sdec(     const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\n\n// Fast scalar\nsize_t tb64xenc(     const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\nsize_t tb64xdec(     const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\n\n// ssse3  \nsize_t tb64v128enc(  const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\nsize_t tb64v128dec(  const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\n\n// avx \nsize_t tb64v128aenc( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\nsize_t tb64v128adec( const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\n\n// avx2\nsize_t tb64v256enc(  const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\nsize_t tb64v256dec(  const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\n\n// avx512_vbmi\nsize_t tb64v512enc(  const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\nsize_t tb64v512dec(  const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out);\n\n// detect cpu && set the default run time functions for tb64enc/tb64dec\n// isshort = 0 : default\n// isshort > 0 : set optimized short strings version (actually only avx2)\nvoid tb64ini(unsigned id, unsigned isshort);  \n\n//------- optimized functions for short strings only --------------------------\n// - decoding without checking  \n// - can read beyond the input buffer end, \n//   therefore input buffer size must be 32 bytes larger than input length\nsize_t _tb64v256enc(const unsigned char *in, size_t inlen, unsigned char *out);\nsize_t _tb64v256dec(const unsigned char *in, size_t inlen, unsigned char *out);\n\n//------- CPU instruction set ----------------------\n// cpuisa  = 0: return current simd set, \n// cpuisa != 0: set simd set 0:scalar, 0x33:sse2, 0x60:avx2\nunsigned cpuini(unsigned cpuisa); \n\n// convert simd set to string \"sse3\", \"ssse3\", \"sse4.1\", \"avx\", \"avx2\", \"neon\",... \n// Ex.: printf(\"current cpu set=%s\\n\", cpustr(cpuini(0)) ); \nchar *cpustr(unsigned cpuisa); \n\n#ifdef __cplusplus\n}\n#endif\n#endif\n"
  },
  {
    "path": "turbob64_.h",
    "content": "/**\n    Copyright (C) powturbo 2016-2023\n    SPDX-License-Identifier: GPL v3 License\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\n    - homepage : https://sites.google.com/site/powturbo/\n    - github   : https://github.com/powturbo\n    - twitter  : https://twitter.com/powturbo\n    - email    : powturbo [_AT_] gmail [_DOT_] com\n**/\n// Turbo-Base64: internal include\n//#define UA_MEMCPY // Force replace unaligned stores with memcpy (see \"conf.h\")\n#include \"conf.h\"\n\nsize_t _tb64xdec( const unsigned char *in, size_t inlen, unsigned char *out);\nsize_t tb64memcpy(const unsigned char *in, size_t inlen, unsigned char *out);  // testing only\n\n#define PREFETCH(_ip_,_i_,_rw_) __builtin_prefetch(_ip_+(_i_),_rw_)\n\n  #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)\n#define BSWAP32(a) a \n#define BSWAP64(a) a \n  #else\n#define BSWAP32(a) bswap32(a)\n#define BSWAP64(a) bswap64(a)\n  #endif  \n\n  #ifdef NB64CHECK  // decoding without checking\n#define CHECK0(a)\n#define CHECK1(a)\n  #else             // decoding incl. checking \n#define CHECK0(a) a\n    #ifdef B64CHECK // Full check\n#define CHECK1(a) a\n    #else\n#define CHECK1(a)\n    #endif\n  #endif\n\n//------- Encode: scalar helper macros & functions ----------------------------------------------------------\nextern unsigned char tb64lutse[];\n\n#define SU32(_u_) (tb64lutse[(_u_>> 8) & 0x3f] << 24 |\\\n                   tb64lutse[(_u_>>14) & 0x3f] << 16 |\\\n                   tb64lutse[(_u_>>20) & 0x3f] <<  8 |\\\n                   tb64lutse[(_u_>>26) & 0x3f])\n\n#define ETAIL()\\\n  unsigned _l = (in+inlen) - ip;   AS(ip <= in+inlen, \"ETAIL:Fatal %d\\n\", (unsigned)(ip - (in+inlen)));\\\n       if(_l == 3) { unsigned _u = ip[0]<<24 | ip[1]<<16 | ip[2]<<8; stou32(op, SU32(_u)); op+=4; }\\\n  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; }\\\n  else if(_l)      { op[0] = tb64lutse[(ip[0]>>2)&0x3f]; op[1] = tb64lutse[(ip[0] & 0x3) << 4],                       op[2] = '=';                           op[3] = '='; op+=4; }\n  \nextern const unsigned short tb64lute[];\n#define XU32(_u_) (tb64lute[(_u_ >>  8) & 0xfff] << 16 |\\\n                   tb64lute[ _u_ >> 20])\n\n#define EXTAIL(_n_) for(; op < out_-4; op += 4, ip += 3) { unsigned _u = BSWAP32(ctou32(ip)); stou32(op, XU32(_u)); } ETAIL()\n\n//------- Decode: scalar helper macros & functions ----------------------------------------------------------\nextern const unsigned tb64lutd0[];\nextern const unsigned tb64lutd1[];\nextern const unsigned tb64lutd2[];\nextern const unsigned tb64lutd3[];\n\n#define DU32(_u_) (tb64lutd0[(unsigned char)(_u_     )] |\\\n                   tb64lutd1[(unsigned char)(_u_>>  8)] |\\\n                   tb64lutd2[(unsigned char)(_u_>> 16)] |\\\n                   tb64lutd3[                _u_>> 24 ] )\n\n#define DXTAILC(ip,out,op,_check_) {\\\n       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*/\\\n  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*/\\\n  else if(ip[1] != '=') { unsigned u = tb64lutd0[ip[0]] | tb64lutd1[ip[1]];                    *op++ = u;                                     _check_; } /*2->1*/\\\n  else                  { unsigned u = tb64lutd0[ip[0]];                                       *op++ = u;                                     _check_; } /*1->1*/\\\n}\n\t\t\t\t   \n#define DXTAIL(ip,out,op) {\\\n       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*/\\\n  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*/\\\n  else if(ip[1] != '=') {                                                                      *op++ = tb64lutd0[ip[0]] | tb64lutd1[ip[1]];  } /*2->1*/\\\n  else                  {                                                                      *op++ = tb64lutd0[ip[0]];                     } /*1->1*/\\\n}\n\nstatic ALWAYS_INLINE size_t _tb64xd(const unsigned char *in, size_t inlen, unsigned char *out) { \n  const unsigned char *ip = in, *in_ = in+inlen;\n        unsigned char *op = out;\n    #ifdef B64CHECK\n  unsigned       cu = 0;\n  for(; ip < in_-4; ip += 4, op += 3) { unsigned u = ctou32(ip); u = DU32(u); stou32(op, u); cu |= u; }\n  DXTAILC(ip,out,op, cu |= u);\n  return (cu == -1)?0:(op-out);\n    #else\n  for(; ip < in_-4; ip += 4, op += 3) { unsigned u = ctou32(ip); u = DU32(u); stou32(op, u); } \n  DXTAIL(ip,out,op)\n  return op - out;\n    #endif\t\t\n}\n\n//------- SSE helper macros & functions ----------------------------------------------------------\n#if defined(__SSSE3__)\n#include <tmmintrin.h>\n#define BITPACK128V8_6(v, cpv) {\\\n  const __m128i merge_ab_bc = _mm_maddubs_epi16(v,            _mm_set1_epi32(0x01400140));  /*dec_reshuffle: https://arxiv.org/abs/1704.00605 P.17*/\\\n                          v = _mm_madd_epi16(merge_ab_bc, _mm_set1_epi32(0x00011000));\\\n                          v = _mm_shuffle_epi8(v, cpv);\\\n}\n\n#define BITMAP128V8_6(iv, shifted, delta_asso, delta_values, ov) { /*map 8-bits ascii to 6-bits binary*/\\\n                shifted    = _mm_srli_epi32(iv, 3);\\\n  const __m128i delta_hash = _mm_avg_epu8(_mm_shuffle_epi8(delta_asso, iv), shifted);\\\n                        ov = _mm_add_epi8(_mm_shuffle_epi8(delta_values, delta_hash), iv);\\\n}\n\n#define B64CHK128(iv, shifted, check_asso, check_values, vx) {\\\n  const __m128i check_hash = _mm_avg_epu8( _mm_shuffle_epi8(check_asso, iv), shifted);\\\n  const __m128i        chk = _mm_adds_epi8(_mm_shuffle_epi8(check_values, check_hash), iv);\\\n                        vx = _mm_or_si128(vx, chk);\\\n}\n\nstatic ALWAYS_INLINE __m128i bitmap128v8_6(const __m128i v) { /*map 8-bits ascii to 6-bits binary*/\n  const __m128i offsets = _mm_set_epi8( 0, 0,-16,-19, -4,-4,-4,-4,   -4,-4,-4,-4, -4,-4,71,65);\n\n  __m128i vidx = _mm_subs_epu8(v,   _mm_set1_epi8(51));\n          vidx = _mm_sub_epi8(vidx, _mm_cmpgt_epi8(v, _mm_set1_epi8(25)));\n  return _mm_add_epi8(v, _mm_shuffle_epi8(offsets, vidx));\n}\n\nstatic ALWAYS_INLINE __m128i bitunpack128v8_6(__m128i v) { /* unpack 6 -> 8 */\n  __m128i va = _mm_mulhi_epu16(_mm_and_si128(v, _mm_set1_epi32(0x0fc0fc00)), _mm_set1_epi32(0x04000040));\n  __m128i vb = _mm_mullo_epi16(_mm_and_si128(v, _mm_set1_epi32(0x003f03f0)), _mm_set1_epi32(0x01000010));\n  return       _mm_or_si128(va, vb);                        \n}\n#endif\n//------- avx2 helper macros & functions ----------------------------------------------------------\n#ifdef __AVX2__\nstatic ALWAYS_INLINE __m256i bitmap256v8_6(const __m256i v) { \t\t\t\t\t//map 8-bits ascii to 6-bits binary (https://arxiv.org/abs/1704.00605) \n  __m256i vidx = _mm256_subs_epu8(v,   _mm256_set1_epi8(51));\n          vidx = _mm256_sub_epi8(vidx, _mm256_cmpgt_epi8(v, _mm256_set1_epi8(25)));\n\n  const __m256i offsets = _mm256_set_epi8(0, 0, -16, -19, -4, -4, -4, -4,   -4, -4, -4, -4, -4, -4, 71, 65,\n                                          0, 0, -16, -19, -4, -4, -4, -4,   -4, -4, -4, -4, -4, -4, 71, 65);\n  return _mm256_add_epi8(v, _mm256_shuffle_epi8(offsets, vidx));\n}\n\nstatic ALWAYS_INLINE __m256i bitunpack256v8_6(__m256i v) { \t\t\t\t\t\t//https://arxiv.org/abs/1704.00605 p.12\n  __m256i va = _mm256_mulhi_epu16(_mm256_and_si256(v, _mm256_set1_epi32(0x0fc0fc00)), _mm256_set1_epi32(0x04000040));\n  __m256i vb = _mm256_mullo_epi16(_mm256_and_si256(v, _mm256_set1_epi32(0x003f03f0)), _mm256_set1_epi32(0x01000010));\n  return _mm256_or_si256(va, vb);\n}\n#endif\n"
  },
  {
    "path": "turbob64c.c",
    "content": "/**\n    Copyright (C) powturbo 2016-2023\n    SPDX-License-Identifier: GPL v3 License\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\n    - homepage : https://sites.google.com/site/powturbo/\n    - github   : https://github.com/powturbo\n    - twitter  : https://twitter.com/powturbo\n    - email    : powturbo [_AT_] gmail [_DOT_] com\n**/\n// Turbo-Base64: Scalar encode\n#include \"turbob64_.h\"\n#include \"turbob64.h\"\n\nsize_t tb64enclen(size_t n) { return TB64ENCLEN(n); }\n \n//----------------------- small 64 bytes lut encoding ---------------------------------------------------------------------------------------------\nunsigned char tb64lutse[] = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n#define ES(_i_) { \\\n  unsigned v = ctou32(ip+3+_i_*6  ); u = BSWAP32(u); stou32(op+_i_*8,   SU32(u));\\\n           u = ctou32(ip+3+_i_*6+3); v = BSWAP32(v); stou32(op+_i_*8+4, SU32(v));\\\n}\n\nsize_t tb64senc(const unsigned char *in, size_t inlen, unsigned char *out) {\n  const unsigned char *ip    = in;\n        unsigned char *op    = out;\n        size_t        outlen = TB64ENCLEN(inlen);\n\t\t \n  if(outlen > 4+8) { \n\tunsigned u = ctou32(ip); \n    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);\t}\n    for(; op < (out+outlen)-(4+ 8); op +=  8, ip += ( 8/4)*3)   ES(0);\n  }\n  for(;   op < (out+outlen)-4;      op +=  4, ip += 3) { unsigned _u = BSWAP32(ctou32(ip)); stou32(op, SU32(_u)); }\n  ETAIL();  \n  return outlen;\n}\n\n//---------------------- Fast encoding with 4k LUT --------------------------------------------------------------------------------------------------\nconst unsigned short tb64lute[1<<12] = { \n0x4141,0x4241,0x4341,0x4441,0x4541,0x4641,0x4741,0x4841,0x4941,0x4a41,0x4b41,0x4c41,0x4d41,0x4e41,0x4f41,0x5041,\n0x5141,0x5241,0x5341,0x5441,0x5541,0x5641,0x5741,0x5841,0x5941,0x5a41,0x6141,0x6241,0x6341,0x6441,0x6541,0x6641,\n0x6741,0x6841,0x6941,0x6a41,0x6b41,0x6c41,0x6d41,0x6e41,0x6f41,0x7041,0x7141,0x7241,0x7341,0x7441,0x7541,0x7641,\n0x7741,0x7841,0x7941,0x7a41,0x3041,0x3141,0x3241,0x3341,0x3441,0x3541,0x3641,0x3741,0x3841,0x3941,0x2b41,0x2f41,\n0x4142,0x4242,0x4342,0x4442,0x4542,0x4642,0x4742,0x4842,0x4942,0x4a42,0x4b42,0x4c42,0x4d42,0x4e42,0x4f42,0x5042,\n0x5142,0x5242,0x5342,0x5442,0x5542,0x5642,0x5742,0x5842,0x5942,0x5a42,0x6142,0x6242,0x6342,0x6442,0x6542,0x6642,\n0x6742,0x6842,0x6942,0x6a42,0x6b42,0x6c42,0x6d42,0x6e42,0x6f42,0x7042,0x7142,0x7242,0x7342,0x7442,0x7542,0x7642,\n0x7742,0x7842,0x7942,0x7a42,0x3042,0x3142,0x3242,0x3342,0x3442,0x3542,0x3642,0x3742,0x3842,0x3942,0x2b42,0x2f42,\n0x4143,0x4243,0x4343,0x4443,0x4543,0x4643,0x4743,0x4843,0x4943,0x4a43,0x4b43,0x4c43,0x4d43,0x4e43,0x4f43,0x5043,\n0x5143,0x5243,0x5343,0x5443,0x5543,0x5643,0x5743,0x5843,0x5943,0x5a43,0x6143,0x6243,0x6343,0x6443,0x6543,0x6643,\n0x6743,0x6843,0x6943,0x6a43,0x6b43,0x6c43,0x6d43,0x6e43,0x6f43,0x7043,0x7143,0x7243,0x7343,0x7443,0x7543,0x7643,\n0x7743,0x7843,0x7943,0x7a43,0x3043,0x3143,0x3243,0x3343,0x3443,0x3543,0x3643,0x3743,0x3843,0x3943,0x2b43,0x2f43,\n0x4144,0x4244,0x4344,0x4444,0x4544,0x4644,0x4744,0x4844,0x4944,0x4a44,0x4b44,0x4c44,0x4d44,0x4e44,0x4f44,0x5044,\n0x5144,0x5244,0x5344,0x5444,0x5544,0x5644,0x5744,0x5844,0x5944,0x5a44,0x6144,0x6244,0x6344,0x6444,0x6544,0x6644,\n0x6744,0x6844,0x6944,0x6a44,0x6b44,0x6c44,0x6d44,0x6e44,0x6f44,0x7044,0x7144,0x7244,0x7344,0x7444,0x7544,0x7644,\n0x7744,0x7844,0x7944,0x7a44,0x3044,0x3144,0x3244,0x3344,0x3444,0x3544,0x3644,0x3744,0x3844,0x3944,0x2b44,0x2f44,\n0x4145,0x4245,0x4345,0x4445,0x4545,0x4645,0x4745,0x4845,0x4945,0x4a45,0x4b45,0x4c45,0x4d45,0x4e45,0x4f45,0x5045,\n0x5145,0x5245,0x5345,0x5445,0x5545,0x5645,0x5745,0x5845,0x5945,0x5a45,0x6145,0x6245,0x6345,0x6445,0x6545,0x6645,\n0x6745,0x6845,0x6945,0x6a45,0x6b45,0x6c45,0x6d45,0x6e45,0x6f45,0x7045,0x7145,0x7245,0x7345,0x7445,0x7545,0x7645,\n0x7745,0x7845,0x7945,0x7a45,0x3045,0x3145,0x3245,0x3345,0x3445,0x3545,0x3645,0x3745,0x3845,0x3945,0x2b45,0x2f45,\n0x4146,0x4246,0x4346,0x4446,0x4546,0x4646,0x4746,0x4846,0x4946,0x4a46,0x4b46,0x4c46,0x4d46,0x4e46,0x4f46,0x5046,\n0x5146,0x5246,0x5346,0x5446,0x5546,0x5646,0x5746,0x5846,0x5946,0x5a46,0x6146,0x6246,0x6346,0x6446,0x6546,0x6646,\n0x6746,0x6846,0x6946,0x6a46,0x6b46,0x6c46,0x6d46,0x6e46,0x6f46,0x7046,0x7146,0x7246,0x7346,0x7446,0x7546,0x7646,\n0x7746,0x7846,0x7946,0x7a46,0x3046,0x3146,0x3246,0x3346,0x3446,0x3546,0x3646,0x3746,0x3846,0x3946,0x2b46,0x2f46,\n0x4147,0x4247,0x4347,0x4447,0x4547,0x4647,0x4747,0x4847,0x4947,0x4a47,0x4b47,0x4c47,0x4d47,0x4e47,0x4f47,0x5047,\n0x5147,0x5247,0x5347,0x5447,0x5547,0x5647,0x5747,0x5847,0x5947,0x5a47,0x6147,0x6247,0x6347,0x6447,0x6547,0x6647,\n0x6747,0x6847,0x6947,0x6a47,0x6b47,0x6c47,0x6d47,0x6e47,0x6f47,0x7047,0x7147,0x7247,0x7347,0x7447,0x7547,0x7647,\n0x7747,0x7847,0x7947,0x7a47,0x3047,0x3147,0x3247,0x3347,0x3447,0x3547,0x3647,0x3747,0x3847,0x3947,0x2b47,0x2f47,\n0x4148,0x4248,0x4348,0x4448,0x4548,0x4648,0x4748,0x4848,0x4948,0x4a48,0x4b48,0x4c48,0x4d48,0x4e48,0x4f48,0x5048,\n0x5148,0x5248,0x5348,0x5448,0x5548,0x5648,0x5748,0x5848,0x5948,0x5a48,0x6148,0x6248,0x6348,0x6448,0x6548,0x6648,\n0x6748,0x6848,0x6948,0x6a48,0x6b48,0x6c48,0x6d48,0x6e48,0x6f48,0x7048,0x7148,0x7248,0x7348,0x7448,0x7548,0x7648,\n0x7748,0x7848,0x7948,0x7a48,0x3048,0x3148,0x3248,0x3348,0x3448,0x3548,0x3648,0x3748,0x3848,0x3948,0x2b48,0x2f48,\n0x4149,0x4249,0x4349,0x4449,0x4549,0x4649,0x4749,0x4849,0x4949,0x4a49,0x4b49,0x4c49,0x4d49,0x4e49,0x4f49,0x5049,\n0x5149,0x5249,0x5349,0x5449,0x5549,0x5649,0x5749,0x5849,0x5949,0x5a49,0x6149,0x6249,0x6349,0x6449,0x6549,0x6649,\n0x6749,0x6849,0x6949,0x6a49,0x6b49,0x6c49,0x6d49,0x6e49,0x6f49,0x7049,0x7149,0x7249,0x7349,0x7449,0x7549,0x7649,\n0x7749,0x7849,0x7949,0x7a49,0x3049,0x3149,0x3249,0x3349,0x3449,0x3549,0x3649,0x3749,0x3849,0x3949,0x2b49,0x2f49,\n0x414a,0x424a,0x434a,0x444a,0x454a,0x464a,0x474a,0x484a,0x494a,0x4a4a,0x4b4a,0x4c4a,0x4d4a,0x4e4a,0x4f4a,0x504a,\n0x514a,0x524a,0x534a,0x544a,0x554a,0x564a,0x574a,0x584a,0x594a,0x5a4a,0x614a,0x624a,0x634a,0x644a,0x654a,0x664a,\n0x674a,0x684a,0x694a,0x6a4a,0x6b4a,0x6c4a,0x6d4a,0x6e4a,0x6f4a,0x704a,0x714a,0x724a,0x734a,0x744a,0x754a,0x764a,\n0x774a,0x784a,0x794a,0x7a4a,0x304a,0x314a,0x324a,0x334a,0x344a,0x354a,0x364a,0x374a,0x384a,0x394a,0x2b4a,0x2f4a,\n0x414b,0x424b,0x434b,0x444b,0x454b,0x464b,0x474b,0x484b,0x494b,0x4a4b,0x4b4b,0x4c4b,0x4d4b,0x4e4b,0x4f4b,0x504b,\n0x514b,0x524b,0x534b,0x544b,0x554b,0x564b,0x574b,0x584b,0x594b,0x5a4b,0x614b,0x624b,0x634b,0x644b,0x654b,0x664b,\n0x674b,0x684b,0x694b,0x6a4b,0x6b4b,0x6c4b,0x6d4b,0x6e4b,0x6f4b,0x704b,0x714b,0x724b,0x734b,0x744b,0x754b,0x764b,\n0x774b,0x784b,0x794b,0x7a4b,0x304b,0x314b,0x324b,0x334b,0x344b,0x354b,0x364b,0x374b,0x384b,0x394b,0x2b4b,0x2f4b,\n0x414c,0x424c,0x434c,0x444c,0x454c,0x464c,0x474c,0x484c,0x494c,0x4a4c,0x4b4c,0x4c4c,0x4d4c,0x4e4c,0x4f4c,0x504c,\n0x514c,0x524c,0x534c,0x544c,0x554c,0x564c,0x574c,0x584c,0x594c,0x5a4c,0x614c,0x624c,0x634c,0x644c,0x654c,0x664c,\n0x674c,0x684c,0x694c,0x6a4c,0x6b4c,0x6c4c,0x6d4c,0x6e4c,0x6f4c,0x704c,0x714c,0x724c,0x734c,0x744c,0x754c,0x764c,\n0x774c,0x784c,0x794c,0x7a4c,0x304c,0x314c,0x324c,0x334c,0x344c,0x354c,0x364c,0x374c,0x384c,0x394c,0x2b4c,0x2f4c,\n0x414d,0x424d,0x434d,0x444d,0x454d,0x464d,0x474d,0x484d,0x494d,0x4a4d,0x4b4d,0x4c4d,0x4d4d,0x4e4d,0x4f4d,0x504d,\n0x514d,0x524d,0x534d,0x544d,0x554d,0x564d,0x574d,0x584d,0x594d,0x5a4d,0x614d,0x624d,0x634d,0x644d,0x654d,0x664d,\n0x674d,0x684d,0x694d,0x6a4d,0x6b4d,0x6c4d,0x6d4d,0x6e4d,0x6f4d,0x704d,0x714d,0x724d,0x734d,0x744d,0x754d,0x764d,\n0x774d,0x784d,0x794d,0x7a4d,0x304d,0x314d,0x324d,0x334d,0x344d,0x354d,0x364d,0x374d,0x384d,0x394d,0x2b4d,0x2f4d,\n0x414e,0x424e,0x434e,0x444e,0x454e,0x464e,0x474e,0x484e,0x494e,0x4a4e,0x4b4e,0x4c4e,0x4d4e,0x4e4e,0x4f4e,0x504e,\n0x514e,0x524e,0x534e,0x544e,0x554e,0x564e,0x574e,0x584e,0x594e,0x5a4e,0x614e,0x624e,0x634e,0x644e,0x654e,0x664e,\n0x674e,0x684e,0x694e,0x6a4e,0x6b4e,0x6c4e,0x6d4e,0x6e4e,0x6f4e,0x704e,0x714e,0x724e,0x734e,0x744e,0x754e,0x764e,\n0x774e,0x784e,0x794e,0x7a4e,0x304e,0x314e,0x324e,0x334e,0x344e,0x354e,0x364e,0x374e,0x384e,0x394e,0x2b4e,0x2f4e,\n0x414f,0x424f,0x434f,0x444f,0x454f,0x464f,0x474f,0x484f,0x494f,0x4a4f,0x4b4f,0x4c4f,0x4d4f,0x4e4f,0x4f4f,0x504f,\n0x514f,0x524f,0x534f,0x544f,0x554f,0x564f,0x574f,0x584f,0x594f,0x5a4f,0x614f,0x624f,0x634f,0x644f,0x654f,0x664f,\n0x674f,0x684f,0x694f,0x6a4f,0x6b4f,0x6c4f,0x6d4f,0x6e4f,0x6f4f,0x704f,0x714f,0x724f,0x734f,0x744f,0x754f,0x764f,\n0x774f,0x784f,0x794f,0x7a4f,0x304f,0x314f,0x324f,0x334f,0x344f,0x354f,0x364f,0x374f,0x384f,0x394f,0x2b4f,0x2f4f,\n0x4150,0x4250,0x4350,0x4450,0x4550,0x4650,0x4750,0x4850,0x4950,0x4a50,0x4b50,0x4c50,0x4d50,0x4e50,0x4f50,0x5050,\n0x5150,0x5250,0x5350,0x5450,0x5550,0x5650,0x5750,0x5850,0x5950,0x5a50,0x6150,0x6250,0x6350,0x6450,0x6550,0x6650,\n0x6750,0x6850,0x6950,0x6a50,0x6b50,0x6c50,0x6d50,0x6e50,0x6f50,0x7050,0x7150,0x7250,0x7350,0x7450,0x7550,0x7650,\n0x7750,0x7850,0x7950,0x7a50,0x3050,0x3150,0x3250,0x3350,0x3450,0x3550,0x3650,0x3750,0x3850,0x3950,0x2b50,0x2f50,\n0x4151,0x4251,0x4351,0x4451,0x4551,0x4651,0x4751,0x4851,0x4951,0x4a51,0x4b51,0x4c51,0x4d51,0x4e51,0x4f51,0x5051,\n0x5151,0x5251,0x5351,0x5451,0x5551,0x5651,0x5751,0x5851,0x5951,0x5a51,0x6151,0x6251,0x6351,0x6451,0x6551,0x6651,\n0x6751,0x6851,0x6951,0x6a51,0x6b51,0x6c51,0x6d51,0x6e51,0x6f51,0x7051,0x7151,0x7251,0x7351,0x7451,0x7551,0x7651,\n0x7751,0x7851,0x7951,0x7a51,0x3051,0x3151,0x3251,0x3351,0x3451,0x3551,0x3651,0x3751,0x3851,0x3951,0x2b51,0x2f51,\n0x4152,0x4252,0x4352,0x4452,0x4552,0x4652,0x4752,0x4852,0x4952,0x4a52,0x4b52,0x4c52,0x4d52,0x4e52,0x4f52,0x5052,\n0x5152,0x5252,0x5352,0x5452,0x5552,0x5652,0x5752,0x5852,0x5952,0x5a52,0x6152,0x6252,0x6352,0x6452,0x6552,0x6652,\n0x6752,0x6852,0x6952,0x6a52,0x6b52,0x6c52,0x6d52,0x6e52,0x6f52,0x7052,0x7152,0x7252,0x7352,0x7452,0x7552,0x7652,\n0x7752,0x7852,0x7952,0x7a52,0x3052,0x3152,0x3252,0x3352,0x3452,0x3552,0x3652,0x3752,0x3852,0x3952,0x2b52,0x2f52,\n0x4153,0x4253,0x4353,0x4453,0x4553,0x4653,0x4753,0x4853,0x4953,0x4a53,0x4b53,0x4c53,0x4d53,0x4e53,0x4f53,0x5053,\n0x5153,0x5253,0x5353,0x5453,0x5553,0x5653,0x5753,0x5853,0x5953,0x5a53,0x6153,0x6253,0x6353,0x6453,0x6553,0x6653,\n0x6753,0x6853,0x6953,0x6a53,0x6b53,0x6c53,0x6d53,0x6e53,0x6f53,0x7053,0x7153,0x7253,0x7353,0x7453,0x7553,0x7653,\n0x7753,0x7853,0x7953,0x7a53,0x3053,0x3153,0x3253,0x3353,0x3453,0x3553,0x3653,0x3753,0x3853,0x3953,0x2b53,0x2f53,\n0x4154,0x4254,0x4354,0x4454,0x4554,0x4654,0x4754,0x4854,0x4954,0x4a54,0x4b54,0x4c54,0x4d54,0x4e54,0x4f54,0x5054,\n0x5154,0x5254,0x5354,0x5454,0x5554,0x5654,0x5754,0x5854,0x5954,0x5a54,0x6154,0x6254,0x6354,0x6454,0x6554,0x6654,\n0x6754,0x6854,0x6954,0x6a54,0x6b54,0x6c54,0x6d54,0x6e54,0x6f54,0x7054,0x7154,0x7254,0x7354,0x7454,0x7554,0x7654,\n0x7754,0x7854,0x7954,0x7a54,0x3054,0x3154,0x3254,0x3354,0x3454,0x3554,0x3654,0x3754,0x3854,0x3954,0x2b54,0x2f54,\n0x4155,0x4255,0x4355,0x4455,0x4555,0x4655,0x4755,0x4855,0x4955,0x4a55,0x4b55,0x4c55,0x4d55,0x4e55,0x4f55,0x5055,\n0x5155,0x5255,0x5355,0x5455,0x5555,0x5655,0x5755,0x5855,0x5955,0x5a55,0x6155,0x6255,0x6355,0x6455,0x6555,0x6655,\n0x6755,0x6855,0x6955,0x6a55,0x6b55,0x6c55,0x6d55,0x6e55,0x6f55,0x7055,0x7155,0x7255,0x7355,0x7455,0x7555,0x7655,\n0x7755,0x7855,0x7955,0x7a55,0x3055,0x3155,0x3255,0x3355,0x3455,0x3555,0x3655,0x3755,0x3855,0x3955,0x2b55,0x2f55,\n0x4156,0x4256,0x4356,0x4456,0x4556,0x4656,0x4756,0x4856,0x4956,0x4a56,0x4b56,0x4c56,0x4d56,0x4e56,0x4f56,0x5056,\n0x5156,0x5256,0x5356,0x5456,0x5556,0x5656,0x5756,0x5856,0x5956,0x5a56,0x6156,0x6256,0x6356,0x6456,0x6556,0x6656,\n0x6756,0x6856,0x6956,0x6a56,0x6b56,0x6c56,0x6d56,0x6e56,0x6f56,0x7056,0x7156,0x7256,0x7356,0x7456,0x7556,0x7656,\n0x7756,0x7856,0x7956,0x7a56,0x3056,0x3156,0x3256,0x3356,0x3456,0x3556,0x3656,0x3756,0x3856,0x3956,0x2b56,0x2f56,\n0x4157,0x4257,0x4357,0x4457,0x4557,0x4657,0x4757,0x4857,0x4957,0x4a57,0x4b57,0x4c57,0x4d57,0x4e57,0x4f57,0x5057,\n0x5157,0x5257,0x5357,0x5457,0x5557,0x5657,0x5757,0x5857,0x5957,0x5a57,0x6157,0x6257,0x6357,0x6457,0x6557,0x6657,\n0x6757,0x6857,0x6957,0x6a57,0x6b57,0x6c57,0x6d57,0x6e57,0x6f57,0x7057,0x7157,0x7257,0x7357,0x7457,0x7557,0x7657,\n0x7757,0x7857,0x7957,0x7a57,0x3057,0x3157,0x3257,0x3357,0x3457,0x3557,0x3657,0x3757,0x3857,0x3957,0x2b57,0x2f57,\n0x4158,0x4258,0x4358,0x4458,0x4558,0x4658,0x4758,0x4858,0x4958,0x4a58,0x4b58,0x4c58,0x4d58,0x4e58,0x4f58,0x5058,\n0x5158,0x5258,0x5358,0x5458,0x5558,0x5658,0x5758,0x5858,0x5958,0x5a58,0x6158,0x6258,0x6358,0x6458,0x6558,0x6658,\n0x6758,0x6858,0x6958,0x6a58,0x6b58,0x6c58,0x6d58,0x6e58,0x6f58,0x7058,0x7158,0x7258,0x7358,0x7458,0x7558,0x7658,\n0x7758,0x7858,0x7958,0x7a58,0x3058,0x3158,0x3258,0x3358,0x3458,0x3558,0x3658,0x3758,0x3858,0x3958,0x2b58,0x2f58,\n0x4159,0x4259,0x4359,0x4459,0x4559,0x4659,0x4759,0x4859,0x4959,0x4a59,0x4b59,0x4c59,0x4d59,0x4e59,0x4f59,0x5059,\n0x5159,0x5259,0x5359,0x5459,0x5559,0x5659,0x5759,0x5859,0x5959,0x5a59,0x6159,0x6259,0x6359,0x6459,0x6559,0x6659,\n0x6759,0x6859,0x6959,0x6a59,0x6b59,0x6c59,0x6d59,0x6e59,0x6f59,0x7059,0x7159,0x7259,0x7359,0x7459,0x7559,0x7659,\n0x7759,0x7859,0x7959,0x7a59,0x3059,0x3159,0x3259,0x3359,0x3459,0x3559,0x3659,0x3759,0x3859,0x3959,0x2b59,0x2f59,\n0x415a,0x425a,0x435a,0x445a,0x455a,0x465a,0x475a,0x485a,0x495a,0x4a5a,0x4b5a,0x4c5a,0x4d5a,0x4e5a,0x4f5a,0x505a,\n0x515a,0x525a,0x535a,0x545a,0x555a,0x565a,0x575a,0x585a,0x595a,0x5a5a,0x615a,0x625a,0x635a,0x645a,0x655a,0x665a,\n0x675a,0x685a,0x695a,0x6a5a,0x6b5a,0x6c5a,0x6d5a,0x6e5a,0x6f5a,0x705a,0x715a,0x725a,0x735a,0x745a,0x755a,0x765a,\n0x775a,0x785a,0x795a,0x7a5a,0x305a,0x315a,0x325a,0x335a,0x345a,0x355a,0x365a,0x375a,0x385a,0x395a,0x2b5a,0x2f5a,\n0x4161,0x4261,0x4361,0x4461,0x4561,0x4661,0x4761,0x4861,0x4961,0x4a61,0x4b61,0x4c61,0x4d61,0x4e61,0x4f61,0x5061,\n0x5161,0x5261,0x5361,0x5461,0x5561,0x5661,0x5761,0x5861,0x5961,0x5a61,0x6161,0x6261,0x6361,0x6461,0x6561,0x6661,\n0x6761,0x6861,0x6961,0x6a61,0x6b61,0x6c61,0x6d61,0x6e61,0x6f61,0x7061,0x7161,0x7261,0x7361,0x7461,0x7561,0x7661,\n0x7761,0x7861,0x7961,0x7a61,0x3061,0x3161,0x3261,0x3361,0x3461,0x3561,0x3661,0x3761,0x3861,0x3961,0x2b61,0x2f61,\n0x4162,0x4262,0x4362,0x4462,0x4562,0x4662,0x4762,0x4862,0x4962,0x4a62,0x4b62,0x4c62,0x4d62,0x4e62,0x4f62,0x5062,\n0x5162,0x5262,0x5362,0x5462,0x5562,0x5662,0x5762,0x5862,0x5962,0x5a62,0x6162,0x6262,0x6362,0x6462,0x6562,0x6662,\n0x6762,0x6862,0x6962,0x6a62,0x6b62,0x6c62,0x6d62,0x6e62,0x6f62,0x7062,0x7162,0x7262,0x7362,0x7462,0x7562,0x7662,\n0x7762,0x7862,0x7962,0x7a62,0x3062,0x3162,0x3262,0x3362,0x3462,0x3562,0x3662,0x3762,0x3862,0x3962,0x2b62,0x2f62,\n0x4163,0x4263,0x4363,0x4463,0x4563,0x4663,0x4763,0x4863,0x4963,0x4a63,0x4b63,0x4c63,0x4d63,0x4e63,0x4f63,0x5063,\n0x5163,0x5263,0x5363,0x5463,0x5563,0x5663,0x5763,0x5863,0x5963,0x5a63,0x6163,0x6263,0x6363,0x6463,0x6563,0x6663,\n0x6763,0x6863,0x6963,0x6a63,0x6b63,0x6c63,0x6d63,0x6e63,0x6f63,0x7063,0x7163,0x7263,0x7363,0x7463,0x7563,0x7663,\n0x7763,0x7863,0x7963,0x7a63,0x3063,0x3163,0x3263,0x3363,0x3463,0x3563,0x3663,0x3763,0x3863,0x3963,0x2b63,0x2f63,\n0x4164,0x4264,0x4364,0x4464,0x4564,0x4664,0x4764,0x4864,0x4964,0x4a64,0x4b64,0x4c64,0x4d64,0x4e64,0x4f64,0x5064,\n0x5164,0x5264,0x5364,0x5464,0x5564,0x5664,0x5764,0x5864,0x5964,0x5a64,0x6164,0x6264,0x6364,0x6464,0x6564,0x6664,\n0x6764,0x6864,0x6964,0x6a64,0x6b64,0x6c64,0x6d64,0x6e64,0x6f64,0x7064,0x7164,0x7264,0x7364,0x7464,0x7564,0x7664,\n0x7764,0x7864,0x7964,0x7a64,0x3064,0x3164,0x3264,0x3364,0x3464,0x3564,0x3664,0x3764,0x3864,0x3964,0x2b64,0x2f64,\n0x4165,0x4265,0x4365,0x4465,0x4565,0x4665,0x4765,0x4865,0x4965,0x4a65,0x4b65,0x4c65,0x4d65,0x4e65,0x4f65,0x5065,\n0x5165,0x5265,0x5365,0x5465,0x5565,0x5665,0x5765,0x5865,0x5965,0x5a65,0x6165,0x6265,0x6365,0x6465,0x6565,0x6665,\n0x6765,0x6865,0x6965,0x6a65,0x6b65,0x6c65,0x6d65,0x6e65,0x6f65,0x7065,0x7165,0x7265,0x7365,0x7465,0x7565,0x7665,\n0x7765,0x7865,0x7965,0x7a65,0x3065,0x3165,0x3265,0x3365,0x3465,0x3565,0x3665,0x3765,0x3865,0x3965,0x2b65,0x2f65,\n0x4166,0x4266,0x4366,0x4466,0x4566,0x4666,0x4766,0x4866,0x4966,0x4a66,0x4b66,0x4c66,0x4d66,0x4e66,0x4f66,0x5066,\n0x5166,0x5266,0x5366,0x5466,0x5566,0x5666,0x5766,0x5866,0x5966,0x5a66,0x6166,0x6266,0x6366,0x6466,0x6566,0x6666,\n0x6766,0x6866,0x6966,0x6a66,0x6b66,0x6c66,0x6d66,0x6e66,0x6f66,0x7066,0x7166,0x7266,0x7366,0x7466,0x7566,0x7666,\n0x7766,0x7866,0x7966,0x7a66,0x3066,0x3166,0x3266,0x3366,0x3466,0x3566,0x3666,0x3766,0x3866,0x3966,0x2b66,0x2f66,\n0x4167,0x4267,0x4367,0x4467,0x4567,0x4667,0x4767,0x4867,0x4967,0x4a67,0x4b67,0x4c67,0x4d67,0x4e67,0x4f67,0x5067,\n0x5167,0x5267,0x5367,0x5467,0x5567,0x5667,0x5767,0x5867,0x5967,0x5a67,0x6167,0x6267,0x6367,0x6467,0x6567,0x6667,\n0x6767,0x6867,0x6967,0x6a67,0x6b67,0x6c67,0x6d67,0x6e67,0x6f67,0x7067,0x7167,0x7267,0x7367,0x7467,0x7567,0x7667,\n0x7767,0x7867,0x7967,0x7a67,0x3067,0x3167,0x3267,0x3367,0x3467,0x3567,0x3667,0x3767,0x3867,0x3967,0x2b67,0x2f67,\n0x4168,0x4268,0x4368,0x4468,0x4568,0x4668,0x4768,0x4868,0x4968,0x4a68,0x4b68,0x4c68,0x4d68,0x4e68,0x4f68,0x5068,\n0x5168,0x5268,0x5368,0x5468,0x5568,0x5668,0x5768,0x5868,0x5968,0x5a68,0x6168,0x6268,0x6368,0x6468,0x6568,0x6668,\n0x6768,0x6868,0x6968,0x6a68,0x6b68,0x6c68,0x6d68,0x6e68,0x6f68,0x7068,0x7168,0x7268,0x7368,0x7468,0x7568,0x7668,\n0x7768,0x7868,0x7968,0x7a68,0x3068,0x3168,0x3268,0x3368,0x3468,0x3568,0x3668,0x3768,0x3868,0x3968,0x2b68,0x2f68,\n0x4169,0x4269,0x4369,0x4469,0x4569,0x4669,0x4769,0x4869,0x4969,0x4a69,0x4b69,0x4c69,0x4d69,0x4e69,0x4f69,0x5069,\n0x5169,0x5269,0x5369,0x5469,0x5569,0x5669,0x5769,0x5869,0x5969,0x5a69,0x6169,0x6269,0x6369,0x6469,0x6569,0x6669,\n0x6769,0x6869,0x6969,0x6a69,0x6b69,0x6c69,0x6d69,0x6e69,0x6f69,0x7069,0x7169,0x7269,0x7369,0x7469,0x7569,0x7669,\n0x7769,0x7869,0x7969,0x7a69,0x3069,0x3169,0x3269,0x3369,0x3469,0x3569,0x3669,0x3769,0x3869,0x3969,0x2b69,0x2f69,\n0x416a,0x426a,0x436a,0x446a,0x456a,0x466a,0x476a,0x486a,0x496a,0x4a6a,0x4b6a,0x4c6a,0x4d6a,0x4e6a,0x4f6a,0x506a,\n0x516a,0x526a,0x536a,0x546a,0x556a,0x566a,0x576a,0x586a,0x596a,0x5a6a,0x616a,0x626a,0x636a,0x646a,0x656a,0x666a,\n0x676a,0x686a,0x696a,0x6a6a,0x6b6a,0x6c6a,0x6d6a,0x6e6a,0x6f6a,0x706a,0x716a,0x726a,0x736a,0x746a,0x756a,0x766a,\n0x776a,0x786a,0x796a,0x7a6a,0x306a,0x316a,0x326a,0x336a,0x346a,0x356a,0x366a,0x376a,0x386a,0x396a,0x2b6a,0x2f6a,\n0x416b,0x426b,0x436b,0x446b,0x456b,0x466b,0x476b,0x486b,0x496b,0x4a6b,0x4b6b,0x4c6b,0x4d6b,0x4e6b,0x4f6b,0x506b,\n0x516b,0x526b,0x536b,0x546b,0x556b,0x566b,0x576b,0x586b,0x596b,0x5a6b,0x616b,0x626b,0x636b,0x646b,0x656b,0x666b,\n0x676b,0x686b,0x696b,0x6a6b,0x6b6b,0x6c6b,0x6d6b,0x6e6b,0x6f6b,0x706b,0x716b,0x726b,0x736b,0x746b,0x756b,0x766b,\n0x776b,0x786b,0x796b,0x7a6b,0x306b,0x316b,0x326b,0x336b,0x346b,0x356b,0x366b,0x376b,0x386b,0x396b,0x2b6b,0x2f6b,\n0x416c,0x426c,0x436c,0x446c,0x456c,0x466c,0x476c,0x486c,0x496c,0x4a6c,0x4b6c,0x4c6c,0x4d6c,0x4e6c,0x4f6c,0x506c,\n0x516c,0x526c,0x536c,0x546c,0x556c,0x566c,0x576c,0x586c,0x596c,0x5a6c,0x616c,0x626c,0x636c,0x646c,0x656c,0x666c,\n0x676c,0x686c,0x696c,0x6a6c,0x6b6c,0x6c6c,0x6d6c,0x6e6c,0x6f6c,0x706c,0x716c,0x726c,0x736c,0x746c,0x756c,0x766c,\n0x776c,0x786c,0x796c,0x7a6c,0x306c,0x316c,0x326c,0x336c,0x346c,0x356c,0x366c,0x376c,0x386c,0x396c,0x2b6c,0x2f6c,\n0x416d,0x426d,0x436d,0x446d,0x456d,0x466d,0x476d,0x486d,0x496d,0x4a6d,0x4b6d,0x4c6d,0x4d6d,0x4e6d,0x4f6d,0x506d,\n0x516d,0x526d,0x536d,0x546d,0x556d,0x566d,0x576d,0x586d,0x596d,0x5a6d,0x616d,0x626d,0x636d,0x646d,0x656d,0x666d,\n0x676d,0x686d,0x696d,0x6a6d,0x6b6d,0x6c6d,0x6d6d,0x6e6d,0x6f6d,0x706d,0x716d,0x726d,0x736d,0x746d,0x756d,0x766d,\n0x776d,0x786d,0x796d,0x7a6d,0x306d,0x316d,0x326d,0x336d,0x346d,0x356d,0x366d,0x376d,0x386d,0x396d,0x2b6d,0x2f6d,\n0x416e,0x426e,0x436e,0x446e,0x456e,0x466e,0x476e,0x486e,0x496e,0x4a6e,0x4b6e,0x4c6e,0x4d6e,0x4e6e,0x4f6e,0x506e,\n0x516e,0x526e,0x536e,0x546e,0x556e,0x566e,0x576e,0x586e,0x596e,0x5a6e,0x616e,0x626e,0x636e,0x646e,0x656e,0x666e,\n0x676e,0x686e,0x696e,0x6a6e,0x6b6e,0x6c6e,0x6d6e,0x6e6e,0x6f6e,0x706e,0x716e,0x726e,0x736e,0x746e,0x756e,0x766e,\n0x776e,0x786e,0x796e,0x7a6e,0x306e,0x316e,0x326e,0x336e,0x346e,0x356e,0x366e,0x376e,0x386e,0x396e,0x2b6e,0x2f6e,\n0x416f,0x426f,0x436f,0x446f,0x456f,0x466f,0x476f,0x486f,0x496f,0x4a6f,0x4b6f,0x4c6f,0x4d6f,0x4e6f,0x4f6f,0x506f,\n0x516f,0x526f,0x536f,0x546f,0x556f,0x566f,0x576f,0x586f,0x596f,0x5a6f,0x616f,0x626f,0x636f,0x646f,0x656f,0x666f,\n0x676f,0x686f,0x696f,0x6a6f,0x6b6f,0x6c6f,0x6d6f,0x6e6f,0x6f6f,0x706f,0x716f,0x726f,0x736f,0x746f,0x756f,0x766f,\n0x776f,0x786f,0x796f,0x7a6f,0x306f,0x316f,0x326f,0x336f,0x346f,0x356f,0x366f,0x376f,0x386f,0x396f,0x2b6f,0x2f6f,\n0x4170,0x4270,0x4370,0x4470,0x4570,0x4670,0x4770,0x4870,0x4970,0x4a70,0x4b70,0x4c70,0x4d70,0x4e70,0x4f70,0x5070,\n0x5170,0x5270,0x5370,0x5470,0x5570,0x5670,0x5770,0x5870,0x5970,0x5a70,0x6170,0x6270,0x6370,0x6470,0x6570,0x6670,\n0x6770,0x6870,0x6970,0x6a70,0x6b70,0x6c70,0x6d70,0x6e70,0x6f70,0x7070,0x7170,0x7270,0x7370,0x7470,0x7570,0x7670,\n0x7770,0x7870,0x7970,0x7a70,0x3070,0x3170,0x3270,0x3370,0x3470,0x3570,0x3670,0x3770,0x3870,0x3970,0x2b70,0x2f70,\n0x4171,0x4271,0x4371,0x4471,0x4571,0x4671,0x4771,0x4871,0x4971,0x4a71,0x4b71,0x4c71,0x4d71,0x4e71,0x4f71,0x5071,\n0x5171,0x5271,0x5371,0x5471,0x5571,0x5671,0x5771,0x5871,0x5971,0x5a71,0x6171,0x6271,0x6371,0x6471,0x6571,0x6671,\n0x6771,0x6871,0x6971,0x6a71,0x6b71,0x6c71,0x6d71,0x6e71,0x6f71,0x7071,0x7171,0x7271,0x7371,0x7471,0x7571,0x7671,\n0x7771,0x7871,0x7971,0x7a71,0x3071,0x3171,0x3271,0x3371,0x3471,0x3571,0x3671,0x3771,0x3871,0x3971,0x2b71,0x2f71,\n0x4172,0x4272,0x4372,0x4472,0x4572,0x4672,0x4772,0x4872,0x4972,0x4a72,0x4b72,0x4c72,0x4d72,0x4e72,0x4f72,0x5072,\n0x5172,0x5272,0x5372,0x5472,0x5572,0x5672,0x5772,0x5872,0x5972,0x5a72,0x6172,0x6272,0x6372,0x6472,0x6572,0x6672,\n0x6772,0x6872,0x6972,0x6a72,0x6b72,0x6c72,0x6d72,0x6e72,0x6f72,0x7072,0x7172,0x7272,0x7372,0x7472,0x7572,0x7672,\n0x7772,0x7872,0x7972,0x7a72,0x3072,0x3172,0x3272,0x3372,0x3472,0x3572,0x3672,0x3772,0x3872,0x3972,0x2b72,0x2f72,\n0x4173,0x4273,0x4373,0x4473,0x4573,0x4673,0x4773,0x4873,0x4973,0x4a73,0x4b73,0x4c73,0x4d73,0x4e73,0x4f73,0x5073,\n0x5173,0x5273,0x5373,0x5473,0x5573,0x5673,0x5773,0x5873,0x5973,0x5a73,0x6173,0x6273,0x6373,0x6473,0x6573,0x6673,\n0x6773,0x6873,0x6973,0x6a73,0x6b73,0x6c73,0x6d73,0x6e73,0x6f73,0x7073,0x7173,0x7273,0x7373,0x7473,0x7573,0x7673,\n0x7773,0x7873,0x7973,0x7a73,0x3073,0x3173,0x3273,0x3373,0x3473,0x3573,0x3673,0x3773,0x3873,0x3973,0x2b73,0x2f73,\n0x4174,0x4274,0x4374,0x4474,0x4574,0x4674,0x4774,0x4874,0x4974,0x4a74,0x4b74,0x4c74,0x4d74,0x4e74,0x4f74,0x5074,\n0x5174,0x5274,0x5374,0x5474,0x5574,0x5674,0x5774,0x5874,0x5974,0x5a74,0x6174,0x6274,0x6374,0x6474,0x6574,0x6674,\n0x6774,0x6874,0x6974,0x6a74,0x6b74,0x6c74,0x6d74,0x6e74,0x6f74,0x7074,0x7174,0x7274,0x7374,0x7474,0x7574,0x7674,\n0x7774,0x7874,0x7974,0x7a74,0x3074,0x3174,0x3274,0x3374,0x3474,0x3574,0x3674,0x3774,0x3874,0x3974,0x2b74,0x2f74,\n0x4175,0x4275,0x4375,0x4475,0x4575,0x4675,0x4775,0x4875,0x4975,0x4a75,0x4b75,0x4c75,0x4d75,0x4e75,0x4f75,0x5075,\n0x5175,0x5275,0x5375,0x5475,0x5575,0x5675,0x5775,0x5875,0x5975,0x5a75,0x6175,0x6275,0x6375,0x6475,0x6575,0x6675,\n0x6775,0x6875,0x6975,0x6a75,0x6b75,0x6c75,0x6d75,0x6e75,0x6f75,0x7075,0x7175,0x7275,0x7375,0x7475,0x7575,0x7675,\n0x7775,0x7875,0x7975,0x7a75,0x3075,0x3175,0x3275,0x3375,0x3475,0x3575,0x3675,0x3775,0x3875,0x3975,0x2b75,0x2f75,\n0x4176,0x4276,0x4376,0x4476,0x4576,0x4676,0x4776,0x4876,0x4976,0x4a76,0x4b76,0x4c76,0x4d76,0x4e76,0x4f76,0x5076,\n0x5176,0x5276,0x5376,0x5476,0x5576,0x5676,0x5776,0x5876,0x5976,0x5a76,0x6176,0x6276,0x6376,0x6476,0x6576,0x6676,\n0x6776,0x6876,0x6976,0x6a76,0x6b76,0x6c76,0x6d76,0x6e76,0x6f76,0x7076,0x7176,0x7276,0x7376,0x7476,0x7576,0x7676,\n0x7776,0x7876,0x7976,0x7a76,0x3076,0x3176,0x3276,0x3376,0x3476,0x3576,0x3676,0x3776,0x3876,0x3976,0x2b76,0x2f76,\n0x4177,0x4277,0x4377,0x4477,0x4577,0x4677,0x4777,0x4877,0x4977,0x4a77,0x4b77,0x4c77,0x4d77,0x4e77,0x4f77,0x5077,\n0x5177,0x5277,0x5377,0x5477,0x5577,0x5677,0x5777,0x5877,0x5977,0x5a77,0x6177,0x6277,0x6377,0x6477,0x6577,0x6677,\n0x6777,0x6877,0x6977,0x6a77,0x6b77,0x6c77,0x6d77,0x6e77,0x6f77,0x7077,0x7177,0x7277,0x7377,0x7477,0x7577,0x7677,\n0x7777,0x7877,0x7977,0x7a77,0x3077,0x3177,0x3277,0x3377,0x3477,0x3577,0x3677,0x3777,0x3877,0x3977,0x2b77,0x2f77,\n0x4178,0x4278,0x4378,0x4478,0x4578,0x4678,0x4778,0x4878,0x4978,0x4a78,0x4b78,0x4c78,0x4d78,0x4e78,0x4f78,0x5078,\n0x5178,0x5278,0x5378,0x5478,0x5578,0x5678,0x5778,0x5878,0x5978,0x5a78,0x6178,0x6278,0x6378,0x6478,0x6578,0x6678,\n0x6778,0x6878,0x6978,0x6a78,0x6b78,0x6c78,0x6d78,0x6e78,0x6f78,0x7078,0x7178,0x7278,0x7378,0x7478,0x7578,0x7678,\n0x7778,0x7878,0x7978,0x7a78,0x3078,0x3178,0x3278,0x3378,0x3478,0x3578,0x3678,0x3778,0x3878,0x3978,0x2b78,0x2f78,\n0x4179,0x4279,0x4379,0x4479,0x4579,0x4679,0x4779,0x4879,0x4979,0x4a79,0x4b79,0x4c79,0x4d79,0x4e79,0x4f79,0x5079,\n0x5179,0x5279,0x5379,0x5479,0x5579,0x5679,0x5779,0x5879,0x5979,0x5a79,0x6179,0x6279,0x6379,0x6479,0x6579,0x6679,\n0x6779,0x6879,0x6979,0x6a79,0x6b79,0x6c79,0x6d79,0x6e79,0x6f79,0x7079,0x7179,0x7279,0x7379,0x7479,0x7579,0x7679,\n0x7779,0x7879,0x7979,0x7a79,0x3079,0x3179,0x3279,0x3379,0x3479,0x3579,0x3679,0x3779,0x3879,0x3979,0x2b79,0x2f79,\n0x417a,0x427a,0x437a,0x447a,0x457a,0x467a,0x477a,0x487a,0x497a,0x4a7a,0x4b7a,0x4c7a,0x4d7a,0x4e7a,0x4f7a,0x507a,\n0x517a,0x527a,0x537a,0x547a,0x557a,0x567a,0x577a,0x587a,0x597a,0x5a7a,0x617a,0x627a,0x637a,0x647a,0x657a,0x667a,\n0x677a,0x687a,0x697a,0x6a7a,0x6b7a,0x6c7a,0x6d7a,0x6e7a,0x6f7a,0x707a,0x717a,0x727a,0x737a,0x747a,0x757a,0x767a,\n0x777a,0x787a,0x797a,0x7a7a,0x307a,0x317a,0x327a,0x337a,0x347a,0x357a,0x367a,0x377a,0x387a,0x397a,0x2b7a,0x2f7a,\n0x4130,0x4230,0x4330,0x4430,0x4530,0x4630,0x4730,0x4830,0x4930,0x4a30,0x4b30,0x4c30,0x4d30,0x4e30,0x4f30,0x5030,\n0x5130,0x5230,0x5330,0x5430,0x5530,0x5630,0x5730,0x5830,0x5930,0x5a30,0x6130,0x6230,0x6330,0x6430,0x6530,0x6630,\n0x6730,0x6830,0x6930,0x6a30,0x6b30,0x6c30,0x6d30,0x6e30,0x6f30,0x7030,0x7130,0x7230,0x7330,0x7430,0x7530,0x7630,\n0x7730,0x7830,0x7930,0x7a30,0x3030,0x3130,0x3230,0x3330,0x3430,0x3530,0x3630,0x3730,0x3830,0x3930,0x2b30,0x2f30,\n0x4131,0x4231,0x4331,0x4431,0x4531,0x4631,0x4731,0x4831,0x4931,0x4a31,0x4b31,0x4c31,0x4d31,0x4e31,0x4f31,0x5031,\n0x5131,0x5231,0x5331,0x5431,0x5531,0x5631,0x5731,0x5831,0x5931,0x5a31,0x6131,0x6231,0x6331,0x6431,0x6531,0x6631,\n0x6731,0x6831,0x6931,0x6a31,0x6b31,0x6c31,0x6d31,0x6e31,0x6f31,0x7031,0x7131,0x7231,0x7331,0x7431,0x7531,0x7631,\n0x7731,0x7831,0x7931,0x7a31,0x3031,0x3131,0x3231,0x3331,0x3431,0x3531,0x3631,0x3731,0x3831,0x3931,0x2b31,0x2f31,\n0x4132,0x4232,0x4332,0x4432,0x4532,0x4632,0x4732,0x4832,0x4932,0x4a32,0x4b32,0x4c32,0x4d32,0x4e32,0x4f32,0x5032,\n0x5132,0x5232,0x5332,0x5432,0x5532,0x5632,0x5732,0x5832,0x5932,0x5a32,0x6132,0x6232,0x6332,0x6432,0x6532,0x6632,\n0x6732,0x6832,0x6932,0x6a32,0x6b32,0x6c32,0x6d32,0x6e32,0x6f32,0x7032,0x7132,0x7232,0x7332,0x7432,0x7532,0x7632,\n0x7732,0x7832,0x7932,0x7a32,0x3032,0x3132,0x3232,0x3332,0x3432,0x3532,0x3632,0x3732,0x3832,0x3932,0x2b32,0x2f32,\n0x4133,0x4233,0x4333,0x4433,0x4533,0x4633,0x4733,0x4833,0x4933,0x4a33,0x4b33,0x4c33,0x4d33,0x4e33,0x4f33,0x5033,\n0x5133,0x5233,0x5333,0x5433,0x5533,0x5633,0x5733,0x5833,0x5933,0x5a33,0x6133,0x6233,0x6333,0x6433,0x6533,0x6633,\n0x6733,0x6833,0x6933,0x6a33,0x6b33,0x6c33,0x6d33,0x6e33,0x6f33,0x7033,0x7133,0x7233,0x7333,0x7433,0x7533,0x7633,\n0x7733,0x7833,0x7933,0x7a33,0x3033,0x3133,0x3233,0x3333,0x3433,0x3533,0x3633,0x3733,0x3833,0x3933,0x2b33,0x2f33,\n0x4134,0x4234,0x4334,0x4434,0x4534,0x4634,0x4734,0x4834,0x4934,0x4a34,0x4b34,0x4c34,0x4d34,0x4e34,0x4f34,0x5034,\n0x5134,0x5234,0x5334,0x5434,0x5534,0x5634,0x5734,0x5834,0x5934,0x5a34,0x6134,0x6234,0x6334,0x6434,0x6534,0x6634,\n0x6734,0x6834,0x6934,0x6a34,0x6b34,0x6c34,0x6d34,0x6e34,0x6f34,0x7034,0x7134,0x7234,0x7334,0x7434,0x7534,0x7634,\n0x7734,0x7834,0x7934,0x7a34,0x3034,0x3134,0x3234,0x3334,0x3434,0x3534,0x3634,0x3734,0x3834,0x3934,0x2b34,0x2f34,\n0x4135,0x4235,0x4335,0x4435,0x4535,0x4635,0x4735,0x4835,0x4935,0x4a35,0x4b35,0x4c35,0x4d35,0x4e35,0x4f35,0x5035,\n0x5135,0x5235,0x5335,0x5435,0x5535,0x5635,0x5735,0x5835,0x5935,0x5a35,0x6135,0x6235,0x6335,0x6435,0x6535,0x6635,\n0x6735,0x6835,0x6935,0x6a35,0x6b35,0x6c35,0x6d35,0x6e35,0x6f35,0x7035,0x7135,0x7235,0x7335,0x7435,0x7535,0x7635,\n0x7735,0x7835,0x7935,0x7a35,0x3035,0x3135,0x3235,0x3335,0x3435,0x3535,0x3635,0x3735,0x3835,0x3935,0x2b35,0x2f35,\n0x4136,0x4236,0x4336,0x4436,0x4536,0x4636,0x4736,0x4836,0x4936,0x4a36,0x4b36,0x4c36,0x4d36,0x4e36,0x4f36,0x5036,\n0x5136,0x5236,0x5336,0x5436,0x5536,0x5636,0x5736,0x5836,0x5936,0x5a36,0x6136,0x6236,0x6336,0x6436,0x6536,0x6636,\n0x6736,0x6836,0x6936,0x6a36,0x6b36,0x6c36,0x6d36,0x6e36,0x6f36,0x7036,0x7136,0x7236,0x7336,0x7436,0x7536,0x7636,\n0x7736,0x7836,0x7936,0x7a36,0x3036,0x3136,0x3236,0x3336,0x3436,0x3536,0x3636,0x3736,0x3836,0x3936,0x2b36,0x2f36,\n0x4137,0x4237,0x4337,0x4437,0x4537,0x4637,0x4737,0x4837,0x4937,0x4a37,0x4b37,0x4c37,0x4d37,0x4e37,0x4f37,0x5037,\n0x5137,0x5237,0x5337,0x5437,0x5537,0x5637,0x5737,0x5837,0x5937,0x5a37,0x6137,0x6237,0x6337,0x6437,0x6537,0x6637,\n0x6737,0x6837,0x6937,0x6a37,0x6b37,0x6c37,0x6d37,0x6e37,0x6f37,0x7037,0x7137,0x7237,0x7337,0x7437,0x7537,0x7637,\n0x7737,0x7837,0x7937,0x7a37,0x3037,0x3137,0x3237,0x3337,0x3437,0x3537,0x3637,0x3737,0x3837,0x3937,0x2b37,0x2f37,\n0x4138,0x4238,0x4338,0x4438,0x4538,0x4638,0x4738,0x4838,0x4938,0x4a38,0x4b38,0x4c38,0x4d38,0x4e38,0x4f38,0x5038,\n0x5138,0x5238,0x5338,0x5438,0x5538,0x5638,0x5738,0x5838,0x5938,0x5a38,0x6138,0x6238,0x6338,0x6438,0x6538,0x6638,\n0x6738,0x6838,0x6938,0x6a38,0x6b38,0x6c38,0x6d38,0x6e38,0x6f38,0x7038,0x7138,0x7238,0x7338,0x7438,0x7538,0x7638,\n0x7738,0x7838,0x7938,0x7a38,0x3038,0x3138,0x3238,0x3338,0x3438,0x3538,0x3638,0x3738,0x3838,0x3938,0x2b38,0x2f38,\n0x4139,0x4239,0x4339,0x4439,0x4539,0x4639,0x4739,0x4839,0x4939,0x4a39,0x4b39,0x4c39,0x4d39,0x4e39,0x4f39,0x5039,\n0x5139,0x5239,0x5339,0x5439,0x5539,0x5639,0x5739,0x5839,0x5939,0x5a39,0x6139,0x6239,0x6339,0x6439,0x6539,0x6639,\n0x6739,0x6839,0x6939,0x6a39,0x6b39,0x6c39,0x6d39,0x6e39,0x6f39,0x7039,0x7139,0x7239,0x7339,0x7439,0x7539,0x7639,\n0x7739,0x7839,0x7939,0x7a39,0x3039,0x3139,0x3239,0x3339,0x3439,0x3539,0x3639,0x3739,0x3839,0x3939,0x2b39,0x2f39,\n0x412b,0x422b,0x432b,0x442b,0x452b,0x462b,0x472b,0x482b,0x492b,0x4a2b,0x4b2b,0x4c2b,0x4d2b,0x4e2b,0x4f2b,0x502b,\n0x512b,0x522b,0x532b,0x542b,0x552b,0x562b,0x572b,0x582b,0x592b,0x5a2b,0x612b,0x622b,0x632b,0x642b,0x652b,0x662b,\n0x672b,0x682b,0x692b,0x6a2b,0x6b2b,0x6c2b,0x6d2b,0x6e2b,0x6f2b,0x702b,0x712b,0x722b,0x732b,0x742b,0x752b,0x762b,\n0x772b,0x782b,0x792b,0x7a2b,0x302b,0x312b,0x322b,0x332b,0x342b,0x352b,0x362b,0x372b,0x382b,0x392b,0x2b2b,0x2f2b,\n0x412f,0x422f,0x432f,0x442f,0x452f,0x462f,0x472f,0x482f,0x492f,0x4a2f,0x4b2f,0x4c2f,0x4d2f,0x4e2f,0x4f2f,0x502f,\n0x512f,0x522f,0x532f,0x542f,0x552f,0x562f,0x572f,0x582f,0x592f,0x5a2f,0x612f,0x622f,0x632f,0x642f,0x652f,0x662f,\n0x672f,0x682f,0x692f,0x6a2f,0x6b2f,0x6c2f,0x6d2f,0x6e2f,0x6f2f,0x702f,0x712f,0x722f,0x732f,0x742f,0x752f,0x762f,\n0x772f,0x782f,0x792f,0x7a2f,0x302f,0x312f,0x322f,0x332f,0x342f,0x352f,0x362f,0x372f,0x382f,0x392f,0x2b2f,0x2f2f };\n\n#define EX(_i_) {\\\n  unsigned v = ctou32(ip+3+_i_*6  ); u = BSWAP32(u); stou32(op+_i_*8,   XU32(u));\\\n           u = ctou32(ip+3+_i_*6+3); v = BSWAP32(v); stou32(op+_i_*8+4, XU32(v));\\\n}\n\nsize_t tb64xenc(const unsigned char *in, size_t inlen, unsigned char *out) {\n         size_t        outlen = TB64ENCLEN(inlen);\n  const  unsigned char *ip    = in, *out_ = out + outlen;\n         unsigned char *op    = out;\n  \n  if(outlen > 4+8) {\n\tunsigned u = ctou32(ip);\n    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); }\n    for(; op < out_-(4+ 8); op +=  8, ip += ( 8/4)*3)   EX(0);\n  }\n  EXTAIL(1);\n  return outlen;\n}\n"
  },
  {
    "path": "turbob64d.c",
    "content": "/**\n    Copyright (C) powturbo 2016-2023\n    SPDX-License-Identifier: GPL v3 License\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\n    - homepage : https://sites.google.com/site/powturbo/\n    - github   : https://github.com/powturbo\n    - twitter  : https://twitter.com/powturbo\n    - email    : powturbo [_AT_] gmail [_DOT_] com\n**/\n// Turbo-Base64: Scalar decode \n//------------- TurboBase64 : Base64 decoding -------------------\n#include \"turbob64.h\"\n#include \"turbob64_.h\"\n\n//--------------------- Decoding with small lut (only 64 bytes used)------------------------------------\n\n#define _ 0xff // invald entry\nstatic const unsigned char lut[] = {\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _,62, _, _, _,63,\n52,53,54,55,56,57,58,59,60,61, _, _, _, _, _, _,\n _, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,\n15,16,17,18,19,20,21,22,23,24,25, _, _, _, _, _,\n _,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,\n41,42,43,44,45,46,47,48,49,50,51, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ \n};\n#undef _\n\t\t\t\t   \n  #ifdef NCHECK     // no checking\n#define DSC(a) DS(a)\n  #else\n    #ifdef B64CHECK // Full check\n#undef DS\n#define DS(a) DSC(a)\n    #endif\n  #endif\n  \n#define DS32(_u_) BSWAP32(lut[(unsigned char)(_u_     )] << 26 |\\\n                          lut[(unsigned char)(_u_>>  8)] << 20 |\\\n                          lut[(unsigned char)(_u_>> 16)] << 14 |\\\n                          lut[                _u_>> 24 ] <<  8)\n\n#define DS32C(_u_)       (lut[(unsigned char)(_u_     )] |\\\n                          lut[(unsigned char)(_u_>>  8)] |\\\n                          lut[(unsigned char)(_u_>> 16)] |\\\n                          lut[                _u_>> 24 ])\n\n#define DS_(_i_,_check0_,_check1_) { unsigned _o0,_o1, _q0,_q1;\\\n  ltou32(&u0, ip+8+_i_*16  ); ltou32(&u1, ip+8+_i_*16+4  ); _o0 = DS32(v0); _o1 = DS32(v1); _check0_; \\\n  ltou32(&v0, ip+8+_i_*16+8); ltou32(&v1, ip+8+_i_*16+8+4); _q0 = DS32(u0); _q1 = DS32(u1); _check1_; \\\n  stou32(op+_i_*12,   _o0); stou32(op+_i_*12+3, _o1);\\\n  stou32(op+_i_*12+6, _q0); stou32(op+_i_*12+9, _q1);\\\n} \n\n#define DS(_i_)    DS_(_i_,;,;)\n#define DSC64(_i_) DS_(_i_,CHECK0(cu |= _o0),CHECK1(cu |= _q0)) \n \nsize_t tb64sdec(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {\n  const unsigned char *ip = in;\n        unsigned char *op = out;  \n        CHECK0(unsigned cu = 0);\n  \n  if(inlen > 16+4) { \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n    if(inlen&3) return 0;\n    unsigned v0 = ctou32(ip), v1 = ctou32(ip+4), u0,u1;\n    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); }\n    for(; ip < in+inlen-4-16;  ip +=  16, op +=  16*3/4)   DS( 0);\n  } else if(!inlen) return 0;\n  for(; ip < (in+inlen)-4; ip += 4, op += 3) { unsigned u = ctou32(ip); u = DS32(u); stou32(op, u); CHECK0(cu |= u); }\n  \n       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\n  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\n  else if(ip[1] != '=') {                                                                        *op++  = BSWAP32(lut[ip[0]]<<26 | lut[ip[1]]<<20); cu |= lut[ip[0]] | lut[ip[1]];             } // 2->1 byte\n  else                  {                                                                        *op++  = BSWAP32(lut[ip[0]]);                      cu |= lut[ip[0]];                          };// 1->1 byte\n  return (cu == 0xff)?0:(op - out);\n}\n\n//------ Fast decoding with pre shifted lookup table: 4k=4*4*256, (but only 4*4*64 = 1024 bytes used) for fast decoding --------------------------------------------------------------------\n\n  #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) \n#define _ -1 // invalid entry\nconst unsigned tb64lutd0[] = {\n         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _, \n         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,\n         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,0xf8000000,         _,         _,         _,0xfc000000,\n0xd0000000,0xd4000000,0xd8000000,0xdc000000,0xe0000000,0xe4000000,0xe8000000,0xec000000,0xf0000000,0xf4000000,         _,         _,         _,         _,         _,         _,\n         _,0x00000000,0x04000000,0x08000000,0x0c000000,0x10000000,0x14000000,0x18000000,0x1c000000,0x20000000,0x24000000,0x28000000,0x2c000000,0x30000000,0x34000000,0x38000000,\n0x3c000000,0x40000000,0x44000000,0x48000000,0x4c000000,0x50000000,0x54000000,0x58000000,0x5c000000,0x60000000,0x64000000,         _,         _,         _,         _,         _,\n         _,0x68000000,0x6c000000,0x70000000,0x74000000,0x78000000,0x7c000000,0x80000000,0x84000000,0x88000000,0x8c000000,0x90000000,0x94000000,0x98000000,0x9c000000,0xa0000000,\n0xa4000000,0xa8000000,0xac000000,0xb0000000,0xb4000000,0xb8000000,0xbc000000,0xc0000000,0xc4000000,0xc8000000,0xcc000000,         _,         _,         _,         _,         _,\n         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,\n         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,\n         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,\n         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,\n         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,\n         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _, \n         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,\n         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _,         _\n};\n\nconst unsigned tb64lutd1[] = {\n        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,\n        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,\n        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,0x3e00000,        _,        _,        _,0x3f00000,\n0x3400000,0x3500000,0x3600000,0x3700000,0x3800000,0x3900000,0x3a00000,0x3b00000,0x3c00000,0x3d00000,        _,        _,        _,        _,        _,        _,\n        _,0x0000000,0x0100000,0x0200000,0x0300000,0x0400000,0x0500000,0x0600000,0x0700000,0x0800000,0x0900000,0x0a00000,0x0b00000,0x0c00000,0x0d00000,0x0e00000,\n0x0f00000,0x1000000,0x1100000,0x1200000,0x1300000,0x1400000,0x1500000,0x1600000,0x1700000,0x1800000,0x1900000,        _,        _,        _,        _,        _,\n        _,0x1a00000,0x1b00000,0x1c00000,0x1d00000,0x1e00000,0x1f00000,0x2000000,0x2100000,0x2200000,0x2300000,0x2400000,0x2500000,0x2600000,0x2700000,0x2800000,\n0x2900000,0x2a00000,0x2b00000,0x2c00000,0x2d00000,0x2e00000,0x2f00000,0x3000000,0x3100000,0x3200000,0x3300000,        _,        _,        _,        _,        _,\n        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,\n        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,\n        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,\n        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,\n        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,\n        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,\n        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,\n        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,        _,         _\n};\n\nconst unsigned tb64lutd2[] = {\n      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,\n      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,\n      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,0xf8000,      _,      _,      _,0xfc000,\n0xd0000,0xd4000,0xd8000,0xdc000,0xe0000,0xe4000,0xe8000,0xec000,0xf0000,0xf4000,      _,      _,      _,      _,      _,      _,\n      _,0x00000,0x04000,0x08000,0x0c000,0x10000,0x14000,0x18000,0x1c000,0x20000,0x24000,0x28000,0x2c000,0x30000,0x34000,0x38000,\n0x3c000,0x40000,0x44000,0x48000,0x4c000,0x50000,0x54000,0x58000,0x5c000,0x60000,0x64000,      _,      _,      _,      _,      _,\n      _,0x68000,0x6c000,0x70000,0x74000,0x78000,0x7c000,0x80000,0x84000,0x88000,0x8c000,0x90000,0x94000,0x98000,0x9c000,0xa0000,\n0xa4000,0xa8000,0xac000,0xb0000,0xb4000,0xb8000,0xbc000,0xc0000,0xc4000,0xc8000,0xcc000,      _,      _,      _,      _,      _,\n      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,\n      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,\n      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,\n      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,\n      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,\n      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _, \n      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,\n      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _,      _\n};\n\nconst unsigned tb64lutd3[] = {\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,0x3e00,     _,     _,     _,0x3f00,\n0x3400,0x3500,0x3600,0x3700,0x3800,0x3900,0x3a00,0x3b00,0x3c00,0x3d00,     _,     _,     _,     _,     _,     _,\n     _,0x0000,0x0100,0x0200,0x0300,0x0400,0x0500,0x0600,0x0700,0x0800,0x0900,0x0a00,0x0b00,0x0c00,0x0d00,0x0e00,\n0x0f00,0x1000,0x1100,0x1200,0x1300,0x1400,0x1500,0x1600,0x1700,0x1800,0x1900,     _,     _,     _,     _,     _,\n     _,0x1a00,0x1b00,0x1c00,0x1d00,0x1e00,0x1f00,0x2000,0x2100,0x2200,0x2300,0x2400,0x2500,0x2600,0x2700,0x2800,\n0x2900,0x2a00,0x2b00,0x2c00,0x2d00,0x2e00,0x2f00,0x3000,0x3100,0x3200,0x3300,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _\n};\n#undef _\n\n  #else\n#define _ -1 // invalid entry\nconst unsigned tb64lutd0[] = { \n   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,\n   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,\n   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,0xf8,   _,   _,   _,0xfc,\n0xd0,0xd4,0xd8,0xdc,0xe0,0xe4,0xe8,0xec,0xf0,0xf4,   _,   _,   _,   _,   _,   _,\n   _,0x00,0x04,0x08,0x0c,0x10,0x14,0x18,0x1c,0x20,0x24,0x28,0x2c,0x30,0x34,0x38,\n0x3c,0x40,0x44,0x48,0x4c,0x50,0x54,0x58,0x5c,0x60,0x64,   _,   _,   _,   _,   _,\n   _,0x68,0x6c,0x70,0x74,0x78,0x7c,0x80,0x84,0x88,0x8c,0x90,0x94,0x98,0x9c,0xa0,\n0xa4,0xa8,0xac,0xb0,0xb4,0xb8,0xbc,0xc0,0xc4,0xc8,0xcc,   _,   _,   _,   _,   _,\n   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,\n   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,\n   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,\n   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,\n   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,\n   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,\n   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,\n   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _,   _\n};\n\nconst unsigned tb64lutd1[] = {\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,0xe003,     _,     _,     _,0xf003,\n0x4003,0x5003,0x6003,0x7003,0x8003,0x9003,0xa003,0xb003,0xc003,0xd003,     _,     _,     _,     _,     _,     _,\n     _,0x0000,0x1000,0x2000,0x3000,0x4000,0x5000,0x6000,0x7000,0x8000,0x9000,0xa000,0xb000,0xc000,0xd000,0xe000,\n0xf000,0x0001,0x1001,0x2001,0x3001,0x4001,0x5001,0x6001,0x7001,0x8001,0x9001,     _,     _,     _,     _,     _,\n     _,0xa001,0xb001,0xc001,0xd001,0xe001,0xf001,0x0002,0x1002,0x2002,0x3002,0x4002,0x5002,0x6002,0x7002,0x8002,\n0x9002,0xa002,0xb002,0xc002,0xd002,0xe002,0xf002,0x0003,0x1003,0x2003,0x3003,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,\n     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _,     _\n};\n\nconst unsigned tb64lutd2[] = {\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,0x800f00,       _,       _,       _,0xc00f00,\n0x000d00,0x400d00,0x800d00,0xc00d00,0x000e00,0x400e00,0x800e00,0xc00e00,0x000f00,0x400f00,       _,       _,       _,       _,       _,       _,\n       _,0x000000,0x400000,0x800000,0xc00000,0x000100,0x400100,0x800100,0xc00100,0x000200,0x400200,0x800200,0xc00200,0x000300,0x400300,0x800300,\n0xc00300,0x000400,0x400400,0x800400,0xc00400,0x000500,0x400500,0x800500,0xc00500,0x000600,0x400600,       _,       _,       _,       _,       _,\n       _,0x800600,0xc00600,0x000700,0x400700,0x800700,0xc00700,0x000800,0x400800,0x800800,0xc00800,0x000900,0x400900,0x800900,0xc00900,0x000a00,\n0x400a00,0x800a00,0xc00a00,0x000b00,0x400b00,0x800b00,0xc00b00,0x000c00,0x400c00,0x800c00,0xc00c00,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _\n};\n\nconst unsigned tb64lutd3[] = {\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,0x3e0000,       _,       _,       _,0x3f0000,\n0x340000,0x350000,0x360000,0x370000,0x380000,0x390000,0x3a0000,0x3b0000,0x3c0000,0x3d0000,       _,       _,       _,       _,       _,       _,\n       _,0x000000,0x010000,0x020000,0x030000,0x040000,0x050000,0x060000,0x070000,0x080000,0x090000,0x0a0000,0x0b0000,0x0c0000,0x0d0000,0x0e0000,\n0x0f0000,0x100000,0x110000,0x120000,0x130000,0x140000,0x150000,0x160000,0x170000,0x180000,0x190000,       _,       _,       _,       _,       _,\n       _,0x1a0000,0x1b0000,0x1c0000,0x1d0000,0x1e0000,0x1f0000,0x200000,0x210000,0x220000,0x230000,0x240000,0x250000,0x260000,0x270000,0x280000,\n0x290000,0x2a0000,0x2b0000,0x2c0000,0x2d0000,0x2e0000,0x2f0000,0x300000,0x310000,0x320000,0x330000,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,\n       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _,       _\n};\n#undef _\n  #endif\n\nsize_t tb64declen(const unsigned char *__restrict in, size_t inlen) {\n  if(!inlen || (inlen&3)) return 0;\n\n  size_t outlen = (inlen/4)*3;\n  const unsigned char *ip = in+inlen;\n       if(ip[-1] != '=');  \n  else if(ip[-2] != '=') outlen -= 1; \n  else if(ip[-3] != '=') outlen -= 2;\n  else                   outlen -= 3;\n  return outlen;\n} \n\n  #ifdef NCHECK\n#define DXC(a) DX(a)\n  #else\n    #ifdef B64CHECK\n#undef DX\n#define DX(a) DXC(a)\n    #endif\n  #endif\n\n  #ifdef _TB64X_32\n#define DX_(_i_,_check0_,_check1_) { unsigned _o0,_o1, _q0,_q1;\\\n  ltou32(&u0, ip+8+_i_*16  ); ltou32(&u1, ip+8+_i_*16+4  ); _o0 = DU32(v0); _o1 = DU32(v1); _check0_; \\\n  ltou32(&v0, ip+8+_i_*16+8); ltou32(&v1, ip+8+_i_*16+8+4); _q0 = DU32(u0); _q1 = DU32(u1); _check1_; \\\n  stou32(op+_i_*12,   _o0); stou32(op+_i_*12+3, _o1);\\\n  stou32(op+_i_*12+6, _q0); stou32(op+_i_*12+9, _q1);\\\n}\n  #else \n#define DX_(_i_,_check0_,_check1_) { unsigned _o0,_o1, _q0,_q1; unsigned long long u;\\\n  ltou64(&u, ip+8+_i_*16  );\\\n            _o0 = DU32((unsigned)v); \\\n  v >>= 32; _o1 = DU32((unsigned)v); _check0_;\\\n  ltou64(&v, ip+8+_i_*16+8);\\\n            _q0 = DU32((unsigned)u);\\\n  u >>= 32; _q1 = DU32((unsigned)u); _check1_;\\\n  stou32(op+_i_*12,   _o0); stou32(op+_i_*12+3, _o1);\\\n  stou32(op+_i_*12+6, _q0); stou32(op+_i_*12+9, _q1);\\\n}\n  #endif\n\n#define DX(_i_)    DX_(_i_,;,;)\n#define DXC64(_i_) DX_(_i_,CHECK0(cu |= _o0),CHECK1(cu |= _q0)) \n\nsize_t tb64xdec(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {\n  const unsigned char *ip = in;\n        unsigned char *op = out;  \n        CHECK0(unsigned cu = 0);\n  \n  if(inlen > 16+4) { \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n    if(inlen&3) return 0;\n\t  #ifdef _TB64X_32\n    unsigned v0 = ctou32(ip), v1 = ctou32(ip+4), u0,u1;\n\t  #else\n    unsigned long long v = ctou64(ip),u; \n\t  #endif\n    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); }\n    for(; ip < in+inlen-4-16;  ip +=  16, op +=  16*3/4)   DX( 0);\n  } else if(!inlen) return 0;\n  for(; ip < (in+inlen)-4; ip += 4, op += 3) { unsigned u = ctou32(ip); u = DU32(u); stou32(op, u); CHECK0(cu |= u); }\n  DXTAILC(ip,out,op,CHECK0(cu |= u));\n  return CHECK0((cu == (unsigned)-1)?(size_t)0:)op - out;\n}\n"
  },
  {
    "path": "turbob64v128.c",
    "content": "/**\n    Copyright (C) powturbo 2016-2023\n    SPDX-License-Identifier: GPL v3 License\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\n    - homepage : https://sites.google.com/site/powturbo/\n    - github   : https://github.com/powturbo\n    - twitter  : https://twitter.com/powturbo\n    - email    : powturbo [_AT_] gmail [_DOT_] com\n**/\n//  Turbo-Base64: ssse3 + arm neon functions (see also turbob64v256)\n\n#include <string.h>\n\n  #if defined(__AVX__)\n#include <immintrin.h>\n#define FUNPREF tb64v128a\n  #elif defined(__SSE4_1__)\n#include <smmintrin.h>\n#define FUNPREF tb64v128\n  #elif defined(__SSSE3__)\n    #ifdef __powerpc64__\n#define __SSE__   1\n#define __SSE2__  1\n#define __SSE3__  1\n#define NO_WARN_X86_INTRINSICS 1\n    #endif\n#define FUNPREF tb64v128\n#include <tmmintrin.h>\n  #elif defined(__SSE2__)\n#include <emmintrin.h>\n  #elif defined(__ARM_NEON)\n#include <arm_neon.h>\n  #endif\n  \n#include \"turbob64_.h\"\n#include \"turbob64.h\"\n\n#ifdef __ARM_NEON  //----------------------------------- arm neon --------------------------------\n\n#define _ 0xff // invald entry\nstatic const unsigned char lut[] = {\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,\n _, _, _, _, _, _, _, _, _, _, _,62, _, _, _,63,\n52,53,54,55,56,57,58,59,60,61, _, _, _, _, _, _,\n _, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,\n15,16,17,18,19,20,21,22,23,24,25, _, _, _, _, _,\n _,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,\n41,42,43,44,45,46,47,48,49,50,51, _, _, _, _, _,\n};\n#undef _\n\n#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ == 10 && __GNUC_MINOR__ <= 2 || \\\n                                                 __GNUC__ ==  9 && __GNUC_MINOR__ <= 3 || \\\n                                                 __GNUC__ ==  8 && __GNUC_MINOR__ <= 4 || \\\n\t\t\t\t\t\t\t\t\t\t\t\t __GNUC__ <= 7)\nstatic inline uint8x16x4_t vld1q_u8_x4(const uint8_t *lut) {\n  uint8x16x4_t v;\n  v.val[0] = vld1q_u8(lut);\n  v.val[1] = vld1q_u8(lut+16);\n  v.val[2] = vld1q_u8(lut+32);\n  v.val[3] = vld1q_u8(lut+48);\n  return v;\n}\n  #endif\n\n#define B64D(iv, ov) {\\\n    iv.val[0] = vqtbx4q_u8(vqtbl4q_u8(vlut1, veorq_u8(iv.val[0], cv40)), vlut0, iv.val[0]);\\\n    iv.val[1] = vqtbx4q_u8(vqtbl4q_u8(vlut1, veorq_u8(iv.val[1], cv40)), vlut0, iv.val[1]);\\\n    iv.val[2] = vqtbx4q_u8(vqtbl4q_u8(vlut1, veorq_u8(iv.val[2], cv40)), vlut0, iv.val[2]);\\\n    iv.val[3] = vqtbx4q_u8(vqtbl4q_u8(vlut1, veorq_u8(iv.val[3], cv40)), vlut0, iv.val[3]);\\\n\\\n\tov.val[0] = vorrq_u8(vshlq_n_u8(iv.val[0], 2), vshrq_n_u8(iv.val[1], 4));\\\n\tov.val[1] = vorrq_u8(vshlq_n_u8(iv.val[1], 4), vshrq_n_u8(iv.val[2], 2));\\\n\tov.val[2] = vorrq_u8(vshlq_n_u8(iv.val[2], 6),            iv.val[3]    );\\\n}\n\n#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])))\n\nsize_t tb64v128dec(const unsigned char *in, size_t inlen, unsigned char *out) {\n  const unsigned char *ip;\n        unsigned char *op; \n  const uint8x16x4_t vlut0 = vld1q_u8_x4( lut),\n                     vlut1 = vld1q_u8_x4(&lut[64]);\n  const uint8x16_t    cv40 = vdupq_n_u8(0x40);\n        uint8x16_t      xv = vdupq_n_u8(0);\n  #define DN 256\n  for(ip = in, op = out; ip != in+(inlen&~(DN-1)); ip += DN, op += (DN/4)*3) { PREFETCH(ip,256,0);\t\n    uint8x16x4_t iv0 = vld4q_u8(ip),\n                 iv1 = vld4q_u8(ip+64);                                                    \n\tuint8x16x3_t ov0,ov1; \n    B64D(iv0, ov0);\n      #if DN > 128\n\tCHECK1(_B64CHK128(iv0,xv));\n      #else\n\tCHECK0(_B64CHK128(iv0,xv));\n      #endif\n\tB64D(iv1, ov1); CHECK1(_B64CHK128(iv1,xv));\n      #if DN > 128\n    iv0 = vld4q_u8(ip+128);\n    iv1 = vld4q_u8(ip+192);              \n      #endif\n\tvst3q_u8(op,    ov0);       \n\tvst3q_u8(op+48, ov1);                                                                                                                                                                       \n      #if DN > 128\n\tB64D(iv0,ov0);\tCHECK1(_B64CHK128(iv0,xv));\n\tB64D(iv1,ov1); \n\tvst3q_u8(op+ 96, ov0);       \n\tvst3q_u8(op+144, ov1);                                                                                                                                                                       \n\tCHECK0(_B64CHK128(iv1,xv));\n      #endif\n  }\n  for(                 ; ip != in+(inlen&~(64-1)); ip += 64, op += (64/4)*3) { \t\n    uint8x16x4_t iv = vld4q_u8(ip);\n\tuint8x16x3_t ov; B64D(iv,ov);\n\tvst3q_u8(op, ov);                                                                                                                          \n\tCHECK0(xv = vorrq_u8(xv, vorrq_u8(vorrq_u8(iv.val[0], iv.val[1]), vorrq_u8(iv.val[2], iv.val[3]))));\n  }\n  size_t rc = 0, r = inlen&(64-1); \n  if(r && !(rc=tb64xdec(ip, r, op)) || vaddvq_u8(vshrq_n_u8(xv,7))) { return 0; }//decode all\n  return (op - out) + rc; \n}\n\n//--------------------------------------------------------------------------------------------------\n#define B64E(iv, ov) {\\\n  ov.val[0] =                                             vshrq_n_u8(iv.val[0], 2);\\\n  ov.val[1] = vandq_u8(vorrq_u8(vshlq_n_u8(iv.val[0], 4), vshrq_n_u8(iv.val[1], 4)), cv3f);\\\n  ov.val[2] = vandq_u8(vorrq_u8(vshlq_n_u8(iv.val[1], 2), vshrq_n_u8(iv.val[2], 6)), cv3f);\\\n  ov.val[3] = vandq_u8(                    iv.val[2],                                cv3f);\\\n\\\n  ov.val[0] = vqtbl4q_u8(vlut, ov.val[0]);\\\n  ov.val[1] = vqtbl4q_u8(vlut, ov.val[1]);\\\n  ov.val[2] = vqtbl4q_u8(vlut, ov.val[2]);\\\n  ov.val[3] = vqtbl4q_u8(vlut, ov.val[3]);\\\n}\n\nsize_t tb64v128enc(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {\n  static unsigned char lut[] = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n  const size_t      outlen = TB64ENCLEN(inlen);\n  const unsigned char *ip, *out_ = out+outlen; \n        unsigned char *op;\n  const uint8x16x4_t  vlut = vld1q_u8_x4(lut);\n  const uint8x16_t    cv3f = vdupq_n_u8(0x3f);\n\n  #define EN 128 // 256//\n  for(ip = in, op = out; op != out+(outlen&~(EN-1)); op += EN, ip += (EN/4)*3) { \t \t\t\t\t\t\t\t\n          uint8x16x3_t iv0 = vld3q_u8(ip),\n                       iv1 = vld3q_u8(ip+48);                   \n\n    uint8x16x4_t ov0,ov1; B64E(iv0, ov0); B64E(iv1, ov1);                                       \n      #if EN > 128 \n    iv0 = vld3q_u8(ip+ 96);\n    iv1 = vld3q_u8(ip+144);                   \n      #endif\n\tvst4q_u8(op,    ov0);                                                       \n\tvst4q_u8(op+64, ov1);                          \t//PREFETCH(ip,256,0);                                                  \n      #if EN > 128 \n                         B64E(iv0, ov0); B64E(iv1, ov1);                                             \n \tvst4q_u8(op+128, ov0);                                                       \n\tvst4q_u8(op+192, ov1);                          \t                                            \n          #endif\n  }\n  for(                 ; op != out+(outlen&~(64-1)); op += 64, ip += (64/4)*3) { \t\t\t\t\t\t\t\t\n    const uint8x16x3_t iv = vld3q_u8(ip);\n    uint8x16x4_t       ov; \n    B64E(iv, ov); \n\tvst4q_u8(op,ov);                                                       \n  } \n  EXTAIL();\n  return outlen;\n}\n\n#elif defined(__SSSE3__) //----------------- SSSE3 / SSE4.1 / AVX (derived from the AVX2 functions ) -----------------------------------------------------------------\n                //--------------- decode -------------------\n#define DS64(_i_) {\\\n  __m128i iv0 = _mm_loadu_si128((__m128i *)(ip+32+_i_*64   )),\\\n          iv1 = _mm_loadu_si128((__m128i *)(ip+32+_i_*64+16));\\\n  \\\n  __m128i ou0,shifted0; BITMAP128V8_6(iu0, shifted0,delta_asso, delta_values, ou0); BITPACK128V8_6(ou0, cpv);\\\n  __m128i ou1,shifted1; BITMAP128V8_6(iu1, shifted1,delta_asso, delta_values, ou1); BITPACK128V8_6(ou1, cpv);\\\n  _mm_storeu_si128((__m128i*)(op+_i_*48)   , ou0);\\\n  _mm_storeu_si128((__m128i*)(op+_i_*48+12), ou1);\\\n  CHECK0(B64CHK128(iu0, shifted0, check_asso, check_values, vx));\\\n  CHECK1(B64CHK128(iu1, shifted1, check_asso, check_values, vx));\\\n  \\\n          iu0 = _mm_loadu_si128((__m128i *)(ip+32+_i_*64+32));\\\n          iu1 = _mm_loadu_si128((__m128i *)(ip+32+_i_*64+48));\\\n  \\\n  __m128i ov2,shifted2; BITMAP128V8_6(iv0, shifted2,delta_asso, delta_values, ov2); BITPACK128V8_6(ov2, cpv);\\\n  __m128i ov3,shifted3; BITMAP128V8_6(iv1, shifted3,delta_asso, delta_values, ov3); BITPACK128V8_6(ov3, cpv);\\\n  _mm_storeu_si128((__m128i*)(op+_i_*48+24), ov2);\\\n  _mm_storeu_si128((__m128i*)(op+_i_*48+36), ov3);\\\n  CHECK1(B64CHK128(iv0, shifted2, check_asso, check_values, vx));\\\n  CHECK1(B64CHK128(iv1, shifted3, check_asso, check_values, vx));\\\n}\t\n\nsize_t T2(FUNPREF, dec)(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {\n  if(inlen&3) return 0;                                              \n\n  const unsigned char *ip = in, *in_ = in+inlen;\t\t\t\t\t\t\t\t\t  \n        unsigned char *op = out;\t\t\n  __m128i vx = _mm_setzero_si128();\t  \n  const __m128i delta_asso   = _mm_setr_epi8(0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,  0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0f);\n  const __m128i delta_values = _mm_setr_epi8(0x00, 0x00, 0x00, 0x13, 0x04, 0xbf, 0xbf, 0xb9,  0xb9, 0x00, 0x10, 0xc3, 0xbf, 0xbf, 0xb9, 0xb9);\n    #ifndef NB64CHECK\n  const __m128i check_asso   = _mm_setr_epi8(0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,  0x01, 0x01, 0x03, 0x07, 0x0b, 0x0b, 0x0b, 0x0f);\n  const __m128i check_values = _mm_setr_epi8(0x80, 0x80, 0x80, 0x80, 0xcf, 0xbf, 0xd5, 0xa6,  0xb5, 0x86, 0xd1, 0x80, 0xb1, 0x80, 0x91, 0x80);    \n    #endif\n  const __m128i          cpv = _mm_set_epi8( -1, -1, -1, -1, 12, 13, 14,  8,    9, 10,  4,  5,  6,  0,  1,  2);\n  \n  if(inlen >= 32+64+4) {\n    __m128i iu0 = _mm_loadu_si128((__m128i *) ip    ),\n            iu1 = _mm_loadu_si128((__m128i *)(ip+16));\t     \t\t\t\t\t\t\t\t\t\n    for(; ip < in_-(32+2*64+4); ip += 128, op += 128*3/4) { DS64(0); DS64(1); }\t\t\t\t\t\t\n    if(   ip < in_-(32+  64+4)) { DS64(0); ip += 64, op += 64*3/4; }\t\t\t\t\t\t\n  } else if(!inlen) return 0;\n  \n  for(; ip < in_-(16+4); ip += 16, op += 16*3/4) { \t\t\t\t\t\t\t\t\t\t\t\n    __m128i iv = _mm_loadu_si128((__m128i *)ip), ov, shifted0;     \t\t\t\t\t\t\t\t\n\tBITMAP128V8_6(iv, shifted0, delta_asso, delta_values, ov);\n\tBITPACK128V8_6(ov, cpv);\n    _mm_storeu_si128((__m128i*) op, ov); \t\t\t\t\t\t\t\t\t\t\t\t\t\t                                              \n    CHECK0(B64CHK128(iv, shifted0, check_asso, check_values, vx));\n  } \n\n  unsigned cx =  _mm_movemask_epi8(vx);\n  size_t rc = 0, r = in_ - ip;\n  if(r && !(rc = _tb64xd(ip, r, op)) || cx) \n\treturn 0;\n  return (op - out)+rc;\n}\n\n                         //---------------------- encode ------------------\n#define ES64(_i_) {\\\n      __m128i v0 = _mm_loadu_si128((__m128i*)(ip+24+_i_*48+ 0)),\\\n              v1 = _mm_loadu_si128((__m128i*)(ip+24+_i_*48+12));\\\n\\\n              u0 = _mm_shuffle_epi8(u0, shuf);\\\n              u1 = _mm_shuffle_epi8(u1, shuf);\\\n              u0 = bitunpack128v8_6(u0);\\\n              u1 = bitunpack128v8_6(u1);\\\n              u0 = bitmap128v8_6(u0);\\\n              u1 = bitmap128v8_6(u1);\\\n      _mm_storeu_si128((__m128i*)(op+_i_*64+ 0), u0);\\\n      _mm_storeu_si128((__m128i*)(op+_i_*64+16), u1);\\\n\\\n              u0 = _mm_loadu_si128((__m128i*)(ip+24+_i_*48+24));\\\n              u1 = _mm_loadu_si128((__m128i*)(ip+24+_i_*48+36));\\\n\\\n              v0 = _mm_shuffle_epi8(v0, shuf);\\\n              v1 = _mm_shuffle_epi8(v1, shuf);\\\n              v0 = bitunpack128v8_6(v0);\\\n              v1 = bitunpack128v8_6(v1); \\\n              v0 = bitmap128v8_6(v0);\\\n              v1 = bitmap128v8_6(v1);\\\n      _mm_storeu_si128((__m128i*)(op+_i_*64+32), v0);\\\n      _mm_storeu_si128((__m128i*)(op+_i_*64+48), v1);\\\n}  \n\nsize_t T2(FUNPREF, enc)(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) { \n  const size_t        outlen = TB64ENCLEN(inlen); \n  const unsigned char *ip = in, *out_ = out+outlen; \n        unsigned char *op = out;\n\n  const __m128i shuf = _mm_set_epi8(10,11,  9,10,  7, 8, 6, 7,    4, 5, 3, 4, 1, 2, 0, 1);\n  \n  if(outlen >= (24+48+4)*4/3) {\n      __m128i u0 = _mm_loadu_si128((__m128i*) ip),\n              u1 = _mm_loadu_si128((__m128i*)(ip+12)); \n    for(; op < out_-(24+2*48+4)*4/3; op += 128, ip += 128*3/4) { ES64(0); ES64(1); }  \n    if(   op < out_-(24+  48+4)*4/3) { ES64(0); op +=  64; ip +=  64*3/4; }\t\t          \t\t\t\t\t\t   \n  }\n  \n  for(; op < out_- (12+4)*4/3; op += 16, ip += 16*3/4) {\n\t__m128i v = _mm_loadu_si128((__m128i*)ip);\n            v = _mm_shuffle_epi8(v, shuf);\n            v =  bitunpack128v8_6(v);\n            v =  bitmap128v8_6(v);\n    _mm_storeu_si128((__m128i*)op, v);\n  }\t\t\t\t\t\n  \n  EXTAIL(3); \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \t\t\t\t\t\t\t \n  return outlen;\n}\n#endif\n//-------------------------------------------------------------------------------------------------------------------\n#ifndef __AVX__ //include only 1 time\nsize_t tb64memcpy(const unsigned char* in, size_t inlen, unsigned char *out) {\n  memcpy(out, in, inlen);\n  return inlen;\n}\n \nstatic unsigned _cpuisa;\n//--------------------- CPU detection -------------------------------------------\n    #if defined(__i386__) || defined(__x86_64__)\n      #if _MSC_VER >=1300\n#include <intrin.h>\n      #elif defined (__INTEL_COMPILER)\n#include <x86intrin.h>\n      #endif\n\nstatic inline void cpuid(int reg[4], int id) {\n      #if defined (_MSC_VER) //|| defined (__INTEL_COMPILER)\n  __cpuidex(reg, id, 0);\n      #elif defined(__i386__) || defined(__x86_64__)\n  __asm(\"cpuid\" : \"=a\"(reg[0]),\"=b\"(reg[1]),\"=c\"(reg[2]),\"=d\"(reg[3]) : \"a\"(id),\"c\"(0) : );\n      #endif\n}\n\nstatic inline uint64_t xgetbv (int ctr) {\n      #if(defined _MSC_VER && (_MSC_FULL_VER >= 160040219) || defined __INTEL_COMPILER)\n  return _xgetbv(ctr);\n      #elif defined(__i386__) || defined(__x86_64__)\n  unsigned a, d;\n  __asm(\"xgetbv\" : \"=a\"(a),\"=d\"(d) : \"c\"(ctr) : );\n  return (uint64_t)d << 32 | a;\n      #else\n  unsigned a=0, d=0;\n  return (uint64_t)d << 32 | a;\n      #endif\n}\n    #endif\n\n#define AVX512F     0x001\n#define AVX512DQ    0x002\n#define AVX512IFMA  0x004\n#define AVX512PF    0x008\n#define AVX512ER    0x010\n#define AVX512CD    0x020\n#define AVX512BW    0x040\n#define AVX512VL    0x080\n#define AVX512VNNI  0x100\n#define AVX512VBMI  0x200\n#define AVX512VBMI2 0x400\n\n#define IS_SSE       0x10\n#define IS_SSE2      0x20\n#define IS_SSE3      0x30\n#define IS_SSSE3     0x32\n#define IS_POWER9    0x34 // powerpc\n#define IS_NEON      0x38 // arm neon\n#define IS_SSE41     0x40\n#define IS_SSE41x    0x41 //+popcount\n#define IS_SSE42     0x42\n#define IS_AVX       0x50\n#define IS_AVX2      0x60\n#define IS_AVX512    0x800\n\nunsigned cpuisa(void) {\n  int c[4] = {0};\n  if(_cpuisa) return _cpuisa;\n  _cpuisa++;\n    #if defined(__i386__) || defined(__x86_64__)\n  cpuid(c, 0);\n  if(c[0]) {\n    cpuid(c, 1);\n    //family = ((c >> 8) & 0xf) + ((c >> 20) & 0xff)\n    //model  = ((c >> 4) & 0xf) + ((c >> 12) & 0xf0)\n    if( c[3] & (1 << 25)) {         _cpuisa  = IS_SSE;\n    if( c[3] & (1 << 26)) {         _cpuisa  = IS_SSE2;\n    if( c[2] & (1 <<  0)) {         _cpuisa  = IS_SSE3;\n      //                            _cpuisa  = IS_SSE3SLOW; // Atom SSSE3 slow\n    if( c[2] & (1 <<  9)) {         _cpuisa  = IS_SSSE3;\n    if( c[2] & (1 << 19)) {         _cpuisa  = IS_SSE41;\n    if( c[2] & (1 << 23)) {         _cpuisa  = IS_SSE41x; // +popcount\n    if( c[2] & (1 << 20)) {         _cpuisa  = IS_SSE42;  // SSE4.2\n    if((c[2] & (1 << 28)) &&\n       (c[2] & (1 << 27)) &&                           // OSXSAVE\n       (c[2] & (1 << 26)) &&                           // XSAVE\n       (xgetbv(0) & 6)==6) {        _cpuisa  = IS_AVX; // AVX\n      if(c[2]& (1 <<  3))           _cpuisa |= 1;      // +FMA3\n      if(c[2]& (1 << 16))           _cpuisa |= 2;      // +FMA4\n      if(c[2]& (1 << 25))           _cpuisa |= 4;      // +AES\n      cpuid(c, 7);\n      if(c[1] & (1 << 5)) {         _cpuisa = IS_AVX2;\n        if(c[1] & (1 << 16)) {\n          cpuid(c, 0xd);\n          if((c[0] & 0x60)==0x60) { _cpuisa = IS_AVX512;\n            cpuid(c, 7);\n            if(c[1] & (1<<16))      _cpuisa |= AVX512F;\n            if(c[1] & (1<<17))      _cpuisa |= AVX512DQ;\n            if(c[1] & (1<<21))      _cpuisa |= AVX512IFMA;\n            if(c[1] & (1<<26))      _cpuisa |= AVX512PF;\n            if(c[1] & (1<<27))      _cpuisa |= AVX512ER;\n            if(c[1] & (1<<28))      _cpuisa |= AVX512CD;\n            if(c[1] & (1<<30))      _cpuisa |= AVX512BW;\n            if(c[1] & (1u<<31))     _cpuisa |= AVX512VL;\n            if(c[2] & (1<< 1))      _cpuisa |= AVX512VBMI;\n            if(c[2] & (1<<11))      _cpuisa |= AVX512VNNI;\n            if(c[2] & (1<< 6))      _cpuisa |= AVX512VBMI2;\n      }}}\n    }}}}}}}}}\n    #elif defined(__powerpc64__)\n  _cpuisa = IS_POWER9; // power9\n    #elif defined(__ARM_NEON)\n  _cpuisa = IS_NEON; // ARM_NEON\n    #endif\n  return _cpuisa;\n}\n\nunsigned cpuini(unsigned cpuisa) { if(cpuisa) _cpuisa = cpuisa; return _cpuisa; }\n\nchar *cpustr(unsigned cpuisa) {\n  if(!cpuisa) cpuisa = _cpuisa;\n    #if defined(__i386__) || defined(__x86_64__)\n  if(cpuisa >= IS_AVX512) {\n    if(cpuisa & AVX512VBMI2) return \"avx512vbmi2\";\n    if(cpuisa & AVX512VBMI)  return \"avx512vbmi\";\n    if(cpuisa & AVX512VNNI)  return \"avx512vnni\";\n    if(cpuisa & AVX512VL)    return \"avx512vl\";\n    if(cpuisa & AVX512BW)    return \"avx512bw\";\n    if(cpuisa & AVX512CD)    return \"avx512cd\";\n    if(cpuisa & AVX512ER)    return \"avx512er\";\n    if(cpuisa & AVX512PF)    return \"avx512pf\";\n    if(cpuisa & AVX512IFMA)  return \"avx512ifma\";\n    if(cpuisa & AVX512DQ)    return \"avx512dq\";\n    if(cpuisa & AVX512F)     return \"avx512f\";\n    return \"avx512\";\n  }\n  else if(cpuisa >= IS_AVX2)    return \"avx2\";\n  else if(cpuisa >= IS_AVX)\n    switch(cpuisa&0xf) {\n      case 1: return \"avx+fma3\";\n      case 2: return \"avx+fma4\";\n      case 4: return \"avx+aes\";\n      case 5: return \"avx+fma3+aes\";\n      default:return \"avx\";\n    }\n  else if(cpuisa >= IS_SSE42)   return \"sse4.2\";\n  else if(cpuisa >= IS_SSE41x)  return \"sse4.1+popcnt\";\n  else if(cpuisa >= IS_SSE41)   return \"sse4.1\";\n  else if(cpuisa >= IS_SSSE3)   return \"ssse3\";\n  else if(cpuisa >= IS_SSE3)    return \"sse3\";\n  else if(cpuisa >= IS_SSE2)    return \"sse2\";\n  else if(cpuisa >= IS_SSE)     return \"sse\";\n     #elif defined(__powerpc64__)\n  if(cpuisa >= IS_POWER9)       return \"power9\";\n    #elif defined(__ARM_NEON)\n  if(cpuisa >= IS_NEON)         return \"arm_neon\";\n    #endif\n  return \"none\";\n}\n\n//---------------------------------------------------------------------------------\nTB64FUNC _tb64e = tb64xenc;\nTB64FUNC _tb64d = tb64xdec;\n\nstatic int tb64set;\n \nvoid tb64ini(unsigned id, unsigned isshort) { \n  int i; \n  if(tb64set) return; \n  tb64set++;   \n  i = id?id:cpuisa();\n    #if defined(__i386__) || defined(__x86_64__)\n      #ifndef NAVX512\n  if(i >= IS_AVX512) {  \n    _tb64e = i >= (IS_AVX512|AVX512VBMI)?tb64v512enc:tb64v256enc; \n    _tb64d = i >= (IS_AVX512|AVX512VBMI)?tb64v512dec:tb64v256dec;\n  } else \n      #endif\n      #ifndef NAVX2\n  if(i >= IS_AVX2) {  \n    _tb64e = isshort?_tb64v256enc:tb64v256enc; \n    _tb64d = isshort?_tb64v256dec:tb64v256dec;\n  } else \n      #endif\n      #ifndef NAVX\n    if(i >= IS_AVX) {  \n    _tb64e = tb64v128aenc; \n    _tb64d = tb64v128adec;\n  } else \n      #endif\n    #endif\n    #if defined(__i386__) || defined(__x86_64__) || defined(__ARM_NEON) || defined(__powerpc64__)\n      #ifndef NSSE\n  if(i >= IS_SSSE3) {  \n    _tb64e = tb64v128enc; \n    _tb64d = tb64v128dec;\n  }\n      #endif\n    #endif\n}\n\nsize_t tb64enc(const unsigned char *in, size_t inlen, unsigned char *out) {\n  if(!tb64set) tb64ini(0,0);\n  return _tb64e(in,inlen,out);\n}\nsize_t tb64dec(const unsigned char *in, size_t inlen, unsigned char *out) {\n  if(!tb64set) tb64ini(0,0);\n  return _tb64d(in,inlen,out);\n}\n#endif\n"
  },
  {
    "path": "turbob64v256.c",
    "content": "/**\n    Copyright (C) powturbo 2016-2023\n    SPDX-License-Identifier: GPL v3 License\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\n    - homepage : https://sites.google.com/site/powturbo/\n    - github   : https://github.com/powturbo\n    - twitter  : https://twitter.com/powturbo\n    - email    : powturbo [_AT_] gmail [_DOT_] com\n**/\n// Turbo-Base64: avx2 encode/decode\n\n// SSE + AVX2 Based on:\n// http://0x80.pl/articles/index.html#base64-algorithm-update\n// https://arxiv.org/abs/1704.00605\n// https://gist.github.com/aqrit/a2ccea48d7cac7e9d4d99f19d4759666 (decode)\n\n#include <immintrin.h>\n#include \"turbob64.h\"\n#include  \"conf.h\" //AS\n#include \"turbob64_.h\"\n\n//--------------------- Decode ----------------------------------------------------------------------\n#define BITPACK256V8_6(v,cpv) {\\\n  const __m256i merge_ab_bc = _mm256_maddubs_epi16(v,            _mm256_set1_epi32(0x01400140));\\\n                          v = _mm256_madd_epi16(merge_ab_bc, _mm256_set1_epi32(0x00011000));\\\n                          v = _mm256_shuffle_epi8(v, cpv);\\\n}\n\n#define BITMAP256V8_6(iv, shifted, delta_asso, delta_values, ov) { /*map 8-bits ascii to 6-bits bin*/\\\n                shifted    = _mm256_srli_epi32(iv, 3);\\\n  const __m256i delta_hash = _mm256_avg_epu8(_mm256_shuffle_epi8(delta_asso, iv), shifted);\\\n                        ov = _mm256_add_epi8(_mm256_shuffle_epi8(delta_values, delta_hash), iv);\\\n}\n//----------------------------\n#define BITPACK256V8_6x(v0,v1,cpv) {\\\n  const __m256i merge_ab_bc0 = _mm256_maddubs_epi16(v0,        _mm256_set1_epi32(0x01400140));\\\n  const __m256i merge_ab_bc1 = _mm256_maddubs_epi16(v1,        _mm256_set1_epi32(0x01400140));\\\n                          v0 = _mm256_madd_epi16(merge_ab_bc0, _mm256_set1_epi32(0x00011000));\\\n                          v1 = _mm256_madd_epi16(merge_ab_bc1, _mm256_set1_epi32(0x00011000));\\\n                          v0 = _mm256_shuffle_epi8(v0, cpv);\\\n                          v1 = _mm256_shuffle_epi8(v1, cpv);\\\n}\n\n#define BITMAP256V8_6x(iv0, shifted0, iv1, shifted1, delta_asso, delta_values, ov0, ov1) { /*map 8-bits ascii to 6-bits bin*/\\\n  __m256i delta_hash0 = _mm256_shuffle_epi8(delta_asso, iv0);\\\n  __m256i delta_hash1 = _mm256_shuffle_epi8(delta_asso, iv1);\\\n          shifted0    = _mm256_srli_epi32(iv0, 3);\\\n          delta_hash0 = _mm256_avg_epu8(delta_hash0, shifted0);\\\n          shifted1    = _mm256_srli_epi32(iv1, 3);\\\n          delta_hash1 = _mm256_avg_epu8(delta_hash1, shifted1);\\\n                  ov0 = _mm256_add_epi8(_mm256_shuffle_epi8(delta_values, delta_hash0), iv0);\\\n                  ov1 = _mm256_add_epi8(_mm256_shuffle_epi8(delta_values, delta_hash1), iv1);\\\n}\n\n//--------------------------\n#define B64CHK256(iv, shifted, check_asso, check_values, vx) {\\\n  const __m256i check_hash = _mm256_avg_epu8( _mm256_shuffle_epi8(check_asso, iv), shifted);\\\n  const __m256i        chk = _mm256_adds_epi8(_mm256_shuffle_epi8(check_values, check_hash), iv);\\\n                        vx = _mm256_or_si256(vx, chk);\\\n}\n\n#define DS128(_i_) {\\\n  __m256i iv0 = _mm256_loadu_si256((__m256i *)(ip+64+_i_*128+0)), \\\n          iv1 = _mm256_loadu_si256((__m256i *)(ip+64+_i_*128+32));\\\n                                                                  \\\n  __m256i ou0,shiftedu0; /*BITMAP256V8_6(iu0, shiftedu0, delta_asso, delta_values, ou0); BITPACK256V8_6(ou0, cpv);*/\\\n  __m256i ou1,shiftedu1; /*BITMAP256V8_6(iu1, shiftedu1, delta_asso, delta_values, ou1); BITPACK256V8_6(ou1, cpv);*/\\\n  BITMAP256V8_6x(iu0, shiftedu0, iu1, shiftedu1, delta_asso, delta_values, ou0, ou1);\\\n  BITPACK256V8_6x(ou0, ou1, cpv);\\\n  CHECK0(B64CHK256(iu0,shiftedu0, check_asso, check_values, vx)); \\\n          iu0 = _mm256_loadu_si256((__m256i *)(ip+64+_i_*128+64));\\\n  CHECK1(B64CHK256(iu1,shiftedu1, check_asso, check_values, vx)); \\\n          iu1 = _mm256_loadu_si256((__m256i *)(ip+64+_i_*128+96));\\\n  _mm_storeu_si128((__m128i*)(op+_i_*96   ), _mm256_castsi256_si128(  ou0   ));\\\n  _mm_storeu_si128((__m128i*)(op+_i_*96+12), _mm256_extracti128_si256(ou0, 1));\\\n  _mm_storeu_si128((__m128i*)(op+_i_*96+24), _mm256_castsi256_si128(  ou1   ));\\\n  _mm_storeu_si128((__m128i*)(op+_i_*96+36), _mm256_extracti128_si256(ou1, 1));\\\n                                                                               \\\n  __m256i ov0,shiftedv0; /*BITMAP256V8_6(iv0, shiftedv0, delta_asso, delta_values, ov0); BITPACK256V8_6(ov0, cpv);*/\\\n  __m256i ov1,shiftedv1; /*BITMAP256V8_6(iv1, shiftedv1, delta_asso, delta_values, ov1); BITPACK256V8_6(ov1, cpv);*/\\\n  BITMAP256V8_6x(iv0, shiftedv0, iv1, shiftedv1, delta_asso, delta_values, ov0, ov1);\\\n  BITPACK256V8_6x(ov0, ov1, cpv);\\\n                                                                  \\\n  CHECK1(B64CHK256(iv0, shiftedv0, check_asso, check_values, vx));\\\n  CHECK1(B64CHK256(iv1, shiftedv1, check_asso, check_values, vx));\\\n  _mm_storeu_si128((__m128i*)(op+_i_*96+48), _mm256_castsi256_si128(  ov0   ));\\\n  _mm_storeu_si128((__m128i*)(op+_i_*96+60), _mm256_extracti128_si256(ov0, 1));\\\n  _mm_storeu_si128((__m128i*)(op+_i_*96+72), _mm256_castsi256_si128(  ov1   ));\\\n  _mm_storeu_si128((__m128i*)(op+_i_*96+84), _mm256_extracti128_si256(ov1, 1));\\\n}\n\nsize_t tb64v256dec(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {\n  if(inlen&3) \n\treturn 0;                               \n  \n  const unsigned char *ip = in, *in_ = in + inlen;\n        unsigned char *op = out;\n        __m256i vx           = _mm256_setzero_si256();\n  const __m256i delta_asso   = _mm256_setr_epi8(0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,   0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0f,\n                                                0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,   0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0f),\n                delta_values = _mm256_setr_epi8(0x00, 0x00, 0x00, 0x13, 0x04, 0xbf, 0xbf, 0xb9,   0xb9, 0x00, 0x10, 0xc3, 0xbf, 0xbf, 0xb9, 0xb9,\n                                                0x00, 0x00, 0x00, 0x13, 0x04, 0xbf, 0xbf, 0xb9,   0xb9, 0x00, 0x10, 0xc3, 0xbf, 0xbf, 0xb9, 0xb9),\n    #ifndef NB64CHECK\n                check_asso   = _mm256_setr_epi8(0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,   0x01, 0x01, 0x03, 0x07, 0x0b, 0x0b, 0x0b, 0x0f,\n                                                0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,   0x01, 0x01, 0x03, 0x07, 0x0b, 0x0b, 0x0b, 0x0f),\n                check_values = _mm256_setr_epi8(0x80, 0x80, 0x80, 0x80, 0xcf, 0xbf, 0xd5, 0xa6,   0xb5, 0x86, 0xd1, 0x80, 0xb1, 0x80, 0x91, 0x80,\n                                                0x80, 0x80, 0x80, 0x80, 0xcf, 0xbf, 0xd5, 0xa6,   0xb5, 0x86, 0xd1, 0x80, 0xb1, 0x80, 0x91, 0x80),\n    #endif\n                         cpv = _mm256_set_epi8( -1, -1, -1, -1, 12, 13, 14,  8,    9, 10,  4,  5,  6,  0,  1,  2,\n                                                -1, -1, -1, -1, 12, 13, 14,  8,    9, 10,  4,  5,  6,  0,  1,  2);\t\t\t\t\t\t\t\t\t\t\t\t  \n        __m128i          _vx;\t\n\t\t\t\t\t\t\t\t\t\t\t\n  if(likely(inlen >= 64+128+4)) { \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n    __m256i iu0 = _mm256_loadu_si256((__m256i *) ip    ),   \n\t        iu1 = _mm256_loadu_si256((__m256i *)(ip+32));    \n    for(;ip < in_-(64+2*128+4); ip += 256, op += 256*3/4) { DS128(0); DS128(1); }\t\n    if(  ip < in_-(64+  128+4))                           { DS128(0); ip += 128; op += 128*3/4; }\n    CHECK0(_vx = _mm_or_si128(_mm256_extracti128_si256(vx, 1), _mm256_castsi256_si128(vx)));\n  } else { \n\tCHECK0(_vx = _mm_setzero_si128());\n    if(!inlen) return 0; \n  }\n  \n  for(;ip < in_-(16+4); ip += 16, op += 16*3/4) {\n    __m128i iv = _mm_loadu_si128((__m128i *) ip), ov, vsh; \n\tBITMAP128V8_6(iv, vsh, _mm256_castsi256_si128(delta_asso), _mm256_castsi256_si128(delta_values), ov); \n\tBITPACK128V8_6(ov, _mm256_castsi256_si128(cpv));\n    _mm_storeu_si128((__m128i*) op, ov);    \n    CHECK0(B64CHK128(iv, vsh, _mm256_castsi256_si128(check_asso), _mm256_castsi256_si128(check_values), _vx));\n  }\n \n  size_t rc = 0, r = in_- ip; \n  if(r && !(rc = _tb64xd(ip, r, op)) CHECK0(|| _mm_movemask_epi8(_vx))) \n\treturn 0;                                                                      //AC(op+rc == out+tb64declen(in, inlen), \"#4 out\"); AC(ip+r == in+inlen, \"#5 in\");\n  return (op - out)+rc;\n}\n\n//-------------------- Encode ----------------------------------------------------------------------\n\n#define ES128(_i_) {\\\n  __m256i v0 = _mm256_castsi128_si256(    _mm_loadu_si128((__m128i *)(ip+48+_i_*96+ 0))  );\\\n          v0 = _mm256_inserti128_si256(v0,_mm_loadu_si128((__m128i *)(ip+48+_i_*96+12)),1);\\\n  __m256i v1 = _mm256_castsi128_si256(    _mm_loadu_si128((__m128i *)(ip+48+_i_*96+24))  );\\\n          v1 = _mm256_inserti128_si256(v1,_mm_loadu_si128((__m128i *)(ip+48+_i_*96+36)),1);\\\n                                                                                           \\\n  u0 = _mm256_shuffle_epi8(u0, vh); u0 = bitunpack256v8_6(u0); u0 = bitmap256v8_6(u0);\\\n  u1 = _mm256_shuffle_epi8(u1, vh); u1 = bitunpack256v8_6(u1); u1 = bitmap256v8_6(u1);\\\n       _mm256_storeu_si256((__m256i*)(op+_i_*128),    u0);                              \\\n       _mm256_storeu_si256((__m256i*)(op+_i_*128+32), u1);                              \\\n\t\t                                                                                   \\\n          u0 = _mm256_castsi128_si256(    _mm_loadu_si128((__m128i *)(ip+48+_i_*96+48))  );\\\n          u0 = _mm256_inserti128_si256(u0,_mm_loadu_si128((__m128i *)(ip+48+_i_*96+60)),1);\\\n          u1 = _mm256_castsi128_si256(    _mm_loadu_si128((__m128i *)(ip+48+_i_*96+72))  );\\\n          u1 = _mm256_inserti128_si256(u1,_mm_loadu_si128((__m128i *)(ip+48+_i_*96+84)),1); \\\n                                                                                           \\\n  v0 = _mm256_shuffle_epi8(v0, vh); v0 = bitunpack256v8_6(v0); v0 = bitmap256v8_6(v0);\\\n  v1 = _mm256_shuffle_epi8(v1, vh); v1 = bitunpack256v8_6(v1); v1 = bitmap256v8_6(v1); \\\n       _mm256_storeu_si256((__m256i*)(op+_i_*128+64), v0);\\\n       _mm256_storeu_si256((__m256i*)(op+_i_*128+96), v1);\\\n}\n\nsize_t tb64v256enc(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {\n            size_t outlen = TB64ENCLEN(inlen);\n  const unsigned char *ip = in, *out_ = out+outlen; \n        unsigned char *op = out;\n\n  const __m256i vh = _mm256_set_epi8(10,11, 9,10, 7, 8, 6, 7, 4,   5, 3, 4, 1, 2, 0, 1,\n                                     10,11, 9,10, 7, 8, 6, 7, 4,   5, 3, 4, 1, 2, 0, 1);\n  if(outlen >= (48+96+4)*4/3) {\n    __m256i u0 = _mm256_castsi128_si256(    _mm_loadu_si128((__m128i *) ip    )  );   \n            u0 = _mm256_inserti128_si256(u0,_mm_loadu_si128((__m128i *)(ip+12)),1);   \n    __m256i u1 = _mm256_castsi128_si256(    _mm_loadu_si128((__m128i *)(ip+24))  );      \n            u1 = _mm256_inserti128_si256(u1,_mm_loadu_si128((__m128i *)(ip+36)),1);   \n    for(; op < out_ - (48+2*96+4)*4/3; ip += 256*3/4, op += 256) { ES128(0); ES128(1); }\t\t    \n    if(   op < out_ - (48+  96+4)*4/3) { ES128(0); ip += 128*3/4; op += 128;  }\t\t    \n  } \n  \n  for(; op < out_- (24+4)*4/3; op += 32, ip += 32*3/4) {\n    __m256i v = _mm256_castsi128_si256(   _mm_loadu_si128((__m128i *) ip    )  );      \n            v = _mm256_inserti128_si256(v,_mm_loadu_si128((__m128i *)(ip+12)),1);   \n            v = _mm256_shuffle_epi8(v, vh); \n\t\t\tv = bitunpack256v8_6(v); \n\t\t\tv = bitmap256v8_6(v);                                                                                                           \n            _mm256_storeu_si256((__m256i*) op, v);                                                 \n  }\n  EXTAIL(7);\n  return outlen;\n}\n\n//------- optimized functions for short strings only --------------------------\n// OVHD=0 : unsafe, can read beyond the input buffer end, therefore input buffer size must be 32 bytes larger than input length\n#define OVHD 0\n//#define OVHD 4 \n#define _CHECK0(a) CHECK0(a)\n#define _CHECK1(a) CHECK1(a)\n\nsize_t _tb64v256dec(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {  AS((inlen&3)==0, \"inlen not multiple of 4\\n\");\n  \n  if(inlen >= 16+OVHD) {\n    const unsigned char *ip = in, *in_ = in + inlen;\n          unsigned char *op = out;\n    const __m256i delta_asso   = _mm256_setr_epi8(0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,   0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0f,\n                                                  0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,   0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0f),\n                  delta_values = _mm256_setr_epi8(0x00, 0x00, 0x00, 0x13, 0x04, 0xbf, 0xbf, 0xb9,   0xb9, 0x00, 0x10, 0xc3, 0xbf, 0xbf, 0xb9, 0xb9,\n                                                  0x00, 0x00, 0x00, 0x13, 0x04, 0xbf, 0xbf, 0xb9,   0xb9, 0x00, 0x10, 0xc3, 0xbf, 0xbf, 0xb9, 0xb9),\n      #ifndef NB64CHECK\n                  check_asso   = _mm256_setr_epi8(0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,   0x01, 0x01, 0x03, 0x07, 0x0b, 0x0b, 0x0b, 0x0f,\n                                                  0x0d, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,   0x01, 0x01, 0x03, 0x07, 0x0b, 0x0b, 0x0b, 0x0f),\n                  check_values = _mm256_setr_epi8(0x80, 0x80, 0x80, 0x80, 0xcf, 0xbf, 0xd5, 0xa6,   0xb5, 0x86, 0xd1, 0x80, 0xb1, 0x80, 0x91, 0x80,\n                                                  0x80, 0x80, 0x80, 0x80, 0xcf, 0xbf, 0xd5, 0xa6,   0xb5, 0x86, 0xd1, 0x80, 0xb1, 0x80, 0x91, 0x80),\n      #endif\n                           cpv = _mm256_set_epi8( -1, -1, -1, -1, 12, 13, 14,  8,    9, 10,  4,  5,  6,  0,  1,  2,\n                                                  -1, -1, -1, -1, 12, 13, 14,  8,    9, 10,  4,  5,  6,  0,  1,  2);\t\t\t\t\t\t\t\t\t\t\t\t  \n          __m256i           vx = _mm256_setzero_si256();\n\n    for(; ip < in_-(32+OVHD); ip += 32, op += 32*3/4) {\n      __m256i iv = _mm256_loadu_si256((__m256i *)ip), ov, vsh; \n\t  BITMAP256V8_6(iv, vsh, delta_asso, delta_values, ov); \n\t  BITPACK256V8_6(ov, cpv);\n      \n      _mm_storeu_si128((__m128i*) op,       _mm256_castsi256_si128(ov));\n      _mm_storeu_si128((__m128i*)(op + 12), _mm256_extracti128_si256(ov, 1)); \n      _CHECK1(B64CHK256(iv, vsh, check_asso, check_values, vx));\n    }\n\t\n    unsigned cx; \n    if(ip < in_-(16+OVHD)) {\n      __m128i iv = _mm_loadu_si128((__m128i *) ip), ov, vsh; \n\t  ip += 16; \n\t    #ifdef B64CHECK\n      __m128i _vx = _mm_or_si128(_mm256_extracti128_si256(vx, 1), _mm256_castsi256_si128(vx));\n\t    #else\n      __m128i _vx = _mm_setzero_si128();\n\t\t#endif\n\t  BITMAP128V8_6(iv, vsh, _mm256_castsi256_si128(delta_asso), _mm256_castsi256_si128(delta_values), ov); \n\t  BITPACK128V8_6(ov, _mm256_castsi256_si128(cpv));\n      _mm_storeu_si128((__m128i*) op, ov);                        \n\t  op += 16*3/4; \n      _CHECK0(B64CHK128(iv, vsh, _mm256_castsi256_si128(check_asso), _mm256_castsi256_si128(check_values), _vx));\n      _CHECK0(cx = _mm_movemask_epi8(_vx));\n    } _CHECK0(else cx = _mm256_movemask_epi8(vx));\n    size_t rc = 0, r = in_- ip; \n    if(r && !(rc = _tb64xd(ip, r, op)) _CHECK0(|| cx)) \n\t  return 0;                                                                      //AC(op+rc == out+tb64declen(in, inlen), \"#4 out\"); AC(ip+r == in+inlen, \"#5 in\");\n    return (op - out)+rc;\n  } else if(!inlen) return 0;\n  return _tb64xd(in, inlen, out);\n}\n\nsize_t _tb64v256enc(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {\n            size_t outlen = TB64ENCLEN(inlen);\n  const unsigned char *ip = in, *out_ = out+outlen; \n        unsigned char *op = out;\n\n  const __m256i vh = _mm256_set_epi8(10,11, 9,10, 7, 8, 6, 7, 4,   5, 3, 4, 1, 2, 0, 1,\n                                     10,11, 9,10, 7, 8, 6, 7, 4,   5, 3, 4, 1, 2, 0, 1);\n\t\t\t\t\t\t\t\t\t \n  for(; op < out_- (24+4)*4/3; op += 32, ip += 32*3/4) {\n    __m256i v = _mm256_castsi128_si256(   _mm_loadu_si128((__m128i *) ip    )  );      \n            v = _mm256_inserti128_si256(v,_mm_loadu_si128((__m128i *)(ip+12)),1);   \n            v = _mm256_shuffle_epi8(v, vh); \n\t\t\tv = bitunpack256v8_6(v); \n\t\t\tv = bitmap256v8_6(v);                                                                                                           \n            _mm256_storeu_si256((__m256i*) op, v);                                                 \n  }\n  if(op <= out_-(12+4)*4/3) {\n    __m128i v0 = _mm_loadu_si128((__m128i*)ip);\n            v0 = _mm_shuffle_epi8(v0, _mm256_castsi256_si128(vh));\n            v0 = bitunpack128v8_6(v0);\n            v0 = bitmap128v8_6(v0);\n    _mm_storeu_si128((__m128i*) op, v0);                                          \n    op += 16; ip += (16/4)*3;\n  }\n  EXTAIL(3);\n  return outlen;\n}\n"
  },
  {
    "path": "turbob64v512.c",
    "content": "/**\n    Copyright (C) powturbo 2016-2023\n    SPDX-License-Identifier: GPL v3 License\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 3 of the License, or\n    (at your option) any later version.\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n    - homepage : https://sites.google.com/site/powturbo/\n    - github   : https://github.com/powturbo\n    - twitter  : https://twitter.com/powturbo\n    - email    : powturbo [_AT_] gmail [_DOT_] com\n**/\n#include <immintrin.h>\n#include \"turbob64.h\"\n#include \"turbob64_.h\"\n\n//-------------------- Encode ----------------------------------------------------------------------\n//AVX512_VBMI: https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#expand=1276,5146,5146,5146&text=_mm512_multishift_epi64_epi8&avx512techs=AVX512_VBMI\n//reference: http://0x80.pl/notesen/2016-04-03-avx512-base64.html#avx512vbmi\n\n#define ES256(_i_) { __m512i v0,v1;\\\n  v0 = _mm512_loadu_si512((__m512i *)(ip+96+_i_*192) ),\\\n  v1 = _mm512_loadu_si512((__m512i *)(ip+96+_i_*192+48));\\\n  u0 = _mm512_permutexvar_epi8(_mm512_multishift_epi64_epi8(vs, _mm512_permutexvar_epi8(vf, u0)), vlut);\\\n  u1 = _mm512_permutexvar_epi8(_mm512_multishift_epi64_epi8(vs, _mm512_permutexvar_epi8(vf, u1)), vlut);\\\n  _mm512_storeu_si512((__m512i*)(op+_i_*256),     u0);\\\n  _mm512_storeu_si512((__m512i*)(op+_i_*256+64), u1);\\\n                                                  \\\n  u0 = _mm512_loadu_si512((__m512i *)(ip+96+_i_*192+ 96));\\\n  u1 = _mm512_loadu_si512((__m512i *)(ip+96+_i_*192+144));\\\n  v0 = _mm512_permutexvar_epi8(_mm512_multishift_epi64_epi8(vs, _mm512_permutexvar_epi8(vf, v0)), vlut);\\\n  v1 = _mm512_permutexvar_epi8(_mm512_multishift_epi64_epi8(vs, _mm512_permutexvar_epi8(vf, v1)), vlut);\\\n  _mm512_storeu_si512((__m512i*)(op+_i_*256+128), v0);\\\n  _mm512_storeu_si512((__m512i*)(op+_i_*256+192), v1);\\\n}\n\nsize_t tb64v512enc(const unsigned char *__restrict in, size_t inlen, unsigned char *__restrict out) {\n            size_t outlen = TB64ENCLEN(inlen);\n  const unsigned char *ip = in, *out_ = out+outlen; \n        unsigned char *op = out;\n\n  const __m512i vlut = _mm512_setr_epi64(0x4847464544434241ull, 0x504F4E4D4C4B4A49ull, // ABCDEF...789+/\n                                         0x5857565554535251ull, 0x6665646362615A59ull,\n                                         0x6E6D6C6B6A696867ull, 0x767574737271706Full,\n                                         0x333231307A797877ull, 0x2F2B393837363534ull), \n                  vf = _mm512_setr_epi32(0x01020001, 0x04050304, 0x07080607, 0x0a0b090a,\n                                         0x0d0e0c0d, 0x10110f10, 0x13141213, 0x16171516,\n                                         0x191a1819, 0x1c1d1b1c, 0x1f201e1f, 0x22232122,\n                                         0x25262425, 0x28292728, 0x2b2c2a2b, 0x2e2f2d2e),\n                  vs = _mm512_set1_epi64(0x3036242a1016040alu); // 48, 54, 36, 42, 16, 22, 4, 10\n\n  if(outlen >= (96+192+4)*4/3) {\n    __m512i u0 = _mm512_loadu_si512((__m512i *) ip    );\n    __m512i u1 = _mm512_loadu_si512((__m512i *)(ip+48));\n    for(; op < out_ - (94+2*192+4)*4/3; op += 512, ip += 512*3/4) { ES256(0); ES256(1); }    \n\tif(op < out_-(96+192+4)*4/3) { ES256(0); op += 256; ip += 256*3/4; }\n  }\n  \n  const __m256i vh = _mm256_set_epi8(10,11, 9,10, 7, 8, 6, 7, 4,   5, 3, 4, 1, 2, 0, 1,\n                                     10,11, 9,10, 7, 8, 6, 7, 4,   5, 3, 4, 1, 2, 0, 1);\n  for(; op < out_- (24+4)*4/3; op += 32, ip += 32*3/4) {\n    __m256i v = _mm256_castsi128_si256(   _mm_loadu_si128((__m128i *) ip    )  );      \n            v = _mm256_inserti128_si256(v,_mm_loadu_si128((__m128i *)(ip+12)),1);   \n            v = _mm256_shuffle_epi8(v, vh); \n\t\t\tv = bitunpack256v8_6(v); \n\t\t\tv = bitmap256v8_6(v);                                                                                                           \n            _mm256_storeu_si256((__m256i*) op, v);                                                 \n  }\n  \n  EXTAIL(7); //TODO: replace by using avx512 mask intrinsics \n  return outlen;\n}\n\n//--------------------- Decode ----------------------------------------------------------------------\n#define BITMAP256V8_6(iv, ov) ov = _mm512_permutex2var_epi8(vlut0, iv, vlut1);  //AVX-512_VBMI\n\n#define BITPACK512V8_6(v) {\\\n  __m512i merge_ab_bc = _mm512_maddubs_epi16(v,        _mm512_set1_epi32(0x01400140)),\\\n                   vm = _mm512_madd_epi16(merge_ab_bc, _mm512_set1_epi32(0x00011000));\\\n                   v  = _mm512_permutexvar_epi8(vp, vm);\\\n}\n\n#define B64CHK(iv, ov, vx) vx = _mm512_ternarylogic_epi32(vx, ov, iv, 0xfe)\n\n#define DS256(_i_) { __m512i iv0,iv1,ou0,ou1,ov0,ov1;      \\\n  iv0 = _mm512_loadu_si512((__m512i *)(ip+128+_i_*256)),   \\\n  iv1 = _mm512_loadu_si512((__m512i *)(ip+128+_i_*256+64));\\\n  \\\n  BITMAP256V8_6(iu0, ou0); CHECK0(B64CHK(iu0, ou0, vx)); BITPACK512V8_6(ou0);\\\n  BITMAP256V8_6(iu1, ou1); CHECK1(B64CHK(iu1, ou1, vx)); BITPACK512V8_6(ou1);\\\n  \\\n  iu0 = _mm512_loadu_si512((__m512i *)(ip+128+_i_*256+128)),\\\n  iu1 = _mm512_loadu_si512((__m512i *)(ip+128+_i_*256+192));\\\n  \\\n  _mm512_storeu_si512((__m128i*)(op+_i_*192), ou0);\\\n  _mm512_storeu_si512((__m128i*)(op+_i_*192+48), ou1);\\\n  \\\n  BITMAP256V8_6(iv0, ov0); CHECK1(B64CHK(iv0, ov0, vx)); BITPACK512V8_6(ov0);\\\n  BITMAP256V8_6(iv1, ov1); CHECK1(B64CHK(iv1, ov1, vx)); BITPACK512V8_6(ov1);\\\n  \\\n  _mm512_storeu_si512((__m128i*)(op+_i_*192+ 96), ov0);\\\n  _mm512_storeu_si512((__m128i*)(op+_i_*192+144), ov1);\\\n}\n\nsize_t tb64v512dec(const unsigned char *in, size_t inlen, unsigned char *out) {\n  const unsigned char *ip = in, *in_ = in + inlen;\n        unsigned char *op = out; \n  if(inlen&3) return 0;                                  \n\n  __m512i vx = _mm512_setzero_si512();\n  const __m512i vlut0 = _mm512_setr_epi32(0x80808080, 0x80808080, 0x80808080, 0x80808080,\n                                          0x80808080, 0x80808080, 0x80808080, 0x80808080,\n                                          0x80808080, 0x80808080, 0x3e808080, 0x3f808080,\n                                          0x37363534, 0x3b3a3938, 0x80803d3c, 0x80808080),\n                vlut1 = _mm512_setr_epi32(0x02010080, 0x06050403, 0x0a090807, 0x0e0d0c0b,\n                                          0x1211100f, 0x16151413, 0x80191817, 0x80808080,\n                                          0x1c1b1a80, 0x201f1e1d, 0x24232221, 0x28272625,\n                                          0x2c2b2a29, 0x302f2e2d, 0x80333231, 0x80808080),\n                   vp = _mm512_setr_epi32(0x06000102, 0x090a0405, 0x0c0d0e08, 0x16101112,\n                                          0x191a1415, 0x1c1d1e18, 0x26202122, 0x292a2425,\n                                          0x2c2d2e28, 0x36303132, 0x393a3435, 0x3c3d3e38,\n                                          0x00000000, 0x00000000, 0x00000000, 0x00000000);\t\t\t\t\t\t\t\t\t\t\t\t  \n  if(inlen >= 128+  256+4) {\n    __m512i iu0 = _mm512_loadu_si512((__m512i *) ip),    \n            iu1 = _mm512_loadu_si512((__m512i *)(ip+64)); \n    for(; ip < in_-(128+2*256+4); ip += 512, op += (512/4)*3) { DS256(0); DS256(1); }\n    if(   ip < in_-(128+  256+4)) { DS256(0); ip += 256; op += (256/4)*3; }\n  } else if(!inlen) return 0;\n  \n  for(; ip < in_-(64+16+4); ip += 64, op += 64*3/4) {\n    __m512i iv = _mm512_loadu_si512((__m512i *) ip), ov;\n    BITMAP256V8_6(iv, ov); \n\tCHECK0(B64CHK(iv, ov, vx)); \n\tBITPACK512V8_6(ov);\n    _mm512_storeu_si512((__m128i*) op, ov);\n  }\n  \n  unsigned rc = 0, r = in_ - ip;                              //replace by using avx512 mask intrinsics\n  if(r && !(rc=_tb64xd(ip, r, op)) || _mm512_movepi8_mask(vx)) \n\treturn 0;\n  return (op-out)+rc; \n}\n\n  #if 0 // AVX512F but Not faster than avx2\n#define BITPACK512V8_6_(v) {\\\n  const __m512i merge_ab_bc = _mm512_maddubs_epi16(v,            _mm512_set1_epi32(0x01400140));\\\n                          v = _mm512_madd_epi16(merge_ab_bc, _mm512_set1_epi32(0x00011000));\\\n                          v = _mm512_shuffle_epi8(v, cpv);\\\n}\n\n#define BITMAP512V8_6_(iv, shifted, ov) { /*map 8-bits ascii to 6-bits bin*/\\\n                shifted    = _mm512_srli_epi32(iv, 3);\\\n  const __m512i delta_hash = _mm512_avg_epu8(_mm512_shuffle_epi8(delta_asso, iv), shifted);\\\n                        ov = _mm512_add_epi8(_mm512_shuffle_epi8(delta_values, delta_hash), iv);\\\n}\n\n#define B64CHK_(iv, shifted, vx) {\\\n  const __m512i check_hash = _mm512_avg_epu8( _mm512_shuffle_epi8(check_asso, iv), shifted);\\\n  const __m512i        chk = _mm512_adds_epi8(_mm512_shuffle_epi8(check_values, check_hash), iv);\\\n                        vx = _mm512_or_si512(vx, chk);\\\n}\n\nsize_t tb64v512dec0(const unsigned char *in, size_t inlen, unsigned char *out) {\n  const unsigned char *ip = in;\n        unsigned char *op = out; \n        \n  __m512i vx = _mm512_setzero_si512();\n  if(inlen >= 120+256) {\n    const __m512i delta_asso   = _mm512_set_epi8(0x0f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,   0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n                                                 0x0f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,   0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n\t\t\t\t\t\t\t\t\t\t\t\t 0x0f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,   0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\n                                                 0x0f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,   0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01);\n    const __m512i delta_values = _mm512_set_epi8(0xb9, 0xb9, 0xbf, 0xbf, 0xc3, 0x10, 0x00, 0xb9,   0xb9, 0xbf, 0xbf, 0x04, 0x13, 0x00, 0x00, 0x00, \n\t\t\t\t\t\t\t\t\t\t\t\t 0xb9, 0xb9, 0xbf, 0xbf, 0xc3, 0x10, 0x00, 0xb9,   0xb9, 0xbf, 0xbf, 0x04, 0x13, 0x00, 0x00, 0x00, \n\t\t\t\t\t\t\t\t\t\t\t\t 0xb9, 0xb9, 0xbf, 0xbf, 0xc3, 0x10, 0x00, 0xb9,   0xb9, 0xbf, 0xbf, 0x04, 0x13, 0x00, 0x00, 0x00, \n\t\t\t\t\t\t\t\t\t\t\t\t 0xb9, 0xb9, 0xbf, 0xbf, 0xc3, 0x10, 0x00, 0xb9,   0xb9, 0xbf, 0xbf, 0x04, 0x13, 0x00, 0x00, 0x00);\n    const __m512i check_asso   = _mm512_set_epi8(0x0f, 0x0b, 0x0b, 0x0b, 0x07, 0x03, 0x01, 0x01,   0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0d,     \n\t\t\t\t\t\t\t\t\t\t\t\t 0x0f, 0x0b, 0x0b, 0x0b, 0x07, 0x03, 0x01, 0x01,   0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0d,     \n\t\t\t\t\t\t\t\t\t\t\t\t 0x0f, 0x0b, 0x0b, 0x0b, 0x07, 0x03, 0x01, 0x01,   0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0d,     \n\t\t\t\t\t\t\t\t\t\t\t\t 0x0f, 0x0b, 0x0b, 0x0b, 0x07, 0x03, 0x01, 0x01,   0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0d);\n    const __m512i check_values = _mm512_set_epi8(0x80, 0x91, 0x80, 0xb1, 0x80, 0xd1, 0x86, 0xb5,   0xa6, 0xd5, 0xbf, 0xcf, 0x80, 0x80, 0x80, 0x80,    \n\t\t\t\t\t\t\t\t\t\t\t\t 0x80, 0x91, 0x80, 0xb1, 0x80, 0xd1, 0x86, 0xb5,   0xa6, 0xd5, 0xbf, 0xcf, 0x80, 0x80, 0x80, 0x80,    \n\t\t\t\t\t\t\t\t\t\t\t\t 0x80, 0x91, 0x80, 0xb1, 0x80, 0xd1, 0x86, 0xb5,   0xa6, 0xd5, 0xbf, 0xcf, 0x80, 0x80, 0x80, 0x80,    \n\t\t\t\t\t\t\t\t\t\t\t\t 0x80, 0x91, 0x80, 0xb1, 0x80, 0xd1, 0x86, 0xb5,   0xa6, 0xd5, 0xbf, 0xcf, 0x80, 0x80, 0x80, 0x80),\n                           cpv = _mm512_set_epi8( -1, -1, -1, -1, 12, 13, 14,  8,    9, 10,  4,  5,  6,  0,  1,  2,\n                                                  -1, -1, -1, -1, 12, 13, 14,  8,    9, 10,  4,  5,  6,  0,  1,  2,\n\t\t\t\t\t\t\t\t\t\t\t\t  -1, -1, -1, -1, 12, 13, 14,  8,    9, 10,  4,  5,  6,  0,  1,  2,\n                                                  -1, -1, -1, -1, 12, 13, 14,  8,    9, 10,  4,  5,  6,  0,  1,  2);\n\t\t\t\t\t\t\t\t\t\t\t\t  \n      __m512i          iu0 = _mm512_loadu_si512((__m512i *) ip);    \n      __m512i          iu1 = _mm512_loadu_si512((__m512i *)(ip+64)); \n    for(        ; ip < in+(inlen-(256+4)); ip += 256, op += (256/4)*3) {           \n      __m512i          iv0 = _mm512_loadu_si512((__m512i *)(ip+128 ));    \n      __m512i          iv1 = _mm512_loadu_si512((__m512i *)(ip+128+64)); \n   \n      __m512i ou0,su0; BITMAP512V8_6_(iu0, su0, ou0); BITPACK512V8_6_(ou0);\n      __m512i ou1,su1; BITMAP512V8_6_(iu1, su1, ou1); BITPACK512V8_6_(ou1);\n      CHECK0(B64CHK_(iu0, su0, vx));\n      CHECK1(B64CHK_(iu1, su1, vx));\n      \n      _mm_storeu_si128((__m128i*) op,       _mm512_castsi512_si128(   ou0   ));\n      _mm_storeu_si128((__m128i*)(op + 12), _mm512_extracti32x4_epi32(ou0, 1));                          \n      _mm_storeu_si128((__m128i*)(op + 24), _mm512_extracti32x4_epi32(ou0, 2));                          \n      _mm_storeu_si128((__m128i*)(op + 36), _mm512_extracti32x4_epi32(ou0, 3));                          \n                      iu0 = _mm512_loadu_si512((__m512i *)(ip+128+128));    \n \n      _mm_storeu_si128((__m128i*)(op + 48), _mm512_castsi512_si128(   ou1   ));\n      _mm_storeu_si128((__m128i*)(op + 60), _mm512_extracti32x4_epi32(ou1, 1));                          \n      _mm_storeu_si128((__m128i*)(op + 72), _mm512_extracti32x4_epi32(ou1, 2));                          \n      _mm_storeu_si128((__m128i*)(op + 84), _mm512_extracti32x4_epi32(ou1, 3));                           \n                       iu1 = _mm512_loadu_si512((__m512i *)(ip+128+192)); \n\t  \n\n      __m512i ov0,sv0; BITMAP512V8_6_(iv0, sv0, ov0); BITPACK512V8_6_(ov0);\n      __m512i ov1,sv1; BITMAP512V8_6_(iv1, sv1, ov1); BITPACK512V8_6_(ov1);\n      \n      _mm_storeu_si128((__m128i*)(op + 96), _mm512_castsi512_si128(   ov0   ));\n      _mm_storeu_si128((__m128i*)(op + 96+12), _mm512_extracti32x4_epi32(ov0, 1));                          \n      _mm_storeu_si128((__m128i*)(op + 96+24), _mm512_extracti32x4_epi32(ov0, 2));                          \n      _mm_storeu_si128((__m128i*)(op + 96+36), _mm512_extracti32x4_epi32(ov0, 3));                          \n\n      _mm_storeu_si128((__m128i*)(op + 96+48), _mm512_castsi512_si128(   ov1   ));\n      _mm_storeu_si128((__m128i*)(op + 96+60), _mm512_extracti32x4_epi32(ov1, 1));                          \n      _mm_storeu_si128((__m128i*)(op + 96+72), _mm512_extracti32x4_epi32(ov1, 2));                          \n      _mm_storeu_si128((__m128i*)(op + 96+84), _mm512_extracti32x4_epi32(ov1, 3));                          \n \n      CHECK1(B64CHK_(iv0, sv0, vx));\n      CHECK1(B64CHK_(iv1, sv1, vx));\n    }\n  }\n  unsigned rc, r = inlen-(ip-in); \n  if(r && !(rc=tb64xdec(ip, r, op)) || _mm512_movepi8_mask(vx)) return 0;\n  return (op-out)+rc; \n}\n#endif\n"
  },
  {
    "path": "vs/getopt.c",
    "content": "/*\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 tv Exp $\t*/\n\n/*\n * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>\n *\n * Permission to use, copy, modify, and distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n *\n * Sponsored in part by the Defense Advanced Research Projects\n * Agency (DARPA) and Air Force Research Laboratory, Air Force\n * Materiel Command, USAF, under agreement number F39502-99-1-0512.\n */\n/*-\n * Copyright (c) 2000 The NetBSD Foundation, Inc.\n * All rights reserved.\n *\n * This code is derived from software contributed to The NetBSD Foundation\n * by Dieter Baron and Thomas Klausner.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n *    notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n *    notice, this list of conditions and the following disclaimer in the\n *    documentation and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\n * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\n * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\n * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n\n#include <errno.h>\n#include <stdlib.h>\n#include <string.h>\n#include \"getopt.h\"\n#include <stdarg.h>\n#include <stdio.h>\n#include <windows.h>\n\n#define\tREPLACE_GETOPT\t\t/* use this getopt as the system getopt(3) */\n\n#ifdef REPLACE_GETOPT\nint\topterr = 1;\t\t/* if error message should be printed */\nint\toptind = 1;\t\t/* index into parent argv vector */\nint\toptopt = '?';\t\t/* character checked for validity */\n#undef\toptreset\t\t/* see getopt.h */\n#define\toptreset\t\t__mingw_optreset\nint\toptreset;\t\t/* reset getopt */\nchar    *optarg;\t\t/* argument associated with option */\n#endif\n\n#define PRINT_ERROR\t((opterr) && (*options != ':'))\n\n#define FLAG_PERMUTE\t0x01\t/* permute non-options to the end of argv */\n#define FLAG_ALLARGS\t0x02\t/* treat non-options as args to option \"-1\" */\n#define FLAG_LONGONLY\t0x04\t/* operate as getopt_long_only */\n\n/* return values */\n#define\tBADCH\t\t(int)'?'\n#define\tBADARG\t\t((*options == ':') ? (int)':' : (int)'?')\n#define\tINORDER \t(int)1\n\n#ifndef __CYGWIN__\n#define __progname __argv[0]\n#else\nextern char __declspec(dllimport) *__progname;\n#endif\n\n#ifdef __CYGWIN__\nstatic char EMSG[] = \"\";\n#else\n#define\tEMSG\t\t\"\"\n#endif\n\nstatic int getopt_internal(int, char * const *, const char *,\n\t\t\t   const struct option *, int *, int);\nstatic int parse_long_options(char * const *, const char *,\n\t\t\t      const struct option *, int *, int);\nstatic int gcd(int, int);\nstatic void permute_args(int, int, int, char * const *);\n\nstatic char *place = EMSG; /* option letter processing */\n\n/* XXX: set optreset to 1 rather than these two */\nstatic int nonopt_start = -1; /* first non option argument (for permute) */\nstatic int nonopt_end = -1;   /* first option after non options (for permute) */\n\n/* Error messages */\nstatic const char recargchar[] = \"option requires an argument -- %c\";\nstatic const char recargstring[] = \"option requires an argument -- %s\";\nstatic const char ambig[] = \"ambiguous option -- %.*s\";\nstatic const char noarg[] = \"option doesn't take an argument -- %.*s\";\nstatic const char illoptchar[] = \"unknown option -- %c\";\nstatic const char illoptstring[] = \"unknown option -- %s\";\n\nstatic void\n_vwarnx(const char *fmt,va_list ap)\n{\n  (void)fprintf(stderr,\"%s: \",__progname);\n  if (fmt != NULL)\n    (void)vfprintf(stderr,fmt,ap);\n  (void)fprintf(stderr,\"\\n\");\n}\n\nstatic void\nwarnx(const char *fmt,...)\n{\n  va_list ap;\n  va_start(ap,fmt);\n  _vwarnx(fmt,ap);\n  va_end(ap);\n}\n\n/*\n * Compute the greatest common divisor of a and b.\n */\nstatic int\ngcd(int a, int b)\n{\n\tint c;\n\n\tc = a % b;\n\twhile (c != 0) {\n\t\ta = b;\n\t\tb = c;\n\t\tc = a % b;\n\t}\n\n\treturn (b);\n}\n\n/*\n * Exchange the block from nonopt_start to nonopt_end with the block\n * from nonopt_end to opt_end (keeping the same order of arguments\n * in each block).\n */\nstatic void\npermute_args(int panonopt_start, int panonopt_end, int opt_end,\n\tchar * const *nargv)\n{\n\tint cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;\n\tchar *swap;\n\n\t/*\n\t * compute lengths of blocks and number and size of cycles\n\t */\n\tnnonopts = panonopt_end - panonopt_start;\n\tnopts = opt_end - panonopt_end;\n\tncycle = gcd(nnonopts, nopts);\n\tcyclelen = (opt_end - panonopt_start) / ncycle;\n\n\tfor (i = 0; i < ncycle; i++) {\n\t\tcstart = panonopt_end+i;\n\t\tpos = cstart;\n\t\tfor (j = 0; j < cyclelen; j++) {\n\t\t\tif (pos >= panonopt_end)\n\t\t\t\tpos -= nnonopts;\n\t\t\telse\n\t\t\t\tpos += nopts;\n\t\t\tswap = nargv[pos];\n\t\t\t/* LINTED const cast */\n\t\t\t((char **) nargv)[pos] = nargv[cstart];\n\t\t\t/* LINTED const cast */\n\t\t\t((char **)nargv)[cstart] = swap;\n\t\t}\n\t}\n}\n\n/*\n * parse_long_options --\n *\tParse long options in argc/argv argument vector.\n * Returns -1 if short_too is set and the option does not match long_options.\n */\nstatic int\nparse_long_options(char * const *nargv, const char *options,\n\tconst struct option *long_options, int *idx, int short_too)\n{\n\tchar *current_argv, *has_equal;\n\tsize_t current_argv_len;\n\tint i, ambiguous, match;\n\n#define IDENTICAL_INTERPRETATION(_x, _y)                                \\\n\t(long_options[(_x)].has_arg == long_options[(_y)].has_arg &&    \\\n\t long_options[(_x)].flag == long_options[(_y)].flag &&          \\\n\t long_options[(_x)].val == long_options[(_y)].val)\n\n\tcurrent_argv = place;\n\tmatch = -1;\n\tambiguous = 0;\n\n\toptind++;\n\n\tif ((has_equal = strchr(current_argv, '=')) != NULL) {\n\t\t/* argument found (--option=arg) */\n\t\tcurrent_argv_len = has_equal - current_argv;\n\t\thas_equal++;\n\t} else\n\t\tcurrent_argv_len = strlen(current_argv);\n\n\tfor (i = 0; long_options[i].name; i++) {\n\t\t/* find matching long option */\n\t\tif (strncmp(current_argv, long_options[i].name,\n\t\t    current_argv_len))\n\t\t\tcontinue;\n\n\t\tif (strlen(long_options[i].name) == current_argv_len) {\n\t\t\t/* exact match */\n\t\t\tmatch = i;\n\t\t\tambiguous = 0;\n\t\t\tbreak;\n\t\t}\n\t\t/*\n\t\t * If this is a known short option, don't allow\n\t\t * a partial match of a single character.\n\t\t */\n\t\tif (short_too && current_argv_len == 1)\n\t\t\tcontinue;\n\n\t\tif (match == -1)\t/* partial match */\n\t\t\tmatch = i;\n\t\telse if (!IDENTICAL_INTERPRETATION(i, match))\n\t\t\tambiguous = 1;\n\t}\n\tif (ambiguous) {\n\t\t/* ambiguous abbreviation */\n\t\tif (PRINT_ERROR)\n\t\t\twarnx(ambig, (int)current_argv_len,\n\t\t\t     current_argv);\n\t\toptopt = 0;\n\t\treturn (BADCH);\n\t}\n\tif (match != -1) {\t\t/* option found */\n\t\tif (long_options[match].has_arg == no_argument\n\t\t    && has_equal) {\n\t\t\tif (PRINT_ERROR)\n\t\t\t\twarnx(noarg, (int)current_argv_len,\n\t\t\t\t     current_argv);\n\t\t\t/*\n\t\t\t * XXX: GNU sets optopt to val regardless of flag\n\t\t\t */\n\t\t\tif (long_options[match].flag == NULL)\n\t\t\t\toptopt = long_options[match].val;\n\t\t\telse\n\t\t\t\toptopt = 0;\n\t\t\treturn (BADARG);\n\t\t}\n\t\tif (long_options[match].has_arg == required_argument ||\n\t\t    long_options[match].has_arg == optional_argument) {\n\t\t\tif (has_equal)\n\t\t\t\toptarg = has_equal;\n\t\t\telse if (long_options[match].has_arg ==\n\t\t\t    required_argument) {\n\t\t\t\t/*\n\t\t\t\t * optional argument doesn't use next nargv\n\t\t\t\t */\n\t\t\t\toptarg = nargv[optind++];\n\t\t\t}\n\t\t}\n\t\tif ((long_options[match].has_arg == required_argument)\n\t\t    && (optarg == NULL)) {\n\t\t\t/*\n\t\t\t * Missing argument; leading ':' indicates no error\n\t\t\t * should be generated.\n\t\t\t */\n\t\t\tif (PRINT_ERROR)\n\t\t\t\twarnx(recargstring,\n\t\t\t\t    current_argv);\n\t\t\t/*\n\t\t\t * XXX: GNU sets optopt to val regardless of flag\n\t\t\t */\n\t\t\tif (long_options[match].flag == NULL)\n\t\t\t\toptopt = long_options[match].val;\n\t\t\telse\n\t\t\t\toptopt = 0;\n\t\t\t--optind;\n\t\t\treturn (BADARG);\n\t\t}\n\t} else {\t\t\t/* unknown option */\n\t\tif (short_too) {\n\t\t\t--optind;\n\t\t\treturn (-1);\n\t\t}\n\t\tif (PRINT_ERROR)\n\t\t\twarnx(illoptstring, current_argv);\n\t\toptopt = 0;\n\t\treturn (BADCH);\n\t}\n\tif (idx)\n\t\t*idx = match;\n\tif (long_options[match].flag) {\n\t\t*long_options[match].flag = long_options[match].val;\n\t\treturn (0);\n\t} else\n\t\treturn (long_options[match].val);\n#undef IDENTICAL_INTERPRETATION\n}\n\n/*\n * getopt_internal --\n *\tParse argc/argv argument vector.  Called by user level routines.\n */\nstatic int\ngetopt_internal(int nargc, char * const *nargv, const char *options,\n\tconst struct option *long_options, int *idx, int flags)\n{\n\tchar *oli;\t\t\t\t/* option letter list index */\n\tint optchar, short_too;\n\tstatic int posixly_correct = -1;\n\n\tif (options == NULL)\n\t\treturn (-1);\n\n\t/*\n\t * XXX Some GNU programs (like cvs) set optind to 0 instead of\n\t * XXX using optreset.  Work around this braindamage.\n\t */\n\tif (optind == 0)\n\t\toptind = optreset = 1;\n\n\t/*\n\t * Disable GNU extensions if POSIXLY_CORRECT is set or options\n\t * string begins with a '+'.\n\t *\n\t * CV, 2009-12-14: Check POSIXLY_CORRECT anew if optind == 0 or\n\t *                 optreset != 0 for GNU compatibility.\n\t */\n\tif (posixly_correct == -1 || optreset != 0)\n\t\tposixly_correct = (getenv(\"POSIXLY_CORRECT\") != NULL);\n\tif (*options == '-')\n\t\tflags |= FLAG_ALLARGS;\n\telse if (posixly_correct || *options == '+')\n\t\tflags &= ~FLAG_PERMUTE;\n\tif (*options == '+' || *options == '-')\n\t\toptions++;\n\n\toptarg = NULL;\n\tif (optreset)\n\t\tnonopt_start = nonopt_end = -1;\nstart:\n\tif (optreset || !*place) {\t\t/* update scanning pointer */\n\t\toptreset = 0;\n\t\tif (optind >= nargc) {          /* end of argument vector */\n\t\t\tplace = EMSG;\n\t\t\tif (nonopt_end != -1) {\n\t\t\t\t/* do permutation, if we have to */\n\t\t\t\tpermute_args(nonopt_start, nonopt_end,\n\t\t\t\t    optind, nargv);\n\t\t\t\toptind -= nonopt_end - nonopt_start;\n\t\t\t}\n\t\t\telse if (nonopt_start != -1) {\n\t\t\t\t/*\n\t\t\t\t * If we skipped non-options, set optind\n\t\t\t\t * to the first of them.\n\t\t\t\t */\n\t\t\t\toptind = nonopt_start;\n\t\t\t}\n\t\t\tnonopt_start = nonopt_end = -1;\n\t\t\treturn (-1);\n\t\t}\n\t\tif (*(place = nargv[optind]) != '-' ||\n\t\t    (place[1] == '\\0' && strchr(options, '-') == NULL)) {\n\t\t\tplace = EMSG;\t\t/* found non-option */\n\t\t\tif (flags & FLAG_ALLARGS) {\n\t\t\t\t/*\n\t\t\t\t * GNU extension:\n\t\t\t\t * return non-option as argument to option 1\n\t\t\t\t */\n\t\t\t\toptarg = nargv[optind++];\n\t\t\t\treturn (INORDER);\n\t\t\t}\n\t\t\tif (!(flags & FLAG_PERMUTE)) {\n\t\t\t\t/*\n\t\t\t\t * If no permutation wanted, stop parsing\n\t\t\t\t * at first non-option.\n\t\t\t\t */\n\t\t\t\treturn (-1);\n\t\t\t}\n\t\t\t/* do permutation */\n\t\t\tif (nonopt_start == -1)\n\t\t\t\tnonopt_start = optind;\n\t\t\telse if (nonopt_end != -1) {\n\t\t\t\tpermute_args(nonopt_start, nonopt_end,\n\t\t\t\t    optind, nargv);\n\t\t\t\tnonopt_start = optind -\n\t\t\t\t    (nonopt_end - nonopt_start);\n\t\t\t\tnonopt_end = -1;\n\t\t\t}\n\t\t\toptind++;\n\t\t\t/* process next argument */\n\t\t\tgoto start;\n\t\t}\n\t\tif (nonopt_start != -1 && nonopt_end == -1)\n\t\t\tnonopt_end = optind;\n\n\t\t/*\n\t\t * If we have \"-\" do nothing, if \"--\" we are done.\n\t\t */\n\t\tif (place[1] != '\\0' && *++place == '-' && place[1] == '\\0') {\n\t\t\toptind++;\n\t\t\tplace = EMSG;\n\t\t\t/*\n\t\t\t * We found an option (--), so if we skipped\n\t\t\t * non-options, we have to permute.\n\t\t\t */\n\t\t\tif (nonopt_end != -1) {\n\t\t\t\tpermute_args(nonopt_start, nonopt_end,\n\t\t\t\t    optind, nargv);\n\t\t\t\toptind -= nonopt_end - nonopt_start;\n\t\t\t}\n\t\t\tnonopt_start = nonopt_end = -1;\n\t\t\treturn (-1);\n\t\t}\n\t}\n\n\t/*\n\t * Check long options if:\n\t *  1) we were passed some\n\t *  2) the arg is not just \"-\"\n\t *  3) either the arg starts with -- we are getopt_long_only()\n\t */\n\tif (long_options != NULL && place != nargv[optind] &&\n\t    (*place == '-' || (flags & FLAG_LONGONLY))) {\n\t\tshort_too = 0;\n\t\tif (*place == '-')\n\t\t\tplace++;\t\t/* --foo long option */\n\t\telse if (*place != ':' && strchr(options, *place) != NULL)\n\t\t\tshort_too = 1;\t\t/* could be short option too */\n\n\t\toptchar = parse_long_options(nargv, options, long_options,\n\t\t    idx, short_too);\n\t\tif (optchar != -1) {\n\t\t\tplace = EMSG;\n\t\t\treturn (optchar);\n\t\t}\n\t}\n\n\tif ((optchar = (int)*place++) == (int)':' ||\n\t    (optchar == (int)'-' && *place != '\\0') ||\n\t    (oli = strchr(options, optchar)) == NULL) {\n\t\t/*\n\t\t * If the user specified \"-\" and  '-' isn't listed in\n\t\t * options, return -1 (non-option) as per POSIX.\n\t\t * Otherwise, it is an unknown option character (or ':').\n\t\t */\n\t\tif (optchar == (int)'-' && *place == '\\0')\n\t\t\treturn (-1);\n\t\tif (!*place)\n\t\t\t++optind;\n\t\tif (PRINT_ERROR)\n\t\t\twarnx(illoptchar, optchar);\n\t\toptopt = optchar;\n\t\treturn (BADCH);\n\t}\n\tif (long_options != NULL && optchar == 'W' && oli[1] == ';') {\n\t\t/* -W long-option */\n\t\tif (*place)\t\t\t/* no space */\n\t\t\t/* NOTHING */;\n\t\telse if (++optind >= nargc) {\t/* no arg */\n\t\t\tplace = EMSG;\n\t\t\tif (PRINT_ERROR)\n\t\t\t\twarnx(recargchar, optchar);\n\t\t\toptopt = optchar;\n\t\t\treturn (BADARG);\n\t\t} else\t\t\t\t/* white space */\n\t\t\tplace = nargv[optind];\n\t\toptchar = parse_long_options(nargv, options, long_options,\n\t\t    idx, 0);\n\t\tplace = EMSG;\n\t\treturn (optchar);\n\t}\n\tif (*++oli != ':') {\t\t\t/* doesn't take argument */\n\t\tif (!*place)\n\t\t\t++optind;\n\t} else {\t\t\t\t/* takes (optional) argument */\n\t\toptarg = NULL;\n\t\tif (*place)\t\t\t/* no white space */\n\t\t\toptarg = place;\n\t\telse if (oli[1] != ':') {\t/* arg not optional */\n\t\t\tif (++optind >= nargc) {\t/* no arg */\n\t\t\t\tplace = EMSG;\n\t\t\t\tif (PRINT_ERROR)\n\t\t\t\t\twarnx(recargchar, optchar);\n\t\t\t\toptopt = optchar;\n\t\t\t\treturn (BADARG);\n\t\t\t} else\n\t\t\t\toptarg = nargv[optind];\n\t\t}\n\t\tplace = EMSG;\n\t\t++optind;\n\t}\n\t/* dump back option letter */\n\treturn (optchar);\n}\n\n#ifdef REPLACE_GETOPT\n/*\n * getopt --\n *\tParse argc/argv argument vector.\n *\n * [eventually this will replace the BSD getopt]\n */\nint\ngetopt(int nargc, char * const *nargv, const char *options)\n{\n\n\t/*\n\t * We don't pass FLAG_PERMUTE to getopt_internal() since\n\t * the BSD getopt(3) (unlike GNU) has never done this.\n\t *\n\t * Furthermore, since many privileged programs call getopt()\n\t * before dropping privileges it makes sense to keep things\n\t * as simple (and bug-free) as possible.\n\t */\n\treturn (getopt_internal(nargc, nargv, options, NULL, NULL, 0));\n}\n#endif /* REPLACE_GETOPT */\n\n/*\n * getopt_long --\n *\tParse argc/argv argument vector.\n */\nint\ngetopt_long(int nargc, char * const *nargv, const char *options,\n    const struct option *long_options, int *idx)\n{\n\n\treturn (getopt_internal(nargc, nargv, options, long_options, idx,\n\t    FLAG_PERMUTE));\n}\n\n/*\n * getopt_long_only --\n *\tParse argc/argv argument vector.\n */\nint\ngetopt_long_only(int nargc, char * const *nargv, const char *options,\n    const struct option *long_options, int *idx)\n{\n\n\treturn (getopt_internal(nargc, nargv, options, long_options, idx,\n\t    FLAG_PERMUTE|FLAG_LONGONLY));\n}\n"
  },
  {
    "path": "vs/getopt.h",
    "content": "#ifndef __GETOPT_H__\n/**\n * DISCLAIMER\n * This file has no copyright assigned and is placed in the Public Domain.\n * This file is a part of the w64 mingw-runtime package.\n *\n * The w64 mingw-runtime package and its code is distributed in the hope that it \n * will be useful but WITHOUT ANY WARRANTY.  ALL WARRANTIES, EXPRESSED OR \n * IMPLIED ARE HEREBY DISCLAIMED.  This includes but is not limited to \n * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n */\n\n#define __GETOPT_H__\n\n/* All the headers include this file. */\n#if _MSC_VER >= 1300\n#include <crtdefs.h>\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\nextern int optind;\t\t/* index of first non-option in argv      */\nextern int optopt;\t\t/* single option character, as parsed     */\nextern int opterr;\t\t/* flag to enable built-in diagnostics... */\n\t\t\t\t/* (user may set to zero, to suppress)    */\n\nextern char *optarg;\t\t/* pointer to argument of current option  */\n\nextern int getopt(int nargc, char * const *nargv, const char *options);\n\n#ifdef _BSD_SOURCE\n/*\n * BSD adds the non-standard `optreset' feature, for reinitialisation\n * of `getopt' parsing.  We support this feature, for applications which\n * proclaim their BSD heritage, before including this header; however,\n * to maintain portability, developers are advised to avoid it.\n */\n# define optreset  __mingw_optreset\nextern int optreset;\n#endif\n#ifdef __cplusplus\n}\n#endif\n/*\n * POSIX requires the `getopt' API to be specified in `unistd.h';\n * thus, `unistd.h' includes this header.  However, we do not want\n * to expose the `getopt_long' or `getopt_long_only' APIs, when\n * included in this manner.  Thus, close the standard __GETOPT_H__\n * declarations block, and open an additional __GETOPT_LONG_H__\n * specific block, only when *not* __UNISTD_H_SOURCED__, in which\n * to declare the extended API.\n */\n#endif /* !defined(__GETOPT_H__) */\n\n#if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__)\n#define __GETOPT_LONG_H__\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\nstruct option\t\t/* specification for a long form option...\t*/\n{\n  const char *name;\t\t/* option name, without leading hyphens */\n  int         has_arg;\t\t/* does it take an argument?\t\t*/\n  int        *flag;\t\t/* where to save its status, or NULL\t*/\n  int         val;\t\t/* its associated status value\t\t*/\n};\n\nenum    \t\t/* permitted values for its `has_arg' field...\t*/\n{\n  no_argument = 0,      \t/* option never takes an argument\t*/\n  required_argument,\t\t/* option always requires an argument\t*/\n  optional_argument\t\t/* option may take an argument\t\t*/\n};\n\nextern int getopt_long(int nargc, char * const *nargv, const char *options,\n    const struct option *long_options, int *idx);\nextern int getopt_long_only(int nargc, char * const *nargv, const char *options,\n    const struct option *long_options, int *idx);\n/*\n * Previous MinGW implementation had...\n */\n#ifndef HAVE_DECL_GETOPT\n/*\n * ...for the long form API only; keep this for compatibility.\n */\n# define HAVE_DECL_GETOPT\t1\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */\n"
  },
  {
    "path": "vs/inttypes.h",
    "content": "// ISO C9x  compliant inttypes.h for Microsoft Visual Studio\n// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 \n// \n//  Copyright (c) 2006-2013 Alexander Chemeris\n// \n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are met:\n// \n//   1. Redistributions of source code must retain the above copyright notice,\n//      this list of conditions and the following disclaimer.\n// \n//   2. Redistributions in binary form must reproduce the above copyright\n//      notice, this list of conditions and the following disclaimer in the\n//      documentation and/or other materials provided with the distribution.\n// \n//   3. Neither the name of the product nor the names of its contributors may\n//      be used to endorse or promote products derived from this software\n//      without specific prior written permission.\n// \n// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED\n// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO\n// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\n// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \n// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n// \n///////////////////////////////////////////////////////////////////////////////\n\n#ifndef _MSC_VER // [\n#error \"Use this header only with Microsoft Visual C++ compilers!\"\n#endif // _MSC_VER ]\n\n#ifndef _MSC_INTTYPES_H_ // [\n#define _MSC_INTTYPES_H_\n\n#if _MSC_VER > 1000\n#pragma once\n#endif\n\n#include \"stdint.h\"\n\n// 7.8 Format conversion of integer types\n\ntypedef struct {\n   intmax_t quot;\n   intmax_t rem;\n} imaxdiv_t;\n\n// 7.8.1 Macros for format specifiers\n\n#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [   See footnote 185 at page 198\n\n// The fprintf macros for signed integers are:\n#define PRId8       \"d\"\n#define PRIi8       \"i\"\n#define PRIdLEAST8  \"d\"\n#define PRIiLEAST8  \"i\"\n#define PRIdFAST8   \"d\"\n#define PRIiFAST8   \"i\"\n\n#define PRId16       \"hd\"\n#define PRIi16       \"hi\"\n#define PRIdLEAST16  \"hd\"\n#define PRIiLEAST16  \"hi\"\n#define PRIdFAST16   \"hd\"\n#define PRIiFAST16   \"hi\"\n\n#define PRId32       \"I32d\"\n#define PRIi32       \"I32i\"\n#define PRIdLEAST32  \"I32d\"\n#define PRIiLEAST32  \"I32i\"\n#define PRIdFAST32   \"I32d\"\n#define PRIiFAST32   \"I32i\"\n\n#define PRId64       \"I64d\"\n#define PRIi64       \"I64i\"\n#define PRIdLEAST64  \"I64d\"\n#define PRIiLEAST64  \"I64i\"\n#define PRIdFAST64   \"I64d\"\n#define PRIiFAST64   \"I64i\"\n\n#define PRIdMAX     \"I64d\"\n#define PRIiMAX     \"I64i\"\n\n#define PRIdPTR     \"Id\"\n#define PRIiPTR     \"Ii\"\n\n// The fprintf macros for unsigned integers are:\n#define PRIo8       \"o\"\n#define PRIu8       \"u\"\n#define PRIx8       \"x\"\n#define PRIX8       \"X\"\n#define PRIoLEAST8  \"o\"\n#define PRIuLEAST8  \"u\"\n#define PRIxLEAST8  \"x\"\n#define PRIXLEAST8  \"X\"\n#define PRIoFAST8   \"o\"\n#define PRIuFAST8   \"u\"\n#define PRIxFAST8   \"x\"\n#define PRIXFAST8   \"X\"\n\n#define PRIo16       \"ho\"\n#define PRIu16       \"hu\"\n#define PRIx16       \"hx\"\n#define PRIX16       \"hX\"\n#define PRIoLEAST16  \"ho\"\n#define PRIuLEAST16  \"hu\"\n#define PRIxLEAST16  \"hx\"\n#define PRIXLEAST16  \"hX\"\n#define PRIoFAST16   \"ho\"\n#define PRIuFAST16   \"hu\"\n#define PRIxFAST16   \"hx\"\n#define PRIXFAST16   \"hX\"\n\n#define PRIo32       \"I32o\"\n#define PRIu32       \"I32u\"\n#define PRIx32       \"I32x\"\n#define PRIX32       \"I32X\"\n#define PRIoLEAST32  \"I32o\"\n#define PRIuLEAST32  \"I32u\"\n#define PRIxLEAST32  \"I32x\"\n#define PRIXLEAST32  \"I32X\"\n#define PRIoFAST32   \"I32o\"\n#define PRIuFAST32   \"I32u\"\n#define PRIxFAST32   \"I32x\"\n#define PRIXFAST32   \"I32X\"\n\n#define PRIo64       \"I64o\"\n#define PRIu64       \"I64u\"\n#define PRIx64       \"I64x\"\n#define PRIX64       \"I64X\"\n#define PRIoLEAST64  \"I64o\"\n#define PRIuLEAST64  \"I64u\"\n#define PRIxLEAST64  \"I64x\"\n#define PRIXLEAST64  \"I64X\"\n#define PRIoFAST64   \"I64o\"\n#define PRIuFAST64   \"I64u\"\n#define PRIxFAST64   \"I64x\"\n#define PRIXFAST64   \"I64X\"\n\n#define PRIoMAX     \"I64o\"\n#define PRIuMAX     \"I64u\"\n#define PRIxMAX     \"I64x\"\n#define PRIXMAX     \"I64X\"\n\n#define PRIoPTR     \"Io\"\n#define PRIuPTR     \"Iu\"\n#define PRIxPTR     \"Ix\"\n#define PRIXPTR     \"IX\"\n\n// The fscanf macros for signed integers are:\n#define SCNd8       \"d\"\n#define SCNi8       \"i\"\n#define SCNdLEAST8  \"d\"\n#define SCNiLEAST8  \"i\"\n#define SCNdFAST8   \"d\"\n#define SCNiFAST8   \"i\"\n\n#define SCNd16       \"hd\"\n#define SCNi16       \"hi\"\n#define SCNdLEAST16  \"hd\"\n#define SCNiLEAST16  \"hi\"\n#define SCNdFAST16   \"hd\"\n#define SCNiFAST16   \"hi\"\n\n#define SCNd32       \"ld\"\n#define SCNi32       \"li\"\n#define SCNdLEAST32  \"ld\"\n#define SCNiLEAST32  \"li\"\n#define SCNdFAST32   \"ld\"\n#define SCNiFAST32   \"li\"\n\n#define SCNd64       \"I64d\"\n#define SCNi64       \"I64i\"\n#define SCNdLEAST64  \"I64d\"\n#define SCNiLEAST64  \"I64i\"\n#define SCNdFAST64   \"I64d\"\n#define SCNiFAST64   \"I64i\"\n\n#define SCNdMAX     \"I64d\"\n#define SCNiMAX     \"I64i\"\n\n#ifdef _WIN64 // [\n#  define SCNdPTR     \"I64d\"\n#  define SCNiPTR     \"I64i\"\n#else  // _WIN64 ][\n#  define SCNdPTR     \"ld\"\n#  define SCNiPTR     \"li\"\n#endif  // _WIN64 ]\n\n// The fscanf macros for unsigned integers are:\n#define SCNo8       \"o\"\n#define SCNu8       \"u\"\n#define SCNx8       \"x\"\n#define SCNX8       \"X\"\n#define SCNoLEAST8  \"o\"\n#define SCNuLEAST8  \"u\"\n#define SCNxLEAST8  \"x\"\n#define SCNXLEAST8  \"X\"\n#define SCNoFAST8   \"o\"\n#define SCNuFAST8   \"u\"\n#define SCNxFAST8   \"x\"\n#define SCNXFAST8   \"X\"\n\n#define SCNo16       \"ho\"\n#define SCNu16       \"hu\"\n#define SCNx16       \"hx\"\n#define SCNX16       \"hX\"\n#define SCNoLEAST16  \"ho\"\n#define SCNuLEAST16  \"hu\"\n#define SCNxLEAST16  \"hx\"\n#define SCNXLEAST16  \"hX\"\n#define SCNoFAST16   \"ho\"\n#define SCNuFAST16   \"hu\"\n#define SCNxFAST16   \"hx\"\n#define SCNXFAST16   \"hX\"\n\n#define SCNo32       \"lo\"\n#define SCNu32       \"lu\"\n#define SCNx32       \"lx\"\n#define SCNX32       \"lX\"\n#define SCNoLEAST32  \"lo\"\n#define SCNuLEAST32  \"lu\"\n#define SCNxLEAST32  \"lx\"\n#define SCNXLEAST32  \"lX\"\n#define SCNoFAST32   \"lo\"\n#define SCNuFAST32   \"lu\"\n#define SCNxFAST32   \"lx\"\n#define SCNXFAST32   \"lX\"\n\n#define SCNo64       \"I64o\"\n#define SCNu64       \"I64u\"\n#define SCNx64       \"I64x\"\n#define SCNX64       \"I64X\"\n#define SCNoLEAST64  \"I64o\"\n#define SCNuLEAST64  \"I64u\"\n#define SCNxLEAST64  \"I64x\"\n#define SCNXLEAST64  \"I64X\"\n#define SCNoFAST64   \"I64o\"\n#define SCNuFAST64   \"I64u\"\n#define SCNxFAST64   \"I64x\"\n#define SCNXFAST64   \"I64X\"\n\n#define SCNoMAX     \"I64o\"\n#define SCNuMAX     \"I64u\"\n#define SCNxMAX     \"I64x\"\n#define SCNXMAX     \"I64X\"\n\n#ifdef _WIN64 // [\n#  define SCNoPTR     \"I64o\"\n#  define SCNuPTR     \"I64u\"\n#  define SCNxPTR     \"I64x\"\n#  define SCNXPTR     \"I64X\"\n#else  // _WIN64 ][\n#  define SCNoPTR     \"lo\"\n#  define SCNuPTR     \"lu\"\n#  define SCNxPTR     \"lx\"\n#  define SCNXPTR     \"lX\"\n#endif  // _WIN64 ]\n\n#endif // __STDC_FORMAT_MACROS ]\n\n// 7.8.2 Functions for greatest-width integer types\n\n// 7.8.2.1 The imaxabs function\n#define imaxabs _abs64\n\n// 7.8.2.2 The imaxdiv function\n\n// This is modified version of div() function from Microsoft's div.c found\n// in %MSVC.NET%\\crt\\src\\div.c\n#ifdef STATIC_IMAXDIV // [\nstatic\n#else // STATIC_IMAXDIV ][\n_inline\n#endif // STATIC_IMAXDIV ]\nimaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)\n{\n   imaxdiv_t result;\n\n   result.quot = numer / denom;\n   result.rem = numer % denom;\n\n   if (numer < 0 && result.rem > 0) {\n      // did division wrong; must fix up\n      ++result.quot;\n      result.rem -= denom;\n   }\n\n   return result;\n}\n\n// 7.8.2.3 The strtoimax and strtoumax functions\n#define strtoimax _strtoi64\n#define strtoumax _strtoui64\n\n// 7.8.2.4 The wcstoimax and wcstoumax functions\n#define wcstoimax _wcstoi64\n#define wcstoumax _wcstoui64\n\n\n#endif // _MSC_INTTYPES_H_ ]\n"
  },
  {
    "path": "vs/stdint.h",
    "content": "// ISO C9x  compliant stdint.h for Microsoft Visual Studio\n// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 \n// \n//  Copyright (c) 2006-2013 Alexander Chemeris\n// \n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are met:\n// \n//   1. Redistributions of source code must retain the above copyright notice,\n//      this list of conditions and the following disclaimer.\n// \n//   2. Redistributions in binary form must reproduce the above copyright\n//      notice, this list of conditions and the following disclaimer in the\n//      documentation and/or other materials provided with the distribution.\n// \n//   3. Neither the name of the product nor the names of its contributors may\n//      be used to endorse or promote products derived from this software\n//      without specific prior written permission.\n// \n// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED\n// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO\n// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\n// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \n// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\n// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n// \n///////////////////////////////////////////////////////////////////////////////\n\n#ifndef _MSC_VER // [\n#error \"Use this header only with Microsoft Visual C++ compilers!\"\n#endif // _MSC_VER ]\n\n#ifndef _MSC_STDINT_H_ // [\n#define _MSC_STDINT_H_\n\n#if _MSC_VER > 1000\n#pragma once\n#endif\n\n#if _MSC_VER >= 1600 // [\n#include <stdint.h>\n#else // ] _MSC_VER >= 1600 [\n\n#include <limits.h>\n\n// For Visual Studio 6 in C++ mode and for many Visual Studio versions when\n// compiling for ARM we should wrap <wchar.h> include with 'extern \"C++\" {}'\n// or compiler give many errors like this:\n//   error C2733: second C linkage of overloaded function 'wmemchr' not allowed\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n#  include <wchar.h>\n#ifdef __cplusplus\n}\n#endif\n\n// Define _W64 macros to mark types changing their size, like intptr_t.\n#ifndef _W64\n#  if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300\n#     define _W64 __w64\n#  else\n#     define _W64\n#  endif\n#endif\n\n\n// 7.18.1 Integer types\n\n// 7.18.1.1 Exact-width integer types\n\n// Visual Studio 6 and Embedded Visual C++ 4 doesn't\n// realize that, e.g. char has the same size as __int8\n// so we give up on __intX for them.\n#if (_MSC_VER < 1300)\n   typedef signed char       int8_t;\n   typedef signed short      int16_t;\n   typedef signed int        int32_t;\n   typedef unsigned char     uint8_t;\n   typedef unsigned short    uint16_t;\n   typedef unsigned int      uint32_t;\n#else\n   typedef signed __int8     int8_t;\n   typedef signed __int16    int16_t;\n   typedef signed __int32    int32_t;\n   typedef unsigned __int8   uint8_t;\n   typedef unsigned __int16  uint16_t;\n   typedef unsigned __int32  uint32_t;\n#endif\ntypedef signed __int64       int64_t;\ntypedef unsigned __int64     uint64_t;\n\n\n// 7.18.1.2 Minimum-width integer types\ntypedef int8_t    int_least8_t;\ntypedef int16_t   int_least16_t;\ntypedef int32_t   int_least32_t;\ntypedef int64_t   int_least64_t;\ntypedef uint8_t   uint_least8_t;\ntypedef uint16_t  uint_least16_t;\ntypedef uint32_t  uint_least32_t;\ntypedef uint64_t  uint_least64_t;\n\n// 7.18.1.3 Fastest minimum-width integer types\ntypedef int8_t    int_fast8_t;\ntypedef int16_t   int_fast16_t;\ntypedef int32_t   int_fast32_t;\ntypedef int64_t   int_fast64_t;\ntypedef uint8_t   uint_fast8_t;\ntypedef uint16_t  uint_fast16_t;\ntypedef uint32_t  uint_fast32_t;\ntypedef uint64_t  uint_fast64_t;\n\n// 7.18.1.4 Integer types capable of holding object pointers\n#ifdef _WIN64 // [\n   typedef signed __int64    intptr_t;\n   typedef unsigned __int64  uintptr_t;\n#else // _WIN64 ][\n   typedef _W64 signed int   intptr_t;\n   typedef _W64 unsigned int uintptr_t;\n#endif // _WIN64 ]\n\n// 7.18.1.5 Greatest-width integer types\ntypedef int64_t   intmax_t;\ntypedef uint64_t  uintmax_t;\n\n\n// 7.18.2 Limits of specified-width integer types\n\n#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [   See footnote 220 at page 257 and footnote 221 at page 259\n\n// 7.18.2.1 Limits of exact-width integer types\n#define INT8_MIN     ((int8_t)_I8_MIN)\n#define INT8_MAX     _I8_MAX\n#define INT16_MIN    ((int16_t)_I16_MIN)\n#define INT16_MAX    _I16_MAX\n#define INT32_MIN    ((int32_t)_I32_MIN)\n#define INT32_MAX    _I32_MAX\n#define INT64_MIN    ((int64_t)_I64_MIN)\n#define INT64_MAX    _I64_MAX\n#define UINT8_MAX    _UI8_MAX\n#define UINT16_MAX   _UI16_MAX\n#define UINT32_MAX   _UI32_MAX\n#define UINT64_MAX   _UI64_MAX\n\n// 7.18.2.2 Limits of minimum-width integer types\n#define INT_LEAST8_MIN    INT8_MIN\n#define INT_LEAST8_MAX    INT8_MAX\n#define INT_LEAST16_MIN   INT16_MIN\n#define INT_LEAST16_MAX   INT16_MAX\n#define INT_LEAST32_MIN   INT32_MIN\n#define INT_LEAST32_MAX   INT32_MAX\n#define INT_LEAST64_MIN   INT64_MIN\n#define INT_LEAST64_MAX   INT64_MAX\n#define UINT_LEAST8_MAX   UINT8_MAX\n#define UINT_LEAST16_MAX  UINT16_MAX\n#define UINT_LEAST32_MAX  UINT32_MAX\n#define UINT_LEAST64_MAX  UINT64_MAX\n\n// 7.18.2.3 Limits of fastest minimum-width integer types\n#define INT_FAST8_MIN    INT8_MIN\n#define INT_FAST8_MAX    INT8_MAX\n#define INT_FAST16_MIN   INT16_MIN\n#define INT_FAST16_MAX   INT16_MAX\n#define INT_FAST32_MIN   INT32_MIN\n#define INT_FAST32_MAX   INT32_MAX\n#define INT_FAST64_MIN   INT64_MIN\n#define INT_FAST64_MAX   INT64_MAX\n#define UINT_FAST8_MAX   UINT8_MAX\n#define UINT_FAST16_MAX  UINT16_MAX\n#define UINT_FAST32_MAX  UINT32_MAX\n#define UINT_FAST64_MAX  UINT64_MAX\n\n// 7.18.2.4 Limits of integer types capable of holding object pointers\n#ifdef _WIN64 // [\n#  define INTPTR_MIN   INT64_MIN\n#  define INTPTR_MAX   INT64_MAX\n#  define UINTPTR_MAX  UINT64_MAX\n#else // _WIN64 ][\n#  define INTPTR_MIN   INT32_MIN\n#  define INTPTR_MAX   INT32_MAX\n#  define UINTPTR_MAX  UINT32_MAX\n#endif // _WIN64 ]\n\n// 7.18.2.5 Limits of greatest-width integer types\n#define INTMAX_MIN   INT64_MIN\n#define INTMAX_MAX   INT64_MAX\n#define UINTMAX_MAX  UINT64_MAX\n\n// 7.18.3 Limits of other integer types\n\n#ifdef _WIN64 // [\n#  define PTRDIFF_MIN  _I64_MIN\n#  define PTRDIFF_MAX  _I64_MAX\n#else  // _WIN64 ][\n#  define PTRDIFF_MIN  _I32_MIN\n#  define PTRDIFF_MAX  _I32_MAX\n#endif  // _WIN64 ]\n\n#define SIG_ATOMIC_MIN  INT_MIN\n#define SIG_ATOMIC_MAX  INT_MAX\n\n#ifndef SIZE_MAX // [\n#  ifdef _WIN64 // [\n#     define SIZE_MAX  _UI64_MAX\n#  else // _WIN64 ][\n#     define SIZE_MAX  _UI32_MAX\n#  endif // _WIN64 ]\n#endif // SIZE_MAX ]\n\n// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>\n#ifndef WCHAR_MIN // [\n#  define WCHAR_MIN  0\n#endif  // WCHAR_MIN ]\n#ifndef WCHAR_MAX // [\n#  define WCHAR_MAX  _UI16_MAX\n#endif  // WCHAR_MAX ]\n\n#define WINT_MIN  0\n#define WINT_MAX  _UI16_MAX\n\n#endif // __STDC_LIMIT_MACROS ]\n\n\n// 7.18.4 Limits of other integer types\n\n#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [   See footnote 224 at page 260\n\n// 7.18.4.1 Macros for minimum-width integer constants\n\n#define INT8_C(val)  val##i8\n#define INT16_C(val) val##i16\n#define INT32_C(val) val##i32\n#define INT64_C(val) val##i64\n\n#define UINT8_C(val)  val##ui8\n#define UINT16_C(val) val##ui16\n#define UINT32_C(val) val##ui32\n#define UINT64_C(val) val##ui64\n\n// 7.18.4.2 Macros for greatest-width integer constants\n// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>.\n// Check out Issue 9 for the details.\n#ifndef INTMAX_C //   [\n#  define INTMAX_C   INT64_C\n#endif // INTMAX_C    ]\n#ifndef UINTMAX_C //  [\n#  define UINTMAX_C  UINT64_C\n#endif // UINTMAX_C   ]\n\n#endif // __STDC_CONSTANT_MACROS ]\n\n#endif // _MSC_VER >= 1600 ]\n\n#endif // _MSC_STDINT_H_ ]\n"
  },
  {
    "path": "vs/turbob64avx.c",
    "content": "#include  \"turbob64v128.c\"\r\n"
  },
  {
    "path": "vs/vs2022/TB64App.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project DefaultTargets=\"Build\" ToolsVersion=\"15.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <ItemGroup Label=\"ProjectConfigurations\">\r\n    <ProjectConfiguration Include=\"Debug|Win32\">\r\n      <Configuration>Debug</Configuration>\r\n      <Platform>Win32</Platform>\r\n    </ProjectConfiguration>\r\n    <ProjectConfiguration Include=\"Debug|x64\">\r\n      <Configuration>Debug</Configuration>\r\n      <Platform>x64</Platform>\r\n    </ProjectConfiguration>\r\n    <ProjectConfiguration Include=\"Release|Win32\">\r\n      <Configuration>Release</Configuration>\r\n      <Platform>Win32</Platform>\r\n    </ProjectConfiguration>\r\n    <ProjectConfiguration Include=\"Release|x64\">\r\n      <Configuration>Release</Configuration>\r\n      <Platform>x64</Platform>\r\n    </ProjectConfiguration>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <ClCompile Include=\"..\\..\\tb64app.c\" />\r\n    <ClCompile Include=\"..\\getopt.c\" />\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <ProjectReference Include=\"TurboBase64.vcxproj\">\r\n      <Project>{a162f37f-183f-4250-88ab-9b9fbde30b04}</Project>\r\n    </ProjectReference>\r\n  </ItemGroup>\r\n  <PropertyGroup Label=\"Globals\">\r\n    <VCProjectVersion>15.0</VCProjectVersion>\r\n    <ProjectGuid>{6876BEB8-2B45-48B9-8381-1D4094FE8868}</ProjectGuid>\r\n    <Keyword>Win32Proj</Keyword>\r\n    <RootNamespace>TB64App</RootNamespace>\r\n    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\r\n    <ProjectName>TB64App</ProjectName>\r\n  </PropertyGroup>\r\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\r\n    <ConfigurationType>Application</ConfigurationType>\r\n    <UseDebugLibraries>true</UseDebugLibraries>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\r\n    <ConfigurationType>Application</ConfigurationType>\r\n    <UseDebugLibraries>true</UseDebugLibraries>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\r\n    <ConfigurationType>Application</ConfigurationType>\r\n    <UseDebugLibraries>false</UseDebugLibraries>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\r\n    <ConfigurationType>Application</ConfigurationType>\r\n    <UseDebugLibraries>false</UseDebugLibraries>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n  </PropertyGroup>\r\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\r\n  <ImportGroup Label=\"ExtensionSettings\">\r\n  </ImportGroup>\r\n  <ImportGroup Label=\"Shared\">\r\n  </ImportGroup>\r\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n  </ImportGroup>\r\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"PropertySheets\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n  </ImportGroup>\r\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n  </ImportGroup>\r\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"PropertySheets\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n  </ImportGroup>\r\n  <PropertyGroup Label=\"UserMacros\" />\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\r\n    <LinkIncremental>true</LinkIncremental>\r\n    <OutDir>$(SolutionDir)msvc.build\\$(Platform)-$(Configuration)\\</OutDir>\r\n    <IntDir>$(SolutionDir)msvc.build\\.obj\\$(Platform)-$(Configuration)-$(ProjectName)\\</IntDir>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\r\n    <LinkIncremental>true</LinkIncremental>\r\n    <OutDir>$(SolutionDir)msvc.build\\$(Platform)-$(Configuration)\\</OutDir>\r\n    <IntDir>$(SolutionDir)msvc.build\\.obj\\$(Platform)-$(Configuration)-$(ProjectName)\\</IntDir>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\r\n    <LinkIncremental>false</LinkIncremental>\r\n    <OutDir>$(SolutionDir)msvc.build\\$(Platform)-$(Configuration)\\</OutDir>\r\n    <IntDir>$(SolutionDir)msvc.build\\.obj\\$(Platform)-$(Configuration)-$(ProjectName)\\</IntDir>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\r\n    <LinkIncremental>false</LinkIncremental>\r\n    <OutDir>$(SolutionDir)msvc.build\\$(Platform)-$(Configuration)\\</OutDir>\r\n    <IntDir>$(SolutionDir)msvc.build\\.obj\\$(Platform)-$(Configuration)-$(ProjectName)\\</IntDir>\r\n  </PropertyGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\r\n    <ClCompile>\r\n      <Optimization>Disabled</Optimization>\r\n      <SDLCheck>true</SDLCheck>\r\n      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <ConformanceMode>true</ConformanceMode>\r\n      <AdditionalOptions>/w24146 /w24133 /w24996</AdditionalOptions>\r\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r\n      <EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>\r\n      <AdditionalIncludeDirectories>vs</AdditionalIncludeDirectories>\r\n      <ExceptionHandling>false</ExceptionHandling>\r\n    </ClCompile>\r\n    <Link>\r\n      <SubSystem>Console</SubSystem>\r\n      <GenerateDebugInformation>true</GenerateDebugInformation>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\r\n    <ClCompile>\r\n      <Optimization>Disabled</Optimization>\r\n      <SDLCheck>true</SDLCheck>\r\n      <PreprocessorDefinitions>CODEC2;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <ConformanceMode>true</ConformanceMode>\r\n      <AdditionalOptions>/w24146 /w24133 /w24996</AdditionalOptions>\r\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r\n      <EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>\r\n      <AdditionalIncludeDirectories>..\\..\\ext</AdditionalIncludeDirectories>\r\n    </ClCompile>\r\n    <Link>\r\n      <SubSystem>Console</SubSystem>\r\n      <GenerateDebugInformation>true</GenerateDebugInformation>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\r\n    <ClCompile>\r\n      <Optimization>MaxSpeed</Optimization>\r\n      <FunctionLevelLinking>true</FunctionLevelLinking>\r\n      <IntrinsicFunctions>true</IntrinsicFunctions>\r\n      <SDLCheck>true</SDLCheck>\r\n      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <ConformanceMode>true</ConformanceMode>\r\n      <AdditionalOptions>/w24146 /w24133 /w24996</AdditionalOptions>\r\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r\n      <EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>\r\n      <AdditionalIncludeDirectories>..\\..\\ext</AdditionalIncludeDirectories>\r\n    </ClCompile>\r\n    <Link>\r\n      <SubSystem>Console</SubSystem>\r\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r\n      <OptimizeReferences>true</OptimizeReferences>\r\n      <GenerateDebugInformation>true</GenerateDebugInformation>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\r\n    <ClCompile>\r\n      <Optimization>MaxSpeed</Optimization>\r\n      <FunctionLevelLinking>true</FunctionLevelLinking>\r\n      <IntrinsicFunctions>true</IntrinsicFunctions>\r\n      <SDLCheck>true</SDLCheck>\r\n      <PreprocessorDefinitions>CODEC2;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <ConformanceMode>true</ConformanceMode>\r\n      <AdditionalOptions>/w24146 /w24133 /w24996</AdditionalOptions>\r\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r\n      <EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>\r\n      <AdditionalIncludeDirectories>..\\..\\ext</AdditionalIncludeDirectories>\r\n    </ClCompile>\r\n    <Link>\r\n      <SubSystem>Console</SubSystem>\r\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r\n      <OptimizeReferences>true</OptimizeReferences>\r\n      <GenerateDebugInformation>true</GenerateDebugInformation>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\r\n  <ImportGroup Label=\"ExtensionTargets\">\r\n  </ImportGroup>\r\n</Project>"
  },
  {
    "path": "vs/vs2022/TurboBase64.sln",
    "content": "﻿\r\nMicrosoft Visual Studio Solution File, Format Version 12.00\r\n# Visual Studio 15\r\nVisualStudioVersion = 15.0.28307.757\r\nMinimumVisualStudioVersion = 10.0.40219.1\r\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"TurboBase64\", \"TurboBase64.vcxproj\", \"{A162F37F-183F-4250-88AB-9B9FBDE30B04}\"\r\nEndProject\r\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"TB64App\", \"TB64App.vcxproj\", \"{6876BEB8-2B45-48B9-8381-1D4094FE8868}\"\r\nEndProject\r\nGlobal\r\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n\t\tDebug|x64 = Debug|x64\r\n\t\tDebug|x86 = Debug|x86\r\n\t\tRelease|x64 = Release|x64\r\n\t\tRelease|x86 = Release|x86\r\n\tEndGlobalSection\r\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n\t\t{A162F37F-183F-4250-88AB-9B9FBDE30B04}.Debug|x64.ActiveCfg = Debug|x64\r\n\t\t{A162F37F-183F-4250-88AB-9B9FBDE30B04}.Debug|x64.Build.0 = Debug|x64\r\n\t\t{A162F37F-183F-4250-88AB-9B9FBDE30B04}.Debug|x86.ActiveCfg = Debug|Win32\r\n\t\t{A162F37F-183F-4250-88AB-9B9FBDE30B04}.Debug|x86.Build.0 = Debug|Win32\r\n\t\t{A162F37F-183F-4250-88AB-9B9FBDE30B04}.Release|x64.ActiveCfg = Release|x64\r\n\t\t{A162F37F-183F-4250-88AB-9B9FBDE30B04}.Release|x64.Build.0 = Release|x64\r\n\t\t{A162F37F-183F-4250-88AB-9B9FBDE30B04}.Release|x86.ActiveCfg = Release|Win32\r\n\t\t{A162F37F-183F-4250-88AB-9B9FBDE30B04}.Release|x86.Build.0 = Release|Win32\r\n\t\t{6876BEB8-2B45-48B9-8381-1D4094FE8868}.Debug|x64.ActiveCfg = Debug|x64\r\n\t\t{6876BEB8-2B45-48B9-8381-1D4094FE8868}.Debug|x64.Build.0 = Debug|x64\r\n\t\t{6876BEB8-2B45-48B9-8381-1D4094FE8868}.Debug|x86.ActiveCfg = Debug|Win32\r\n\t\t{6876BEB8-2B45-48B9-8381-1D4094FE8868}.Debug|x86.Build.0 = Debug|Win32\r\n\t\t{6876BEB8-2B45-48B9-8381-1D4094FE8868}.Release|x64.ActiveCfg = Release|x64\r\n\t\t{6876BEB8-2B45-48B9-8381-1D4094FE8868}.Release|x64.Build.0 = Release|x64\r\n\t\t{6876BEB8-2B45-48B9-8381-1D4094FE8868}.Release|x86.ActiveCfg = Release|Win32\r\n\t\t{6876BEB8-2B45-48B9-8381-1D4094FE8868}.Release|x86.Build.0 = Release|Win32\r\n\tEndGlobalSection\r\n\tGlobalSection(SolutionProperties) = preSolution\r\n\t\tHideSolutionNode = FALSE\r\n\tEndGlobalSection\r\n\tGlobalSection(ExtensibilityGlobals) = postSolution\r\n\t\tSolutionGuid = {A02524FA-10E2-4E1C-BE79-0AE7B077D2CE}\r\n\tEndGlobalSection\r\nEndGlobal\r\n"
  },
  {
    "path": "vs/vs2022/TurboBase64.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Project DefaultTargets=\"Build\" ToolsVersion=\"15.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\r\n  <ItemGroup Label=\"ProjectConfigurations\">\r\n    <ProjectConfiguration Include=\"Debug|Win32\">\r\n      <Configuration>Debug</Configuration>\r\n      <Platform>Win32</Platform>\r\n    </ProjectConfiguration>\r\n    <ProjectConfiguration Include=\"Debug|x64\">\r\n      <Configuration>Debug</Configuration>\r\n      <Platform>x64</Platform>\r\n    </ProjectConfiguration>\r\n    <ProjectConfiguration Include=\"Release|Win32\">\r\n      <Configuration>Release</Configuration>\r\n      <Platform>Win32</Platform>\r\n    </ProjectConfiguration>\r\n    <ProjectConfiguration Include=\"Release|x64\">\r\n      <Configuration>Release</Configuration>\r\n      <Platform>x64</Platform>\r\n    </ProjectConfiguration>\r\n  </ItemGroup>\r\n  <ItemGroup>\r\n    <ClCompile Include=\"..\\..\\turbob64v256.c\">\r\n      <PreprocessorDefinitions Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">__SSE__;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX__;__AVX2__;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <PreprocessorDefinitions Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">__SSE__;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX2__;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <EnableEnhancedInstructionSet Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">AdvancedVectorExtensions2</EnableEnhancedInstructionSet>\r\n    </ClCompile>\r\n    <ClCompile Include=\"..\\..\\turbob64c.c\">\r\n      <EnableEnhancedInstructionSet Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">NotSet</EnableEnhancedInstructionSet>\r\n      <EnableEnhancedInstructionSet Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">NotSet</EnableEnhancedInstructionSet>\r\n    </ClCompile>\r\n    <ClCompile Include=\"..\\..\\turbob64d.c\">\r\n      <EnableEnhancedInstructionSet Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">NotSet</EnableEnhancedInstructionSet>\r\n      <EnableEnhancedInstructionSet Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">NotSet</EnableEnhancedInstructionSet>\r\n    </ClCompile>\r\n    <ClCompile Include=\"..\\..\\turbob64v128.c\">\r\n      <PreprocessorDefinitions Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">__SSE__;__SSE2__;__SSE3__;__SSSE3__;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <PreprocessorDefinitions Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">__SSE__;__SSE2__;__SSE3__;__SSSE3__;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <EnableEnhancedInstructionSet Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">NotSet</EnableEnhancedInstructionSet>\r\n      <EnableEnhancedInstructionSet Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">NotSet</EnableEnhancedInstructionSet>\r\n    </ClCompile>\r\n    <ClCompile Include=\"..\\..\\turbob64v512.c\">\r\n      <PreprocessorDefinitions Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">__SSE__;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__,__AVX2__,__AVX512VBMI__;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <EnableEnhancedInstructionSet Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">AdvancedVectorExtensions512</EnableEnhancedInstructionSet>\r\n      <EnableEnhancedInstructionSet Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">AdvancedVectorExtensions512</EnableEnhancedInstructionSet>\r\n    </ClCompile>\r\n    <ClCompile Include=\"..\\turbob64avx.c\">\r\n      <PreprocessorDefinitions Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">__SSE__;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX__;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <PreprocessorDefinitions Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">__SSE__;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;__AVX__;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <EnableEnhancedInstructionSet Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">AdvancedVectorExtensions</EnableEnhancedInstructionSet>\r\n      <EnableEnhancedInstructionSet Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">AdvancedVectorExtensions</EnableEnhancedInstructionSet>\r\n    </ClCompile>\r\n  </ItemGroup>\r\n  <PropertyGroup Label=\"Globals\">\r\n    <VCProjectVersion>15.0</VCProjectVersion>\r\n    <ProjectGuid>{A162F37F-183F-4250-88AB-9B9FBDE30B04}</ProjectGuid>\r\n    <Keyword>Win32Proj</Keyword>\r\n    <RootNamespace>TurboBase64</RootNamespace>\r\n    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\r\n    <ProjectName>TurboBase64</ProjectName>\r\n  </PropertyGroup>\r\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\r\n    <ConfigurationType>StaticLibrary</ConfigurationType>\r\n    <UseDebugLibraries>true</UseDebugLibraries>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\r\n    <ConfigurationType>StaticLibrary</ConfigurationType>\r\n    <UseDebugLibraries>true</UseDebugLibraries>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\r\n    <ConfigurationType>StaticLibrary</ConfigurationType>\r\n    <UseDebugLibraries>false</UseDebugLibraries>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\r\n    <ConfigurationType>StaticLibrary</ConfigurationType>\r\n    <UseDebugLibraries>false</UseDebugLibraries>\r\n    <PlatformToolset>v143</PlatformToolset>\r\n  </PropertyGroup>\r\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\r\n  <ImportGroup Label=\"ExtensionSettings\">\r\n  </ImportGroup>\r\n  <ImportGroup Label=\"Shared\">\r\n  </ImportGroup>\r\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n  </ImportGroup>\r\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"PropertySheets\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n  </ImportGroup>\r\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n  </ImportGroup>\r\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"PropertySheets\">\r\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\r\n  </ImportGroup>\r\n  <PropertyGroup Label=\"UserMacros\" />\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\r\n    <LinkIncremental>true</LinkIncremental>\r\n    <IntDir>$(SolutionDir)msvc.build\\.obj\\$(Platform)-$(Configuration)-$(ProjectName)\\</IntDir>\r\n    <OutDir>$(SolutionDir)msvc.build\\$(Platform)-$(Configuration)\\</OutDir>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\r\n    <LinkIncremental>true</LinkIncremental>\r\n    <IntDir>$(SolutionDir)msvc.build\\.obj\\$(Platform)-$(Configuration)-$(ProjectName)\\</IntDir>\r\n    <OutDir>$(SolutionDir)msvc.build\\$(Platform)-$(Configuration)\\</OutDir>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\r\n    <LinkIncremental>false</LinkIncremental>\r\n    <IntDir>$(SolutionDir)msvc.build\\.obj\\$(Platform)-$(Configuration)-$(ProjectName)\\</IntDir>\r\n    <OutDir>$(SolutionDir)msvc.build\\$(Platform)-$(Configuration)\\</OutDir>\r\n  </PropertyGroup>\r\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\r\n    <LinkIncremental>false</LinkIncremental>\r\n    <IntDir>$(SolutionDir)msvc.build\\.obj\\$(Platform)-$(Configuration)-$(ProjectName)\\</IntDir>\r\n    <OutDir>$(SolutionDir)msvc.build\\$(Platform)-$(Configuration)\\</OutDir>\r\n  </PropertyGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\r\n    <ClCompile>\r\n      <Optimization>MaxSpeed</Optimization>\r\n      <SDLCheck>true</SDLCheck>\r\n      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <ConformanceMode>true</ConformanceMode>\r\n      <EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>\r\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r\n      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r\n      <AdditionalOptions>/w24003 /w24005 /w24028 /w24047 /w24090 /w24133 /w24146 /w24333 /w24789 %(AdditionalOptions)</AdditionalOptions>\r\n      <AdditionalIncludeDirectories>..\\..</AdditionalIncludeDirectories>\r\n      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>\r\n      <ExceptionHandling>false</ExceptionHandling>\r\n      <FloatingPointModel>Fast</FloatingPointModel>\r\n      <BasicRuntimeChecks>Default</BasicRuntimeChecks>\r\n    </ClCompile>\r\n    <Link>\r\n      <SubSystem>Console</SubSystem>\r\n      <GenerateDebugInformation>true</GenerateDebugInformation>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\r\n    <ClCompile>\r\n      <Optimization>Disabled</Optimization>\r\n      <SDLCheck>true</SDLCheck>\r\n      <PreprocessorDefinitions>__SSE__;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;USE_SSE;USE_AVX2;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <ConformanceMode>true</ConformanceMode>\r\n      <EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>\r\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\r\n      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r\n      <AdditionalOptions>/w24003 /w24005 /w24028 /w24047 /w24090 /w24133 /w24146 /w24333 /w24789 %(AdditionalOptions)</AdditionalOptions>\r\n      <AdditionalIncludeDirectories>..\\..</AdditionalIncludeDirectories>\r\n    </ClCompile>\r\n    <Link>\r\n      <SubSystem>Console</SubSystem>\r\n      <GenerateDebugInformation>true</GenerateDebugInformation>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\r\n    <ClCompile>\r\n      <Optimization>MaxSpeed</Optimization>\r\n      <FunctionLevelLinking>true</FunctionLevelLinking>\r\n      <IntrinsicFunctions>false</IntrinsicFunctions>\r\n      <SDLCheck>true</SDLCheck>\r\n      <PreprocessorDefinitions>__SSE__;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;USE_SSE;USE_AVX2;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <ConformanceMode>true</ConformanceMode>\r\n      <EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>\r\n      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>\r\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r\n      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r\n      <AdditionalOptions>/w24003 /w24005 /w24028 /w24047 /w24090 /w24133 /w24146 /w24333 /w24789 %(AdditionalOptions)</AdditionalOptions>\r\n      <AdditionalIncludeDirectories>..\\..</AdditionalIncludeDirectories>\r\n    </ClCompile>\r\n    <Link>\r\n      <SubSystem>Console</SubSystem>\r\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r\n      <OptimizeReferences>true</OptimizeReferences>\r\n      <GenerateDebugInformation>true</GenerateDebugInformation>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\r\n    <ClCompile>\r\n      <Optimization>MaxSpeed</Optimization>\r\n      <FunctionLevelLinking>true</FunctionLevelLinking>\r\n      <IntrinsicFunctions>true</IntrinsicFunctions>\r\n      <SDLCheck>true</SDLCheck>\r\n      <PreprocessorDefinitions>__SSE__;__SSE2__;__SSE3__;__SSSE3__;__SSE4_1__;__SSE4_2__;USE_SSE;USE_AVX2;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r\n      <ConformanceMode>true</ConformanceMode>\r\n      <EnableEnhancedInstructionSet>AdvancedVectorExtensions2</EnableEnhancedInstructionSet>\r\n      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>\r\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\r\n      <MultiProcessorCompilation>true</MultiProcessorCompilation>\r\n      <AdditionalOptions>/w24003 /w24005 /w24028 /w24047 /w24090 /w24133 /w24146 /w24333 /w24789 %(AdditionalOptions)</AdditionalOptions>\r\n      <AdditionalIncludeDirectories>..\\..</AdditionalIncludeDirectories>\r\n    </ClCompile>\r\n    <Link>\r\n      <SubSystem>Console</SubSystem>\r\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\r\n      <OptimizeReferences>true</OptimizeReferences>\r\n      <GenerateDebugInformation>true</GenerateDebugInformation>\r\n    </Link>\r\n  </ItemDefinitionGroup>\r\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\r\n  <ImportGroup Label=\"ExtensionTargets\">\r\n  </ImportGroup>\r\n</Project>"
  }
]