cnlohr / rv003usb

CH32V003 RISC-V Pure Software USB Controller
MIT License
459 stars 47 forks source link

Better instructions parsing of 00/11 to 1/0 #8

Open Domkeykong opened 1 year ago

Domkeykong commented 1 year ago

While looking at the rv32e instruction set i found these 2 which can be very useful:

        snez a0, a0 // set not equal zero

which can be used here to save 3 instructions: https://github.com/cnlohr/rv003usb/blob/4cfe8201e15f54e5ece6e178153990f82d764951/firmware/rv003usb.S#L142-L144

and this

        seqz a0, a0 // set equal zero

which can be used here as an alternative: https://github.com/cnlohr/rv003usb/blob/4cfe8201e15f54e5ece6e178153990f82d764951/firmware/rv003usb.S#L285 with both of those changes combined you may even be able to drop the requirements of having D- before D+

cnlohr commented 1 year ago

Please articulate more, exactly what the change would be (before/after)

Side-note: I have NEVER seen sltiu that's very cool.

cnlohr commented 1 year ago

side-note: It would be mega cool to be able to do all this on the 24MHz internal clock for other situations w/o pll.

cnlohr commented 1 year ago

side-side-note: I really wish they had c.sltiu

duk-37 commented 1 year ago

The proposal here is just to replace the highlighted instruction sequences with snez a0, a0 and seqz a0, a0 respectively. This works because at either of these points in time a0 will just be either zero or nonzero. Really the only issue I see with this would be alignment for the rest of the start of packet_type_loop, but that's fixable.