Hi there,

I'm trying to write in-line assembly that clobbers an array in memory,
but unfortunately I have no idea how to do that. Here is a piece of code
from my program:

/*
There is OUTPUT_NODES arrays of 2 doubles. This code computes the
distance between each of those OUTPUT_NODES arrays found in the
network_t structure and the input array provided as an argument, too. It
then stores the results in the distance and do some other stuff with it
(this isn't shown in the code below).
*/

#define OUTPUT_NODES 10
#define INPUT_NODES 2
typedef struct
{

        double weight[OUTPUT_NODES][INPUT_NODES];

} network_t;
void fillDistance(double input[INPUT_NODES], network_t *network)
{
     double distance[OUTPUT_NODES];
     asm(
          "xorq %%rax, %%rax\n
\t"                                                 /*Clear rax*/
          "movupd %[input], %%xmm0
\n"                                      /*load the input vector in
xmm0*/
          "0:\t movupd (%[weights],%%rax,8), %%xmm1\n\t"       /* load
the first weight vector into xmm1*/
          "subpd %%xmm0, %%xmm1\n
\t"                                    /*subtract the two vectors */
          "mulpd %%xmm1,  %%xmm1\n
\t"                                   /*square the result*/
          "unpckhpd %%xmm1, %%xmm2\n
\t"                              /*bring the upper quadword of xmm1 in
the low quadword of xmm2*/
          "addpd %%xmm2, %%xmm1\n
\t"                                    /*add low quadword of xmm1 with
low quadword of xmm2(former high quadword of xmm1)*/
          "movupd %%xmm1, (%[distance],%%rax,4)\n\t"            /*store
the low quadword of xmm1 in the first elementof distance array*/
          "addq $2, %%rax\n
\t"                                                        /*since
scaling in x86 has a mximum of 8 and we are dealing with arrays of 2
doubles, we add 2 to rax and multiply the scale y 2*/
          "loop
0b" ::                                                                        
/*start with the next weight array and store its results in the next element of 
distance*/

     "c"(OUTPUT_NODES), [input]"m"(input), [weights]"r"(network->weights), 
[distance]"r"(distance) :

          "rax", "xmm0", "xmm1", "xmm2"
     );
     /* Do some other stuff with distance and then return */
}

My question is: how can I tell the compiler that I'm clobbering the
distance array. I couldn't just add "m" to the output list since the
compiler requires an lvalue to be specified.
_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to