cpu.x86: use push and pop when emitting %prologue and %epilogue
push/pop REG has the same effect as sub/add rsp, 8 so use them instead when applicable to generate a little shorter codedb4
							parent
							
								
									35d81c742d
								
							
						
					
					
						commit
						e41aef9a50
					
				| 
						 | 
				
			
			@ -61,10 +61,13 @@ HELP: (%slot)
 | 
			
		|||
  }
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
HELP: decr-stack-reg
 | 
			
		||||
{ $values { "n" number } }
 | 
			
		||||
{ $description "Emits an instruction for decrementing the stack register the given number of bytes." } ;
 | 
			
		||||
{ $description "Emits an instruction for decrementing the stack register the given number of bytes. If n is equal to the " { $link cell } " size, then a " { $link PUSH } " instruction is emitted instead because it has a shorter encoding." } ;
 | 
			
		||||
 | 
			
		||||
HELP: incr-stack-reg
 | 
			
		||||
{ $values { "n" number } }
 | 
			
		||||
{ $description "Emits an instruction for incrementing the stack register the given number of bytes. If n is equal to the " { $link cell } " size, then a " { $link POP } " instruction is emitted instead because it has a shorter encoding." } ;
 | 
			
		||||
 | 
			
		||||
HELP: load-zone-offset
 | 
			
		||||
{ $values { "nursery-ptr" "a register symbol" } }
 | 
			
		||||
| 
						 | 
				
			
			@ -106,3 +109,11 @@ HELP: copy-register*
 | 
			
		|||
    "0000000533c61fe0: 0f28ca  movaps xmm1, xmm2"
 | 
			
		||||
  }
 | 
			
		||||
} ;
 | 
			
		||||
 | 
			
		||||
ARTICLE: "cpu.x86" "x86 compiler backend"
 | 
			
		||||
"Implementation of " { $vocab-link "cpu.architecture" } " for x86 machines."
 | 
			
		||||
$nl
 | 
			
		||||
{ $link ADD } " and " { $link SUB } " variants:"
 | 
			
		||||
{ $subsections (%inc) decr-stack-reg incr-stack-reg } ;
 | 
			
		||||
 | 
			
		||||
ABOUT: "cpu.x86"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
USING: compiler.cfg.debugger compiler.cfg.instructions
 | 
			
		||||
compiler.codegen.gc-maps compiler.codegen.relocation compiler.cfg.registers
 | 
			
		||||
cpu.architecture cpu.x86.features kernel kernel.private make math math.libm
 | 
			
		||||
compiler.cfg.registers compiler.codegen.gc-maps
 | 
			
		||||
compiler.codegen.relocation cpu.architecture cpu.x86 cpu.x86.assembler
 | 
			
		||||
cpu.x86.features kernel kernel.private layouts make math math.libm
 | 
			
		||||
namespaces sequences system tools.test ;
 | 
			
		||||
IN: cpu.x86.tests
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -37,3 +38,14 @@ IN: cpu.x86.tests
 | 
			
		|||
    [ D 0 %clear ] B{ } make
 | 
			
		||||
    cpu x86.32? B{ 199 6 144 18 0 0 } B{ 73 199 6 144 18 0 0 } ? =
 | 
			
		||||
] unit-test
 | 
			
		||||
 | 
			
		||||
! %prologue
 | 
			
		||||
{ t } [
 | 
			
		||||
    [ 2 cells %prologue ] B{ } make
 | 
			
		||||
    [ pic-tail-reg PUSH ] B{ } make =
 | 
			
		||||
] unit-test
 | 
			
		||||
 | 
			
		||||
{ t } [
 | 
			
		||||
    [ 8 cells %prologue ] B{ } make
 | 
			
		||||
    [ stack-reg 7 cells SUB ] B{ } make =
 | 
			
		||||
] unit-test
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,6 +30,8 @@ HOOK: stack-reg cpu ( -- reg )
 | 
			
		|||
 | 
			
		||||
HOOK: reserved-stack-space cpu ( -- n )
 | 
			
		||||
 | 
			
		||||
HOOK: pic-tail-reg cpu ( -- reg )
 | 
			
		||||
 | 
			
		||||
: stack@ ( n -- op ) stack-reg swap [+] ;
 | 
			
		||||
 | 
			
		||||
: special-offset ( m -- n )
 | 
			
		||||
| 
						 | 
				
			
			@ -37,11 +39,17 @@ HOOK: reserved-stack-space cpu ( -- n )
 | 
			
		|||
 | 
			
		||||
: spill@ ( n -- op ) spill-offset special-offset stack@ ;
 | 
			
		||||
 | 
			
		||||
: (%inc) ( n reg -- ) swap cells dup 0 > [ ADD ] [ neg SUB ] if ; inline
 | 
			
		||||
 | 
			
		||||
: decr-stack-reg ( n -- )
 | 
			
		||||
    [ stack-reg swap SUB ] unless-zero ;
 | 
			
		||||
    [
 | 
			
		||||
        dup cell = [ drop pic-tail-reg PUSH ] [ stack-reg swap SUB ] if
 | 
			
		||||
    ] unless-zero ;
 | 
			
		||||
 | 
			
		||||
: incr-stack-reg ( n -- )
 | 
			
		||||
    [ stack-reg swap ADD ] unless-zero ;
 | 
			
		||||
    [
 | 
			
		||||
        dup cell = [ drop pic-tail-reg POP ] [ stack-reg swap ADD ] if
 | 
			
		||||
    ] unless-zero ;
 | 
			
		||||
 | 
			
		||||
: align-stack ( n -- n' ) 16 align ;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -51,8 +59,6 @@ M: x86 stack-frame-size ( stack-frame -- i )
 | 
			
		|||
    cell +
 | 
			
		||||
    align-stack ;
 | 
			
		||||
 | 
			
		||||
HOOK: pic-tail-reg cpu ( -- reg )
 | 
			
		||||
 | 
			
		||||
M: x86 complex-addressing? t ;
 | 
			
		||||
 | 
			
		||||
M: x86 fused-unboxing? t ;
 | 
			
		||||
| 
						 | 
				
			
			@ -93,8 +99,6 @@ M: x86 %replace-imm
 | 
			
		|||
M: x86 %clear ( loc -- )
 | 
			
		||||
    297 swap %replace-imm ;
 | 
			
		||||
 | 
			
		||||
: (%inc) ( n reg -- ) swap cells dup 0 > [ ADD ] [ neg SUB ] if ; inline
 | 
			
		||||
 | 
			
		||||
M: x86 %inc ( loc -- )
 | 
			
		||||
    [ n>> ] [ ds-loc? ds-reg rs-reg ? ] bi (%inc) ;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue