Adafruit Industries artwork

Deep Dive w/Scott: Guest

Adafruit Industries

English - July 16, 2021 00:00 - 2 hours - 248 MB Video - ★★★★★ - 10 ratings
Education Homepage Download Apple Podcasts Google Podcasts Overcast Castro Pocket Casts RSS feed


Join Scott and guest @jim_mussared (@jimmo on GitHub) as they talk about MicroPython and debugging the native emitter.

Scott is sponsored by Adafruit to work on CircuitPython. Support them, and by extension Scott, by purchasing hardware from https://adafruit.com

Jim is sponsored by George Robotics to work on MicroPython. Sponsor them on GitHub: https://github.com/sponsors/micropython See https://github.com/micropython/micropython and http://micropython.org/ for more information about MicroPython.

Chat with Scott, Jim and lot of others on the Adafruit Discord at https://adafru.it/discord.

Deep Dive happens every week. Normally Fridays at 2pm Pacific but occasionally shifted to Thursday at 2pm. Typically goes for two hours or more. Questions are welcome. Next week should be on Friday.

Links:
* https://github.com/jimmo
* https://github.com/micropython/micropython/issues/7523
* https://devblogs.microsoft.com/oldnewthing/20210531-00/?p=105265
* https://github.com/sponsors/micropython
* https://store.micropython.org/

Thanks to @dcd for timecodes.

0:00 Getting started after technical issues

0:03:43 Welcome Jim @jim_mussared
0:07:44 Black box with blinky lights on the wall
0:08:50 http://megaprocessor.com/
0:12:00 - black screen - ( obs transition / rearrange screen)
0:15:16 Jim’s desktop
0:17:00 @micropython.native decorator - compile to native thumb code in RAM
0:20:00 freezing code moves it to flash
0:21:55 import mic0ropython discussion - to catch code not portable to cpython
0:23:00 const variables, and _ prefixed variables
0:25:23 thumb code ( ARM and thumb ( native cortex machine code ) )
0:26:55 ISA - (RISC-V api )
0:30:20 instruction lookahead - deep pipelining
0:31:15 Spectre / speculative look ahead / security issues
0:32:25 Jim’s secret agenda for the deep dive - native emitter for RISC-V (esp32)
0:34:20 CP needs BLE if not native USB
0:35:35 micropython.native code incorrect execution
0:36:10 mpr - micropython remote “mpr run”
0:36:50 mpr mount - access to remote REPL
0:37:40 CP-like workflow over serial (esp32)
0:38:35 @micropython.viper - optimization by skipping the python object overhead
0:40:10 MP type hints - normally ignored
0:40:45 type hints as IDE help
0:41:20 If you have repeating numbers like your 255s and 0s, is it a bad idea to make them consts? Are they already treated like consts internally?
0:43:44 disassemble (alias blaze = ‘make -j 16’ / on linux port )
0:47:00 microcpython -v -v -v to disassemble to micropython VM bytecode - walk through the byte code
0:51:15 - 3 stacks to discuss later
0:53:30 mp binary op internals
0:55:40 what is an emitter - lexical analysis , parse into tree, emit code from parse tree ( byte code, emit native code, or emit viper code )
0:57:50 byte code emitter emitbc.c
0:58:59 compile.c calls emitter, or emitnative.c
1:01:30 Is .native and .viper just at a method level? Class level too?
1:02:50 native ‘everything’ by saving the python to a code
1:08:00 continue in emit native
1:10:10 what if we use a local variable?
1:11:34 gdb ./micropython ( oops - rebuild first )
1:13:35 mp_obj_t ( the most useful point of this deep dive )
1:15:20 type tagging ( see mpconfig.h )
1:16:45 some builds of CP don’t support long integers
1:18:35 . is there anything else than micropython that emit micropython bytecode? Like at one point everyone was making JVM bytecode even not being java
1:20:05 everything is a 32 bit integer - ( or a pointer to an object )
1:21:10 Why (3) is really 1 and 0x1ff
1:22:25 gdb backtrace doesn’t work with native emitter
1:23:10 anybody doing "hand written" bytecode to do something smart or super optimised?
1:25:00 Write part of the core in the python
1:27:55 looking at the native code generated in a file
1:29:49 Is there a byte code to python "decompiler"?
1:30:30 debug the debugging code
1:32:03 objdump to disassemble the generated code (x86-64 code)
1:34:50 rbp is pointer to func table - ( there is no linker)
1:41:03 viper generation
1:45:40 emit_native_jump_helper
1:47:08 3 different stacks ( processor, MP function stack, emitter stack (while emitting )
1:49:00 optimization
1:51:50 - another optimization - keep variables in registers
1:53:50 - clobber EAX
1:55:40 RISC-V ISA/calling conventions ( ABI - binary interface )
1:57:30 one character fix ( use EDI instead of EAX )
1:58:52 Write a test to verify the fix
1:59:45 fixed on thumb code
2:00:00 MP issue https://github.com/micropython/micropython/issues/7523
Thanks to Jim and https://store.micropython.org/
2:08:00 wrap up!
2:08:30 - final frame :-)

-----------------------------------------
LIVE CHAT IS HERE! http://adafru.it/discord

Adafruit on Instagram: https://www.instagram.com/adafruit

Subscribe to Adafruit on YouTube: http://adafru.it/subscribe

New tutorials on the Adafruit Learning System: http://learn.adafruit.com/
-----------------------------------------