Assembly decoding help?

Justin Bailey jgbailey at gmail.com
Tue Mar 4 20:07:03 EST 2008


I'm trying to get a feel for the assembly output by GHC on my
platform. Below is a module containing one function and the associated
assembly. I've put in comments what I think is going on, but I'd
appreciate it if anyone could give me some pointers. I'd really like
to know three things:

  * Why does _Add_unsafeShiftR_info check if (%esi) is 3?
  * What's going on in _s86_info?
  * At the end of _s87_info, 8 is added to %ebp and then jumped to. Is
that a jump to the I# constructor and, if so, how did it's address get
to that offset from %ebp?

Thanks in advance for any assistance!

Justin

--- cut here ----

# Compiled with
#
#  ghc -c Add.hs -fext-core -keep-s-files -fasm -O2 -ddump-to-file
-ddump-stg -ddump-cmm
#
# Platform: Windows XP.
# Processor Pentium 4.
# GHC Version: 6.8.2.
#
# > {-# OPTIONS_GHC -fglasgow-exts -fbang-patterns  #-}
# > module Add (unsafeShiftR)
#
# > where
#
# > import Data.Bits
# > import GHC.Base (uncheckedShiftRL#, Int(..), word2Int#, int2Word#)
#
# > I# a `unsafeShiftR` I# b = I# (word2Int# (int2Word# a
`uncheckedShiftRL#` b))
#

.data
	.align 4
.globl _Add_unsafeShiftR_closure
_Add_unsafeShiftR_closure:
	.long	_Add_unsafeShiftR_info # Specifies entry point for unsafeShiftR?
.text
	.align 4,0x90
	.long	33
	.long	34
_s87_info:
	addl $8,%edi
	cmpl 92(%ebx),%edi						# Stack check?
	ja .Lc8n
	movl 4(%ebp),%eax							# Get value to be shifted
	movl 3(%esi),%ecx							# Get shift amount
	shrl %cl,%eax									# Shift value
	movl $_base_GHCziBase_Izh_con_info,-4(%edi) # Get ready to call I#?
	movl %eax,(%edi)							# Constructor value
	leal -3(%edi),%esi						# Address to what in I#?
	addl $8,%ebp									# Make room on stack for next caller?
	jmp *(%ebp)										# Go to constructor? Tail call?
.Lc8n:
	movl $8,112(%ebx)
	jmp *-8(%ebx)									# Error routine if stack overflows?
.text
	.align 4,0x90
	.long	1
	.long	34
_s86_info:
	movl 4(%ebp),%eax							# Testing what here?
	movl 3(%esi),%ecx
	movl %ecx,4(%ebp)
	movl %eax,%esi
	movl $_s87_info,(%ebp)
	testl $3,%esi
	jne _s87_info
	jmp *(%esi)
.text
	.align 4,0x90
	.long	131084
	.long	0
	.long	15
.globl _Add_unsafeShiftR_info
_Add_unsafeShiftR_info:
	movl (%ebp),%esi
	movl $_s86_info,(%ebp)
	testl $3,%esi									# Looking at StgRetInfoTable here?
	jne _s86_info									# Enter body of unsafeShiftR?
	jmp *(%esi)
.data
	.align 4
__module_registered:
	.long	0
.text
	.align 4,0x90
.globl ___stginit_Add_
___stginit_Add_:
	cmpl $0,__module_registered
	jne .Lc8E
.Lc8F:
	movl $1,__module_registered
	addl $-4,%ebp
	movl $___stginit_base_GHCziBase_,(%ebp)
	addl $-4,%ebp
	movl $___stginit_base_Prelude_,(%ebp)
	addl $-4,%ebp
	movl $___stginit_base_DataziBits_,(%ebp)
.Lc8E:
	addl $4,%ebp
	jmp *-4(%ebp)
.text
	.align 4,0x90
.globl ___stginit_Add
___stginit_Add:
	jmp ___stginit_Add_
.ident "GHC 6.8.2"


More information about the Glasgow-haskell-users mailing list