|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Runtime.CompilerServices; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +namespace TestBitwiseClearShift |
| 9 | +{ |
| 10 | + public class Program |
| 11 | + { |
| 12 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 13 | + [Fact] |
| 14 | + public static int CheckBitwiseClearShift() |
| 15 | + { |
| 16 | + bool fail = false; |
| 17 | + |
| 18 | + if (!Bic(0xFFFFFFFF, 0x12345678, 0xEDCBA987)) |
| 19 | + { |
| 20 | + fail = true; |
| 21 | + } |
| 22 | + |
| 23 | + if (!BicLSL(0xFFFFFFFF, 0x12345678, 0xDCBA987F)) |
| 24 | + { |
| 25 | + fail = true; |
| 26 | + } |
| 27 | + |
| 28 | + if (!BicLSR(0xFFFFFFFF, 0x12345678, 0xFFFEDCBA)) |
| 29 | + { |
| 30 | + fail = true; |
| 31 | + } |
| 32 | + |
| 33 | + if (!BicASR(0xFFFF, 0x8765, 0xFEF1)) |
| 34 | + { |
| 35 | + fail = true; |
| 36 | + } |
| 37 | + |
| 38 | + if (!BicLargeShift(0xFEFEFEFE, 1, 0xFEFCFEFE)) |
| 39 | + { |
| 40 | + fail = true; |
| 41 | + } |
| 42 | + |
| 43 | + if (!BicLargeShift64Bit(0xFEFEFEFEFEFEFE, 0xFEDCBA98765432, 0xFEFEFEFEF01234)) |
| 44 | + { |
| 45 | + fail = true; |
| 46 | + } |
| 47 | + |
| 48 | + if (Bics(0xFFFFFFFF, 0x100) != 1) |
| 49 | + { |
| 50 | + fail = true; |
| 51 | + } |
| 52 | + |
| 53 | + if (BicsLSL(0xFFFFFFFF, 1) != 1) |
| 54 | + { |
| 55 | + fail = true; |
| 56 | + } |
| 57 | + |
| 58 | + if (BicsLSR(0xFFFFFFFF, 0x87654321) != 1) |
| 59 | + { |
| 60 | + fail = true; |
| 61 | + } |
| 62 | + |
| 63 | + if (BicsASR(0xFFFF, 0x8F6E) != 1) |
| 64 | + { |
| 65 | + fail = true; |
| 66 | + } |
| 67 | + |
| 68 | + if (BicsLargeShift(0xFFFFFFFF, 0x87654321) != 1) |
| 69 | + { |
| 70 | + fail = true; |
| 71 | + } |
| 72 | + |
| 73 | + if (BicsLargeShift64Bit(0xFFFFFFFFFFFFFFFF, 0xFEDCBA9876543210) != 1) |
| 74 | + { |
| 75 | + fail = true; |
| 76 | + } |
| 77 | + |
| 78 | + if (fail) |
| 79 | + { |
| 80 | + return 101; |
| 81 | + } |
| 82 | + return 100; |
| 83 | + } |
| 84 | + |
| 85 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 86 | + static bool Bic(uint a, uint b, uint c) |
| 87 | + { |
| 88 | + //ARM64-FULL-LINE: bic {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}} |
| 89 | + if ((a & ~b) == c) |
| 90 | + { |
| 91 | + return true; |
| 92 | + } |
| 93 | + return false; |
| 94 | + } |
| 95 | + |
| 96 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 97 | + static bool BicLSL(uint a, uint b, uint c) |
| 98 | + { |
| 99 | + //ARM64-FULL-LINE: bic {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSL #4 |
| 100 | + if ((a & ~(b<<4)) == c) |
| 101 | + { |
| 102 | + return true; |
| 103 | + } |
| 104 | + return false; |
| 105 | + } |
| 106 | + |
| 107 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 108 | + static bool BicLSR(uint a, uint b, uint c) |
| 109 | + { |
| 110 | + //ARM64-FULL-LINE: bic {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSR #12 |
| 111 | + if ((a & ~(b>>12)) == c) |
| 112 | + { |
| 113 | + return true; |
| 114 | + } |
| 115 | + return false; |
| 116 | + } |
| 117 | + |
| 118 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 119 | + static bool BicASR(int a, int b, int c) |
| 120 | + { |
| 121 | + //ARM64-FULL-LINE: bic {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, ASR #7 |
| 122 | + if ((a & ~(b>>7)) == c) |
| 123 | + { |
| 124 | + return true; |
| 125 | + } |
| 126 | + return false; |
| 127 | + } |
| 128 | + |
| 129 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 130 | + static bool BicLargeShift(uint a, uint b, uint c) |
| 131 | + { |
| 132 | + //ARM64-FULL-LINE: bic {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSL #17 |
| 133 | + if ((a & ~(b<<145)) == c) |
| 134 | + { |
| 135 | + return true; |
| 136 | + } |
| 137 | + return false; |
| 138 | + } |
| 139 | + |
| 140 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 141 | + static bool BicLargeShift64Bit(long a, long b, long c) |
| 142 | + { |
| 143 | + //ARM64-FULL-LINE: bic {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, ASR #36 |
| 144 | + if ((a & ~(b>>292)) == c) |
| 145 | + { |
| 146 | + return true; |
| 147 | + } |
| 148 | + return false; |
| 149 | + } |
| 150 | + |
| 151 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 152 | + static int Bics(uint a, uint b) |
| 153 | + { |
| 154 | + //ARM64-FULL-LINE: bics {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}} |
| 155 | + if ((a & ~b) == 0) |
| 156 | + { |
| 157 | + return -1; |
| 158 | + } |
| 159 | + return 1; |
| 160 | + } |
| 161 | + |
| 162 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 163 | + static int BicsLSL(uint a, uint b) |
| 164 | + { |
| 165 | + //ARM64-FULL-LINE: bics {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSL #31 |
| 166 | + if ((a & ~(b<<31)) == 0) |
| 167 | + { |
| 168 | + return -1; |
| 169 | + } |
| 170 | + return 1; |
| 171 | + } |
| 172 | + |
| 173 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 174 | + static int BicsLSR(uint a, uint b) |
| 175 | + { |
| 176 | + //ARM64-FULL-LINE: bics {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSR #20 |
| 177 | + if ((a & ~(b>>20)) == 0) |
| 178 | + { |
| 179 | + return -1; |
| 180 | + } |
| 181 | + return 1; |
| 182 | + } |
| 183 | + |
| 184 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 185 | + static int BicsASR(int a, int b) |
| 186 | + { |
| 187 | + //ARM64-FULL-LINE: bics {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, ASR #9 |
| 188 | + if ((a & ~(b>>9)) == 0) |
| 189 | + { |
| 190 | + return -1; |
| 191 | + } |
| 192 | + return 1; |
| 193 | + } |
| 194 | + |
| 195 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 196 | + static int BicsLargeShift(uint a, uint b) |
| 197 | + { |
| 198 | + //ARM64-FULL-LINE: bics {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, LSR #3 |
| 199 | + if ((a & ~(b>>99)) == 0) |
| 200 | + { |
| 201 | + return -1; |
| 202 | + } |
| 203 | + return 1; |
| 204 | + } |
| 205 | + |
| 206 | + [MethodImpl(MethodImplOptions.NoInlining)] |
| 207 | + static int BicsLargeShift64Bit(ulong a, ulong b) |
| 208 | + { |
| 209 | + //ARM64-FULL-LINE: bics {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, LSL #51 |
| 210 | + if ((a & ~(b<<179)) == 0) |
| 211 | + { |
| 212 | + return -1; |
| 213 | + } |
| 214 | + return 1; |
| 215 | + } |
| 216 | + } |
| 217 | +} |
0 commit comments