Chip16 Official thread (Development/Suggestions)

Discussion in 'Web development / Programming' started by tykel, Nov 6, 2011.

  1. refraction

    refraction PCSX2 Coder Contributors Award Winner!

    Messages:
    10,102
    Likes Received:
    19
    Sorry for the double post

    @tykel, something that has been annoying me, most operations are done as unsigned operations, however the new 1.3 spec ones use signed operations in order to pass the 1.3 spec test. Shouldn't we just make these unsigned as well as it doesn't make sense from a hardware or programming perspective.

    Edit: I have also released a new version of my emulator (1.7), quite a few changes, but I pretty much rewrote the recompiler to support 7 X86 registers in Register Caching instead of one as it represents more closely how it is done than before and hopefully better performance. I changed a bunch of other stuff too, but this was the vast majority of the changes.
    Last edited: Nov 6, 2015
  2. tykel

    tykel Sober coder

    Messages:
    462
    Likes Received:
    4
    My understanding is that values are treated as signed unless it indicates they are unsigned (or that they are addresses/pointers for instance). I'm open to discuss this.

    I'll be looking into your recompiler, implementing a JIT is something I still have never got around to doing! :)
  3. refraction

    refraction PCSX2 Coder Contributors Award Winner!

    Messages:
    10,102
    Likes Received:
    19
    I see, it seems my entire emulator, except the 1.3 spec stuff (For the test) are treated completely as unsigned, all with the exception of Immediate values, although they were unsigned for ages :p The biggest problem is that the specification doesn't specify any of this, nor are there any "U" suffixes to say that values are treated as unsigned. It would be good to standardise this, from a hardware perspective, generally unless it was a specific command (suffixed as said above) it would be treated as signed, however if you do this now with chip16, it breaks lots of the roms :p

    Good luck with the recompiler! If you need any help let me know! (btw that was me adding you on facebook :p )
  4. overclocked

    overclocked Member

    Messages:
    56
    Likes Received:
    1
    I have questions about:
    SHL RX, N
    SHR RX, N

    Is the N-flag mirroring the bit that is shifted out if the 16-bit register or is it suppose to just used as a Negative-flag and shows the state of the top-bit after shifting. If the N-bit isn't used as out-shift-bit, shouldn't the overflow at least be used as this. Or must the user save the out-shift-bit before shifting? I'm working on a nice Chip16 Library and also a good use of it! :)
  5. refraction

    refraction PCSX2 Coder Contributors Award Winner!

    Messages:
    10,102
    Likes Received:
    19
    I'm confused what you mean? the N bit is how many places to shift for example if you shift this

    1111000011110000
    say N = 3, in SHR this will become
    0001111000011110

    in SHL it will become

    1000011110000000

    in SAR it will be come

    1111111000011110

    SAL will be the same as the SHL result (the LSB never gets copied)
  6. overclocked

    overclocked Member

    Messages:
    56
    Likes Received:
    1
    Sorry for being unclear. I understand that the N that is listed in the instruction here really is the number of bits it will shift, but in the spec, both N-flag and Z-flag is also changed. What do they tell us? And is there a flag telling us what the last bit shifted out was?
  7. refraction

    refraction PCSX2 Coder Contributors Award Winner!

    Messages:
    10,102
    Likes Received:
    19
    oh, no you just test the bits of the results, if the top bit is 1, set the N flag, if the whole result is 0, set the zero flag (of course if you set zero you can skip the negative check or visa versa, depending which way you call them)
  8. overclocked

    overclocked Member

    Messages:
    56
    Likes Received:
    1
    OK thanks! Then the current nChip16 is correct is this matter and I need to save the bit BEFORE shifting if I need to keep track of what shifted out. Thanks! In this matter, it woul be possible to use f.e. the O-bit (overflow) to indicate the shifted out bit. But nevermind, as long as this is 100% clear to everyone then I'm satisfied! On to my library!
  9. refraction

    refraction PCSX2 Coder Contributors Award Winner!

    Messages:
    10,102
    Likes Received:
    19
    Why do you need to remember the bit you shifted out? What do you require it for?
  10. overclocked

    overclocked Member

    Messages:
    56
    Likes Received:
    1
    It's a secret! :) But in this case, to get more than 16 usuable bits. I've seen several CPU's that handles these just to support relatively fast access to arithmetics more than the machine's native number of bits.
  11. refraction

    refraction PCSX2 Coder Contributors Award Winner!

    Messages:
    10,102
    Likes Received:
    19
    Okay well, good luck! :)
  12. tykel

    tykel Sober coder

    Messages:
    462
    Likes Received:
    4
    Are you making a proprietary extension to Chip16 then? ;)
    In terms of the binary operations, shouldn't the resulting bit string be the same regardless of whether it is signed or not, and only change the decimal representation? (E.g. 1000 0000 can be either -127 or 128 depending on whether we treat as a int8_t or uint8_t)
    I guess it wouldn't hurt to make this more explicit in the spec, agreed. Could add to each instruction whether the operands are interpreted as signed or unsigned.
  13. refraction

    refraction PCSX2 Coder Contributors Award Winner!

    Messages:
    10,102
    Likes Received:
    19
    Well as an example

    say we have 2 ( 0000 0000 0000 0010 )
    and -12 ( 1000 0000 0000 1100 )

    now is that -12 or 32780. your results are different depending which it is

    2 - -12 = 14
    2 - 32780 = 32758 (when wrapped to 16 bit)

    obviously the second one should be wrong, but these are the answers the current implementation expects.
  14. tykel

    tykel Sober coder

    Messages:
    462
    Likes Received:
    4
    2 == 0000 0000 0000 0010 in both unsigned and signed since the top bit is 0, we agree thus far.

    12 == 0000 0000 0000 1100 in both unsigned and signed, similarly;
    -12 signed == ~12 + 1 == 1111 1111 1111 0011 + 0..1 == 1111 1111 1111 0100 == 65524 unsigned

    2 - -12 = 14
    14 == 0000 0000 0000 1110

    2 - 65524 == 0 - 65522 == 65536 - 65522 == 14 also, we use the fact 65536 == 0x10000 when we "borrow" an extra bit

    I uploaded a quick C program which reinterprets a signed variable's memory as unsigned and performs the operations above, it will show you these results.



    However, I still think making when signed and unsigned variables are used more explicit is a good idea. Coming up in spec 1.3b? :p

    Attached Files:

    • test.txt
      File size:
      626 bytes
      Views:
      0
  15. refraction

    refraction PCSX2 Coder Contributors Award Winner!

    Messages:
    10,102
    Likes Received:
    19
    That works fine in straight C but try doing it in x86, it doesn't work so well :p if i replace my DIV instructions with iDIV (And extend the sign accordingly to EDX) it stops working.
  16. refraction

    refraction PCSX2 Coder Contributors Award Winner!

    Messages:
    10,102
    Likes Received:
    19
    Sorry for the double post but as you can see I had little choice :p

    To celebrate the near 1 year anniversary of somebody last posting in this thread, I have released version 1.81 of my emu. It has improved texture filtering and I have upgraded SDL to version 2.0 which gets rid of that horrible stutter when VSync is enabled, along with fixing a couple of bugs, enjoy!

    https://github.com/refractionpcsx2/refchip16/releases/tag/1.81
    Shendo and paul_nicholls like this.
  17. paul_nicholls

    paul_nicholls Member

    Messages:
    187
    Likes Received:
    0
    Looks good mate, will give it a spin :)
    Thanks for keeping the thread alive! lol
    Paul
  18. Shendo

    Shendo Moderator Staff Member Moderator

    Messages:
    5,154
    Likes Received:
    45
    Screenshot from 2016-10-20 04-18-11.png

    Long overdue and not completely finished but I guess it'll work as a proof of concept...
    I included both a compiled program and the source.

    Attached Files:

Share This Page