Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
tests
MemsetTest.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2011 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#include "
src/core/SkMemset.h
"
9
#include "
tests/Test.h
"
10
11
#include <cstddef>
12
#include <cstdint>
13
14
static
void
set_zero
(
void
* dst,
size_t
bytes) {
15
char
* ptr = (
char
*)dst;
16
for
(
size_t
i = 0; i < bytes; ++i) {
17
ptr[i] = 0;
18
}
19
}
20
21
#define MAX_ALIGNMENT 64
22
#define MAX_COUNT ((MAX_ALIGNMENT) * 32)
23
#define PAD 32
24
#define TOTAL (PAD + MAX_ALIGNMENT + MAX_COUNT + PAD)
25
26
#define VALUE16 0x1234
27
#define VALUE32 0x12345678
28
29
static
void
compare16
(
skiatest::Reporter
* r,
const
uint16_t
base
[],
30
uint16_t value,
int
count
) {
31
for
(
int
i = 0; i <
count
; ++i) {
32
if
(
base
[i] !=
value
) {
33
ERRORF
(r,
"[%d] expected %x found %x\n"
, i,
value
,
base
[i]);
34
return
;
35
}
36
}
37
}
38
39
static
void
compare32
(
skiatest::Reporter
* r,
const
uint32_t
base
[],
40
uint32_t value,
int
count
) {
41
for
(
int
i = 0; i <
count
; ++i) {
42
if
(
base
[i] !=
value
) {
43
ERRORF
(r,
"[%d] expected %x found %x\n"
, i,
value
,
base
[i]);
44
return
;
45
}
46
}
47
}
48
49
static
void
test_16
(
skiatest::Reporter
*
reporter
) {
50
uint16_t
buffer
[
TOTAL
];
51
52
for
(
int
count
= 0;
count
<
MAX_COUNT
; ++
count
) {
53
for
(
int
alignment = 0; alignment <
MAX_ALIGNMENT
; ++alignment) {
54
set_zero
(
buffer
,
sizeof
(
buffer
));
55
56
uint16_t*
base
= &
buffer
[
PAD
+ alignment];
57
SkOpts::memset16
(
base
,
VALUE16
,
count
);
58
59
compare16
(
reporter
,
buffer
, 0,
PAD
+ alignment);
60
compare16
(
reporter
,
base
,
VALUE16
,
count
);
61
compare16
(
reporter
,
base
+
count
, 0,
TOTAL
-
count
-
PAD
- alignment);
62
}
63
}
64
}
65
66
static
void
test_32
(
skiatest::Reporter
*
reporter
) {
67
uint32_t
buffer
[
TOTAL
];
68
69
for
(
int
count
= 0;
count
<
MAX_COUNT
; ++
count
) {
70
for
(
int
alignment = 0; alignment <
MAX_ALIGNMENT
; ++alignment) {
71
set_zero
(
buffer
,
sizeof
(
buffer
));
72
73
uint32_t*
base
= &
buffer
[
PAD
+ alignment];
74
SkOpts::memset32
(
base
,
VALUE32
,
count
);
75
76
compare32
(
reporter
,
buffer
, 0,
PAD
+ alignment);
77
compare32
(
reporter
,
base
,
VALUE32
,
count
);
78
compare32
(
reporter
,
base
+
count
, 0,
TOTAL
-
count
-
PAD
- alignment);
79
}
80
}
81
}
82
83
/**
84
* Test SkOpts::memset16 and SkOpts::memset32.
85
* For performance considerations, implementations may take different paths
86
* depending on the alignment of the dst, and/or the size of the count.
87
*/
88
DEF_TEST
(Memset,
reporter
) {
89
test_16
(
reporter
);
90
test_32
(
reporter
);
91
}
reporter
reporter
Definition
FontMgrTest.cpp:39
count
int count
Definition
FontMgrTest.cpp:50
PAD
#define PAD
Definition
MemsetTest.cpp:23
test_32
static void test_32(skiatest::Reporter *reporter)
Definition
MemsetTest.cpp:66
MAX_ALIGNMENT
#define MAX_ALIGNMENT
Definition
MemsetTest.cpp:21
test_16
static void test_16(skiatest::Reporter *reporter)
Definition
MemsetTest.cpp:49
compare16
static void compare16(skiatest::Reporter *r, const uint16_t base[], uint16_t value, int count)
Definition
MemsetTest.cpp:29
VALUE16
#define VALUE16
Definition
MemsetTest.cpp:26
compare32
static void compare32(skiatest::Reporter *r, const uint32_t base[], uint32_t value, int count)
Definition
MemsetTest.cpp:39
set_zero
static void set_zero(void *dst, size_t bytes)
Definition
MemsetTest.cpp:14
MAX_COUNT
#define MAX_COUNT
Definition
MemsetTest.cpp:22
VALUE32
#define VALUE32
Definition
MemsetTest.cpp:27
TOTAL
#define TOTAL
Definition
MemsetTest.cpp:24
SkMemset.h
Test.h
DEF_TEST
#define DEF_TEST(name, reporter)
Definition
Test.h:312
ERRORF
#define ERRORF(r,...)
Definition
Test.h:293
skiatest::Reporter
Definition
Test.h:58
buffer
static const uint8_t buffer[]
Definition
fl_pixel_buffer_texture_test.cc:44
value
uint8_t value
Definition
fl_standard_message_codec.cc:36
SkOpts::memset16
void(* memset16)(uint16_t[], uint16_t, int)
SkOpts::memset32
void(* memset32)(uint32_t[], uint32_t, int)
base
Definition
ax_tree_id_registry.h:17
Generated on Fri Apr 26 2024 06:17:47 for Flutter Engine by
1.9.8