how to load array elements in MMX or SSE registers to do sum operation on them

75 Views Asked by At

I have the code bellow.

    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <string>
    #include <vector>
    #include <iterator>
    
    using namespace std;
  
    vector<int> &split(const string &s, char delim, vector<int> &elems) {
        stringstream ss(s);
        string item;
        while (getline(ss, item, delim)) {
            if (item.length() > 0) {
                elems.push_back(stoi(item));  
            }
        }
        return elems;
    }
    
    vector<int> split(const string &s, char delim) {
        vector<int> elems;
        split(s, delim, elems);
        return elems;
    }
    
    
    vector<int> negative(vector<int> elems){
        vector<int> results;
       for (auto &elem : elems){
           int temp = 255 - elem > 0 ? 255 - elem : 0 ;
           results.push_back(temp);
       }
        return results;
    }
    
    vector<int> negativeAssembly(vector<int> elems){
        vector<int> results;
        for (auto elem : elems){
            asm (
                "sub  $255, %[in1];"
                "neg %[out]"
                : [out] "=r" (elem)
                : [in1] "r" (elem)
            );
            results.push_back(elem);
        }
        return results;
    }
    
    int main(){
        vector<int> elems;
        ifstream infile("./image.txt");
        for( string line; getline(infile, line ); ){
            elems = split(line, ' ');
            elems = negativeAssembly(elems);
        }
        

return 0;
}

image.txt file contains:

0   1   5   8   12
6   250 50  40  35
80  45  34  18  87
123 13  165 250 80

Now I write Negative function that for each pixel count it's subtraction from 255.

Then I write the subtraction part with inline assembly in negativeAssembly function. but I need to convert the all operation in function to assembly with MMX or SSE registers. how can I do that, I'm really confused.

0

There are 0 best solutions below