rv64: Vectorize bulk memory operations
127be8c166c760988166b132fbe56e60af289cb31c88e6c62861d1af98678da5
Use byte-wide vector loops for large aggregate copies, slice copies and growth, and frame clears. Set each vector length from the remaining bytes and keep small fixed operations unrolled. Preserve the address of a spilled reserve while clearing its frame. Cover vector selection and boundary sizes with the shared-code interpreter at the minimum vector length. Enable vector state for native fixture workers and interrupt runtime compilation before its first publication. Matched cold-cache fixed-point self compilation uses 1.64% fewer guest instructions. Compilation of the 23 pinned program fixtures uses 4.2% to 11.9% fewer instructions. Assisted-by: Codex:gpt-6 Change-Id: Idcf9388362fbff09da0e708ae72e24eaa993561f
1 parent
a1c086d3
lib/std/arch/rv64.rad
+1 -1
| 186 | 186 | export constant INSTR_SIZE: i32 = 4; |
|
| 187 | 187 | /// Stack alignment requirement in bytes. |
|
| 188 | 188 | export constant STACK_ALIGNMENT: i32 = 16; |
|
| 189 | 189 | ||
| 190 | 190 | /// Largest number of accesses of a blit that are emitted inline, at two instructions each. A |
|
| 191 | - | /// longer copy loops, at five instructions per access. Inline copies reach at most 256 bytes |
|
| 191 | + | /// longer copy uses a vector loop. Inline copies reach at most 256 bytes |
|
| 192 | 192 | /// from an address, which is within an immediate offset. |
|
| 193 | 193 | export constant BLIT_UNROLL_UNITS: u32 = 32; |
|
| 194 | 194 | ||
| 195 | 195 | ///////////////////////// |
|
| 196 | 196 | // Codegen Allocation // |
lib/std/arch/rv64/encode.rad
+29 -1
| 1 | - | //! RISC-V RV64I+M+Zba+Zbb+Zbs instruction encoding. |
|
| 1 | + | //! RISC-V RV64I+M+Zba+Zbb+Zbs+Zve64x instruction encoding. |
|
| 2 | 2 | //! |
|
| 3 | 3 | //! Provides type-safe functions for encoding RV64 instructions. |
|
| 4 | 4 | ||
| 5 | 5 | use std::lang::gen; |
|
| 6 | + | use super::vector; |
|
| 6 | 7 | ||
| 7 | 8 | /// Opcode for atomic memory instructions. |
|
| 8 | 9 | export constant OP_AMO: u32 = 0x2f; |
|
| 9 | 10 | /// Opcode for memory ordering instructions. |
|
| 10 | 11 | export constant OP_MISC_MEM: u32 = 0x0f; |
|
| 11 | 12 | /// Instruction word for local instruction synchronization. |
|
| 12 | 13 | export constant FENCE_I: u32 = 0x0000100f; |
|
| 13 | 14 | /// Fence bits outside the predecessor and successor fields. |
|
| 14 | 15 | export constant FENCE_FIXED_MASK: u32 = 0xf00fffff; |
|
| 15 | 16 | ||
| 17 | + | /// Upper bound for the vector type immediate in `vsetvli`. |
|
| 18 | + | constant VSETVLI_TYPE_LIMIT: u32 = 1 << 11; |
|
| 19 | + | ||
| 16 | 20 | ////////////////////// |
|
| 17 | 21 | // Opcode Constants // |
|
| 18 | 22 | ////////////////////// |
|
| 19 | 23 | ||
| 20 | 24 | export constant OP_LOAD: u32 = 0x03; |
| 956 | 960 | ||
| 957 | 961 | /// Zero-extend the low word of `rs1` to 64 bits. |
|
| 958 | 962 | export fn zextW(rd: gen::Reg, rs1: gen::Reg) -> u32 { |
|
| 959 | 963 | return addUw(rd, rs1, super::ZERO); |
|
| 960 | 964 | } |
|
| 965 | + | ||
| 966 | + | /// Set the vector length from `count` with an 11-bit vector type immediate. |
|
| 967 | + | export fn vsetvli(rd: gen::Reg, count: gen::Reg, vtype: u32) -> u32 { |
|
| 968 | + | assert vtype < VSETVLI_TYPE_LIMIT; |
|
| 969 | + | return (vtype << 20) | (*count as u32 << 15) | vector::SET_LENGTH | (*rd as u32 << 7); |
|
| 970 | + | } |
|
| 971 | + | ||
| 972 | + | /// Load active bytes into vector register `vd` from `address`, without a mask. |
|
| 973 | + | export fn vle8(vd: u8, address: gen::Reg) -> u32 { |
|
| 974 | + | assert vd as u32 < vector::REGISTER_COUNT; |
|
| 975 | + | return vector::UNMASKED | vector::OP_LOAD_FP | (vd as u32 << 7) | (*address as u32 << 15); |
|
| 976 | + | } |
|
| 977 | + | ||
| 978 | + | /// Store active bytes of vector register `vs` at `address`, without a mask. |
|
| 979 | + | export fn vse8(vs: u8, address: gen::Reg) -> u32 { |
|
| 980 | + | assert vs as u32 < vector::REGISTER_COUNT; |
|
| 981 | + | return vector::UNMASKED | vector::OP_STORE_FP | (vs as u32 << 7) | (*address as u32 << 15); |
|
| 982 | + | } |
|
| 983 | + | ||
| 984 | + | /// Set active elements of vector register `vd` to a signed five-bit immediate. |
|
| 985 | + | export fn vmvVi(vd: u8, value: i32) -> u32 { |
|
| 986 | + | assert vd as u32 < vector::REGISTER_COUNT and value >= -16 and value <= 15; |
|
| 987 | + | return vector::VMV_VI | (vd as u32 << 7) | ((value as u32 & 31) << 15); |
|
| 988 | + | } |
lib/std/arch/rv64/isel.rad
+40 -27
| 37 | 37 | use std::mem::heap; |
|
| 38 | 38 | ||
| 39 | 39 | use super::atomics; |
|
| 40 | 40 | use super::emit; |
|
| 41 | 41 | use super::encode; |
|
| 42 | + | use super::vector; |
|
| 42 | 43 | ||
| 43 | 44 | /// Largest object size representable as a signed address offset. |
|
| 44 | 45 | constant MAX_OBJECT_SIZE: u32 = 0x7fffffff; |
|
| 45 | 46 | ||
| 46 | 47 | /////////////// |
| 864 | 865 | return super::DWORD_SIZE as u32; |
|
| 865 | 866 | } |
|
| 866 | 867 | return alignment; |
|
| 867 | 868 | } |
|
| 868 | 869 | ||
| 869 | - | /// Emit a loop that copies the bytes from the cursor `src` up to `end` to the cursor `dst`, |
|
| 870 | - | /// `unit` bytes at a time through `tmp`. The loop runs at least once, and leaves both cursors |
|
| 871 | - | /// after the bytes. |
|
| 870 | + | /// Byte-wide elements, eight-register groups, and agnostic tail and mask policies. |
|
| 871 | + | constant BYTE_VECTOR_TYPE: u32 = vector::TYPE_TAIL_AGNOSTIC |
|
| 872 | + | | vector::TYPE_MASK_AGNOSTIC | vector::TYPE_GROUP_8; |
|
| 873 | + | /// First register of the caller-saved group used by memory operations. |
|
| 874 | + | constant BYTE_VECTOR: u8 = 8; |
|
| 875 | + | ||
| 876 | + | /// Emit a loop that copies the bytes from the cursor `src` up to `end` to the cursor `dst` |
|
| 877 | + | /// through a vector group. The loop runs at least once, and leaves both cursors after the |
|
| 878 | + | /// bytes. `tmp` holds the number of bytes in each vector access. |
|
| 872 | 879 | fn emitCopyLoop( |
|
| 873 | - | e: &mut emit::Emitter, src: gen::Reg, dst: gen::Reg, end: gen::Reg, tmp: gen::Reg, unit: u32 |
|
| 880 | + | e: &mut emit::Emitter, src: gen::Reg, dst: gen::Reg, end: gen::Reg, tmp: gen::Reg |
|
| 874 | 881 | ) throws (super::Error) { |
|
| 875 | 882 | let start = e.code.len; |
|
| 876 | - | try emit::emitSload(e, tmp, src, 0, accessType(unit)); |
|
| 877 | - | try emit::emitStore(e, tmp, dst, 0, accessType(unit)); |
|
| 878 | - | try emit::emit(e, encode::addi(src, src, unit as i32)); |
|
| 879 | - | try emit::emit(e, encode::addi(dst, dst, unit as i32)); |
|
| 883 | + | try emit::emit(e, encode::sub(tmp, end, src)); |
|
| 884 | + | try emit::emit(e, encode::vsetvli(tmp, tmp, BYTE_VECTOR_TYPE)); |
|
| 885 | + | try emit::emit(e, encode::vle8(BYTE_VECTOR, src)); |
|
| 886 | + | try emit::emit(e, encode::vse8(BYTE_VECTOR, dst)); |
|
| 887 | + | try emit::emit(e, encode::add(src, src, tmp)); |
|
| 888 | + | try emit::emit(e, encode::add(dst, dst, tmp)); |
|
| 880 | 889 | let offset = (start as i32 - e.code.len as i32) * super::INSTR_SIZE; |
|
| 881 | 890 | try emit::emit(e, encode::bne(src, end, offset)); |
|
| 882 | 891 | } |
|
| 883 | 892 | ||
| 884 | 893 | /// Copy an object of layout `object` from `src` to `dst`. Both addresses are aligned to the |
| 901 | 910 | } |
|
| 902 | 911 | // The cursors and the end are scratch registers, so that both addresses keep their |
|
| 903 | 912 | // values. A spilled operand sits in a scratch register that is reused once the move that |
|
| 904 | 913 | // reads it has run: the source in the register of the destination cursor, and the |
|
| 905 | 914 | // destination in that of the end. |
|
| 906 | - | let body = object.size - object.size % unit; |
|
| 907 | 915 | try emit::emit(e, encode::addi(super::SCRATCH3, src, 0)); |
|
| 908 | 916 | try emit::emit(e, encode::addi(super::SCRATCH1, dst, 0)); |
|
| 909 | - | if body as i32 <= super::MAX_IMM { |
|
| 910 | - | try emit::emit(e, encode::addi(super::SCRATCH2, super::SCRATCH3, body as i32)); |
|
| 917 | + | if object.size as i32 <= super::MAX_IMM { |
|
| 918 | + | try emit::emit(e, encode::addi(super::SCRATCH2, super::SCRATCH3, object.size as i32)); |
|
| 911 | 919 | } else { |
|
| 912 | - | try emit::loadImm(e, super::SCRATCH2, body as i64); |
|
| 920 | + | try emit::loadImm(e, super::SCRATCH2, object.size as i64); |
|
| 913 | 921 | try emit::emit(e, encode::add(super::SCRATCH2, super::SCRATCH2, super::SCRATCH3)); |
|
| 914 | 922 | } |
|
| 915 | 923 | try emitCopyLoop( |
|
| 916 | - | e, super::SCRATCH3, super::SCRATCH1, super::SCRATCH2, super::ADDR_SCRATCH, unit |
|
| 924 | + | e, super::SCRATCH3, super::SCRATCH1, super::SCRATCH2, super::ADDR_SCRATCH |
|
| 917 | 925 | ); |
|
| 918 | - | try emitCopy(e, super::SCRATCH1, super::SCRATCH3, object.size - body, unit); |
|
| 919 | 926 | } |
|
| 920 | 927 | ||
| 921 | 928 | /// Multiply `rs` by the constant `size`. `rd` can be `rs`. A `size` that is not a |
|
| 922 | 929 | /// power of two is loaded into `tmp`, which must differ from `rs`. |
|
| 923 | 930 | fn emitScale( |
| 1217 | 1224 | try emit::emit(e, encode::bne(t3, super::ZERO, again)); |
|
| 1218 | 1225 | try emit::emitLd(e, t3, h, gen::data::HEAP_BASE_OFFSET); |
|
| 1219 | 1226 | try emit::emit(e, encode::add(t3, t3, a)); |
|
| 1220 | 1227 | // Publish the new pointer and capacity, then copy the elements from the old pointer |
|
| 1221 | 1228 | // in T1 up to the end in ADDR_SCRATCH. The slice address is not used after the length |
|
| 1222 | - | // is loaded, so a spilled one can sit in T2, which carries the copied units. |
|
| 1229 | + | // is loaded, so a spilled one can sit in T2, which carries the vector access length. |
|
| 1223 | 1230 | let old = try getSrcReg(s, e, slice, t2); |
|
| 1224 | 1231 | try emit::emitLd(e, t1, old, SLICE_PTR_OFFSET); |
|
| 1225 | 1232 | try emit::emitSd(e, t3, old, SLICE_PTR_OFFSET); |
|
| 1226 | 1233 | try loadU32(s, e, a, a, capacity); |
|
| 1227 | 1234 | try emit::emitSw(e, a, old, SLICE_CAP_OFFSET); |
|
| 1228 | 1235 | try emit::emitLoad(e, a, old, SLICE_LEN_OFFSET, il::Type::W32); |
|
| 1229 | 1236 | try emitScale(e, a, a, size, t2); |
|
| 1230 | 1237 | try emit::emit(e, encode::add(a, a, t1)); |
|
| 1231 | 1238 | let skip = try emitBranchHole(e, encode::beq(t1, a, 0)); |
|
| 1232 | - | try emitCopyLoop(e, t1, t3, a, t2, copyUnit(alignment)); |
|
| 1239 | + | try emitCopyLoop(e, t1, t3, a, t2); |
|
| 1233 | 1240 | emit::patch(e, skip, encode::beq( |
|
| 1234 | 1241 | t1, a, (e.code.len as i32 - skip as i32) * super::INSTR_SIZE |
|
| 1235 | 1242 | )); |
|
| 1236 | 1243 | } |
|
| 1237 | 1244 | // Success and failure set the result. |
| 1284 | 1291 | try emitCopyLoop( |
|
| 1285 | 1292 | e, |
|
| 1286 | 1293 | super::SCRATCH1, |
|
| 1287 | 1294 | super::SCRATCH2, |
|
| 1288 | 1295 | super::SCRATCH3, |
|
| 1289 | - | super::ADDR_SCRATCH, |
|
| 1290 | - | copyUnit(object.alignment) |
|
| 1296 | + | super::ADDR_SCRATCH |
|
| 1291 | 1297 | ); |
|
| 1292 | 1298 | emit::patch(e, skip, encode::beq( |
|
| 1293 | 1299 | super::SCRATCH1, super::SCRATCH3, (e.code.len as i32 - skip as i32) * super::INSTR_SIZE |
|
| 1294 | 1300 | )); |
|
| 1295 | 1301 | } |
|
| 1296 | 1302 | ||
| 1297 | 1303 | /// Zero `size` bytes of the frame at SP plus `offset`. The region is 8-byte aligned. |
|
| 1298 | 1304 | fn emitZeroFrame(e: &mut emit::Emitter, offset: i32, size: u32) throws (super::Error) { |
|
| 1299 | 1305 | let words = (size / 8) as i32; |
|
| 1300 | 1306 | if words > ZERO_UNROLL_WORDS { |
|
| 1301 | - | // Clear with a loop over a cursor. |
|
| 1307 | + | // Clear with a loop over a cursor. SCRATCH1 can hold the address |
|
| 1308 | + | // of a spilled reserve. |
|
| 1302 | 1309 | try emitAddOffset(e, super::ADDR_SCRATCH, super::SP, offset as i64); |
|
| 1303 | - | try emit::loadImm(e, super::SCRATCH3, words as i64); |
|
| 1310 | + | try emit::loadImm(e, super::SCRATCH3, size as i64); |
|
| 1304 | 1311 | let start = e.code.len; |
|
| 1305 | - | try emit::emit(e, encode::sd(super::ZERO, super::ADDR_SCRATCH, 0)); |
|
| 1306 | - | try emit::emit(e, encode::addi(super::ADDR_SCRATCH, super::ADDR_SCRATCH, 8)); |
|
| 1307 | - | try emit::emit(e, encode::addi(super::SCRATCH3, super::SCRATCH3, -1)); |
|
| 1312 | + | try emit::emit(e, encode::vsetvli( |
|
| 1313 | + | super::SCRATCH2, super::SCRATCH3, BYTE_VECTOR_TYPE |
|
| 1314 | + | )); |
|
| 1315 | + | try emit::emit(e, encode::vmvVi(BYTE_VECTOR, 0)); |
|
| 1316 | + | try emit::emit(e, encode::vse8(BYTE_VECTOR, super::ADDR_SCRATCH)); |
|
| 1317 | + | try emit::emit(e, encode::add( |
|
| 1318 | + | super::ADDR_SCRATCH, super::ADDR_SCRATCH, super::SCRATCH2 |
|
| 1319 | + | )); |
|
| 1320 | + | try emit::emit(e, encode::sub(super::SCRATCH3, super::SCRATCH3, super::SCRATCH2)); |
|
| 1308 | 1321 | let back = (start as i32 - e.code.len as i32) * super::INSTR_SIZE; |
|
| 1309 | 1322 | try emit::emit(e, encode::bne(super::SCRATCH3, super::ZERO, back)); |
|
| 1310 | - | } else { |
|
| 1311 | - | for i in 0 .. words { |
|
| 1312 | - | try emit::emitSd(e, super::ZERO, super::SP, offset + i * 8); |
|
| 1313 | - | } |
|
| 1323 | + | return; |
|
| 1324 | + | } |
|
| 1325 | + | for i in 0 .. words { |
|
| 1326 | + | try emit::emitSd(e, super::ZERO, super::SP, offset + i * 8); |
|
| 1314 | 1327 | } |
|
| 1315 | 1328 | let mut at = offset + words * 8; |
|
| 1316 | 1329 | let tail = size - (words * 8) as u32; |
|
| 1317 | 1330 | if tail >= 4 { |
|
| 1318 | 1331 | try emit::emitSw(e, super::ZERO, super::SP, at); |
lib/std/arch/rv64/shared/tests/run.rad
+48 -4
| 90 | 90 | ||
| 91 | 91 | /// Registers of the modeled machine. |
|
| 92 | 92 | record Machine { |
|
| 93 | 93 | /// General-purpose registers. |
|
| 94 | 94 | regs: [u64; 32], |
|
| 95 | + | /// Byte vector group at the minimum 64-bit VLEN, with LMUL=8. |
|
| 96 | + | vector: [u8; 64], |
|
| 97 | + | /// Number of active bytes in the vector group. |
|
| 98 | + | vl: u32, |
|
| 95 | 99 | /// Number of instructions executed. |
|
| 96 | 100 | steps: u32, |
|
| 97 | 101 | /// Address held by the last load-reserved, until a store-conditional or a trap clears it. |
|
| 98 | 102 | reservation: ?u64, |
|
| 99 | 103 | /// Store-conditionals that fail before one can succeed. Each failure models another hart |
| 170 | 174 | return Outcome::Faulted; |
|
| 171 | 175 | } |
|
| 172 | 176 | set m.steps += 1; |
|
| 173 | 177 | let mut next = pc + 1; |
|
| 174 | 178 | match decode::decode(code[pc]) { |
|
| 179 | + | case decode::Instr::Vector { bits } => { |
|
| 180 | + | if (bits & 0xfff0707f) == 0x0c307057 { |
|
| 181 | + | let count = read(m, rv64::reg(decode::rs1(bits))); |
|
| 182 | + | let vl = (count if count < 64 else 64) as u32; |
|
| 183 | + | set m.vl = vl; |
|
| 184 | + | write(m, rv64::reg(decode::rd(bits)), vl as u64); |
|
| 185 | + | } else if bits == 0x5e003457 { |
|
| 186 | + | for i in 0 .. m.vl { |
|
| 187 | + | set m.vector[i] = 0; |
|
| 188 | + | } |
|
| 189 | + | } else if (bits & 0xfff07fff) == 0x02000407 { |
|
| 190 | + | let address = read(m, rv64::reg(decode::rs1(bits))); |
|
| 191 | + | for i in 0 .. m.vl { |
|
| 192 | + | let value = load(address + i as u64, 1) else { |
|
| 193 | + | return Outcome::Faulted; |
|
| 194 | + | }; |
|
| 195 | + | set m.vector[i] = value as u8; |
|
| 196 | + | } |
|
| 197 | + | } else if (bits & 0xfff07fff) == 0x02000427 { |
|
| 198 | + | let address = read(m, rv64::reg(decode::rs1(bits))); |
|
| 199 | + | for i in 0 .. m.vl { |
|
| 200 | + | if not store(address + i as u64, 1, m.vector[i] as u64) { |
|
| 201 | + | return Outcome::Faulted; |
|
| 202 | + | } |
|
| 203 | + | } |
|
| 204 | + | } else { |
|
| 205 | + | return Outcome::Faulted; |
|
| 206 | + | } |
|
| 207 | + | } |
|
| 175 | 208 | case decode::Instr::AddUw { rd, rs1, rs2 } => { |
|
| 176 | 209 | write(m, rd, read(m, rs1) as u32 as u64 + read(m, rs2)); |
|
| 177 | 210 | } |
|
| 178 | 211 | case decode::Instr::Sh1add { rd, rs1, rs2 } => { |
|
| 179 | 212 | write(m, rd, (read(m, rs1) << 1) + read(m, rs2)); |
| 507 | 540 | unsafe fn boot(args: &[u64]) -> Machine { |
|
| 508 | 541 | for i in 0 .. MEMORY_SIZE { |
|
| 509 | 542 | set MEMORY[i] = 0; |
|
| 510 | 543 | } |
|
| 511 | 544 | assert store(TABLE + SLOT as u64 * 8, 8, PACKAGE_BASE); |
|
| 512 | - | let mut m = Machine { regs: [0; 32], steps: 0, reservation: nil, contended: 0 }; |
|
| 545 | + | let mut m = Machine { |
|
| 546 | + | regs: [0; 32], vector: [0; 64], vl: 0, steps: 0, reservation: nil, contended: 0 |
|
| 547 | + | }; |
|
| 513 | 548 | write(&mut m, rv64::GP, TABLE); |
|
| 514 | 549 | write(&mut m, rv64::SP, STACK); |
|
| 515 | 550 | write(&mut m, rv64::RA, RETURN); |
|
| 516 | 551 | for arg, i in args { |
|
| 517 | 552 | write(&mut m, rv64::ARG_REGS[i], arg); |
| 1099 | 1134 | match decode::decode(word) { |
|
| 1100 | 1135 | case decode::Instr::Sd { rs1, .. } => return rs1, |
|
| 1101 | 1136 | case decode::Instr::Sw { rs1, .. } => return rs1, |
|
| 1102 | 1137 | case decode::Instr::Sh { rs1, .. } => return rs1, |
|
| 1103 | 1138 | case decode::Instr::Sb { rs1, .. } => return rs1, |
|
| 1104 | - | else => return nil, |
|
| 1139 | + | case decode::Instr::Vector { bits } => { |
|
| 1140 | + | if (bits & 0xfff0707f) == 0x02000027 { |
|
| 1141 | + | return rv64::reg(decode::rs1(bits)); |
|
| 1142 | + | } |
|
| 1143 | + | return nil; |
|
| 1144 | + | } |
|
| 1145 | + | else => return nil, |
|
| 1105 | 1146 | } |
|
| 1106 | 1147 | } |
|
| 1107 | 1148 | ||
| 1108 | 1149 | /// Whether the code reloads both spilled operands from the stack before its first store to |
|
| 1109 | 1150 | /// other memory, which is the first store of the copy. |
| 1185 | 1226 | ||
| 1186 | 1227 | /// The blit checks copy every size below this one. |
|
| 1187 | 1228 | constant SMALL_SIZES: u32 = 41; |
|
| 1188 | 1229 | /// Larger sizes of the blit checks. They include copies that need a loop, with and without a |
|
| 1189 | 1230 | /// tail, and a copy longer than an immediate offset reaches. |
|
| 1190 | - | constant LARGE_SIZES: [u32; 12] = [48, 56, 64, 65, 72, 77, 96, 128, 256, 520, 2051, 2056]; |
|
| 1231 | + | constant LARGE_SIZES: [u32; 18] = [ |
|
| 1232 | + | 48, 56, 63, 64, 65, 72, 77, 96, 127, 128, 129, 255, 256, 257, |
|
| 1233 | + | 511, 520, 2051, 2056, |
|
| 1234 | + | ]; |
|
| 1191 | 1235 | /// Alignments of the objects of the blit checks. |
|
| 1192 | 1236 | constant BOUNDARIES: [u32; 4] = [1, 2, 4, 8]; |
|
| 1193 | 1237 | /// The modes of the blit checks. |
|
| 1194 | 1238 | constant MODES: [BlitMode; 3] = [BlitMode::Registers, BlitMode::Spilled, BlitMode::Aliased]; |
|
| 1195 | 1239 | ||
| 1196 | - | /// A copy moves exactly the bytes of the layout, with units as wide as its alignment allows, |
|
| 1240 | + | /// A copy moves exactly the bytes of the layout, |
|
| 1197 | 1241 | /// for every size from zero to forty and some larger ones, also sizes that the alignment does |
|
| 1198 | 1242 | /// not divide. It leaves the addresses intact, also when they are spilled or equal. |
|
| 1199 | 1243 | @test unsafe fn blitCopies() throws (testing::TestError) { |
|
| 1200 | 1244 | for boundary in BOUNDARIES { |
|
| 1201 | 1245 | for mode in MODES { |
lib/std/arch/rv64/tests.rad
+25 -0
| 1820 | 1820 | } |
|
| 1821 | 1821 | } |
|
| 1822 | 1822 | return false; |
|
| 1823 | 1823 | } |
|
| 1824 | 1824 | ||
| 1825 | + | /// Large memory operations select bounded vector loads and stores. |
|
| 1826 | + | @test unsafe fn testVectorMemorySelection() throws (testing::TestError) { |
|
| 1827 | + | let pointer = il::PtrType { layout: 0, own: true, mutable: true, nullable: false }; |
|
| 1828 | + | let arena = heap::over(&mut REGISTER_SCRATCH[..]); |
|
| 1829 | + | let mut slots: *mut [il::Slot] = &mut []; |
|
| 1830 | + | try! slots.append( |
|
| 1831 | + | il::Slot { offset: 0, kind: il::SlotKind::Ptr(pointer), regions: &[] }, arena |
|
| 1832 | + | ); |
|
| 1833 | + | let layouts = [ |
|
| 1834 | + | il::Layout { size: 520, alignment: 8, slots: &slots[..], regions: 0 }, |
|
| 1835 | + | il::Layout { size: 16, alignment: 8, slots: &[], regions: 0 }, |
|
| 1836 | + | ]; |
|
| 1837 | + | let large = try generateBody(&layouts[..], nil, &[blitOf(0, 1, 0)]); |
|
| 1838 | + | assert containsInstruction(large, 0x02000007, 0xfff0707f); |
|
| 1839 | + | assert containsInstruction(large, 0x02000027, 0xfff0707f); |
|
| 1840 | + | let small = try generateBody(&layouts[..], nil, &[blitOf(0, 1, 1)]); |
|
| 1841 | + | assert not containsInstruction(small, 0x02000027, 0xfff0707f); |
|
| 1842 | + | let cleared = try generateBody(&layouts[..], 0, &[]); |
|
| 1843 | + | assert containsInstruction(cleared, 0x02000027, 0xfff0707f); |
|
| 1844 | + | let copied = try generateBody(&layouts[..], nil, &[ |
|
| 1845 | + | il::Instr::SliceCopy { dst: il::Reg { n: 0 }, src: il::Reg { n: 1 }, layout: 1 } |
|
| 1846 | + | ]); |
|
| 1847 | + | assert containsInstruction(copied, 0x02000007, 0xfff0707f); |
|
| 1848 | + | } |
|
| 1849 | + | ||
| 1825 | 1850 | /// Bit manipulation selection preserves single-use expression semantics. |
|
| 1826 | 1851 | @test unsafe fn testBitManipulationSelection() throws (testing::TestError) { |
|
| 1827 | 1852 | let shift = il::Instr::BinOp { |
|
| 1828 | 1853 | op: il::BinOp::Shl, typ: il::Type::W64, dst: il::Reg { n: 2 }, a: reg(0), b: il::Val::Imm(3) |
|
| 1829 | 1854 | }; |
test/kernel/fixture.rad
+5 -4
| 3 | 3 | use std::arch::rv64; |
|
| 4 | 4 | use kernel::abi; |
|
| 5 | 5 | use kernel::backing; |
|
| 6 | 6 | use kernel::budgets; |
|
| 7 | 7 | use kernel::calls; |
|
| 8 | + | use kernel::capability; |
|
| 9 | + | use kernel::domains; |
|
| 8 | 10 | use kernel::limits; |
|
| 9 | 11 | use kernel::loader; |
|
| 10 | 12 | use kernel::pages; |
|
| 11 | 13 | use kernel::physical; |
|
| 12 | 14 | use kernel::slots; |
|
| 13 | - | use kernel::capability; |
|
| 14 | - | use kernel::domains; |
|
| 15 | 15 | use kernel::state; |
|
| 16 | 16 | ||
| 17 | 17 | /// Bytes in one 64-bit argument or register value. |
|
| 18 | 18 | export constant WORD_BYTES: u32 = 8; |
|
| 19 | 19 | /// Bits in each lifecycle continuation-ownership word. |
|
| 20 | 20 | export constant CONTEXT_BITS: u32 = 32; |
|
| 21 | 21 | /// Machine privilege in the saved mstatus MPP field. |
|
| 22 | 22 | export constant MACHINE_PRIVILEGE: u64 = 0x1800; |
|
| 23 | - | /// Machine privilege and interrupt-enable state restored by mret. |
|
| 24 | - | export constant MACHINE_STATUS: u64 = MACHINE_PRIVILEGE | 0x80; |
|
| 23 | + | /// Machine privilege, interrupt-enable state and vector state restored by mret. |
|
| 24 | + | export constant MACHINE_STATUS: u64 = |
|
| 25 | + | MACHINE_PRIVILEGE | rv64::MSTATUS_MPIE | rv64::MSTATUS_VS_INITIAL; |
|
| 25 | 26 | ||
| 26 | 27 | /// A pending domain and its initial execution context. |
|
| 27 | 28 | export record Actor: Copy { |
|
| 28 | 29 | /// Execute capability in the fixture's bootstrap table. |
|
| 29 | 30 | handle: abi::Handle, |
test/runtime/kernel/dispatchcheck.rad
+1 -1
| 24 | 24 | /// Delay before the first user window, in timer ticks. |
|
| 25 | 25 | constant START_DELAY: u64 = 1000000; |
|
| 26 | 26 | /// End of the first interrupted load, relative to the first window start. It |
|
| 27 | 27 | /// must fall after the loader reserves its output and before its compilation |
|
| 28 | 28 | /// ends, so cancellation covers unpublished native code and metadata. |
|
| 29 | - | constant FIRST_WINDOW_END: u64 = 10000000; |
|
| 29 | + | constant FIRST_WINDOW_END: u64 = 6000000; |
|
| 30 | 30 | /// End of the controller's cancellation window. |
|
| 31 | 31 | constant CANCEL_WINDOW_END: u64 = 50000000; |
|
| 32 | 32 | /// End of the retry loader's first window. |
|
| 33 | 33 | constant RETRY_WINDOW_END: u64 = 60000000; |
|
| 34 | 34 | /// End of the witness window. |
test/tests/reserve.zeroed.rad
+2 -2
| 13 | 13 | } |
|
| 14 | 14 | ||
| 15 | 15 | /// Record that nests an array of records. |
|
| 16 | 16 | record Holder { |
|
| 17 | 17 | /// Links. |
|
| 18 | - | links: [Links; 3], |
|
| 18 | + | links: [Links; 65], |
|
| 19 | 19 | /// Optional slice. |
|
| 20 | 20 | text: ?*[u8], |
|
| 21 | 21 | } |
|
| 22 | 22 | ||
| 23 | 23 | fn stir(a: u64, b: u64, c: u64) -> u64 { |
| 27 | 27 | } |
|
| 28 | 28 | ||
| 29 | 29 | unsafe fn probe() -> i32 { |
|
| 30 | 30 | let holder = Holder { links: undefined, text: undefined }; |
|
| 31 | 31 | let mut i: u32 = 0; |
|
| 32 | - | while i < 3 { |
|
| 32 | + | while i < 65 { |
|
| 33 | 33 | if holder.links[i].first <> nil or holder.links[i].second <> nil { |
|
| 34 | 34 | return 1; |
|
| 35 | 35 | } |
|
| 36 | 36 | set i += 1; |
|
| 37 | 37 | } |