Skip to content

Commit 18ff7fd

Browse files
committed
Add GCC15 notes, varargs tests, and ternary condition ABI selftest
1 parent af1dcbf commit 18ff7fd

12 files changed

Lines changed: 512 additions & 109 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14-
os: [ubuntu-latest, macos-latest]
15-
gcc-version: [9, 11]
14+
include:
15+
- os: ubuntu-latest
16+
gcc-version: 9
17+
- os: ubuntu-latest
18+
gcc-version: 11
19+
- os: macos-latest
20+
gcc-version: 14
21+
- os: macos-latest
22+
gcc-version: 15
1623

1724
steps:
1825
- uses: actions/checkout@v2
@@ -32,33 +39,6 @@ jobs:
3239
echo "CC=gcc-${{ matrix.gcc-version }}" >> $GITHUB_ENV
3340
echo "CXX=g++-${{ matrix.gcc-version }}" >> $GITHUB_ENV
3441
35-
- name: Build Plugin
36-
run: make
37-
38-
- name: Build Runtime
39-
run: |
40-
gcc -Iinclude -c runtime/ternary_runtime.c -o ternary_runtime.o
41-
4242
- name: Run Tests
4343
run: |
44-
cd tests
45-
chmod +x run_tests.sh
46-
./run_tests.sh
47-
# Compile ABI test
48-
gcc -I../include -c test_abi.c -o test_abi.o
49-
gcc test_abi.o ../runtime/ternary_runtime.o -o test_abi
50-
./test_abi
51-
# Compile promotion test
52-
gcc -fplugin=../ternary_plugin.so -fplugin-arg-ternary_plugin-types -I../include -c test_promotion.c -o test_promotion.o
53-
gcc test_promotion.o -o test_promotion
54-
./test_promotion
55-
# Sanity check
56-
gcc -c test_no_ternary.c -o test_no_ternary.o
57-
# Run benchmark
58-
gcc -I../include -c benchmark.c -o benchmark.o
59-
gcc benchmark.o ../runtime/ternary_runtime.o -o benchmark
60-
./benchmark
61-
# Edge cases
62-
gcc -I../include -c test_edge_cases.c -o test_edge_cases.o
63-
gcc test_edge_cases.o ../runtime/ternary_runtime.o -o test_edge_cases
64-
./test_edge_cases
44+
make test

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ To build the plugin, you need GCC with plugin support enabled.
9090
make
9191
```
9292

93+
On macOS, prefer Homebrew GCC and set the toolchain explicitly:
94+
95+
```bash
96+
make CXX=g++-15 CC=gcc-15
97+
```
98+
9399
Alternatively, with CMake (requires GMP and other deps):
94100

95101
```bash
@@ -110,6 +116,10 @@ Optional arguments:
110116

111117
- `-fplugin-arg-ternary_plugin-warn` emits a warning for each ternary operator.
112118
- `-fplugin-arg-ternary_plugin-stats` prints a summary at the end of compilation.
119+
- `-fplugin-arg-ternary_plugin-version` prints the plugin version and GCC version.
120+
- `-fplugin-arg-ternary_plugin-selftest` prints a brief self-test summary of enabled features.
121+
- `-fplugin-arg-ternary_plugin-trace` logs lowering decisions for matching statements.
122+
- `-fplugin-arg-ternary_plugin-dump-gimple` dumps matching GIMPLE statements before rewriting.
113123
- `-fplugin-arg-ternary_plugin-lower` replaces ternary operators with calls to
114124
`__ternary_select_[i|u]<bits>` for integral result types (e.g., `__ternary_select_i32`)
115125
and `__ternary_select_f32` or `__ternary_select_f64` for floating-point types.
@@ -128,6 +138,14 @@ Optional arguments:
128138
- `-fplugin-arg-ternary_plugin-prefix=<name>` sets the function name prefix used by `-lower`
129139
(default: `__ternary_select`).
130140

141+
Example with trace/dumps enabled:
142+
143+
```bash
144+
gcc -fplugin=./ternary_plugin.so -fplugin-arg-ternary_plugin-lower \
145+
-fplugin-arg-ternary_plugin-trace -fplugin-arg-ternary_plugin-dump-gimple \
146+
-Iinclude -c source.c
147+
```
148+
131149
## Implementing the Helpers
132150

