Skip to content

Commit ba20b35

Browse files
committed
upstream CI: support Apple Clang before macOS 15, fix #516
1 parent 30ab5f6 commit ba20b35

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

constantine/platforms/isa_arm64/macro_assembler_arm64.nim

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,29 @@ func setOutputToFlag*(a: var Assembler_arm64, outputFlag: NimNode, carryOrBorrow
373373
else: outputFlag
374374
let symStr = $nimSymbol
375375

376-
let desc = OperandDesc(
377-
asmId: "",
378-
nimSymbol: ident(symStr),
379-
rm: carryOrBorrow,
380-
constraint: asmOutputOverwrite)
381-
desc.setConstraintDesc(nimSymbol)
382-
a.operands.incl(desc)
376+
if false:
377+
# Unsupported before MacOS 15 (Apple Clang 16) and before Clang 17:
378+
# https://github.com/mratsim/constantine/issues/516
379+
# https://reviews.llvm.org/D149123
380+
let desc = OperandDesc(
381+
asmId: "",
382+
nimSymbol: ident(symStr),
383+
rm: carryOrBorrow,
384+
constraint: asmOutputOverwrite)
385+
desc.setConstraintDesc(nimSymbol)
386+
a.operands.incl(desc)
387+
else:
388+
let cc = if carryOrBorrow == CarryFlag: ConditionCode.cs
389+
else: ConditionCode.cc
390+
let asmId = "[" & $nimSymbol & "]"
391+
a.code &= "cset %" & asmId & ", " & $cc & '\n'
392+
let desc = OperandDesc(
393+
asmId: asmId,
394+
nimSymbol: ident(symStr),
395+
rm: Reg,
396+
constraint: asmOutputOverwrite)
397+
desc.setConstraintDesc(nimSymbol)
398+
a.operands.incl(desc)
383399

384400
func generate*(a: Assembler_arm64): NimNode =
385401
## Generate the inline assembly code from
@@ -570,6 +586,15 @@ func codeFragment(a: var Assembler_arm64, instr: string, op0, op1: Operand, op2:
570586
if op1.desc.constraint != asmClobberedRegister:
571587
a.operands.incl op1.desc
572588

589+
func codeFragment(a: var Assembler_arm64, instr: string, op: Operand, cc: ConditionCode) =
590+
# Generate a code fragment
591+
let off = a.getStrOffset(op)
592+
593+
a.code &= instr & " " & off & ", " & $cc & '\n'
594+
595+
if op.desc.constraint != asmClobberedRegister:
596+
a.operands.incl op.desc
597+
573598
func codeFragment(a: var Assembler_arm64, instr: string, op0, op1, op2: Operand, cc: ConditionCode) =
574599
# Generate a code fragment
575600
let off0 = a.getStrOffset(op0)
@@ -813,6 +838,11 @@ func cmn*(a: var Assembler_arm64, lhs: Operand, rhs: Operand) =
813838
## This uses ADDS and discards the result
814839
a.codeFragment("cmn", lhs, rhs)
815840

841+
func cset*(a: var Assembler_arm64, dst: Operand, cc: ConditionCode) =
842+
## Store a condition code in a register
843+
doAssert dst.isOutput(), $dst.repr
844+
a.codeFragment("cset", dst, cc)
845+
816846
func `and`*(a: var Assembler_arm64, dst: Operand, lhs: Operand, rhs: OperandReuse) =
817847
a.codeFragment("and", dst, lhs, rhs)
818848

0 commit comments

Comments
 (0)