[  gcc и asm - Форум ]

 

Гость



Дата: 17.05.2024
День недели: Пятница
Время на сайте:10:05
Ваш IP:18.226.222.89
 

 

 Поиск по  форуму



  • Страница 1 из 1
  • 1
Форум » Форум » SSE,MMX,3DNow » gcc и asm (пример использования ассемблерных интсрукций в gcc и g++)

gcc и asm

 *
earn   Дата: 12.02.2010 11:31
Вот пример реально работаюшей програмки))

Code


#include <iostream>
#include <stdio.h>
#include <time.h>
#include <math.h>

using namespace std;

#define muls_arr(at,bt,ct)    \
     __asm__ __volatile__   \
            (     \
                    "movups (%[a]), %%xmm0 \n\t"    \
                    "movups (%[b]), %%xmm1 \n\t"    \
                    "mulps  %%xmm1, %%xmm0 \n\t"    \
                    "movups %%xmm0, %[c] \n\t"    \
                    : [c] "=m" (*ct)  \
                    : [a] "r" (at), [b] "r" (bt)    \
     )     \

#define copy_vec(at,bt)    \
     __asm__ __volatile__   \
            (     \
                    "movups (%[a]), %%xmm0 \n\t"    \
                    "movups %%xmm0, %[c]   \n\t"    \
                    : [c] "=m" (*bt)  \
                    : [a] "r" (at)                  \
     )     \

#define one_vec(at)     \
     __asm__ __volatile__   \
            (     \
                    "movups (%[a]),%%xmm0  \n\t"    \
                    "divps %%xmm0,%%xmm0  \n\t"     \
      "movups %%xmm0, %[b]   \n\t"    \
                    : [b] "=m" (*at)  \
                    : [a] "r"  (at)                 \
     )     \

#define norm_vec_old(v,n)     \
     __asm__ __volatile__   \
            (     \
                    "movaps (%[a]),%%xmm7     \n\t"    \
          \
      "shufps $0,%%xmm7,%%xmm0     \n\t" \
          \
      "shufps $1,%%xmm7,%%xmm1 \n\t" \
          \
      "movaps %%xmm7,%%xmm2     \n\t" \
      "shufps $2,%%xmm2,%%xmm2 \n\t" \
          \
      "mulss  %%xmm0,%%xmm0    \n\t" /* a^2 */ \
      "mulss  %%xmm1,%%xmm1    \n\t" /* b^2 */ \
      "mulss  %%xmm2,%%xmm2    \n\t" /* c^2 */ \
                       \
      "addss    %%xmm1,%%xmm0  \n\t"  \
      "addss    %%xmm2,%%xmm0  \n\t" /* a^2+b^2+c^2*/ \
          \
      "sqrtss %%xmm0,%%xmm0    \n\t"  \
          \
      "movss  (%[n]),%%xmm3   \n\t"\
      "divss  %%xmm0,%%xmm3  \n\t" /*xmm3=1.0/L*/ \
          \
      /*"shufps $0,%%xmm3,%%xmm3 \n\t" */\
          \
      /*"mulps    %%xmm3,%%xmm7     \n\t" */\
          \
      "movups %%xmm1, %[b]      \n\t"    \
                    : [b] "=m" (v)   \
                    : [a] "r"  (v) , [n] "r" (&n)  /*(0x3f800000) =1.0*/ \
     )     \

#define norm_vec(at,bt,n)          \
     __asm__ __volatile__   \
            (     \
                    "movups (%[a]), %%xmm7 \n\t"    \
          \
      "movaps  %%xmm7,%%xmm0     \n\t"\
      "shufps $0,%%xmm0,%%xmm0   \n\t"\
          \
      "movaps  %%xmm7,%%xmm1     \n\t"\
      "shufps $85,%%xmm1,%%xmm1   \n\t"\
          \
      "movaps  %%xmm7,%%xmm2     \n\t"\
      "shufps $170,%%xmm2,%%xmm2   \n\t"\
          \
          \
      "mulss  %%xmm0,%%xmm0    \n\t" /* a^2 */ \
      "mulss  %%xmm1,%%xmm1    \n\t" /* b^2 */ \
      "mulss  %%xmm2,%%xmm2    \n\t" /* c^2 */ \
                 \
      "addss    %%xmm1,%%xmm0  \n\t"  \
      "addss    %%xmm2,%%xmm0  \n\t" /* a^2+b^2+c^2*/ \
          \
      "sqrtss %%xmm0,%%xmm0    \n\t"  \
          \
      "movss  (%[n]),%%xmm3   \n\t"   \
      "divss  %%xmm0,%%xmm3  \n\t" /*xmm3=1.0/L*/ \
          \
      "shufps $0,%%xmm3,%%xmm3 \n\t"  \
          \
      "mulps    %%xmm3,%%xmm7     \n\t" \
      "movups %%xmm7, %[c]   \n\t"    \
          \
                    : [c] "=m" (*bt)  \
                    : [a] "r" (at), [n] "r" (&n)    \
     )     \

void norm_v(float *v,float *v1)
        {
        float q1=v[0];
        float q2=v[1];
        float q3=v[2];
        float l=sqrtf(q1*q1+q2*q2+q3*q3);
        float l1=1.0f/l;
          
            
        v1[0]=q1*l1;
        v1[1]=q2*l1;
        v1[2]=q3*l1;
        v1[3]=v[0];
            
        }     

int main() {
            float* aa = new float[4];
            float* bb = new float[4];
            float* cc = new float[4];
     float a[4] __attribute__ (( aligned(16)));
     float  n = 1.0;
            for(int i = 0; i<4; i++)
            {
                    aa[i] = 1.1111111f+(0.11111111f)*(float)i;
                    a[i] = 2.11111111f+(0.111111111f)*(float)i;

                    bb[i] = 2.5f;
                    cc[i] = 0.0f;
            }

            
        time_t start,end;
         start = clock();

     for(int i = 0; i<30000000; i++)
            {

                
     //muls_arr(aa,bb,cc);
     //copy_vec(a,aa);
            //one_vec(aa);
     norm_vec(aa,a,n);
     //norm_v(aa,a);
     }
     cout << aa[0] << " " << aa[1] << " " << aa[2] << " " << aa[3] << endl;
     cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << endl;

            cout << bb[0] << " " << bb[1] << " " << bb[2] << " " << bb[3] << endl;
            cout << cc[0] << " " << cc[1] << " " << cc[2] << " " << cc[3] << endl;
         
      end=clock();     
     printf("time=%d\n",end-start);     
            return 0;     
     }

        //asm(".intel_syntax noprefix\n"); // turn ON sse2 comands movupd and other
        //asm(".att_syntax prefix");

лан с цветом пака касяк
а про инлайн асемблер я читал тут http://opennet.ru/base/dev/gccasm.txt.html


________________________________________________________



 *
earn   Дата: 12.02.2010 14:04
cool


________________________________________________________


 *
Relliqysmu   Дата: 21.06.2013 12:37
<b>Hermes Bag For Men</b>http://discounthermes.99rwad.com#dsfdgfdgfd The Hermes natural leather cases Comcast settlement pros significantly appreciates and is extremely well intentioned within disney world musical legacy. can easily Hermes Birkin affordable handbags costs we now have many talented middle management at walt disney world who else we just imagine is will also play a key perform in managing the packaged group. We will absolutely desired administrators inside mother board working with ourThe chicago, il Tribune scooped the storyline around midAugust, not to mention followups will need made an appearance documented in Trib, all of the connected marketing, MSNBC but at the neighbors. Govan's example has grown to become something of a cause clbre sending using a Hermes handbag start the rage americans extremely practical knowledge at inefficient and uncaring customer satisfaction so the other way round, it's a commuter lessons, based on it, will be certainly in truth Hermes handbag sales agreement not a way for fans to connect Hermes carrying cases whilst teams that you could possibly a more traditional get at university or college, places it's a university resort.


________________________________________________________


 *
AniaBed   Дата: 09.07.2013 17:51
Требуются авторы студенческих работ. Работа удаленно, оплата 2 раза в месяц. ОЧЕНЬ МНОГО ЗАКАЗОВ!!!
Подробнее на http://work.guland.ru/



________________________________________________________


 *
AniaBed   Дата: 11.07.2013 22:58
Требуются авторы студенческих работ. Работа удаленно, оплата 2 раза в месяц. ОЧЕНЬ МНОГО ЗАКАЗОВ!!!
Подробнее на http://work.guland.ru/



________________________________________________________


 *
Abrekcopy   Дата: 24.07.2013 17:00
<a href=http://www.goldchess.com/gdc/igra-v-shahmati.html>играть а шахматы</a> это развлечение для всех! На нашем портале Вы можете абсолютно бесплатно сыграть в шахматы с соперниками из более чем 100 стран мира.


________________________________________________________


 *
AleksLiaine   Дата: 05.11.2013 12:43
Шоппинг в Варшаве. Узнай, где цены на брендовые вещи дешевле на 40-80%, чем в торговых центрах. Подробнее у нас на сайте <a href=http://warsawoutletguide.pl/>warsawoutletguide.pl</a>


