badlogic / wee

A wee educational programming environment.
MIT License
19 stars 0 forks source link

Some thoughts on instruction set #1

Closed binji closed 6 years ago

binji commented 6 years ago

Hi, just saw your twitter post and thought I'd take a look!

First off, this is very cool!

Some initial thoughts/comments:

badlogic commented 6 years ago

Thanks for the feedback!

Thanks again, i'll update the specs as soon as i find a spare hour :)

binji commented 6 years ago

I think you get unsigned mul for free, since it's sign-agnostic as long as you assume 2's complement.

i added ports as a polling and blocking workaround. i think for most things this will be sufficient.

Ah, I didn't notice that port_read is blocking. OK, seems like it could work :-)

sp always points at the last pushed value, so for pop i have to read, then subtract

That doesn't line up with how you define push currently:

Write the 32-bit value word2 to the stack at address sp, then decrease sp by 4

badlogic commented 6 years ago

Sadly, ou only get addition/substraction for free :/

I'm gonna fix up the push semantics!

binji commented 6 years ago

Nope, multiply works too! We use that fact in WebAssembly. You can also see that the same code is generated in godbolt.

badlogic commented 6 years ago

Ah, I remembered x86 imul and assumed there was a reason for it that I can't ignore.

I do need signed/unsigned cmp though!

binji commented 6 years ago

Yeah, the high 32-bits and flags only make sense for signed, but the low 32-bits are the same for signed or unsigned. And you're right about cmp!

Though you could make the argument that having unsigned makes things more complicated. AIUI Java originally had only signed integers (Though it sounds like they have some support for unsigned now) and I guess it mostly works. I found this SO answer that mentions the design choice.

badlogic commented 6 years ago

Since Wee is supposed to be a learning environment, I believe it's important to expose students to two's complement. Having the defaults signed, but offering unsigned variants when necessary seems like a good compromise imo.

I've added:

Really appreciate that you took the time to give feedback on this somewhat dry matter. Thanks!