mirror of
https://github.com/cc65/cc65.git
synced 2024-09-27 19:55:09 +00:00
Implement aslax7/shlax7/asrax7/shrax7
This commit is contained in:
parent
51b946bf25
commit
7d7cf2d1e0
21
libsrc/runtime/aslax7.s
Normal file
21
libsrc/runtime/aslax7.s
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
;
|
||||||
|
; Miloslaw Smyk, 2024
|
||||||
|
;
|
||||||
|
; CC65 runtime: Scale the primary register by 128, unsigned
|
||||||
|
;
|
||||||
|
|
||||||
|
.export shlax7, aslax7
|
||||||
|
|
||||||
|
aslax7:
|
||||||
|
shlax7: ; XXXXXXXL AAAAAAAl
|
||||||
|
tay
|
||||||
|
txa
|
||||||
|
lsr ; XXXXXXXL -> 0XXXXXXX, L->C
|
||||||
|
tya
|
||||||
|
ror ; AAAAAAAl -> LAAAAAAA, l->C
|
||||||
|
tax
|
||||||
|
lda #$00 ; LAAAAAAA 00000000
|
||||||
|
ror ; LAAAAAAA l0000000
|
||||||
|
rts
|
||||||
|
|
||||||
|
; 10 bytes, 16 cycles + rts
|
18
libsrc/runtime/asrax7.s
Normal file
18
libsrc/runtime/asrax7.s
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
;
|
||||||
|
; Miloslaw Smyk, 2024
|
||||||
|
;
|
||||||
|
; CC65 runtime: Scale the primary register by 128, signed
|
||||||
|
;
|
||||||
|
|
||||||
|
.export asrax7
|
||||||
|
|
||||||
|
asrax7: ; HXXXXXXL hAAAAAAl
|
||||||
|
asl ; AAAAAAA0, h->C
|
||||||
|
txa
|
||||||
|
rol ; XXXXXXLh, H->C
|
||||||
|
ldx #$00 ; 00000000 XXXXXXLh
|
||||||
|
bcc :+
|
||||||
|
dex ; 11111111 XXXXXXLh if C
|
||||||
|
: rts
|
||||||
|
|
||||||
|
; 12 cycles max, 9 bytes
|
18
libsrc/runtime/shrax7.s
Normal file
18
libsrc/runtime/shrax7.s
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
;
|
||||||
|
; Miloslaw Smyk, 2024
|
||||||
|
;
|
||||||
|
; CC65 runtime: Scale the primary register by 128, unsigned
|
||||||
|
;
|
||||||
|
|
||||||
|
.export shrax7
|
||||||
|
|
||||||
|
shrax7: ; HXXXXXXL hAAAAAAl
|
||||||
|
asl ; AAAAAAA0, h->C
|
||||||
|
txa
|
||||||
|
rol ; XXXXXXLh, H->C
|
||||||
|
ldx #$00 ; 00000000 XXXXXXLh
|
||||||
|
bcc :+
|
||||||
|
inx ; 0000000H XXXXXXLh if C
|
||||||
|
: rts
|
||||||
|
|
||||||
|
; 12 cycles max, 9 bytes
|
@ -3260,6 +3260,14 @@ void g_asr (unsigned flags, unsigned long val)
|
|||||||
}
|
}
|
||||||
val -= 8;
|
val -= 8;
|
||||||
}
|
}
|
||||||
|
if (val == 7) {
|
||||||
|
if (flags & CF_UNSIGNED) {
|
||||||
|
AddCodeLine ("jsr shrax7");
|
||||||
|
} else {
|
||||||
|
AddCodeLine ("jsr asrax7");
|
||||||
|
}
|
||||||
|
val = 0;
|
||||||
|
}
|
||||||
if (val >= 4) {
|
if (val >= 4) {
|
||||||
if (flags & CF_UNSIGNED) {
|
if (flags & CF_UNSIGNED) {
|
||||||
AddCodeLine ("jsr shrax4");
|
AddCodeLine ("jsr shrax4");
|
||||||
@ -3402,6 +3410,14 @@ void g_asl (unsigned flags, unsigned long val)
|
|||||||
AddCodeLine ("lda #$00");
|
AddCodeLine ("lda #$00");
|
||||||
val -= 8;
|
val -= 8;
|
||||||
}
|
}
|
||||||
|
if (val == 7) {
|
||||||
|
if (flags & CF_UNSIGNED) {
|
||||||
|
AddCodeLine ("jsr shlax7");
|
||||||
|
} else {
|
||||||
|
AddCodeLine ("jsr aslax7");
|
||||||
|
}
|
||||||
|
val = 0;
|
||||||
|
}
|
||||||
if (val >= 4) {
|
if (val >= 4) {
|
||||||
if (flags & CF_UNSIGNED) {
|
if (flags & CF_UNSIGNED) {
|
||||||
AddCodeLine ("jsr shlax4");
|
AddCodeLine ("jsr shlax4");
|
||||||
|
@ -99,6 +99,7 @@ static const FuncInfo FuncInfoTable[] = {
|
|||||||
{ "aslax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "aslax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
{ "aslax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "aslax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
{ "aslax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "aslax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
|
{ "aslax7", REG_AX, PSTATE_ALL | REG_AXY },
|
||||||
{ "aslaxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
|
{ "aslaxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
|
||||||
{ "asleax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
{ "asleax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
||||||
{ "asleax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
{ "asleax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
||||||
@ -108,6 +109,7 @@ static const FuncInfo FuncInfoTable[] = {
|
|||||||
{ "asrax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "asrax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
{ "asrax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "asrax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
{ "asrax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "asrax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
|
{ "asrax7", REG_AX, PSTATE_ALL | REG_AX },
|
||||||
{ "asraxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
|
{ "asraxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
|
||||||
{ "asreax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
{ "asreax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
||||||
{ "asreax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
{ "asreax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
||||||
@ -245,6 +247,7 @@ static const FuncInfo FuncInfoTable[] = {
|
|||||||
{ "shlax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "shlax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
{ "shlax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "shlax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
{ "shlax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "shlax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
|
{ "shlax7", REG_AX, PSTATE_ALL | REG_AXY },
|
||||||
{ "shlaxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
|
{ "shlaxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
|
||||||
{ "shleax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
{ "shleax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
||||||
{ "shleax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
{ "shleax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
||||||
@ -254,6 +257,7 @@ static const FuncInfo FuncInfoTable[] = {
|
|||||||
{ "shrax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "shrax2", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
{ "shrax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "shrax3", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
{ "shrax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
{ "shrax4", REG_AX, PSTATE_ALL | REG_AX | REG_TMP1 },
|
||||||
|
{ "shrax7", REG_AX, PSTATE_ALL | REG_AX },
|
||||||
{ "shraxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
|
{ "shraxy", REG_AXY, PSTATE_ALL | REG_AXY | REG_TMP1 },
|
||||||
{ "shreax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
{ "shreax1", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
||||||
{ "shreax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
{ "shreax2", REG_EAX, PSTATE_ALL | REG_EAX | REG_TMP1 },
|
||||||
|
44
test/val/lib_runtime_aslax7.c
Normal file
44
test/val/lib_runtime_aslax7.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
!!DESCRIPTION!! A small test for aslax7.
|
||||||
|
!!ORIGIN!!
|
||||||
|
!!LICENCE!!
|
||||||
|
!!AUTHOR!!
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
signed int ai = -32768, ti, refi;
|
||||||
|
signed char ac = -128, tc, refc;
|
||||||
|
|
||||||
|
do {
|
||||||
|
refi = ai << 4;
|
||||||
|
refi = refi << 3;
|
||||||
|
|
||||||
|
ti = ai << 7;
|
||||||
|
|
||||||
|
if (ti != refi) {
|
||||||
|
printf("wrong result on int %d << 7: %04X, expected %04X\n", ai, ti, refi);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} while (ai != -32768);
|
||||||
|
|
||||||
|
do {
|
||||||
|
refc = ac << 4;
|
||||||
|
refc = refc << 3;
|
||||||
|
|
||||||
|
tc = ac << 7;
|
||||||
|
|
||||||
|
if (tc != refc) {
|
||||||
|
printf("wrong result on char %d << 7: %04X, expected %04X\n", ac, tc, refc);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} while (ac != -128);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
44
test/val/lib_runtime_asrax7.c
Normal file
44
test/val/lib_runtime_asrax7.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
!!DESCRIPTION!! A small test for asrax7.
|
||||||
|
!!ORIGIN!!
|
||||||
|
!!LICENCE!!
|
||||||
|
!!AUTHOR!!
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
signed int ai = -32768, ti, refi;
|
||||||
|
signed char ac = -128, tc, refc;
|
||||||
|
|
||||||
|
do {
|
||||||
|
refi = ai >> 4;
|
||||||
|
refi = refi >> 3;
|
||||||
|
|
||||||
|
ti = ai >> 7;
|
||||||
|
|
||||||
|
if (ti != refi) {
|
||||||
|
printf("wrong result on int %d >> 7: %04X, expected %04X\n", ai, ti, refi);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} while (ai != -32768);
|
||||||
|
|
||||||
|
do {
|
||||||
|
refc = ac >> 4;
|
||||||
|
refc = refc >> 3;
|
||||||
|
|
||||||
|
tc = ac >> 7;
|
||||||
|
|
||||||
|
if (tc != refc) {
|
||||||
|
printf("wrong result on char %d >> 7: %04X, expected %04X\n", ac, tc, refc);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} while (ac != -128);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
44
test/val/lib_runtime_shlax7.c
Normal file
44
test/val/lib_runtime_shlax7.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
!!DESCRIPTION!! A small test for shlax7.
|
||||||
|
!!ORIGIN!!
|
||||||
|
!!LICENCE!!
|
||||||
|
!!AUTHOR!!
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
unsigned int ai = 0, ti, refi;
|
||||||
|
unsigned char ac = 0, tc, refc;
|
||||||
|
|
||||||
|
do {
|
||||||
|
refi = ai << 4;
|
||||||
|
refi = refi << 3;
|
||||||
|
|
||||||
|
ti = ai << 7;
|
||||||
|
|
||||||
|
if (ti != refi) {
|
||||||
|
printf("wrong result on int %u << 7: %04X, expected %04X\n", ai, ti, refi);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} while (ai != 0);
|
||||||
|
|
||||||
|
do {
|
||||||
|
refc = ac << 4;
|
||||||
|
refc = refc << 3;
|
||||||
|
|
||||||
|
tc = ac << 7;
|
||||||
|
|
||||||
|
if (tc != refc) {
|
||||||
|
printf("wrong result on char %u << 7: %04X, expected %04X\n", ac, tc, refc);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} while (ac != 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
44
test/val/lib_runtime_shrax7.c
Normal file
44
test/val/lib_runtime_shrax7.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
!!DESCRIPTION!! A small test for shrax7.
|
||||||
|
!!ORIGIN!!
|
||||||
|
!!LICENCE!!
|
||||||
|
!!AUTHOR!!
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
unsigned int ai = 0, ti, refi;
|
||||||
|
unsigned char ac = 0, tc, refc;
|
||||||
|
|
||||||
|
do {
|
||||||
|
refi = ai >> 4;
|
||||||
|
refi = refi >> 3;
|
||||||
|
|
||||||
|
ti = ai >> 7;
|
||||||
|
|
||||||
|
if (ti != refi) {
|
||||||
|
printf("wrong result on int %d >> 7: %04X, expected %04X\n", ai, ti, refi);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} while (ai != 0);
|
||||||
|
|
||||||
|
do {
|
||||||
|
refc = ac >> 4;
|
||||||
|
refc = refc >> 3;
|
||||||
|
|
||||||
|
tc = ac >> 7;
|
||||||
|
|
||||||
|
if (tc != refc) {
|
||||||
|
printf("wrong result on char %d >> 7: %04X, expected %04X\n", ac, tc, refc);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} while (ac != 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user