Skip to content

code_native generates different code with dump_module=true and dump_module=false #57881

Open
@dzhang314

Description

@dzhang314

According to the documentation for code_native, the flag dump_module::Bool is only supposed to affect metadata.

If dump_module is false, do not print metadata such as rodata or directives.

However, I observe different actual assembly code generated with dump_module=true and dump_module=false. As a very simple example:

   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.9 (2025-03-10)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> code_native(+, (Float64, Float64); dump_module=false)
	.text
; ┌ @ float.jl:409 within `+`
	push	rbp
	mov	rbp, rsp
	mov	rax, qword ptr [r13 + 16]
	mov	rax, qword ptr [rax + 16]
	mov	rax, qword ptr [rax]
	addsd	xmm0, xmm1
	pop	rbp
	ret
; └
; ┌ @ float.jl:409 within `<invalid>`
	nop	word ptr cs:[rax + rax]
; └

julia> code_native(+, (Float64, Float64); dump_module=true)
	.text
	.file	"+"
	.globl	"julia_+_72"                    # -- Begin function julia_+_72
	.p2align	4, 0x90
	.type	"julia_+_72",@function
"julia_+_72":                           # @"julia_+_72"
; ┌ @ float.jl:409 within `+`
# %bb.0:                                # %top
	push	rbp
	mov	rbp, rsp
	vaddsd	xmm0, xmm0, xmm1
	pop	rbp
	ret
.Lfunc_end0:
	.size	"julia_+_72", .Lfunc_end0-"julia_+_72"
; └
                                        # -- End function
	.section	".note.GNU-stack","",@progbits

The first version has a three-level pointer chase that's absent from the second version! In addition, note the use of the two-argument form addsd xmm0, xmm1 compared to the three-argument form vaddsd xmm0, xmm0, xmm1 and the presence of the extra nop instruction. What is going on here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsThis change adds or pertains to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions