Skip to content
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

refactor(connect-four): add board evaluation #228

Merged
merged 14 commits into from
May 20, 2024
Merged

Commits on May 12, 2024

  1. Configuration menu
    Copy the full SHA
    aa7f522 View commit details
    Browse the repository at this point in the history
  2. refactor: better performance

    kyranet committed May 12, 2024
    Configuration menu
    Copy the full SHA
    142bfe8 View commit details
    Browse the repository at this point in the history

Commits on May 13, 2024

  1. ci: use nightly

    kyranet committed May 13, 2024
    Configuration menu
    Copy the full SHA
    13f8bb9 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5932eb5 View commit details
    Browse the repository at this point in the history
  3. refactor: better code

    kyranet committed May 13, 2024
    Configuration menu
    Copy the full SHA
    4b707c9 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    d611caf View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    2c1fbd8 View commit details
    Browse the repository at this point in the history
  6. refactor: better evaluate_window mask creation

    From 1 SSE2 and a jump, to 2 SSE instructions and no jump
    kyranet committed May 13, 2024
    Configuration menu
    Copy the full SHA
    187388b View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    d69b50f View commit details
    Browse the repository at this point in the history

Commits on May 14, 2024

  1. Configuration menu
    Copy the full SHA
    e665c82 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f4ee0bb View commit details
    Browse the repository at this point in the history

Commits on May 16, 2024

  1. chore: better documentation

    Co-authored-by: Tyler J Russell <[email protected]>
    kyranet and Nytelife26 authored May 16, 2024
    Configuration menu
    Copy the full SHA
    336abaa View commit details
    Browse the repository at this point in the history
  2. perf: improve evaluate_window's performance even further

    The code prior to this commit was already quite fast, at 37 instructions.
    
    For this commit, I did two things:
    
    1. I read all the indexes once per line instead of once per window, this
      allowed the code to read the values as a sequence of contiguous `u8`
      values instead of a sequence that jumps around in memory. This by
      itself allows the `evaluate_window` function to use a slice rather
      than having to create a new array per window. This change reduced the
      number of instructions in `evaluate_window` from 37 to 23.
    2. I changed `ConnectFour` to add a `score_player_mask` field containing
      the `Simd<u8, 4>` value, rather than having to make a new one on every
      `evaluate_window` call. This change reduced the number of instructions
      in `evaluate_window` from 23 to 19.
    
    The final x86 assembly code for `evaluate_window` is as follows:
    
    ```asm
    ; fn evaluate_window(&self, player: Player, window: &[u8; 4]) -> i32 {
         movdqa  xmm0, xmmword, ptr, [rdx]
         pxor    xmm1, xmm1
         movdqa  xmm2, xmm0
         pcmpeqb xmm2, xmm1
         xorps   xmm3, xmm3
         movss   xmm3, xmm2
         pmovmskb eax, xmm3
    ; match mask.to_bitmask() {
     movzx   eax, al
         pcmpeqb xmm0, xmmword, ptr, [rcx]
     lea     rcx, [rip, +, switch.table._ZN8skyra_ai5games12connect_four11ConnectFour15evaluate_window17hbe62da8767e17f32E]
         movss   xmm1, xmm0
         pmovmskb edx, xmm1
     movzx   edx, dl
     lea     r8, [rip, +, switch.table._ZN8skyra_ai5games12connect_four11ConnectFour15evaluate_window17hbe62da8767e17f32E.300]
     movzx   edx, byte, ptr, [rdx, +, r8]
    ; let mask: u8 = (player_pieces << 3) | empty_pieces;
     or      dl, byte, ptr, [rax, +, rcx]
     movsx   rax, dl
    ; match mask {
     lea     rcx, [rip, +, switch.table._ZN8skyra_ai5games12connect_four11ConnectFour15evaluate_window17hbe62da8767e17f32E.299]
     mov     eax, dword, ptr, [rcx, +, 4*rax, -, 4]
    ; }
     ret
    ```
    kyranet committed May 16, 2024
    Configuration menu
    Copy the full SHA
    78e92d8 View commit details
    Browse the repository at this point in the history

Commits on May 20, 2024

  1. ci: use NPM_PUBLISH_TOKEN instead of NPM_TOKEN

    That's the name of the token we use for publish
    kyranet committed May 20, 2024
    Configuration menu
    Copy the full SHA
    086237b View commit details
    Browse the repository at this point in the history