hppa qemu and string functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Off and on, I've been working on a user-only target of hppa to qemu. It's now about 95% working. If anyone would like to try it out, it's available at

  git://github.com/rth7680/qemu.git tgt-hppa

While implementing the unit-type instructions, I wondered why no one (outside hp?) had written a version of the string routines utilizing the UXOR insn, with the SomeByteZero and NoByteZero conditions.

Attached are versions of strlen, strchr and strrchr. They pass simple tests within my emulator; I'd be interested to know if they pass full glibc testing on real hardware.


Thanks,


r~
;! HP-PA  strlen

;! Copyright (C) 2016 Free Software Foundation, Inc.

	.text
	.export		strlen
	.balign		16
strlen:
	.proc
	.callinfo	frame=0,no_calls
	.entry

	;! Compute the number of bytes required to align the pointer.
	;! Shifting by 1 gets us 4 insns to play with per entry.
	ldo		-1(%r26), %r20
	depw,z		%r20, 30, 2, %r20
	blr		%r20, %r0
	 copy		%r26, %r28

	;! ptr % 4 == 1
	ldb		0(%r26), %r20
	cmpiclr,=	0, %r20, %r0
	b,n		9f
	ldo		1(%r26), %r26

	;! ptr % 4 == 2
	ldb		0(%r26), %r20
	cmpiclr,=	0, %r20, %r0
	b,n		9f
	ldo		1(%r26), %r26

	;! ptr % 4 == 3
	ldb		0(%r26), %r20
	cmpiclr,=	0, %r20, %r0
	b,n		9f
	ldo		1(%r26), %r26

	;! ptr % 4 == 0
	;! Main loop.  Use the Some Byte Zero unit condition to find
	;; a word containing the string terminator.
0:	ldw,ma		4(%r26), %r20
	uxor,sbz	%r0, %r20, %r0
	b,n		0b

	;! Found, somewhere in with word in %r20.  Test each byte in
	;! sequence, computing the appopriate offset from %r26 into %r21.
	ldo		-1(%r26), %r21
	extrw,u,<>	%r20, 23, 8, %r0
	ldo		-2(%r26), %r21
	extrw,u,<>	%r20, 15, 8, %r0
	ldo		-3(%r26), %r21
	extrw,u,<>	%r20,  7, 8, %r0
	ldo		-4(%r26), %r21
	bv		0(%r2)
	 sub		%r21, %r28, %r28

	;! Found, with no displacement off %r26.
9:	bv		0(%r2)
	 sub		%r26, %r28, %r28

	.exit
	.procend
;! HP-PA  strchr

;! Copyright (C) 2016 Free Software Foundation, Inc.

	.text
	.export		strchr
	.balign		16
strchr:
	.proc
	.callinfo	frame=0,no_calls
	.entry

	;! Compute the number of bytes required to align the pointer.
	;! Multiply by 3, giving us 6 insns per entry to work with.
	ldo		-1(%r26), %r20
	extrw,u		%r25, 31, 8, %r25
	extrw,u		%r20, 31, 2, %r20
	shladd,l	%r20, 1, %r20, %r20
	blr		%r20, %r0
	 copy		%r26, %r28

	;! ptr % 4 == 1
	ldb		0(%r28), %r20
	cmpclr,<>	%r25, %r20, %r0
	bv,n		0(%r2)
	cmpclr,<>	%r0, %r20, %r0
	b,n		9f
	ldo		1(%r28), %r28

	;! ptr % 4 == 2
	ldb		0(%r28), %r20
	cmpclr,<>	%r25, %r20, %r0
	bv,n		0(%r2)
	cmpclr,<>	%r0, %r20, %r0
	b,n		9f
	ldo		1(%r28), %r28

	;! ptr % 4 == 3
	ldb		0(%r28), %r20
	cmpclr,<>	%r25, %r20, %r0
	bv,n		0(%r2)
	cmpclr,<>	%r0, %r20, %r0
	b,n		9f
	ldo		1(%r28), %r28

	;! ptr % 4 == 0
	ldw,ma		4(%r28), %r20
	depw		%r25, 23, 8, %r25
	depw		%r25, 15, 16, %r25

	;! Main loop.  Use the No Byte Zero unit condition to find
	;; a word containing C or 0.
0:	uxor,nbz	%r25, %r20, %r0
	b,n		1f
	uxor,nbz	%r0, %r20, %r0
	b,n		1f
	b		0b
	 ldw,ma		4(%r28), %r20

	;! Found, somewhere in with word in %r20.
	;! Test each byte in sequence.
1:	extrw,u		%r25, 31, 8, %r25

	extrw,u		%r20,  7, 8, %r21
	ldo		-4(%r28), %r28
	cmpclr,<>	%r25, %r21, %r0
	bv,n		0(%r2)
	cmpclr,<>	%r0, %r21, %r0
	b,n		9f

	extrw,u		%r20, 15, 8, %r21
	ldo		1(%r28), %r28
	cmpclr,<>	%r25, %r21, %r0
	bv,n		0(%r2)
	cmpclr,<>	%r0, %r21, %r0
	b,n		9f

	extrw,u		%r20, 23, 8, %r21
	ldo		1(%r28), %r28
	cmpclr,<>	%r25, %r21, %r0
	bv,n		0(%r2)
	cmpclr,<>	%r0, %r21, %r0
	b,n		9f

	extrw,u		%r20, 31, 8, %r21
	ldo		1(%r28), %r28
	cmpclr,<>	%r25, %r21, %r0
	bv,n		0(%r2)

	;! String terminator found before the search character.
9:	bv		0(%r2)
	 ldi		0, %r28

	.exit
	.procend
;! HP-PA  strrchr

;! Copyright (C) 2016 Free Software Foundation, Inc.

	.text
	.export		strrchr
	.balign		16
strrchr:
	.proc
	.callinfo	frame=0,no_calls
	.entry

	;! Compute the number of bytes required to align the pointer.
	;! Multiply by 3, giving us 6 insns per entry to work with.
	ldo		-1(%r26), %r20
	extrw,u		%r25, 31, 8, %r25
	extrw,u		%r20, 31, 2, %r20
	shladd,l	%r20, 1, %r20, %r20
	blr		%r20, %r0
	 ;! Begin by assuming that C is not present.
	 ldi		0, %r28

	;! ptr % 4 == 1
	ldb		0(%r26), %r20
	cmpclr,<>	%r25, %r20, %r0
	copy		%r26, %r28
	cmpclr,<>	%r0, %r20, %r0
	bv,n		0(%r2)
	ldo		1(%r26), %r26

	;! ptr % 4 == 2
	ldb		0(%r26), %r20
	cmpclr,<>	%r25, %r20, %r0
	copy		%r26, %r28
	cmpclr,<>	%r0, %r20, %r0
	bv,n		0(%r2)
	ldo		1(%r26), %r26

	;! ptr % 4 == 3
	ldb		0(%r26), %r20
	cmpclr,<>	%r25, %r20, %r0
	copy		%r26, %r28
	cmpclr,<>	%r0, %r20, %r0
	bv,n		0(%r2)
	ldo		1(%r26), %r26

	;! ptr % 4 == 0
	ldw,ma		4(%r26), %r20
	copy		%r25, %r24
	depw		%r24, 23, 8, %r24
	depw		%r24, 15, 16, %r24

	;! Main loop.
0:	;; Test for a NUL terminator within the word and exit if found.
	uxor,nbz	%r0, %r20, %r0
	b,n		1f

	;; Test for C within the word.  If not found, loop and load the
	;; next word in the delay slot.  If found, load the next word
	;; now anyway, since we know that we havn't seen end-of-string.
	copy		%r20, %r21
	uxor,sbz	%r24, %r20, %r0
	b		0b
	 ldw,ma		4(%r26), %r20

	;; Found C within the "current" word.  Note that it is now in %r21,
	;; and the address for the beginning of that word is now -8(%r26),
	;; since we have incremented the pointer twice since the load.
	extrw,u		%r21,  7, 8, %r22
	cmpclr,<>	%r25, %r22, %r0
	ldo		-8(%r26), %r28

	extrw,u		%r21, 15, 8, %r22
	cmpclr,<>	%r25, %r22, %r0
	ldo		-7(%r26), %r28

	extrw,u		%r21, 23, 8, %r22
	cmpclr,<>	%r25, %r22, %r0
	ldo		-6(%r26), %r28

	extrw,u		%r21, 31, 8, %r22
	cmpclr,<>	%r25, %r22, %r0
	ldo		-5(%r26), %r28

	b,n		0b

	;! Found NUL somewhere in with word in %r20, loaded from -4(%r26).
	;! Test each byte in sequence.
1:	extrw,u		%r20,  7, 8, %r21
	cmpclr,<>	%r25, %r21, %r0
	ldo		-4(%r26), %r28
	cmpclr,<>	%r0, %r21, %r0
	bv,n		0(%r2)

	extrw,u		%r20, 15, 8, %r21
	cmpclr,<>	%r25, %r21, %r0
	ldo		-3(%r26), %r28
	cmpclr,<>	%r0, %r21, %r0
	bv,n		0(%r2)

	extrw,u		%r20, 23, 8, %r21
	cmpclr,<>	%r25, %r21, %r0
	ldo		-2(%r26), %r28
	cmpclr,<>	%r0, %r21, %r0
	bv,n		0(%r2)

	;; Having checked the others, the last byte must be NUL.
	;; Do check for the unusual case of C == NUL.
	cmpclr,<>	%r25, %r0, %r0
	ldo		-1(%r26), %r28
	bv,n		0(%r2)

	.exit
	.procend

[Index of Archives]     [Linux SoC]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux