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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,8 @@ src/simulate/simulate_fusion_op2_bin_vec.cpp
src/simulate/simulate_fusion_op2_scalar_vec.cpp
src/simulate/simulate_fusion_at.cpp
src/simulate/simulate_fusion_at_array.cpp
src/simulate/simulate_fusion_ptr_at.cpp
src/simulate/simulate_fusion_widen.cpp
src/simulate/simulate_fusion_tableindex.cpp
src/simulate/simulate_fusion_tablewithhash.cpp
src/simulate/simulate_fusion_misc_copy.cpp
Expand Down
9 changes: 9 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,16 @@ Small-table regime micro-benchmarks (N from 1 to 64) - the load profile the larg

| File | Description |
|---|---|
| `bench_arr_at_i64.das` | Array read and write with an `int`, `int64` and `uint64` index, same loop shape for all three |
| `bench_double_index.das` | A table indexed by an element of another table: fixed arrays and arrays of `int` and `uint8`, local, global and argument; the Doom column loops through global `uint8` pointers; a class-then-transition automaton step |
| `bench_global_at.das` | Global array and global fixed array read and write by index in a context that is not solid (the global is found by name hash) |
| `bench_global_local_op2.das` | A global combined with a local in a binary operation under `options solid_context` |
| `bench_ptr_at.das` | `p[i]` read through a pointer: local, argument, global and field pointer; local, expression, constant and `uint` index; `int`, `uint8` and `float3` elements |
| `bench_ptr_set.das` | `p[i] = value` and `*p = value` through a pointer, `int` and `uint8` elements, with and without a narrowing cast on the value |
| `bench_small_int_at.das` | Array and fixed-array read of `uint8`, `uint16` and `int16` elements cast to `int` or `uint` |
| `bench_table_index_i64.das` | Table read with an `int`, `int64` and `uint64` key, same loop shape for all three |
| `bench_v_ldu.das` | Fusion-engine `Op2At` array-indexed read at sizeof(T) in {4,8,12,16} - int, int64, float3, float4. Used to compare DAS_FUSION=0 vs current `DAS_LDU_WORKHORSE` ladder vs `v_zero+memcpy(sizeof(CTYPE))` |
| `bench_widen_read.das` | A small int cast to `int` or `uint` when read from a loop variable, a field of a loop variable, a local struct field and an argument struct field |

## sql/

Expand Down
158 changes: 158 additions & 0 deletions benchmarks/fusion/bench_double_index.das
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
options gen2
options persistent_heap

require dastest/testing_boost

let N = 10000
let OUTER = 10
let TOTAL = N * OUTER
let STATES = 64

var g_lut : int[256]
var g_remap : int[256]
var g_bytes : uint8[256]
var g_colormap : uint8?
var g_translation : uint8?
var g_source : uint8?

def sum_argument_arrays(lut_array, remap_array : array<int>) {
var sum = 0
for (_j in range(OUTER)) {
for (i in range(N)) {
sum += lut_array[remap_array[i & 255]]
}
}
return sum
}

def run_automaton(classes : uint8 const?; transitions : int const?; input : uint8 const?) {
var state = 0
for (_j in range(OUTER)) {
for (i in range(N)) {
unsafe {
let c = int(classes[int(input[i])])
state = transitions[state * STATES + c]
}
}
}
return state
}

[benchmark]
def double_index_tables(b : B?) {
var lut, remap : int[256]
var bytes : uint8[256]
for (i in range(256)) {
lut[i] = i
remap[i] = 255 - i
bytes[i] = uint8(255 - i)
g_lut[i] = i
g_remap[i] = 255 - i
g_bytes[i] = uint8(255 - i)
}
let lut_array <- [for (i in range(256)); i]
let remap_array <- [for (i in range(256)); 255 - i]
var expected = 0
for (i in range(N)) {
expected += 255 - (i & 255)
}
expected *= OUTER
b |> run("local_fixed_int_of_int/{TOTAL}", TOTAL) {
var sum = 0
for (_j in range(OUTER)) {
for (i in range(N)) {
sum += lut[remap[i & 255]]
}
}
b |> equal(sum, expected)
}
b |> run("local_fixed_int_of_uint8/{TOTAL}", TOTAL) {
var sum = 0
for (_j in range(OUTER)) {
for (i in range(N)) {
sum += lut[int(bytes[i & 255])]
}
}
b |> equal(sum, expected)
}
b |> run("global_fixed_int_of_int/{TOTAL}", TOTAL) {
var sum = 0
for (_j in range(OUTER)) {
for (i in range(N)) {
sum += g_lut[g_remap[i & 255]]
}
}
b |> equal(sum, expected)
}
b |> run("global_fixed_int_of_uint8/{TOTAL}", TOTAL) {
var sum = 0
for (_j in range(OUTER)) {
for (i in range(N)) {
sum += g_lut[int(g_bytes[i & 255])]
}
}
b |> equal(sum, expected)
}
b |> run("argument_array_int_of_int/{TOTAL}", TOTAL) {
b |> equal(sum_argument_arrays(lut_array, remap_array), expected)
}
}

