compiling over, pick, >r and r>

cvs
Slava Pestov 2005-03-14 18:20:57 +00:00
parent e2541faa72
commit 0fa94a9102
8 changed files with 50 additions and 17 deletions

View File

@ -56,6 +56,7 @@ cpu "x86" = [
cpu "ppc" = [
"/library/compiler/ppc/assembler.factor"
"/library/compiler/ppc/stack.factor"
"/library/compiler/ppc/generator.factor"
] pull-in
"compile" get cpu "x86" = and [

View File

@ -3,6 +3,9 @@
IN: assembler
USING: errors kernel math memory words ;
! See the Motorola or IBM documentation for details. The opcode
! names are standard.
: insn ( operand opcode -- ) 26 shift bitor compile-cell ;
: b-form ( bo bi bd aa lk -- n )
@ -10,7 +13,7 @@ USING: errors kernel math memory words ;
r> bitor r> bitor r> bitor r> bitor ;
: d-form ( d a simm -- n )
>r 16 shift >r 21 shift r> bitor r> bitor ;
HEX: ffff bitand >r 16 shift >r 21 shift r> bitor r> bitor ;
: i-form ( li aa lk -- n )
>r 1 shift bitor r> bitor ;
@ -19,6 +22,7 @@ USING: errors kernel math memory words ;
1 shift >r 11 shift >r 21 shift r> bitor r> bitor ;
: ADDI d-form 14 insn ;
: SUBI neg ADDI ;
: LI 0 rot ADDI ;
: ADDIS d-form 15 insn ;
: LIS 0 rot ADDIS ;
@ -30,5 +34,6 @@ USING: errors kernel math memory words ;
: MFLR 8 MFSPR ;
: MTSPR 5 shift 467 xfx-form 31 insn ;
: MTLR 8 MTSPR ;
: LWZ d-form 32 insn ;
: STW d-form 36 insn ;
: STWU d-form 37 insn ;

View File

@ -0,0 +1,6 @@
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: compiler
USING: assembler inference kernel words ;
#return [ drop BLR ] "generator" set-word-prop

View File

@ -1,11 +1,18 @@
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: assembler
USING: errors kernel math memory words ;
USING: compiler errors kernel math memory words ;
: PUSH-DS
#! Push r18 on the data stack.
18 14 4 STWU ;
! Pushing and popping the data stack.
: PEEK-DS 18 14 0 LWZ ;
: POP-DS PEEK-DS 14 14 4 SUBI ;
: PUSH-DS 18 14 4 STWU ;
: REPL-DS 18 14 0 STW ;
! Pushing and popping the return stack.
: PEEK-CS 18 15 0 LWZ ;
: POP-CS PEEK-CS 15 15 4 SUBI ;
: PUSH-CS 18 15 4 STWU ;
: w>h/h dup -16 shift HEX: ffff bitand >r HEX: ffff bitand r> ;
@ -15,8 +22,19 @@ USING: errors kernel math memory words ;
18 LI
] [
w>h/h 18 LIS 18 18 rot ORI
] ifte PUSH-DS ;
] ifte ;
: PUSH-CS
#! Push r18 on the return stack.
18 15 4 STWU ;
#push-immediate [
immediate-literal PUSH-DS
] "generator" set-word-prop
#replace-immediate [
immediate-literal REPL-DS
] "generator" set-word-prop
\ drop [ drop 14 14 4 SUBI ] "generator" set-word-prop
\ dup [ drop PEEK-DS PUSH-DS ] "generator" set-word-prop
\ over [ drop 18 14 -4 LWZ PUSH-DS ] "generator" set-word-prop
\ pick [ drop 18 14 -8 LWZ PUSH-DS ] "generator" set-word-prop
\ >r [ drop POP-DS PUSH-CS ] "generator" set-word-prop
\ r> [ drop POP-CS PUSH-DS ] "generator" set-word-prop

View File

@ -23,7 +23,7 @@ void primitive_set_literal_top(void);
void collect_literals(void);
#ifdef FACTOR_PPC
extern void flush_icache(void *start, int len);
void flush_icache(void *start, int len);
#else
INLINE void flush_icache(void *start, int len) {}
#endif

View File

@ -1,11 +1,7 @@
#ifndef __FACTOR_H__
#define __FACTOR_H__
#if defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32)
#define FACTOR_X86
#elif defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC)
#define FACTOR_PPC
#endif
#include "platform.h"
#if defined(WIN32)
#define DLLEXPORT __declspec(dllexport)

View File

@ -1,3 +1,5 @@
#include "platform.h"
/* Thanks to Joshua Grams for this code.
On PowerPC processors, we must flush the instruction cache manually
@ -12,8 +14,8 @@ This function is called from compiler.c. */
/* IN: 3 = start, 4 = len */
.global _flush_icache
_flush_icache:
.global flush_icache
flush_icache:
/* compute number of cache lines to flush */
add 4,4,3
clrrwi 3,3,5 /* align addr to next lower cache line boundary */

5
native/platform.h Normal file
View File

@ -0,0 +1,5 @@
#if defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32)
#define FACTOR_X86
#elif defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC)
#define FACTOR_PPC
#endif