Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

c2goasm generates asm which triggers expected identifier, found "." #23

Open
ahysing opened this issue Nov 23, 2019 · 1 comment
Open

Comments

@ahysing
Copy link

ahysing commented Nov 23, 2019

I am trying to build a C function for variance of a population. I am building it with only c99, c2goasm and clang for mac.
clang works as expected. c2goasm works as expected. however the assembly produced by c2goasm does not work in the build process for go.
go compiler outputs

./stats_nocgo.s:431: expected identifier, found "."
asm: assembly of ./stats_nocgo.s failed

I have posted a working example of this issue as a small github project on my profile.
do make test to see the message above.

Gist of the Code

My c-code looks like

#include <stdint.h>

#define SIZE 16

void variance_uint32_nocgo_darwin(uint32_t buf[], int len, double *result) {
    double intermediate[SIZE];

    uint32_t sum = 0;
    for (int i = 0; i < len; i++) {
        uint32_t value = buf[i];
        sum += value;
    }
    double mean = sum / ((double)len);

    double accumulator = 0.0;
    for (int j = 0; j < len / SIZE; j++) {
        for (int i = 0; i < SIZE; i++) {
            intermediate[i] = (double)buf[(j * SIZE) + i];
        }
        for (int i = 0; i < SIZE; i++) {
            double value = intermediate[i];
            double diff = value - mean;
            intermediate[i] = diff;
        }
        for (int i = 0; i < SIZE; i++) {
            double diff = intermediate[i];
            accumulator += diff * diff;
        }
    }

    int start = (len - (len % SIZE));
    for (int i = start; i < len; i++) {
        intermediate[i - start] = (double)buf[i];
    }
    int end = (len % SIZE);
    for (int i = 0; i < end; i++) {
        double value = intermediate[i];
        double diff = value - mean;
        intermediate[i] = diff;
    }
    for (int i = 0; i < end; i++) {
        double diff = intermediate[i];
        accumulator += diff * diff;
    }

    double variance = accumulator / (double)(len - 1);
    *result = variance;
}

I have also uploaded the output assembly from clang and and c2goasm into as separte folders called examples

Build and run

I am bulding with

clang -S -O3 -mavx2 -masm=intel -mno-red-zone -mstackrealign -mllvm -inline-threshold=1000 -fno-asynchronous-unwind-tables -fno-exceptions -fno-rtti     -c stats_nocgo.c -o stats_intermediate.s
c2goasm stats_intermediate.s stats_nocgo.s;
rm stats_intermediate.s
CGO_ENABLED=0 go build .

The

System Information

go version 13.

$ go version
go version go1.13.1 darwin/amd64
$ clang --version
Apple clang version 11.0.0 (clang-1100.0.33.12)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Running on macOS 10.14.6

@elichai
Copy link

elichai commented Feb 24, 2021

I'm having the same problem on linux + gcc

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants