Giter Club home page Giter Club logo

Comments (7)

BurningEnlightenment avatar BurningEnlightenment commented on July 3, 2024

Sadly there isn't any built in function like

int base64_codec_supported(int flags);

but you can indirectly check for codec support by calling base64_decode with the appropriate flags and build a little helper function on top of that as demonstrated in test/codec_supported.c. The relevant snippet:

int base64ex_codec_supported(int flags)
{
    // Check if given codec is supported by trying to decode a test string:
    char a[] = "aGVsbG8=";
    char b[10];
    size_t outlen;

    return (base64_decode(a, sizeof(a)-1, b, &outlen, flags) != -1);
}

use it like so:

if (base64ex_codec_supported(BASE64_FORCE_AVX2))
{
     /*...*/
} 

from base64.

WojciechMula avatar WojciechMula commented on July 3, 2024

It is a really good solution, thank you for help.

from base64.

aklomp avatar aklomp commented on July 3, 2024

You should probably not be using the FORCE flags, they're mainly for testing purposes. On x86, the library should auto-detect at runtime the best compiled-in codec for the current platform. That code should do the right thing; if not, please file a bug!

This library is built for performance and portability. The idea is that this library could in principle be distributed in compiled binary form as a Debian package or so. This means that the capabilities of the target machine are unknown at compile time. To be portable but still get the best performance, this library does a number of runtime checks to determine the SIMD support level of the architecture it's running on, and chooses the best available codec, once, at runtime. The checking code (in codec_choose.c) is built without architecture-specific compiler flags, so that it will run on any generic machine.

So the idea is that you should build with the maximum SIMD level your compiler will support, and rely on runtime feature detection to determine the actual codec that the machine will run. If you don't want to rely on our platform detection, you can bypass it with the FORCE flags, but then it's on you to do proper fallback on older machines.

To get a list of built-in codecs, @BurningEnlightenment's solution is currently the correct one. You basically request some work from a codec and see if it returns an error. Maybe this should be a proper API call, since the test harness already has a use for this functionality...

from base64.

WojciechMula avatar WojciechMula commented on July 3, 2024

@aklomp The solution suggested by @BurningEnlightenment seems perfect, but in the end I won't use FORCE flags.

BTW I would suggest to get rid of FORCE flags at all. Instead an extra procedure base64_setup_coded could be available to change codec in runtime. Such procedure could be even enabled by some compile-time definition, as it's intended for tests as you said.

from base64.

BurningEnlightenment avatar BurningEnlightenment commented on July 3, 2024

So the idea is that you should build with the maximum SIMD level your compiler will support, and rely on runtime feature detection to determine the actual codec that the machine will run.

Is there actually an use case where you would want to exclude one of the codecs? If not I'm tempted to replace the user options in #7 with some detection logic...

from base64.

aklomp avatar aklomp commented on July 3, 2024

Well, the basic idea is that you compile for the best case, and fall back to what is available. Sorry if I didn't word this clearly in #7 or the README. (Pull requests welcome :)
You might want to exclude a codec if your compiler does not have proper support for it (e.g. GCC 4.6 miscompiled NEON64), but in that case you could just... not pass in the architecture flags. Also, this library does not do runtime detection on ARM (it's complicated), so on that platform, you do have to choose at compile time.

from base64.

WojciechMula avatar WojciechMula commented on July 3, 2024

@aklomp OK, thanks for the explanation. Please close the issue.

BTW, your library was included in a pretty big project, it replaced our in-house code.

from base64.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.