test.c (139595) | test.c (140892) |
---|---|
1/* 2 * Copyright (c) 2005 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * --- 9 unchanged lines hidden (view full) --- 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. 25 * | 1/* 2 * Copyright (c) 2005 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * --- 9 unchanged lines hidden (view full) --- 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. 25 * |
26 * $FreeBSD: head/tools/regression/ia64/unaligned/test.c 139595 2005-01-02 21:33:40Z marcel $ | 26 * $FreeBSD: head/tools/regression/ia64/unaligned/test.c 140892 2005-01-27 06:50:05Z marcel $ |
27 */ 28 | 27 */ 28 |
29#include <machine/float.h> |
|
29#include <string.h> 30 | 30#include <string.h> 31 |
31struct { | 32/* Memory accesses. */ 33#define Load 0x01 34#define Store 0x02 35 36/* Data type. */ 37#define Integer 0x11 38#define FloatingPoint 0x12 39 40/* Data size. */ 41#define Small 0x21 42#define Medium 0x22 43#define Large 0x23 44 45/* Post increment. */ 46#define NoPostInc 0x31 47#define MinConstPostInc 0x32 48#define PlusConstPostInc 0x33 49#define ScratchRegPostInc 0x34 50#define PreservedRegPostInc 0x35 51 52#if ACCESS == 0 || TYPE == 0 || SIZE == 0 || POSTINC == 0 53#error define ACCESS, TYPE, SIZE and/or POSTINC 54#endif 55 56#if TYPE == Integer 57# define REG "r8" 58# if SIZE == Small 59# define DATA_TYPE short 60# define DATA_VALUE 0x1234 61# define LD "ld2" 62# define ST "st2" 63# elif SIZE == Medium 64# define DATA_TYPE int 65# define DATA_VALUE 0x12345678 66# define LD "ld4" 67# define ST "st4" 68# elif SIZE == Large 69# define DATA_TYPE long 70# define DATA_VALUE 0x1234567890ABCDEF 71# define LD "ld8" 72# define ST "st8" 73# endif 74#elif TYPE == FloatingPoint 75# define REG "f6" 76# if SIZE == Small 77# define DATA_TYPE float 78# define DATA_VALUE FLT_MIN 79# define LD "ldfs" 80# define ST "stfs" 81# elif SIZE == Medium 82# define DATA_TYPE double 83# define DATA_VALUE DBL_MIN 84# define LD "ldfd" 85# define ST "stfd" 86# elif SIZE == Large 87# define DATA_TYPE long double 88# define DATA_VALUE LDBL_MIN 89# define LD "ldfe" 90# define ST "stfe" 91# endif 92#endif 93 94static struct { |
32 DATA_TYPE aligned; 33 char _; 34 char misaligned[sizeof(DATA_TYPE)]; 35} data; 36 37int 38main() 39{ 40 DATA_TYPE *aligned = &data.aligned; 41 DATA_TYPE *misaligned = (DATA_TYPE *)data.misaligned; 42 DATA_TYPE value = DATA_VALUE; 43 44 /* Set PSR.ac. */ 45 asm volatile("sum 8"); 46 | 95 DATA_TYPE aligned; 96 char _; 97 char misaligned[sizeof(DATA_TYPE)]; 98} data; 99 100int 101main() 102{ 103 DATA_TYPE *aligned = &data.aligned; 104 DATA_TYPE *misaligned = (DATA_TYPE *)data.misaligned; 105 DATA_TYPE value = DATA_VALUE; 106 107 /* Set PSR.ac. */ 108 asm volatile("sum 8"); 109 |
47#if defined(TEST_STORE) 48 /* Misaligned store. */ 49 *misaligned = value; 50 memcpy(aligned, misaligned, sizeof(DATA_TYPE)); 51#elif defined(TEST_LOAD) | 110#if ACCESS == Load 111 /* 112 * LOAD 113 */ |
52 memcpy(misaligned, &value, sizeof(DATA_TYPE)); | 114 memcpy(misaligned, &value, sizeof(DATA_TYPE)); |
115 116# if POSTINC == NoPostInc |
|
53 /* Misaligned load. */ 54 *aligned = *misaligned; | 117 /* Misaligned load. */ 118 *aligned = *misaligned; |
55#else 56#error Define TEST_LOAD or TEST_STORE | 119# elif POSTINC == MinConstPostInc 120 asm volatile( 121 "ld8 r2=%0;;" 122 LD " " REG "=[r2],%2;;" 123 "st8 %0=r2;" ST " %1=" REG ";;" 124 : "=m"(misaligned), "=m"(*aligned) 125 : "i"(-sizeof(DATA_TYPE)) 126 : REG, "r2", "memory"); 127# elif POSTINC == PlusConstPostInc 128 asm volatile( 129 "ld8 r2=%0;;" 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 == ScratchRegPostInc 136 asm volatile( 137 "ld8 r2=%0; mov r3=%2;;" 138 LD " " REG "=[r2],r3;;" 139 "st8 %0=r2;" ST " %1=" REG ";;" 140 : "=m"(misaligned), "=m"(*aligned) 141 : "i"(sizeof(DATA_TYPE)) 142 : REG, "r2", "r3", "memory"); 143# elif POSTINC == PreservedRegPostInc 144 asm volatile( 145 "ld8 r2=%0; mov r4=%2;;" 146 LD " " REG "=[r2],r4;;" 147 "st8 %0=r2;" ST " %1=" REG ";;" 148 : "=m"(misaligned), "=m"(*aligned) 149 : "i"(sizeof(DATA_TYPE)) 150 : REG, "r2", "r4", "memory"); 151# endif 152 153#elif ACCESS == Store 154 /* 155 * STORE 156 */ 157 158# if POSTINC == NoPostInc 159 /* Misaligned store. */ 160 *misaligned = value; 161# elif POSTINC == MinConstPostInc 162 asm volatile( 163 "ld8 r2=%0;" LD " " REG "=%1;;" 164 ST " [r2]=" REG ",%2;;" 165 "st8 %0=r2;;" 166 : "=m"(misaligned) 167 : "m"(value), "i"(-sizeof(DATA_TYPE)) 168 : REG, "r2", "memory"); 169# elif POSTINC == PlusConstPostInc 170 asm volatile( 171 "ld8 r2=%0;" LD " " REG "=%1;;" 172 ST " [r2]=" REG ",%2;;" 173 "st8 %0=r2;;" 174 : "=m"(misaligned) 175 : "m"(value), "i"(sizeof(DATA_TYPE)) 176 : REG, "r2", "memory"); 177# elif POSTINC == ScratchRegPostInc || POSTINC == PreservedRegPostInc 178 return (1); 179# endif 180 181 memcpy(aligned, misaligned, sizeof(DATA_TYPE)); |
57#endif 58 | 182#endif 183 |
59 return (*aligned == value) ? 0 : 1; | 184 if (*aligned != value) 185 return (2); 186 187#if POSTINC == NoPostInc 188 return (0); 189#elif POSTINC == MinConstPostInc 190 return (((char *)misaligned == data.misaligned - sizeof(DATA_TYPE)) 191 ? 0 : 4); 192#else 193 return (((char *)misaligned == data.misaligned + sizeof(DATA_TYPE)) 194 ? 0 : 4); 195#endif |
60} | 196} |