Skip to content

mips: add GOMIPS=softfloat support #4371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 12, 2024
Merged

mips: add GOMIPS=softfloat support #4371

merged 2 commits into from
Aug 12, 2024

Conversation

aykevl
Copy link
Member

@aykevl aykevl commented Jul 29, 2024

Previously, the compiler would default to hardfloat. This is not supported by some MIPS CPUs.

This took me much longer than it should have because of a quirk in the LLVM Mips backend: if the target-features string is not set (like during LTO), the Mips backend picks the first function in the module and uses that. Unfortunately, in the case of TinyGo this first function is llvm.dbg.value, which is an LLVM intrinsic and doesn't have the target-features string.
I fixed it by adding a -mllvm -mattr= flag to the linker.

@aykevl aykevl mentioned this pull request Jul 29, 2024
Copy link

github-actions bot commented Jul 29, 2024

Size difference with the dev branch:

Binary size difference
not the same command!
    tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/adafruit4650
    go: downloading tinygo.org/x/tinyfont v0.3.0
not the same command!
    tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/websocket/dial/
    go: downloading golang.org/x/net v0.7.0
not the same command!
    tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/mqttclient/natiu/
    go: downloading github.com/soypat/natiu-mqtt v0.5.1
not the same command!
    tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/mqttclient/paho/
    go: downloading github.com/eclipse/paho.mqtt.golang v1.2.0
 flash                          ram
 before   after   diff          before   after   diff
 332216  327824  -4392  -1.32%   15504   15564     60   0.39% tinygo build -size short -o ./build/test.hex -target=matrixportal-m4 -stack-size 8kb ./examples/net/webstatic/
  67512   66672   -840  -1.24%    6176    6176      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp2515/main.go
 291480  290808   -672  -0.23%   12508   12432    -76  -0.61% tinygo build -size short -o ./build/test.hex -target=pyportal -stack-size 8kb ./examples/net/http-get/
   8780    8192   -588  -6.70%    4748    4748      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/max72xx/main.go
 240256  239688   -568  -0.24%    9264    9200    -64  -0.69% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/websocket/dial/
  81960   81444   -516  -0.63%    6564    6588     24   0.37% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/lora/lorawan/atcmd/
 113892  113560   -332  -0.29%   12868   12868      0   0.00% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webclient/
 282700  282368   -332  -0.12%   16988   16924    -64  -0.38% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/mqttclient/paho/
 116788  116552   -236  -0.20%    7744    7744      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 -stack-size 8kb ./examples/net/tcpclient/
 281308  281112   -196  -0.07%   17928   18032    104   0.58% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webserver/
 152772  152588   -184  -0.12%    6428    6428      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/mqttclient/natiu/
   5656    5588    -68  -1.20%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/customchar/main.go
  15972   15940    -32  -0.20%    2344    2344      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hub75/main.go
  16736   16716    -20  -0.12%    4308    4308      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/adafruit4650
  12904   12892    -12  -0.09%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis2mdl/main.go
  88392   88380    -12  -0.01%    6076    6076      0   0.00% tinygo build -size short -o ./build/test.hex -target=challenger-rp2040 ./examples/net/ntpclient/
   9680    9672     -8  -0.08%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp3008/main.go
  10404   10396     -8  -0.08%    3312    3312      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/seesaw
   6476    6468     -8  -0.12%    2272    2272      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1306/i2c_128x32/main.go
  31752   31744     -8  -0.03%    4772    4772      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bme280/main.go
  16356   16348     -8  -0.05%    4716    4716      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/microphone/main.go
   8384    8376     -8  -0.10%    3744    3744      0   0.00% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/encoders/quadrature-interrupt
   8196    8192     -4  -0.05%    2304    2304      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/at24cx/main.go
  10412   10408     -4  -0.04%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/hd44780i2c/main.go
  11632   11628     -4  -0.03%    4772    4772      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis3dh/main.go
   9820    9816     -4  -0.04%    4764    4764      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017/main.go
  10256   10252     -4  -0.04%    4772    4772      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017-multiple/main.go
   8140    8136     -4  -0.05%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mma8653/main.go
   6004    6000     -4  -0.07%    2296    2296      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13x/main.go
  26320   26316     -4  -0.02%   16716   16716      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/waveshare-epd/epd2in66b/main.go
  12064   12060     -4  -0.03%    3288    3288      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/qmi8658c/main.go
   8916    8912     -4  -0.04%    3260    3260      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/xpt2046/main.go
  13572   13568     -4  -0.03%    4916    4916      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/sx126x/lora_rxtx/
  11784   11780     -4  -0.03%    3308    3308      0   0.00% tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/uc8151/main.go
  10296   10292     -4  -0.04%    3340    3340      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd4x/main.go
   9448    9444     -4  -0.04%    4748    4748      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ds18b20/main.go
  15728   15724     -4  -0.03%    4860    4860      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/as560x/main.go
   9776    9772     -4  -0.04%    3280    3280      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu6886/main.go
   7708    7704     -4  -0.05%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ttp229/main.go
   9204    9200     -4  -0.04%    3272    3272      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu9150/main.go
   9468    9468      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adxl345/main.go
  13424   13424      0   0.00%    6780    6780      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/amg88xx
   8580    8580      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/main.go
   9668    9668      0   0.00%    4752    4752      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/itsybitsy-m0/main.go
  12084   12084      0   0.00%    4804    4804      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bmp388/main.go
   4444    4444      0   0.00%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/easystepper/main.go
   7036    7036      0   0.00%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/gc9a01/main.go
   7772    7772      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/hcsr04/main.go
  14512   14512      0   0.00%    6556    6556      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/hts221/main.go
  10024   10024      0   0.00%    6900    6900      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/basic
  29400   29400      0   0.00%   38060   38060      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/pyportal_boing
  13856   13856      0   0.00%    6556    6556      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/lps22hb/main.go
  25956   25956      0   0.00%    2312    2312      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/lsm303agr/main.go
  12348   12348      0   0.00%    4780    4780      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/lsm6ds3/main.go
  12132   12132      0   0.00%    3336    3336      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/pca9685/main.go
   6052    6052      0   0.00%    3272    3272      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setbuffer/main.go
   5084    5084      0   0.00%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setpixel/main.go
   2825    2825      0   0.00%     558     558      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino ./examples/servo
  13644   13644      0   0.00%    3384    3384      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico     ./examples/sgp30
   7952    7952      0   0.00%    6780    6780      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/shifter/main.go
   5924    5924      0   0.00%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1306/spi_128x64/main.go
   5672    5672      0   0.00%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1331/main.go
   6600    6600      0   0.00%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7735/main.go
   6512    6512      0   0.00%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7789/main.go
  16868   16868      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/thermistor/main.go
   9968    9968      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/tm1637/main.go
   6376    6376      0   0.00%    2304    2304      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13/main.go
   6256    6256      0   0.00%    2304    2304      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd4in2/main.go
   6748    6748      0   0.00%    4772    4772      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/ws2812
   1581    1581      0   0.00%     598     598      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino   ./examples/ws2812
   1056    1056      0   0.00%     180     180      0   0.00% tinygo build -size short -o ./build/test.hex -target=digispark ./examples/ws2812
  10992   10992      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/buzzer/main.go
  12700   12700      0   0.00%    4772    4772      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/veml6070/main.go
   6664    6664      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/simple/main.go
   8576    8576      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/speed/main.go
   6632    6632      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/simple/main.go
   9184    9184      0   0.00%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/speed/main.go
   7284    7284      0   0.00%    3304    3304      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-f103rb ./examples/shiftregister/main.go
   9152    9152      0   0.00%    5236    5236      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-l432kc ./examples/aht20/main.go
  10168   10168      0   0.00%    6780    6780      0   0.00% tinygo build -size short -o ./build/test.elf -target=wioterminal ./examples/axp192/m5stack-core2-blinky/
   8452    8452      0   0.00%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=circuitplay-express ./examples/makeybutton/main.go
  11284   11284      0   0.00%    3308    3308      0   0.00% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/sh1106/macropad_spi
   5492    5494      2   0.04%    9502    9502      0   0.00% tinygo build -size short -o ./build/test.bin -target=m5stamp-c3          ./examples/ws2812
  11584   11588      4   0.03%    6556    6556      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/apds9960/proximity/main.go
   8152    8156      4   0.05%    3332    3332      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/sram/main.go
  10044   10048      4   0.04%    6908    6908      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/scroll
  10644   10648      4   0.04%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mag3110/main.go
   8048    8052      4   0.05%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mpu6050/main.go
  10296   10300      4   0.04%    4516    4516      0   0.00% tinygo build -size short -o ./build/test.hex -target=circuitplay-bluefruit ./examples/tone
   9400    9404      4   0.04%    6772    6772      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/fourwire/main.go
  14896   14900      4   0.03%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl53l1x/main.go
   6900    6904      4   0.06%    2252    2252      0   0.00% tinygo build -size short -o ./build/test.hex -target=hifive1b ./examples/ssd1351/main.go
   7176    7180      4   0.06%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/clkout/
   8656    8660      4   0.05%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina260/main.go
   7332    7340      8   0.11%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/blinkm/main.go
  64388   64396      8   0.01%    8996    8996      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/flash/console/qspi
   5608    5616      8   0.14%    2264    2264      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/text/main.go
  26372   26380      8   0.03%    3320    3320      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/microbitmatrix/main.go
  26188   26196      8   0.03%    5364    5364      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit-v2 ./examples/microbitmatrix/main.go
  13372   13380      8   0.06%    4740    4740      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl6180x/main.go
  61248   61256      8   0.01%    5928    5928      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/is31fl3731/main.go
  71416   71424      8   0.01%   10732   10732      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/sdcard/console/
  30464   30472      8   0.03%    4276    4276      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/ssd1289/main.go
  12468   12480     12   0.10%    6968    6968      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/pyportal_touchpaint/main.go
   8024    8040     16   0.20%    4732    4732      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bh1750/main.go
  27324   27340     16   0.06%    4772    4772      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp180/main.go
  22064   22080     16   0.07%    3528    3528      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/time/main.go
 262536  262552     16   0.01%   46736   46736      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/slideshow
  60372   60388     16   0.03%    8216    8216      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/i2csoft/adt7410/
  69420   69444     24   0.03%    3628    3628      0   0.00% tinygo build -size short -o ./build/test.hex -target=pinetime     ./examples/bma42x/main.go
  74780   74812     32   0.04%    7460    7460      0   0.00% tinygo build -size short -o ./build/test.hex -target=p1am-100 ./examples/p1am/main.go
 100960  100992     32   0.03%    9728    9728      0   0.00% tinygo build -size short -o ./build/test.hex -target=metro-m4-airlift -stack-size 8kb ./examples/net/socket/
  67964   68000     36   0.05%    6488    6488      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/uart/main.go
  36320   36356     36   0.10%    3972    3972      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8523/
  67436   67476     40   0.06%    6352    6352      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/i2c/main.go
  11140   11180     40   0.36%    4236    4236      0   0.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/irremote/main.go
  68324   68380     56   0.08%    6956    6956      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/flash/console/spi
  56264   56320     56   0.10%    3676    3676      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht4x/main.go
  56172   56228     56   0.10%    3668    3668      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/shtc3/main.go
  62852   62916     64   0.10%    6176    6176      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmi160/main.go
  56200   56264     64   0.11%    3668    3668      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht3x/main.go
  60248   60320     72   0.12%    6176    6176      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adt7410/main.go
  62848   62920     72   0.11%    6208    6208      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp280/main.go
  10544   10616     72   0.68%    4852    4852      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/basic
  69664   69736     72   0.10%    6320    6320      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/time/
  10632   10708     76   0.71%    4860    4860      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/scroll
  64648   64728     80   0.12%    4764    4764      0   0.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mcp9808/main.go
 108484  108564     80   0.07%    7516    7516      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino-mkrwifi1010 -stack-size 8kb ./examples/net/tlsclient/
  68604   68700     96   0.14%    6348    6348      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/main.go
  76176   76272     96   0.13%    6316    6316      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/dht/main.go
  70128   70224     96   0.14%    6316    6316      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/alarm/
  70088   70184     96   0.14%    6324    6324      0   0.00% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/timer/
  64148   64288    140   0.22%    6240    6248      8   0.13% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ndir/main_ndir.go
  65720   65864    144   0.22%    4796    4808     12   0.25% tinygo build -size short -o ./build/test.hex -target=pico ./examples/ndir/main_ndir.go
  61072   61224    152   0.25%    3764    3776     12   0.32% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ndir/main_ndir.go
