Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* PATCH: (on Alpha) emulating missing instructions
@ 1999-10-15  9:30 Luke Deller
  1999-10-15 12:42 ` Eric Bohm
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Luke Deller @ 1999-10-15  9:30 UTC (permalink / raw)
  To: linux-kernel; +Cc: axp-list, Daniel Paul Potts

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1715 bytes --]

Daniel & I tried to run Loki's new beta version of Civilization Call to
Power for alpha linux on a multia (ev4 alpha).  We got an illegal
instruction exception.  We discovered that it was compiled for ev6, and so
contained instructions not supported by our CPU.

So we have patched the linux kernel to emulate the instructions we needed.
These instructions are:
- byte/word load/store instructions (ldbu,stb,ldwu,stw)
- some multimedia instructions (minsw, maxsw, minuw, maxuw, minsb, maxsb,
  minub, maxub)

We have tried to make the emulation fairly fast - we have added it as some
assembly language code to the "illegal instruction exception" kernel entry
point in arch/alpha/kernel/entry.S:entIF.  (Of course it's still faster
to avoid emulation and use a binary compiled for your generation of alpha
cpu).

We put an option for enabling it in the "Kernel Hacking" section of the
configuration.

The patch is applied to kernel version 2.2.11
(Loki say not to use 2.2.12 for Civilization CTP) 

We only wrote enough emulation code to get CivilizationCTP to run ..  in the
future it would be cool to see emulation of a more complete set of
instructions in the kernel.

Hope this is useful to somebody,

Luke Deller & Daniel Potts.

--------------------------------------------------------------------------
           Luke Deller                               luked@cse.unsw.edu.au
 _--_|\    Computer Engineering student           
/      \   School of Computer Science and Engineering     ? ? ? ?        
\_.--._*   The University of New South Wales               ~~^^~  
      v    Sydney, NSW     2052    AUSTRALIA                o o
-------------------------------------------------------ooO--(_)--Ooo------

[-- Attachment #2: linux-alpha-emu-for2_2_11.patch --]
[-- Type: TEXT/PLAIN, Size: 16525 bytes --]

diff -u --recursive --new-file v2.2.11/linux/arch/alpha/config.in linux/arch/alpha/config.in
--- v2.2.11/linux/arch/alpha/config.in	Sun May 23 06:41:37 1999
+++ linux/arch/alpha/config.in	Fri Oct 15 18:18:16 1999
@@ -280,6 +280,7 @@
 #bool 'Debug kmalloc/kfree' CONFIG_DEBUG_MALLOC
 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
   tristate 'Kernel FP software completion' CONFIG_MATHEMU
+  bool 'Emulation of some extended instruction sets' CONFIG_ALPHA_EXTINSNS
 else
   define_bool CONFIG_MATHEMU y
 fi
diff -u --recursive --new-file v2.2.11/linux/arch/alpha/defconfig linux/arch/alpha/defconfig
--- v2.2.11/linux/arch/alpha/defconfig	Sun Jun 13 04:52:51 1999
+++ linux/arch/alpha/defconfig	Fri Oct 15 18:17:50 1999
@@ -330,4 +330,5 @@
 # Kernel hacking
 #
 CONFIG_MATHEMU=y
+# CONFIG_ALPHA_EXTINSNS is not set
 # CONFIG_MAGIC_SYSRQ is not set
diff -u --recursive --new-file v2.2.11/linux/arch/alpha/kernel/entry.S linux/arch/alpha/kernel/entry.S
--- v2.2.11/linux/arch/alpha/kernel/entry.S	Tue Aug 10 05:04:57 1999
+++ linux/arch/alpha/kernel/entry.S	Fri Oct 15 18:18:30 1999
@@ -173,10 +173,819 @@
 	jsr	$31,do_entArith
 .end entArith
 
+#ifdef CONFIG_ALPHA_EXTINSNS
+/* emulation of some extended alpha instructions */
+
+.align 3
+.ent	get_user_sp
+get_user_sp:
+	subq		$30,6*8,$30
+	stq		$0,0($30)
+	stq		$1,8($30)
+	stq		$16,16($30)
+	mov		$25,$3
+	stq		$22,24($30)
+	stq		$23,32($30)
+	stq		$24,40($30)
+	call_pal	PAL_rdusp
+	ldq		$24,40($30)
+	mov		$3,$25
+	ldq		$23,32($30)
+	ldq		$22,24($30)
+	mov		$0,$3
+	ldq		$16,16($30)
+	ldq		$1,8($30)
+	ldq		$0,0($30)
+	addq		$30,6*8,$30
+	ret		$31,($5)
+.end	get_user_sp
+
+.align 3
+.ent	put_user_sp
+put_user_sp:
+	subq		$30,5*8,$30
+	stq		$16,0($30)
+	stq		$22,8($30)
+	stq		$23,16($30)
+	mov		$3,$16
+	stq		$24,24($30)
+	mov		$1,$3
+	stq		$25,32($30)
+	call_pal	PAL_wrusp
+	ldq		$25,32($30)
+	ldq		$24,24($30)
+	mov		$3,$1
+	ldq		$23,16($30)
+	ldq		$22,8($30)
+	ldq		$16,0($30)
+	addq		$30,5*8,$30
+	ret		$31,($5)
+.end	put_user_sp
+
+/* a code table .. make sure each entry is exactly 2 instructions */
+.align 3
+.ent	get_ureg_table
+get_ureg0:
+	ldq	$3,8*0($30)
+	ret	$31,($5)
+get_ureg1:
+	ldq	$3,8*1($30)
+	ret	$31,($5)
+get_ureg2:
+	ldq	$3,8*2($30)
+	ret	$31,($5)
+get_ureg3:
+	ldq	$3,8*3($30)
+	ret	$31,($5)
+get_ureg4:
+	ldq	$3,8*4($30)
+	ret	$31,($5)
+get_ureg5:
+	ldq	$3,8*5($30)
+	ret	$31,($5)
+get_ureg6:
+	mov	$6,$3
+	ret	$31,($5)
+get_ureg7:
+	mov	$7,$3
+	ret	$31,($5)
+get_ureg8:
+	mov	$8,$3
+	ret	$31,($5)
+get_ureg9:
+	mov	$9,$3
+	ret	$31,($5)
+get_ureg10:
+	mov	$10,$3
+	ret	$31,($5)
+get_ureg11:
+	mov	$11,$3
+	ret	$31,($5)
+get_ureg12:
+	mov	$12,$3
+	ret	$31,($5)
+get_ureg13:
+	mov	$13,$3
+	ret	$31,($5)
+get_ureg14:
+	mov	$14,$3
+	ret	$31,($5)
+get_ureg15:
+	mov	$15,$3
+	ret	$31,($5)
+get_ureg16:
+	ldq	$3,8*10($30)
+	ret	$31,($5)
+get_ureg17:
+	ldq	$3,8*11($30)
+	ret	$31,($5)
+get_ureg18:
+	ldq	$3,8*12($30)
+	ret	$31,($5)
+get_ureg19:
+	mov	$19,$3
+	ret	$31,($5)
+get_ureg20:
+	mov	$20,$3
+	ret	$31,($5)
+get_ureg21:
+	mov	$21,$3
+	ret	$31,($5)
+get_ureg22:
+	mov	$22,$3
+	ret	$31,($5)
+get_ureg23:
+	mov	$23,$3
+	ret	$31,($5)
+get_ureg24:
+	mov	$24,$3
+	ret	$31,($5)
+get_ureg25:
+	mov	$25,$3
+	ret	$31,($5)
+get_ureg26:
+	mov	$26,$3
+	ret	$31,($5)
+get_ureg27:
+	mov	$27,$3
+	ret	$31,($5)
+get_ureg28:
+	mov	$28,$3
+	ret	$31,($5)
+get_ureg29:
+	ldq	$3,9*8($30)
+	ret	$31,($5)
+get_ureg30:
+	br	$31,get_user_sp 
+	ret	$31,($5)
+get_ureg31:
+	mov	$31,$3
+	ret	$31,($5)
+.end	get_ureg_table
+
+/* another code table .. make sure each entry is exactly 2 instructions */
+.align 3
+.ent	put_ureg_table
+put_ureg0:
+	stq	$3,8*0($30)
+	ret	$31,($5)
+put_ureg1:
+	stq	$3,8*1($30)
+	ret	$31,($5)
+put_ureg2:
+	stq	$3,8*2($30)
+	ret	$31,($5)
+put_ureg3:
+	stq	$3,8*3($30)
+	ret	$31,($5)
+put_ureg4:
+	stq	$3,8*4($30)
+	ret	$31,($5)
+put_ureg5:
+	stq	$3,8*5($30)
+	ret	$31,($5)
+put_ureg6:
+	mov	$3,$6
+	ret	$31,($5)
+put_ureg7:
+	mov	$3,$7
+	ret	$31,($5)
+put_ureg8:
+	mov	$3,$8
+	ret	$31,($5)
+put_ureg9:
+	mov	$3,$9
+	ret	$31,($5)
+put_ureg10:
+	mov	$3,$10
+	ret	$31,($5)
+put_ureg11:
+	mov	$3,$11
+	ret	$31,($5)
+put_ureg12:
+	mov	$3,$12
+	ret	$31,($5)
+put_ureg13:
+	mov	$3,$13
+	ret	$31,($5)
+put_ureg14:
+	mov	$3,$14
+	ret	$31,($5)
+put_ureg15:
+	mov	$3,$15
+	ret	$31,($5)
+put_ureg16:
+	stq	$3,8*10($30)
+	ret	$31,($5)
+put_ureg17:
+	stq	$3,8*11($30)
+	ret	$31,($5)
+put_ureg18:
+	stq	$3,8*12($30)
+	ret	$31,($5)
+put_ureg19:
+	mov	$3,$19
+	ret	$31,($5)
+put_ureg20:
+	mov	$3,$20
+	ret	$31,($5)
+put_ureg21:
+	mov	$3,$21
+	ret	$31,($5)
+put_ureg22:
+	mov	$3,$22
+	ret	$31,($5)
+put_ureg23:
+	mov	$3,$23
+	ret	$31,($5)
+put_ureg24:
+	mov	$3,$24
+	ret	$31,($5)
+put_ureg25:
+	mov	$3,$25
+	ret	$31,($5)
+put_ureg26:
+	mov	$3,$26
+	ret	$31,($5)
+put_ureg27:
+	mov	$3,$27
+	ret	$31,($5)
+put_ureg28:
+	mov	$3,$28
+	ret	$31,($5)
+put_ureg29:
+	stq	$3,9*8($30)
+	ret	$31,($5)
+put_ureg30:
+	br	$31,put_user_sp 
+	ret	$31,($5)
+put_ureg31:
+	ret	$31,($5)
+.end	put_ureg_table
+
+/* this macro trashes $5 & index, and returns user reg val in $3 */
+#define get_user_reg(index)           \
+	br	$3,1f                 ;\
+1:	                              ;\
+	s8addq	index,$3,index        ;\
+	lda	$5,get_ureg0-1b($31)  ;\
+	addq	index,$5,index        ;\
+	jsr	$5,(index),get_ureg16
+
+/* this macro trashes $3, $5 & index, and takes new user reg val in $3 */
+#define put_user_reg(index)           \
+	br	$5,1f                 ;\
+1:	                              ;\
+	s8addq	index,$5,index        ;\
+	lda	$5,put_ureg0-1b($31)  ;\
+	addq	index,$5,index        ;\
+	jsr	$5,(index),put_ureg16
+
+.align 3
+.globl	emul_ldwu
+.ent	emul_ldwu
+emul_ldwu:
+	stq	$3,24($30)
+	stq	$4,32($30)
+	stq	$5,40($30)
+
+	srl	$0,21,$1
+	srl	$0,16,$2
+	and	$1,0x1f,$1
+	sll	$0,48,$0
+	and	$2,0x1f,$2
+	sra	$0,48,$0   /* $0 = disp */
+	get_user_reg($2)   /* $3 = Rb  */
+	addq	$0,$3,$0
+	ldq_u	$3,0($0)
+	ldq_u	$5,1($0)
+	extwl	$3,$0,$3
+	extwh	$5,$0,$5
+	or	$3,$5,$3
+	put_user_reg($1)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_ldwu
+
+.align 3
+.globl	emul_stw
+.ent	emul_stw
+emul_stw:
+	stq	$3,24($30)
+	stq	$4,32($30)
+	stq	$5,40($30)
+
+	srl	$0,21,$1
+	srl	$0,16,$2
+	and	$1,0x1f,$1
+	sll	$0,48,$0
+	and	$2,0x1f,$2
+	sra	$0,48,$0   /* $0 = disp */
+	get_user_reg($1)
+	mov	$3,$1
+	get_user_reg($2)   /* $3 = Rb  */
+	/* needs writing here */
+	addq	$0,$3,$0
+	ldq_u	$3,1($0)
+	ldq_u	$2,0($0)
+	inswh	$1,$0,$5
+	inswl	$1,$0,$4
+	mskwh	$3,$0,$3
+	mskwl	$2,$0,$2
+	or	$3,$5,$3
+	or	$2,$4,$2
+	stq_u	$3,1($0)
+	stq_u	$2,0($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_stw
+
+.align 3
+.globl	emul_ldbu
+.ent	emul_ldbu
+emul_ldbu:
+	stq	$3,24($30)
+	stq	$4,32($30)
+	stq	$5,40($30)
+
+	srl	$0,21,$1
+	srl	$0,16,$2
+	and	$1,0x1f,$1
+	sll	$0,48,$4
+	and	$2,0x1f,$2
+	sra	$4,48,$4   /* $0 = disp */
+	get_user_reg($2)   /* $3 = Rb  */
+	addq	$4,$3,$4
+	ldq_u	$3,0($4)
+	extbl	$3,$4,$3
+	put_user_reg($1)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_ldbu
+
+.align 3
+.globl	emul_stb
+.ent	emul_stb
+emul_stb:
+	stq	$3,24($30)
+	stq	$4,32($30)
+	stq	$5,40($30)
+
+	srl	$0,21,$1
+	srl	$0,16,$2
+	and	$1,0x1f,$1
+	sll	$0,48,$0
+	and	$2,0x1f,$2
+	sra	$0,48,$0   /* $0 = disp */
+	get_user_reg($1)
+	mov	$3,$1
+	get_user_reg($2)   /* $3 = Rb  */
+	addq	$0,$3,$0
+	ldq_u	$2,0($0)
+	insbl	$1,$0,$3
+	mskbl	$2,$0,$2
+
+	ldq	$5,40($30)
+	or	$2,$3,$2
+
+	ldq	$3,24($30)
+	stq_u	$2,0($0)
+
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_stb
+
+.align 3
+.globl	emul_minsw_4
+.ent	emul_minsw_4
+emul_minsw_4:
+	stq	$6,48($30)
+
+	extwl	$3,0x6,$4 /* get word 3 of ra (most significant) -> $4 */
+	extwl	$2,0x6,$1 /* get word 3 of rb                    -> $2 */
+	cmple	$2,$3,$6
+	cmovne	$6,$1,$4
+
+	extwl	$3,0x4,$5 /* get word 2 of ra                    -> $5 */
+	extwl	$2,0x4,$1 /* get word 2 of rb                    -> $1 */
+	cmple	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x2,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x2,$1 /* get word 1 of rb                    -> $1 */
+	cmple	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x0,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x0,$1 /* get word 1 of rb                    -> $1 */
+	cmple	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$3
+	
+	ldq	$6,48($30)
+
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_minsw_4
+
+.align 3
+.globl	emul_minuw_4
+.ent	emul_minuw_4
+emul_minuw_4:
+	stq	$6,48($30)
+
+	extwl	$3,0x6,$4 /* get word 3 of ra (most significant) -> $4 */
+	extwl	$2,0x6,$1 /* get word 3 of rb                    -> $2 */
+	cmpule	$2,$3,$6
+	cmovne	$6,$1,$4
+
+	extwl	$3,0x4,$5 /* get word 2 of ra                    -> $5 */
+	extwl	$2,0x4,$1 /* get word 2 of rb                    -> $1 */
+	cmpule	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x2,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x2,$1 /* get word 1 of rb                    -> $1 */
+	cmpule	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x0,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x0,$1 /* get word 1 of rb                    -> $1 */
+	cmpule	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$3
+	
+	ldq	$6,48($30)
+
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_minuw_4
+
+.align 3
+.globl	emul_maxsw_4
+.ent	emul_maxsw_4
+emul_maxsw_4:
+	stq	$6,48($30)
+
+	extwl	$3,0x6,$4 /* get word 3 of ra (most significant) -> $4 */
+	extwl	$2,0x6,$1 /* get word 3 of rb                    -> $2 */
+	cmple	$4,$1,$6
+	cmovne	$6,$1,$4
+
+	extwl	$3,0x4,$5 /* get word 2 of ra                    -> $5 */
+	extwl	$2,0x4,$1 /* get word 2 of rb                    -> $1 */
+	cmple	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x2,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x2,$1 /* get word 1 of rb                    -> $1 */
+	cmple	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x0,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x0,$1 /* get word 1 of rb                    -> $1 */
+	cmple	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$3
+	
+	ldq	$6,48($30)
+
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_maxsw_4
+
+.align 3
+.globl	emul_maxuw_4
+.ent	emul_maxuw_4
+emul_maxuw_4:
+	stq	$6,48($30)
+
+	extwl	$3,0x6,$4 /* get word 3 of ra (most significant) -> $4 */
+	extwl	$2,0x6,$1 /* get word 3 of rb                    -> $2 */
+	cmpule	$4,$1,$6
+	cmovne	$6,$1,$4
+
+	extwl	$3,0x4,$5 /* get word 2 of ra                    -> $5 */
+	extwl	$2,0x4,$1 /* get word 2 of rb                    -> $1 */
+	cmpule	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x2,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x2,$1 /* get word 1 of rb                    -> $1 */
+	cmpule	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x0,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x0,$1 /* get word 1 of rb                    -> $1 */
+	cmpule	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$3
+	
+	ldq	$6,48($30)
+
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_maxuw_4
+
+.align 3
+.globl	emul_maxub_8
+.ent	emul_maxub_8
+emul_maxub_8:
+	cmpbge	$2,$3,$1
+	zap	$3,$1,$3
+	zapnot	$2,$1,$2
+	or	$3,$2,$3
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_maxub_8
+
+.align 3
+.globl	emul_maxub_8
+.ent	emul_maxub_8
+emul_maxsb_8:
+	lda	$1,0x7f7f($31)
+	ldah	$1,0x7f7f($1)
+	sll	$1,32,$5
+	or	$1,$5,$1
+	not	$1,$1
+	xor	$3,$1,$5
+	xor	$2,$1,$1
+
+	cmpbge	$1,$5,$1
+	zap	$3,$1,$3
+	zapnot	$2,$1,$2
+	or	$3,$2,$3
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_maxub_8
+
+.align 3
+.globl	emul_minub_8
+.ent	emul_minub_8
+emul_minub_8:
+	cmpbge	$3,$2,$1
+	zap	$3,$1,$3
+	zapnot	$2,$1,$2
+	or	$3,$2,$3
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_minub_8
+
+.align 3
+.globl	emul_minsb_8
+.ent	emul_minsb_8
+emul_minsb_8:
+	lda	$1,0x7f7f($31)
+	ldah	$1,0x7f7f($1)
+	sll	$1,32,$5
+	or	$1,$5,$1
+	not	$1,$1
+	xor	$3,$1,$5
+	xor	$2,$1,$1
+
+	cmpbge	$5,$1,$1
+	zap	$3,$1,$3
+	zapnot	$2,$1,$2
+	or	$3,$2,$3
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_minsb_8
+
+.align 3
+.globl	emul_sexw
+.ent	emul_sexw
+emul_sexw:
+	sll	$3,48,$3
+	and	$0,0x1f,$1
+	sra	$3,48,$3
+	put_user_reg($1)
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_sexw
+
+.align 3
+.globl	emul_sexb
+.ent	emul_sexb
+emul_sexb:
+	sll	$3,56,$3
+	and	$0,0x1f,$1
+	sra	$3,56,$3
+	put_user_reg($1)
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_sexb
+
+.align 3
+.globl	emul_mmx
+.ent	emul_mmx
+emul_mmx:
+	stq	$3,24($30)
+	stq	$4,32($30)
+	stq	$5,40($30)
+
+	srl	$0,5,$4
+	srl	$0,12,$2
+	and	$4,0x3f,$4
+	blbs	$2,21f
+	srl	$0,16,$1
+	and	$1,0x1f,$1
+	get_user_reg($1)
+21:
+	srl	$0,13,$1
+	and	$1,0xff,$1
+	cmovlbs	$2,$1,$3
+	/* now:	$0 = insn
+		$3 = regb val
+		$4 = operation function code */
+	cmpeq	$4,0x1,$2
+	beq	$4,emul_sexb
+	bne	$2,emul_sexw
+	srl	$0,21,$1
+	mov	$3,$2
+	and	$1,0x1f,$1
+	get_user_reg($1)
+	cmpeq	$4,0x3a,$1
+	cmpeq	$4,0x38,$5
+	and	$0,0x1f,$0
+	/* now:	$0 = rc index
+		$2 = rb val
+		$3 = ra val
+		$4 = operation function code */
+	bne	$1,emul_minub_8
+	bne	$5,emul_minsb_8
+	cmpeq	$4,0x3e,$1
+	cmpeq	$4,0x3c,$5
+	bne	$1,emul_maxsb_8
+	bne	$5,emul_maxub_8
+	cmpeq	$4,0x39,$1
+	cmpeq	$4,0x3f,$5
+	bne	$1,emul_minsw_4
+	bne	$5,emul_maxsw_4
+	cmpeq	$4,0x3b,$1
+	cmpeq	$4,0x3d,$5
+	bne	$1,emul_minuw_4
+	bne	$5,emul_maxuw_4
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	br	old_entIF
+.end	emul_mmx
+
+#endif /* CONFIG_ALPHA_EXTINSNS */
+
 .align 3
 .globl	entIF
 .ent	entIF
 entIF:
+#ifdef CONFIG_ALPHA_EXTINSNS
+	subq	$30,7*8,$30 /* 3 regs saved here, 3 or 4 more saved in fns */
+	stq	$0,0($30)
+	ldq	$0,8+7*8($30)
+	stq	$1,8($30)
+	ldl	$0,-4($0)
+	stq	$2,16($30)
+	srl	$0,26,$1
+	and	$1,0x3f,$1
+	cmpeq	$1,0x1c,$2
+	bne	$2,emul_mmx
+	cmpeq	$1,0x0a,$2
+	bne	$2,emul_ldbu
+	cmpeq	$1,0x0e,$2
+	bne	$2,emul_stb
+	cmpeq	$1,0x0c,$2
+	cmpeq	$1,0x0d,$1
+	bne	$2,emul_ldwu
+	bne	$1,emul_stw
+	ldq	$0,0($30)
+	ldq	$1,8($30)
+	ldq	$2,16($30)
+	addq	$30,7*8,$30
+old_entIF:
+#endif /* CONFIG_ALPHA_EXTINSNS */
 	SAVE_ALL
 	lda	$8,0x3fff
 	lda	$26,ret_from_sys_call

^ permalink raw reply	[flat|nested] 12+ messages in thread

* PATCH: (on Alpha) emulating missing instructions
  1999-10-15  9:30 PATCH: (on Alpha) emulating missing instructions Luke Deller
@ 1999-10-15 12:42 ` Eric Bohm
  1999-10-15 15:02   ` Luke Deller
  1999-10-15 14:28 ` Michal Jaegermann
  1999-10-16  9:13 ` patch_v2: " Luke Deller
  2 siblings, 1 reply; 12+ messages in thread
From: Eric Bohm @ 1999-10-15 12:42 UTC (permalink / raw)
  To: axp-list; +Cc: linux-kernel, Daniel Paul Potts

>>>>> "Luke" == Luke Deller <luked@cse.unsw.edu.au> writes:

    Luke> Daniel & I tried to run Loki's new beta version of
    Luke> Civilization Call to Power for alpha linux on a multia (ev4
    Luke> alpha).  We got an illegal instruction exception.  We
    Luke> discovered that it was compiled for ev6, and so contained
    Luke> instructions not supported by our CPU.

    Luke> So we have patched the linux kernel to emulate the
    Luke> instructions we needed.  These instructions are: - byte/word
    Luke> load/store instructions (ldbu,stb,ldwu,stw) - some
    Luke> multimedia instructions (minsw, maxsw, minuw, maxuw, minsb,
    Luke> maxsb, minub, maxub)

Good work.

The same problem happens on my EV56.  Would you expect your patch to
work there also?  Or are there EV5 elements that I should expect
to be issues?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: PATCH: (on Alpha) emulating missing instructions
  1999-10-15  9:30 PATCH: (on Alpha) emulating missing instructions Luke Deller
  1999-10-15 12:42 ` Eric Bohm
@ 1999-10-15 14:28 ` Michal Jaegermann
  1999-10-16  9:13 ` patch_v2: " Luke Deller
  2 siblings, 0 replies; 12+ messages in thread
From: Michal Jaegermann @ 1999-10-15 14:28 UTC (permalink / raw)
  To: axp-list

On Fri, Oct 15, 1999 at 07:30:21PM +1000, Luke Deller wrote:
> (Loki say not to use 2.2.12 for Civilization CTP) 

Any ideas if this is because of the same floating point issues
which trip em86?  Or they run into something else?

Warning!  Unpatched 2.2.11 has very nasty memory leaks.

  Michal


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: PATCH: (on Alpha) emulating missing instructions
  1999-10-15 12:42 ` Eric Bohm
@ 1999-10-15 15:02   ` Luke Deller
  1999-10-16  4:10     ` Eric Bohm
  0 siblings, 1 reply; 12+ messages in thread
From: Luke Deller @ 1999-10-15 15:02 UTC (permalink / raw)
  To: Eric Bohm; +Cc: axp-list, linux-kernel, Daniel Paul Potts

On Fri, 15 Oct 1999, Eric Bohm wrote:

> >>>>> "Luke" == Luke Deller <luked@cse.unsw.edu.au> writes:
> 
>     Luke> Daniel & I tried to run Loki's new beta version of
>     Luke> Civilization Call to Power for alpha linux on a multia (ev4
>     Luke> alpha).  We got an illegal instruction exception.  We
>     Luke> discovered that it was compiled for ev6, and so contained
>     Luke> instructions not supported by our CPU.
> 
>     Luke> So we have patched the linux kernel to emulate the
>     Luke> instructions we needed.  These instructions are: - byte/word
>     Luke> load/store instructions (ldbu,stb,ldwu,stw) - some
>     Luke> multimedia instructions (minsw, maxsw, minuw, maxuw, minsb,
>     Luke> maxsb, minub, maxub)
> 
> Good work.
> 
> The same problem happens on my EV56.  Would you expect your patch to
> work there also?  Or are there EV5 elements that I should expect
> to be issues?

I think that ev56 supports the byte/word load/store instructions, but it is
still missing the multimedia instructions (minsw etc).  I would expect that
ev56 users could also use this patch.  Let me know if it works ok :-)

--------------------------------------------------------------------------
           Luke Deller                               luked@cse.unsw.edu.au
 _--_|\    Computer Engineering student           
/      \   School of Computer Science and Engineering     ? ? ? ?        
\_.--._*   The University of New South Wales               ~~^^~  
      v    Sydney, NSW     2052    AUSTRALIA                o o
-------------------------------------------------------ooO--(_)--Ooo------


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: PATCH: (on Alpha) emulating missing instructions
  1999-10-15 15:02   ` Luke Deller
@ 1999-10-16  4:10     ` Eric Bohm
  0 siblings, 0 replies; 12+ messages in thread
From: Eric Bohm @ 1999-10-16  4:10 UTC (permalink / raw)
  To: axp-list

>>>>> "Luke" == Luke Deller <luked@cse.unsw.edu.au> writes:

    Luke> On Fri, 15 Oct 1999, Eric Bohm wrote:
    >> >>>>> "Luke" == Luke Deller <luked@cse.unsw.edu.au> writes:
    >> 
    Luke> Daniel & I tried to run Loki's new beta version of
    Luke> Civilization Call to Power for alpha linux on a multia (ev4
    Luke> alpha).  We got an illegal instruction exception.  We
    Luke> discovered that it was compiled for ev6, and so contained
    Luke> instructions not supported by our CPU.
    >>
    Luke> So we have patched the linux kernel to emulate the
    Luke> instructions we needed.  These instructions are: - byte/word
    Luke> load/store instructions (ldbu,stb,ldwu,stw) - some
    Luke> multimedia instructions (minsw, maxsw, minuw, maxuw, minsb,
    Luke> maxsb, minub, maxub)
    Eric> Good work.

    Eric> The same problem happens on my EV56.  Would you expect your
    Eric> patch to work there also?  Or are there EV5 elements that I
    Eric> should expect to be issues?

    Luke> I think that ev56 supports the byte/word load/store
    Luke> instructions, but it is still missing the multimedia
    Luke> instructions (minsw etc).  I would expect that ev56 users
    Luke> could also use this patch.  Let me know if it works ok :-)

It is working quite well here in my LX164.

Thank you very much.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* patch_v2: (on Alpha) emulating missing instructions
  1999-10-15  9:30 PATCH: (on Alpha) emulating missing instructions Luke Deller
  1999-10-15 12:42 ` Eric Bohm
  1999-10-15 14:28 ` Michal Jaegermann
@ 1999-10-16  9:13 ` Luke Deller
  2 siblings, 0 replies; 12+ messages in thread
From: Luke Deller @ 1999-10-16  9:13 UTC (permalink / raw)
  To: linux-kernel; +Cc: axp-list, Daniel Paul Potts

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2516 bytes --]

Here is a better patch for the emulation code of some missing alpha
instructions.

This time the code should be secure ;)
Also I've added a description to Documentation/Configure.help

- Luke & Dan

On Fri, 15 Oct 1999, Luke Deller wrote:

> Daniel & I tried to run Loki's new beta version of Civilization Call to
> Power for alpha linux on a multia (ev4 alpha).  We got an illegal
> instruction exception.  We discovered that it was compiled for ev6, and so
> contained instructions not supported by our CPU.
> 
> So we have patched the linux kernel to emulate the instructions we needed.
> These instructions are:
> - byte/word load/store instructions (ldbu,stb,ldwu,stw)
> - some multimedia instructions (minsw, maxsw, minuw, maxuw, minsb, maxsb,
>   minub, maxub)
> 
> We have tried to make the emulation fairly fast - we have added it as some
> assembly language code to the "illegal instruction exception" kernel entry
> point in arch/alpha/kernel/entry.S:entIF.  (Of course it's still faster
> to avoid emulation and use a binary compiled for your generation of alpha
> cpu).
> 
> We put an option for enabling it in the "Kernel Hacking" section of the
> configuration.
> 
> The patch is applied to kernel version 2.2.11
> (Loki say not to use 2.2.12 for Civilization CTP) 
> 
> We only wrote enough emulation code to get CivilizationCTP to run ..  in the
> future it would be cool to see emulation of a more complete set of
> instructions in the kernel.
> 
> Hope this is useful to somebody,
> 
> Luke Deller & Daniel Potts.
> 
> --------------------------------------------------------------------------
>            Luke Deller                               luked@cse.unsw.edu.au
>  _--_|\    Computer Engineering student           
> /      \   School of Computer Science and Engineering     ? ? ? ?        
> \_.--._*   The University of New South Wales               ~~^^~  
>       v    Sydney, NSW     2052    AUSTRALIA                o o
> -------------------------------------------------------ooO--(_)--Ooo------
> 

--------------------------------------------------------------------------
           Luke Deller                               luked@cse.unsw.edu.au
 _--_|\    Computer Engineering student           
/      \   School of Computer Science and Engineering     ? ? ? ?        
\_.--._*   The University of New South Wales               ~~^^~  
      v    Sydney, NSW     2052    AUSTRALIA                o o
-------------------------------------------------------ooO--(_)--Ooo------

[-- Attachment #2: linux-alpha-emu-v2-for2_2_11.patch --]
[-- Type: TEXT/PLAIN, Size: 19234 bytes --]

diff -u --recursive --new-file v2.2.11/linux/Documentation/Configure.help linux/Documentation/Configure.help
--- v2.2.11/linux/Documentation/Configure.help	Tue Aug 10 05:04:57 1999
+++ linux/Documentation/Configure.help	Sat Oct 16 18:50:42 1999
@@ -11588,8 +11588,22 @@
    Everyone using these boards should say Y here.  
    See "linux/Documentation/cpqarray.txt" for the current list of 
    boards supported by this driver, and for further information 
-   on the use of this driver. 
- 
+   on the use of this driver.
+
+Emulation of some extended alpha instructions
+CONFIG_ALPHA_EXTINSNS
+  This emulates some instructions which are not implemented in hardware
+  on some alpha CPU's.  Emulation is provided for byte/word load/store
+  instructions (in the BWX instruction set extension) and some multimedia
+  extension instructions.  If you say Y here then this emulation code will
+  be included in your kernel.  Any of these instructions which your
+  hardware supports will not be emulated even if you have included the
+  emulation code in your kernel.
+
+  Here is the list of emulated instructions:
+  maxuw, maxsw, minuw, minsw, maxub, maxsb, minsb, minub,
+  stb, stw, ldbu, ldwu.
+
 #
 # A couple of things I keep forgetting:
 #   capitalize: AppleTalk, Ethernet, DOS, DMA, FAT, FTP, Internet, 
diff -u --recursive --new-file v2.2.11/linux/arch/alpha/config.in linux/arch/alpha/config.in
--- v2.2.11/linux/arch/alpha/config.in	Sun May 23 06:41:37 1999
+++ linux/arch/alpha/config.in	Fri Oct 15 18:44:37 1999
@@ -280,6 +280,7 @@
 #bool 'Debug kmalloc/kfree' CONFIG_DEBUG_MALLOC
 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
   tristate 'Kernel FP software completion' CONFIG_MATHEMU
+  bool 'Emulation of some extended instruction sets' CONFIG_ALPHA_EXTINSNS
 else
   define_bool CONFIG_MATHEMU y
 fi
diff -u --recursive --new-file v2.2.11/linux/arch/alpha/defconfig linux/arch/alpha/defconfig
--- v2.2.11/linux/arch/alpha/defconfig	Sun Jun 13 04:52:51 1999
+++ linux/arch/alpha/defconfig	Fri Oct 15 18:44:37 1999
@@ -330,4 +330,5 @@
 # Kernel hacking
 #
 CONFIG_MATHEMU=y
+# CONFIG_ALPHA_EXTINSNS is not set
 # CONFIG_MAGIC_SYSRQ is not set
diff -u --recursive --new-file v2.2.11/linux/arch/alpha/kernel/entry.S linux/arch/alpha/kernel/entry.S
--- v2.2.11/linux/arch/alpha/kernel/entry.S	Tue Aug 10 05:04:57 1999
+++ linux/arch/alpha/kernel/entry.S	Sat Oct 16 19:04:41 1999
@@ -39,6 +39,13 @@
 #define	PF_PTRACED	0x00000010
 
 /*
+ * This is used to tell if a memory address is in user land.
+ * This must be consistent with USER_DS in include/asm-alpha/uaccess.h 
+ * and TASK_SIZE in include/asm-alpha/processor.h
+ */
+#define LOG2_TASKSIZE 42
+
+/*
  * This defines the normal kernel pt-regs layout.
  *
  * regs 9-15 preserved by C code
@@ -173,10 +180,836 @@
 	jsr	$31,do_entArith
 .end entArith
 
+#ifdef CONFIG_ALPHA_EXTINSNS
+/* emulation of some extended alpha instructions */
+
+/* This emulation code doesn't handle segfaults as nicely as it should ..
+ * it just faults in kernel mode (resulting in the user task being killed)
+ * rather than pretending that the fault happened in userland (which should
+ * result in a SIGSEGV being sent to the user task).
+ *
+ * The emulation code ensures that the user doesn't access kernel space by
+ * checking that the high bits of the load/store virtual address are zero.
+ */
+
+.align 3
+.ent	get_user_sp
+get_user_sp:
+	subq		$30,6*8,$30
+	stq		$0,0($30)
+	stq		$1,8($30)
+	stq		$16,16($30)
+	mov		$25,$3
+	stq		$22,24($30)
+	stq		$23,32($30)
+	stq		$24,40($30)
+	call_pal	PAL_rdusp
+	ldq		$24,40($30)
+	mov		$3,$25
+	ldq		$23,32($30)
+	ldq		$22,24($30)
+	mov		$0,$3
+	ldq		$16,16($30)
+	ldq		$1,8($30)
+	ldq		$0,0($30)
+	addq		$30,6*8,$30
+	ret		$31,($5)
+.end	get_user_sp
+
+.align 3
+.ent	put_user_sp
+put_user_sp:
+	subq		$30,5*8,$30
+	stq		$16,0($30)
+	stq		$22,8($30)
+	stq		$23,16($30)
+	mov		$3,$16
+	stq		$24,24($30)
+	mov		$1,$3
+	stq		$25,32($30)
+	call_pal	PAL_wrusp
+	ldq		$25,32($30)
+	ldq		$24,24($30)
+	mov		$3,$1
+	ldq		$23,16($30)
+	ldq		$22,8($30)
+	ldq		$16,0($30)
+	addq		$30,5*8,$30
+	ret		$31,($5)
+.end	put_user_sp
+
+/* a code table .. make sure each entry is exactly 2 instructions */
+.align 3
+.ent	get_ureg_table
+get_ureg0:
+	ldq	$3,8*0($30)
+	ret	$31,($5)
+get_ureg1:
+	ldq	$3,8*1($30)
+	ret	$31,($5)
+get_ureg2:
+	ldq	$3,8*2($30)
+	ret	$31,($5)
+get_ureg3:
+	ldq	$3,8*3($30)
+	ret	$31,($5)
+get_ureg4:
+	ldq	$3,8*4($30)
+	ret	$31,($5)
+get_ureg5:
+	ldq	$3,8*5($30)
+	ret	$31,($5)
+get_ureg6:
+	mov	$6,$3
+	ret	$31,($5)
+get_ureg7:
+	mov	$7,$3
+	ret	$31,($5)
+get_ureg8:
+	mov	$8,$3
+	ret	$31,($5)
+get_ureg9:
+	mov	$9,$3
+	ret	$31,($5)
+get_ureg10:
+	mov	$10,$3
+	ret	$31,($5)
+get_ureg11:
+	mov	$11,$3
+	ret	$31,($5)
+get_ureg12:
+	mov	$12,$3
+	ret	$31,($5)
+get_ureg13:
+	mov	$13,$3
+	ret	$31,($5)
+get_ureg14:
+	mov	$14,$3
+	ret	$31,($5)
+get_ureg15:
+	mov	$15,$3
+	ret	$31,($5)
+get_ureg16:
+	ldq	$3,8*10($30)
+	ret	$31,($5)
+get_ureg17:
+	ldq	$3,8*11($30)
+	ret	$31,($5)
+get_ureg18:
+	ldq	$3,8*12($30)
+	ret	$31,($5)
+get_ureg19:
+	mov	$19,$3
+	ret	$31,($5)
+get_ureg20:
+	mov	$20,$3
+	ret	$31,($5)
+get_ureg21:
+	mov	$21,$3
+	ret	$31,($5)
+get_ureg22:
+	mov	$22,$3
+	ret	$31,($5)
+get_ureg23:
+	mov	$23,$3
+	ret	$31,($5)
+get_ureg24:
+	mov	$24,$3
+	ret	$31,($5)
+get_ureg25:
+	mov	$25,$3
+	ret	$31,($5)
+get_ureg26:
+	mov	$26,$3
+	ret	$31,($5)
+get_ureg27:
+	mov	$27,$3
+	ret	$31,($5)
+get_ureg28:
+	mov	$28,$3
+	ret	$31,($5)
+get_ureg29:
+	ldq	$3,9*8($30)
+	ret	$31,($5)
+get_ureg30:
+	br	$31,get_user_sp 
+	ret	$31,($5)
+get_ureg31:
+	mov	$31,$3
+	ret	$31,($5)
+.end	get_ureg_table
+
+/* another code table .. make sure each entry is exactly 2 instructions */
+.align 3
+.ent	put_ureg_table
+put_ureg0:
+	stq	$3,8*0($30)
+	ret	$31,($5)
+put_ureg1:
+	stq	$3,8*1($30)
+	ret	$31,($5)
+put_ureg2:
+	stq	$3,8*2($30)
+	ret	$31,($5)
+put_ureg3:
+	stq	$3,8*3($30)
+	ret	$31,($5)
+put_ureg4:
+	stq	$3,8*4($30)
+	ret	$31,($5)
+put_ureg5:
+	stq	$3,8*5($30)
+	ret	$31,($5)
+put_ureg6:
+	mov	$3,$6
+	ret	$31,($5)
+put_ureg7:
+	mov	$3,$7
+	ret	$31,($5)
+put_ureg8:
+	mov	$3,$8
+	ret	$31,($5)
+put_ureg9:
+	mov	$3,$9
+	ret	$31,($5)
+put_ureg10:
+	mov	$3,$10
+	ret	$31,($5)
+put_ureg11:
+	mov	$3,$11
+	ret	$31,($5)
+put_ureg12:
+	mov	$3,$12
+	ret	$31,($5)
+put_ureg13:
+	mov	$3,$13
+	ret	$31,($5)
+put_ureg14:
+	mov	$3,$14
+	ret	$31,($5)
+put_ureg15:
+	mov	$3,$15
+	ret	$31,($5)
+put_ureg16:
+	stq	$3,8*10($30)
+	ret	$31,($5)
+put_ureg17:
+	stq	$3,8*11($30)
+	ret	$31,($5)
+put_ureg18:
+	stq	$3,8*12($30)
+	ret	$31,($5)
+put_ureg19:
+	mov	$3,$19
+	ret	$31,($5)
+put_ureg20:
+	mov	$3,$20
+	ret	$31,($5)
+put_ureg21:
+	mov	$3,$21
+	ret	$31,($5)
+put_ureg22:
+	mov	$3,$22
+	ret	$31,($5)
+put_ureg23:
+	mov	$3,$23
+	ret	$31,($5)
+put_ureg24:
+	mov	$3,$24
+	ret	$31,($5)
+put_ureg25:
+	mov	$3,$25
+	ret	$31,($5)
+put_ureg26:
+	mov	$3,$26
+	ret	$31,($5)
+put_ureg27:
+	mov	$3,$27
+	ret	$31,($5)
+put_ureg28:
+	mov	$3,$28
+	ret	$31,($5)
+put_ureg29:
+	stq	$3,9*8($30)
+	ret	$31,($5)
+put_ureg30:
+	br	$31,put_user_sp 
+	ret	$31,($5)
+put_ureg31:
+	ret	$31,($5)
+.end	put_ureg_table
+
+/* this macro trashes $5 & index, and returns user reg val in $3 */
+#define get_user_reg(index)           \
+	br	$3,1f                 ;\
+1:	                              ;\
+	s8addq	index,$3,index        ;\
+	lda	$5,get_ureg0-1b($31)  ;\
+	addq	index,$5,index        ;\
+	jsr	$5,(index),get_ureg16
+
+/* this macro trashes $3, $5 & index, and takes new user reg val in $3 */
+#define put_user_reg(index)           \
+	br	$5,1f                 ;\
+1:	                              ;\
+	s8addq	index,$5,index        ;\
+	lda	$5,put_ureg0-1b($31)  ;\
+	addq	index,$5,index        ;\
+	jsr	$5,(index),put_ureg16
+
+.align 3
+.globl	emul_ldwu
+.ent	emul_ldwu
+emul_ldwu:
+	stq	$3,24($30)
+	stq	$4,32($30)
+	stq	$5,40($30)
+
+	srl	$0,21,$1
+	srl	$0,16,$2
+	and	$1,0x1f,$1
+	sll	$0,48,$0
+	and	$2,0x1f,$2
+	sra	$0,48,$0   /* $0 = disp */
+	get_user_reg($2)   /* $3 = Rb  */
+	addq	$0,$3,$0
+	srl	$0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
+	cmovne	$5,$31,$0       /* then force a segfault by putting addr=0 */
+	ldq_u	$3,0($0)
+	ldq_u	$5,1($0)
+	extwl	$3,$0,$3
+	extwh	$5,$0,$5
+	or	$3,$5,$3
+	put_user_reg($1)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_ldwu
+
+.align 3
+.globl	emul_stw
+.ent	emul_stw
+emul_stw:
+	stq	$3,24($30)
+	stq	$4,32($30)
+	stq	$5,40($30)
+
+	srl	$0,21,$1
+	srl	$0,16,$2
+	and	$1,0x1f,$1
+	sll	$0,48,$0
+	and	$2,0x1f,$2
+	sra	$0,48,$0   /* $0 = disp */
+	get_user_reg($1)
+	mov	$3,$1
+	get_user_reg($2)   /* $3 = Rb  */
+	/* needs writing here */
+	addq	$0,$3,$0
+	srl	$0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
+	cmovne	$5,$31,$0       /* then force a segfault by putting addr=0 */
+	ldq_u	$3,1($0)
+	ldq_u	$2,0($0)
+	inswh	$1,$0,$5
+	inswl	$1,$0,$4
+	mskwh	$3,$0,$3
+	mskwl	$2,$0,$2
+	or	$3,$5,$3
+	or	$2,$4,$2
+	stq_u	$3,1($0)
+	stq_u	$2,0($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_stw
+
+.align 3
+.globl	emul_ldbu
+.ent	emul_ldbu
+emul_ldbu:
+	stq	$3,24($30)
+	stq	$4,32($30)
+	stq	$5,40($30)
+
+	srl	$0,21,$1
+	srl	$0,16,$2
+	and	$1,0x1f,$1
+	sll	$0,48,$0
+	and	$2,0x1f,$2
+	sra	$0,48,$0   /* $0 = disp */
+	get_user_reg($2)   /* $3 = Rb  */
+	addq	$0,$3,$0
+	srl	$0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
+	cmovne	$5,$31,$0       /* then force a segfault by putting addr=0 */
+	ldq_u	$3,0($0)
+	extbl	$3,$0,$3
+	put_user_reg($1)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_ldbu
+
+.align 3
+.globl	emul_stb
+.ent	emul_stb
+emul_stb:
+	stq	$3,24($30)
+	stq	$4,32($30)
+	stq	$5,40($30)
+
+	srl	$0,21,$1
+	srl	$0,16,$2
+	and	$1,0x1f,$1
+	sll	$0,48,$0
+	and	$2,0x1f,$2
+	sra	$0,48,$0   /* $0 = disp */
+	get_user_reg($1)
+	mov	$3,$1
+	get_user_reg($2)   /* $3 = Rb  */
+	addq	$0,$3,$0
+	srl	$0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
+	cmovne	$5,$31,$0       /* then force a segfault by putting addr=0 */
+	ldq_u	$2,0($0)
+	insbl	$1,$0,$3
+	mskbl	$2,$0,$2
+
+	ldq	$5,40($30)
+	or	$2,$3,$2
+
+	ldq	$3,24($30)
+	stq_u	$2,0($0)
+
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_stb
+
+.align 3
+.globl	emul_minsw_4
+.ent	emul_minsw_4
+emul_minsw_4:
+	stq	$6,48($30)
+
+	extwl	$3,0x6,$4 /* get word 3 of ra (most significant) -> $4 */
+	extwl	$2,0x6,$1 /* get word 3 of rb                    -> $2 */
+	cmple	$2,$3,$6
+	cmovne	$6,$1,$4
+
+	extwl	$3,0x4,$5 /* get word 2 of ra                    -> $5 */
+	extwl	$2,0x4,$1 /* get word 2 of rb                    -> $1 */
+	cmple	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x2,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x2,$1 /* get word 1 of rb                    -> $1 */
+	cmple	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x0,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x0,$1 /* get word 1 of rb                    -> $1 */
+	cmple	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$3
+	
+	ldq	$6,48($30)
+
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_minsw_4
+
+.align 3
+.globl	emul_minuw_4
+.ent	emul_minuw_4
+emul_minuw_4:
+	stq	$6,48($30)
+
+	extwl	$3,0x6,$4 /* get word 3 of ra (most significant) -> $4 */
+	extwl	$2,0x6,$1 /* get word 3 of rb                    -> $2 */
+	cmpule	$2,$3,$6
+	cmovne	$6,$1,$4
+
+	extwl	$3,0x4,$5 /* get word 2 of ra                    -> $5 */
+	extwl	$2,0x4,$1 /* get word 2 of rb                    -> $1 */
+	cmpule	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x2,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x2,$1 /* get word 1 of rb                    -> $1 */
+	cmpule	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x0,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x0,$1 /* get word 1 of rb                    -> $1 */
+	cmpule	$2,$3,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$3
+	
+	ldq	$6,48($30)
+
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_minuw_4
+
+.align 3
+.globl	emul_maxsw_4
+.ent	emul_maxsw_4
+emul_maxsw_4:
+	stq	$6,48($30)
+
+	extwl	$3,0x6,$4 /* get word 3 of ra (most significant) -> $4 */
+	extwl	$2,0x6,$1 /* get word 3 of rb                    -> $2 */
+	cmple	$4,$1,$6
+	cmovne	$6,$1,$4
+
+	extwl	$3,0x4,$5 /* get word 2 of ra                    -> $5 */
+	extwl	$2,0x4,$1 /* get word 2 of rb                    -> $1 */
+	cmple	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x2,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x2,$1 /* get word 1 of rb                    -> $1 */
+	cmple	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x0,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x0,$1 /* get word 1 of rb                    -> $1 */
+	cmple	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$3
+	
+	ldq	$6,48($30)
+
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_maxsw_4
+
+.align 3
+.globl	emul_maxuw_4
+.ent	emul_maxuw_4
+emul_maxuw_4:
+	stq	$6,48($30)
+
+	extwl	$3,0x6,$4 /* get word 3 of ra (most significant) -> $4 */
+	extwl	$2,0x6,$1 /* get word 3 of rb                    -> $2 */
+	cmpule	$4,$1,$6
+	cmovne	$6,$1,$4
+
+	extwl	$3,0x4,$5 /* get word 2 of ra                    -> $5 */
+	extwl	$2,0x4,$1 /* get word 2 of rb                    -> $1 */
+	cmpule	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x2,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x2,$1 /* get word 1 of rb                    -> $1 */
+	cmpule	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$4
+
+	extwl	$3,0x0,$5 /* get word 1 of ra                    -> $5 */
+	extwl	$2,0x0,$1 /* get word 1 of rb                    -> $1 */
+	cmpule	$5,$1,$6
+	sll	$4,16,$4
+	cmovne	$6,$1,$5
+	or	$4,$5,$3
+	
+	ldq	$6,48($30)
+
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_maxuw_4
+
+.align 3
+.globl	emul_maxub_8
+.ent	emul_maxub_8
+emul_maxub_8:
+	cmpbge	$2,$3,$1
+	zap	$3,$1,$3
+	zapnot	$2,$1,$2
+	or	$3,$2,$3
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_maxub_8
+
+.align 3
+.globl	emul_maxub_8
+.ent	emul_maxub_8
+emul_maxsb_8:
+	lda	$1,0x7f7f($31)
+	ldah	$1,0x7f7f($1)
+	sll	$1,32,$5
+	or	$1,$5,$1
+	not	$1,$1
+	xor	$3,$1,$5
+	xor	$2,$1,$1
+
+	cmpbge	$1,$5,$1
+	zap	$3,$1,$3
+	zapnot	$2,$1,$2
+	or	$3,$2,$3
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_maxub_8
+
+.align 3
+.globl	emul_minub_8
+.ent	emul_minub_8
+emul_minub_8:
+	cmpbge	$3,$2,$1
+	zap	$3,$1,$3
+	zapnot	$2,$1,$2
+	or	$3,$2,$3
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_minub_8
+
+.align 3
+.globl	emul_minsb_8
+.ent	emul_minsb_8
+emul_minsb_8:
+	lda	$1,0x7f7f($31)
+	ldah	$1,0x7f7f($1)
+	sll	$1,32,$5
+	or	$1,$5,$1
+	not	$1,$1
+	xor	$3,$1,$5
+	xor	$2,$1,$1
+
+	cmpbge	$5,$1,$1
+	zap	$3,$1,$3
+	zapnot	$2,$1,$2
+	or	$3,$2,$3
+	put_user_reg($0)
+
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_minsb_8
+
+.align 3
+.globl	emul_sexw
+.ent	emul_sexw
+emul_sexw:
+	sll	$3,48,$3
+	and	$0,0x1f,$1
+	sra	$3,48,$3
+	put_user_reg($1)
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_sexw
+
+.align 3
+.globl	emul_sexb
+.ent	emul_sexb
+emul_sexb:
+	sll	$3,56,$3
+	and	$0,0x1f,$1
+	sra	$3,56,$3
+	put_user_reg($1)
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	call_pal PAL_rti
+.end	emul_sexb
+
+.align 3
+.globl	emul_mmx
+.ent	emul_mmx
+emul_mmx:
+	stq	$3,24($30)
+	stq	$4,32($30)
+	stq	$5,40($30)
+
+	srl	$0,5,$4
+	srl	$0,12,$2
+	and	$4,0x3f,$4
+	blbs	$2,21f
+	srl	$0,16,$1
+	and	$1,0x1f,$1
+	get_user_reg($1)
+21:
+	srl	$0,13,$1
+	and	$1,0xff,$1
+	cmovlbs	$2,$1,$3
+	/* now:	$0 = insn
+		$3 = regb val
+		$4 = operation function code */
+	cmpeq	$4,0x1,$2
+	beq	$4,emul_sexb
+	bne	$2,emul_sexw
+	srl	$0,21,$1
+	mov	$3,$2
+	and	$1,0x1f,$1
+	get_user_reg($1)
+	cmpeq	$4,0x3a,$1
+	cmpeq	$4,0x38,$5
+	and	$0,0x1f,$0
+	/* now:	$0 = rc index
+		$2 = rb val
+		$3 = ra val
+		$4 = operation function code */
+	bne	$1,emul_minub_8
+	bne	$5,emul_minsb_8
+	cmpeq	$4,0x3e,$1
+	cmpeq	$4,0x3c,$5
+	bne	$1,emul_maxsb_8
+	bne	$5,emul_maxub_8
+	cmpeq	$4,0x39,$1
+	cmpeq	$4,0x3f,$5
+	bne	$1,emul_minsw_4
+	bne	$5,emul_maxsw_4
+	cmpeq	$4,0x3b,$1
+	cmpeq	$4,0x3d,$5
+	bne	$1,emul_minuw_4
+	bne	$5,emul_maxuw_4
+	ldq	$5,40($30)
+	ldq	$4,32($30)
+	ldq	$3,24($30)
+	ldq	$2,16($30)
+	ldq	$1,8($30)
+	ldq	$0,0($30)
+	addq	$30,7*8,$30
+	br	old_entIF
+.end	emul_mmx
+
+#endif /* CONFIG_ALPHA_EXTINSNS */
+
 .align 3
 .globl	entIF
 .ent	entIF
 entIF:
+#ifdef CONFIG_ALPHA_EXTINSNS
+	subq	$30,7*8,$30 /* 3 regs saved here, 3 or 4 more saved in fns */
+	stq	$0,0($30)
+	ldq	$0,8+7*8($30)
+	stq	$1,8($30)
+	ldl	$0,-4($0)
+	stq	$2,16($30)
+	srl	$0,26,$1
+	and	$1,0x3f,$1
+	cmpeq	$1,0x1c,$2
+	bne	$2,emul_mmx
+	cmpeq	$1,0x0a,$2
+	bne	$2,emul_ldbu
+	cmpeq	$1,0x0e,$2
+	bne	$2,emul_stb
+	cmpeq	$1,0x0c,$2
+	cmpeq	$1,0x0d,$1
+	bne	$2,emul_ldwu
+	bne	$1,emul_stw
+	ldq	$0,0($30)
+	ldq	$1,8($30)
+	ldq	$2,16($30)
+	addq	$30,7*8,$30
+old_entIF:
+#endif /* CONFIG_ALPHA_EXTINSNS */
 	SAVE_ALL
 	lda	$8,0x3fff
 	lda	$26,ret_from_sys_call

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: patch_v2: (on Alpha) emulating missing instructions
@ 1999-10-18 13:05 Robert Harley
  0 siblings, 0 replies; 12+ messages in thread
From: Robert Harley @ 1999-10-18 13:05 UTC (permalink / raw)
  To: axp-list

Luke Deller wrote:
>+ extwl $3,0x6,$4 /* get word 3 of ra (most significant) -> $4 */ 
>+ extwl $2,0x6,$1 /* get word 3 of rb -> $2 */ 
>+ cmple $2,$3,$6 
>+ cmovne $6,$1,$4 

Surely you should compare registers 1 and 4, rather than 2 and 3.


>+ extwl $3,0x4,$5 /* get word 2 of ra -> $5 */ 
>+ extwl $2,0x4,$1 /* get word 2 of rb -> $1 */ 
>+ cmple $2,$3,$6 
>+ sll $4,16,$4 
>+ cmovne $6,$1,$5 
>+ or $4,$5,$4 

Likewise with 1 and 5.  Same elsewhere.


>+.globl emul_maxub_8 
>+.ent emul_maxub_8 
>+emul_maxsb_8: 

ub or sb?


>+ lda $1,0x7f7f($31) 
>+ ldah $1,0x7f7f($1) 
>+ sll $1,32,$5 
>+ or $1,$5,$1 
>+ not $1,$1 

I think you could get the 0x8080808080808080 pattern shorter by something like:

not $31, $1
zap $1, 0x55, $1
srl $1, 1, $5
xor $1, $5, $1


Bye,
  Rob.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: patch_v2: (on Alpha) emulating missing instructions
@ 1999-10-18 14:46 Robert Harley
  1999-10-18 15:31 ` Phil Carmody
  0 siblings, 1 reply; 12+ messages in thread
From: Robert Harley @ 1999-10-18 14:46 UTC (permalink / raw)
  To: axp-list

BTW, here is a fast and short way of doing minuw():

------------------------------------------------------------------------------
#define CMPBGE(a, b, c) \
  asm("cmpbge %1, %2, %0" : "=r" (c) : "r" (a), "r" (b))
#define ZAP(a, b, c) \
  asm("zap %1, %2, %0" : "=r" (c) : "r" (a), "r" (b))
#define ZAPNOT(a, b, c) \
  asm("zapnot %1, %2, %0" : "=r" (c) : "r" (a), "r" (b))

static u64 minuw(u64 x, u64 y) {
  u64 eq, ge1, ge2;

  CMPBGE(x, y, ge1);
  CMPBGE(0, x ^ y, eq);

  ge2 = (ge1 & ~eq | eq & ge1<<1) & 0xAA;
  ge2 |= ge2>>1;

  ZAP(x, ge2, x);
  ZAPNOT(y, ge2, y);

  return x | y;
} /* end function minuw */
------------------------------------------------------------------------------


The output from gcc 2.95 looks like:

------------------------------------------------------------------------------
minuw:
        cmpbge $16, $17, $1
        xor $16,$17,$3
        mov $31,$2
        cmpbge $2, $3, $2
        addq $1,$1,$4
        bic $1,$2,$1
        and $2,$4,$2
        bis $1,$2,$1
        and $1,170,$1
        srl $1,1,$2
        bis $1,$2,$1
        zapnot $17, $1, $17
        zap $16, $1, $16
        bis $16,$17,$0
        ret $31,($26),1
        .end minuw
------------------------------------------------------------------------------


This bit:

        mov $31,$2
        cmpbge $2, $3, $2

would be better as:

        cmpbge $31, $3, $2


Bye,
  Rob.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: patch_v2: (on Alpha) emulating missing instructions
  1999-10-18 14:46 Robert Harley
@ 1999-10-18 15:31 ` Phil Carmody
  1999-10-23 20:39   ` Richard Henderson
  0 siblings, 1 reply; 12+ messages in thread
From: Phil Carmody @ 1999-10-18 15:31 UTC (permalink / raw)
  To: axp-list

On Mon, 18 Oct 1999, EXT Robert Harley wrote:
>   ge2 = (ge1 & ~eq | eq & ge1<<1) & 0xAA;


For the C coders out there, an expression of the form 

D = (A & M) | (B & ~M);

can be turned into 

D = A ^ ((A ^ B) & M);

i.e. change (^) the bits which are different (A^B) and within (&) the mask

Now it appears that the alpha can do (B&~M) as one instruction, and
there's no need to create a temporary ~M, so this isn't a win for us.
However, as it is a win on other architectures, and isn't a loss for
us I'd thought I'd share it.

Phil
-- 
Phil Carmody
Not speaking for or on behalf of Nokia Telecommunications

sequal : second part of a dilogy which is identical to the first part. 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: patch_v2: (on Alpha) emulating missing instructions
  1999-10-18 15:31 ` Phil Carmody
@ 1999-10-23 20:39   ` Richard Henderson
       [not found]     ` <rth@twiddle.net>
  0 siblings, 1 reply; 12+ messages in thread
From: Richard Henderson @ 1999-10-23 20:39 UTC (permalink / raw)
  To: axp-list

On Mon, Oct 18, 1999 at 04:31:25PM +0100, Phil Carmody wrote:
>	D = (A & M) | (B & ~M);
> can be turned into 
>	D = A ^ ((A ^ B) & M);

I'll note that the former expression, given an andnot operation,
has 3 ops and a tree height of 2.  The later expression has 3 ops
and a tree height of 3.  I.e. the former expression takes better
advantage of instruction-level parallelism.


r~


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: patch_v2: (on Alpha) emulating missing instructions
       [not found]     ` <rth@twiddle.net>
@ 1999-10-24 15:04       ` Christoph Dworzak
  1999-10-25  9:47         ` Phil Carmody
  0 siblings, 1 reply; 12+ messages in thread
From: Christoph Dworzak @ 1999-10-24 15:04 UTC (permalink / raw)
  To: axp-list

Hi

On Oct 23 Richard Henderson (rth@twiddle.net) wrote:
> On Mon, Oct 18, 1999 at 04:31:25PM +0100, Phil Carmody wrote:
> >	D = (A & M) | (B & ~M);

I used the same sequence twice to exchange bits between two
variables depending on a mask:

t = (A & M) | (B & ~M);
B = (B & M) | (A & ~M);
A = t;

> > can be turned into 
> >	D = A ^ ((A ^ B) & M);
> 
> I'll note that the former expression, given an andnot operation,
> has 3 ops and a tree height of 2.  The later expression has 3 ops
> and a tree height of 3.  I.e. the former expression takes better
> advantage of instruction-level parallelism.
 
In my App the later is faster (4 ops instead of 6):

t = (A ^ B) & M;
A ^= t;
B ^= t;

Can it get any better?

Bye
 dworz


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: patch_v2: (on Alpha) emulating missing instructions
  1999-10-24 15:04       ` Christoph Dworzak
@ 1999-10-25  9:47         ` Phil Carmody
  0 siblings, 0 replies; 12+ messages in thread
From: Phil Carmody @ 1999-10-25  9:47 UTC (permalink / raw)
  To: axp-list

On Sun, 24 Oct 1999, EXT axp@amazing.ch (Christoph Dworzak) wrote:
> Hi
> 
> On Oct 23 Richard Henderson (rth@twiddle.net) wrote:
> > On Mon, Oct 18, 1999 at 04:31:25PM +0100, Phil Carmody wrote:
> > >	D = (A & M) | (B & ~M);
> 
> I used the same sequence twice to exchange bits between two
> variables depending on a mask:
> 
> t = (A & M) | (B & ~M);
> B = (B & M) | (A & ~M);
> A = t;
> 
> > > can be turned into 
> > >	D = A ^ ((A ^ B) & M);
> > 
> > I'll note that the former expression, given an andnot operation,
> > has 3 ops and a tree height of 2.  The later expression has 3 ops
> > and a tree height of 3.  I.e. the former expression takes better
> > advantage of instruction-level parallelism.

Accepted, yes. However, with registers coming out of your ears there
should be plenty of other things that can fill the gaps. (and OOOE
goes a long way to filling the gaps anyway).
I merely wanted people to have to tool in their toolkit, should it be
needed (as it was for Cristoph).
  
> In my App the later is faster (4 ops instead of 6):
> 
> t = (A ^ B) & M;
> A ^= t;
> B ^= t;
> 
> Can it get any better?

Yes, get a TI DSP processor (the MVP/MP will do) which can do 'insert bit
string' operations in a single processor cycle.

t=A
A=A with bits from B
B=B with bits from t

three ticks.

Phil
-- 
Phil Carmody
Not speaking for or on behalf of Nokia Telecommunications

Resistrance : Peaceful and passive resistance


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1999-10-25 12:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-10-15  9:30 PATCH: (on Alpha) emulating missing instructions Luke Deller
1999-10-15 12:42 ` Eric Bohm
1999-10-15 15:02   ` Luke Deller
1999-10-16  4:10     ` Eric Bohm
1999-10-15 14:28 ` Michal Jaegermann
1999-10-16  9:13 ` patch_v2: " Luke Deller
  -- strict thread matches above, loose matches on Subject: below --
1999-10-18 13:05 Robert Harley
1999-10-18 14:46 Robert Harley
1999-10-18 15:31 ` Phil Carmody
1999-10-23 20:39   ` Richard Henderson
     [not found]     ` <rth@twiddle.net>
1999-10-24 15:04       ` Christoph Dworzak
1999-10-25  9:47         ` Phil Carmody

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox