LDC2 (2.108.1/master) using LLVM-MOS (v18) backend
Build ldc2 + llvm-mos or run
$ docker run --rm -it -v $(pwd):/work -w /work kassany/ldc-mos:latest bash
LDC2 using LLVM-MOS backend
License: Apache License 2.0
LDC2 (2.108.1/master) using LLVM-MOS (v18) backend
Build ldc2 + llvm-mos or run
$ docker run --rm -it -v $(pwd):/work -w /work kassany/ldc-mos:latest bash
Currently the same LLVM-MOS v18 Backend is used in zig and ldc2 (dlang). However, when building the new soa_example.d
file, it can be seen that the layout of the SOA structure has a size of i32 bit and not i16 bit.
I have tried modifying the compiler bitness on the ldc2 side (not dmd frontend), by adding mos-target to the compiler driver. However, no change in the result.
src: https://github.com/kassane/dlang-mos-hello-world/blob/main/c64/soa/src/soa_example.d
#include <stdio.h>
typedef struct {
unsigned int c;
unsigned int d;
} TransparentStruct;
typedef struct {
TransparentStruct data[5];
size_t length;
} StructOfArray;
void clear(StructOfArray *soa) {
soa->length = 0;
}
size_t capacity(const StructOfArray *soa) {
return sizeof(soa->data) / sizeof(soa->data[0]);
}
size_t size(const StructOfArray *soa) {
return soa->length;
}
int main() {
StructOfArray soa = {
.data = {
{ 'a', 'b' }, { 'c', 'd' },
{ 'e', 'f' }, { 'g', 'h' },
{ 'i', 'j' }
},
.length = 5
};
for (size_t idx = 0; idx < sizeof(soa.data) / sizeof(soa.data[0]); idx++) {
printf("c[%zu].c: %d\n", idx, soa.data[idx].c);
printf("c[%zu].d: %d\n", idx, soa.data[idx].d);
}
clear(&soa);
printf("Cleared size: %zu\n", size(&soa));
printf("Capacity: %zu\n", capacity(&soa));
return 0;
}
$ zig cc \
-target mos-freestanding-none \
src/soa_example.c \
-I/opt/llvm-mos-sdk/mos-platform/common/include \
-Oz \
-s \
-c \
-S \
-emit-llvm \
-o soa_zigcc.ll
$ ldmd2 -i \
-mtriple=mos \
src/soa_example.c \
-I/opt/llvm-mos-sdk/mos-platform/common/include \
-release \
-Oz \
-betterC \
--output-ll \
-of=soa_ldc.ll \
-gcc=/opt/llvm-mos/bin/mos-c64-clang \
-linker=/opt/llvm-mos/bin/ld.lld
ldc2 output:
; ModuleID = 'src/soa_example.c'
source_filename = "src/soa_example.c"
target datalayout = "e-m:e-p:16:8-p1:8:8-i16:8-i32:8-i64:8-f32:8-f64:8-a:8-Fi8-n8"
target triple = "mos"
%soa_example.StructOfArray = type { [5 x %soa_example.TransparentStruct], i32 }
%soa_example.TransparentStruct = type { i32, i32 }
@.str = private unnamed_addr constant [14 x i8] c"c[%zu].c: %d\0A\00" ; [#uses = 5]
@.str.1 = private unnamed_addr constant [14 x i8] c"c[%zu].d: %d\0A\00" ; [#uses = 5]
@.str.2 = private unnamed_addr constant [19 x i8] c"Cleared size: %zu\0A\00" ; [#uses = 1]
@.str.3 = private unnamed_addr constant [15 x i8] c"Capacity: %zu\0A\00" ; [#uses = 1]
zig output:
; ModuleID = 'src/soa_example.c'
source_filename = "src/soa_example.c"
target datalayout = "e-m:e-p:16:8-p1:8:8-i16:8-i32:8-i64:8-f32:8-f64:8-a:8-Fi8-n8"
target triple = "mos-unknown-unknown-unknown"
%struct.StructOfArray = type { [5 x %struct.TransparentStruct], i16 }
%struct.TransparentStruct = type { i16, i16 }
@.str = private unnamed_addr constant [14 x i8] c"c[%zu].c: %d\0A\00", align 1
@.str.1 = private unnamed_addr constant [14 x i8] c"c[%zu].d: %d\0A\00", align 1
@.str.2 = private unnamed_addr constant [19 x i8] c"Cleared size: %zu\0A\00", align 1
@.str.3 = private unnamed_addr constant [15 x i8] c"Capacity: %zu\0A\00", align 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.