simple-sum.uir 723 Bytes
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1 2
// require "primitives.uir"

3
.funcsig @simplesum_sig = (@i64 @i64) -> ()
4 5
.funcdef @simplesum VERSION @simplesum_v1 <@simplesum_sig> {
    %entry (<@i64> %from <@i64> %to):
Kunshan Wang's avatar
Kunshan Wang committed
6
        [%starttrap] TRAP <>
7
        BRANCH %head(@I64_0 %from %to)
Kunshan Wang's avatar
Kunshan Wang committed
8

9
    %head(<@i64> %sum <@i64> %i <@i64> %to):
Kunshan Wang's avatar
Kunshan Wang committed
10
        %le  = SLE <@i64> %i %to
11
        BRANCH2 %le %body(%sum %i %to) %exit(%sum)
Kunshan Wang's avatar
Kunshan Wang committed
12
        
13
    %body(<@i64> %sum <@i64> %i <@i64> %to):
Kunshan Wang's avatar
Kunshan Wang committed
14 15
        %sum2 = ADD <@i64> %sum %i
        %i2   = ADD <@i64> %i @I64_1
16
        BRANCH %head(%sum2 %i2 %to)
Kunshan Wang's avatar
Kunshan Wang committed
17
        //[%montrap] TRAP <> %head %head KEEPALIVE (%from %to %sum %i %le %sum2 %i2)
Kunshan Wang's avatar
Kunshan Wang committed
18

19
    %exit(<@i64> %sum):
Kunshan Wang's avatar
Kunshan Wang committed
20
        [%exittrap] TRAP <> KEEPALIVE (%sum)
Kunshan Wang's avatar
Kunshan Wang committed
21 22
        COMMINST @uvm.thread_exit
}