• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dead Reckoning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dead Reckoning


  • Subject: Re: Dead Reckoning
  • From: Graham Cox <email@hidden>
  • Date: Sat, 10 Oct 2015 16:13:48 +1100

> On 10 Oct 2015, at 3:54 pm, Jens Alfke <email@hidden> wrote:
>
> There’s very little reason to use macros for things like this, when an inline function is as efficient and safer.
>


Probably another example of modern technology passing me by - used these macros for >20 years…  ;)

Here’s a quick test I ran, disassembling a simple C file without and then with optimisations. The non-opt case makes the function call, the opt case goes even further and for my test case just loads a constant, since in my test case it never changes. That suggests it really does optimise away the function call (though at this stage it’s still present - presumably the lnker’s dead-code stripper would remove the actual function).

No optimisation:


LCPI0_0:
	.quad	4614256656552969552     ## double 3.1415926540000001
LCPI0_1:
	.quad	4640537203540230144     ## double 180
	.section	__TEXT,__text,regular,pure_instructions
	.globl	_radians_to_degrees
	.align	4, 0x90
_radians_to_degrees:                    ## @radians_to_degrees
Lfunc_begin0:
	.file	1 "/Users/grahamcox/Projects/Test" "testoptimaisation.c"
	.loc	1 13 0                  ## /Users/grahamcox/Projects/Test/testoptimaisation.c:13:0
	.cfi_startproc
## BB#0:
	pushq	%rbp
Ltmp0:
	.cfi_def_cfa_offset 16
Ltmp1:
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
Ltmp2:
	.cfi_def_cfa_register %rbp
	movsd	LCPI0_0(%rip), %xmm1
	movsd	LCPI0_1(%rip), %xmm2
	movsd	%xmm0, -8(%rbp)
	.loc	1 15 2 prologue_end     ## /Users/grahamcox/Projects/Test/testoptimaisation.c:15:2
Ltmp3:
	mulsd	-8(%rbp), %xmm2
	divsd	%xmm1, %xmm2
	movaps	%xmm2, %xmm0
	popq	%rbp
	retq
Ltmp4:
Lfunc_end0:
	.cfi_endproc

	.section	__TEXT,__literal8,8byte_literals
	.align	3
LCPI1_0:
	.quad	4615288898129284301     ## double 3.6000000000000001
	.section	__TEXT,__text,regular,pure_instructions
	.globl	_test
	.align	4, 0x90
_test:                                  ## @test
Lfunc_begin1:
	.loc	1 21 0                  ## /Users/grahamcox/Projects/Test/testoptimaisation.c:21:0
	.cfi_startproc
## BB#0:
	pushq	%rbp
Ltmp5:
	.cfi_def_cfa_offset 16
Ltmp6:
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
Ltmp7:
	.cfi_def_cfa_register %rbp
	subq	$32, %rsp
	movsd	LCPI1_0(%rip), %xmm0
	.loc	1 22 2 prologue_end     ## /Users/grahamcox/Projects/Test/testoptimaisation.c:22:2
Ltmp8:
	movsd	%xmm0, -8(%rbp)
	.loc	1 24 13                 ## /Users/grahamcox/Projects/Test/testoptimaisation.c:24:13
	movsd	-8(%rbp), %xmm0
	callq	_radians_to_degrees
	leaq	L_.str(%rip), %rdi
	movsd	%xmm0, -16(%rbp)
	.loc	1 26 2                  ## /Users/grahamcox/Projects/Test/testoptimaisation.c:26:2
	movsd	-16(%rbp), %xmm0
	movb	$1, %al
	callq	_printf
	.loc	1 27 1                  ## /Users/grahamcox/Projects/Test/testoptimaisation.c:27:1
	movl	êx, -20(%rbp)         ## 4-byte Spill
	addq	$32, %rsp
	popq	%rbp
	retq
Ltmp9:
Lfunc_end1:
	.cfi_endproc

With full optimisation, :


LCPI0_0:
	.quad	4640537203540230144     ## double 180
LCPI0_1:
	.quad	4614256656552969552     ## double 3.1415926540000001
	.section	__TEXT,__text,regular,pure_instructions
	.private_extern	_radians_to_degrees
	.globl	_radians_to_degrees
_radians_to_degrees:                    ## @radians_to_degrees
Lfunc_begin0:
	.file	1 "/Users/grahamcox/Projects/Test" "testoptimaisation.c"
	.loc	1 13 0                  ## /Users/grahamcox/Projects/Test/testoptimaisation.c:13:0
	.cfi_startproc
## BB#0:
	pushq	%rbp
Ltmp0:
	.cfi_def_cfa_offset 16
Ltmp1:
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
Ltmp2:
	.cfi_def_cfa_register %rbp
	##DEBUG_VALUE: radians_to_degrees:rad <- XMM0
	.loc	1 15 2 prologue_end     ## /Users/grahamcox/Projects/Test/testoptimaisation.c:15:2
Ltmp3:
	mulsd	LCPI0_0(%rip), %xmm0
	divsd	LCPI0_1(%rip), %xmm0
	popq	%rbp
	retq
Ltmp4:
Lfunc_end0:
	.cfi_endproc
	.section	__TEXT,__literal8,8byte_literals
	.align	3
LCPI1_0:
	.quad	4641461314255121455     ## double 206.26480622016376
	.section	__TEXT,__text,regular,pure_instructions
	.private_extern	_test
	.globl	_test
_test:                                  ## @test
Lfunc_begin1:
	.loc	1 21 0                  ## /Users/grahamcox/Projects/Test/testoptimaisation.c:21:0
	.cfi_startproc
## BB#0:
	pushq	%rbp
Ltmp5:
	.cfi_def_cfa_offset 16
Ltmp6:
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
Ltmp7:
	.cfi_def_cfa_register %rbp
Ltmp8:
	##DEBUG_VALUE: test:r <- 3.600000e+00
	##DEBUG_VALUE: radians_to_degrees:rad <- 3.600000e+00
	##DEBUG_VALUE: test:d <- 2.062648e+02
	.loc	1 26 2 prologue_end     ## /Users/grahamcox/Projects/Test/testoptimaisation.c:26:2
	leaq	L_.str(%rip), %rdi
	movsd	LCPI1_0(%rip), %xmm0
	movb	$1, %al
	popq	%rbp
	jmp	_printf                 ## TAILCALL
Ltmp9:
Lfunc_end1:
	.cfi_endproc


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Dead Reckoning (From: Michael de Haan  <email@hidden>)
 >Re: Dead Reckoning (From: Michael de Haan  <email@hidden>)
 >Re: Dead Reckoning (From: Graham Cox <email@hidden>)
 >Re: Dead Reckoning (From: Rick Mann <email@hidden>)
 >Re: Dead Reckoning (From: Graham Cox <email@hidden>)
 >Re: Dead Reckoning (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Dead Reckoning
  • Next by Date: Re: Dead Reckoning
  • Previous by thread: Re: Dead Reckoning
  • Next by thread: TableView Segue
  • Index(es):
    • Date
    • Thread