Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 12 additions & 12 deletions emulation/rocjitsu/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ Before writing new infrastructure, check these existing libraries:
- **Intrusive list** — `util/intrusive_list.h` for linked data structures
that need O(1) insert/erase without heap allocation per node.
- **Arena allocator** — `util/arena_alloc.h` for fixed-size block pools.
- **Exceptions** — `util/except.h` for `InvalidInst`, `UnimplementedInst`,
`ConfigError`.
- **Expected failures** — Return `Result` or `FailureOr<T>` and accept a
`DiagnosticEmitter` when the caller needs a reason. Its sink is non-owning
and must not outlive its callable.
- **Exceptions** — `util/except.h` for unrecoverable initialization,
configuration, and execution failures.
- **Register sets** — `isa/register_set.h` for ISA-independent register
file modeling (SGPR/VGPR/AccVGPR bitsets).
- **Spill manager** — `code/patch/spill_manager.h` for scratch layout
Expand Down Expand Up @@ -88,16 +91,13 @@ Before writing new infrastructure, check these existing libraries:
`stderr` — it runs inside another runtime's `OnLoad`, its messages must
survive a log-groups-OFF build, and its signal-backtrace path must stay
async-signal-safe (`rj_hsa_dbt_hooks.cpp` uses raw `::write`).
- **Exceptions.** Exceptions are used only for unrecoverable errors
during initialization and configuration (`ConfigError`) or when
encountering invalid/unimplemented instructions during code object
parsing (`InvalidInst`, `UnimplementedInst`). All exception types
live in `util/except.h`. Do not throw exceptions in simulation hot
paths (event handlers, instruction execution, cache lookups). Do not
add `try`/`catch` blocks unless you are at a boundary that must
translate an error (e.g., the C API layer). There is no general
exception safety guarantee — assume code is not exception-safe
unless explicitly documented.
- **Errors.** Expected failures such as a rejected instruction encoding return
`Result` or `FailureOr<T>` and optionally emit a diagnostic. Exceptions are
reserved for unrecoverable initialization, configuration, or execution
failures. Do not throw exceptions in simulation hot paths (event handlers,
instruction execution, cache lookups). Do not add `try`/`catch` blocks unless
you are at a boundary that must translate an error (e.g., the C API layer).
There is no general exception safety guarantee unless explicitly documented.

## ISA codegen workflow

Expand Down
9 changes: 5 additions & 4 deletions emulation/rocjitsu/docs/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ Foo foo = static_cast<Foo>(bar); // OK but could use auto instead to avoid repet

## Error Handling

- Exceptions are only for unrecoverable errors: initialization/configuration
failures (`ConfigError`) and invalid or unimplemented instructions during
code-object parsing (`InvalidInst`, `UnimplementedInst`). All exception types
live in `util/except.h`.
- Expected failures such as a rejected instruction encoding return `Result` or
`FailureOr<T>`. Accept a `DiagnosticEmitter` when the caller needs the reason;
its sink is non-owning and must not outlive its callable.
- Exceptions are only for unrecoverable initialization, configuration, or
execution failures. Exception types live in `util/except.h`.
- Do not throw in simulation hot paths (event handlers, instruction execution,
cache lookups).
- Do not add `try`/`catch` except at a boundary that must translate an error
Expand Down
2 changes: 1 addition & 1 deletion emulation/rocjitsu/fuzz/decode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ninja -C build-decode-afl rj_decode_fuzz
build-decode-afl/fuzz/decode/rj_decode_fuzz --afl --target gfx1250
```

`InvalidInst` is an ordinary rejection. Other exceptions, signals, sanitizer
Decoder failure is an ordinary rejection. Exceptions from unrelated failures, signals, sanitizer
findings, and decoder invariant failures remain crashes for AFL++ to retain.

## Offline LLVM comparison
Expand Down
14 changes: 5 additions & 9 deletions emulation/rocjitsu/fuzz/decode/decode_fuzz_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "rocjitsu/isa/instruction.h"
#include "rocjitsu/isa/operand.h"
#include "rocjitsu/isa/target_registry.h"
#include "util/except.h"

#include <array>
#include <cstdlib>
Expand Down Expand Up @@ -91,17 +90,14 @@ DecodeRecord decode_window(Decoder &decoder, std::span<const uint8_t> bytes) {
words[word] |= static_cast<uint32_t>(bytes[word * sizeof(uint32_t) + byte]) << (byte * 8);
}

std::unique_ptr<Instruction> inst;
try {
inst.reset(decoder.decode(words.data()));
} catch (const util::InvalidInst &error) {
util::StringDiagnostic rejection;
DecodeResult decoded = decoder.decode(words.data(), rejection.emitter());
if (decoded.failed()) {
DecodeRecord record;
record.rejection = error.what();
record.rejection = rejection.message();
return record;
}

if (!inst)
fail_invariant("a successful decode returned null");
std::unique_ptr<Instruction> inst = std::move(decoded).value();

const int size = inst->size();
if (size != 4 && size != 8 && size != 12 && size != 16)
Expand Down
Loading
Loading