5193862 5186832  -7030  -0.00%  780030  780046     16   0.00%

@aykevl aykevl marked this pull request as draft July 29, 2024 18:02
@aykevl
Copy link
Member Author

aykevl commented Jul 29, 2024

Actually I want to change the code a little bit, so converted to draft.

@aykevl aykevl marked this pull request as ready for review July 30, 2024 15:56
@aykevl aykevl marked this pull request as draft July 30, 2024 16:01
@aykevl aykevl marked this pull request as ready for review July 30, 2024 17:10
@aykevl
Copy link
Member Author

aykevl commented Jul 30, 2024

Ok, now it's ready (and hopefully it passes!). I've refactored the code a bit to avoid some unnecessary complications so that it is easier to add subarch support (GOARM, GOMIPS, GO386, etc).

@aykevl aykevl force-pushed the mips-softfloat branch 2 times, most recently from d8cbd0c to d4cf648 Compare July 30, 2024 17:41
@clabby
Copy link

clabby commented Jul 30, 2024

Trying this out at the moment (thank you for working on BE MIPS32 support!)

Noticing that the resulting MIPS32 BE binary includes some MIPS64 instructions, some from r6 (it looks like we're only enabling r2 in the features you pass to LLVM, so unsure why they're landing in there).

Host OS: MacOS Sonoma 14.5
TinyGo Rev: d8cbd0ccd5074b519376e481bcc00a7a3e9d38a4
LLVM version: 18.1.8
Build command: GOOS=linux GOARCH=mips GOMIPS=softfloat tinygo build -o hello.elf -scheduler=none -gc=leaking
Example binary:

package main

import (
	"os"
	"strconv"
)

func main() {
	a := [][]byte{}
	for i := 0; i < 1000; i++ {
		b := doWork(byte(i % 256))
		a = append(a, b)
	}

	b := len(a)
	_, _ = os.Stdout.Write([]byte("done with work, len(b) = " + strconv.Itoa(b) + "\n"))
}

func doWork(x byte) []byte {
	b := make([]byte, 4096)
	for i := 0; i < len(b); i++ {
		b[i] = x
	}
	return b
}

@aykevl
Copy link
Member Author

aykevl commented Jul 30, 2024

Noticing that the resulting MIPS32 BE binary includes some MIPS64 instructions, some from r6 (it looks like we're only enabling r2 in the features you pass to LLVM, so unsure why they're landing in there).

Are you sure about that? Which r6 instructions do you see?

EDIT: at least qemu-mips-static doesn't complain about unknown instructions. But who knows, maybe it implements some 64-bit instructions for some reason.

aykevl added 2 commits July 30, 2024 19:55
Move triple calculation into defaultTarget. It was separate for historic
reasons that no longer apply. Merging the code makes future changes
easier (in particular, softfloat support).

The new code is actually shorter than the old code even though it has
more comments.
Previously, the compiler would default to hardfloat. This is not
supported by some MIPS CPUs.

