9front - general discussion about 9front
 help / color / mirror / Atom feed
From: cinap_lenrek@felloff.net
To: 9front@9front.org
Subject: Re: arm64 fails to link when float converted to int (Was Re: [9front] netsurf native frontend (text_insert: illegal combination FCVTZSDW FCON NONE REG))
Date: Sat, 1 Aug 2020 13:43:06 +0200	[thread overview]
Message-ID: <8BFCD64ADCEA9E2631D9323B893FF9A2@felloff.net> (raw)
In-Reply-To: <AB617CEA-B63A-4CAC-A5C0-E4C0D2F05F18@cpan.org>

this is clearly a compiler bug.

lets compare with the other compilers:

term% for(i in 5c 7c 8c){echo $i; $i -o/dev/null -S a.c}
5c
	TEXT	main+0(SB),0,$8
	MOVW	$1,R1
	MOVD	$1.50000000000000000e+00,F0
	MOVWD	R1,F1 <- convert lhs to float
	MULD	F0,F1 <- do floatingpoint multiplication
	MOVDW	F1,R3 <- convert result back to integer
	MOVW	$0,R0
	BL	,exits+0(SB)
	RET	,
	END	,
7c
	TEXT	main+0(SB),0,$16
	MOVW	$1,R1
	FCVTZSDW	$1.50000000000000000e+00,R2	<- tries to convert rhs to int??
	MULW	R2,R1,R2 <- multiplication done in int? bug!
	MOV	$0,R0
	BL	,exits+0(SB)
	RETURN	,
	END	,
8c
	TEXT	main+0(SB),0,$20
	MOVL	$1,size+-4(SP)
	FMOVD	$(1.50000000000000000e+00),F0
	FMOVL	size+-4(SP),F0 <- convert lhs to float
	FMULDP	F0,F1 <- do floatingpoint multiplication

	FSTCW	,.safe+-16(SP)
	MOVW	$3967,.safe+-14(SP)
	FLDCW	.safe+-14(SP), <- hahahaha, thanks intel!
	FMOVLP	F0,.safe+-12(SP)
	FLDCW	.safe+-16(SP),
	MOVL	.safe+-12(SP),AX <- convert result back to integer

	MOVL	$0,(SP)
	CALL	,exits+0(SB)
	RET	,
	END	,

we have to do the operation using the type of the right hand side:

diff -r f8f63e944375 sys/src/cmd/7c/cgen.c
--- a/sys/src/cmd/7c/cgen.c	Fri Jul 17 16:53:20 2020 +0200
+++ b/sys/src/cmd/7c/cgen.c	Sat Aug 01 13:33:09 2020 +0200
@@ -287,10 +287,10 @@
 				reglcgen(&nod2, l, Z);
 			else
 				nod2 = *l;
-			regalloc(&nod, n, nn);
+			regalloc(&nod, r, nn);
 			cgen(r, &nod);
 		} else {
-			regalloc(&nod, n, nn);
+			regalloc(&nod, r, nn);
 			cgen(r, &nod);
 			if(l->addable < INDEXED)
 				reglcgen(&nod2, l, Z);

with that change, 7c properly does the multiplication in floating
point, and converts the result back to integer:

term% /sys/src/cmd/7c/6.out -o/dev/null -S a.c
	TEXT	main+0(SB),0,$16
	MOVW	$1,R1
	FMOVD	$1.50000000000000000e+00,F1
	SCVTFWD	R1,F4 <- convert left hand side to float
	FMULD	F1,F4,F1 <- do floatingpoint multiplication
	FCVTZSDW	F1,R1 <- convert result back to integer
	MOV	$0,R0
	BL	,exits+0(SB)
	RETURN	,
	END	,

we'll need to to do a bunch of test now to make sure this
change doesnt break anything.

feel free to test and report any errors would be appreciated.

--
cinap


  reply	other threads:[~2020-08-01 11:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21 15:54 netsurf native frontend telephil9
2020-05-21 16:06 ` [9front] " hiro
2020-05-21 17:59 ` Romano
2020-07-28  7:11   ` [9front] netsurf native frontend (text_insert: illegal combination FCVTZSDW FCON NONE REG) Romano
2020-07-29  6:08     ` arm64 fails to link when float converted to int (Was Re: [9front] netsurf native frontend (text_insert: illegal combination FCVTZSDW FCON NONE REG)) Romano
2020-08-01 11:43       ` cinap_lenrek [this message]
2020-08-01 12:23         ` Anthony Martin
2020-05-21 21:16 ` [9front] netsurf native frontend Dave MacFarlane
2020-05-23 11:03   ` telephil9
2020-05-23 15:42     ` Stanley Lieber
2020-05-23 16:13     ` Stanley Lieber
2020-05-23  4:08 ` kokamoto
2020-05-23  6:13   ` Eli Cohen
2020-05-23  6:18     ` telephil9
2020-05-23  6:37       ` Eli Cohen
2020-05-23 20:10   ` jamos
2020-05-24  0:02     ` kokamoto
2020-05-25  3:51       ` kokamoto
2020-05-24  2:13 ` sl
2020-08-01 18:41 arm64 fails to link when float converted to int (Was Re: [9front] netsurf native frontend (text_insert: illegal combination FCVTZSDW FCON NONE REG)) Romano

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=8BFCD64ADCEA9E2631D9323B893FF9A2@felloff.net \
    --to=cinap_lenrek@felloff.net \
    --cc=9front@9front.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 NNTP newsgroup(s).