LCOV - code coverage report
Current view: top level - libavutil/tests - cpu.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 35 42 83.3 %
Date: 2018-05-20 11:54:08 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This file is part of FFmpeg.
       3             :  *
       4             :  * FFmpeg is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Lesser General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2.1 of the License, or (at your option) any later version.
       8             :  *
       9             :  * FFmpeg is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Lesser General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public
      15             :  * License along with FFmpeg; if not, write to the Free Software
      16             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      17             :  */
      18             : 
      19             : #include <stdio.h>
      20             : 
      21             : #include "config.h"
      22             : 
      23             : #include "libavutil/cpu.h"
      24             : #include "libavutil/avstring.h"
      25             : 
      26             : #if HAVE_UNISTD_H
      27             : #include <unistd.h>
      28             : #endif
      29             : #if !HAVE_GETOPT
      30             : #include "compat/getopt.c"
      31             : #endif
      32             : 
      33             : static const struct {
      34             :     int flag;
      35             :     const char *name;
      36             : } cpu_flag_tab[] = {
      37             : #if   ARCH_AARCH64
      38             :     { AV_CPU_FLAG_ARMV8,     "armv8"      },
      39             :     { AV_CPU_FLAG_NEON,      "neon"       },
      40             :     { AV_CPU_FLAG_VFP,       "vfp"        },
      41             : #elif ARCH_ARM
      42             :     { AV_CPU_FLAG_ARMV5TE,   "armv5te"    },
      43             :     { AV_CPU_FLAG_ARMV6,     "armv6"      },
      44             :     { AV_CPU_FLAG_ARMV6T2,   "armv6t2"    },
      45             :     { AV_CPU_FLAG_VFP,       "vfp"        },
      46             :     { AV_CPU_FLAG_VFP_VM,    "vfp_vm"     },
      47             :     { AV_CPU_FLAG_VFPV3,     "vfpv3"      },
      48             :     { AV_CPU_FLAG_NEON,      "neon"       },
      49             :     { AV_CPU_FLAG_SETEND,    "setend"     },
      50             : #elif ARCH_PPC
      51             :     { AV_CPU_FLAG_ALTIVEC,   "altivec"    },
      52             : #elif ARCH_X86
      53             :     { AV_CPU_FLAG_MMX,       "mmx"        },
      54             :     { AV_CPU_FLAG_MMXEXT,    "mmxext"     },
      55             :     { AV_CPU_FLAG_SSE,       "sse"        },
      56             :     { AV_CPU_FLAG_SSE2,      "sse2"       },
      57             :     { AV_CPU_FLAG_SSE2SLOW,  "sse2slow"   },
      58             :     { AV_CPU_FLAG_SSE3,      "sse3"       },
      59             :     { AV_CPU_FLAG_SSE3SLOW,  "sse3slow"   },
      60             :     { AV_CPU_FLAG_SSSE3,     "ssse3"      },
      61             :     { AV_CPU_FLAG_ATOM,      "atom"       },
      62             :     { AV_CPU_FLAG_SSE4,      "sse4.1"     },
      63             :     { AV_CPU_FLAG_SSE42,     "sse4.2"     },
      64             :     { AV_CPU_FLAG_AVX,       "avx"        },
      65             :     { AV_CPU_FLAG_AVXSLOW,   "avxslow"    },
      66             :     { AV_CPU_FLAG_XOP,       "xop"        },
      67             :     { AV_CPU_FLAG_FMA3,      "fma3"       },
      68             :     { AV_CPU_FLAG_FMA4,      "fma4"       },
      69             :     { AV_CPU_FLAG_3DNOW,     "3dnow"      },
      70             :     { AV_CPU_FLAG_3DNOWEXT,  "3dnowext"   },
      71             :     { AV_CPU_FLAG_CMOV,      "cmov"       },
      72             :     { AV_CPU_FLAG_AVX2,      "avx2"       },
      73             :     { AV_CPU_FLAG_BMI1,      "bmi1"       },
      74             :     { AV_CPU_FLAG_BMI2,      "bmi2"       },
      75             :     { AV_CPU_FLAG_AESNI,     "aesni"      },
      76             :     { AV_CPU_FLAG_AVX512,    "avx512"     },
      77             : #endif
      78             :     { 0 }
      79             : };
      80             : 
      81           2 : static void print_cpu_flags(int cpu_flags, const char *type)
      82             : {
      83             :     int i;
      84             : 
      85           2 :     printf("cpu_flags(%s) = 0x%08X\n", type, cpu_flags);
      86           2 :     printf("cpu_flags_str(%s) =", type);
      87          50 :     for (i = 0; cpu_flag_tab[i].flag; i++)
      88          48 :         if (cpu_flags & cpu_flag_tab[i].flag)
      89          15 :             printf(" %s", cpu_flag_tab[i].name);
      90           2 :     printf("\n");
      91           2 : }
      92             : 
      93             : 
      94           1 : int main(int argc, char **argv)
      95             : {
      96           1 :     int cpu_flags_raw = av_get_cpu_flags();
      97             :     int cpu_flags_eff;
      98           1 :     int cpu_count = av_cpu_count();
      99           1 :     char threads[5] = "auto";
     100             :     int i;
     101             : 
     102          25 :     for(i = 0; cpu_flag_tab[i].flag; i++) {
     103          24 :         unsigned tmp = 0;
     104          24 :         if (av_parse_cpu_caps(&tmp, cpu_flag_tab[i].name) < 0) {
     105           0 :             fprintf(stderr, "Table missing %s\n", cpu_flag_tab[i].name);
     106           0 :             return 4;
     107             :         }
     108             :     }
     109             : 
     110           1 :     if (cpu_flags_raw < 0)
     111           0 :         return 1;
     112             : 
     113           2 :     for (;;) {
     114           3 :         int c = getopt(argc, argv, "c:t:");
     115           3 :         if (c == -1)
     116           1 :             break;
     117           2 :         switch (c) {
     118           1 :         case 'c':
     119             :         {
     120           1 :             unsigned flags = av_get_cpu_flags();
     121           1 :             if (av_parse_cpu_caps(&flags, optarg) < 0)
     122           0 :                 return 2;
     123             : 
     124           1 :             av_force_cpu_flags(flags);
     125           1 :             break;
     126             :         }
     127           1 :         case 't':
     128             :         {
     129           1 :             int len = av_strlcpy(threads, optarg, sizeof(threads));
     130           1 :             if (len >= sizeof(threads)) {
     131           0 :                 fprintf(stderr, "Invalid thread count '%s'\n", optarg);
     132           0 :                 return 2;
     133             :             }
     134             :         }
     135             :         }
     136             :     }
     137             : 
     138           1 :     cpu_flags_eff = av_get_cpu_flags();
     139             : 
     140           1 :     if (cpu_flags_eff < 0)
     141           0 :         return 3;
     142             : 
     143           1 :     print_cpu_flags(cpu_flags_raw, "raw");
     144           1 :     print_cpu_flags(cpu_flags_eff, "effective");
     145           1 :     printf("threads = %s (cpu_count = %d)\n", threads, cpu_count);
     146             : 
     147           1 :     return 0;
     148             : }

Generated by: LCOV version 1.13