9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Romano <unobe@cpan.org>
To: 9front@9front.org,telephil9@gmail.com
Subject: arm64 fails to link when float converted to int (Was Re: [9front] netsurf native frontend (text_insert: illegal combination FCVTZSDW FCON NONE REG))
Date: Wed, 29 Jul 2020 06:08:53 +0000	[thread overview]
Message-ID: <AB617CEA-B63A-4CAC-A5C0-E4C0D2F05F18@cpan.org> (raw)
In-Reply-To: <1B1B16C8-C577-4155-A61D-292785CED256@cpan.org>

TLDR; netsurf/frontends/plan9/drawui/entry.c:162 multiplies d->entry by 1.5. Changing the factor to 2 (an int) resolves. Here's a test .c file that reproduces the problem:
cpu% cat arm64-int-test.c
#include <u.h>
#include <libc.h>

void
main()
{
    int size = 1;
	size*=1.5;
    exits(0);
}
cpu% 7c arm64-int-test.c
cpu% 7l arm64-int-test.7
main: illegal combination FCVTZSDW FCON NONE REG
(833)	FCVTZSDW	$1.500000e+00,R2
main: illegal combination FCVTZSDW FCON NONE REG
(833)	FCVTZSDW	$1.500000e+00,R2
cpu%

Narrative:

So I tried poking around a bit more: googling initially didn't appear all that helpful. It appears the logic is the same as Go's compiler, which refers to 7l from Plan9 (copyrights dating back to the '90s). I ran acid to show the stack trace and the registers. I don't know how to determine which archived library code this machine code is being generated for, or if that's even the place to look for this type of error. 

cpu% acid /bin/7l
/bin/7l:arm64 plan 9 executable
/sys/lib/acid/port
/sys/lib/acid/arm64
acid: progargs = "-o 7.netsurf utils/bloom.7 utils/corestrings.7 utils/file.7 utils/filename.7 utils/filepath.7 utils/hashmap.7 utils/hashtable.7 utils/http/cache-control.7 utils/http/challenge.7 utils/http/content-disposition.7 utils/http/content-type.7 utils/http/generics.7 utils/http/parameter.7 utils/http/primitives.7 utils/http/strict-transport-security.7 utils/http/www-authenticate.7 utils/idna.7 utils/libdom.7 utils/log.7 utils/messages.7 utils/nsoption.7 utils/nsurl/nsurl.7 utils/nsurl/parse.7 utils/punycode.7 utils/ssl_certs.7 utils/talloc.7 utils/time.7 utils/url.7 utils/useragent.7 utils/utf8.7 utils/utils.7 content/content.7 content/content_factory.7 content/dirlist.7 content/fetch.7 content/fetchers/about.7 content/fetchers/data.7 content/fetchers/file.7 content/fetchers/resource.7 content/fs_backing_store.7 content/handlers/css/css.7 content/handlers/css/dump.7 content/handlers/css/hints.7 content/handlers/css/internal.7 content/handlers/css/select.7 content/handlers/css/utils.7 content/handlers/html/box.7 content/handlers/html/box_construct.7 content/handlers/html/box_normalise.7 content/handlers/html/box_textarea.7 content/handlers/html/font.7 content/handlers/html/form.7 content/handlers/html/html.7 content/handlers/html/html_css.7 content/handlers/html/html_css_fetcher.7 content/handlers/html/html_forms.7 content/handlers/html/html_object.7 content/handlers/html/html_redraw.7 content/handlers/html/html_redraw_border.7 content/handlers/html/html_script.7 content/handlers/html/imagemap.7 content/handlers/html/interaction.7 content/handlers/html/layout.7 content/handlers/html/search.7 content/handlers/html/table.7 content/handlers/image/bmp.7 content/handlers/image/gif.7 content/handlers/image/ico.7 content/handlers/image/image.7 content/handlers/image/image_cache.7 content/handlers/javascript/content.7 content/handlers/javascript/duktape/dukky.7 content/handlers/javascript/duktape/duktape.7 content/handlers/javascript/fetcher.7 content/handlers/text/textplain.7 content/hlcache.7 content/llcache.7 content/mimesniff.7 content/no_backing_store.7 content/urldb.7 content/webfs.7 desktop/browser.7 desktop/browser_history.7 desktop/browser_window.7 desktop/cookie_manager.7 desktop/cw_helper.7 desktop/download.7 desktop/font_haru.7 desktop/frames.7 desktop/global_history.7 desktop/gui_factory.7 desktop/hotlist.7 desktop/knockout.7 desktop/local_history.7 desktop/mouse.7 desktop/netsurf.7 desktop/page-info.7 desktop/plot_style.7 desktop/print.7 desktop/save_pdf.7 desktop/save_text.7 desktop/scrollbar.7 desktop/search.7 desktop/searchweb.7 desktop/selection.7 desktop/sslcert_viewer.7 desktop/system_colour.7 desktop/textarea.7 desktop/textinput.7 desktop/treeview.7 desktop/version.7 frontends/plan9/plotter.7 frontends/plan9/schedule.7 frontends/plan9/window.7 frontends/plan9/fetch.7 frontends/plan9/bitmap.7 frontends/plan9/layout.7 frontends/plan9/clipboard.7 frontends/plan9/utils.7 frontends/plan9/gui.7 frontends/plan9/drawui/data.7 frontends/plan9/drawui/window.7 frontends/plan9/drawui/button.7 frontends/plan9/drawui/entry.7 frontends/plan9/drawui/toolbar.7 frontends/plan9/drawui/scrollbar.7 ../posix/src/iconv.7 ../posix/src/preadwrite.7 ../posix/src/math9.7 content/handlers/javascript/duktape/libduktape.7.a ../libnspsl/src/libnspsl.7.a ../libdom/src/libdom.7.a ../libcss/src/libcss.7.a ../libhubbub/src/libhubbub.7.a ../libparserutils/src/libparserutils.7.a ../libwapcaplet/src/libwapcaplet.7.a ../libnsutils/src/libnsutils.7.a ../libnslog/src/libnslog.7.a ../libnsbmp/src/libnsbmp.7.a ../libnsgif/src/libnsgif.7.a ../libutf8proc/src/libutf8proc.7.a /arm64/lib/ape/libap.a"
acid: new()
144283: ???	_main	MOV	R30,-160(SP)!
144283: ???	main+0x4	MOVWU	R0,104(SP)
Notes pending:
	sys: trap: BRK instruction
acid: filepc("/sys/src/cmd/7l/span.c:749")
<stdin>:4: (error) no function pcwhere
acid: filepc("/sys/src/cmd/7l/span.c:749")
acid: ma = filepc("/sys/src/cmd/7l/span.c:751")
acid: print(ma)
123496
acid: setbp(123496)
<stdin>:10: (error) no function setbp
acid: bpset(123496)
acid: cont()
text_insert: illegal combination FCVTZSDW FCON NONE REG
144283: ???	oplook+0x248	BL	prasm(SB)
Notes pending:
	sys: trap: BRK instruction
acid: lstk()
oplook(p=0x52ea258)+0x248 /sys/src/cmd/7l/span.c:751
	a1=0x1935000000012
	a3=0x1b0c969000000001
	e=0x32b70
	o=0x0
span()+0x7c /sys/src/cmd/7l/span.c:37
	bflag=0x400000000
	otxt=0x163bec00163bd0
	c=0x163bec
	p=0x52ea258
	m=0x7000000004
main(argc=0x8e,argv=0x1fffef180)+0x494 /sys/src/cmd/7l/obj.c:240
	_argc=0x6f
	_args=0x1fffef193
_main+0x28 /sys/src/libc/arm64/main9.s:17
acid: regs()
R0	0x00000000052ea258 R1	0x00000001fffee810 R2	0x0000000000028bf4
R3	0x0000000020000000 R4	0x0000000000000001 R5	0x000000000002339b
R6	0x0000000000000120 R7	0x0000000000000000 R8	0x000000004a200000
R9	0x0000000000000000 R10	0x00000001fffeea30 R11	0x0000000000000000
R12	0x0000000000000038 R13	0x0000000000000038 R14	0x0000000000000038
R15	0x0000000000000038 R16	0x97a3d7a220310c00 R17	0xffffffffc00f9f0c
R18	0x0875b486156a038a R19	0xabbd7f2d00000600 R20	0xbdfb65a508018891
R21	0xfb8eef8303a1c056 R22	0x7701204088940008 R23	0x30bd38232a00814d
R24	0x0ba2cb7a34057080 R25	0xf6faa6d3e3bed2fb R26	0xffffffffc08e20a8
R27	0xffffffffc007e000 R28	0x0000000000030000 R29	0xffffffffc0088958
R30	0x000000000001e264
acid: step()
(1705)	FCVTZSDW	$1.500000e+00,R5
text_insert: illegal combination FCVTZSDW FCON NONE REG
(1705)	FCVTZSDW	$1.500000e+00,R5
<stdin>:21: (error) msg: pid=144283 startstop: process exited
acid:

From a couple of the Go sources, it's clear that FCVTZSDW is converting 64float to 32int[1][2],so for me it's understandable that 1.5 can't be converted to an integer. The connection of 1.5e0 to 1.5 didn't dawn on me immediately, however. I ended up watching a youtube on ARM development, then reading ARM developer docs and a blog post about ARM development[3]: they all didn't seem to help me understand how to figure out the location of the problem. So after a bit of contemplation, I figured searching for 1.5 in the netsurf source might yield something. Since 7.nsfb builds fine, I wasn't quite sure it would help much, but what had I to lose, except more time?

cpu%  walk . | grep '\.c$' | xargs grep '[^0-9]1\.5'
./content/handlers/css/select.c:		FLTTOFIX(1.5000), /* x-large */
./content/handlers/html/layout.c:				size = FLTTOFIX(1.5);
./content/handlers/javascript/duktape/duktape.c:			 * (e.g. '1.5e+2').  This clause catches NULs.
./content/handlers/javascript/duktape/duktape.c:	 *  -1.5 -> floor(-1.0) -> -1  (towards +Inf)
./content/handlers/javascript/duktape/duktape.c:	 *  +1.5 -> floor(+2.0) -> 2   (towards +Inf)
./content/handlers/javascript/duktape/duktape.c:	 * Lua 5.1.5, and different hash initializer.
./content/handlers/javascript/duktape/duktape.c:	/* Number/string -> coerce string to number (e.g. "'1.5' == 1.5" -> true). */
./content/handlers/javascript/duktape/duktape.c: *    10.2.1.1.5 DeleteBinding (N)  [declarative environment record]
./content/handlers/javascript/duktape/duktape.c:	 * the double is out-of-range.  C99 Section 6.3.1.5:
./frontends/riscos/window.c:				1.5, 2.0, 3.0, 4.0, 6.0, 8.0, 12.0, 16.0};
./frontends/plan9/drawui/entry.c:		entry->size *= 1.5;

Huh, 1.5 in plan9 drawui. Change that to 2, and the linking was successful!  I'm happy that netsurf now builds on arm64, but this raises a question of why this doesn't cause a problem for i386 (the other arch I built netsurf on back in May). I reviewed the dentry struct in entry.h in the same directory and see that entry is of type int, so maybe on other architectures it's just rounded? For instance, on p. 42 in The C Programming Language, Section 2.7 contains this section: "Expressions that might lose information , like assigning a longer integer type to a shorter, or a floating-point type to an integer, may draw a warning, but they are not illegal." The arm64 compiler could emit the warning but still apply the operation (maybe it would be something like converting the int to a float, then multiplying, then rounding to get an int again).  At any rate, the test script above can be used as a test for anyone looking to reproduce the problem, and if desired, provide a solution.

[1] https://www.golang.ir/src/cmd/compile/internal/ssa/opGen.go
[2] https://www.golang.ir/src/cmd/compile/internal/ssa/rewriteARM64.go
[3] https://modexp.wordpress.com/2018/10/30/arm64-assembly/

On Tue, Jul 28, 2020, at 12:11 AM, Romano wrote:
> Philippe,
> 
> I attempted to build on a rpi4 using the arm64 kernel ( I ran a 
> sysupdate on Saturday). The framebuffer executable builds fine, but at 
> the very last step of building the native front-end I'm getting an 
> error:
> 
> pcc -o 7.netsurf utils/bloom.7 utils/corestrings.7 utils/file.7 
> utils/filename.7 utils/filepath.7 utils/hashmap.7 utils/hashtable.7 
> utils/http/cache-control.7 utils/http/challenge.7 
> utils/http/content-disposition.7 utils/http/content-type.7 
> utils/http/generics.7 utils/http/parameter.7 utils/http/primitives.7 
> utils/http/strict-transport-security.7 utils/http/www-authenticate.7 
> utils/idna.7 utils/libdom.7 utils/log.7 utils/messages.7 
> utils/nsoption.7 utils/nsurl/nsurl.7 utils/nsurl/parse.7 
> utils/punycode.7 utils/ssl_certs.7 utils/talloc.7 utils/time.7 
> utils/url.7 utils/useragent.7 utils/utf8.7 utils/utils.7 
> content/content.7 content/content_factory.7 content/dirlist.7 
> content/fetch.7 content/fetchers/about.7 content/fetchers/data.7 
> content/fetchers/file.7 content/fetchers/resource.7 
> content/fs_backing_store.7 content/handlers/css/css.7 
> content/handlers/css/dump.7 content/handlers/css/hints.7 
> content/handlers/css/internal.7 content/handlers/css/select.7 
> content/handlers/css/utils.7 content/handlers/html/box.7 
> content/handlers/html/box_construct.7 
> content/handlers/html/box_normalise.7 
> content/handlers/html/box_textarea.7 content/handlers/html/font.7 
> content/handlers/html/form.7 content/handlers/html/html.7 
> content/handlers/html/html_css.7 
> content/handlers/html/html_css_fetcher.7 
> content/handlers/html/html_forms.7 content/handlers/html/html_object.7 
> content/handlers/html/html_redraw.7 
> content/handlers/html/html_redraw_border.7 
> content/handlers/html/html_script.7 content/handlers/html/imagemap.7 
> content/handlers/html/interaction.7 content/handlers/html/layout.7 
> content/handlers/html/search.7 content/handlers/html/table.7 
> content/handlers/image/bmp.7 content/handlers/image/gif.7 
> content/handlers/image/ico.7 content/handlers/image/image.7 
> content/handlers/image/image_cache.7 
> content/handlers/javascript/content.7 
> content/handlers/javascript/duktape/dukky.7 
> content/handlers/javascript/duktape/duktape.7 
> content/handlers/javascript/fetcher.7 content/handlers/text/textplain.7 
> content/hlcache.7 content/llcache.7 content/mimesniff.7 
> content/no_backing_store.7 content/urldb.7 content/webfs.7 
> desktop/browser.7 desktop/browser_history.7 desktop/browser_window.7 
> desktop/cookie_manager.7 desktop/cw_helper.7 desktop/download.7 
> desktop/font_haru.7 desktop/frames.7 desktop/global_history.7 
> desktop/gui_factory.7 desktop/hotlist.7 desktop/knockout.7 
> desktop/local_history.7 desktop/mouse.7 desktop/netsurf.7 
> desktop/page-info.7 desktop/plot_style.7 desktop/print.7 
> desktop/save_pdf.7 desktop/save_text.7 desktop/scrollbar.7 
> desktop/search.7 desktop/searchweb.7 desktop/selection.7 
> desktop/sslcert_viewer.7 desktop/system_colour.7 desktop/textarea.7 
> desktop/textinput.7 desktop/treeview.7 desktop/version.7 
> frontends/plan9/plotter.7 frontends/plan9/schedule.7 
> frontends/plan9/window.7 frontends/plan9/fetch.7 
> frontends/plan9/bitmap.7 frontends/plan9/layout.7 
> frontends/plan9/clipboard.7 frontends/plan9/utils.7 
> frontends/plan9/gui.7 frontends/plan9/drawui/data.7 
> frontends/plan9/drawui/window.7 frontends/plan9/drawui/button.7 
> frontends/plan9/drawui/entry.7 frontends/plan9/drawui/toolbar.7 
> frontends/plan9/drawui/scrollbar.7 ../posix/src/iconv.7 
> ../posix/src/preadwrite.7 ../posix/src/math9.7 
> content/handlers/javascript/duktape/libduktape.7.a 
> ../libnspsl/src/libnspsl.7.a ../libdom/src/libdom.7.a 
> ../libcss/src/libcss.7.a ../libhubbub/src/libhubbub.7.a 
> ../libparserutils/src/libparserutils.7.a 
> ../libwapcaplet/src/libwapcaplet.7.a ../libnsutils/src/libnsutils.7.a 
> ../libnslog/src/libnslog.7.a ../libnsbmp/src/libnsbmp.7.a 
> ../libnsgif/src/libnsgif.7.a ../libutf8proc/src/libutf8proc.7.a
> text_insert: illegal combination FCVTZSDW FCON NONE REG
> (1705)	FCVTZSDW	$1.500000e+00,R5
> text_insert: illegal combination FCVTZSDW FCON NONE REG
> (1705)	FCVTZSDW	$1.500000e+00,R5
> pcc: 7l: 7l 101895: error
> mk: pcc -o 7.netsurf ...  : exit status=rc 101892: pcc 101894: 7l: 7l 
> 101895: error
> 
> Any ideas? Is this is a problem with the 7l linker specifically not 
> knowing how to translate an instruction to arm64 assembly? Do you need 
> more information?
> 
> On Thu, May 21, 2020, at 10:59 AM, Romano wrote:
> > Very cool, Philippe!
> > 
> > I'm testing a build now on 386.
> > 
> > Maybe it was mentioned previously and I didn't see it, but it looks 
> > like nsport is what someone needs to clone first: 
> > http://github.com/netsurf-plan9/nsport . Then cd into that dir and run 
> > 'fetch clone git', 'fetch clone ssh' or 'fetch clone http' (the 
> > instructions in README.plan9 say a simple 'fetch clone' without args 
> > would work, but it didn't work for me).
> > 
> > Note also that git9 changed the flag for creating a new branch: you 
> > might have to update the fetch script to use -n instead of -c.
> > 
> > I'll let you know how the build goes, and if I run in to any other gotchas.
> > 
> > 
> > 
> > On May 21, 2020 3:54:03 PM UTC, telephil9@gmail.com wrote:
> > >Hi,
> > >
> > >I've just committed the initial release for the netsurf native
> > >frontend.
> > >Feature-wise it is almost on par with the framebuffer frontend except
> > >for images that are not handled yet.
> > >I tried to make it look and behave like a native application but would
> > >like to have some feedback on this.
> > >
> > >All code is in the main repository: http://github.com/netsurf-plan9
> > >
> > >In order not to mess with the current framebuffer frontend, I created a
> > >separate mkfile found in netsurf/mkfile.native.
> > >To build this new frontend, just run mk as usual and then run mk -f
> > >mkfile.native in the netsurf directory.
> > >
> > >Regards,
> > >Philippe
> >


  reply	other threads:[~2020-07-29  6:08 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     ` Romano [this message]
2020-08-01 11:43       ` arm64 fails to link when float converted to int (Was Re: [9front] netsurf native frontend (text_insert: illegal combination FCVTZSDW FCON NONE REG)) cinap_lenrek
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=AB617CEA-B63A-4CAC-A5C0-E4C0D2F05F18@cpan.org \
    --to=unobe@cpan.org \
    --cc=9front@9front.org \
    --cc=telephil9@gmail.com \
    /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).