Implement shifting with a differently-sized integer
Этот коммит содержится в:
родитель
337e48270b
коммит
8fb9cd4e23
1 изменённых файлов: 19 добавлений и 7 удалений
12
compiler.go
12
compiler.go
|
@ -1530,6 +1530,15 @@ func (c *Compiler) parseBinOp(frame *Frame, binop *ssa.BinOp) (llvm.Value, error
|
|||
return c.builder.CreateOr(x, y, ""), nil
|
||||
case token.XOR: // ^
|
||||
return c.builder.CreateXor(x, y, ""), nil
|
||||
case token.SHL, token.SHR:
|
||||
sizeX := c.targetData.TypeAllocSize(x.Type())
|
||||
sizeY := c.targetData.TypeAllocSize(y.Type())
|
||||
if sizeX > sizeY {
|
||||
// x and y must have equal sizes, make Y bigger in this case.
|
||||
// y is unsigned, this has been checked by the Go type checker.
|
||||
y = c.builder.CreateZExt(y, x.Type(), "")
|
||||
}
|
||||
switch binop.Op {
|
||||
case token.SHL: // <<
|
||||
return c.builder.CreateShl(x, y, ""), nil
|
||||
case token.SHR: // >>
|
||||
|
@ -1538,6 +1547,9 @@ func (c *Compiler) parseBinOp(frame *Frame, binop *ssa.BinOp) (llvm.Value, error
|
|||
} else {
|
||||
return c.builder.CreateLShr(x, y, ""), nil
|
||||
}
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
case token.AND_NOT: // &^
|
||||
// Go specific. Calculate "and not" with x & (~y)
|
||||
inv := c.builder.CreateNot(y, "") // ~y
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче