2 * Copyright (c) 2005 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <machine/float.h>
32 /* Memory accesses. */
38 #define FloatingPoint 0x12
46 #define NoPostInc 0x31
47 #define MinConstPostInc 0x32
48 #define PlusConstPostInc 0x33
49 #define ScratchRegPostInc 0x34
50 #define PreservedRegPostInc 0x35
52 #if ACCESS == 0 || TYPE == 0 || SIZE == 0 || POSTINC == 0
53 #error define ACCESS, TYPE, SIZE and/or POSTINC
59 # define DATA_TYPE short
60 # define DATA_VALUE 0x1234
64 # define DATA_TYPE int
65 # define DATA_VALUE 0x12345678
69 # define DATA_TYPE long
70 # define DATA_VALUE 0x1234567890ABCDEF
74 #elif TYPE == FloatingPoint
77 # define DATA_TYPE float
78 # define DATA_VALUE FLT_MIN
82 # define DATA_TYPE double
83 # define DATA_VALUE DBL_MIN
87 # define DATA_TYPE long double
88 # define DATA_VALUE LDBL_MIN
97 char misaligned[sizeof(DATA_TYPE)];
100 DATA_TYPE *aligned = &data.aligned;
101 DATA_TYPE *misaligned = (DATA_TYPE *)data.misaligned;
102 DATA_TYPE value = DATA_VALUE;
105 block_copy(void *dst, void *src, size_t sz)
108 memcpy(dst, src, sz);
116 asm volatile("sum 8");
122 block_copy(misaligned, &value, sizeof(DATA_TYPE));
124 # if POSTINC == NoPostInc
125 /* Misaligned load. */
126 *aligned = *misaligned;
127 # elif POSTINC == MinConstPostInc
130 LD " " REG "=[r2],%2;;"
131 "st8 %0=r2;" ST " %1=" REG ";;"
132 : "=m"(misaligned), "=m"(*aligned)
133 : "i"(-sizeof(DATA_TYPE))
134 : REG, "r2", "memory");
135 # elif POSTINC == PlusConstPostInc
138 LD " " REG "=[r2],%2;;"
139 "st8 %0=r2;" ST " %1=" REG ";;"
140 : "=m"(misaligned), "=m"(*aligned)
141 : "i"(sizeof(DATA_TYPE))
142 : REG, "r2", "memory");
143 # elif POSTINC == ScratchRegPostInc
145 "ld8 r2=%0; mov r3=%2;;"
146 LD " " REG "=[r2],r3;;"
147 "st8 %0=r2;" ST " %1=" REG ";;"
148 : "=m"(misaligned), "=m"(*aligned)
149 : "i"(sizeof(DATA_TYPE))
150 : REG, "r2", "r3", "memory");
151 # elif POSTINC == PreservedRegPostInc
153 "ld8 r2=%0; mov r4=%2;;"
154 LD " " REG "=[r2],r4;;"
155 "st8 %0=r2;" ST " %1=" REG ";;"
156 : "=m"(misaligned), "=m"(*aligned)
157 : "i"(sizeof(DATA_TYPE))
158 : REG, "r2", "r4", "memory");
161 #elif ACCESS == Store
166 # if POSTINC == NoPostInc
167 /* Misaligned store. */
169 # elif POSTINC == MinConstPostInc
171 "ld8 r2=%0;" LD " " REG "=%1;;"
172 ST " [r2]=" REG ",%2;;"
175 : "m"(value), "i"(-sizeof(DATA_TYPE))
176 : REG, "r2", "memory");
177 # elif POSTINC == PlusConstPostInc
179 "ld8 r2=%0;" LD " " REG "=%1;;"
180 ST " [r2]=" REG ",%2;;"
183 : "m"(value), "i"(sizeof(DATA_TYPE))
184 : REG, "r2", "memory");
185 # elif POSTINC == ScratchRegPostInc || POSTINC == PreservedRegPostInc
189 block_copy(aligned, data.misaligned, sizeof(DATA_TYPE));
192 if (*aligned != value)
195 #if POSTINC == NoPostInc
197 #elif POSTINC == MinConstPostInc
198 return (((char *)misaligned == data.misaligned - sizeof(DATA_TYPE))
201 return (((char *)misaligned == data.misaligned + sizeof(DATA_TYPE))