public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* hppa qemu and string functions
@ 2016-11-09 12:53 Richard Henderson
  2016-11-09 14:51 ` Aw: " Helge Deller
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2016-11-09 12:53 UTC (permalink / raw)
  To: linux-parisc; +Cc: GNU C Library

[-- Attachment #1: Type: text/plain, Size: 597 bytes --]

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~

[-- Attachment #2: strlen.S --]
[-- Type: text/plain, Size: 1258 bytes --]

;! 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

[-- Attachment #3: strchr.S --]
[-- Type: text/plain, Size: 1791 bytes --]

;! 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

[-- Attachment #4: strrchr.S --]
[-- Type: text/plain, Size: 2554 bytes --]

;! 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

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

* Aw: hppa qemu and string functions
  2016-11-09 12:53 hppa qemu and string functions Richard Henderson
@ 2016-11-09 14:51 ` Helge Deller
  2016-11-09 15:51   ` Jeff Law
  2016-11-10  9:39   ` Richard Henderson
  0 siblings, 2 replies; 4+ messages in thread
From: Helge Deller @ 2016-11-09 14:51 UTC (permalink / raw)
  To: Richard Henderson; +Cc: linux-parisc, GNU C Library

Hi Richard,

> 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

COOL!
I'm happy to test, but can you shortly describe the required steps how I can build & test it?

With "user-only target of hppa" I assume this means that I can run hppa binaries
on e.g. x86-64, similiar to what is described here: https://wiki.debian.org/QemuUserEmulation ?

> 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.

Interesting.
I assume nobody did, because there are a few hppa/linux/glibc users anyway ? :-)
 
> 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.

If you like I can give you access to a hppa-linux box...

Helge

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

* Re: Aw: hppa qemu and string functions
  2016-11-09 14:51 ` Aw: " Helge Deller
@ 2016-11-09 15:51   ` Jeff Law
  2016-11-10  9:39   ` Richard Henderson
  1 sibling, 0 replies; 4+ messages in thread
From: Jeff Law @ 2016-11-09 15:51 UTC (permalink / raw)
  To: Helge Deller, Richard Henderson; +Cc: linux-parisc, GNU C Library

On 11/09/2016 07:51 AM, Helge Deller wrote:
> Hi Richard,
>
>> 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
>
> COOL!
> I'm happy to test, but can you shortly describe the required steps how I can build & test it?
>
> With "user-only target of hppa" I assume this means that I can run hppa binaries
> on e.g. x86-64, similiar to what is described here: https://wiki.debian.org/QemuUserEmulation ?
>
>> 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.
>
> Interesting.
> I assume nobody did, because there are a few hppa/linux/glibc users anyway ? :-)
Probably a safe assumption.  I'm pretty sure the hpux string routines 
used uxor.  There was also at least one hpux routine in libc which used 
the branch-in-delay-slot-of-branch trick, but I can't recall why it was 
useful.

jeff

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

* Re: Aw: hppa qemu and string functions
  2016-11-09 14:51 ` Aw: " Helge Deller
  2016-11-09 15:51   ` Jeff Law
@ 2016-11-10  9:39   ` Richard Henderson
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2016-11-10  9:39 UTC (permalink / raw)
  To: Helge Deller; +Cc: linux-parisc, GNU C Library

On 11/09/2016 03:51 PM, Helge Deller wrote:
> Hi Richard,
>
>> 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
>
> COOL!
> I'm happy to test, but can you shortly describe the required steps how I can build & test it?

Check out the indicated branch, configure --target-list=hppa-linux-user, make, 
install.  qemu-hppa will be the user-mode emulator.

>
> With "user-only target of hppa" I assume this means that I can run hppa binaries
> on e.g. x86-64, similiar to what is described here: https://wiki.debian.org/QemuUserEmulation ?

Yes, exactly.


r~

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

end of thread, other threads:[~2016-11-10  9:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-09 12:53 hppa qemu and string functions Richard Henderson
2016-11-09 14:51 ` Aw: " Helge Deller
2016-11-09 15:51   ` Jeff Law
2016-11-10  9:39   ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).