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

Support a '@' operator to perform a grover search from C. #4

Open
wants to merge 5 commits into
base: 6502q
Choose a base branch
from

Conversation

bennbollay
Copy link
Member

Informational at this point in time, only.

@bennbollay
Copy link
Member Author

Here's the generated assembly:

;
; File generated by cc65 v 2.17 - Git b4a95cb0
;
        .fopt           compiler,"cc65 v 2.17 - Git b4a95cb0"
        .setcpu         "6502Q"
        .smart          on
        .autoimport     on
        .case           on
        .debuginfo      off
        .importzp       sp, sreg, regsave, regbank
        .importzp       tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4
        .macpack        longbranch
        .export         _buffer
        .export         _value
        .export         _parameters
        .export         _immediates
        .export         _locals
        .export         _globals
        .export         _example
        .export         _caller

.segment        "DATA"

_value:
        .word   $0031

.segment        "BSS"

_buffer:
        .res    300,$00

; ---------------------------------------------------------------
; void __near__ parameters (__near__ void *, int)
; ---------------------------------------------------------------

.segment        "CODE"

.proc   _parameters: near

.segment        "CODE"

;
; {
;
        jsr     pushax
;
; y = buf @ val;
;
        jsr     decsp2
        ldy     #$07
        jsr     pushwysp
        ldy     #$05
        lda     (sp),y
        tax
        dey
        lda     (sp),y
        jsr     pushax
        jsr     _groversearch
        ldy     #$03
        lda     (sp),y
        tax
        dey
        lda     (sp),y
        jsr     stax0sp
;
; }
;
        jmp     incsp6

.endproc

; ---------------------------------------------------------------
; void __near__ immediates (void)
; ---------------------------------------------------------------

.segment        "CODE"

.proc   _immediates: near

.segment        "CODE"

;
; y = (void *)0x1000 @ 42;
;
        jsr     decsp2
        ldx     #$10
        lda     #$00
        jsr     pushax
        lda     #$2A
        jsr     pusha0
        jsr     _groversearch
        ldy     #$00
        lda     #$2A
        sta     (sp),y
        tya
        iny
        sta     (sp),y
;
; }
;
        jmp     incsp2

.endproc

; ---------------------------------------------------------------
; void __near__ locals (void)
; ---------------------------------------------------------------

.segment        "CODE"

.proc   _locals: near

.segment        "CODE"

;
; char *buf = (char *)0x2000;
;
        jsr     decsp2
        ldx     #$20
        lda     #$00
        jsr     pushax
;
; int val = 129;
;
        lda     #$81
        jsr     pusha0
;
; y = buf @ val;
;
        ldy     #$05
        jsr     pushwysp
        ldy     #$03
        lda     (sp),y
        tax
        dey
        lda     (sp),y
        jsr     pushax
        jsr     _groversearch
        ldy     #$01
        lda     (sp),y
        tax
        dey
        lda     (sp),y
        ldy     #$04
        jsr     staxysp
;
; }
;
        jmp     incsp6

.endproc

; ---------------------------------------------------------------
; void __near__ globals (void)
; ---------------------------------------------------------------

.segment        "CODE"

.proc   _globals: near

.segment        "CODE"

;
; y = buffer @ value;
;
        jsr     decsp2
        lda     #<(_buffer)
        ldx     #>(_buffer)
        jsr     pushax
        ldx     #$00
        lda     _value
        bpl     L0015
        dex
L0015:  jsr     pushax
        jsr     _groversearch
        lda     _value
        ldx     _value+1
        jsr     stax0sp
;
; }
;
        jmp     incsp2

.endproc

; ---------------------------------------------------------------
; int __near__ example (__near__ void *, int)
; ---------------------------------------------------------------

.segment        "CODE"

.proc   _example: near

.segment        "CODE"

;
; {
;
        jsr     pushax
;
; b = b;
;
        ldy     #$03
        lda     (sp),y
        tax
        dey
        lda     (sp),y
        jsr     staxysp
;
; v = v;
;
        ldy     #$01
        lda     (sp),y
        tax
        dey
        lda     (sp),y
        jsr     stax0sp
;
; return 5;
;
        ldx     #$00
        lda     #$05
;
; }
;
        jmp     incsp4

.endproc

; ---------------------------------------------------------------
; int __near__ caller (void)
; ---------------------------------------------------------------

.segment        "CODE"

.proc   _caller: near

.segment        "CODE"

;
; return example(buffer, value);
;
        lda     #<(_buffer)
        ldx     #>(_buffer)
        jsr     pushax
        lda     _value
        ldx     _value+1
        jmp     _example

.endproc

Benn Bollay added 3 commits March 20, 2018 14:41
Grover requires a certain number of loops, chosen based on the estimation of
how many 'correct' values there are in the input.  This adds support for syntax
allowing the caller to specify that 'm' value:

```
    // Calibrate for 'm' = 5
    y = (@[] = 5,
            buffer @[] value);
```
@bennbollay bennbollay changed the title NOT READY: Support a '@' operator to perform a grover search from C. Support a '@' operator to perform a grover search from C. Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant