File: memcpy.c

package info (click to toggle)
zapping 0.10~cvs6-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,856 kB
  • ctags: 11,841
  • sloc: ansic: 111,154; asm: 11,770; sh: 9,812; xml: 2,742; makefile: 1,283; perl: 488
file content (95 lines) | stat: -rw-r--r-- 2,303 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 *  Copyright (C) 2004 Michael H. Schimek
 *
 *  This program 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.
 *
 *  This program 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* $Id: memcpy.c,v 1.5 2005/06/28 01:09:44 mschimek Exp $ */

#undef NDEBUG

#include <inttypes.h>
#include <string.h>
#include "libtv/image_format.h"
#include "libtv/cpu.h"

#include "guard.h"

static uint8_t *		sbuffer;
static uint8_t *		sbuffer_end;
static uint8_t *		dbuffer;
static uint8_t *		dbuffer_end;

static void
test1				(uint8_t *		dst,
				 uint8_t *		src,
				 unsigned int		n_bytes)
{
	unsigned int i;
	unsigned int size;
	uint8_t *p;

	memset (dbuffer, 0xAA, dbuffer_end - dbuffer);

	size = sbuffer_end - sbuffer;
	for (i = 0; i < size; ++i)
		sbuffer[i] = i;

	tv_memcpy (dst, src, n_bytes);

	for (p = dbuffer; p < dst;)
		assert (0xAA == *p++);

	for (i = 0; i < n_bytes; ++i)
		assert (*p++ == *src++);

	while (p < dbuffer_end)
		assert (0xAA == *p++);
}

int
main				(int			argc,
				 char **		argv)
{
	unsigned int buffer_size;
	unsigned int i;

	buffer_size = 64 << 10;

	sbuffer = guard_alloc (buffer_size);
	sbuffer_end = sbuffer + buffer_size;

	dbuffer = guard_alloc (buffer_size);
	dbuffer_end = dbuffer + buffer_size;

	/* Use generic version. */
	cpu_features = (cpu_feature_set) 0;

	if (argc > 1) {
		/* Use optimized version, if available. */
		cpu_features = cpu_feature_set_from_string (argv[1]);
	}

	for (i = 0; i < 33; ++i) {
		test1 (dbuffer, sbuffer, i);
		test1 (dbuffer, sbuffer, i + 16384);
		test1 (dbuffer_end - i, sbuffer_end - i, i);
		test1 (dbuffer_end - i - 16384,
		       sbuffer_end - i - 16384, i + 16384);
		test1 (dbuffer + i, sbuffer + (i ^ 31), i * 3);
	}

	return EXIT_SUCCESS;
}