Integer subtraction with borrow flags.

This is the x86-style of borrow flags. ARM uses subtract-with-carry
which inverts the sense of the carry flag.
This commit is contained in:
Jakob Stoklund Olesen
2016-09-23 15:47:39 -07:00
parent 9cb3451432
commit f66d84fd95
2 changed files with 82 additions and 8 deletions

View File

@@ -11,3 +11,14 @@ ebb1(v1: i32, v2: i32, v3: i32, v4: i32, v5: i32, v6: i32):
; check: $v30 = iadd_cin $v3, $v6, $v21 ; check: $v30 = iadd_cin $v3, $v6, $v21
return v10, v20, v30 return v10, v20, v30
} }
function sub_i96(i32, i32, i32, i32, i32, i32) -> i32, i32, i32 {
ebb1(v1: i32, v2: i32, v3: i32, v4: i32, v5: i32, v6: i32):
v10, v11 = isub_bout v1, v4
;check: $v10, $v11 = isub_bout $v1, $v4
v20, v21 = isub_borrow v2, v5, v11
; check: $v20, $v21 = isub_borrow $v2, $v5, $v11
v30 = isub_bin v3, v6, v21
; check: $v30 = isub_bin $v3, $v6, $v21
return v10, v20, v30
}

View File

@@ -406,24 +406,30 @@ isub_imm = Instruction(
ins=(X, y), outs=a) ins=(X, y), outs=a)
# #
# Integer arithmetic with carry. # Integer arithmetic with carry and/or borrow.
# #
a = Operand('a', iB) a = Operand('a', iB)
x = Operand('x', iB) x = Operand('x', iB)
y = Operand('y', iB) y = Operand('y', iB)
cin = Operand('cin', b1, doc="Input carry flag") c_in = Operand('c_in', b1, doc="Input carry flag")
cout = Operand('cout', b1, doc="Output carry flag") c_out = Operand('c_out', b1, doc="Output carry flag")
b_in = Operand('b_in', b1, doc="Input borrow flag")
b_out = Operand('b_out', b1, doc="Output borrow flag")
iadd_cin = Instruction( iadd_cin = Instruction(
'iadd_cin', """ 'iadd_cin', """
Add integers with carry in. Add integers with carry in.
Same as :inst:`iadd` with an additional carry input. Same as :inst:`iadd` with an additional carry input. Computes:
.. math::
a = x + y + c_{in} \pmod 2^B
Polymorphic over all scalar integer types, but does not support vector Polymorphic over all scalar integer types, but does not support vector
types. types.
""", """,
ins=(x, y, cin), outs=a) ins=(x, y, c_in), outs=a)
iadd_cout = Instruction( iadd_cout = Instruction(
'iadd_cout', """ 'iadd_cout', """
@@ -431,21 +437,78 @@ iadd_cout = Instruction(
Same as :inst:`iadd` with an additional carry output. Same as :inst:`iadd` with an additional carry output.
.. math::
a &= x + y \pmod 2^B \\
c_{out} &= x+y >= 2^B
Polymorphic over all scalar integer types, but does not support vector Polymorphic over all scalar integer types, but does not support vector
types. types.
""", """,
ins=(x, y), outs=(a, cout)) ins=(x, y), outs=(a, c_out))
iadd_carry = Instruction( iadd_carry = Instruction(
'iadd_carry', """ 'iadd_carry', """
Add integers with carry in and out. Add integers with carry in and out.
Same as :inst:`iadd` with an additional carry output. Same as :inst:`iadd` with an additional carry input and output.
.. math::
a &= x + y + c_{in} \pmod 2^B \\
c_{out} &= x + y + c_{in} >= 2^B
Polymorphic over all scalar integer types, but does not support vector Polymorphic over all scalar integer types, but does not support vector
types. types.
""", """,
ins=(x, y, cin), outs=(a, cout)) ins=(x, y, c_in), outs=(a, c_out))
isub_bin = Instruction(
'isub_bin', """
Subtract integers with borrow in.
Same as :inst:`isub` with an additional borrow flag input. Computes:
.. math::
a = x - (y + b_{in}) \pmod 2^B
Polymorphic over all scalar integer types, but does not support vector
types.
""",
ins=(x, y, b_in), outs=a)
isub_bout = Instruction(
'isub_bout', """
Subtract integers with borrow out.
Same as :inst:`isub` with an additional borrow flag output.
.. math::
a &= x - y \pmod 2^B \\
b_{out} &= x < y
Polymorphic over all scalar integer types, but does not support vector
types.
""",
ins=(x, y), outs=(a, b_out))
isub_borrow = Instruction(
'isub_borrow', """
Subtract integers with borrow in and out.
Same as :inst:`isub` with an additional borrow flag input and output.
.. math::
a &= x - (y + b_{in}) \pmod 2^B \\
b_{out} &= x < y + b_{in}
Polymorphic over all scalar integer types, but does not support vector
types.
""",
ins=(x, y, b_in), outs=(a, b_out))
# #
# Bitwise operations. # Bitwise operations.