2026-08-13 11:24:44 +02:00
|
|
|
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
|
|
|
|
#include "textflag.h"
|
|
|
|
|
|
|
|
|
|
// add returns a + b.
|
|
|
|
|
TEXT ·add(SB), NOSPLIT, $0-24
|
2026-09-17 20:33:18 +02:00
|
|
|
MOVV a+0(FP), R4
|
|
|
|
|
MOVV b+8(FP), R5
|
|
|
|
|
ADDV R5, R4, R4
|
|
|
|
|
MOVV R4, ret+16(FP)
|
2026-08-13 11:24:44 +02:00
|
|
|
RET
|
|
|
|
|
|
|
|
|
|
// arith exercises the 3R integer and FP set.
|
|
|
|
|
TEXT ·arith(SB), NOSPLIT, $0-0
|
2026-09-17 20:33:18 +02:00
|
|
|
ADDV R4, R5, R6
|
|
|
|
|
SUBV R7, R8, R9
|
|
|
|
|
MULV R10, R11, R12
|
|
|
|
|
DIVV R13, R14, R15
|
|
|
|
|
AND R16, R17, R18
|
|
|
|
|
OR R18, R19, R20
|
|
|
|
|
XOR R20, R21, R2
|
|
|
|
|
SLLV R2, R23, R24
|
|
|
|
|
SRLV R24, R25, R26
|
|
|
|
|
SRAV R26, R27, R28
|
2026-08-13 11:24:44 +02:00
|
|
|
RET
|
|
|
|
|
|
|
|
|
|
// imm exercises the immediate forms.
|
|
|
|
|
TEXT ·imm(SB), NOSPLIT, $0-0
|
2026-09-17 20:33:18 +02:00
|
|
|
ADDV $42, R4, R5
|
|
|
|
|
ADDV $-8, R6
|
|
|
|
|
AND $0xff, R7, R8
|
|
|
|
|
OR $1, R9, R10
|
|
|
|
|
XOR $0, R11, R12
|
|
|
|
|
SGT $100, R13, R14
|
|
|
|
|
SLLV $4, R15, R16
|
|
|
|
|
MOVV $0x12345, R17
|
2026-08-13 11:24:44 +02:00
|
|
|
RET
|
|
|
|
|
|
2026-09-20 00:57:02 +02:00
|
|
|
// branch exercises conditional and unconditional control flow. Every
|
|
|
|
|
// path must terminate: the smoke harness calls functions with a zeroed
|
|
|
|
|
// argument block, and a $0-0 function's registers carry whatever the
|
|
|
|
|
// caller left, so a branch maze can reach any label.
|
2026-08-13 11:24:44 +02:00
|
|
|
TEXT ·branch(SB), NOSPLIT, $0-0
|
2026-09-17 20:33:18 +02:00
|
|
|
BEQ R4, R5, done
|
|
|
|
|
BNE R6, R7, skip
|
|
|
|
|
BLT R8, R9, done
|
|
|
|
|
BGE R10, R11, done
|
|
|
|
|
BLTU R12, R13, done
|
|
|
|
|
BGEU R14, R15, done
|
|
|
|
|
|
2026-08-13 11:24:44 +02:00
|
|
|
skip:
|
2026-09-17 20:33:18 +02:00
|
|
|
JMP loop
|
|
|
|
|
|
2026-08-13 11:24:44 +02:00
|
|
|
loop:
|
2026-09-20 00:57:02 +02:00
|
|
|
JAL fin
|
|
|
|
|
RET
|
|
|
|
|
|
|
|
|
|
fin:
|
2026-08-13 11:24:44 +02:00
|
|
|
RET
|
2026-09-17 20:33:18 +02:00
|
|
|
|
2026-08-13 11:24:44 +02:00
|
|
|
done:
|
|
|
|
|
RET
|