[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to write optimized code for an instruction set not supported by my computer?



On Fri, Nov 6, 2015 at 7:33 AM, Mario Castelán Castro
<marioxcc.MT@yandex.com> wrote:
> Hello.
>
> What is the usual workflow to write code that takes advantage of an
> instruction set that is not present in my computer

You're asking one question here.

> (either in assembly or
> using intrinsic functions that represent those instructions in an higher
> level language)?.

You're asking a different question here.

> For example, if I want to write code for decoding and
> encoding Base64 that uses AVX instructions

You're beggin a question here, and I will ask it --

Why on earth would you want to go to the bother of using AVX
instructions for working with Base64?

And the answer to that question is that you have something else you
want to do and you are using Base64 as a MacGuffin. Which is not a
problem for me, but might be a problem for you.

The question being begged is this -- Do you really want to use AVX
enough to sign the Intel agreement that you can't read unless you
agree to it before you read it so you can download it and read it?

It *is* a valid question, and I can't tell you the answer to that.
Maybe you can't answer that question yourself yet.

> in my machine that has no support
> for any version of AVX (only SSE 4.2 and CLMUL), what is the recommended
> workflow?.

The real workflow is that, if you have real reason (not Base64, of
course), you get the hardware now. And you trust Intel not to ask for
your first-born son (speaking figuratively) and sign the agreement and
use their emulator.

Both.

Running the emulator on hardware that can actually run the
instructions is a very useful debugging tool to help you debug your
understanding of the instruction set. (Writing your own emulator can
help, as well, but it may not be worth the time investment.)

> It seems like I *could* develop within a virtual machine emulated with Bochs
> that supports these instructions, but that would give a very big overhead,
> since I would have to emulate a whole system, and Bochs has no
> multithreading support (so that will make it less efficient if I want to
> write multithreaded code).

There are several ways to support multithreading in emulation. Well,
we can say two main ways --

Write it yourself (in other words, as co-operative multi-tasking in
the emulator core code, and some support routines to make it appear
pre-emptive multi-processing to the running application).

Or, let the OS handle it (in other words, someone else has already
written the co-operative part and hopefully mapped it to actual OS
calls that can give both the appearance and advantages of
multi-processing).

> Is there a better option?

>From what the others have said about AVX, if you need to use for
something real (not Base64, of course), you're going ot have to roll
up your sleeves and do some of the grunt work yourself.

If you really do mean Base64 (in other words, if you just want to play
or this is a homework project or something), well, you have to decide
whether you want to trust Intel and sign their agreement and download
their emulator just to play or do a homework assignment or something.

And maybe, once you have real specs in your hands, write your own
emulator to help you cut through the sales talk in the specs. (Bochs
or QEMU might help you at this step.)

And expect that what you learn will only be partly applicable in the real world.

> Regards and thanks in advance.
>

Hope that helps.

-- 
Joel Rees

Be careful when you look at conspiracy.
Arm yourself with knowledge of yourself, as well:
http://reiisi.blogspot.jp/2011/10/conspiracy-theories.html


Reply to: