libera/#sicl - IRC Chatlog
Search
5:44:33
rotateq
beach: How is MOD implemented in SICL? The usual way with (mod x y) = (- x (* y (floor (/ x y)))) ?
5:47:07
rotateq
I should go on implementing it without division via Montgomery reduction, but something didn't work out from translating the "pseudo-code".
6:03:26
rotateq
So maybe we save Montgomery for a possible compiler macro. :) It's good when being on a small platform when one doesn't have division routines.
6:05:44
rotateq
When reading in one of my favorite math books "Concrete Mathematics - A Foundation for Computer Science" by Knuth et al. he gives, that it would make sense to define (mod x 0) = x.
6:27:26
beach
rotateq: Modern processors have a "divide" instruction that computes both values of FLOOR at the same time, for some not-too-large positive integers.
6:27:48
moon-child
rotateq: mathematica lies anyway. Try 0/0, it will say 'undefined'; but give it 0/x with no information about x, and it will tell you 0
6:28:53
rotateq
Yes beach, also very nice, so doing like TRUNCATE naturally. Even some storing the values then directly in two registers I think if it makes sense.
6:29:03
moon-child
beach: divmod is old. And, not all modern isas have it, e.g. I think riscv elides it because it wants only one output per instruction
6:29:37
rotateq
moon-child: And Wolfram Language is called by the company/website the "most modern" language which has "everything".
6:31:14
moon-child
that's clearly impossible, as it would then contain contradictory features. Mathematica makes certain tradeoffs which are probably reasonable in context. But 'mathematica gives answer y' is not necessarily a good justification for y
6:31:59
beach
moon-child: Good point. MOD would still be a machine instruction in many cases though.
6:34:31
moon-child
beach: yes. But I think orthodoxy is that it is better to start by distinguishing DIVs and MODs, and attempt to merge them when profitable. In which context it is counterproductive to define MOD in terms of DIVMOD (though one should ideally be able to ultimately generate the same code either, so perhaps it does not matter so much)
6:36:25
beach
But I am frequently wrong, so I would not be surprised if some assumptions are, and I need to do something different later.
6:38:16
moon-child
I mean that it should be implemented as (values (primop:div x y) (primop:mod x y)). Basic dce will get rid of either value if it is unneeded. Later on, if it is determined that two numbers must be both divided and modded, those instructions will be merged
6:40:44
moon-child
perhaps value numbering tells you the inputs are the same along some path, but that wasn't obvious in the source
6:41:32
moon-child
I also think that analyses and optimizions are more clearly expressed. You do not say 'do this for output 2 of divmod', but 'do this for mod'. There is a misdirection in the former
6:47:21
beach
One thing is clear, though. If I spend my time changing perhaps sub-optimal decisions for micro-optimizations before we a native executable in which we can measure the impact of such decisions, I will likely never have enough time to work on getting the bootstrapping procedure to produce such an executable. I think I need to "delegate" some chunks of optimization work to other.
6:48:46
rotateq
Surely again you go the way saner and more thoughtful way. :) Everything else is just optional.
6:50:14
beach
It is just that I have to think of everything and act upon everything, we are looking at another few decades before I have something to show.
6:50:50
beach
I am working on the ELS paper right now, and after that, I absolutely have to get back to bootstrapping.
6:53:15
beach
Anyway, today I need to go buy food, so I will go prepare for that. I'll be back probably in less than 2 hours.
14:38:11
yitzi
beach: I commented yesterday (or something) that figured out how to do capture the line+column information for the example that you and Bike were talking about for source code via pprint. I did so by capturing the current object being printed in the stream style object I came up with in trivial-stream-column. I am thinking of changing the name from "style" to something better that indicates that this is okay...
14:39:40
yitzi
Basically, one can pass this "style" (or stream state) to something like a measure-string method to predict the layout width. Since one could put other things in the "style" maybe call it a stream-state or something? If someone has a good name that would be awesome.
15:09:48
Bike
continuing from what i was talking about last night. big reason i'm thinking of this is i've read some of what the racket people have been doing and it's interesting
15:11:03
Bike
one thing is, you can do something like (defun foo (f) (declare (type (function * float) f)) (... (funcall f ...))), and if f returns a non-float, you could get an error message something like "F, which was declared a (function * float), returned [whatever] instead"
15:11:18
Bike
like the error message refers to the actual declaration that was the problem, even though the error is detected later
15:12:31
Bike
that doesn't in itself have much to do with timing, but with good messages it seems less important to signal errors at particular times
15:18:38
beach
But I think the way to go is what I suggested, i.e. rather than altering the semantics (supposing the AREF specification is fixed, or supposing an operator that is already required to signal an error), do the test early, but then make two branches where one ends in (a better) error.
15:24:19
beach
I don't know. But it seems uncontroversial to do it the way I suggest, whereas there might be objections to eliding some operation that look like it ought to be performed even in case of an error situation following it.
15:25:43
Bike
but if it's specified loosely, an implementation can still choose to do it without elision. it wouldn't require implementation changes or anything
15:26:43
beach
That's true. But we don't have a specification at the moment, other than people's "gut feeling".
15:27:56
beach
And I frankly don't see any way that something like this could be specified more loosely. As in, I can give examples like yours, but can't think of any general way of phrasing it.
15:32:57
Bike
what i'm imagining is the page on aref etc say "an error might be signaled", and then elsewhere there's a section explaining where an error can be signaled, sort of like 3.5.1.1.1
15:33:08
Bike
so i don't think people would care much any more than they do about 3.5.1.1.1 or "error terminology"
15:36:10
Bike
oh, i think 3.5.1.1.1 is just about argument count mismatches and stuff, not type problems