-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunc_rsh.go
60 lines (51 loc) · 940 Bytes
/
func_rsh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package fgbase
import (
"reflect"
)
func rshFire2(a, b interface{}) interface{} {
switch a.(type) {
case uint8:
{
return a.(uint8) >> b.(uint8)
}
case uint16:
{
return a.(uint16) >> b.(uint16)
}
case uint32:
{
return a.(uint32) >> b.(uint32)
}
case uint64:
{
return a.(uint64) >> b.(uint64)
}
case uint:
{
return a.(uint) >> b.(uint)
}
default:
{
return nil
}
}
}
// Right shift primitive
func rshFire(n *Node) error {
a := n.Srcs[0]
b := n.Srcs[1]
x := n.Dsts[0]
aTmp, bTmp, same := Promote(n, a.SrcGet(), b.SrcGet())
if !same {
n.LogError("incompatible types for right shift (%v>>%v)", reflect.TypeOf(a.Val), reflect.TypeOf(b.Val))
x.DstPut(nil)
} else {
x.DstPut(rshFire2(aTmp, bTmp))
}
return nil
}
// FuncRsh right shifts a value(x = a >> b).
func FuncRsh(a, b, x Edge) Node {
node := MakeNode("rsh", []*Edge{&a, &b}, []*Edge{&x}, nil, rshFire)
return node
}