________________________________________________________


 *
Dwightboug   Дата: 07.02.2014 16:08
cialis 2.5 mg <a href=http://dstvmediasales.com/sitemap.php?farm=buy-viagra-tablets-online>buy viagra tablets online</a> cialis poppers http://dstvmediasales.com/sitemap.php?farm=cialis-loss-of-hearing - cialis loss of hearing silagra brand name viagra cumwithuscom http://www.rwuk.org/?product=generic-viagra-in-us - generic viagra in us propecia testicle pain swelling of the lips


________________________________________________________


 *
Dwightboug   Дата: 15.02.2014 08:32
viagra online buy uk <a href=http://www.rwuk.org/?product=cheap-kamagra-online-pharmacy>cheap kamagra online pharmacy</a> zithromax online prescription http://www.rwuk.org/?product=propecia-low-sperm-count-stopped - propecia low sperm count stopped cialis airport security http://www.rwuk.org/?product=propecia-how-to-take - propecia how to take kamagra to you

Добавлено (15.02.2014, 08:30)
---------------------------------------------
viagra online buy uk <a href=http://www.rwuk.org/?product=cheap-kamagra-online-pharmacy>cheap kamagra online pharmacy</a> zithromax online prescription http://www.rwuk.org/?product=propecia-low-sperm-count-stopped - propecia low sperm count stopped cialis airport security http://www.rwuk.org/?product=propecia-how-to-take - propecia how to take kamagra to you

Добавлено (15.02.2014, 08:30)
---------------------------------------------
viagra online buy uk <a href=http://www.rwuk.org/?product=cheap-kamagra-online-pharmacy>cheap kamagra online pharmacy</a> zithromax online prescription http://www.rwuk.org/?product=propecia-low-sperm-count-stopped - propecia low sperm count stopped cialis airport security http://www.rwuk.org/?product=propecia-how-to-take - propecia how to take kamagra to you

Добавлено (15.02.2014, 08:31)
---------------------------------------------
viagra online buy uk <a href=http://www.rwuk.org/?product=cheap-kamagra-online-pharmacy>cheap kamagra online pharmacy</a> zithromax online prescription http://www.rwuk.org/?product=propecia-low-sperm-count-stopped - propecia low sperm count stopped cialis airport security http://www.rwuk.org/?product=propecia-how-to-take - propecia how to take kamagra to you

Добавлено (15.02.2014, 08:31)
---------------------------------------------
viagra online buy uk <a href=http://www.rwuk.org/?product=cheap-kamagra-online-pharmacy>cheap kamagra online pharmacy</a> zithromax online prescription http://www.rwuk.org/?product=propecia-low-sperm-count-stopped - propecia low sperm count stopped cialis airport security http://www.rwuk.org/?product=propecia-how-to-take - propecia how to take kamagra to you

Добавлено (15.02.2014, 08:31)
---------------------------------------------
viagra online buy uk <a href=http://www.rwuk.org/?product=cheap-kamagra-online-pharmacy>cheap kamagra online pharmacy</a> zithromax online prescription http://www.rwuk.org/?product=propecia-low-sperm-count-stopped - propecia low sperm count stopped cialis airport security http://www.rwuk.org/?product=propecia-how-to-take - propecia how to take kamagra to you

Добавлено (15.02.2014, 08:31)
---------------------------------------------
viagra online buy uk <a href=http://www.rwuk.org/?product=cheap-kamagra-online-pharmacy>cheap kamagra online pharmacy</a> zithromax online prescription http://www.rwuk.org/?product=propecia-low-sperm-count-stopped - propecia low sperm count stopped cialis airport security http://www.rwuk.org/?product=propecia-how-to-take - propecia how to take kamagra to you

Добавлено (15.02.2014, 08:32)
---------------------------------------------
viagra online buy uk <a href=http://www.rwuk.org/?product=cheap-kamagra-online-pharmacy>cheap kamagra online pharmacy</a> zithromax online prescription http://www.rwuk.org/?product=propecia-low-sperm-count-stopped - propecia low sperm count stopped cialis airport security http://www.rwuk.org/?product=propecia-how-to-take - propecia how to take kamagra to you


________________________________________________________


Форум » Форум » SSE,MMX,3DNow » gcc и asm (пример использования ассемблерных интсрукций в gcc и g++)
  • Страница 1 из 1
  • 1
Поиск:
 

 

 

 

 

 Сайт управляется системой uCoz