133151
When using `-lower`, the plugin emits calls to external functions like `__ternary_select_i32`.
@@ -136,12 +154,15 @@ You need to provide implementations for these functions, tailored to your ternar
136154
Include `include/ternary_helpers.h` in your code, which provides example implementations using
137155
placeholder ternary ISA instructions (for example, `tsel`, `tadd`, `tmul`, `tnot`). Adjust the
138156
assembly to match your ISA. `TERNARY_COND_T` defines the condition type used by select helpers
139-
and must match the source condition type (defaults to `bool`).
157+
and is fixed to `ternary_cond_t` (default: `int64_t`). The plugin lowers conditions to
158+
`ternary_cond_t` before helper calls.
140159

141160
For testing without the plugin, the header provides C implementations of all ternary operations.
142161
Packed ternary types use a 2-bit encoding per trit (00 = -1, 01 = 0, 10 = +1).
143162
Define `TERNARY_USE_BUILTIN_TYPES` before including the header when compiling with
144163
`-fplugin-arg-ternary_plugin-types` to avoid typedef conflicts.
164+
Helper/runtime support is currently provided for t6/t12/t24 only; t48/t96/t192 require
165+
custom runtime implementations.
145166

146167
For example:
147168

@@ -165,7 +186,7 @@ gcc -fplugin=./ternary_plugin.so -fplugin-arg-ternary_plugin-lower -Iinclude -c
165186
For a minimal out-of-line runtime, use the reference implementation in `runtime/ternary_runtime.c`
166187
with the public header `include/ternary_runtime.h`. It implements the same packed 2-bit-trit
167188
semantics as the helpers (t6/t12/t24) and is intended as a starting point for a real ISA-backed
168-
library.
189+
library. Packed helpers for t48/t96/t192 are not provided in this reference runtime.
169190

170191
Example build:
171192

@@ -184,6 +205,12 @@ gcc -fplugin=./ternary_plugin.so -fplugin-arg-ternary_plugin-lower \
184205
-fplugin-arg-ternary_plugin-conv -Iinclude -c test_ternary.c
185206
```
186207

208+
On macOS, run:
209+
210+
```bash
211+
make test CXX=g++-15 CC=gcc-15
212+
```
213+
187214
## Description
188215

189216
This plugin analyzes ternary conditional expressions in the code and can optionally

ROADMAP.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Ternary GCC Plugin Roadmap
22

33
This roadmap focuses on getting a usable, testable ternary toolchain surfaced
4-
through a GCC plugin, with a stable ABI and runtime.
4+
through a GCC plugin, with a stable ABI and runtime on binary substrates.
55

66
## Phase 0: Baseline and Scope Lock
77

88
- Define supported GCC versions and host platforms.
99
- Freeze the ternary ABI surface (type sizes, packing, calling convention).
1010
- Decide on ternary XOR semantics and rounding rules for conversions.
11+
- Confirm the software-first contract (helpers as reference semantics).
1112

1213
Deliverables:
1314
- ABI section in `SPECIFICATION.md` finalized.
@@ -18,6 +19,7 @@ Deliverables:
1819
- Implement `__ternary_*` functions referenced by the plugin.
1920
- Provide a portable reference implementation in C/C++.
2021
- Define headers for builtins and public API.
22+
- Add container helpers for t6/t12/t24 and a plan for larger widths.
2123

2224
Deliverables:
2325
- `lib/` or `runtime/` with source and headers.
@@ -28,6 +30,7 @@ Deliverables:
2830
- Add user-facing types/macros and builtins in `include/ternary_plugin.h`.
2931
- Define how ternary literals and casts are written in C/C++.
3032
- Validate type promotion and conversion rules.
33+
- Lock down exact condition type handling in helper signatures.
3134

3235
Deliverables:
3336
- Updated header APIs and example usage in `README.md`.
@@ -83,7 +86,17 @@ Deliverables:
8386
- Compatibility matrix in `README.md`.
8487
- ABI validation step in CI.
8588

86-
## Phase 8: Extensions (Optional)
89+
## Phase 8: Optional Hardware Backend
90+
91+
- Define an ISA encoding that preserves the helper ABI semantics.
92+
- Add a codegen path that targets the hardware mnemonics.
93+
- Provide a fallback mechanism to the helper runtime when unavailable.
94+
95+
Deliverables:
96+
- Hardware backend design note and prototype.
97+
- Compatibility tests against the helper ABI.
98+
99+
## Phase 9: Extensions (Optional)
87100

88101
- Vector/packed ternary operations.
89102
- Ternary-aware optimizations (strength reduction, peepholes).

0 commit comments

Comments
 (0)