This took me much longer than it should have because of a quirk in the
LLVM Mips backend: if the target-features string is not set (like during
LTO), the Mips backend picks the first function in the module and uses
that. Unfortunately, in the case of TinyGo this first function is
`llvm.dbg.value`, which is an LLVM intrinsic and doesn't have the
target-features string. I fixed it by adding a `-mllvm -mattr=` flag to
the linker.
@clabby
Copy link

clabby commented Jul 30, 2024

Noticing that the resulting MIPS32 BE binary includes some MIPS64 instructions, some from r6 (it looks like we're only enabling r2 in the features you pass to LLVM, so unsure why they're landing in there).

Are you sure about that? Which r6 instructions do you see?

Apologies - was mistaken, SWC2 is not from r6, rather an extension - misread a note where it was changed in r6. From the MIPS spec:

Coprocessor 2 is optional and may be omitted. Software may determine if Coprocessor 2 is implemented by checking the state of the C2 bit in the Config1 CP0 register. If Coprocessor 2 is implemented, the Coprocessor 2 interface instructions (BC2, CFC2, COP2, CTC2, DMFC2, DMTC2, LDC2, LWC2, MFC2, MTC2, SDC2, and SWC2) may be omitted on an instruction-by-instruction basis.

With the standard "big Go," it seems to use r1, which might be why the coprocessor instructions aren't used w/ GOARCH=mips? Also saw an instance of DADDIU, which is from MIPS64.

(Let me know if there's a better place to discuss - sorry for cluttering your PR!)

@aykevl
Copy link
Member Author

aykevl commented Jul 30, 2024

With the standard "big Go," it seems to use r1, which might be why the coprocessor instructions aren't used w/ GOARCH=mips?

Yeah we should probably switch to mips32r1, I can do that in a separate PR (after the refactor in this PR).

Also saw an instance of DADDIU, which is from MIPS64.

I don't, when I disassemble the binary. I also don't see SWC2. Where do you see it? Can you maybe give me the binary and the instruction address?

(Let me know if there's a better place to discuss - sorry for cluttering your PR!)

I guess the original issue is a place we could discuss this.

@aykevl aykevl mentioned this pull request Jul 31, 2024
@deadprogram
Copy link
Member

So is this PR ready to merge?

@aykevl
Copy link
Member Author

aykevl commented Aug 12, 2024

From my point of view, yes. It makes TinyGo a bit more compatible with older/simpler MIPS cores. A future PR will move to mips32r1 for even wider compatibility.

@deadprogram
Copy link
Member

OK, great. Thanks @aykevl now merging.

@deadprogram deadprogram merged commit f188eaf into dev Aug 12, 2024
25 checks passed
@deadprogram deadprogram deleted the mips-softfloat branch August 12, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants