diff options
| author | Russ Cox <rsc@golang.org> | 2009-01-22 16:23:44 -0800 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2009-01-22 16:23:44 -0800 |
| commit | 1f8a40d85c3bb7a1cf3113e7ab1afdb44f6c0e4d (patch) | |
| tree | ece2442553c8681e8134d2201e6201e1e429adb8 /src/runtime | |
| parent | 8c5bc7e93adae7546b4f1520d1b20f18ebe95d88 (diff) | |
| download | go-1f8a40d85c3bb7a1cf3113e7ab1afdb44f6c0e4d.tar.xz | |
move math routines from package sys to package math,
though they still build in src/runtime.
use cgo instead of hand-written wrappers.
R=r
DELTA=740 (289 added, 300 deleted, 151 changed)
OCL=23326
CL=23331
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/Makefile | 15 | ||||
| -rw-r--r-- | src/runtime/amd64_darwin.h | 10 | ||||
| -rw-r--r-- | src/runtime/cgo2c.c | 99 | ||||
| -rw-r--r-- | src/runtime/float.c | 173 | ||||
| -rw-r--r-- | src/runtime/float_go.cgo | 52 | ||||
| -rw-r--r-- | src/runtime/rt1_amd64_darwin.c | 54 | ||||
| -rw-r--r-- | src/runtime/runtime.c | 255 | ||||
| -rw-r--r-- | src/runtime/runtime.h | 25 | ||||
| -rw-r--r-- | src/runtime/sema.c | 6 | ||||
| -rw-r--r-- | src/runtime/sema_go.cgo | 15 |
10 files changed, 357 insertions, 347 deletions
diff --git a/src/runtime/Makefile b/src/runtime/Makefile index f62229fd2c..03633a61d3 100644 --- a/src/runtime/Makefile +++ b/src/runtime/Makefile @@ -17,23 +17,26 @@ LIBOFILES=\ rt1_$(GOARCH)_$(GOOS).$O\ rt2_$(GOARCH).$O\ sys_$(GOARCH)_$(GOOS).$O\ - runtime.$O\ - hashmap.$O\ + array.$O\ chan.$O\ + float.$O\ + float_go.$O\ + hashmap.$O\ iface.$O\ - array.$O\ - mem.$O\ malloc.$O\ malloc_go.$O\ mcache.$O\ mcentral.$O\ + mem.$O\ mfixalloc.$O\ mheap.$O\ msize.$O\ print.$O\ - rune.$O\ proc.$O\ + rune.$O\ + runtime.$O\ sema.$O\ + sema_go.$O\ string.$O\ symtab.$O\ @@ -69,7 +72,7 @@ cgo2c: cgo2c.c quietgcc -o $@ $< %.c: %.cgo cgo2c - ./cgo2c < $< > $@.tmp + ./cgo2c $< > $@.tmp mv -f $@.tmp $@ %.$O: %.s diff --git a/src/runtime/amd64_darwin.h b/src/runtime/amd64_darwin.h index 45174cb42a..28e58972b1 100644 --- a/src/runtime/amd64_darwin.h +++ b/src/runtime/amd64_darwin.h @@ -58,8 +58,8 @@ void bsdthread_register(void); typedef int32 kern_return_t; typedef uint32 mach_port_t; -mach_port_t semcreate(void); -void semacquire(mach_port_t); -void semrelease(mach_port_t); -void semreset(mach_port_t); -void semdestroy(mach_port_t); +mach_port_t mach_semcreate(void); +void mach_semacquire(mach_port_t); +void mach_semrelease(mach_port_t); +void mach_semreset(mach_port_t); +void mach_semdestroy(mach_port_t); diff --git a/src/runtime/cgo2c.c b/src/runtime/cgo2c.c index 0d1817d6bd..3905f7e6dc 100644 --- a/src/runtime/cgo2c.c +++ b/src/runtime/cgo2c.c @@ -21,11 +21,13 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <errno.h> -/* The name of the program. */ -static const char *program_name; +/* Whether we're emitting for gcc */ +static int gcc; -/* The line number. */ +/* File and line number */ +static const char *file; static unsigned int lineno; /* List of names and types. */ @@ -39,8 +41,7 @@ struct params { static void bad_eof(void) { - fprintf(stderr, "%s: line %u: unexpected EOF\n", - program_name, lineno); + fprintf(stderr, "%s:%u: unexpected EOF\n", file, lineno); exit(1); } @@ -48,8 +49,7 @@ bad_eof(void) static void bad_mem(void) { - fprintf(stderr, "%s: line %u: out of memory\n", - program_name, lineno); + fprintf(stderr, "%s:%u: out of memory\n", file, lineno); exit(1); } @@ -212,8 +212,8 @@ read_package(void) token = read_token_no_eof(); if (strcmp(token, "package") != 0) { fprintf(stderr, - "%s: line %u: expected \"package\", got \"%s\"\n", - program_name, lineno, token); + "%s:%u: expected \"package\", got \"%s\"\n", + file, lineno, token); exit(1); } return read_token_no_eof(); @@ -298,8 +298,8 @@ read_params(void) } } if (strcmp(token, ")") != 0) { - fprintf(stderr, "%s: line %u: expected '('\n", - program_name, lineno); + fprintf(stderr, "%s:%u: expected '('\n", + file, lineno); exit(1); } return ret; @@ -316,16 +316,16 @@ read_func_header(char **name, struct params **params, struct params **rets) if (token == NULL) return 0; if (strcmp(token, "func") != 0) { - fprintf(stderr, "%s: line %u: expected \"func\"\n", - program_name, lineno); + fprintf(stderr, "%s:%u: expected \"func\"\n", + file, lineno); exit(1); } *name = read_token_no_eof(); token = read_token(); if (token == NULL || strcmp(token, "(") != 0) { - fprintf(stderr, "%s: line %u: expected \"(\"\n", - program_name, lineno); + fprintf(stderr, "%s:%u: expected \"(\"\n", + file, lineno); exit(1); } *params = read_params(); @@ -338,8 +338,8 @@ read_func_header(char **name, struct params **params, struct params **rets) token = read_token(); } if (token == NULL || strcmp(token, "{") != 0) { - fprintf(stderr, "%s: line %u: expected \"{\"\n", - program_name, lineno); + fprintf(stderr, "%s:%u: expected \"{\"\n", + file, lineno); exit(1); } return 1; @@ -455,21 +455,22 @@ write_gcc_func_trailer(char *package, char *name, struct params *rets) /* Write out a function header. */ static void -write_func_header(int flag_gcc, char *package, char *name, +write_func_header(char *package, char *name, struct params *params, struct params *rets) { - if (flag_gcc) + if (gcc) write_gcc_func_header(package, name, params, rets); else write_6g_func_header(package, name, params, rets); + printf("#line %d \"%s\"\n", lineno, file); } /* Write out a function trailer. */ static void -write_func_trailer(int flag_gcc, char *package, char *name, +write_func_trailer(char *package, char *name, struct params *rets) { - if (flag_gcc) + if (gcc) write_gcc_func_trailer(package, name, rets); else write_6g_func_trailer(rets); @@ -478,7 +479,7 @@ write_func_trailer(int flag_gcc, char *package, char *name, /* Read and write the body of the function, ending in an unnested } (which is read but not written). */ static void -copy_body() +copy_body(void) { int nesting = 0; while (1) { @@ -541,7 +542,7 @@ copy_body() /* Process the entire file. */ static void -process_file(int flag_gcc) +process_file(void) { char *package, *name; struct params *params, *rets; @@ -549,9 +550,9 @@ process_file(int flag_gcc) package = read_package(); read_preprocessor_lines(); while (read_func_header(&name, ¶ms, &rets)) { - write_func_header(flag_gcc, package, name, params, rets); + write_func_header(package, name, params, rets); copy_body(); - write_func_trailer(flag_gcc, package, name, rets); + write_func_trailer(package, name, rets); free(name); free_params(params); free_params(rets); @@ -559,25 +560,43 @@ process_file(int flag_gcc) free(package); } -/* Main function. */ +static void +usage(void) +{ + fprintf(stderr, "Usage: cgo2c [--6g | --gc] [file]\n"); + exit(1); +} + int main(int argc, char **argv) { - int flag_gcc = 0; - int i; + while(argc > 1 && argv[1][0] == '-') { + if(strcmp(argv[1], "-") == 0) + break; + if(strcmp(argv[1], "--6g") == 0) + gcc = 0; + else if(strcmp(argv[1], "--gcc") == 0) + gcc = 1; + else + usage(); + argc--; + argv++; + } + + if(argc <= 1 || strcmp(argv[1], "-") == 0) { + file = "<stdin>"; + process_file(); + return 0; + } + + if(argc > 2) + usage(); - program_name = argv[0]; - for (i = 1; i < argc; ++i) { - if (strcmp(argv[i], "--6g") == 0) - flag_gcc = 0; - else if (strcmp(argv[i], "--gcc") == 0) - flag_gcc = 1; - else { - fprintf(stderr, "Usage: %s [--6g][--gcc]\n", - program_name); - exit(1); - } + file = argv[1]; + if(freopen(file, "r", stdin) == 0) { + fprintf(stderr, "open %s: %s\n", file, strerror(errno)); + exit(1); } - process_file(flag_gcc); + process_file(); return 0; } diff --git a/src/runtime/float.c b/src/runtime/float.c new file mode 100644 index 0000000000..5122f359a7 --- /dev/null +++ b/src/runtime/float.c @@ -0,0 +1,173 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "runtime.h" + +static uint64 uvnan = 0x7FF0000000000001ULL; +static uint64 uvinf = 0x7FF0000000000000ULL; +static uint64 uvneginf = 0xFFF0000000000000ULL; + +uint32 +float32tobits(float32 f) +{ + // The obvious cast-and-pointer code is technically + // not valid, and gcc miscompiles it. Use a union instead. + union { + float32 f; + uint32 i; + } u; + u.f = f; + return u.i; +} + +uint64 +float64tobits(float64 f) +{ + // The obvious cast-and-pointer code is technically + // not valid, and gcc miscompiles it. Use a union instead. + union { + float64 f; + uint64 i; + } u; + u.f = f; + return u.i; +} + +float64 +float64frombits(uint64 i) +{ + // The obvious cast-and-pointer code is technically + // not valid, and gcc miscompiles it. Use a union instead. + union { + float64 f; + uint64 i; + } u; + u.i = i; + return u.f; +} + +float32 +float32frombits(uint32 i) +{ + // The obvious cast-and-pointer code is technically + // not valid, and gcc miscompiles it. Use a union instead. + union { + float32 f; + uint32 i; + } u; + u.i = i; + return u.f; +} + +bool +isInf(float64 f, int32 sign) +{ + uint64 x; + + x = float64tobits(f); + if(sign == 0) + return x == uvinf || x == uvneginf; + if(sign > 0) + return x == uvinf; + return x == uvneginf; +} + +float64 +NaN(void) +{ + return float64frombits(uvnan); +} + +bool +isNaN(float64 f) +{ + uint64 x; + + x = float64tobits(f); + return ((uint32)(x>>52) & 0x7FF) == 0x7FF && !isInf(f, 0); +} + +float64 +Inf(int32 sign) +{ + if(sign >= 0) + return float64frombits(uvinf); + else + return float64frombits(uvneginf); +} + +enum +{ + MASK = 0x7ffL, + SHIFT = 64-11-1, + BIAS = 1022L, +}; + +float64 +frexp(float64 d, int32 *ep) +{ + uint64 x; + + if(d == 0) { + *ep = 0; + return 0; + } + x = float64tobits(d); + *ep = (int32)((x >> SHIFT) & MASK) - BIAS; + x &= ~((uint64)MASK << SHIFT); + x |= (uint64)BIAS << SHIFT; + return float64frombits(x); +} + +float64 +ldexp(float64 d, int32 e) +{ + uint64 x; + + if(d == 0) + return 0; + x = float64tobits(d); + e += (int32)(x >> SHIFT) & MASK; + if(e <= 0) + return 0; /* underflow */ + if(e >= MASK){ /* overflow */ + if(d < 0) + return Inf(-1); + return Inf(1); + } + x &= ~((uint64)MASK << SHIFT); + x |= (uint64)e << SHIFT; + return float64frombits(x); +} + +float64 +modf(float64 d, float64 *ip) +{ + float64 dd; + uint64 x; + int32 e; + + if(d < 1) { + if(d < 0) { + d = modf(-d, ip); + *ip = -*ip; + return -d; + } + *ip = 0; + return d; + } + + x = float64tobits(d); + e = (int32)((x >> SHIFT) & MASK) - BIAS; + + /* + * Keep the top 11+e bits; clear the rest. + */ + if(e <= 64-11) + x &= ~(((uint64)1 << (64LL-11LL-e))-1); + dd = float64frombits(x); + *ip = dd; + return d - dd; +} + diff --git a/src/runtime/float_go.cgo b/src/runtime/float_go.cgo new file mode 100644 index 0000000000..518d559507 --- /dev/null +++ b/src/runtime/float_go.cgo @@ -0,0 +1,52 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package math + +#include "runtime.h" + +func Frexp(f float64) (frac float64, exp int32) { + frac = frexp(f, &exp); +} + +func Ldexp(frac float64, exp int32) (f float64) { + f = ldexp(frac, exp); +} + +func Modf(f float64) (integer float64, frac float64) { + frac = modf(f, &integer); +} + +func IsInf(f float64, sign int32) (is bool) { + is = isInf(f, sign); +} + +func IsNaN(f float64) (is bool) { + is = isNaN(f); +} + +func Inf(sign int32) (f float64) { + f = Inf(sign); +} + +func NaN() (f float64) { + f = NaN(); +} + +func Float32bits(f float32) (b uint32) { + b = float32tobits(f); +} + +func Float64bits(f float64) (b uint64) { + b = float64tobits(f); +} + +func Float32frombits(b uint32) (f float32) { + f = float32frombits(b); +} + +func Float64frombits(b uint64) (f float64) { + f = float64frombits(b); +} + diff --git a/src/runtime/rt1_amd64_darwin.c b/src/runtime/rt1_amd64_darwin.c index f1ef946646..453bd519c2 100644 --- a/src/runtime/rt1_amd64_darwin.c +++ b/src/runtime/rt1_amd64_darwin.c @@ -232,10 +232,10 @@ initsema(uint32 *psema) if(*psema != 0) // already have one return; - sema = semcreate(); + sema = mach_semcreate(); if(!cas(psema, 0, sema)){ // Someone else filled it in. Use theirs. - semdestroy(sema); + mach_semdestroy(sema); return; } } @@ -281,14 +281,14 @@ lock(Lock *l) initsema(&l->sema); if(xadd(&l->key, 1) > 1) // someone else has it; wait - semacquire(l->sema); + mach_semacquire(l->sema); } void unlock(Lock *l) { if(xadd(&l->key, -1) > 0) // someone else is waiting - semrelease(l->sema); + mach_semrelease(l->sema); } @@ -300,14 +300,14 @@ void usemacquire(Usema *s) { if((int32)xadd(&s->u, -1) < 0) - semacquire(s->k); + mach_semacquire(s->k); } void usemrelease(Usema *s) { if((int32)xadd(&s->u, 1) <= 0) - semrelease(s->k); + mach_semrelease(s->k); } @@ -622,20 +622,20 @@ machcall(mach_msg_header_t *h, int32 maxsize, int32 rxsize) enum { - Tsemcreate = 3418, - Rsemcreate = Tsemcreate + Reply, + Tmach_semcreate = 3418, + Rmach_semcreate = Tmach_semcreate + Reply, - Tsemdestroy = 3419, - Rsemdestroy = Tsemdestroy + Reply, + Tmach_semdestroy = 3419, + Rmach_semdestroy = Tmach_semdestroy + Reply, }; -typedef struct TsemcreateMsg TsemcreateMsg; -typedef struct RsemcreateMsg RsemcreateMsg; -typedef struct TsemdestroyMsg TsemdestroyMsg; -// RsemdestroyMsg = CodeMsg +typedef struct Tmach_semcreateMsg Tmach_semcreateMsg; +typedef struct Rmach_semcreateMsg Rmach_semcreateMsg; +typedef struct Tmach_semdestroyMsg Tmach_semdestroyMsg; +// Rmach_semdestroyMsg = CodeMsg #pragma pack on -struct TsemcreateMsg +struct Tmach_semcreateMsg { mach_msg_header_t h; NDR_record_t ndr; @@ -643,14 +643,14 @@ struct TsemcreateMsg int32 value; }; -struct RsemcreateMsg +struct Rmach_semcreateMsg { mach_msg_header_t h; mach_msg_body_t body; mach_msg_port_descriptor_t semaphore; }; -struct TsemdestroyMsg +struct Tmach_semdestroyMsg { mach_msg_header_t h; mach_msg_body_t body; @@ -659,11 +659,11 @@ struct TsemdestroyMsg #pragma pack off mach_port_t -semcreate(void) +mach_semcreate(void) { union { - TsemcreateMsg tx; - RsemcreateMsg rx; + Tmach_semcreateMsg tx; + Rmach_semcreateMsg rx; uint8 pad[MinMachMsg]; } m; kern_return_t r; @@ -671,7 +671,7 @@ semcreate(void) m.tx.h.bits = 0; m.tx.h.size = sizeof(m.tx); m.tx.h.remote_port = mach_task_self(); - m.tx.h.id = Tsemcreate; + m.tx.h.id = Tmach_semcreate; m.tx.ndr = zerondr; m.tx.policy = 0; // 0 = SYNC_POLICY_FIFO @@ -680,15 +680,15 @@ semcreate(void) if((r = machcall(&m.tx.h, sizeof m, sizeof(m.rx))) != 0) macherror(r, "semaphore_create"); if(m.rx.body.descriptor_count != 1) - unimplemented("semcreate desc count"); + unimplemented("mach_semcreate desc count"); return m.rx.semaphore.name; } void -semdestroy(mach_port_t sem) +mach_semdestroy(mach_port_t sem) { union { - TsemdestroyMsg tx; + Tmach_semdestroyMsg tx; uint8 pad[MinMachMsg]; } m; kern_return_t r; @@ -696,7 +696,7 @@ semdestroy(mach_port_t sem) m.tx.h.bits = MACH_MSGH_BITS_COMPLEX; m.tx.h.size = sizeof(m.tx); m.tx.h.remote_port = mach_task_self(); - m.tx.h.id = Tsemdestroy; + m.tx.h.id = Tmach_semdestroy; m.tx.body.descriptor_count = 1; m.tx.semaphore.name = sem; m.tx.semaphore.disposition = MACH_MSG_TYPE_MOVE_SEND; @@ -714,7 +714,7 @@ kern_return_t mach_semaphore_signal(uint32 sema); kern_return_t mach_semaphore_signal_all(uint32 sema); void -semacquire(mach_port_t sem) +mach_semacquire(mach_port_t sem) { kern_return_t r; @@ -723,7 +723,7 @@ semacquire(mach_port_t sem) } void -semrelease(mach_port_t sem) +mach_semrelease(mach_port_t sem) { kern_return_t r; diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 31bd1ed868..29a67b190d 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -113,261 +113,6 @@ rnd(uint32 n, uint32 m) return n; } -static uint64 uvnan = 0x7FF0000000000001ULL; -static uint64 uvinf = 0x7FF0000000000000ULL; -static uint64 uvneginf = 0xFFF0000000000000ULL; - -static uint32 -float32tobits(float32 f) -{ - // The obvious cast-and-pointer code is technically - // not valid, and gcc miscompiles it. Use a union instead. - union { - float32 f; - uint32 i; - } u; - u.f = f; - return u.i; -} - -static uint64 -float64tobits(float64 f) -{ - // The obvious cast-and-pointer code is technically - // not valid, and gcc miscompiles it. Use a union instead. - union { - float64 f; - uint64 i; - } u; - u.f = f; - return u.i; -} - -static float64 -float64frombits(uint64 i) -{ - // The obvious cast-and-pointer code is technically - // not valid, and gcc miscompiles it. Use a union instead. - union { - float64 f; - uint64 i; - } u; - u.i = i; - return u.f; -} - -static float32 -float32frombits(uint32 i) -{ - // The obvious cast-and-pointer code is technically - // not valid, and gcc miscompiles it. Use a union instead. - union { - float32 f; - uint32 i; - } u; - u.i = i; - return u.f; -} - -bool -isInf(float64 f, int32 sign) -{ - uint64 x; - - x = float64tobits(f); - if(sign == 0) - return x == uvinf || x == uvneginf; - if(sign > 0) - return x == uvinf; - return x == uvneginf; -} - -static float64 -NaN(void) -{ - return float64frombits(uvnan); -} - -bool -isNaN(float64 f) -{ - uint64 x; - - x = float64tobits(f); - return ((uint32)(x>>52) & 0x7FF) == 0x7FF && !isInf(f, 0); -} - -static float64 -Inf(int32 sign) -{ - if(sign >= 0) - return float64frombits(uvinf); - else - return float64frombits(uvneginf); -} - -enum -{ - MASK = 0x7ffL, - SHIFT = 64-11-1, - BIAS = 1022L, -}; - -static float64 -frexp(float64 d, int32 *ep) -{ - uint64 x; - - if(d == 0) { - *ep = 0; - return 0; - } - x = float64tobits(d); - *ep = (int32)((x >> SHIFT) & MASK) - BIAS; - x &= ~((uint64)MASK << SHIFT); - x |= (uint64)BIAS << SHIFT; - return float64frombits(x); -} - -static float64 -ldexp(float64 d, int32 e) -{ - uint64 x; - - if(d == 0) - return 0; - x = float64tobits(d); - e += (int32)(x >> SHIFT) & MASK; - if(e <= 0) - return 0; /* underflow */ - if(e >= MASK){ /* overflow */ - if(d < 0) - return Inf(-1); - return Inf(1); - } - x &= ~((uint64)MASK << SHIFT); - x |= (uint64)e << SHIFT; - return float64frombits(x); -} - -static float64 -modf(float64 d, float64 *ip) -{ - float64 dd; - uint64 x; - int32 e; - - if(d < 1) { - if(d < 0) { - d = modf(-d, ip); - *ip = -*ip; - return -d; - } - *ip = 0; - return d; - } - - x = float64tobits(d); - e = (int32)((x >> SHIFT) & MASK) - BIAS; - - /* - * Keep the top 11+e bits; clear the rest. - */ - if(e <= 64-11) - x &= ~(((uint64)1 << (64LL-11LL-e))-1); - dd = float64frombits(x); - *ip = dd; - return d - dd; -} - -// func Frexp(float64) (float64, int32); // break fp into exp,frac -void -sys·Frexp(float64 din, float64 dou, int32 iou) -{ - dou = frexp(din, &iou); - FLUSH(&dou); -} - -//func ldexp(int32, float64) float64; // make fp from exp,frac -void -sys·Ldexp(float64 din, int32 ein, float64 dou) -{ - dou = ldexp(din, ein); - FLUSH(&dou); -} - -//func modf(float64) (float64, float64); // break fp into double+double -void -sys·Modf(float64 din, float64 integer, float64 fraction) -{ - fraction = modf(din, &integer); - FLUSH(&fraction); -} - -//func isinf(float64, int32 sign) bool; // test for infinity -void -sys·IsInf(float64 din, int32 signin, bool out) -{ - out = isInf(din, signin); - FLUSH(&out); -} - -//func isnan(float64) bool; // test for NaN -void -sys·IsNaN(float64 din, bool out) -{ - out = isNaN(din); - FLUSH(&out); -} - -//func inf(int32 sign) float64; // signed infinity -void -sys·Inf(int32 signin, float64 out) -{ - out = Inf(signin); - FLUSH(&out); -} - -//func nan() float64; // NaN -void -sys·NaN(float64 out) -{ - out = NaN(); - FLUSH(&out); -} - -// func float32bits(float32) uint32; // raw bits of float32 -void -sys·Float32bits(float32 din, uint32 iou) -{ - iou = float32tobits(din); - FLUSH(&iou); -} - -// func float64bits(float64) uint64; // raw bits of float64 -void -sys·Float64bits(float64 din, uint64 iou) -{ - iou = float64tobits(din); - FLUSH(&iou); -} - -// func float32frombits(uint32) float32; // raw bits to float32 -void -sys·Float32frombits(uint32 uin, float32 dou) -{ - dou = float32frombits(uin); - FLUSH(&dou); -} - -// func float64frombits(uint64) float64; // raw bits to float64 -void -sys·Float64frombits(uint64 uin, float64 dou) -{ - dou = float64frombits(uin); - FLUSH(&dou); -} - static int32 argc; static uint8** argv; diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index 735f1aa9ce..bc6b2f76d5 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -370,15 +370,12 @@ void notewakeup(Note*); #define sys_printpointer sys·printpointer #define sys_printstring sys·printstring #define sys_printuint sys·printuint -#define sys_readfile sys·readfile -#define sys_semacquire sys·semacquire -#define sys_semrelease sys·semrelease #define sys_setcallerpc sys·setcallerpc #define sys_slicestring sys·slicestring #endif /* - * low level go -called + * low level go-called */ void sys_Goexit(void); void sys_Gosched(void); @@ -407,12 +404,20 @@ void sys_cmpstring(string, string, int32); void sys_slicestring(string, int32, int32, string); void sys_indexstring(string, int32, byte); void sys_intstring(int64, string); -bool isInf(float64, int32); -bool isNaN(float64); /* - * User go-called + * wrapped for go users */ -void sys_readfile(string, string, bool); -void sys_semacquire(uint32*); -void sys_semrelease(uint32*); +float64 Inf(int32 sign); +float64 NaN(void); +float32 float32frombits(uint32 i); +uint32 float32tobits(float32 f); +float64 float64frombits(uint64 i); +uint64 float64tobits(float64 f); +float64 frexp(float64 d, int32 *ep); +bool isInf(float64 f, int32 sign); +bool isNaN(float64 f); +float64 ldexp(float64 d, int32 e); +float64 modf(float64 d, float64 *ip); +void semacquire(uint32*); +void semrelease(uint32*); diff --git a/src/runtime/sema.c b/src/runtime/sema.c index e4309f079b..cad08d1672 100644 --- a/src/runtime/sema.c +++ b/src/runtime/sema.c @@ -133,11 +133,10 @@ cansemacquire(uint32 *addr) return 0; } -// func sync.semacquire(addr *uint32) // For now has no return value. // Might return an ok (not interrupted) bool in the future? void -sync·semacquire(uint32 *addr) +semacquire(uint32 *addr) { Sema s; @@ -163,9 +162,8 @@ sync·semacquire(uint32 *addr) semwakeup(addr); } -// func sync.semrelease(addr *uint32) void -sync·semrelease(uint32 *addr) +semrelease(uint32 *addr) { uint32 v; diff --git a/src/runtime/sema_go.cgo b/src/runtime/sema_go.cgo new file mode 100644 index 0000000000..eb4082a0d1 --- /dev/null +++ b/src/runtime/sema_go.cgo @@ -0,0 +1,15 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package sync +#include "runtime.h" + +func semacquire(addr *uint32) { + semacquire(addr); +} + +func semrelease(addr *uint32) { + semrelease(addr); +} + |
