⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testvmx.c

📁 The Valgrind distribution has multiple tools. The most popular is the memory checking tool (called M
💻 C
📖 第 1 页 / 共 5 页
字号:
/* HOW TO COMPILE:     gcc -O -g -Wall -maltivec -mabi=altivec -DALTIVEC -DGCC_COMPILER          testVMX.c -o testVMX*//* * testVMX - A test program to check the correctness of VMX instructions *  * Copyright (C) 2004 CEPBA-IBM Research Institute *  * Authors: Jose Maria Cela, Raul de la Cruz, *          Rogeli Grima, Xavier Saez <blade_support@ciri.upc.es> * * Web page: http://www.ciri.upc.es/cela_pblade/ *  * This file is part of testVMX. *  * testVMX is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * testVMX is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with testVMX; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  US *//* * Version 0.2.2 2004/09/02 * Removed some not useful flags for compilation and changed the GPL license * header updating the contact email and adding the web page URL * * Version 0.2.1 2004/07/07 * Some flags added in Makefile for XLC compilation (-qalias, -qinline) * * Version 0.2 2004/07/02 * Makefile and testVMX.c patched to compile with SLES 9 (Linux - GCC 3.3.3), * IBM XLC Enterprise Edition and MacOS X 10.3 (Darwin - GCC 3.3) * * Version 0.1 2004/03/05 * First public version release */#include <stdio.h>#include <stdlib.h>#include <math.h>#include <limits.h>#include <string.h>/* Calloc for align data to 16 bytes boundaries *//* ----------- BEGIN #include "memoryVector.h" ----------- *//* * testVMX - A test program to check the correctness of VMX instructions *  * Copyright (C) 2004 CEPBA-IBM Research Institute *  * Authors: Jose Maria Cela, Raul de la Cruz, *          Rogeli Grima, Xavier Saez <blade_support@ciri.upc.es> * * Web page: http://www.ciri.upc.es/cela_pblade/ *  * This file is part of testVMX. *  * testVMX is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * testVMX is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with testVMX; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  US */#ifndef MEMORY_VECTOR_H# define MEMORY_VECTOR_H# include <stdlib.h>  void *calloc_vec( size_t nmemb, size_t size );  void  free_vec( void *ptr );#endif/* ----------- END #include "memoryVector.h" ----------- *//* ----------- BEGIN #include "memoryVector.c" ----------- *//* * testVMX - A test program to check the correctness of VMX instructions *  * Copyright (C) 2004 CEPBA-IBM Research Institute *  * Authors: Jose Maria Cela, Raul de la Cruz, *          Rogeli Grima, Xavier Saez <blade_support@ciri.upc.es> * * Web page: http://www.ciri.upc.es/cela_pblade/ *  * This file is part of testVMX. *  * testVMX is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * testVMX is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with testVMX; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  US */#include <stdio.h>#include <string.h>/* #include "memoryVector.h"*/typedef struct        {          char  *realAdd;          char  *returnAdd;        } Tmemtab;static Tmemtab *memTab    = NULL;static size_t   nadd      =   0;static size_t   MAX_N_ADD = 100;void *calloc_vec( size_t nmemb, size_t size ){/* ---------------------------------------------------------- Local Variables */    char   *realadd;    char   *retadd;    size_t  nbytes, cc, rr;/* -------------------------------------------------------------------- BEGIN */  if (memTab == (Tmemtab*)NULL)  {    memTab = (Tmemtab *) malloc( MAX_N_ADD*sizeof(Tmemtab) );    if (memTab == (Tmemtab*)NULL)    {      fprintf(stderr, "\n------------ FATAL ERRROR ------------------\n");      fprintf(stderr, "Memory table out of memory\n");      return NULL;     }  }  /* 16 extra bytes are allocated for adjust alignement */  nbytes = (size*nmemb)+16;  /* Alloc a block of 'nbytes' */  realadd = (char *) malloc( nbytes );  if (realadd == (char *)NULL)  {      fprintf(stderr, "\n------------ FATAL ERRROR ------------------\n");      fprintf(stderr, "Out of memory\n");      return NULL;  }  memset( realadd, 0, nbytes );  cc = ((size_t)realadd)/16;  rr = ((size_t)realadd)%16;  if (rr == 0)    retadd = realadd;  else    retadd = (char *)((cc+1)*16);  if (nadd == MAX_N_ADD)  {    MAX_N_ADD += 100;    memTab = (Tmemtab*) realloc( memTab, MAX_N_ADD*sizeof(Tmemtab) );    if (memTab == (Tmemtab*)NULL)    {      free( realadd );      fprintf(stderr, "\n------------ FATAL ERRROR ------------------\n");      fprintf(stderr, "Memory table out of memory\n");      return NULL;     }  }  memTab[nadd].realAdd   =  realadd;  memTab[nadd].returnAdd =  retadd;;  nadd++;  return (void*)retadd;/* ---------------------------------------------------------------------- END */}void free_vec( void *ptr ){/* ---------------------------------------------------------- Local Variables */  int ii, pos;/* -------------------------------------------------------------------- BEGIN */  pos = -1;  for (ii= 0; ii< nadd; ii++)    if (memTab[ii].returnAdd == ptr)    {      pos = ii;      break;    }  if (pos == -1)  {      fprintf(stderr, "\n------------ WARNING ------------------------\n");      fprintf(stderr, "Pointer not found in memory table\n\n");  }  else  {    free( memTab[ii].realAdd );    for (ii= pos+1; ii< nadd; ii++)      memTab[ii-1] = memTab[ii];    nadd--;    if (nadd == 0)    {      free( memTab );      memTab    = NULL;      MAX_N_ADD = 100;    }  }/* ---------------------------------------------------------------------- END */}/* ----------- END #include "memoryVector.c" ----------- */#ifdef ALTIVEC# ifdef GCC_COMPILER#  include <altivec.h># endif//#define TEST_FLOATS/* Redefinition for undefined NAN and xlC compiling C++ code */# if !defined(NAN) || ( defined(__IBMCPP__) && defined(XLC_COMPILER) )#  undef   NAN#  define  NAN 0x7FC00000/* #  define  NAN 0xFFFA5A5A * #  define  NAN 0x80000000  * #  define  NAN 0x00008000  */# endifint part1( );int part2( );int part3( );int part4( );int part5( );typedef union{   vector signed char    v;   signed char           e[16];} TvecChar;typedef union{   vector unsigned char  v;   unsigned char         e[16];} TvecUChar;typedef union{   vector bool char      v;   unsigned char         e[16];} TvecBChar;typedef union{   vector signed short   v;   signed short          e[8];} TvecShort;typedef union{   vector unsigned short v;   unsigned short        e[8];} TvecUShort;typedef union{   vector bool short     v;   unsigned short        e[8];} TvecBShort;typedef union{   vector signed int     v;   signed int            e[4];} TvecInt;typedef union{   vector unsigned int   v;   unsigned int          e[4];} TvecUInt;typedef union{   vector bool int       v;   unsigned int          e[4];} TvecBInt;#if defined TEST_FLOATStypedef union{   vector float          v;   float                 e[4];   signed int            i[4];} TvecFloat;#endif/* Scalar bool types declaration */typedef unsigned char   TboolChar;typedef unsigned short  TboolShort;typedef unsigned int    TboolInt;#endif/********************************************************************** Main() **********************************************************************/int main(){  TvecChar      Caux1,  Caux2,  Caux3;//,  Caux4;  TvecUChar     UCaux1, UCaux2, UCaux3;//, UCaux4;  TvecBChar     BCaux1;//, BCaux2, BCaux3, BCaux4;  TvecShort     Saux1,  Saux2,  Saux3;//,  Saux4;  TvecUShort    USaux1, USaux2, USaux3;//, USaux4;  TvecBShort    BSaux1;//, BSaux2, BSaux3, BSaux4;  TvecInt       Iaux1,  Iaux2,  Iaux3;//,  Iaux4;  TvecUInt      UIaux1, UIaux2, UIaux3;//, UIaux4;  TvecBInt      BIaux1;//, BIaux2, BIaux3, BIaux4;#if defined TEST_FLOATS  TvecFloat     Faux1,  Faux2,  Faux3;//,  Faux4;#endif      int                  i, err, j;//, b, bAux;#if defined TEST_FLOATS  int                  b;  signed   int         Ivec1, Ivec2, Ivec3;#endif//  unsigned char        *UCvec1;//  signed   short       *Svec1;//  unsigned short       *USvec1;//  unsigned int         *UIvec1;#if defined TEST_FLOATS//  float                *Fvec1;#endif  /* For saturated rutines *///  long long int         LLaux;  signed   char         Caux;  unsigned char         UCaux;  signed   short        Saux;  unsigned short        USaux;  signed   int          Iaux;//, I1, I2;  unsigned int          UIaux;//, UI1, UI2;#if defined TEST_FLOATS  float                 Faux;#endif    /* Scalar bool types definition */  TboolChar             BCaux;  TboolShort            BSaux;  TboolInt              BIaux;/*  union  {    float          f;    signed   int   si;    unsigned int   ui;    signed   short ss[2];    unsigned short us[2];    signed   char  sc[4];    unsigned char  uc[4];  } INTunion1, INTunion2;  union  {    signed   short  ss;    unsigned short  us;    signed   char   sc[2];    unsigned char   uc[2];  } SHOunion1, SHOunion2;*/#if defined (GCC_COMPILER)  vector signed char    Ccons1   = (vector signed char){-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7};  vector signed char    Ccons2   = (vector signed char){1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};  vector signed char    Ccons3   = (vector signed char){-128, 127, -128, 127, -128, 127, -128, 127, -128, 127, -128, 127, -128, 127, -128, 127};  vector unsigned char  UCcons1  = (vector unsigned char){248, 249, 250, 251, 252, 253, 254, 255, 0, 1, 2, 3, 4, 5, 6, 7};  vector unsigned char  UCcons2  = (vector unsigned char){2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};  vector unsigned char  UCcons3  = (vector unsigned char){1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8};  vector signed short   Scons1   = (vector signed short){-4, -3, -2, -1, 0, 1, 2, 3};  vector signed short   Scons2   = (vector signed short){-32768, 10000, 1, 1, 1, 1, -10000, -10000};  vector signed short   Scons3   = (vector signed short){-32768, 32767, -32768, 32767, -32768, 32767, -32768, 32767};  vector unsigned short UScons1  = (vector unsigned short){65532, 65533, 65534, 65535, 0, 1, 2, 3};  vector unsigned short UScons2  = (vector unsigned short){1, 1, 1, 1, 1, 1, 1, 1};  vector unsigned short UScons3  = (vector unsigned short){1, 2, 3, 4, 1, 2, 3, 4};  vector signed int     Icons1   = (vector signed int){-4, -1, 1, 4};  vector signed int     Icons2   = (vector signed int){1, 1, 1, 1};  vector signed int     Icons3   = (vector signed int){0x80000000, 0x7FFFFFFF, 0x80000000, 0x7FFFFFFF};  vector unsigned int   UIcons1  = (vector unsigned int){0xFFFFFFFE, 0xFFFFFFFF, 0, 1};  vector unsigned int   UIcons2  = (vector unsigned int){1, 1, 1, 1};  vector unsigned int   UIcons3  = (vector unsigned int){1, 2, 1, 2};#if defined TEST_FLOATS  vector float          Fcons1   = (vector float){-1.5, 1.0, 0.5, -3.999};  vector float          Fcons2   = (vector float){1.0, 1.0, 1.0, 1.0};  vector float          Fcons3   = (vector float){100000000000.0, 1.0, -1.0, -1234567890.0};#endif#elif defined (MAC_COMPILER) || defined (XLC_COMPILER)  vector signed char    Ccons1   = (vector signed char)(-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7);  vector signed char    Ccons2   = (vector signed char)(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);  vector signed char    Ccons3   = (vector signed char)(-128, 127, -128, 127, -128, 127, -128, 127, -128, 127, -128, 127, -128, 127, -128, 127);  vector unsigned char  UCcons1  = (vector unsigned char)(248, 249, 250, 251, 252, 253, 254, 255, 0, 1, 2, 3, 4, 5, 6, 7);  vector unsigned char  UCcons2  = (vector unsigned char)(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2);  vector unsigned char  UCcons3  = (vector unsigned char)(1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8);  vector signed short   Scons1   = (vector signed short)(-4, -3, -2, -1, 0, 1, 2, 3);  vector signed short   Scons2   = (vector signed short)(-32768, 10000, 1, 1, 1, 1, -10000, -10000);  vector signed short   Scons3   = (vector signed short)(-32768, 32767, -32768, 32767, -32768, 32767, -32768, 32767);  vector unsigned short UScons1  = (vector unsigned short)(65532, 65533, 65534, 65535, 0, 1, 2, 3);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -