Revision ec9a41f5

View differences:

libavcodec/i386/dsputil_mmx.c
1082 1082
    }
1083 1083
}
1084 1084

  
1085
#else // TESTCPU_MAIN
1086
/*
1087
 * for testing speed of various routine - should be probably extended
1088
 * for a general purpose regression test later
1089
 *
1090
 * for now use it this way:
1091
 *
1092
 * gcc -O4 -fomit-frame-pointer -DHAVE_AV_CONFIG_H -DTESTCPU_MAIN  -I../.. -o test dsputil_mmx.c
1093
 *
1094
 * in libavcodec/i386 directory - then run ./test
1095
 */
1096
static inline long long rdtsc()
1097
{
1098
    long long l;
1099
    asm volatile(   "rdtsc\n\t"
1100
		    : "=A" (l)
1101
		);
1102
    return l;
1103
}
1104

  
1105
int main(int argc, char* argv[])
1106
{
1107
    volatile int v;
1108
    int i;
1109
    const int linesize = 720;
1110
    char empty[32768];
1111
    uint64_t te, ts = rdtsc();
1112
    char* im, *bu = empty;
1113
    op_pixels_func fc = put_pixels_y2_mmx2;
1114
    bu += 32;
1115
    bu =(char*)(((long)bu) & ~0xf); // 16 bytes alignment
1116
    im = bu;
1117
    for(i=0; i<1000000; i++){
1118
	fc(im, im + 1000, linesize, 16);
1119
	im += 4; //
1120
	if (im > bu + 10000)
1121
            im = bu;
1122
    }
1123
    te = rdtsc();
1124
    printf("CPU Ticks: %7d\n", (int)(te - ts));
1125
}
1126 1085
#endif
tests/Makefile
36 36
audiogen: audiogen.c
37 37
	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $<
38 38

  
39
DSPDEPS = $(SRC_PATH)/libavcodec/i386/dsputil_mmx.c \
40
 $(SRC_PATH)/libavcodec/i386/dsputil_mmx_avg.h 
41

  
42
dsptest: dsptest.c $(DSPDEPS)
43
	$(CC) -O4 -fomit-frame-pointer -DHAVE_AV_CONFIG_H -I.. -I$(SRC_PATH)/libavcodec/i386 -I$(SRC_PATH)/libavcodec/ -o $@ $<
44

  
39 45
clean:
40 46
	rm -rf vsynth1
41 47
	rm -f asynth1.sw *~ audiogen videogen
tests/dsptest.c
1
/*
2
 * MMX optimized DSP utils
3
 * Copyright (c) 2000, 2001 Gerard Lantau.
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
 *
19
 */
20

  
21
#define TESTCPU_MAIN
22
#include "dsputil.h"
23
#include "../libavcodec/i386/cputest.c"
24
#include "../libavcodec/i386/dsputil_mmx.c"
25
#undef TESTCPU_MAIN
26

  
27
#define PAD 0x10000
28
/*
29
 * for testing speed of various routine - should be probably extended
30
 * for a general purpose regression test later
31
 *
32
 * currently only for i386 - FIXME
33
 */
34
static const struct pix_func {
35
    char* name;
36
    op_pixels_func func;
37
    int mm_flags;
38
} pix_func[] = {
39
    { "put_pixels_x2_mmx", put_pixels_y2_mmx, MM_MMX },
40
    { "put_pixels_x2_3dnow", put_pixels_y2_3dnow, MM_3DNOW },
41
    { "put_pixels_x2_mmx2", put_pixels_y2_mmx2, MM_MMXEXT | PAD },
42

  
43
    { "put_no_rnd_pixels_x2_mmx", put_no_rnd_pixels_x2_mmx, MM_MMX },
44
    { "put_no_rnd_pixels_x2_3dnow", put_no_rnd_pixels_x2_3dnow, MM_3DNOW },
45
    { "put_no_rnd_pixels_x2_mmx2", put_no_rnd_pixels_x2_mmx2, MM_MMXEXT | PAD },
46

  
47
    { "put_pixels_y2_mmx", put_pixels_y2_mmx, MM_MMX },
48
    { "put_pixels_y2_3dnow", put_pixels_y2_3dnow, MM_3DNOW },
49
    { "put_pixels_y2_mmx2", put_pixels_y2_mmx2, MM_MMXEXT | PAD },
50
    { 0, 0 }
51
};
52

  
53
static inline long long rdtsc()
54
{
55
    long long l;
56
    asm volatile(   "rdtsc\n\t"
57
		    : "=A" (l)
58
		);
59
    return l;
60
}
61

  
62
static test_speed(int step)
63
{
64
    const struct pix_func* pix = pix_func;
65
    const int linesize = 720;
66
    char empty[32768];
67
    char* bu =(char*)(((long)empty + 32) & ~0xf);
68

  
69
    while (pix->name)
70
    {
71
	int i;
72
        uint64_t te, ts;
73
        op_pixels_func func = pix->func;
74
	char* im = bu;
75

  
76
	if (!(pix->mm_flags & mm_flags))
77
            continue;
78

  
79
	printf("%30s... ", pix->name);
80
        fflush(stdout);
81
	ts = rdtsc();
82
	for(i=0; i<100000; i++){
83
	    func(im, im + 1000, linesize, 16);
84
	    im += step;
85
	    if (im > bu + 20000)
86
		im = bu;
87
	}
88
	te = rdtsc();
89
        emms();
90
	printf("% 9d\n", (int)(te - ts));
91
	if (pix->mm_flags & PAD)
92
            puts("");
93
        pix++;
94
    }
95
}
96

  
97
int main(int argc, char* argv[])
98
{
99
    int step = 16;
100

  
101
    if (argc > 1)
102
    {
103
        // something simple for now
104
	if (argc > 2 && (strcmp("-s", argv[1]) == 0
105
			 || strcmp("-step", argv[1]) == 0))
106
            step = atoi(argv[2]);
107
    }
108

  
109
    mm_flags = mm_support();
110
    printf("dsptest: CPU flags:");
111
    if (mm_flags & MM_MMX)
112
        printf(" mmx");
113
    if (mm_flags & MM_MMXEXT)
114
        printf(" mmxext");
115
    if (mm_flags & MM_3DNOW)
116
        printf(" 3dnow");
117
    if (mm_flags & MM_SSE)
118
        printf(" sse");
119
    if (mm_flags & MM_SSE2)
120
        printf(" sse2");
121
    printf("\n");
122

  
123
    printf("Using step: %d\n", step);
124
    test_speed(step);
125
}

Also available in: Unified diff