-
I'm trying to write an inline assembly function for an ESP32-S3FN8. mpy-cross works for generating precompiled binaries when passing the xtensawin architecture, however when i try to use |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
well, time to answer my own question once again it appears xtensawin doesn't have an inline option, only native emitter. So to turn this into another question, I'm using xtensawin because I saw somewhere that xtensa is for ESP8266 and xtensawin is for ESP32. is that the case or is there some confusion? is there a technical reason why xtensawin can't have inline assembly? EDIT: let me rephrase.. what i need is not necessarily xtensawin inline assembly, but rather i'm trying to do 16bit clamped addition very quickly. i have a viper function that calls on this: _INT_MINVAL = const(-32768)
_INT_MAXVAL = const(32767)
@micropython.native
def _16bit_clamp_add(a, b):
a = -(~a & 0b0111111111111111) - 1 if a & 0b1000000000000000 else (a & 0b0111111111111111)
b = -(~b & 0b0111111111111111) - 1 if b & 0b1000000000000000 else (b & 0b0111111111111111)
res = a+b
res = (_INT_MINVAL if res < _INT_MINVAL else _INT_MAXVAL if res > _INT_MAXVAL else res)
if res < 0:
return res & 0b0111111111111111 | 0b1000000000000000
return res & 0b0111111111111111 prior to this, this entire block was replaced by a simple line in viper that was (consider out and in both results of ptr16 addressings)
and is now
due to the addition overflowing in 16bit arithmetic. however, the code (part of an I2S audio library) no longer performs as quickly, causing dropouts. is there a better way to approach this? the reason i'm using native instead of viper is viper lacking the |
Beta Was this translation helpful? Give feedback.
-
I feel I must be missing something here, but the following works to clamp a value as you require: @micropython.viper
def test(x):
return max(0-32768, min(x, 32767)) |
Beta Was this translation helpful? Give feedback.
-
my viper snippet for something like this in viper mode looks like:
where cossum is a normal viper |
Beta Was this translation helpful? Give feedback.
clamping bit values after a bit shift. that's what i'm missing. this is the actual full code now