[SOLVED] micropython.native in frozen bytecode

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

[SOLVED] micropython.native in frozen bytecode

Post by kevinkk525 » Sat Sep 22, 2018 8:31 am

Is it possible to use the micropython.native emitter in frozen bytecode?

I tried to use it but when compiling the esp8266 firmware I get an error that the emitter is not supported.
Last edited by kevinkk525 on Tue Sep 25, 2018 2:06 pm, edited 2 times in total.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: micropython.native in frozen bytecode

Post by jickster » Sat Sep 22, 2018 12:22 pm

kevinkk525 wrote:Is it possible to use the micropython.native empitter in frozen bytecode?

I tried to use it but when compiling the esp8266 firmware I get an error that the emitter is not supported.
I also tried a few months back and same result.
I don’t think it’s supported.


Sent from my iPhone using Tapatalk Pro

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: micropython.native in frozen bytecode

Post by pythoncoder » Sun Sep 23, 2018 7:31 am

The clue is in the name: it's MicroPython bytecode which is frozen. The way I believe it works is that, on the PC, the MicroPython source is cross-compiled to bytecode. The bytecode for all frozen modules is then converted to data tables in C source (frozen_mpy.c) which is then compiled into the build. This process precludes native code emitters and inline assembler.

The frozen_mpy.c file (in the build directory for your port) is worth a look if you're interested.
Peter Hinch
Index to my micropython libraries.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: micropython.native in frozen bytecode

Post by kevinkk525 » Sun Sep 23, 2018 7:38 am

ok so if I use frozen modules, I can't benefit from the native emitter because only the internal compiler of micropython can do that?
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: micropython.native in frozen bytecode

Post by pythoncoder » Sun Sep 23, 2018 7:51 am

The way I deal with this is to partition the application into modules which can be frozen with a few, usually small, modules which can't. As you probably know, optimisation is best directed at the usually small number of functions which are performance critical.
Peter Hinch
Index to my micropython libraries.

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: micropython.native in frozen bytecode

Post by jickster » Sun Sep 23, 2018 2:40 pm

kevinkk525 wrote:ok so if I use frozen modules, I can't benefit from the native emitter because only the internal compiler of micropython can do that?
This isn’t a permanent restriction: if different emitters can run in C on the target there’s nothing stopping same code from running on PC.

It just hasn’t been implemented.


Sent from my iPhone using Tapatalk Pro

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

micropython.native in frozen bytecode

Post by jickster » Sun Sep 23, 2018 2:43 pm

pythoncoder wrote:This process precludes native code emitters and inline assembler.
.
If C code on the target can use native emitters there’s no reason why same C code can run on PC.

It simply hasn’t been implemented.


Sent from my iPhone using Tapatalk Pro

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: micropython.native in frozen bytecode

Post by pythoncoder » Mon Sep 24, 2018 5:02 am

As I see it the limitation is in the cross-compiler which produces only bytecode. A modification to enable it to produce a mixture of bytecode and (correctly linked) native code would, I suspect, be nontrivial. It would also mean that the cross-compiler would need target-specific options (bytecode is generic). The build process would then need to convert the bytecode to C data. I'm not sure how it would handle and correctly link bunches of machine code. Perhaps the CC would need to emit assembler source, which could be assembled and linked?

All this is way above my pay grade ;)

In practical applications I think there is little need: optimisation is best targeted at small amounts of code. The frozen bytecode option works well for the large modules. I've written some fairly hefty applications for the Pyboard and never found this to be a practical problem.
Peter Hinch
Index to my micropython libraries.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: micropython.native in frozen bytecode

Post by kevinkk525 » Mon Sep 24, 2018 7:29 am

Hmm sounds rather complicated. Doubt that anyone would want to put that effort into the cross-compiler just to get some more performance.
Thanks for you answers!
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply