Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/libc/ceilf.src
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@

_ceil:
_ceilf:
call __frameset0
ld bc, (ix+6)
ld a, (ix+9)
ld hl, 6
add hl, sp
ld a, (hl)
dec hl
dec hl
dec hl
ld bc, (hl)
call __fneg
ld l, a
ld h, 0
push hl
push bc
call _floor
pop bc
pop bc
push hl
ex (sp), hl
pop bc
ld a, e
call __fneg
ld e, a
push bc
pop hl
pop ix
ret

.extern __frameset0
.extern __fneg
.extern _floor

Expand Down
12 changes: 7 additions & 5 deletions src/libc/cimagf.src
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
; float cimagf(float _Complex)
_cimagf:
_cimag:
ld iy, 0
add iy, sp
ld sp, iy
ld hl, (iy + 7)
ld e, (iy + 10)
ld hl, 10
add hl, sp
ld e, (hl)
dec hl
dec hl
dec hl
ld hl, (hl)
ret
1 change: 0 additions & 1 deletion src/libc/cimagl.src
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
_cimagl:
ld iy, 0
add iy, sp
ld sp, iy
ld hl, (iy + 11)
ld de, (iy + 14)
ld bc, (iy + 17)
Expand Down
7 changes: 3 additions & 4 deletions src/libc/strrstr.src
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ _strrstr:
ld bc, 0
cpir
sbc hl, hl
dec hl
sbc hl, bc ; carry will be cleared
scf
sbc hl, bc ; carry will be set
ex (sp), hl ; strlen(needle)
push hl ; needle

ex de, hl
push hl
ld bc, 0
ld bc, -1
cpir
sbc hl, hl
dec hl
sbc hl, bc
ex (sp), hl ; strlen(haystack)
push hl ; haystack
Expand Down
7 changes: 3 additions & 4 deletions src/libc/strstr.src
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ _strstr:
ld bc, 0
cpir
sbc hl, hl
dec hl
sbc hl, bc ; carry will be cleared
scf
sbc hl, bc ; carry will be set
ex (sp), hl ; strlen(needle)
push hl ; needle

ex de, hl
push hl
ld bc, 0
ld bc, -1
cpir
sbc hl, hl
dec hl
sbc hl, bc
ex (sp), hl ; strlen(haystack)
push hl ; haystack
Expand Down
26 changes: 8 additions & 18 deletions src/srldrvce/srldrvce.asm
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ srl_GetCDCStandardDescriptors:
jq nz,.noserial

ld a,3
ld hl,.device+deviceDescriptor.iSerialNumber
ld (hl),a
ld (.device+deviceDescriptor.iSerialNumber),a

ld de,.stringserialnum + 2
ld hl,ti.OP4
Expand All @@ -550,9 +549,7 @@ srl_GetCDCStandardDescriptors:
jq c,.store
add a,'A'-'9'-1
.store:
ex de,hl
ld (hl),a
ex de,hl
ld (de),a
inc de
inc de
ret
Expand Down Expand Up @@ -615,15 +612,12 @@ srl_UsbEventCallback:
push de
push de
call usb_FindDevice
pop de
pop de
pop de
ld sp, ix
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't exactly a peephole optimization, but you could entirely remove this.

Suggested change
ld sp, ix

ld de, 0
push de
push hl
call usb_GetDeviceEndpoint
pop de
pop de
ld sp, ix
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't exactly a peephole optimization, but you could entirely remove this.

Suggested change
ld sp, ix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized we can also call .line_coding here to save another byte

Copy link
Copy Markdown
Contributor Author

@ZERICO2005 ZERICO2005 Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although to be fair. If we need to save bytes we would just rewrite that whole function in assembly lol

ld de, 0
push de
push de
Expand All @@ -634,11 +628,7 @@ srl_UsbEventCallback:
push hl
call usb_ScheduleControlTransfer
ld bc, 1
pop hl
pop hl
pop hl
pop hl
pop hl
ld sp, ix
.BB0_5:
push bc
pop hl
Expand Down Expand Up @@ -668,7 +658,7 @@ get_device_type:
call next_descriptor
inc hl
inc hl
ld de,0
inc.s de ; clear UDE
ld e,(hl) ; total descriptor length
inc hl
ld d,(hl)
Expand Down Expand Up @@ -828,7 +818,7 @@ set_rate_cdc:
ld (.linecoding),hl
ld bc,0
push bc ; transferred
ld bc,50
ld c,50 ; ld bc, 50
push bc ; num retries
ld bc,.linecoding
push bc ; data
Expand Down Expand Up @@ -984,8 +974,8 @@ ring_buf_push:
sbc hl,hl ; check if bc is 0
adc hl,bc
ret z
ld hl,(xring_buf_ctrl.data_end)
ex de,hl ; hl = data
ld de,(xring_buf_ctrl.data_end)
push bc
ldir ; de = data_end + len
ld (xring_buf_ctrl.data_end),de
Expand Down
4 changes: 2 additions & 2 deletions src/usbdrvce/usbdrvce.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2952,8 +2952,8 @@ assert endpointDescriptor.wMaxPacketSize+2 = endpointDescriptor.bInterval
inc hl
ld b,(hl)
inc b
djnz .validInterval
jq .invalidParam
dec b
jq z, .invalidParam
.validInterval:
ex de,hl
inc.s hl
Expand Down
Loading