public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: linux-parisc@vger.kernel.org
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: hppa qemu and string functions
Date: Wed, 09 Nov 2016 12:53:00 -0000	[thread overview]
Message-ID: <21645bc2-f005-5e60-d26a-41af60e3c035@twiddle.net> (raw)

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

             reply	other threads:[~2016-11-09 12:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-09 12:53 Richard Henderson [this message]
2016-11-09 14:51 ` Aw: " Helge Deller
2016-11-09 15:51   ` Jeff Law
2016-11-10  9:39   ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21645bc2-f005-5e60-d26a-41af60e3c035@twiddle.net \
    --to=rth@twiddle.net \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-parisc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).