Files
wasmtime/cranelift/filetests/filetests/runtests/fibonacci.clif
Afonso Bordado 7a9078d9cc cranelift: Allow call and call_indirect in runtests (#4667)
* cranelift: Change test runner order

Changes the ordering of runtests to run per target and then per function.

This change doesn't do a lot by itself, but helps future refactorings of runtests.

* cranelift: Rename SingleFunctionCompiler to TestCaseCompiler

* cranelift: Skip runtests per target instead of per run

* cranelift: Deduplicate test names

With the upcoming changes to the runtest infrastructure we require unique ExtNames for all tests.

Note that for test names we have a 16 character limit on test names, and must be unique within those 16 characters.

* cranelift: Add TestFileCompiler to runtests

TestFileCompiler allows us to compile the entire file once, and then call the trampolines for each test.

The previous code was compiling the function for each invocation of a test.

* cranelift: Deduplicate ExtName for avg_round tests

* cranelift: Rename functions as they are defined.

The JIT internally only deals with User functions, and cannot link test name funcs.

This also caches trampolines by signature.

* cranelift: Preserve original name when reporting errors.

* cranelift: Rename aarch64 test functions

* cranelift: Add `call` and `call_indirect` tests!

* cranelift: Add pauth runtests for aarch64

* cranelift: Rename duplicate s390x tests

* cranelift: Delete `i128_bricmp_of` function from i128-bricmp

It looks like we forgot to delete it when it was moved to
`i128-bricmp-overflow`, and since it didn't have a run invocation
it was never compiled.

However, s390x does not support this, and panics when lowering.

* cranelift: Add `colocated` call tests

* cranelift: Rename *more* `s390x` tests

* cranelift: Add pauth + sign_return_address call tests

* cranelift: Undeduplicate test names

With the latest main changes we now support *unlimited* length test names.

This commit reverts:
52274676ff631c630f9879dd32e756566d3e700f
7989edc172493547cdf63e180bb58365e8a43a42
25c8a8395527d98976be6a34baa3b0b214776739
792e8cfa8f748077f9d80fe7ee5e958b7124e83b

* cranelift: Add LibCall tests

* cranelift: Revert more test names

These weren't auto reverted by the previous revert.

* cranelift: Disable libcall tests for aarch64

* cranelift: Runtest fibonacci tests

* cranelift: Misc cleanup
2022-08-26 12:42:16 -07:00

71 lines
1.6 KiB
Plaintext

test interpret
test run
target x86_64
target aarch64
target aarch64 sign_return_address
target aarch64 has_pauth sign_return_address
target s390x
; A non-recursive fibonacci implementation.
function %fibonacci(i32) -> i32 {
block0(v0: i32):
v1 = icmp_imm ule v0, 2
v2 = iconst.i32 1
brnz v1, block3(v2) ; handle base case, n <= 2
jump block1(v0, v2)
block1(v4: i32, v5:i32):
v6 = iconst.i32 1
v7 = iadd_imm v4, -2
jump block2(v7, v5, v6)
block2(v10: i32, v11: i32, v12: i32): ; params: n, fib(n-1), fib(n-2)
v13 = iadd v11, v12
v14 = iadd_imm v10, -1
v15 = icmp_imm eq v14, 0
brnz v15, block3(v13)
jump block2(v14, v13, v11)
block3(v20: i32): ; early return and end of loop
return v20
}
; run: %fibonacci(0) == 1
; run: %fibonacci(1) == 1
; run: %fibonacci(2) == 1
; run: %fibonacci(3) == 2
; run: %fibonacci(4) == 3
; run: %fibonacci(5) == 5
; run: %fibonacci(6) == 8
; run: %fibonacci(10) == 55
; A recursive fibonacci implementation.
function %fibonacci_recursive(i32) -> i32 {
fn0 = %fibonacci_recursive(i32) -> i32
block0(v0: i32):
v1 = icmp_imm ule v0, 2
brnz v1, block2
jump block1(v0)
block1(v10: i32):
v11 = iadd_imm v10, -1
v12 = call fn0(v11)
v13 = iadd_imm v10, -2
v14 = call fn0(v13)
v15 = iadd v12, v14
return v15
block2:
v20 = iconst.i32 1
return v20
}
; run: %fibonacci_recursive(0) == 1
; run: %fibonacci_recursive(1) == 1
; run: %fibonacci_recursive(2) == 1
; run: %fibonacci_recursive(3) == 2
; run: %fibonacci_recursive(4) == 3
; run: %fibonacci_recursive(5) == 5
; run: %fibonacci_recursive(6) == 8
; run: %fibonacci_recursive(10) == 55