[erlang-questions] Vector instructions
Tony Rogvall
tony@REDACTED
Tue Apr 8 06:12:02 CEST 2008
Hi!
>
> How about,
> %% <3.1415, 1.0>
> V1 = <<16#40, 16#49, 16#0E, 16#56, 16#3F, 16#80, 16#00, 16#00>>,
> %% <1.0, 1.6180>
> V2 = <<16#3F, 16#80, 16#00, 16#00, 16#3F, 16#CF, 16#1A, 16#9F>>,
> vec:add(single, V1, V2).
>
This is a more promising start! Today floats are allocated as separate
objects so there
is no way to use SIMD instructions on tuple with floats anyway!!!
>
> obviously V1 and V2 would normally be created with helper functions.
> The
> advantage of using binaries would be that you would have to add a new
> type to Erlang and could more easily do DSP functionality on an input
> stream, eg GSM codecs using for VOIP, before having to optimise with C
> or another lower language. The first parameter to vec:add/3 would be
> one
> of the atoms: single, double, octet, short, long, or longlong.
>
> What about matricies? list of binaries?
>
I suggest first to implement the operation(s) you showed, possibly
adding alignment support
to the allocation of the vectors since many SIMD instructions operates
best when given 16 bytes aligned
pointers. Rough code ahead ;-)
Future binary comprehension could use an updated syntax to handle this
in a neat way.
[ <<X+Y:32/float>> || <<X:32/float>> <- V1 ; <<Y:32/float>> <- V2 ]
Note that the expression X+Y must have a special treat and that ; in
this comprehension expression means
"parallel". This would basically be compiled to vec:add(single, V1,
V2).
/Tony
More information about the erlang-questions
mailing list