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

Add floating point type? #90

Closed
HPCguy opened this issue Feb 12, 2022 · 3 comments
Closed

Add floating point type? #90

HPCguy opened this issue Feb 12, 2022 · 3 comments

Comments

@HPCguy
Copy link
Contributor

HPCguy commented Feb 12, 2022

I'm guessing 32bit floating point would take 150-400 lines of C source code to implement. For instance, now that dynamic library support has been expanded, AMaCC can call strtof() to parse float constants, saving many lines of compiler code. New IR symbols can be added for FP operations, probably around a dozen. It's my belief that type promotions and function call ABI would be the hardest part of the whole implementation. I think the AMaCC type system is already well positioned to handle float, although some comparison expressions in amacc.c may get longer if there are three base types to consider rather than two. The question for discussion is, just because it can be added, should it be added?

@HPCguy
Copy link
Contributor Author

HPCguy commented Feb 15, 2022

I've opened a branch for this, and I have floating point data movement and floating point constants working. AMaCC is only 35 lines longer, which also includes support for typed function prototypes for external libraries.

int main()
{
int ii;
union {
int i;
float f;
} val;
float a = malloc(10sizeof(float));

val.f = 1.0; // actually works!

for (ii=0; ii<10; ++ii) {
a[ii] = val.f;
val.i = val.i + 0x10000;
}

for (ii=0; ii<10; ++ii) {
val.f = a[ii];
printf("%08x\n", val.i);
}

return 0;
}

$ ./amacc decl.c
3f800000
3f810000
3f820000
3f830000
3f840000
3f850000
3f860000
3f870000
3f880000
3f890000

80: e24b0008 sub r0, fp, #8
84: e52d0004 push {r0} ; (str r0, [sp, #-4]!)
88: ed9f0a6c vldr s0, [pc, #432] ; 0x240 <---- fp constant
8c: e49d1004 pop {r1} ; (ldr r1, [sp], #4)
90: ed810a00 vstr s0, [r1] <----- proper data movement with coprocessor
94: e24b0004 sub r0, fp, #4
98: e52d0004 push {r0} ; (str r0, [sp, #-4]!)
9c: e3a00000 mov r0, #0
a0: e49d1004 pop {r1} ; (ldr r1, [sp], #4)
a4: e5810000 str r0, [r1]
a8: ea000022 b 0x138

a[ii] = val.f // float data movement works with complex types

ac: e24b000c sub r0, fp, #12
b0: e5900000 ldr r0, [r0]
b4: e52d0004 push {r0} ; (str r0, [sp, #-4]!)
b8: e24b0004 sub r0, fp, #4
bc: e5900000 ldr r0, [r0]
c0: e52d0004 push {r0} ; (str r0, [sp, #-4]!)
c4: e3a00004 mov r0, #4
c8: e49d1004 pop {r1} ; (ldr r1, [sp], #4)
cc: e0000091 mul r0, r1, r0
d0: e49d1004 pop {r1} ; (ldr r1, [sp], #4)
d4: e0800001 add r0, r0, r1
d8: e52d0004 push {r0} ; (str r0, [sp, #-4]!)
dc: e24b0008 sub r0, fp, #8
e0: ed900a00 vldr s0, [r0]
e4: e49d1004 pop {r1} ; (ldr r1, [sp], #4)
e8: ed810a00 vstr s0, [r1]

constant pool includes FP

234: b6c06340 strblt r6, [r0], r0, asr #6
238: b6c87008 strblt r7, [r8], r8
23c: 00010000 andeq r0, r1, r0
240: 3f800000 svccc 0x00800000
244: b6c06334 ; instruction: 0xb6c06334

@HPCguy
Copy link
Contributor Author

HPCguy commented Feb 23, 2022

I restructured quite a bit for this change, probably more than AMaCC would be comfortable with. I'm moving this ticket over to the HPCguy / Squint repository. I'll still be fixing the AMaCC bugs I have logged in the other issues here.

@HPCguy HPCguy closed this as completed Feb 23, 2022
@HPCguy
Copy link
Contributor Author

HPCguy commented Mar 3, 2022

Floating point support has been added to the Main branch of https://github.com/HPCguy/Squint. I will gladly add this to AMaCC as-is.

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

No branches or pull requests

1 participant