i rediscovered Any critiques about these extensions on `Duration`? just now, and was curious if were were any differences between the following:
extension Duration
{
@inlinable public
func negate1() -> Self
{
.zero - self
}
@inlinable public
func negate2() -> Self
{
.init(secondsComponent: -self.components.seconds,
attosecondsComponent: -self.components.attoseconds)
}
}
when i plugged them into Godbolt, i was surprised to discover that Duration’s arithmetic is actually part of the runtime, and not inlinable at all.
(extension in output):Swift.Duration.negate1() -> Swift.Duration:
push r14
push rbx
push rax
mov rbx, rsi
mov r14, rdi
call ($ss8DurationV4zeroABvgZ)@PLT
mov rdi, rax
mov rsi, rdx
mov rdx, r14
mov rcx, rbx
add rsp, 8
pop rbx
pop r14
jmp ($ss8DurationV1soiyA2B_ABtFZ)@PLT
(extension in output):Swift.Duration.negate2() -> Swift.Duration:
push r15
push r14
push rbx
mov r14, rsi
mov r15, rdi
call ($ss8DurationV10componentss5Int64V7seconds_AE11attosecondstvg)@PLT
mov rbx, rax
neg rbx
jo .LBB2_3
mov rdi, r15
mov rsi, r14
call ($ss8DurationV10componentss5Int64V7seconds_AE11attosecondstvg)@PLT
neg rdx
jo .LBB2_4
mov rdi, rbx
mov rsi, rdx
pop rbx
pop r14
pop r15
jmp ($ss8DurationV16secondsComponent011attosecondsC0ABs5Int64V_AFtcfC)@PLT
are there good reasons why Duration’s arithmetic is still behind a resilience barrier?
2 Likes
Just a guess, but Duration might be represented as a single 128-bit integer value rather than two 64-bit values.