[benchmark]
def double_index_pointers(b : B?) {
var colormap <- [for (i in range(256)); uint8(255 - i)]
var translation <- [for (i in range(256)); uint8(i ^ 1)]
var source <- [for (i in range(128)); uint8(i * 2)]
var screen : array<uint8>
screen |> resize(N)
g_colormap = unsafe(addr(colormap[0]))
g_translation = unsafe(addr(translation[0]))
g_source = unsafe(addr(source[0]))
let dest = unsafe(addr(screen[0]))
b |> run("doom_column/{TOTAL}", TOTAL) {
for (_j in range(OUTER)) {
var frac = 0
var dest_addr : uint64 = unsafe(reinterpret<uint64>(dest))
for (_i in range(N)) {
unsafe {
*reinterpret<uint8?>(dest_addr) = g_colormap[int(g_source[frac >> 16 & 127])]
}
dest_addr++
frac += 40000
}
}
b |> equal(int(screen[0]), 255)
}
b |> run("doom_translated_column/{TOTAL}", TOTAL) {
for (_j in range(OUTER)) {
var frac = 0
var dest_addr : uint64 = unsafe(reinterpret<uint64>(dest))
for (_i in range(N)) {
unsafe {
*reinterpret<uint8?>(dest_addr) = g_colormap[int(g_translation[
int(g_source[frac >> 16 & 127])])]
}
dest_addr++
frac += 40000
}
}
b |> equal(int(screen[0]), 254)
}
g_colormap = null
g_translation = null
g_source = null
}

[benchmark]
def double_index_automaton(b : B?) {
var classes <- [for (i in range(256)); uint8(i & (STATES - 1))]
var transitions <- [for (i in range(STATES * STATES)); (i * 7 + 3) & (STATES - 1)]
var input <- [for (i in range(N)); uint8((i * 31) & 255)]
let pclasses = unsafe(addr(classes[0]))
let ptransitions = unsafe(addr(transitions[0]))
let pinput = unsafe(addr(input[0]))
let expected = run_automaton(pclasses, ptransitions, pinput)
b |> run("class_then_transition/{TOTAL}", TOTAL) {
b |> equal(run_automaton(pclasses, ptransitions, pinput), expected)
}
}
60 changes: 60 additions & 0 deletions benchmarks/fusion/bench_global_at.das
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
options gen2
options persistent_heap

require dastest/testing_boost

let N = 10000
let OUTER = 10
let TOTAL = N * OUTER

var g_values : array<int>
var g_table : int[1024]

[benchmark]
def global_at(b : B?) {
delete g_values
g_values <- [for (i in range(N)); i & 1023]
for (i in range(1024)) {
g_table[i] = i
}
var expected = 0
for (v in g_values) {
expected += v
}
expected *= OUTER
b |> run("array_local_idx/{TOTAL}", TOTAL) {
var sum = 0
for (_j in range(OUTER)) {
for (i in range(N)) {
sum += g_values[i]
}
}
b |> equal(sum, expected)
}
b |> run("array_expr_idx/{TOTAL}", TOTAL) {
var sum = 0
for (_j in range(OUTER)) {
for (i in range(N)) {
sum += g_values[N - 1 - i]
}
}
b |> equal(sum, expected)
}
b |> run("fixed_expr_idx/{TOTAL}", TOTAL) {
var sum = 0
for (_j in range(OUTER)) {
for (i in range(N)) {
sum += g_table[i & 1023]
}
}
b |> equal(sum, expected)
}
b |> run("fixed_write_expr_idx/{TOTAL}", TOTAL) {
for (_j in range(OUTER)) {
for (i in range(N)) {
g_table[i & 1023] = i
}
}
b |> equal(g_table[0], 9216)
}
}
41 changes: 41 additions & 0 deletions benchmarks/fusion/bench_global_local_op2.das
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
options gen2
options persistent_heap
options solid_context = true

require dastest/testing_boost

let N = 10000
let OUTER = 10
let TOTAL = N * OUTER

var g_scale = 3
var g_bias = 0.5

[benchmark]
def global_op_local(b : B?) {
var expected = 0
for (i in range(N)) {
expected += g_scale * i
}
expected *= OUTER
b |> run("int_mul/{TOTAL}", TOTAL) {
var sum = 0
for (_j in range(OUTER)) {
for (i in range(N)) {
sum += g_scale * i
}
}
b |> equal(sum, expected)
}
b |> run("float_add/{TOTAL}", TOTAL) {
var sum = 0.0
for (_j in range(OUTER)) {
var x = 0.0
for (_i in range(N)) {
x = g_bias + x
}
sum += x
}
b |> equal(sum > 0.0, true)
}
}
Loading
Loading