compiler/ lib/ examples/ std/ arch/ rv64/ tests/ abi.sizes.rad 3.4 KiB aggregate.return.rad 4.0 KiB arith.assignment.rad 580 B arith.basic.rad 176 B arith.modulo.rad 96 B arith.subword.rad 3.8 KiB arith.sum.rad 177 B arith.w64.rad 4.1 KiB array.assign.rad 221 B array.bounds.check.rad 321 B array.index.assign.rad 367 B array.index.rad 249 B array.length.rad 262 B array.math.rad 1.2 KiB array.nested.assign.rad 319 B array.nested.rad 325 B array.record.elements.rad 1.7 KiB array.repeat.edge.rad 548 B array.repeat.rad 828 B array.return.rad 330 B array.slice.empty.rad 108 B array.slice.gen.end.rad 126 B array.slice.gen.index.rad 139 B array.slice.gen.open.rad 125 B array.slice.gen.start.end.rad 127 B array.slice.gen.start.rad 126 B array.slice.rad 759 B as.precedence.rad 212 B assert.basic.rad 387 B assert.fail.rad 138 B assert.false.rad 140 B assert.true.rad 100 B assign.mutable.rad 6.1 KiB assign.rad 129 B assign.shadow.mutable.rad 461 B binop.bitwise.rad 1.2 KiB binop.cmp.rad 426 B bool.comparison.array.rad 688 B bool.comparison.nested.gen.rad 1.0 KiB bool.comparison.opt.rad 905 B bool.comparison.record.gen.rad 1.0 KiB bool.comparison.record.rad 1.1 KiB bool.comparison.slice.gen.rad 157 B bool.comparison.slice.rad 4.1 KiB bool.comparison.slice.record.gen.rad 2.0 KiB bool.comparison.slice.union.gen.rad 2.5 KiB bool.comparison.union.ctor.rad 690 B bool.comparison.union.gen.rad 1.2 KiB bool.comparison.union.record.gen.rad 1.5 KiB bool.comparison.union.simple.gen.rad 281 B bool.operators.complex.rad 384 B bool.operators.rad 831 B bool.short.circuit.rad 2.3 KiB bool.simple.rad 194 B bool.values.rad 772 B builtin.size.align.rad 1.3 KiB builtin.sliceof.mut.rad 606 B builtin.sliceof.rad 505 B call.arg.clobber.rad 717 B call.basic.rad 241 B call.clobber.rad 462 B cast.same.size.rad 1.0 KiB casting.numbers.rad 1.5 KiB char.literal.rad 165 B compound.assign.field.rad 285 B compound.assign.rad 1.1 KiB cond.assign.rad 723 B cond.expr.aggregate.rad 1.1 KiB cond.expr.rad 1.8 KiB cond.for.else.break.rad 326 B cond.for.indexed.rad 238 B cond.for.rad 165 B cond.for.range.indexed.rad 526 B cond.for.range.rad 171 B cond.for.unsigned.range.rad 644 B cond.forever.break.continue.rad 182 B cond.forever.break.rad 232 B cond.fused.rad 926 B cond.if.case.rad 2.2 KiB cond.if.else.min.rad 143 B cond.if.else.rad 225 B cond.if.elseif.rad 420 B cond.if.noelse.rad 120 B cond.if.rad 865 B cond.match.fallthrough.rad 369 B cond.match.guard.rad 1.4 KiB cond.match.guard.regalloc.rad 1.3 KiB cond.while.else.break.rad 282 B cond.while.rad 119 B const.array.copy.mutate.rad 386 B const.array.rad 195 B const.basic.rad 325 B const.char.rad 159 B const.fn.array.rad 664 B const.record.array.rad 1.2 KiB const.record.array.simple.rad 523 B const.record.ctor.rad 170 B const.record.fn.rad 353 B const.record.rad 182 B const.slice.param.rad 333 B const.union.payload.ctor.rad 349 B const.union.record.literal.rad 359 B data.array.rad 767 B data.bool.rad 216 B data.i16.rad 261 B data.i32.rad 281 B data.i8.rad 248 B data.record.rad 561 B data.simple.rad 436 B data.u16.rad 220 B data.u32.rad 240 B data.u8.rad 208 B data.union.rad 886 B debug.tag.rad 557 B edge.cases.2.rad 337 B edge.cases.3.rad 594 B edge.cases.4.rad 1.2 KiB edge.cases.5.rad 1.0 KiB edge.cases.6.rad 2.6 KiB edge.cases.7.addr.bug.rad 224 B edge.cases.8.bug.rad 508 B edge.cases.rad 223 B error.basic.rad 159 B error.catch.rad 1.6 KiB error.division.zero.rad 164 B error.modulo.zero.rad 162 B error.multi.basic.rad 672 B error.multi.catch.rad 772 B error.multi.catch.typed.binding.rad 791 B error.multi.catch.typed.catchall.rad 1.0 KiB error.multi.catch.typed.rad 1.1 KiB error.multi.propagate.multi.rad 953 B error.multi.propagate.rad 825 B error.multi.try.optional.rad 507 B error.slice.bounds.rad 219 B error.try.bang.success.rad 370 B error.try.catch.binding.rad 2.0 KiB error.try.optional.rad 1.8 KiB error.try.rad 4.0 KiB fn.block.scope.rad 508 B fn.callback.nested.rad 1.2 KiB fn.default.rad 131 B fn.local.rad 140 B fn.recursion.2.rad 239 B fn.void.rad 150 B for.else.continue.rad 1.1 KiB frame.large.rad 567 B if-let-mut.rad 1.1 KiB iflet.shadow.leak.rad 317 B integer.bitwise.basic.rad 693 B integer.overflow.rad 1.8 KiB large.blit.store.rad 2.1 KiB let.guard.rad 1.9 KiB literal.w64.rad 1.7 KiB loc.addr.offset.bug.rad 410 B loc.addr.opt.to.opt.rad 433 B loc.addr.optional.assign.rad 408 B loc.addr.record.assign.rad 443 B loop.complex.flow.rad 1007 B loop.sealblock.rad 911 B match.array.rad 3.4 KiB match.char.rad 1.6 KiB match.multi.seal.rad 987 B match.multi.survive.rad 1.6 KiB match.mutref.push.rad 1.0 KiB match.mutref.union.rad 662 B match.nested.call.rad 1.7 KiB match.nested.deep.rad 2.2 KiB match.nested.deref.rad 3.7 KiB match.nested.guard.rad 1.6 KiB match.nested.iflet.guard.rad 1.6 KiB match.nested.iflet.rad 1.4 KiB match.nested.letelse.rad 813 B match.nested.letelse.union.rad 1.3 KiB match.nested.literal.rad 3.1 KiB match.nested.multi.rad 2.4 KiB match.nested.pattern.rad 5.2 KiB match.nested.record.rad 2.0 KiB match.nested.union.rad 2.3 KiB match.nested.whilelet.rad 2.4 KiB match.string.rad 1.8 KiB match.value.copy.rad 2.0 KiB match.void.then.or.rad 1.6 KiB memzero.result.bug.rad 806 B memzero.union.bug.rad 576 B mutref.loop.bug.rad 1.8 KiB opt.assignment.bug.rad 1.3 KiB opt.bug.test.rad 1.4 KiB opt.if.let.complex.rad 6.2 KiB opt.if.let.guard.rad 809 B opt.if.let.rad 956 B opt.nil.check.rad 1.5 KiB opt.record.eq.rad 842 B opt.record.rad 655 B opt.return.array.rad 289 B opt.return.nested.rad 797 B opt.return.record.rad 344 B opt.slice.npo.rad 2.8 KiB opt.type.rad 200 B opt.while.let.complex.rad 404 B panic.rad 111 B placeholder.basic.rad 133 B placeholder.comprehensive.rad 562 B pointer.copy.edge.case.rad 1.3 KiB pointer.slice.index.rad 269 B pointer.slice.store.rad 881 B prog.ackermann.rad 5.0 KiB prog.bignum.rad 9.4 KiB prog.binsearch.rad 2.4 KiB prog.bubblesort.rad 2.0 KiB prog.cordic.rad 6.9 KiB prog.crc32.rad 2.7 KiB prog.dijkstra.rad 7.7 KiB prog.eval.rad 6.2 KiB prog.hanoi.rad 3.8 KiB prog.huffman.rad 9.3 KiB prog.hybridsort.rad 3.0 KiB prog.linkedlist.rad 5.8 KiB prog.lzw.rad 6.7 KiB prog.matmul.rad 2.9 KiB prog.mersenne.rad 5.2 KiB prog.nqueens.rad 3.4 KiB prog.rbtree.rad 8.2 KiB prog.regex.rad 10.2 KiB prog.sha256.rad 7.0 KiB prog.sieve.rad 2.8 KiB prog.symtab.rad 10.1 KiB prog.tokenizer.rad 13.8 KiB prog.vm.rad 17.4 KiB ptr.assign.rad 137 B ptr.deref.rad 622 B ptr.eq.rad 966 B ptr.mutate.rad 244 B ptr.opaque.rad 1.4 KiB record.access.rad 285 B record.alignment.rad 179 B record.array.elements.rad 1.7 KiB record.copy.rad 2.0 KiB record.field.assign.rad 184 B record.nested.calls.2.rad 612 B record.nested.calls.3.rad 734 B record.param.lit.rad 353 B record.ptr.access.rad 227 B record.ptr.mutate.rad 243 B record.shorthand.rad 1.5 KiB record.unlabeled.rad 407 B ref.if.bug.rad 519 B ref.immut.loop.bug.rad 670 B ref.mut.ptr.rad 261 B regalloc.callee.save.rad 1.5 KiB regalloc.spill.reuse.rad 473 B reserve.loop.rad 392 B result.void.success.rad 716 B slice.alloc.loop.rad 788 B slice.append.rad 3.3 KiB slice.cap.rad 941 B slice.delete.rad 971 B slice.of.rad 460 B slice.subslice.rad 1.4 KiB spill.blockarg.clobber.rad 3.5 KiB spill.loop.rad 1.6 KiB stack.local.corrupt.rad 320 B static.array.mutate.rad 387 B static.basic.rad 327 B static.fn.array.rad 628 B static.record.array.rad 503 B static.slice.index.assign.rad 408 B static.slice.offset.rad 668 B string.basic.rad 149 B string.escape.rad 349 B string.index.rad 116 B switch.blockargs.clobber.rad 1.3 KiB trait.aggregate.ret.rad 1.5 KiB trait.array.optional.rad 1.7 KiB trait.basic.rad 565 B trait.control.flow.rad 1.1 KiB trait.fn.param.rad 1.6 KiB trait.multiple.methods.rad 1.2 KiB trait.multiple.traits.rad 1.2 KiB trait.multiple.types.rad 1.3 KiB trait.supertrait.rad 2.5 KiB trait.throws.rad 1.0 KiB trait.writer.rad 2.6 KiB type.unify.rad 4.5 KiB undefined.rad 417 B union-tag.rad 911 B union.bitfield.rad 1.2 KiB union.discriminant.cast.rad 389 B union.edge.case.2.rad 679 B union.edge.case.3.rad 608 B union.mixed.assign.rad 977 B union.payload.mutref.rad 1.4 KiB union.payload.rad 580 B union.record.forward.rad 1.3 KiB union.void.match.rad 403 B union.void.rad 824 B unsigned.compare.rad 1.9 KiB var.align.rad 1013 B var.infer.rad 549 B decode.rad 14.6 KiB emit.rad 24.4 KiB encode.rad 19.9 KiB isel.rad 41.1 KiB printer.rad 13.0 KiB tests.rad 15.7 KiB rv64.rad 13.0 KiB collections/ lang/ sys/ arch.rad 65 B collections.rad 36 B fmt.rad 3.8 KiB intrinsics.rad 206 B io.rad 1.2 KiB lang.rad 222 B mem.rad 2.2 KiB sys.rad 167 B testing.rad 2.4 KiB tests.rad 11.6 KiB vec.rad 3.1 KiB std.rad 231 B scripts/ seed/ test/ vim/ .gitignore 353 B .gitsigners 112 B LICENSE 1.1 KiB Makefile 3.1 KiB README 2.5 KiB std.lib 987 B std.lib.test 252 B
lib/std/arch/rv64/tests/arith.subword.rad 3.8 KiB raw
1
//! Test sub-word arithmetic normalization.
2
//! Verifies that W8/W16 arithmetic results are properly sign/zero-extended,
3
//! and that W32 operations use the correct *w instruction variants.
4
5
fn testI8Overflow() -> bool {
6
    let a: i8 = 120;
7
    let b: i8 = 10;
8
    let result: i8 = a + b;
9
    // 120 + 10 = 130, which wraps to -126 in i8
10
    if result != -126 {
11
        return false;
12
    }
13
    return true;
14
}
15
16
fn testU8Overflow() -> bool {
17
    let a: u8 = 250;
18
    let b: u8 = 10;
19
    let result: u8 = a + b;
20
    // 250 + 10 = 260, which wraps to 4 in u8
21
    if result != 4 {
22
        return false;
23
    }
24
    return true;
25
}
26
27
fn testI8Subtraction() -> bool {
28
    let a: i8 = -100;
29
    let b: i8 = 50;
30
    let result: i8 = a - b;
31
    // -100 - 50 = -150, which wraps to 106 in i8
32
    if result != 106 {
33
        return false;
34
    }
35
    return true;
36
}
37
38
fn testU8Subtraction() -> bool {
39
    let a: u8 = 5;
40
    let b: u8 = 10;
41
    let result: u8 = a - b;
42
    // 5 - 10 = -5, which wraps to 251 in u8
43
    if result != 251 {
44
        return false;
45
    }
46
    return true;
47
}
48
49
fn testI16Overflow() -> bool {
50
    let a: i16 = 32000;
51
    let b: i16 = 1000;
52
    let result: i16 = a + b;
53
    // 32000 + 1000 = 33000, which wraps to -32536 in i16
54
    if result != -32536 {
55
        return false;
56
    }
57
    return true;
58
}
59
60
fn testU16Overflow() -> bool {
61
    let a: u16 = 65530;
62
    let b: u16 = 10;
63
    let result: u16 = a + b;
64
    // 65530 + 10 = 65540, which wraps to 4 in u16
65
    if result != 4 {
66
        return false;
67
    }
68
    return true;
69
}
70
71
fn testI8Multiply() -> bool {
72
    let a: i8 = 15;
73
    let b: i8 = 10;
74
    let result: i8 = a * b;
75
    // 15 * 10 = 150, which wraps to -106 in i8
76
    if result != -106 {
77
        return false;
78
    }
79
    return true;
80
}
81
82
fn testU8Multiply() -> bool {
83
    let a: u8 = 20;
84
    let b: u8 = 15;
85
    let result: u8 = a * b;
86
    // 20 * 15 = 300, which wraps to 44 in u8
87
    if result != 44 {
88
        return false;
89
    }
90
    return true;
91
}
92
93
fn testI8Comparison() -> bool {
94
    let a: i8 = 127;
95
    let b: i8 = a + 1;
96
    // b should be -128 after overflow
97
    if b >= 0 {
98
        return false;
99
    }
100
    if b != -128 {
101
        return false;
102
    }
103
    return true;
104
}
105
106
fn testU8Comparison() -> bool {
107
    let a: u8 = 255;
108
    let b: u8 = a + 1 as u8;
109
    // b should be 0 after overflow
110
    if b != 0 {
111
        return false;
112
    }
113
    return true;
114
}
115
116
fn testNarrowingCast() -> bool {
117
    let x: i32 = 1000;
118
    let narrow: u8 = x as u8;
119
    // 1000 = 0x3E8, lower byte = 0xE8 = 232
120
    if narrow != 232 {
121
        return false;
122
    }
123
    return true;
124
}
125
126
fn testW32ShiftRight() -> bool {
127
    let max: u32 = 0xFFFFFFFF;
128
    let shifted: u32 = max >> 16;
129
    // Should be 0xFFFF = 65535
130
    if shifted != 65535 {
131
        return false;
132
    }
133
    return true;
134
}
135
136
fn testI8NegOverflow() -> bool {
137
    let min: i8 = -128;
138
    let negated: i8 = -min;
139
    // RV64 should preserve i8 wrap behavior: -(-128) == -128
140
    if negated != -128 {
141
        return false;
142
    }
143
    return true;
144
}
145
146
fn testU8BitNot() -> bool {
147
    let x: u8 = 0;
148
    let inverted: u8 = ~x;
149
    // 8-bit not of 0 is 0xFF.
150
    if inverted != 255 {
151
        return false;
152
    }
153
    return true;
154
}
155
156
fn testW32ShiftLargeImmediate() -> bool {
157
    let x: u32 = 1;
158
    let shifted: u32 = x << 40;
159
    // Shift amount should be masked to 5 bits for 32-bit shifts: 40 % 32 = 8.
160
    if shifted != 256 {
161
        return false;
162
    }
163
    return true;
164
}
165
166
@default fn main() -> i32 {
167
    assert testI8Overflow();
168
    assert testU8Overflow();
169
    assert testI8Subtraction();
170
    assert testU8Subtraction();
171
    assert testI16Overflow();
172
    assert testU16Overflow();
173
    assert testI8Multiply();
174
    assert testU8Multiply();
175
    assert testI8Comparison();
176
    assert testU8Comparison();
177
    assert testNarrowingCast();
178
    assert testW32ShiftRight();
179
    assert testI8NegOverflow();
180
    assert testU8BitNot();
181
    assert testW32ShiftLargeImmediate();
182
    return 0;
183
}